j2k: merge cosmetics and non functional changes from jpeg2000

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/23/head
Michael Niedermayer 12 years ago
parent e5c7bafb44
commit 53ec1c811e
  1. 33
      libavcodec/j2k.c
  2. 17
      libavcodec/j2k.h
  3. 102
      libavcodec/j2kdec.c

@ -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)

@ -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"
@ -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];
}

@ -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;
@ -182,14 +183,14 @@ static int get_siz(Jpeg2000DecoderContext *s)
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;
@ -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
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;
@ -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,8 +375,10 @@ 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;
@ -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++)
@ -595,7 +601,8 @@ static void decode_sigpass(Jpeg2000T1Context *t1, int width, int height, int bpn
}
}
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,15 +612,16 @@ 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++) {
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;
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,
int bpno, int bandno, int seg_symbols, int vert_causal_ctx_csty_symbol)
@ -622,15 +630,18 @@ 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)) ||
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 {
runlen = 0;
@ -648,8 +659,13 @@ 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;
@ -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;
@ -860,7 +877,7 @@ 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++) {
@ -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)
};

Loading…
Cancel
Save