⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpc_qmfb.c

📁 用C语言实现的JPEG编码
💻 C
📖 第 1 页 / 共 3 页
字号:
	abort();	return -1;}static int jpc_ns_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters){	jas_seq_t *lf;	jas_seq_t *hf;	/* Avoid compiler warnings about unused parameters. */	qmfb = 0;	lf = 0;	hf = 0;	if (len > 1 || (!len)) {		if (!(lf = jas_seq_create(-3, 4))) {			goto error;		}		jas_seq_set(lf, -3, jpc_dbltofix(-0.09127176311424948));		jas_seq_set(lf, -2, jpc_dbltofix(-0.05754352622849957));		jas_seq_set(lf, -1, jpc_dbltofix(0.5912717631142470));		jas_seq_set(lf, 0, jpc_dbltofix(1.115087052456994));		jas_seq_set(lf, 1, jpc_dbltofix(0.5912717631142470));		jas_seq_set(lf, 2, jpc_dbltofix(-0.05754352622849957));		jas_seq_set(lf, 3, jpc_dbltofix(-0.09127176311424948));		if (!(hf = jas_seq_create(-3, 6))) {			goto error;		}		jas_seq_set(hf, -3, jpc_dbltofix(-0.02674875741080976 * 2.0));		jas_seq_set(hf, -2, jpc_dbltofix(-0.01686411844287495 * 2.0));		jas_seq_set(hf, -1, jpc_dbltofix(0.07822326652898785 * 2.0));		jas_seq_set(hf, 0, jpc_dbltofix(0.2668641184428723 * 2.0));		jas_seq_set(hf, 1, jpc_dbltofix(-0.6029490182363579 * 2.0));		jas_seq_set(hf, 2, jpc_dbltofix(0.2668641184428723 * 2.0));		jas_seq_set(hf, 3, jpc_dbltofix(0.07822326652898785 * 2.0));		jas_seq_set(hf, 4, jpc_dbltofix(-0.01686411844287495 * 2.0));		jas_seq_set(hf, 5, jpc_dbltofix(-0.02674875741080976 * 2.0));	} else if (len == 1) {		if (!(lf = jas_seq_create(0, 1))) {			goto error;		}		jas_seq_set(lf, 0, jpc_dbltofix(1.0));		if (!(hf = jas_seq_create(0, 1))) {			goto error;		}		jas_seq_set(hf, 0, jpc_dbltofix(2.0));	} else {		abort();	}	filters[0] = lf;	filters[1] = hf;	return 0;error:	if (lf) {		jas_seq_destroy(lf);	}	if (hf) {		jas_seq_destroy(hf);	}	return -1;}#define	NNS_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \{ \	register jpc_fix_t *lptr = (lstartptr); \	register jpc_fix_t *hptr = (hstartptr); \	register int n = (hendind) - (hstartind); \	jpc_fix_t twoalpha = jpc_fix_mulbyint(alpha, 2); \	if ((hstartind) < (lstartind)) { \		jpc_fix_pluseq(*hptr, jpc_fix_mul(*lptr, (twoalpha))); \		hptr += (step); \		--n; \	} \	if ((hendind) >= (lendind)) { \		--n; \	} \	while (n-- > 0) { \		jpc_fix_pluseq(*hptr, jpc_fix_mul(jpc_fix_add(*lptr, lptr[(step)]), (alpha))); \		hptr += (step); \		lptr += (step); \	} \	if ((hendind) >= (lendind)) { \		jpc_fix_pluseq(*hptr, jpc_fix_mul(*lptr, (twoalpha))); \	} \}#define	NNS_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \{ \	register jpc_fix_t *lptr = (lstartptr); \	register jpc_fix_t *hptr = (hstartptr); \	register int n = (lendind) - (lstartind); \	int twoalpha = jpc_fix_mulbyint(alpha, 2); \	if ((hstartind) >= (lstartind)) { \		jpc_fix_pluseq(*lptr, jpc_fix_mul(*hptr, (twoalpha))); \		lptr += (step); \		--n; \	} \	if ((lendind) > (hendind)) { \		--n; \	} \	while (n-- > 0) { \		jpc_fix_pluseq(*lptr, jpc_fix_mul(jpc_fix_add(*hptr, hptr[(step)]), (alpha))); \		lptr += (step); \		hptr += (step); \	} \	if ((lendind) > (hendind)) { \		jpc_fix_pluseq(*lptr, jpc_fix_mul(*hptr, (twoalpha))); \	} \}#define	NNS_SCALE(startptr, startind, endind, step, alpha) \{ \	register jpc_fix_t *ptr = (startptr); \	register int n = (endind) - (startind); \	while (n-- > 0) { \		jpc_fix_muleq(*ptr, alpha); \		ptr += (step); \	} \}static void jpc_ns_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x){	jpc_fix_t *startptr;	int startind;	int endind;	jpc_fix_t *lstartptr;	int lstartind;	int lendind;	jpc_fix_t *hstartptr;	int hstartind;	int hendind;	int interstep;	int intrastep;	int numseq;	/* Avoid compiler warnings about unused parameters. */	qmfb = 0;	if (flags & JPC_QMFB1D_VERT) {		interstep = 1;		intrastep = jas_seq2d_rowstep(x);		numseq = jas_seq2d_width(x);		startind = jas_seq2d_ystart(x);		endind = jas_seq2d_yend(x);	} else {		interstep = jas_seq2d_rowstep(x);		intrastep = 1;		numseq = jas_seq2d_height(x);		startind = jas_seq2d_xstart(x);		endind = jas_seq2d_xend(x);	}	assert(startind < endind);	startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));	if (!(flags & JPC_QMFB1D_RITIMODE)) {		while (numseq-- > 0) {			jpc_qmfb1d_setup(startptr, startind, endind, intrastep,			  &lstartptr, &lstartind, &lendind, &hstartptr,			  &hstartind, &hendind);			if (endind - startind > 1) {				jpc_qmfb1d_split(startptr, startind, endind,				  intrastep, lstartptr, lstartind, lendind,				  hstartptr, hstartind, hendind);				NNS_LIFT0(lstartptr, lstartind, lendind,				  hstartptr, hstartind, hendind, intrastep,				  jpc_dbltofix(-1.586134342));				NNS_LIFT1(lstartptr, lstartind, lendind,				  hstartptr, hstartind, hendind, intrastep,				  jpc_dbltofix(-0.052980118));				NNS_LIFT0(lstartptr, lstartind, lendind,				  hstartptr, hstartind, hendind, intrastep,				  jpc_dbltofix(0.882911075));				NNS_LIFT1(lstartptr, lstartind, lendind,				  hstartptr, hstartind, hendind, intrastep,				  jpc_dbltofix(0.443506852));				NNS_SCALE(lstartptr, lstartind, lendind,				  intrastep, jpc_dbltofix(1.0/1.23017410558578));				NNS_SCALE(hstartptr, hstartind, hendind,				  intrastep, jpc_dbltofix(1.0/1.62578613134411));			} else {#if 0				if (lstartind == lendind) {					*startptr = jpc_fix_asl(*startptr, 1);				}#endif			}			startptr += interstep;		}	} else {		/* The reversible integer-to-integer mode is not supported		  for this transform. */		abort();	}}static void jpc_ns_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x){	jpc_fix_t *startptr;	int startind;	int endind;	jpc_fix_t *lstartptr;	int lstartind;	int lendind;	jpc_fix_t *hstartptr;	int hstartind;	int hendind;	int interstep;	int intrastep;	int numseq;	/* Avoid compiler warnings about unused parameters. */	qmfb = 0;	if (flags & JPC_QMFB1D_VERT) {		interstep = 1;		intrastep = jas_seq2d_rowstep(x);		numseq = jas_seq2d_width(x);		startind = jas_seq2d_ystart(x);		endind = jas_seq2d_yend(x);	} else {		interstep = jas_seq2d_rowstep(x);		intrastep = 1;		numseq = jas_seq2d_height(x);		startind = jas_seq2d_xstart(x);		endind = jas_seq2d_xend(x);	}	assert(startind < endind);	startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));	if (!(flags & JPC_QMFB1D_RITIMODE)) {		while (numseq-- > 0) {			jpc_qmfb1d_setup(startptr, startind, endind, intrastep,			  &lstartptr, &lstartind, &lendind, &hstartptr,			  &hstartind, &hendind);			if (endind - startind > 1) {				NNS_SCALE(lstartptr, lstartind, lendind,				  intrastep, jpc_dbltofix(1.23017410558578));				NNS_SCALE(hstartptr, hstartind, hendind,				  intrastep, jpc_dbltofix(1.62578613134411));				NNS_LIFT1(lstartptr, lstartind, lendind,				  hstartptr, hstartind, hendind, intrastep,				  jpc_dbltofix(-0.443506852));				NNS_LIFT0(lstartptr, lstartind, lendind,				  hstartptr, hstartind, hendind, intrastep,				  jpc_dbltofix(-0.882911075));				NNS_LIFT1(lstartptr, lstartind, lendind,				  hstartptr, hstartind, hendind, intrastep,				  jpc_dbltofix(0.052980118));				NNS_LIFT0(lstartptr, lstartind, lendind,				  hstartptr, hstartind, hendind, intrastep,				  jpc_dbltofix(1.586134342));				jpc_qmfb1d_join(startptr, startind, endind,				  intrastep, lstartptr, lstartind, lendind,				  hstartptr, hstartind, hendind);			} else {#if 0				if (lstartind == lendind) {					*startptr = jpc_fix_asr(*startptr, 1);				}#endif			}			startptr += interstep;		}	} else {		/* The reversible integer-to-integer mode is not supported		  for this transform. */		abort();	}}/******************************************************************************\*\******************************************************************************/jpc_qmfb1d_t *jpc_qmfb1d_make(int qmfbid){	jpc_qmfb1d_t *qmfb;	if (!(qmfb = jpc_qmfb1d_create())) {		return 0;	}	switch (qmfbid) {	case JPC_QMFB1D_FT:		qmfb->ops = &jpc_ft_ops;		break;	case JPC_QMFB1D_NS:		qmfb->ops = &jpc_ns_ops;		break;	default:		jpc_qmfb1d_destroy(qmfb);		return 0;		break;	}	return qmfb;}static jpc_qmfb1d_t *jpc_qmfb1d_create(){	jpc_qmfb1d_t *qmfb;	if (!(qmfb = jas_malloc(sizeof(jpc_qmfb1d_t)))) {		return 0;	}	qmfb->ops = 0;	return qmfb;}jpc_qmfb1d_t *jpc_qmfb1d_copy(jpc_qmfb1d_t *qmfb){	jpc_qmfb1d_t *newqmfb;	if (!(newqmfb = jpc_qmfb1d_create())) {		return 0;	}	newqmfb->ops = qmfb->ops;	return newqmfb;}void jpc_qmfb1d_destroy(jpc_qmfb1d_t *qmfb){	jas_free(qmfb);}/******************************************************************************\*\******************************************************************************/void jpc_qmfb1d_getbands(jpc_qmfb1d_t *qmfb, int flags, uint_fast32_t xstart,  uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend, int maxbands,  int *numbandsptr, jpc_qmfb1dband_t *bands){	int start;	int end;	assert(maxbands >= 2);	if (flags & JPC_QMFB1D_VERT) {		start = ystart;		end = yend;	} else {		start = xstart;		end = xend;	}	assert(jpc_qmfb1d_getnumchans(qmfb) == 2);	assert(start <= end);	bands[0].start = JPC_CEILDIVPOW2(start, 1);	bands[0].end = JPC_CEILDIVPOW2(end, 1);	bands[0].locstart = start;	bands[0].locend = start + bands[0].end - bands[0].start;	bands[1].start = JPC_FLOORDIVPOW2(start, 1);	bands[1].end = JPC_FLOORDIVPOW2(end, 1);	bands[1].locstart = bands[0].locend;	bands[1].locend = bands[1].locstart + bands[1].end - bands[1].start;	assert(bands[1].locend == end);	*numbandsptr = 2;}/******************************************************************************\*\******************************************************************************/int jpc_qmfb1d_getnumchans(jpc_qmfb1d_t *qmfb){	return (*qmfb->ops->getnumchans)(qmfb);}int jpc_qmfb1d_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters){	return (*qmfb->ops->getanalfilters)(qmfb, len, filters);}int jpc_qmfb1d_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters){	return (*qmfb->ops->getsynfilters)(qmfb, len, filters);}void jpc_qmfb1d_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x){	(*qmfb->ops->analyze)(qmfb, flags, x);}void jpc_qmfb1d_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x){	(*qmfb->ops->synthesize)(qmfb, flags, x);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -