Algorithmic optimizations in t1.c, thanks to Guido J. !

This commit is contained in:
Francois-Olivier Devaux 2007-02-21 07:57:27 +00:00
parent eac141b69a
commit 7cb2194c8e
2 changed files with 33 additions and 42 deletions

View File

@ -5,6 +5,9 @@ What's New for OpenJPEG
! : changed ! : changed
+ : added + : added
February 21, 2007
+ [FOD] Algorithmic optimizations in t1.c, thanks to Guido J. !
February 19, 2007 February 19, 2007
+ [FOD] Added OPJ_LIMIT_DECODING enabling us to limit the decoding to main header (modified openjpeg.c, openjpeg.h, j2k.c and j2k.h) + [FOD] Added OPJ_LIMIT_DECODING enabling us to limit the decoding to main header (modified openjpeg.c, openjpeg.h, j2k.c and j2k.h)

View File

@ -934,7 +934,6 @@ void t1_destroy(opj_t1_t *t1) {
void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
int compno, resno, bandno, precno, cblkno; int compno, resno, bandno, precno, cblkno;
int x, y, i, j, orient;
tile->distotile = 0; /* fixed_quality */ tile->distotile = 0; /* fixed_quality */
@ -951,38 +950,34 @@ void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
opj_tcd_precinct_t *prc = &band->precincts[precno]; opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
int x, y, w, i, j, orient;
opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
if (band->bandno == 0) { x = cblk->x0 - band->x0;
x = cblk->x0 - band->x0; y = cblk->y0 - band->y0;
y = cblk->y0 - band->y0; if (band->bandno & 1) {
} else if (band->bandno == 1) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0; x += pres->x1 - pres->x0;
y = cblk->y0 - band->y0; }
} else if (band->bandno == 2) { if (band->bandno & 2) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = cblk->x0 - band->x0; y += pres->y1 - pres->y0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
} else { /* if (band->bandno == 3) */
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
} }
w = tilec->x1 - tilec->x0;
if (tcp->tccps[compno].qmfbid == 1) { if (tcp->tccps[compno].qmfbid == 1) {
for (j = 0; j < cblk->y1 - cblk->y0; j++) { for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) { for (i = 0; i < cblk->x1 - cblk->x0; i++) {
t1->data[j][i] = t1->data[j][i] =
tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0)] << T1_NMSEDEC_FRACBITS; tilec->data[(x + i) + (y + j) * w] << T1_NMSEDEC_FRACBITS;
} }
} }
} else if (tcp->tccps[compno].qmfbid == 0) { } else { /* if (tcp->tccps[compno].qmfbid == 0) */
for (j = 0; j < cblk->y1 - cblk->y0; j++) { for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) { for (i = 0; i < cblk->x1 - cblk->x0; i++) {
t1->data[j][i] = t1->data[j][i] =
fix_mul( fix_mul(
tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)], tilec->data[x + i + (y + j) * w],
8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (13 - T1_NMSEDEC_FRACBITS); 8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (13 - T1_NMSEDEC_FRACBITS);
} }
} }
@ -1019,7 +1014,7 @@ void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
opj_tcd_precinct_t *prc = &band->precincts[precno]; opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
int x, y, i, j, orient; int x, y, w, i, j, orient;
opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
orient = band->bandno; /* FIXME */ orient = band->bandno; /* FIXME */
@ -1031,30 +1026,23 @@ void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
t1_decode_cblk(t1, cblk, orient, tcp->tccps[compno].roishift, tcp->tccps[compno].cblksty); t1_decode_cblk(t1, cblk, orient, tcp->tccps[compno].roishift, tcp->tccps[compno].cblksty);
if (band->bandno == 0) { x = cblk->x0 - band->x0;
x = cblk->x0 - band->x0; y = cblk->y0 - band->y0;
y = cblk->y0 - band->y0; if (band->bandno & 1) {
} else if (band->bandno == 1) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0; x += pres->x1 - pres->x0;
y = cblk->y0 - band->y0; }
} else if (band->bandno == 2) { if (band->bandno & 2) {
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = cblk->x0 - band->x0; y += pres->y1 - pres->y0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
} else { /* if (band->bandno == 3) */
opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
} }
if (tcp->tccps[compno].roishift) { if (tcp->tccps[compno].roishift) {
int thresh, val, mag; int thresh = 1 << tcp->tccps[compno].roishift;
thresh = 1 << tcp->tccps[compno].roishift;
for (j = 0; j < cblk->y1 - cblk->y0; j++) { for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) { for (i = 0; i < cblk->x1 - cblk->x0; i++) {
val = t1->data[j][i]; int val = t1->data[j][i];
mag = int_abs(val); int mag = int_abs(val);
if (mag >= thresh) { if (mag >= thresh) {
mag >>= tcp->tccps[compno].roishift; mag >>= tcp->tccps[compno].roishift;
t1->data[j][i] = val < 0 ? -mag : mag; t1->data[j][i] = val < 0 ? -mag : mag;
@ -1063,22 +1051,22 @@ void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
} }
} }
w = tilec->x1 - tilec->x0;
if (tcp->tccps[compno].qmfbid == 1) { if (tcp->tccps[compno].qmfbid == 1) {
for (j = 0; j < cblk->y1 - cblk->y0; j++) { for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) { for (i = 0; i < cblk->x1 - cblk->x0; i++) {
int tmp = t1->data[j][i]; tilec->data[x + i + (y + j) * w] = t1->data[j][i]/2;
tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = tmp/2;
} }
} }
} else { /* if (tcp->tccps[compno].qmfbid == 0) */ } else { /* if (tcp->tccps[compno].qmfbid == 0) */
for (j = 0; j < cblk->y1 - cblk->y0; j++) { for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) { for (i = 0; i < cblk->x1 - cblk->x0; i++) {
double tmp = (double)(t1->data[j][i] * band->stepsize * 4096.0);
if (t1->data[j][i] >> 1 == 0) { if (t1->data[j][i] >> 1 == 0) {
tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = 0; tilec->data[x + i + (y + j) * w] = 0;
} else { } else {
double tmp = (double)((t1->data[j][i] << 12) * band->stepsize);
int tmp2 = ((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2); int tmp2 = ((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2);
tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = ((tmp<0)?-tmp2:tmp2); tilec->data[x + i + (y + j) * w] = ((tmp<0)?-tmp2:tmp2);
} }
} }
} }