diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-05-26 22:40:25 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-05-27 02:27:56 +0200 |
commit | 53ec1c811e41807a296934eb142f4aebe787e390 (patch) | |
tree | d6bb422791fa17efc0160d80806d3eb67a9fb7b9 | |
parent | e5c7bafb4444763bcc8b9b4e2fb4acbd2a7dd2e9 (diff) | |
download | ffmpeg-streaming-53ec1c811e41807a296934eb142f4aebe787e390.zip ffmpeg-streaming-53ec1c811e41807a296934eb142f4aebe787e390.tar.gz |
j2k: merge cosmetics and non functional changes from jpeg2000
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavcodec/j2k.c | 39 | ||||
-rw-r--r-- | libavcodec/j2k.h | 31 | ||||
-rw-r--r-- | libavcodec/j2kdec.c | 162 |
3 files changed, 138 insertions, 94 deletions
diff --git a/libavcodec/j2k.c b/libavcodec/j2k.c index c779480..cd6152c 100644 --- a/libavcodec/j2k.c +++ b/libavcodec/j2k.c @@ -114,7 +114,7 @@ static int getsigctxno(int flag, int bandno) if (v == 1) return 3; if (d >= 2) return 2; if (d == 1) return 1; - } else{ + } else { if (d >= 3) return 8; if (d == 2) { if (h+v >= 1) return 7; @@ -172,7 +172,10 @@ void ff_j2k_set_significant(Jpeg2000T1Context *t1, int x, int y, t1->flags[y - 1][x - 1] |= JPEG2000_T1_SIG_SE; } -int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int cbps, int dx, int dy) +int ff_j2k_init_component(Jpeg2000Component *comp, + Jpeg2000CodingStyle *codsty, + Jpeg2000QuantStyle *qntsty, + int cbps, int dx, int dy) { uint8_t log2_band_prec_width, log2_band_prec_height; int reslevelno, bandno, gbandno = 0, ret, i, j, csize = 1; @@ -182,16 +185,20 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, for (i = 0; i < 2; i++) csize *= comp->coord[i][1] - comp->coord[i][0]; - comp->data = av_malloc_array(csize, sizeof(int)); + comp->data = av_malloc_array(csize, sizeof(*comp->data)); if (!comp->data) return AVERROR(ENOMEM); comp->reslevel = av_malloc_array(codsty->nreslevels, sizeof(*comp->reslevel)); if (!comp->reslevel) return AVERROR(ENOMEM); + /* LOOP on resolution levels */ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) { - int declvl = codsty->nreslevels - reslevelno; + int declvl = codsty->nreslevels - reslevelno; // N_L -r see ISO/IEC 15444-1:2002 B.5 Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno; + /* Compute borders for each resolution level. + * Computation of trx_0, trx_1, try_0 and try_1. + * see ISO/IEC 15444-1:2002 eq. B.5 and B-14 */ for (i = 0; i < 2; i++) for (j = 0; j < 2; j++) reslevel->coord[i][j] = @@ -200,22 +207,34 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, reslevel->log2_prec_width = codsty->log2_prec_widths[reslevelno]; reslevel->log2_prec_height = codsty->log2_prec_heights[reslevelno]; + /* Number of bands for each resolution level */ if (reslevelno == 0) reslevel->nbands = 1; else reslevel->nbands = 3; + /* Number of precincts wich span the tile for resolution level reslevelno + * see B.6 in ISO/IEC 15444-1:2002 eq. B-16 + * num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -| - (trx_0 / 2 ^ log2_prec_width) + * num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| - (try_0 / 2 ^ log2_prec_width) + * for Dcinema profiles in JPEG 2000 + * num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -| + * num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| */ if (reslevel->coord[0][1] == reslevel->coord[0][0]) reslevel->num_precincts_x = 0; else - reslevel->num_precincts_x = ff_jpeg2000_ceildivpow2(reslevel->coord[0][1], reslevel->log2_prec_width) - - (reslevel->coord[0][0] >> reslevel->log2_prec_width); + reslevel->num_precincts_x = + ff_jpeg2000_ceildivpow2(reslevel->coord[0][1], + reslevel->log2_prec_width) - + (reslevel->coord[0][0] >> reslevel->log2_prec_width); if (reslevel->coord[1][1] == reslevel->coord[1][0]) reslevel->num_precincts_y = 0; else - reslevel->num_precincts_y = ff_jpeg2000_ceildivpow2(reslevel->coord[1][1], reslevel->log2_prec_height) - - (reslevel->coord[1][0] >> reslevel->log2_prec_height); + reslevel->num_precincts_y = + ff_jpeg2000_ceildivpow2(reslevel->coord[1][1], + reslevel->log2_prec_height) - + (reslevel->coord[1][0] >> reslevel->log2_prec_height); reslevel->band = av_malloc_array(reslevel->nbands, sizeof(*reslevel->band)); if (!reslevel->band) @@ -252,7 +271,7 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, reslevel->log2_prec_width); band->log2_cblk_height = FFMIN(codsty->log2_cblk_height, reslevel->log2_prec_height); - } else{ + } else { /* 3 bands x0_b = 1 y0_b = 0; x0_b = 0 y0_b = 1; x0_b = y0_b = 1 */ /* x0_b and y0_b are computed with ((bandno + 1 >> i) & 1) */ for (i = 0; i < 2; i++) @@ -376,7 +395,7 @@ void ff_j2k_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty) for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) { Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno; - for (bandno = 0; bandno < reslevel->nbands ; bandno++) { + for (bandno = 0; bandno < reslevel->nbands; bandno++) { Jpeg2000Band *band = reslevel->band + bandno; for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++) { Jpeg2000Prec *prec = band->prec + precno; diff --git a/libavcodec/j2k.h b/libavcodec/j2k.h index c395945..5c6b1d3 100644 --- a/libavcodec/j2k.h +++ b/libavcodec/j2k.h @@ -24,11 +24,14 @@ #define AVCODEC_J2K_H /** - * JPEG2000 tables * @file - * @author Kamil Nowosad + * JPEG 2000 structures and defines common + * to encoder and decoder */ +#include <stdint.h> + +#include "avcodec.h" #include "mqc.h" #include "j2k_dwt.h" @@ -114,7 +117,7 @@ enum Jpeg2000Quantsty { // quantization style typedef struct Jpeg2000T1Context { int data[JPEG2000_MAX_CBLKW][JPEG2000_MAX_CBLKH]; - int flags[JPEG2000_MAX_CBLKW+2][JPEG2000_MAX_CBLKH+2]; + int flags[JPEG2000_MAX_CBLKW + 2][JPEG2000_MAX_CBLKH + 2]; MqcState mqc; } Jpeg2000T1Context; @@ -139,10 +142,10 @@ typedef struct Jpeg2000CodingStyle { } Jpeg2000CodingStyle; typedef struct Jpeg2000QuantStyle { - uint8_t expn[32 * 3]; // quantization exponent + uint8_t expn[32 * 3]; // quantization exponent uint16_t mant[32 * 3]; // quantization mantissa - uint8_t quantsty; // quantization style - uint8_t nguardbits; // number of guard bits + uint8_t quantsty; // quantization style + uint8_t nguardbits; // number of guard bits } Jpeg2000QuantStyle; typedef struct Jpeg2000Pass { @@ -150,7 +153,7 @@ typedef struct Jpeg2000Pass { int64_t disto; } Jpeg2000Pass; -typedef struct Jpeg2000Cblk { +typedef struct Jpeg2000Cblk { uint8_t npasses; uint8_t ninclpasses; // number coding of passes included in codestream uint8_t nonzerobits; @@ -179,7 +182,7 @@ typedef struct Jpeg2000Band { typedef struct Jpeg2000ResLevel { uint8_t nbands; - uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} + uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} uint16_t num_precincts_x, num_precincts_y; // number of precincts in x/y direction uint8_t log2_prec_width, log2_prec_height; // exponent of precinct size Jpeg2000Band *band; @@ -189,7 +192,7 @@ typedef struct Jpeg2000Component { Jpeg2000ResLevel *reslevel; DWTContext dwt; int *data; - uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} + uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} } Jpeg2000Component; /* misc tools */ @@ -207,9 +210,14 @@ static inline int ff_jpeg2000_ceildiv(int a, int b) Jpeg2000TgtNode *ff_j2k_tag_tree_init(int w, int h); /* TIER-1 routines */ + +/* Set up lookup tables used in TIER-1. */ void ff_jpeg2000_init_tier1_luts(void); -void ff_j2k_set_significant(Jpeg2000T1Context *t1, int x, int y, int negative); +/* Update significance of a coefficient at current position (x,y) and + * for neighbors. */ +void ff_j2k_set_significant(Jpeg2000T1Context *t1, + int x, int y, int negative); extern uint8_t ff_jpeg2000_sigctxno_lut[256][4]; @@ -220,11 +228,12 @@ static inline int ff_jpeg2000_getsigctxno(int flag, int bandno) return ff_jpeg2000_sigctxno_lut[flag & 255][bandno]; } +static const uint8_t refctxno_lut[2][2] = { { 14, 15 }, { 16, 16 } }; + /* Get context label (number in range[14..16]) of a coefficient for magnitude * refinement pass. */ static inline int ff_jpeg2000_getrefctxno(int flag) { - static const uint8_t refctxno_lut[2][2] = { { 14, 15 }, { 16, 16 } }; return refctxno_lut[(flag >> 14) & 1][(flag & 255) != 0]; } diff --git a/libavcodec/j2kdec.c b/libavcodec/j2kdec.c index a368a64..2193539 100644 --- a/libavcodec/j2kdec.c +++ b/libavcodec/j2kdec.c @@ -41,10 +41,10 @@ #define HAD_QCC 0x02 typedef struct Jpeg2000Tile { - Jpeg2000Component *comp; - uint8_t properties[4]; - Jpeg2000CodingStyle codsty[4]; - Jpeg2000QuantStyle qntsty[4]; + Jpeg2000Component *comp; + uint8_t properties[4]; + Jpeg2000CodingStyle codsty[4]; + Jpeg2000QuantStyle qntsty[4]; } Jpeg2000Tile; typedef struct Jpeg2000DecoderContext { @@ -98,8 +98,9 @@ static void j2k_flush(Jpeg2000DecoderContext *s) s->bit_index = 8; } -/** decode the value stored in node */ -static int tag_tree_decode(Jpeg2000DecoderContext *s, Jpeg2000TgtNode *node, int threshold) +/* decode the value stored in node */ +static int tag_tree_decode(Jpeg2000DecoderContext *s, Jpeg2000TgtNode *node, + int threshold) { Jpeg2000TgtNode *stack[30]; int sp = -1, curval = 0; @@ -109,7 +110,7 @@ static int tag_tree_decode(Jpeg2000DecoderContext *s, Jpeg2000TgtNode *node, int while (node && !node->vis) { stack[++sp] = node; - node = node->parent; + node = node->parent; } if (node) @@ -169,27 +170,27 @@ static int get_siz(Jpeg2000DecoderContext *s) for (i = 0; i < s->ncomponents; i++) { // Ssiz_i XRsiz_i, YRsiz_i uint8_t x = bytestream2_get_byteu(&s->g); - s->cbps[i] = (x & 0x7f) + 1; + s->cbps[i] = (x & 0x7f) + 1; s->precision = FFMAX(s->cbps[i], s->precision); s->sgnd[i] = !!(x & 0x80); s->cdx[i] = bytestream2_get_byteu(&s->g); s->cdy[i] = bytestream2_get_byteu(&s->g); } - s->numXtiles = ff_jpeg2000_ceildiv(s->width - s->tile_offset_x, s->tile_width); + s->numXtiles = ff_jpeg2000_ceildiv(s->width - s->tile_offset_x, s->tile_width); s->numYtiles = ff_jpeg2000_ceildiv(s->height - s->tile_offset_y, s->tile_height); if (s->numXtiles * (uint64_t)s->numYtiles > INT_MAX/sizeof(Jpeg2000Tile)) return AVERROR(EINVAL); - s->tile = av_mallocz(s->numXtiles * s->numYtiles * sizeof(Jpeg2000Tile)); + s->tile = av_mallocz(s->numXtiles * s->numYtiles * sizeof(*s->tile)); if (!s->tile) return AVERROR(ENOMEM); for (i = 0; i < s->numXtiles * s->numYtiles; i++) { Jpeg2000Tile *tile = s->tile + i; - tile->comp = av_mallocz(s->ncomponents * sizeof(Jpeg2000Component)); + tile->comp = av_mallocz(s->ncomponents * sizeof(*tile->comp)); if (!tile->comp) return AVERROR(ENOMEM); } @@ -227,7 +228,7 @@ static int get_siz(Jpeg2000DecoderContext *s) return 0; } -/** get common part for COD and COC segments */ +/* get common part for COD and COC segments */ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c) { uint8_t byte; @@ -268,8 +269,9 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c) return 0; } -/** get coding parameters for a particular tile or whole image*/ -static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *properties) +/* get coding parameters for a particular tile or whole image*/ +static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, + uint8_t *properties) { Jpeg2000CodingStyle tmp; int compno; @@ -286,18 +288,19 @@ static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *p } tmp.nlayers = bytestream2_get_be16u(&s->g); - tmp.mct = bytestream2_get_byteu(&s->g); // multiple component transformation + tmp.mct = bytestream2_get_byteu(&s->g); // multiple component transformation get_cox(s, &tmp); - for (compno = 0; compno < s->ncomponents; compno++) { + for (compno = 0; compno < s->ncomponents; compno++) if (!(properties[compno] & HAD_COC)) - memcpy(c + compno, &tmp, sizeof(Jpeg2000CodingStyle)); - } + memcpy(c + compno, &tmp, sizeof(tmp)); return 0; } -/** get coding parameters for a component in the whole image on a particular tile */ -static int get_coc(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *properties) +/* Get coding parameters for a component in the whole image or a + * particular tile. */ +static int get_coc(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, + uint8_t *properties) { int compno; @@ -314,7 +317,7 @@ static int get_coc(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *p return 0; } -/** get common part for QCD and QCC segments */ +/* Get common part for QCD and QCC segments. */ static int get_qcx(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q) { int i, x; @@ -325,7 +328,7 @@ static int get_qcx(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q) x = bytestream2_get_byteu(&s->g); // Sqcd q->nguardbits = x >> 5; - q->quantsty = x & 0x1f; + q->quantsty = x & 0x1f; if (q->quantsty == JPEG2000_QSTY_NONE) { n -= 3; @@ -336,20 +339,20 @@ static int get_qcx(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q) } else if (q->quantsty == JPEG2000_QSTY_SI) { if (bytestream2_get_bytes_left(&s->g) < 2) return AVERROR(EINVAL); - x = bytestream2_get_be16u(&s->g); + x = bytestream2_get_be16u(&s->g); q->expn[0] = x >> 11; q->mant[0] = x & 0x7ff; for (i = 1; i < 32 * 3; i++) { - int curexpn = FFMAX(0, q->expn[0] - (i-1)/3); + int curexpn = FFMAX(0, q->expn[0] - (i - 1) / 3); q->expn[i] = curexpn; q->mant[i] = q->mant[0]; } - } else{ + } else { n = (n - 3) >> 1; if (bytestream2_get_bytes_left(&s->g) < 2 * n || 32*3 < n) return AVERROR(EINVAL); for (i = 0; i < n; i++) { - x = bytestream2_get_be16u(&s->g); + x = bytestream2_get_be16u(&s->g); q->expn[i] = x >> 11; q->mant[i] = x & 0x7ff; } @@ -357,8 +360,9 @@ static int get_qcx(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q) return 0; } -/** get quantization parameters for a particular tile or a whole image */ -static int get_qcd(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, uint8_t *properties) +/* Get quantization parameters for a particular tile or a whole image. */ +static int get_qcd(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, + uint8_t *properties) { Jpeg2000QuantStyle tmp; int compno; @@ -371,17 +375,19 @@ static int get_qcd(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, uint return 0; } -/** get quantization parameters for a component in the whole image on in a particular tile */ -static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, uint8_t *properties) +/* Get quantization parameters for a component in the whole image + * on in a particular tile. */ +static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, + uint8_t *properties) { int compno; if (bytestream2_get_bytes_left(&s->g) < 1) return AVERROR(EINVAL); - compno = bytestream2_get_byteu(&s->g); + compno = bytestream2_get_byteu(&s->g); properties[compno] |= HAD_QCC; - return get_qcx(s, n-1, q+compno); + return get_qcx(s, n - 1, q + compno); } /** get start of tile segment */ @@ -412,9 +418,9 @@ static int get_sot(Jpeg2000DecoderContext *s) static int init_tile(Jpeg2000DecoderContext *s, int tileno) { - int compno, - tilex = tileno % s->numXtiles, - tiley = tileno / s->numXtiles; + int compno; + int tilex = tileno % s->numXtiles; + int tiley = tileno / s->numXtiles; Jpeg2000Tile *tile = s->tile + tileno; if (!tile->comp) @@ -479,8 +485,8 @@ static int decode_packet(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty, Jpeg2000Prec *prec = band->prec + precno; int pos = 0; - if (band->coord[0][0] == band->coord[0][1] - || band->coord[1][0] == band->coord[1][1]) + if (band->coord[0][0] == band->coord[0][1] || + band->coord[1][0] == band->coord[1][1]) continue; for (cblkny = prec->yi0; cblkny < prec->yi1; cblkny++) @@ -590,12 +596,13 @@ static void decode_sigpass(Jpeg2000T1Context *t1, int width, int height, int bpn ff_j2k_set_significant(t1, x, y, t1->data[y][x] < 0); } - t1->flags[y+1][x+1] |= JPEG2000_T1_VIS; + t1->flags[y + 1][x + 1] |= JPEG2000_T1_VIS; } } } -static void decode_refpass(Jpeg2000T1Context *t1, int width, int height, int bpno) +static void decode_refpass(Jpeg2000T1Context *t1, int width, int height, + int bpno) { int phalf, nhalf; int y0, x, y; @@ -605,14 +612,15 @@ static void decode_refpass(Jpeg2000T1Context *t1, int width, int height, int bpn for (y0 = 0; y0 < height; y0 += 4) for (x = 0; x < width; x++) - for (y = y0; y < height && y < y0+4; y++) { - if ((t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS)) == JPEG2000_T1_SIG) { - int ctxno = ff_jpeg2000_getrefctxno(t1->flags[y+1][x+1]); - int r = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? phalf : nhalf; - t1->data[y][x] += t1->data[y][x] < 0 ? -r : r; - t1->flags[y+1][x+1] |= JPEG2000_T1_REF; + for (y = y0; y < height && y < y0 + 4; y++) + if ((t1->flags[y + 1][x + 1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS)) == JPEG2000_T1_SIG) { + int ctxno = ff_jpeg2000_getrefctxno(t1->flags[y + 1][x + 1]); + int r = ff_mqc_decode(&t1->mqc, + t1->mqc.cx_states + ctxno) + ? phalf : nhalf; + t1->data[y][x] += t1->data[y][x] < 0 ? -r : r; + t1->flags[y + 1][x + 1] |= JPEG2000_T1_REF; } - } } static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int width, int height, @@ -622,19 +630,22 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int for (y0 = 0; y0 < height; y0 += 4) { for (x = 0; x < width; x++) { - if (y0 + 3 < height && !( - (t1->flags[y0+1][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) || - (t1->flags[y0+2][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) || - (t1->flags[y0+3][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) || - (t1->flags[y0+4][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)))) { + if (y0 + 3 < height && + !((t1->flags[y0 + 1][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) || + (t1->flags[y0 + 2][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) || + (t1->flags[y0 + 3][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) || + (t1->flags[y0 + 4][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)))) { if (!ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_RL)) continue; - runlen = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI); - runlen = (runlen << 1) | ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI); + runlen = ff_mqc_decode(&t1->mqc, + t1->mqc.cx_states + MQC_CX_UNI); + runlen = (runlen << 1) | ff_mqc_decode(&t1->mqc, + t1->mqc.cx_states + + MQC_CX_UNI); dec = 1; - } else{ + } else { runlen = 0; - dec = 0; + dec = 0; } for (y = y0 + runlen; y < y0 + 4 && y < height; y++) { @@ -648,12 +659,17 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int } } if (dec) { - int xorbit, ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y+1][x+1], &xorbit); - t1->data[y][x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ? -mask : mask; + int xorbit; + int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y + 1][x + 1], + &xorbit); + t1->data[y][x] = (ff_mqc_decode(&t1->mqc, + t1->mqc.cx_states + ctxno) ^ + xorbit) + ? -mask : mask; ff_j2k_set_significant(t1, x, y, t1->data[y][x] < 0); } dec = 0; - t1->flags[y+1][x+1] &= ~JPEG2000_T1_VIS; + t1->flags[y + 1][x + 1] &= ~JPEG2000_T1_VIS; } } } @@ -663,13 +679,14 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI); val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI); val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI); - if (val != 0xa) { - av_log(s->avctx, AV_LOG_ERROR,"Segmentation symbol value incorrect\n"); - } + if (val != 0xa) + av_log(s->avctx, AV_LOG_ERROR, + "Segmentation symbol value incorrect\n"); } } -static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty, Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk, +static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty, + Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk, int width, int height, int bandpos) { int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y, clnpass_cnt = 0; @@ -820,7 +837,7 @@ static int decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile) for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]) { uint8_t *dst; - x = tile->comp[compno].coord[0][0] - s->image_offset_x; + x = tile->comp[compno].coord[0][0] - s->image_offset_x; dst = line + x * s->ncomponents + compno; for (; x < tile->comp[compno].coord[0][1] - s->image_offset_x; x += s->cdx[compno]) { @@ -860,12 +877,12 @@ static int decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile) return 0; } -static void cleanup(Jpeg2000DecoderContext *s) +static void jpeg2000_dec_cleanup(Jpeg2000DecoderContext *s) { int tileno, compno; for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) { for (compno = 0; compno < s->ncomponents; compno++) { - Jpeg2000Component *comp = s->tile[tileno].comp + compno; + Jpeg2000Component *comp = s->tile[tileno].comp + compno; Jpeg2000CodingStyle *codsty = s->tile[tileno].codsty + compno; ff_j2k_cleanup(comp, codsty); @@ -878,8 +895,8 @@ static void cleanup(Jpeg2000DecoderContext *s) static int decode_codestream(Jpeg2000DecoderContext *s) { Jpeg2000CodingStyle *codsty = s->codsty; - Jpeg2000QuantStyle *qntsty = s->qntsty; - uint8_t *properties = s->properties; + Jpeg2000QuantStyle *qntsty = s->qntsty; + uint8_t *properties = s->properties; for (;;) { int oldpos, marker, len, ret = 0; @@ -976,9 +993,8 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s) return 0; } -static int decode_frame(AVCodecContext *avctx, - void *data, int *got_frame, - AVPacket *avpkt) +static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data, + int *got_frame, AVPacket *avpkt) { Jpeg2000DecoderContext *s = avctx->priv_data; AVFrame *picture = data; @@ -1021,14 +1037,14 @@ static int decode_frame(AVCodecContext *avctx, if (ret = decode_tile(s, s->tile + tileno)) goto err_out; - cleanup(s); + jpeg2000_dec_cleanup(s); *got_frame = 1; return bytestream2_tell(&s->g); err_out: - cleanup(s); + jpeg2000_dec_cleanup(s); return ret; } @@ -1054,6 +1070,6 @@ AVCodec ff_j2k_decoder = { .capabilities = CODEC_CAP_EXPERIMENTAL | CODEC_CAP_FRAME_THREADS, .priv_data_size = sizeof(Jpeg2000DecoderContext), .init_static_data = jpeg2000_init_static_data, - .decode = decode_frame, + .decode = jpeg2000_decode_frame, .profiles = NULL_IF_CONFIG_SMALL(profiles) }; |