📄 jpc_qmfb.c
字号:
while (n-- > 0) {
dstptr2 = dstptr;
srcptr2 = srcptr;
for (i = 0; i < numcols; ++i) {
*dstptr2 = *srcptr2;
++dstptr2;
++srcptr2;
}
dstptr += numcols;
srcptr += stride << 1;
}
/* Copy the appropriate samples into the lowpass channel. */
dstptr = &a[(1 - parity) * stride];
srcptr = &a[(2 - parity) * stride];
n = numrows - m - (!parity);
while (n-- > 0) {
dstptr2 = dstptr;
srcptr2 = srcptr;
for (i = 0; i < numcols; ++i) {
*dstptr2 = *srcptr2;
++dstptr2;
++srcptr2;
}
dstptr += stride;
srcptr += stride << 1;
}
/* Copy the saved samples into the highpass channel. */
dstptr = &a[hstartcol * stride];
srcptr = buf;
n = m;
while (n-- > 0) {
dstptr2 = dstptr;
srcptr2 = srcptr;
for (i = 0; i < numcols; ++i) {
*dstptr2 = *srcptr2;
++dstptr2;
++srcptr2;
}
dstptr += stride;
srcptr += numcols;
}
}
#if !defined(HAVE_VLA)
/* If the split buffer was allocated on the heap, free this memory. */
if (buf != splitbuf) {
jas_free(buf);
}
#endif
}
void jpc_qmfb_join_row(jpc_fix_t *a, int numcols, int parity)
{
int bufsize = JPC_CEILDIVPOW2(numcols, 1);
#if !defined(HAVE_VLA)
jpc_fix_t joinbuf[QMFB_JOINBUFSIZE];
#else
jpc_fix_t joinbuf[bufsize];
#endif
jpc_fix_t *buf = joinbuf;
register jpc_fix_t *srcptr;
register jpc_fix_t *dstptr;
register int n;
int hstartcol;
#if !defined(HAVE_VLA)
/* Allocate memory for the join buffer from the heap. */
if (bufsize > QMFB_JOINBUFSIZE) {
if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
/* We have no choice but to commit suicide. */
abort();
}
}
#endif
hstartcol = (numcols + 1 - parity) >> 1;
/* Save the samples from the lowpass channel. */
n = hstartcol;
srcptr = &a[0];
dstptr = buf;
while (n-- > 0) {
*dstptr = *srcptr;
++srcptr;
++dstptr;
}
/* Copy the samples from the highpass channel into place. */
srcptr = &a[hstartcol];
dstptr = &a[1 - parity];
n = numcols - hstartcol;
while (n-- > 0) {
*dstptr = *srcptr;
dstptr += 2;
++srcptr;
}
/* Copy the samples from the lowpass channel into place. */
srcptr = buf;
dstptr = &a[parity];
n = hstartcol;
while (n-- > 0) {
*dstptr = *srcptr;
dstptr += 2;
++srcptr;
}
#if !defined(HAVE_VLA)
/* If the join buffer was allocated on the heap, free this memory. */
if (buf != joinbuf) {
jas_free(buf);
}
#endif
}
void jpc_qmfb_join_col(jpc_fix_t *a, int numrows, int stride,
int parity)
{
int bufsize = JPC_CEILDIVPOW2(numrows, 1);
#if !defined(HAVE_VLA)
jpc_fix_t joinbuf[QMFB_JOINBUFSIZE];
#else
jpc_fix_t joinbuf[bufsize];
#endif
jpc_fix_t *buf = joinbuf;
register jpc_fix_t *srcptr;
register jpc_fix_t *dstptr;
register int n;
int hstartcol;
#if !defined(HAVE_VLA)
/* Allocate memory for the join buffer from the heap. */
if (bufsize > QMFB_JOINBUFSIZE) {
if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
/* We have no choice but to commit suicide. */
abort();
}
}
#endif
hstartcol = (numrows + 1 - parity) >> 1;
/* Save the samples from the lowpass channel. */
n = hstartcol;
srcptr = &a[0];
dstptr = buf;
while (n-- > 0) {
*dstptr = *srcptr;
srcptr += stride;
++dstptr;
}
/* Copy the samples from the highpass channel into place. */
srcptr = &a[hstartcol * stride];
dstptr = &a[(1 - parity) * stride];
n = numrows - hstartcol;
while (n-- > 0) {
*dstptr = *srcptr;
dstptr += 2 * stride;
srcptr += stride;
}
/* Copy the samples from the lowpass channel into place. */
srcptr = buf;
dstptr = &a[parity * stride];
n = hstartcol;
while (n-- > 0) {
*dstptr = *srcptr;
dstptr += 2 * stride;
++srcptr;
}
#if !defined(HAVE_VLA)
/* If the join buffer was allocated on the heap, free this memory. */
if (buf != joinbuf) {
jas_free(buf);
}
#endif
}
void jpc_qmfb_join_colgrp(jpc_fix_t *a, int numrows, int stride,
int parity)
{
int bufsize = JPC_CEILDIVPOW2(numrows, 1);
#if !defined(HAVE_VLA)
jpc_fix_t joinbuf[QMFB_JOINBUFSIZE * JPC_QMFB_COLGRPSIZE];
#else
jpc_fix_t joinbuf[bufsize * JPC_QMFB_COLGRPSIZE];
#endif
jpc_fix_t *buf = joinbuf;
jpc_fix_t *srcptr;
jpc_fix_t *dstptr;
register jpc_fix_t *srcptr2;
register jpc_fix_t *dstptr2;
register int n;
register int i;
int hstartcol;
#if !defined(HAVE_VLA)
/* Allocate memory for the join buffer from the heap. */
if (bufsize > QMFB_JOINBUFSIZE) {
if (!(buf = jas_malloc(bufsize * JPC_QMFB_COLGRPSIZE * sizeof(jpc_fix_t)))) {
/* We have no choice but to commit suicide. */
abort();
}
}
#endif
hstartcol = (numrows + 1 - parity) >> 1;
/* Save the samples from the lowpass channel. */
n = hstartcol;
srcptr = &a[0];
dstptr = buf;
while (n-- > 0) {
dstptr2 = dstptr;
srcptr2 = srcptr;
for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
*dstptr2 = *srcptr2;
++dstptr2;
++srcptr2;
}
srcptr += stride;
dstptr += JPC_QMFB_COLGRPSIZE;
}
/* Copy the samples from the highpass channel into place. */
srcptr = &a[hstartcol * stride];
dstptr = &a[(1 - parity) * stride];
n = numrows - hstartcol;
while (n-- > 0) {
dstptr2 = dstptr;
srcptr2 = srcptr;
for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
*dstptr2 = *srcptr2;
++dstptr2;
++srcptr2;
}
dstptr += 2 * stride;
srcptr += stride;
}
/* Copy the samples from the lowpass channel into place. */
srcptr = buf;
dstptr = &a[parity * stride];
n = hstartcol;
while (n-- > 0) {
dstptr2 = dstptr;
srcptr2 = srcptr;
for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
*dstptr2 = *srcptr2;
++dstptr2;
++srcptr2;
}
dstptr += 2 * stride;
srcptr += JPC_QMFB_COLGRPSIZE;
}
#if !defined(HAVE_VLA)
/* If the join buffer was allocated on the heap, free this memory. */
if (buf != joinbuf) {
jas_free(buf);
}
#endif
}
void jpc_qmfb_join_colres(jpc_fix_t *a, int numrows, int numcols,
int stride, int parity)
{
int bufsize = JPC_CEILDIVPOW2(numrows, 1);
#if !defined(HAVE_VLA)
jpc_fix_t joinbuf[QMFB_JOINBUFSIZE * JPC_QMFB_COLGRPSIZE];
#else
jpc_fix_t joinbuf[bufsize * numcols];
#endif
jpc_fix_t *buf = joinbuf;
jpc_fix_t *srcptr;
jpc_fix_t *dstptr;
register jpc_fix_t *srcptr2;
register jpc_fix_t *dstptr2;
register int n;
register int i;
int hstartcol;
#if !defined(HAVE_VLA)
/* Allocate memory for the join buffer from the heap. */
if (bufsize > QMFB_JOINBUFSIZE) {
if (!(buf = jas_malloc(bufsize * numcols * sizeof(jpc_fix_t)))) {
/* We have no choice but to commit suicide. */
abort();
}
}
#endif
hstartcol = (numrows + 1 - parity) >> 1;
/* Save the samples from the lowpass channel. */
n = hstartcol;
srcptr = &a[0];
dstptr = buf;
while (n-- > 0) {
dstptr2 = dstptr;
srcptr2 = srcptr;
for (i = 0; i < numcols; ++i) {
*dstptr2 = *srcptr2;
++dstptr2;
++srcptr2;
}
srcptr += stride;
dstptr += numcols;
}
/* Copy the samples from the highpass channel into place. */
srcptr = &a[hstartcol * stride];
dstptr = &a[(1 - parity) * stride];
n = numrows - hstartcol;
while (n-- > 0) {
dstptr2 = dstptr;
srcptr2 = srcptr;
for (i = 0; i < numcols; ++i) {
*dstptr2 = *srcptr2;
++dstptr2;
++srcptr2;
}
dstptr += 2 * stride;
srcptr += stride;
}
/* Copy the samples from the lowpass channel into place. */
srcptr = buf;
dstptr = &a[parity * stride];
n = hstartcol;
while (n-- > 0) {
dstptr2 = dstptr;
srcptr2 = srcptr;
for (i = 0; i < numcols; ++i) {
*dstptr2 = *srcptr2;
++dstptr2;
++srcptr2;
}
dstptr += 2 * stride;
srcptr += numcols;
}
#if !defined(HAVE_VLA)
/* If the join buffer was allocated on the heap, free this memory. */
if (buf != joinbuf) {
jas_free(buf);
}
#endif
}
/******************************************************************************\
* 5/3 transform
\******************************************************************************/
void jpc_ft_fwdlift_row(jpc_fix_t *a, int numcols, int parity)
{
register jpc_fix_t *lptr;
register jpc_fix_t *hptr;
register int n;
int llen;
llen = (numcols + 1 - parity) >> 1;
if (numcols > 1) {
/* Apply the first lifting step. */
lptr = &a[0];
hptr = &a[llen];
if (parity) {
hptr[0] -= lptr[0];
++hptr;
}
n = numcols - llen - parity - (parity == (numcols & 1));
while (n-- > 0) {
hptr[0] -= (lptr[0] + lptr[1]) >> 1;
++hptr;
++lptr;
}
if (parity == (numcols & 1)) {
hptr[0] -= lptr[0];
}
/* Apply the second lifting step. */
lptr = &a[0];
hptr = &a[llen];
if (!parity) {
lptr[0] += (hptr[0] + 1) >> 1;
++lptr;
}
n = llen - (!parity) - (parity != (numcols & 1));
while (n-- > 0) {
lptr[0] += (hptr[0] + hptr[1] + 2) >> 2;
++lptr;
++hptr;
}
if (parity != (numcols & 1)) {
lptr[0] += (hptr[0] + 1) >> 1;
}
} else {
if (parity) {
lptr = &a[0];
lptr[0] <<= 1;
}
}
}
void jpc_ft_fwdlift_col(jpc_fix_t *a, int numrows, int stride, int parity)
{
jpc_fix_t *lptr;
jpc_fix_t *hptr;
#if 0
register jpc_fix_t *lptr2;
register jpc_fix_t *hptr2;
register int i;
#endif
register int n;
int llen;
llen = (numrows + 1 - parity) >> 1;
if (numrows > 1) {
/* Apply the first lifting step. */
lptr = &a[0];
hptr = &a[llen * stride];
if (parity) {
hptr[0] -= lptr[0];
hptr += stride;
}
n = numrows - llen - parity - (parity == (numrows & 1));
while (n-- > 0) {
hptr[0] -= (lptr[0] + lptr[stride]) >> 1;
hptr += stride;
lptr += stride;
}
if (parity == (numrows & 1)) {
hptr[0] -= lptr[0];
}
/* Apply the second lifting step. */
lptr = &a[0];
hptr = &a[llen * stride];
if (!parity) {
lptr[0] += (hptr[0] + 1) >> 1;
lptr += stride;
}
n = llen - (!parity) - (parity != (numrows & 1));
while (n-- > 0) {
lptr[0] += (hptr[0] + hptr[stride] + 2) >> 2;
lptr += stride;
hptr += stride;
}
if (parity != (numrows & 1)) {
lptr[0] += (hptr[0] + 1) >> 1;
}
} else {
if (parity) {
lptr = &a[0];
lptr[0] <<= 1;
}
}
}
void jpc_ft_fwdlift_colgrp(jpc_fix_t *a, int numrows, int stride, int parity)
{
jpc_fix_t *lptr;
jpc_fix_t *hptr;
register jpc_fix_t *lptr2;
register jpc_fix_t *hptr2;
register int n;
register int i;
int llen;
llen = (numrows + 1 - parity) >> 1;
if (numrows > 1) {
/* Apply the first lifting step. */
lptr = &a[0];
hptr = &a[llen * stride];
if (parity) {
lptr2 = lptr;
hptr2 = hptr;
for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
hptr2[0] -= lptr2[0];
++hptr2;
++lptr2;
}
hptr += stride;
}
n = numrows - llen - parity - (parity == (numrows & 1));
while (n-- > 0) {
lptr2 = lptr;
hptr2 = hptr;
for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
hptr2[0] -= (lptr2[0] + lptr2[stride]) >> 1;
++lptr2;
++hptr2;
}
hptr += stride;
lptr += stride;
}
if (parity == (numrows & 1)) {
lptr2 = lptr;
hptr2 = hptr;
for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
hptr2[0] -= lptr2[0];
++lptr2;
++hptr2;
}
}
/* Apply the second lifting step. */
lptr = &a[0];
hptr = &a[llen * stride];
if (!parity) {
lptr2 = lptr;
hptr2 = hptr;
for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
lptr2[0] += (hptr2[0] + 1) >> 1;
++lptr2;
++hptr2;
}
lptr += stride;
}
n = llen - (!parity) - (parity != (numrows & 1));
while (n-- > 0) {
lptr2 = lptr;
hptr2 = hptr;
for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
lptr2[0] += (hptr2[0] + hptr2[stride] + 2) >> 2;
++lptr2;
++hptr2;
}
lptr += stride;
hptr += stride;
}
if (parity != (numrows & 1)) {
lptr2 = lptr;
hptr2 = hptr;
for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
lptr2[0] += (hptr2[0] + 1) >> 1;
++lptr2;
++hptr2;
}
}
} else {
if (parity) {
lptr2 = &a[0];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -