Commit 53ec1c81 authored by Michael Niedermayer's avatar Michael Niedermayer

j2k: merge cosmetics and non functional changes from jpeg2000

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent e5c7bafb
...@@ -114,7 +114,7 @@ static int getsigctxno(int flag, int bandno) ...@@ -114,7 +114,7 @@ static int getsigctxno(int flag, int bandno)
if (v == 1) return 3; if (v == 1) return 3;
if (d >= 2) return 2; if (d >= 2) return 2;
if (d == 1) return 1; if (d == 1) return 1;
} else{ } else {
if (d >= 3) return 8; if (d >= 3) return 8;
if (d == 2) { if (d == 2) {
if (h+v >= 1) return 7; if (h+v >= 1) return 7;
...@@ -172,7 +172,10 @@ void ff_j2k_set_significant(Jpeg2000T1Context *t1, int x, int y, ...@@ -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; 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; uint8_t log2_band_prec_width, log2_band_prec_height;
int reslevelno, bandno, gbandno = 0, ret, i, j, csize = 1; int reslevelno, bandno, gbandno = 0, ret, i, j, csize = 1;
...@@ -182,16 +185,20 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, ...@@ -182,16 +185,20 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty,
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
csize *= comp->coord[i][1] - comp->coord[i][0]; 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) if (!comp->data)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
comp->reslevel = av_malloc_array(codsty->nreslevels, sizeof(*comp->reslevel)); comp->reslevel = av_malloc_array(codsty->nreslevels, sizeof(*comp->reslevel));
if (!comp->reslevel) if (!comp->reslevel)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
/* LOOP on resolution levels */
for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) { 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; 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 (i = 0; i < 2; i++)
for (j = 0; j < 2; j++) for (j = 0; j < 2; j++)
reslevel->coord[i][j] = reslevel->coord[i][j] =
...@@ -200,22 +207,34 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, ...@@ -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_width = codsty->log2_prec_widths[reslevelno];
reslevel->log2_prec_height = codsty->log2_prec_heights[reslevelno]; reslevel->log2_prec_height = codsty->log2_prec_heights[reslevelno];
/* Number of bands for each resolution level */
if (reslevelno == 0) if (reslevelno == 0)
reslevel->nbands = 1; reslevel->nbands = 1;
else else
reslevel->nbands = 3; 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]) if (reslevel->coord[0][1] == reslevel->coord[0][0])
reslevel->num_precincts_x = 0; reslevel->num_precincts_x = 0;
else else
reslevel->num_precincts_x = ff_jpeg2000_ceildivpow2(reslevel->coord[0][1], reslevel->log2_prec_width) reslevel->num_precincts_x =
- (reslevel->coord[0][0] >> reslevel->log2_prec_width); 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]) if (reslevel->coord[1][1] == reslevel->coord[1][0])
reslevel->num_precincts_y = 0; reslevel->num_precincts_y = 0;
else else
reslevel->num_precincts_y = ff_jpeg2000_ceildivpow2(reslevel->coord[1][1], reslevel->log2_prec_height) reslevel->num_precincts_y =
- (reslevel->coord[1][0] >> reslevel->log2_prec_height); 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)); reslevel->band = av_malloc_array(reslevel->nbands, sizeof(*reslevel->band));
if (!reslevel->band) if (!reslevel->band)
...@@ -252,7 +271,7 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, ...@@ -252,7 +271,7 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty,
reslevel->log2_prec_width); reslevel->log2_prec_width);
band->log2_cblk_height = FFMIN(codsty->log2_cblk_height, band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
reslevel->log2_prec_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 */ /* 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) */ /* x0_b and y0_b are computed with ((bandno + 1 >> i) & 1) */
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
...@@ -376,7 +395,7 @@ void ff_j2k_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty) ...@@ -376,7 +395,7 @@ void ff_j2k_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) { for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
Jpeg2000ResLevel *reslevel = comp->reslevel + 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; Jpeg2000Band *band = reslevel->band + bandno;
for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++) { for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++) {
Jpeg2000Prec *prec = band->prec + precno; Jpeg2000Prec *prec = band->prec + precno;
......
...@@ -24,11 +24,14 @@ ...@@ -24,11 +24,14 @@
#define AVCODEC_J2K_H #define AVCODEC_J2K_H
/** /**
* JPEG2000 tables
* @file * @file
* @author Kamil Nowosad * JPEG 2000 structures and defines common
* to encoder and decoder
*/ */
#include <stdint.h>
#include "avcodec.h"
#include "mqc.h" #include "mqc.h"
#include "j2k_dwt.h" #include "j2k_dwt.h"
...@@ -114,7 +117,7 @@ enum Jpeg2000Quantsty { // quantization style ...@@ -114,7 +117,7 @@ enum Jpeg2000Quantsty { // quantization style
typedef struct Jpeg2000T1Context { typedef struct Jpeg2000T1Context {
int data[JPEG2000_MAX_CBLKW][JPEG2000_MAX_CBLKH]; 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; MqcState mqc;
} Jpeg2000T1Context; } Jpeg2000T1Context;
...@@ -207,9 +210,14 @@ static inline int ff_jpeg2000_ceildiv(int a, int b) ...@@ -207,9 +210,14 @@ static inline int ff_jpeg2000_ceildiv(int a, int b)
Jpeg2000TgtNode *ff_j2k_tag_tree_init(int w, int h); Jpeg2000TgtNode *ff_j2k_tag_tree_init(int w, int h);
/* TIER-1 routines */ /* TIER-1 routines */
/* Set up lookup tables used in TIER-1. */
void ff_jpeg2000_init_tier1_luts(void); 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]; extern uint8_t ff_jpeg2000_sigctxno_lut[256][4];
...@@ -220,11 +228,12 @@ static inline int ff_jpeg2000_getsigctxno(int flag, int bandno) ...@@ -220,11 +228,12 @@ static inline int ff_jpeg2000_getsigctxno(int flag, int bandno)
return ff_jpeg2000_sigctxno_lut[flag & 255][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 /* Get context label (number in range[14..16]) of a coefficient for magnitude
* refinement pass. */ * refinement pass. */
static inline int ff_jpeg2000_getrefctxno(int flag) 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]; return refctxno_lut[(flag >> 14) & 1][(flag & 255) != 0];
} }
......
...@@ -98,8 +98,9 @@ static void j2k_flush(Jpeg2000DecoderContext *s) ...@@ -98,8 +98,9 @@ static void j2k_flush(Jpeg2000DecoderContext *s)
s->bit_index = 8; s->bit_index = 8;
} }
/** decode the value stored in node */ /* decode the value stored in node */
static int tag_tree_decode(Jpeg2000DecoderContext *s, Jpeg2000TgtNode *node, int threshold) static int tag_tree_decode(Jpeg2000DecoderContext *s, Jpeg2000TgtNode *node,
int threshold)
{ {
Jpeg2000TgtNode *stack[30]; Jpeg2000TgtNode *stack[30];
int sp = -1, curval = 0; int sp = -1, curval = 0;
...@@ -182,14 +183,14 @@ static int get_siz(Jpeg2000DecoderContext *s) ...@@ -182,14 +183,14 @@ static int get_siz(Jpeg2000DecoderContext *s)
if (s->numXtiles * (uint64_t)s->numYtiles > INT_MAX/sizeof(Jpeg2000Tile)) if (s->numXtiles * (uint64_t)s->numYtiles > INT_MAX/sizeof(Jpeg2000Tile))
return AVERROR(EINVAL); 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) if (!s->tile)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
for (i = 0; i < s->numXtiles * s->numYtiles; i++) { for (i = 0; i < s->numXtiles * s->numYtiles; i++) {
Jpeg2000Tile *tile = s->tile + 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) if (!tile->comp)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
...@@ -227,7 +228,7 @@ static int get_siz(Jpeg2000DecoderContext *s) ...@@ -227,7 +228,7 @@ static int get_siz(Jpeg2000DecoderContext *s)
return 0; 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) static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
{ {
uint8_t byte; uint8_t byte;
...@@ -268,8 +269,9 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c) ...@@ -268,8 +269,9 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
return 0; return 0;
} }
/** get coding parameters for a particular tile or whole image*/ /* get coding parameters for a particular tile or whole image*/
static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *properties) static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c,
uint8_t *properties)
{ {
Jpeg2000CodingStyle tmp; Jpeg2000CodingStyle tmp;
int compno; int compno;
...@@ -289,15 +291,16 @@ static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *p ...@@ -289,15 +291,16 @@ static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *p
tmp.mct = bytestream2_get_byteu(&s->g); // multiple component transformation tmp.mct = bytestream2_get_byteu(&s->g); // multiple component transformation
get_cox(s, &tmp); get_cox(s, &tmp);
for (compno = 0; compno < s->ncomponents; compno++) { for (compno = 0; compno < s->ncomponents; compno++)
if (!(properties[compno] & HAD_COC)) if (!(properties[compno] & HAD_COC))
memcpy(c + compno, &tmp, sizeof(Jpeg2000CodingStyle)); memcpy(c + compno, &tmp, sizeof(tmp));
}
return 0; return 0;
} }
/** get coding parameters for a component in the whole image on a particular tile */ /* Get coding parameters for a component in the whole image or a
static int get_coc(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *properties) * particular tile. */
static int get_coc(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c,
uint8_t *properties)
{ {
int compno; int compno;
...@@ -314,7 +317,7 @@ static int get_coc(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *p ...@@ -314,7 +317,7 @@ static int get_coc(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *p
return 0; 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) static int get_qcx(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q)
{ {
int i, x; int i, x;
...@@ -340,11 +343,11 @@ static int get_qcx(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q) ...@@ -340,11 +343,11 @@ static int get_qcx(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q)
q->expn[0] = x >> 11; q->expn[0] = x >> 11;
q->mant[0] = x & 0x7ff; q->mant[0] = x & 0x7ff;
for (i = 1; i < 32 * 3; i++) { 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->expn[i] = curexpn;
q->mant[i] = q->mant[0]; q->mant[i] = q->mant[0];
} }
} else{ } else {
n = (n - 3) >> 1; n = (n - 3) >> 1;
if (bytestream2_get_bytes_left(&s->g) < 2 * n || 32*3 < n) if (bytestream2_get_bytes_left(&s->g) < 2 * n || 32*3 < n)
return AVERROR(EINVAL); return AVERROR(EINVAL);
...@@ -357,8 +360,9 @@ static int get_qcx(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q) ...@@ -357,8 +360,9 @@ static int get_qcx(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q)
return 0; return 0;
} }
/** get quantization parameters for a particular tile or a whole image */ /* Get quantization parameters for a particular tile or a whole image. */
static int get_qcd(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, uint8_t *properties) static int get_qcd(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q,
uint8_t *properties)
{ {
Jpeg2000QuantStyle tmp; Jpeg2000QuantStyle tmp;
int compno; int compno;
...@@ -371,8 +375,10 @@ static int get_qcd(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, uint ...@@ -371,8 +375,10 @@ static int get_qcd(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, uint
return 0; return 0;
} }
/** get quantization parameters for a component in the whole image on in a particular tile */ /* Get quantization parameters for a component in the whole image
static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, uint8_t *properties) * on in a particular tile. */
static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q,
uint8_t *properties)
{ {
int compno; int compno;
...@@ -381,7 +387,7 @@ static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, uint ...@@ -381,7 +387,7 @@ static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, uint
compno = bytestream2_get_byteu(&s->g); compno = bytestream2_get_byteu(&s->g);
properties[compno] |= HAD_QCC; 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 */ /** get start of tile segment */
...@@ -412,9 +418,9 @@ static int get_sot(Jpeg2000DecoderContext *s) ...@@ -412,9 +418,9 @@ static int get_sot(Jpeg2000DecoderContext *s)
static int init_tile(Jpeg2000DecoderContext *s, int tileno) static int init_tile(Jpeg2000DecoderContext *s, int tileno)
{ {
int compno, int compno;
tilex = tileno % s->numXtiles, int tilex = tileno % s->numXtiles;
tiley = tileno / s->numXtiles; int tiley = tileno / s->numXtiles;
Jpeg2000Tile *tile = s->tile + tileno; Jpeg2000Tile *tile = s->tile + tileno;
if (!tile->comp) if (!tile->comp)
...@@ -479,8 +485,8 @@ static int decode_packet(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty, ...@@ -479,8 +485,8 @@ static int decode_packet(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
Jpeg2000Prec *prec = band->prec + precno; Jpeg2000Prec *prec = band->prec + precno;
int pos = 0; int pos = 0;
if (band->coord[0][0] == band->coord[0][1] if (band->coord[0][0] == band->coord[0][1] ||
|| band->coord[1][0] == band->coord[1][1]) band->coord[1][0] == band->coord[1][1])
continue; continue;
for (cblkny = prec->yi0; cblkny < prec->yi1; cblkny++) for (cblkny = prec->yi0; cblkny < prec->yi1; cblkny++)
...@@ -590,12 +596,13 @@ static void decode_sigpass(Jpeg2000T1Context *t1, int width, int height, int bpn ...@@ -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); 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 phalf, nhalf;
int y0, x, y; int y0, x, y;
...@@ -605,13 +612,14 @@ static void decode_refpass(Jpeg2000T1Context *t1, int width, int height, int bpn ...@@ -605,13 +612,14 @@ static void decode_refpass(Jpeg2000T1Context *t1, int width, int height, int bpn
for (y0 = 0; y0 < height; y0 += 4) for (y0 = 0; y0 < height; y0 += 4)
for (x = 0; x < width; x++) for (x = 0; x < width; x++)
for (y = y0; y < height && y < y0+4; y++) { 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) { 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 ctxno = ff_jpeg2000_getrefctxno(t1->flags[y + 1][x + 1]);
int r = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? phalf : nhalf; 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->data[y][x] += t1->data[y][x] < 0 ? -r : r;
t1->flags[y+1][x+1] |= JPEG2000_T1_REF; t1->flags[y + 1][x + 1] |= JPEG2000_T1_REF;
}
} }
} }
...@@ -622,17 +630,20 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int ...@@ -622,17 +630,20 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int
for (y0 = 0; y0 < height; y0 += 4) { for (y0 = 0; y0 < height; y0 += 4) {
for (x = 0; x < width; x++) { for (x = 0; x < width; x++) {
if (y0 + 3 < height && !( if (y0 + 3 < height &&
(t1->flags[y0+1][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) || !((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 + 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 + 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)))) { (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)) if (!ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_RL))
continue; continue;
runlen = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI); runlen = ff_mqc_decode(&t1->mqc,
runlen = (runlen << 1) | ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI); t1->mqc.cx_states + MQC_CX_UNI);
runlen = (runlen << 1) | ff_mqc_decode(&t1->mqc,
t1->mqc.cx_states +
MQC_CX_UNI);
dec = 1; dec = 1;
} else{ } else {
runlen = 0; runlen = 0;
dec = 0; dec = 0;
} }
...@@ -648,12 +659,17 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int ...@@ -648,12 +659,17 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int
} }
} }
if (dec) { if (dec) {
int xorbit, ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y+1][x+1], &xorbit); int xorbit;
t1->data[y][x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ? -mask : mask; 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); ff_j2k_set_significant(t1, x, y, t1->data[y][x] < 0);
} }
dec = 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 ...@@ -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); 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) { if (val != 0xa)
av_log(s->avctx, AV_LOG_ERROR,"Segmentation symbol value incorrect\n"); 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 width, int height, int bandpos)
{ {
int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y, clnpass_cnt = 0; int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y, clnpass_cnt = 0;
...@@ -860,7 +877,7 @@ static int decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile) ...@@ -860,7 +877,7 @@ static int decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
return 0; return 0;
} }
static void cleanup(Jpeg2000DecoderContext *s) static void jpeg2000_dec_cleanup(Jpeg2000DecoderContext *s)
{ {
int tileno, compno; int tileno, compno;
for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) { for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) {
...@@ -976,9 +993,8 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s) ...@@ -976,9 +993,8 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s)
return 0; return 0;
} }
static int decode_frame(AVCodecContext *avctx, static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
void *data, int *got_frame, int *got_frame, AVPacket *avpkt)
AVPacket *avpkt)
{ {
Jpeg2000DecoderContext *s = avctx->priv_data; Jpeg2000DecoderContext *s = avctx->priv_data;
AVFrame *picture = data; AVFrame *picture = data;
...@@ -1021,14 +1037,14 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -1021,14 +1037,14 @@ static int decode_frame(AVCodecContext *avctx,
if (ret = decode_tile(s, s->tile + tileno)) if (ret = decode_tile(s, s->tile + tileno))
goto err_out; goto err_out;
cleanup(s); jpeg2000_dec_cleanup(s);
*got_frame = 1; *got_frame = 1;
return bytestream2_tell(&s->g); return bytestream2_tell(&s->g);
err_out: err_out:
cleanup(s); jpeg2000_dec_cleanup(s);
return ret; return ret;
} }
...@@ -1054,6 +1070,6 @@ AVCodec ff_j2k_decoder = { ...@@ -1054,6 +1070,6 @@ AVCodec ff_j2k_decoder = {
.capabilities = CODEC_CAP_EXPERIMENTAL | CODEC_CAP_FRAME_THREADS, .capabilities = CODEC_CAP_EXPERIMENTAL | CODEC_CAP_FRAME_THREADS,
.priv_data_size = sizeof(Jpeg2000DecoderContext), .priv_data_size = sizeof(Jpeg2000DecoderContext),
.init_static_data = jpeg2000_init_static_data, .init_static_data = jpeg2000_init_static_data,
.decode = decode_frame, .decode = jpeg2000_decode_frame,
.profiles = NULL_IF_CONFIG_SMALL(profiles) .profiles = NULL_IF_CONFIG_SMALL(profiles)
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment