j2k: Rename structs to be more similar to jpeg2000dec

This should simplify merging

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-05-21 21:19:05 +02:00
parent 376e89e280
commit 0ab0ed2b86
4 changed files with 205 additions and 205 deletions

View File

@ -64,12 +64,12 @@ static int tag_tree_size(int w, int h)
return res + 1; return res + 1;
} }
J2kTgtNode *ff_j2k_tag_tree_init(int w, int h) Jpeg2000TgtNode *ff_j2k_tag_tree_init(int w, int h)
{ {
int pw = w, ph = h; int pw = w, ph = h;
J2kTgtNode *res, *t, *t2; Jpeg2000TgtNode *res, *t, *t2;
t = res = av_mallocz(tag_tree_size(w, h)*sizeof(J2kTgtNode)); t = res = av_mallocz(tag_tree_size(w, h)*sizeof(Jpeg2000TgtNode));
if (res == NULL) if (res == NULL)
return NULL; return NULL;
@ -93,7 +93,7 @@ J2kTgtNode *ff_j2k_tag_tree_init(int w, int h)
return res; return res;
} }
static void tag_tree_zero(J2kTgtNode *t, int w, int h) static void tag_tree_zero(Jpeg2000TgtNode *t, int w, int h)
{ {
int i, siz = tag_tree_size(w, h); int i, siz = tag_tree_size(w, h);
@ -178,7 +178,7 @@ void ff_j2k_init_tier1_luts(void)
ff_j2k_sgnctxno_lut[i][j] = getsgnctxno(i + (j << 8), &ff_j2k_xorbit_lut[i][j]); ff_j2k_sgnctxno_lut[i][j] = getsgnctxno(i + (j << 8), &ff_j2k_xorbit_lut[i][j]);
} }
void ff_j2k_set_significant(J2kT1Context *t1, int x, int y, int negative) void ff_j2k_set_significant(Jpeg2000T1Context *t1, int x, int y, int negative)
{ {
x++; y++; x++; y++;
t1->flags[y][x] |= J2K_T1_SIG; t1->flags[y][x] |= J2K_T1_SIG;
@ -199,7 +199,7 @@ void ff_j2k_set_significant(J2kT1Context *t1, int x, int y, int negative)
t1->flags[y-1][x-1] |= J2K_T1_SIG_SE; t1->flags[y-1][x-1] |= J2K_T1_SIG_SE;
} }
int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantStyle *qntsty, int cbps, int dx, int dy) int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int cbps, int dx, int dy)
{ {
int reslevelno, bandno, gbandno = 0, ret, i, j, csize = 1; int reslevelno, bandno, gbandno = 0, ret, i, j, csize = 1;
@ -211,13 +211,13 @@ int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantSt
comp->data = av_malloc(csize * sizeof(int)); comp->data = av_malloc(csize * sizeof(int));
if (!comp->data) if (!comp->data)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
comp->reslevel = av_malloc(codsty->nreslevels * sizeof(J2kResLevel)); comp->reslevel = av_malloc(codsty->nreslevels * sizeof(Jpeg2000ResLevel));
if (!comp->reslevel) if (!comp->reslevel)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
int declvl = codsty->nreslevels - reslevelno; int declvl = codsty->nreslevels - reslevelno;
J2kResLevel *reslevel = comp->reslevel + reslevelno; Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++) for (j = 0; j < 2; j++)
@ -241,11 +241,11 @@ int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantSt
reslevel->num_precincts_y = ff_j2k_ceildivpow2(reslevel->coord[1][1], codsty->log2_prec_height) reslevel->num_precincts_y = ff_j2k_ceildivpow2(reslevel->coord[1][1], codsty->log2_prec_height)
- (reslevel->coord[1][0] >> codsty->log2_prec_height); - (reslevel->coord[1][0] >> codsty->log2_prec_height);
reslevel->band = av_malloc(reslevel->nbands * sizeof(J2kBand)); reslevel->band = av_malloc(reslevel->nbands * sizeof(Jpeg2000Band));
if (!reslevel->band) if (!reslevel->band)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
for (bandno = 0; bandno < reslevel->nbands; bandno++, gbandno++){ for (bandno = 0; bandno < reslevel->nbands; bandno++, gbandno++){
J2kBand *band = reslevel->band + bandno; Jpeg2000Band *band = reslevel->band + bandno;
int cblkno, precx, precy, precno; int cblkno, precx, precy, precno;
int x0, y0, x1, y1; int x0, y0, x1, y1;
int xi0, yi0, xi1, yi1; int xi0, yi0, xi1, yi1;
@ -285,15 +285,15 @@ int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantSt
band->cblknx = ff_j2k_ceildiv(band->cblknx, dx); band->cblknx = ff_j2k_ceildiv(band->cblknx, dx);
band->cblkny = ff_j2k_ceildiv(band->cblkny, dy); band->cblkny = ff_j2k_ceildiv(band->cblkny, dy);
band->cblk = av_malloc(sizeof(J2kCblk) * band->cblknx * band->cblkny); band->cblk = av_malloc(sizeof(Jpeg2000Cblk) * band->cblknx * band->cblkny);
if (!band->cblk) if (!band->cblk)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
band->prec = av_malloc(sizeof(J2kCblk) * reslevel->num_precincts_x * reslevel->num_precincts_y); band->prec = av_malloc(sizeof(Jpeg2000Cblk) * reslevel->num_precincts_x * reslevel->num_precincts_y);
if (!band->prec) if (!band->prec)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){ for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){
J2kCblk *cblk = band->cblk + cblkno; Jpeg2000Cblk *cblk = band->cblk + cblkno;
cblk->zero = 0; cblk->zero = 0;
cblk->lblock = 3; cblk->lblock = 3;
cblk->length = 0; cblk->length = 0;
@ -325,7 +325,7 @@ int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantSt
cblkperprecw = 1<<(codsty->log2_prec_width - codsty->log2_cblk_width); cblkperprecw = 1<<(codsty->log2_prec_width - codsty->log2_cblk_width);
for (precx = 0, precno = 0; precx < reslevel->num_precincts_x; precx++){ for (precx = 0, precno = 0; precx < reslevel->num_precincts_x; precx++){
for (precy = 0; precy < reslevel->num_precincts_y; precy++, precno = 0){ for (precy = 0; precy < reslevel->num_precincts_y; precy++, precno = 0){
J2kPrec *prec = band->prec + precno; Jpeg2000Prec *prec = band->prec + precno;
prec->xi0 = xi0; prec->xi0 = xi0;
prec->xi1 = xi1; prec->xi1 = xi1;
prec->cblkincl = ff_j2k_tag_tree_init(prec->xi1 - prec->xi0, prec->cblkincl = ff_j2k_tag_tree_init(prec->xi1 - prec->xi0,
@ -345,20 +345,20 @@ int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantSt
return 0; return 0;
} }
void ff_j2k_reinit(J2kComponent *comp, J2kCodingStyle *codsty) void ff_j2k_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
{ {
int reslevelno, bandno, cblkno, precno; int reslevelno, bandno, cblkno, precno;
for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
J2kResLevel *rlevel = comp->reslevel + reslevelno; Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;
for (bandno = 0; bandno < rlevel->nbands; bandno++){ for (bandno = 0; bandno < rlevel->nbands; bandno++){
J2kBand *band = rlevel->band + bandno; Jpeg2000Band *band = rlevel->band + bandno;
for(precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++){ for(precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++){
J2kPrec *prec = band->prec + precno; Jpeg2000Prec *prec = band->prec + precno;
tag_tree_zero(prec->zerobits, prec->xi1 - prec->xi0, prec->yi1 - prec->yi0); tag_tree_zero(prec->zerobits, prec->xi1 - prec->xi0, prec->yi1 - prec->yi0);
tag_tree_zero(prec->cblkincl, prec->xi1 - prec->xi0, prec->yi1 - prec->yi0); tag_tree_zero(prec->cblkincl, prec->xi1 - prec->xi0, prec->yi1 - prec->yi0);
} }
for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){ for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){
J2kCblk *cblk = band->cblk + cblkno; Jpeg2000Cblk *cblk = band->cblk + cblkno;
cblk->length = 0; cblk->length = 0;
cblk->lblock = 3; cblk->lblock = 3;
} }
@ -366,16 +366,16 @@ void ff_j2k_reinit(J2kComponent *comp, J2kCodingStyle *codsty)
} }
} }
void ff_j2k_cleanup(J2kComponent *comp, J2kCodingStyle *codsty) void ff_j2k_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
{ {
int reslevelno, bandno, precno; int reslevelno, bandno, precno;
for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
J2kResLevel *reslevel = comp->reslevel + reslevelno; Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
for (bandno = 0; bandno < reslevel->nbands ; bandno++){ for (bandno = 0; bandno < reslevel->nbands ; bandno++){
J2kBand *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++){
J2kPrec *prec = band->prec + precno; Jpeg2000Prec *prec = band->prec + precno;
av_freep(&prec->zerobits); av_freep(&prec->zerobits);
av_freep(&prec->cblkincl); av_freep(&prec->cblkincl);
} }

View File

@ -31,7 +31,7 @@
#include "mqc.h" #include "mqc.h"
#include "j2k_dwt.h" #include "j2k_dwt.h"
enum J2kMarkers{ enum Jpeg2000Markers{
J2K_SOC = 0xff4f, ///< start of codestream J2K_SOC = 0xff4f, ///< start of codestream
J2K_SIZ = 0xff51, ///< image and tile size J2K_SIZ = 0xff51, ///< image and tile size
J2K_COD, ///< coding style default J2K_COD, ///< coding style default
@ -54,7 +54,7 @@ enum J2kMarkers{
J2K_EOC = 0xffd9, ///< end of codestream J2K_EOC = 0xffd9, ///< end of codestream
}; };
enum J2kQuantsty{ ///< quantization style enum Jpeg2000Quantsty{ ///< quantization style
J2K_QSTY_NONE, ///< no quantization J2K_QSTY_NONE, ///< no quantization
J2K_QSTY_SI, ///< scalar derived J2K_QSTY_SI, ///< scalar derived
J2K_QSTY_SE ///< scalar expoounded J2K_QSTY_SE ///< scalar expoounded
@ -104,13 +104,13 @@ typedef struct {
int data[J2K_MAX_CBLKW][J2K_MAX_CBLKH]; int data[J2K_MAX_CBLKW][J2K_MAX_CBLKH];
int flags[J2K_MAX_CBLKW+2][J2K_MAX_CBLKH+2]; int flags[J2K_MAX_CBLKW+2][J2K_MAX_CBLKH+2];
MqcState mqc; MqcState mqc;
} J2kT1Context; } Jpeg2000T1Context;
typedef struct J2kTgtNode { typedef struct Jpeg2000TgtNode {
uint8_t val; uint8_t val;
uint8_t vis; uint8_t vis;
struct J2kTgtNode *parent; struct Jpeg2000TgtNode *parent;
} J2kTgtNode; } Jpeg2000TgtNode;
typedef struct { typedef struct {
uint8_t nreslevels; ///< number of resolution levels uint8_t nreslevels; ///< number of resolution levels
@ -123,19 +123,19 @@ typedef struct {
uint8_t nlayers; ///< number of layers uint8_t nlayers; ///< number of layers
uint8_t mct; ///< multiple component transformation uint8_t mct; ///< multiple component transformation
uint8_t cblk_style; ///< codeblock coding style uint8_t cblk_style; ///< codeblock coding style
} J2kCodingStyle; } Jpeg2000CodingStyle;
typedef struct { typedef struct {
uint8_t expn[32 * 3]; ///< quantization exponent uint8_t expn[32 * 3]; ///< quantization exponent
uint16_t mant[32 * 3]; ///< quantization mantissa uint16_t mant[32 * 3]; ///< quantization mantissa
uint8_t quantsty; ///< quantization style uint8_t quantsty; ///< quantization style
uint8_t nguardbits; ///< number of guard bits uint8_t nguardbits; ///< number of guard bits
} J2kQuantStyle; } Jpeg2000QuantStyle;
typedef struct { typedef struct {
uint16_t rate; uint16_t rate;
int64_t disto; int64_t disto;
} J2kPass; } Jpeg2000Pass;
typedef struct { typedef struct {
uint8_t npasses; uint8_t npasses;
@ -146,38 +146,38 @@ typedef struct {
uint8_t lblock; uint8_t lblock;
uint8_t zero; uint8_t zero;
uint8_t data[8192]; uint8_t data[8192];
J2kPass passes[100]; Jpeg2000Pass passes[100];
} J2kCblk; ///< code block } Jpeg2000Cblk; ///< code block
typedef struct { typedef struct {
uint16_t xi0, xi1, yi0, yi1; ///< codeblock indexes ([xi0, xi1)) uint16_t xi0, xi1, yi0, yi1; ///< codeblock indexes ([xi0, xi1))
J2kTgtNode *zerobits; Jpeg2000TgtNode *zerobits;
J2kTgtNode *cblkincl; Jpeg2000TgtNode *cblkincl;
} J2kPrec; ///< precinct } Jpeg2000Prec; ///< precinct
typedef struct { typedef struct {
uint16_t coord[2][2]; ///< border coordinates {{x0, x1}, {y0, y1}} uint16_t coord[2][2]; ///< border coordinates {{x0, x1}, {y0, y1}}
uint16_t codeblock_width, codeblock_height; uint16_t codeblock_width, codeblock_height;
uint16_t cblknx, cblkny; uint16_t cblknx, cblkny;
uint32_t stepsize; ///< quantization stepsize (* 2^13) uint32_t stepsize; ///< quantization stepsize (* 2^13)
J2kPrec *prec; Jpeg2000Prec *prec;
J2kCblk *cblk; Jpeg2000Cblk *cblk;
} J2kBand; ///< subband } Jpeg2000Band; ///< subband
typedef struct { typedef struct {
uint8_t nbands; 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 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 uint8_t log2_prec_width, log2_prec_height; ///< exponent of precinct size
J2kBand *band; Jpeg2000Band *band;
} J2kResLevel; ///< resolution level } Jpeg2000ResLevel; ///< resolution level
typedef struct { typedef struct {
J2kResLevel *reslevel; Jpeg2000ResLevel *reslevel;
DWTContext dwt; DWTContext dwt;
int *data; int *data;
uint16_t coord[2][2]; ///< border coordinates {{x0, x1}, {y0, y1}} uint16_t coord[2][2]; ///< border coordinates {{x0, x1}, {y0, y1}}
} J2kComponent; } Jpeg2000Component;
/* debug routines */ /* debug routines */
#if 0 #if 0
@ -199,12 +199,12 @@ static inline int ff_j2k_ceildiv(int a, int b)
} }
/* tag tree routines */ /* tag tree routines */
J2kTgtNode *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 */
void ff_j2k_init_tier1_luts(void); void ff_j2k_init_tier1_luts(void);
void ff_j2k_set_significant(J2kT1Context *t1, int x, int y, int negative); void ff_j2k_set_significant(Jpeg2000T1Context *t1, int x, int y, int negative);
extern uint8_t ff_j2k_nbctxno_lut[256][4]; extern uint8_t ff_j2k_nbctxno_lut[256][4];
@ -227,8 +227,8 @@ static inline int ff_j2k_getsgnctxno(int flag, int *xorbit)
return ff_j2k_sgnctxno_lut[flag&15][(flag>>8)&15]; return ff_j2k_sgnctxno_lut[flag&15][(flag>>8)&15];
} }
int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantStyle *qntsty, int cbps, int dx, int dy); int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int cbps, int dx, int dy);
void ff_j2k_reinit(J2kComponent *comp, J2kCodingStyle *codsty); void ff_j2k_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty);
void ff_j2k_cleanup(J2kComponent *comp, J2kCodingStyle *codsty); void ff_j2k_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty);
#endif /* AVCODEC_J2K_H */ #endif /* AVCODEC_J2K_H */

View File

@ -42,11 +42,11 @@
#define HAD_QCC 0x02 #define HAD_QCC 0x02
typedef struct { typedef struct {
J2kComponent *comp; Jpeg2000Component *comp;
uint8_t properties[4]; uint8_t properties[4];
J2kCodingStyle codsty[4]; Jpeg2000CodingStyle codsty[4];
J2kQuantStyle qntsty[4]; Jpeg2000QuantStyle qntsty[4];
} J2kTile; } Jpeg2000Tile;
typedef struct { typedef struct {
AVCodecContext *avctx; AVCodecContext *avctx;
@ -66,17 +66,17 @@ typedef struct {
int numXtiles, numYtiles; int numXtiles, numYtiles;
int maxtilelen; int maxtilelen;
J2kCodingStyle codsty[4]; Jpeg2000CodingStyle codsty[4];
J2kQuantStyle qntsty[4]; Jpeg2000QuantStyle qntsty[4];
int bit_index; int bit_index;
int curtileno; int curtileno;
J2kTile *tile; Jpeg2000Tile *tile;
} J2kDecoderContext; } Jpeg2000DecoderContext;
static int get_bits(J2kDecoderContext *s, int n) static int get_bits(Jpeg2000DecoderContext *s, int n)
{ {
int res = 0; int res = 0;
@ -91,14 +91,14 @@ static int get_bits(J2kDecoderContext *s, int n)
return res; return res;
} }
static void j2k_flush(J2kDecoderContext *s) static void j2k_flush(Jpeg2000DecoderContext *s)
{ {
if (bytestream2_get_byte(&s->g) == 0xff) if (bytestream2_get_byte(&s->g) == 0xff)
bytestream2_skip(&s->g, 1); bytestream2_skip(&s->g, 1);
s->bit_index = 8; s->bit_index = 8;
} }
#if 0 #if 0
void printcomp(J2kComponent *comp) void printcomp(Jpeg2000Component *comp)
{ {
int i; int i;
for (i = 0; i < comp->y1 - comp->y0; i++) for (i = 0; i < comp->y1 - comp->y0; i++)
@ -110,7 +110,7 @@ static void nspaces(FILE *fd, int n)
while(n--) putc(' ', fd); while(n--) putc(' ', fd);
} }
static void dump(J2kDecoderContext *s, FILE *fd) static void dump(Jpeg2000DecoderContext *s, FILE *fd)
{ {
int tileno, compno, reslevelno, bandno, precno; int tileno, compno, reslevelno, bandno, precno;
fprintf(fd, "XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n" fprintf(fd, "XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n"
@ -119,18 +119,18 @@ static void dump(J2kDecoderContext *s, FILE *fd)
s->width, s->height, s->tile_width, s->tile_height, s->width, s->height, s->tile_width, s->tile_height,
s->numXtiles, s->numYtiles, s->ncomponents); s->numXtiles, s->numYtiles, s->ncomponents);
for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
J2kTile *tile = s->tile + tileno; Jpeg2000Tile *tile = s->tile + tileno;
nspaces(fd, 2); nspaces(fd, 2);
fprintf(fd, "tile %d:\n", tileno); fprintf(fd, "tile %d:\n", tileno);
for(compno = 0; compno < s->ncomponents; compno++){ for(compno = 0; compno < s->ncomponents; compno++){
J2kComponent *comp = tile->comp + compno; Jpeg2000Component *comp = tile->comp + compno;
nspaces(fd, 4); nspaces(fd, 4);
fprintf(fd, "component %d:\n", compno); fprintf(fd, "component %d:\n", compno);
nspaces(fd, 4); nspaces(fd, 4);
fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d\n", fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
comp->x0, comp->x1, comp->y0, comp->y1); comp->x0, comp->x1, comp->y0, comp->y1);
for(reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ for(reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
J2kResLevel *reslevel = comp->reslevel + reslevelno; Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
nspaces(fd, 6); nspaces(fd, 6);
fprintf(fd, "reslevel %d:\n", reslevelno); fprintf(fd, "reslevel %d:\n", reslevelno);
nspaces(fd, 6); nspaces(fd, 6);
@ -138,7 +138,7 @@ static void dump(J2kDecoderContext *s, FILE *fd)
reslevel->x0, reslevel->x1, reslevel->y0, reslevel->x0, reslevel->x1, reslevel->y0,
reslevel->y1, reslevel->nbands); reslevel->y1, reslevel->nbands);
for(bandno = 0; bandno < reslevel->nbands; bandno++){ for(bandno = 0; bandno < reslevel->nbands; bandno++){
J2kBand *band = reslevel->band + bandno; Jpeg2000Band *band = reslevel->band + bandno;
nspaces(fd, 8); nspaces(fd, 8);
fprintf(fd, "band %d:\n", bandno); fprintf(fd, "band %d:\n", bandno);
nspaces(fd, 8); nspaces(fd, 8);
@ -149,7 +149,7 @@ static void dump(J2kDecoderContext *s, FILE *fd)
band->codeblock_width, band->codeblock_height, band->codeblock_width, band->codeblock_height,
band->cblknx, band->cblkny); band->cblknx, band->cblkny);
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++){
J2kPrec *prec = band->prec + precno; Jpeg2000Prec *prec = band->prec + precno;
nspaces(fd, 10); nspaces(fd, 10);
fprintf(fd, "prec %d:\n", precno); fprintf(fd, "prec %d:\n", precno);
nspaces(fd, 10); nspaces(fd, 10);
@ -164,9 +164,9 @@ static void dump(J2kDecoderContext *s, FILE *fd)
#endif #endif
/** decode the value stored in node */ /** decode the value stored in node */
static int tag_tree_decode(J2kDecoderContext *s, J2kTgtNode *node, int threshold) static int tag_tree_decode(Jpeg2000DecoderContext *s, Jpeg2000TgtNode *node, int threshold)
{ {
J2kTgtNode *stack[30]; Jpeg2000TgtNode *stack[30];
int sp = -1, curval = 0; int sp = -1, curval = 0;
if(!node) if(!node)
@ -203,7 +203,7 @@ static int tag_tree_decode(J2kDecoderContext *s, J2kTgtNode *node, int threshold
/* marker segments */ /* marker segments */
/** get sizes and offsets of image, tiles; number of components */ /** get sizes and offsets of image, tiles; number of components */
static int get_siz(J2kDecoderContext *s) static int get_siz(Jpeg2000DecoderContext *s)
{ {
int i, ret; int i, ret;
ThreadFrame frame = { .f = s->picture }; ThreadFrame frame = { .f = s->picture };
@ -245,17 +245,17 @@ static int get_siz(J2kDecoderContext *s)
s->numXtiles = ff_j2k_ceildiv(s->width - s->tile_offset_x, s->tile_width); s->numXtiles = ff_j2k_ceildiv(s->width - s->tile_offset_x, s->tile_width);
s->numYtiles = ff_j2k_ceildiv(s->height - s->tile_offset_y, s->tile_height); s->numYtiles = ff_j2k_ceildiv(s->height - s->tile_offset_y, s->tile_height);
if(s->numXtiles * (uint64_t)s->numYtiles > INT_MAX/sizeof(J2kTile)) 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(J2kTile)); s->tile = av_mallocz(s->numXtiles * s->numYtiles * sizeof(Jpeg2000Tile));
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++){
J2kTile *tile = s->tile + i; Jpeg2000Tile *tile = s->tile + i;
tile->comp = av_mallocz(s->ncomponents * sizeof(J2kComponent)); tile->comp = av_mallocz(s->ncomponents * sizeof(Jpeg2000Component));
if (!tile->comp) if (!tile->comp)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
@ -294,7 +294,7 @@ static int get_siz(J2kDecoderContext *s)
} }
/** get common part for COD and COC segments */ /** get common part for COD and COC segments */
static int get_cox(J2kDecoderContext *s, J2kCodingStyle *c) static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
{ {
if (bytestream2_get_bytes_left(&s->g) < 5) if (bytestream2_get_bytes_left(&s->g) < 5)
return AVERROR(EINVAL); return AVERROR(EINVAL);
@ -317,9 +317,9 @@ static int get_cox(J2kDecoderContext *s, J2kCodingStyle *c)
} }
/** get coding parameters for a particular tile or whole image*/ /** get coding parameters for a particular tile or whole image*/
static int get_cod(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties) static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *properties)
{ {
J2kCodingStyle tmp; Jpeg2000CodingStyle tmp;
int compno; int compno;
if (bytestream2_get_bytes_left(&s->g) < 5) if (bytestream2_get_bytes_left(&s->g) < 5)
@ -341,13 +341,13 @@ static int get_cod(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties)
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(J2kCodingStyle)); memcpy(c + compno, &tmp, sizeof(Jpeg2000CodingStyle));
} }
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 on a particular tile */
static int get_coc(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties) static int get_coc(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *properties)
{ {
int compno; int compno;
@ -365,7 +365,7 @@ static int get_coc(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties)
} }
/** get common part for QCD and QCC segments */ /** get common part for QCD and QCC segments */
static int get_qcx(J2kDecoderContext *s, int n, J2kQuantStyle *q) static int get_qcx(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q)
{ {
int i, x; int i, x;
@ -408,21 +408,21 @@ static int get_qcx(J2kDecoderContext *s, int n, J2kQuantStyle *q)
} }
/** 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(J2kDecoderContext *s, int n, J2kQuantStyle *q, uint8_t *properties) static int get_qcd(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, uint8_t *properties)
{ {
J2kQuantStyle tmp; Jpeg2000QuantStyle tmp;
int compno; int compno;
if (get_qcx(s, n, &tmp)) if (get_qcx(s, n, &tmp))
return -1; return -1;
for (compno = 0; compno < s->ncomponents; compno++) for (compno = 0; compno < s->ncomponents; compno++)
if (!(properties[compno] & HAD_QCC)) if (!(properties[compno] & HAD_QCC))
memcpy(q + compno, &tmp, sizeof(J2kQuantStyle)); memcpy(q + compno, &tmp, sizeof(Jpeg2000QuantStyle));
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 on in a particular tile */
static int get_qcc(J2kDecoderContext *s, int n, J2kQuantStyle *q, uint8_t *properties) static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, uint8_t *properties)
{ {
int compno; int compno;
@ -435,7 +435,7 @@ static int get_qcc(J2kDecoderContext *s, int n, J2kQuantStyle *q, uint8_t *prope
} }
/** get start of tile segment */ /** get start of tile segment */
static uint8_t get_sot(J2kDecoderContext *s) static uint8_t get_sot(Jpeg2000DecoderContext *s)
{ {
if (bytestream2_get_bytes_left(&s->g) < 8) if (bytestream2_get_bytes_left(&s->g) < 8)
return AVERROR(EINVAL); return AVERROR(EINVAL);
@ -449,30 +449,30 @@ static uint8_t get_sot(J2kDecoderContext *s)
bytestream2_skipu(&s->g, 4); ///< Psot (ignored) bytestream2_skipu(&s->g, 4); ///< Psot (ignored)
if (!bytestream2_get_byteu(&s->g)){ ///< TPsot if (!bytestream2_get_byteu(&s->g)){ ///< TPsot
J2kTile *tile = s->tile + s->curtileno; Jpeg2000Tile *tile = s->tile + s->curtileno;
/* copy defaults */ /* copy defaults */
memcpy(tile->codsty, s->codsty, s->ncomponents * sizeof(J2kCodingStyle)); memcpy(tile->codsty, s->codsty, s->ncomponents * sizeof(Jpeg2000CodingStyle));
memcpy(tile->qntsty, s->qntsty, s->ncomponents * sizeof(J2kQuantStyle)); memcpy(tile->qntsty, s->qntsty, s->ncomponents * sizeof(Jpeg2000QuantStyle));
} }
bytestream2_get_byteu(&s->g); ///< TNsot bytestream2_get_byteu(&s->g); ///< TNsot
return 0; return 0;
} }
static int init_tile(J2kDecoderContext *s, int tileno) static int init_tile(Jpeg2000DecoderContext *s, int tileno)
{ {
int compno, int compno,
tilex = tileno % s->numXtiles, tilex = tileno % s->numXtiles,
tiley = tileno / s->numXtiles; tiley = tileno / s->numXtiles;
J2kTile *tile = s->tile + tileno; Jpeg2000Tile *tile = s->tile + tileno;
if (!tile->comp) if (!tile->comp)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
for (compno = 0; compno < s->ncomponents; compno++){ for (compno = 0; compno < s->ncomponents; compno++){
J2kComponent *comp = tile->comp + compno; Jpeg2000Component *comp = tile->comp + compno;
J2kCodingStyle *codsty = tile->codsty + compno; Jpeg2000CodingStyle *codsty = tile->codsty + compno;
J2kQuantStyle *qntsty = tile->qntsty + compno; Jpeg2000QuantStyle *qntsty = tile->qntsty + compno;
int ret; // global bandno int ret; // global bandno
comp->coord[0][0] = FFMAX(tilex * s->tile_width + s->tile_offset_x, s->image_offset_x); comp->coord[0][0] = FFMAX(tilex * s->tile_width + s->tile_offset_x, s->image_offset_x);
@ -487,7 +487,7 @@ static int init_tile(J2kDecoderContext *s, int tileno)
} }
/** read the number of coding passes */ /** read the number of coding passes */
static int getnpasses(J2kDecoderContext *s) static int getnpasses(Jpeg2000DecoderContext *s)
{ {
int num; int num;
if (!get_bits(s, 1)) if (!get_bits(s, 1))
@ -502,7 +502,7 @@ static int getnpasses(J2kDecoderContext *s)
return num < 0 ? num : 37 + num; return num < 0 ? num : 37 + num;
} }
static int getlblockinc(J2kDecoderContext *s) static int getlblockinc(Jpeg2000DecoderContext *s)
{ {
int res = 0, ret; int res = 0, ret;
while (ret = get_bits(s, 1)){ while (ret = get_bits(s, 1)){
@ -513,7 +513,7 @@ static int getlblockinc(J2kDecoderContext *s)
return res; return res;
} }
static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLevel *rlevel, int precno, static int decode_packet(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty, Jpeg2000ResLevel *rlevel, int precno,
int layno, uint8_t *expn, int numgbits) int layno, uint8_t *expn, int numgbits)
{ {
int bandno, cblkny, cblknx, cblkno, ret; int bandno, cblkny, cblknx, cblkno, ret;
@ -525,8 +525,8 @@ static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLev
return ret; return ret;
for (bandno = 0; bandno < rlevel->nbands; bandno++){ for (bandno = 0; bandno < rlevel->nbands; bandno++){
J2kBand *band = rlevel->band + bandno; Jpeg2000Band *band = rlevel->band + bandno;
J2kPrec *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]
@ -535,7 +535,7 @@ static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLev
for (cblkny = prec->yi0; cblkny < prec->yi1; cblkny++) for (cblkny = prec->yi0; cblkny < prec->yi1; cblkny++)
for(cblknx = prec->xi0, cblkno = cblkny * band->cblknx + cblknx; cblknx < prec->xi1; cblknx++, cblkno++, pos++){ for(cblknx = prec->xi0, cblkno = cblkny * band->cblknx + cblknx; cblknx < prec->xi1; cblknx++, cblkno++, pos++){
J2kCblk *cblk = band->cblk + cblkno; Jpeg2000Cblk *cblk = band->cblk + cblkno;
int incl, newpasses, llen; int incl, newpasses, llen;
if (cblk->npasses) if (cblk->npasses)
@ -571,12 +571,12 @@ static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLev
} }
for (bandno = 0; bandno < rlevel->nbands; bandno++){ for (bandno = 0; bandno < rlevel->nbands; bandno++){
J2kBand *band = rlevel->band + bandno; Jpeg2000Band *band = rlevel->band + bandno;
int yi, cblknw = band->prec[precno].xi1 - band->prec[precno].xi0; int yi, cblknw = band->prec[precno].xi1 - band->prec[precno].xi0;
for (yi = band->prec[precno].yi0; yi < band->prec[precno].yi1; yi++){ for (yi = band->prec[precno].yi0; yi < band->prec[precno].yi1; yi++){
int xi; int xi;
for (xi = band->prec[precno].xi0; xi < band->prec[precno].xi1; xi++){ for (xi = band->prec[precno].xi0; xi < band->prec[precno].xi1; xi++){
J2kCblk *cblk = band->cblk + yi * cblknw + xi; Jpeg2000Cblk *cblk = band->cblk + yi * cblknw + xi;
if (bytestream2_get_bytes_left(&s->g) < cblk->lengthinc) if (bytestream2_get_bytes_left(&s->g) < cblk->lengthinc)
return AVERROR(EINVAL); return AVERROR(EINVAL);
bytestream2_get_bufferu(&s->g, cblk->data, cblk->lengthinc); bytestream2_get_bufferu(&s->g, cblk->data, cblk->lengthinc);
@ -588,7 +588,7 @@ static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLev
return 0; return 0;
} }
static int jpeg2000_decode_packets(J2kDecoderContext *s, J2kTile *tile) static int jpeg2000_decode_packets(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
{ {
int layno, reslevelno, compno, precno, ok_reslevel; int layno, reslevelno, compno, precno, ok_reslevel;
s->bit_index = 8; s->bit_index = 8;
@ -597,10 +597,10 @@ static int jpeg2000_decode_packets(J2kDecoderContext *s, J2kTile *tile)
for (reslevelno = 0; ok_reslevel; reslevelno++){ for (reslevelno = 0; ok_reslevel; reslevelno++){
ok_reslevel = 0; ok_reslevel = 0;
for (compno = 0; compno < s->ncomponents; compno++){ for (compno = 0; compno < s->ncomponents; compno++){
J2kCodingStyle *codsty = tile->codsty + compno; Jpeg2000CodingStyle *codsty = tile->codsty + compno;
J2kQuantStyle *qntsty = tile->qntsty + compno; Jpeg2000QuantStyle *qntsty = tile->qntsty + compno;
if (reslevelno < codsty->nreslevels){ if (reslevelno < codsty->nreslevels){
J2kResLevel *rlevel = tile->comp[compno].reslevel + reslevelno; Jpeg2000ResLevel *rlevel = tile->comp[compno].reslevel + reslevelno;
ok_reslevel = 1; ok_reslevel = 1;
for (precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++){ for (precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++){
if (decode_packet(s, codsty, rlevel, precno, layno, qntsty->expn + if (decode_packet(s, codsty, rlevel, precno, layno, qntsty->expn +
@ -615,7 +615,7 @@ static int jpeg2000_decode_packets(J2kDecoderContext *s, J2kTile *tile)
} }
/* TIER-1 routines */ /* TIER-1 routines */
static void decode_sigpass(J2kT1Context *t1, int width, int height, int bpno, int bandno, int bpass_csty_symbol, static void decode_sigpass(Jpeg2000T1Context *t1, int width, int height, int bpno, int bandno, int bpass_csty_symbol,
int vert_causal_ctx_csty_symbol) int vert_causal_ctx_csty_symbol)
{ {
int mask = 3 << (bpno - 1), y0, x, y; int mask = 3 << (bpno - 1), y0, x, y;
@ -642,7 +642,7 @@ static void decode_sigpass(J2kT1Context *t1, int width, int height, int bpno, in
} }
} }
static void decode_refpass(J2kT1Context *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;
@ -662,7 +662,7 @@ static void decode_refpass(J2kT1Context *t1, int width, int height, int bpno)
} }
} }
static void decode_clnpass(J2kDecoderContext *s, J2kT1Context *t1, int width, int height, static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int width, int height,
int bpno, int bandno, int seg_symbols) int bpno, int bandno, int seg_symbols)
{ {
int mask = 3 << (bpno - 1), y0, x, y, runlen, dec; int mask = 3 << (bpno - 1), y0, x, y, runlen, dec;
@ -712,7 +712,7 @@ static void decode_clnpass(J2kDecoderContext *s, J2kT1Context *t1, int width, in
} }
} }
static int decode_cblk(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kT1Context *t1, J2kCblk *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;
@ -755,7 +755,7 @@ static int decode_cblk(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kT1Contex
return 0; return 0;
} }
static void mct_decode(J2kDecoderContext *s, J2kTile *tile) static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
{ {
int i, *src[3], i0, i1, i2, csize = 1; int i, *src[3], i0, i1, i2, csize = 1;
@ -786,21 +786,21 @@ static void mct_decode(J2kDecoderContext *s, J2kTile *tile)
} }
} }
static int decode_tile(J2kDecoderContext *s, J2kTile *tile) static int decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
{ {
int compno, reslevelno, bandno; int compno, reslevelno, bandno;
int x, y, *src[4]; int x, y, *src[4];
uint8_t *line; uint8_t *line;
J2kT1Context t1; Jpeg2000T1Context t1;
for (compno = 0; compno < s->ncomponents; compno++){ for (compno = 0; compno < s->ncomponents; compno++){
J2kComponent *comp = tile->comp + compno; Jpeg2000Component *comp = tile->comp + compno;
J2kCodingStyle *codsty = tile->codsty + compno; Jpeg2000CodingStyle *codsty = tile->codsty + compno;
for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
J2kResLevel *rlevel = comp->reslevel + reslevelno; Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;
for (bandno = 0; bandno < rlevel->nbands; bandno++){ for (bandno = 0; bandno < rlevel->nbands; bandno++){
J2kBand *band = rlevel->band + bandno; Jpeg2000Band *band = rlevel->band + bandno;
int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos; int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
bandpos = bandno + (reslevelno > 0); bandpos = bandno + (reslevelno > 0);
@ -903,13 +903,13 @@ static int decode_tile(J2kDecoderContext *s, J2kTile *tile)
return 0; return 0;
} }
static void cleanup(J2kDecoderContext *s) static void 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++){
for (compno = 0; compno < s->ncomponents; compno++){ for (compno = 0; compno < s->ncomponents; compno++){
J2kComponent *comp = s->tile[tileno].comp + compno; Jpeg2000Component *comp = s->tile[tileno].comp + compno;
J2kCodingStyle *codsty = s->tile[tileno].codsty + compno; Jpeg2000CodingStyle *codsty = s->tile[tileno].codsty + compno;
ff_j2k_cleanup(comp, codsty); ff_j2k_cleanup(comp, codsty);
} }
@ -918,10 +918,10 @@ static void cleanup(J2kDecoderContext *s)
av_freep(&s->tile); av_freep(&s->tile);
} }
static int decode_codestream(J2kDecoderContext *s) static int decode_codestream(Jpeg2000DecoderContext *s)
{ {
J2kCodingStyle *codsty = s->codsty; Jpeg2000CodingStyle *codsty = s->codsty;
J2kQuantStyle *qntsty = s->qntsty; Jpeg2000QuantStyle *qntsty = s->qntsty;
uint8_t *properties = s->properties; uint8_t *properties = s->properties;
for (;;){ for (;;){
@ -937,7 +937,7 @@ static int decode_codestream(J2kDecoderContext *s)
oldpos = bytestream2_tell(&s->g); oldpos = bytestream2_tell(&s->g);
if (marker == J2K_SOD){ if (marker == J2K_SOD){
J2kTile *tile = s->tile + s->curtileno; Jpeg2000Tile *tile = s->tile + s->curtileno;
if (ret = init_tile(s, s->curtileno)) { if (ret = init_tile(s, s->curtileno)) {
av_log(s->avctx, AV_LOG_ERROR, "tile initialization failed\n"); av_log(s->avctx, AV_LOG_ERROR, "tile initialization failed\n");
return ret; return ret;
@ -994,7 +994,7 @@ static int decode_codestream(J2kDecoderContext *s)
return 0; return 0;
} }
static int jp2_find_codestream(J2kDecoderContext *s) static int jp2_find_codestream(Jpeg2000DecoderContext *s)
{ {
uint32_t atom_size, atom; uint32_t atom_size, atom;
int found_codestream = 0, search_range = 10; int found_codestream = 0, search_range = 10;
@ -1021,7 +1021,7 @@ static int decode_frame(AVCodecContext *avctx,
void *data, int *got_frame, void *data, int *got_frame,
AVPacket *avpkt) AVPacket *avpkt)
{ {
J2kDecoderContext *s = avctx->priv_data; Jpeg2000DecoderContext *s = avctx->priv_data;
AVFrame *picture = data; AVFrame *picture = data;
int tileno, ret; int tileno, ret;
@ -1074,7 +1074,7 @@ err_out:
static av_cold int j2kdec_init(AVCodecContext *avctx) static av_cold int j2kdec_init(AVCodecContext *avctx)
{ {
J2kDecoderContext *s = avctx->priv_data; Jpeg2000DecoderContext *s = avctx->priv_data;
s->avctx = avctx; s->avctx = avctx;
@ -1087,7 +1087,7 @@ AVCodec ff_j2k_decoder = {
.name = "j2k", .name = "j2k",
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_JPEG2000, .id = AV_CODEC_ID_JPEG2000,
.priv_data_size = sizeof(J2kDecoderContext), .priv_data_size = sizeof(Jpeg2000DecoderContext),
.init = j2kdec_init, .init = j2kdec_init,
.decode = decode_frame, .decode = decode_frame,
.capabilities = CODEC_CAP_EXPERIMENTAL | CODEC_CAP_FRAME_THREADS, .capabilities = CODEC_CAP_EXPERIMENTAL | CODEC_CAP_FRAME_THREADS,

View File

@ -55,8 +55,8 @@ static const int dwt_norms[2][4][10] = { // [dwt_type][band][rlevel] (multiplied
}; };
typedef struct { typedef struct {
J2kComponent *comp; Jpeg2000Component *comp;
} J2kTile; } Jpeg2000Tile;
typedef struct { typedef struct {
AVCodecContext *avctx; AVCodecContext *avctx;
@ -77,11 +77,11 @@ typedef struct {
int64_t lambda; int64_t lambda;
J2kCodingStyle codsty; Jpeg2000CodingStyle codsty;
J2kQuantStyle qntsty; Jpeg2000QuantStyle qntsty;
J2kTile *tile; Jpeg2000Tile *tile;
} J2kEncoderContext; } Jpeg2000EncoderContext;
/* debug */ /* debug */
@ -94,14 +94,14 @@ static void nspaces(FILE *fd, int n)
while(n--) putc(' ', fd); while(n--) putc(' ', fd);
} }
static void printcomp(J2kComponent *comp) static void printcomp(Jpeg2000Component *comp)
{ {
int i; int i;
for (i = 0; i < comp->y1 - comp->y0; i++) for (i = 0; i < comp->y1 - comp->y0; i++)
ff_j2k_printv(comp->data + i * (comp->x1 - comp->x0), comp->x1 - comp->x0); ff_j2k_printv(comp->data + i * (comp->x1 - comp->x0), comp->x1 - comp->x0);
} }
static void dump(J2kEncoderContext *s, FILE *fd) static void dump(Jpeg2000EncoderContext *s, FILE *fd)
{ {
int tileno, compno, reslevelno, bandno, precno; int tileno, compno, reslevelno, bandno, precno;
fprintf(fd, "XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n" fprintf(fd, "XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n"
@ -110,18 +110,18 @@ static void dump(J2kEncoderContext *s, FILE *fd)
s->width, s->height, s->tile_width, s->tile_height, s->width, s->height, s->tile_width, s->tile_height,
s->numXtiles, s->numYtiles, s->ncomponents); s->numXtiles, s->numYtiles, s->ncomponents);
for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
J2kTile *tile = s->tile + tileno; Jpeg2000Tile *tile = s->tile + tileno;
nspaces(fd, 2); nspaces(fd, 2);
fprintf(fd, "tile %d:\n", tileno); fprintf(fd, "tile %d:\n", tileno);
for(compno = 0; compno < s->ncomponents; compno++){ for(compno = 0; compno < s->ncomponents; compno++){
J2kComponent *comp = tile->comp + compno; Jpeg2000Component *comp = tile->comp + compno;
nspaces(fd, 4); nspaces(fd, 4);
fprintf(fd, "component %d:\n", compno); fprintf(fd, "component %d:\n", compno);
nspaces(fd, 4); nspaces(fd, 4);
fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d\n", fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
comp->x0, comp->x1, comp->y0, comp->y1); comp->x0, comp->x1, comp->y0, comp->y1);
for(reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){ for(reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
J2kResLevel *reslevel = comp->reslevel + reslevelno; Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
nspaces(fd, 6); nspaces(fd, 6);
fprintf(fd, "reslevel %d:\n", reslevelno); fprintf(fd, "reslevel %d:\n", reslevelno);
nspaces(fd, 6); nspaces(fd, 6);
@ -129,7 +129,7 @@ static void dump(J2kEncoderContext *s, FILE *fd)
reslevel->x0, reslevel->x1, reslevel->y0, reslevel->x0, reslevel->x1, reslevel->y0,
reslevel->y1, reslevel->nbands); reslevel->y1, reslevel->nbands);
for(bandno = 0; bandno < reslevel->nbands; bandno++){ for(bandno = 0; bandno < reslevel->nbands; bandno++){
J2kBand *band = reslevel->band + bandno; Jpeg2000Band *band = reslevel->band + bandno;
nspaces(fd, 8); nspaces(fd, 8);
fprintf(fd, "band %d:\n", bandno); fprintf(fd, "band %d:\n", bandno);
nspaces(fd, 8); nspaces(fd, 8);
@ -140,7 +140,7 @@ static void dump(J2kEncoderContext *s, FILE *fd)
band->codeblock_width, band->codeblock_height, band->codeblock_width, band->codeblock_height,
band->cblknx, band->cblkny); band->cblknx, band->cblkny);
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++){
J2kPrec *prec = band->prec + precno; Jpeg2000Prec *prec = band->prec + precno;
nspaces(fd, 10); nspaces(fd, 10);
fprintf(fd, "prec %d:\n", precno); fprintf(fd, "prec %d:\n", precno);
nspaces(fd, 10); nspaces(fd, 10);
@ -157,7 +157,7 @@ static void dump(J2kEncoderContext *s, FILE *fd)
/* bitstream routines */ /* bitstream routines */
/** put n times val bit */ /** put n times val bit */
static void put_bits(J2kEncoderContext *s, int val, int n) // TODO: optimize static void put_bits(Jpeg2000EncoderContext *s, int val, int n) // TODO: optimize
{ {
while (n-- > 0){ while (n-- > 0){
if (s->bit_index == 8) if (s->bit_index == 8)
@ -170,14 +170,14 @@ static void put_bits(J2kEncoderContext *s, int val, int n) // TODO: optimize
} }
/** put n least significant bits of a number num */ /** put n least significant bits of a number num */
static void put_num(J2kEncoderContext *s, int num, int n) static void put_num(Jpeg2000EncoderContext *s, int num, int n)
{ {
while(--n >= 0) while(--n >= 0)
put_bits(s, (num >> n) & 1, 1); put_bits(s, (num >> n) & 1, 1);
} }
/** flush the bitstream */ /** flush the bitstream */
static void j2k_flush(J2kEncoderContext *s) static void j2k_flush(Jpeg2000EncoderContext *s)
{ {
if (s->bit_index){ if (s->bit_index){
s->bit_index = 0; s->bit_index = 0;
@ -188,9 +188,9 @@ static void j2k_flush(J2kEncoderContext *s)
/* tag tree routines */ /* tag tree routines */
/** code the value stored in node */ /** code the value stored in node */
static void tag_tree_code(J2kEncoderContext *s, J2kTgtNode *node, int threshold) static void tag_tree_code(Jpeg2000EncoderContext *s, Jpeg2000TgtNode *node, int threshold)
{ {
J2kTgtNode *stack[30]; Jpeg2000TgtNode *stack[30];
int sp = 1, curval = 0; int sp = 1, curval = 0;
stack[0] = node; stack[0] = node;
@ -216,7 +216,7 @@ static void tag_tree_code(J2kEncoderContext *s, J2kTgtNode *node, int threshold)
} }
/** update the value in node */ /** update the value in node */
static void tag_tree_update(J2kTgtNode *node) static void tag_tree_update(Jpeg2000TgtNode *node)
{ {
int lev = 0; int lev = 0;
while (node->parent){ while (node->parent){
@ -228,7 +228,7 @@ static void tag_tree_update(J2kTgtNode *node)
} }
} }
static int put_siz(J2kEncoderContext *s) static int put_siz(Jpeg2000EncoderContext *s)
{ {
int i; int i;
@ -257,9 +257,9 @@ static int put_siz(J2kEncoderContext *s)
return 0; return 0;
} }
static int put_cod(J2kEncoderContext *s) static int put_cod(Jpeg2000EncoderContext *s)
{ {
J2kCodingStyle *codsty = &s->codsty; Jpeg2000CodingStyle *codsty = &s->codsty;
if (s->buf_end - s->buf < 14) if (s->buf_end - s->buf < 14)
return -1; return -1;
@ -284,11 +284,11 @@ static int put_cod(J2kEncoderContext *s)
return 0; return 0;
} }
static int put_qcd(J2kEncoderContext *s, int compno) static int put_qcd(Jpeg2000EncoderContext *s, int compno)
{ {
int i, size; int i, size;
J2kCodingStyle *codsty = &s->codsty; Jpeg2000CodingStyle *codsty = &s->codsty;
J2kQuantStyle *qntsty = &s->qntsty; Jpeg2000QuantStyle *qntsty = &s->qntsty;
if (qntsty->quantsty == J2K_QSTY_NONE) if (qntsty->quantsty == J2K_QSTY_NONE)
size = 4 + 3 * (codsty->nreslevels-1); size = 4 + 3 * (codsty->nreslevels-1);
@ -310,7 +310,7 @@ static int put_qcd(J2kEncoderContext *s, int compno)
return 0; return 0;
} }
static uint8_t *put_sot(J2kEncoderContext *s, int tileno) static uint8_t *put_sot(Jpeg2000EncoderContext *s, int tileno)
{ {
uint8_t *psotptr; uint8_t *psotptr;
@ -334,27 +334,27 @@ static uint8_t *put_sot(J2kEncoderContext *s, int tileno)
* allocate memory for them * allocate memory for them
* divide the input image into tile-components * divide the input image into tile-components
*/ */
static int init_tiles(J2kEncoderContext *s) static int init_tiles(Jpeg2000EncoderContext *s)
{ {
int tileno, tilex, tiley, compno; int tileno, tilex, tiley, compno;
J2kCodingStyle *codsty = &s->codsty; Jpeg2000CodingStyle *codsty = &s->codsty;
J2kQuantStyle *qntsty = &s->qntsty; Jpeg2000QuantStyle *qntsty = &s->qntsty;
s->numXtiles = ff_j2k_ceildiv(s->width, s->tile_width); s->numXtiles = ff_j2k_ceildiv(s->width, s->tile_width);
s->numYtiles = ff_j2k_ceildiv(s->height, s->tile_height); s->numYtiles = ff_j2k_ceildiv(s->height, s->tile_height);
s->tile = av_malloc(s->numXtiles * s->numYtiles * sizeof(J2kTile)); s->tile = av_malloc(s->numXtiles * s->numYtiles * sizeof(Jpeg2000Tile));
if (!s->tile) if (!s->tile)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
for (tileno = 0, tiley = 0; tiley < s->numYtiles; tiley++) for (tileno = 0, tiley = 0; tiley < s->numYtiles; tiley++)
for (tilex = 0; tilex < s->numXtiles; tilex++, tileno++){ for (tilex = 0; tilex < s->numXtiles; tilex++, tileno++){
J2kTile *tile = s->tile + tileno; Jpeg2000Tile *tile = s->tile + tileno;
tile->comp = av_malloc(s->ncomponents * sizeof(J2kComponent)); tile->comp = av_malloc(s->ncomponents * sizeof(Jpeg2000Component));
if (!tile->comp) if (!tile->comp)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
for (compno = 0; compno < s->ncomponents; compno++){ for (compno = 0; compno < s->ncomponents; compno++){
J2kComponent *comp = tile->comp + compno; Jpeg2000Component *comp = tile->comp + compno;
int ret, i, j; int ret, i, j;
comp->coord[0][0] = tilex * s->tile_width; comp->coord[0][0] = tilex * s->tile_width;
@ -373,15 +373,15 @@ static int init_tiles(J2kEncoderContext *s)
return 0; return 0;
} }
static void copy_frame(J2kEncoderContext *s) static void copy_frame(Jpeg2000EncoderContext *s)
{ {
int tileno, compno, i, y, x; int tileno, compno, i, y, x;
uint8_t *line; uint8_t *line;
for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
J2kTile *tile = s->tile + tileno; Jpeg2000Tile *tile = s->tile + tileno;
if (s->planar){ if (s->planar){
for (compno = 0; compno < s->ncomponents; compno++){ for (compno = 0; compno < s->ncomponents; compno++){
J2kComponent *comp = tile->comp + compno; Jpeg2000Component *comp = tile->comp + compno;
int *dst = comp->data; int *dst = comp->data;
line = s->picture.data[compno] line = s->picture.data[compno]
+ comp->coord[1][0] * s->picture.linesize[compno] + comp->coord[1][0] * s->picture.linesize[compno]
@ -411,11 +411,11 @@ static void copy_frame(J2kEncoderContext *s)
} }
} }
static void init_quantization(J2kEncoderContext *s) static void init_quantization(Jpeg2000EncoderContext *s)
{ {
int compno, reslevelno, bandno; int compno, reslevelno, bandno;
J2kQuantStyle *qntsty = &s->qntsty; Jpeg2000QuantStyle *qntsty = &s->qntsty;
J2kCodingStyle *codsty = &s->codsty; Jpeg2000CodingStyle *codsty = &s->codsty;
for (compno = 0; compno < s->ncomponents; compno++){ for (compno = 0; compno < s->ncomponents; compno++){
int gbandno = 0; int gbandno = 0;
@ -473,7 +473,7 @@ static int getnmsedec_ref(int x, int bpno)
return lut_nmsedec_ref0[x & ((1 << NMSEDEC_BITS) - 1)]; return lut_nmsedec_ref0[x & ((1 << NMSEDEC_BITS) - 1)];
} }
static void encode_sigpass(J2kT1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno) static void encode_sigpass(Jpeg2000T1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
{ {
int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS); int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS);
int vert_causal_ctx_csty_loc_symbol; int vert_causal_ctx_csty_loc_symbol;
@ -496,7 +496,7 @@ static void encode_sigpass(J2kT1Context *t1, int width, int height, int bandno,
} }
} }
static void encode_refpass(J2kT1Context *t1, int width, int height, int *nmsedec, int bpno) static void encode_refpass(Jpeg2000T1Context *t1, int width, int height, int *nmsedec, int bpno)
{ {
int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS); int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS);
for (y0 = 0; y0 < height; y0 += 4) for (y0 = 0; y0 < height; y0 += 4)
@ -510,7 +510,7 @@ static void encode_refpass(J2kT1Context *t1, int width, int height, int *nmsedec
} }
} }
static void encode_clnpass(J2kT1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno) static void encode_clnpass(Jpeg2000T1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
{ {
int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS); int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS);
int vert_causal_ctx_csty_loc_symbol; int vert_causal_ctx_csty_loc_symbol;
@ -566,7 +566,7 @@ static void encode_clnpass(J2kT1Context *t1, int width, int height, int bandno,
} }
} }
static void encode_cblk(J2kEncoderContext *s, J2kT1Context *t1, J2kCblk *cblk, J2kTile *tile, static void encode_cblk(Jpeg2000EncoderContext *s, Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk, Jpeg2000Tile *tile,
int width, int height, int bandpos, int lev) int width, int height, int bandpos, int lev)
{ {
int pass_t = 2, passno, x, y, max=0, nmsedec, bpno; int pass_t = 2, passno, x, y, max=0, nmsedec, bpno;
@ -625,7 +625,7 @@ static void encode_cblk(J2kEncoderContext *s, J2kT1Context *t1, J2kCblk *cblk, J
/* tier-2 routines: */ /* tier-2 routines: */
static void putnumpasses(J2kEncoderContext *s, int n) static void putnumpasses(Jpeg2000EncoderContext *s, int n)
{ {
if (n == 1) if (n == 1)
put_num(s, 0, 1); put_num(s, 0, 1);
@ -640,7 +640,7 @@ static void putnumpasses(J2kEncoderContext *s, int n)
} }
static int encode_packet(J2kEncoderContext *s, J2kResLevel *rlevel, int precno, static int encode_packet(Jpeg2000EncoderContext *s, Jpeg2000ResLevel *rlevel, int precno,
uint8_t *expn, int numgbits) uint8_t *expn, int numgbits)
{ {
int bandno, empty = 1; int bandno, empty = 1;
@ -667,8 +667,8 @@ static int encode_packet(J2kEncoderContext *s, J2kResLevel *rlevel, int precno,
} }
for (bandno = 0; bandno < rlevel->nbands; bandno++){ for (bandno = 0; bandno < rlevel->nbands; bandno++){
J2kBand *band = rlevel->band + bandno; Jpeg2000Band *band = rlevel->band + bandno;
J2kPrec *prec = band->prec + precno; Jpeg2000Prec *prec = band->prec + precno;
int yi, xi, pos; int yi, xi, pos;
int cblknw = prec->xi1 - prec->xi0; int cblknw = prec->xi1 - prec->xi0;
@ -688,7 +688,7 @@ static int encode_packet(J2kEncoderContext *s, J2kResLevel *rlevel, int precno,
for (pos=0, yi = prec->yi0; yi < prec->yi1; yi++){ for (pos=0, yi = prec->yi0; yi < prec->yi1; yi++){
for (xi = prec->xi0; xi < prec->xi1; xi++, pos++){ for (xi = prec->xi0; xi < prec->xi1; xi++, pos++){
int pad = 0, llen, length; int pad = 0, llen, length;
J2kCblk *cblk = band->cblk + yi * cblknw + xi; Jpeg2000Cblk *cblk = band->cblk + yi * cblknw + xi;
if (s->buf_end - s->buf < 20) // approximately if (s->buf_end - s->buf < 20) // approximately
return -1; return -1;
@ -717,13 +717,13 @@ static int encode_packet(J2kEncoderContext *s, J2kResLevel *rlevel, int precno,
} }
j2k_flush(s); j2k_flush(s);
for (bandno = 0; bandno < rlevel->nbands; bandno++){ for (bandno = 0; bandno < rlevel->nbands; bandno++){
J2kBand *band = rlevel->band + bandno; Jpeg2000Band *band = rlevel->band + bandno;
J2kPrec *prec = band->prec + precno; Jpeg2000Prec *prec = band->prec + precno;
int yi, cblknw = prec->xi1 - prec->xi0; int yi, cblknw = prec->xi1 - prec->xi0;
for (yi = prec->yi0; yi < prec->yi1; yi++){ for (yi = prec->yi0; yi < prec->yi1; yi++){
int xi; int xi;
for (xi = prec->xi0; xi < prec->xi1; xi++){ for (xi = prec->xi0; xi < prec->xi1; xi++){
J2kCblk *cblk = band->cblk + yi * cblknw + xi; Jpeg2000Cblk *cblk = band->cblk + yi * cblknw + xi;
if (cblk->ninclpasses){ if (cblk->ninclpasses){
if (s->buf_end - s->buf < cblk->passes[cblk->ninclpasses-1].rate) if (s->buf_end - s->buf < cblk->passes[cblk->ninclpasses-1].rate)
return -1; return -1;
@ -735,18 +735,18 @@ static int encode_packet(J2kEncoderContext *s, J2kResLevel *rlevel, int precno,
return 0; return 0;
} }
static int encode_packets(J2kEncoderContext *s, J2kTile *tile, int tileno) static int encode_packets(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno)
{ {
int compno, reslevelno, ret; int compno, reslevelno, ret;
J2kCodingStyle *codsty = &s->codsty; Jpeg2000CodingStyle *codsty = &s->codsty;
J2kQuantStyle *qntsty = &s->qntsty; Jpeg2000QuantStyle *qntsty = &s->qntsty;
av_log(s->avctx, AV_LOG_DEBUG, "tier2\n"); av_log(s->avctx, AV_LOG_DEBUG, "tier2\n");
// lay-rlevel-comp-pos progression // lay-rlevel-comp-pos progression
for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
for (compno = 0; compno < s->ncomponents; compno++){ for (compno = 0; compno < s->ncomponents; compno++){
int precno; int precno;
J2kResLevel *reslevel = s->tile[tileno].comp[compno].reslevel + reslevelno; Jpeg2000ResLevel *reslevel = s->tile[tileno].comp[compno].reslevel + reslevelno;
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++){
if (ret = encode_packet(s, reslevel, precno, qntsty->expn + (reslevelno ? 3*reslevelno-2 : 0), if (ret = encode_packet(s, reslevel, precno, qntsty->expn + (reslevelno ? 3*reslevelno-2 : 0),
qntsty->nguardbits)) qntsty->nguardbits))
@ -758,7 +758,7 @@ static int encode_packets(J2kEncoderContext *s, J2kTile *tile, int tileno)
return 0; return 0;
} }
static int getcut(J2kCblk *cblk, int64_t lambda, int dwt_norm) static int getcut(Jpeg2000Cblk *cblk, int64_t lambda, int dwt_norm)
{ {
int passno, res = 0; int passno, res = 0;
for (passno = 0; passno < cblk->npasses; passno++){ for (passno = 0; passno < cblk->npasses; passno++){
@ -776,23 +776,23 @@ static int getcut(J2kCblk *cblk, int64_t lambda, int dwt_norm)
return res; return res;
} }
static void truncpasses(J2kEncoderContext *s, J2kTile *tile) static void truncpasses(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile)
{ {
int compno, reslevelno, bandno, cblkno, lev; int compno, reslevelno, bandno, cblkno, lev;
J2kCodingStyle *codsty = &s->codsty; Jpeg2000CodingStyle *codsty = &s->codsty;
for (compno = 0; compno < s->ncomponents; compno++){ for (compno = 0; compno < s->ncomponents; compno++){
J2kComponent *comp = tile->comp + compno; Jpeg2000Component *comp = tile->comp + compno;
for (reslevelno = 0, lev = codsty->nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++, lev--){ for (reslevelno = 0, lev = codsty->nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++, lev--){
J2kResLevel *reslevel = comp->reslevel + reslevelno; Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
for (bandno = 0; bandno < reslevel->nbands ; bandno++){ for (bandno = 0; bandno < reslevel->nbands ; bandno++){
int bandpos = bandno + (reslevelno > 0); int bandpos = bandno + (reslevelno > 0);
J2kBand *band = reslevel->band + bandno; Jpeg2000Band *band = reslevel->band + bandno;
for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){ for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){
J2kCblk *cblk = band->cblk + cblkno; Jpeg2000Cblk *cblk = band->cblk + cblkno;
cblk->ninclpasses = getcut(cblk, s->lambda, cblk->ninclpasses = getcut(cblk, s->lambda,
(int64_t)dwt_norms[codsty->transform][bandpos][lev] * (int64_t)band->stepsize >> 13); (int64_t)dwt_norms[codsty->transform][bandpos][lev] * (int64_t)band->stepsize >> 13);
@ -802,13 +802,13 @@ static void truncpasses(J2kEncoderContext *s, J2kTile *tile)
} }
} }
static int encode_tile(J2kEncoderContext *s, J2kTile *tile, int tileno) static int encode_tile(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno)
{ {
int compno, reslevelno, bandno, ret; int compno, reslevelno, bandno, ret;
J2kT1Context t1; Jpeg2000T1Context t1;
J2kCodingStyle *codsty = &s->codsty; Jpeg2000CodingStyle *codsty = &s->codsty;
for (compno = 0; compno < s->ncomponents; compno++){ for (compno = 0; compno < s->ncomponents; compno++){
J2kComponent *comp = s->tile[tileno].comp + compno; Jpeg2000Component *comp = s->tile[tileno].comp + compno;
av_log(s->avctx, AV_LOG_DEBUG,"dwt\n"); av_log(s->avctx, AV_LOG_DEBUG,"dwt\n");
if (ret = ff_j2k_dwt_encode(&comp->dwt, comp->data)) if (ret = ff_j2k_dwt_encode(&comp->dwt, comp->data))
@ -816,10 +816,10 @@ static int encode_tile(J2kEncoderContext *s, J2kTile *tile, int tileno)
av_log(s->avctx, AV_LOG_DEBUG,"after dwt -> tier1\n"); av_log(s->avctx, AV_LOG_DEBUG,"after dwt -> tier1\n");
for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
J2kResLevel *reslevel = comp->reslevel + reslevelno; Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
for (bandno = 0; bandno < reslevel->nbands ; bandno++){ for (bandno = 0; bandno < reslevel->nbands ; bandno++){
J2kBand *band = reslevel->band + bandno; Jpeg2000Band *band = reslevel->band + bandno;
int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos; int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
yy0 = bandno == 0 ? 0 : comp->reslevel[reslevelno-1].coord[1][1] - comp->reslevel[reslevelno-1].coord[1][0]; yy0 = bandno == 0 ? 0 : comp->reslevel[reslevelno-1].coord[1][1] - comp->reslevel[reslevelno-1].coord[1][0];
y0 = yy0; y0 = yy0;
@ -880,14 +880,14 @@ static int encode_tile(J2kEncoderContext *s, J2kTile *tile, int tileno)
return 0; return 0;
} }
static void cleanup(J2kEncoderContext *s) static void cleanup(Jpeg2000EncoderContext *s)
{ {
int tileno, compno; int tileno, compno;
J2kCodingStyle *codsty = &s->codsty; Jpeg2000CodingStyle *codsty = &s->codsty;
for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
for (compno = 0; compno < s->ncomponents; compno++){ for (compno = 0; compno < s->ncomponents; compno++){
J2kComponent *comp = s->tile[tileno].comp + compno; Jpeg2000Component *comp = s->tile[tileno].comp + compno;
ff_j2k_cleanup(comp, codsty); ff_j2k_cleanup(comp, codsty);
} }
av_freep(&s->tile[tileno].comp); av_freep(&s->tile[tileno].comp);
@ -895,11 +895,11 @@ static void cleanup(J2kEncoderContext *s)
av_freep(&s->tile); av_freep(&s->tile);
} }
static void reinit(J2kEncoderContext *s) static void reinit(Jpeg2000EncoderContext *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++){
J2kTile *tile = s->tile + tileno; Jpeg2000Tile *tile = s->tile + tileno;
for (compno = 0; compno < s->ncomponents; compno++) for (compno = 0; compno < s->ncomponents; compno++)
ff_j2k_reinit(tile->comp + compno, &s->codsty); ff_j2k_reinit(tile->comp + compno, &s->codsty);
} }
@ -909,7 +909,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pict, int *got_packet) const AVFrame *pict, int *got_packet)
{ {
int tileno, ret; int tileno, ret;
J2kEncoderContext *s = avctx->priv_data; Jpeg2000EncoderContext *s = avctx->priv_data;
if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width*avctx->height*9 + FF_MIN_BUFFER_SIZE)) < 0) if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width*avctx->height*9 + FF_MIN_BUFFER_SIZE)) < 0)
return ret; return ret;
@ -962,9 +962,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
static av_cold int j2kenc_init(AVCodecContext *avctx) static av_cold int j2kenc_init(AVCodecContext *avctx)
{ {
int i, ret; int i, ret;
J2kEncoderContext *s = avctx->priv_data; Jpeg2000EncoderContext *s = avctx->priv_data;
J2kCodingStyle *codsty = &s->codsty; Jpeg2000CodingStyle *codsty = &s->codsty;
J2kQuantStyle *qntsty = &s->qntsty; Jpeg2000QuantStyle *qntsty = &s->qntsty;
s->avctx = avctx; s->avctx = avctx;
av_log(s->avctx, AV_LOG_DEBUG, "init\n"); av_log(s->avctx, AV_LOG_DEBUG, "init\n");
@ -1020,7 +1020,7 @@ static av_cold int j2kenc_init(AVCodecContext *avctx)
static int j2kenc_destroy(AVCodecContext *avctx) static int j2kenc_destroy(AVCodecContext *avctx)
{ {
J2kEncoderContext *s = avctx->priv_data; Jpeg2000EncoderContext *s = avctx->priv_data;
cleanup(s); cleanup(s);
return 0; return 0;
@ -1030,7 +1030,7 @@ AVCodec ff_j2k_encoder = {
.name = "j2k", .name = "j2k",
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_JPEG2000, .id = AV_CODEC_ID_JPEG2000,
.priv_data_size = sizeof(J2kEncoderContext), .priv_data_size = sizeof(Jpeg2000EncoderContext),
.init = j2kenc_init, .init = j2kenc_init,
.encode2 = encode_frame, .encode2 = encode_frame,
.close = j2kenc_destroy, .close = j2kenc_destroy,