37 #define SHL(a, n) ((n) >= 0 ? (a) << (n) : (a) >> -(n))
45 while (w > 1 || h > 1) {
46 res += w * (int64_t)h;
66 while (w > 1 || h > 1) {
75 for (i = 0; i < ph; i++)
76 for (j = 0; j < pw; j++)
77 t[i * pw + j].parent = &t2[(i >> 1) * w + (j >> 1)];
89 for (i = 0; i < siz; i++) {
113 if (h == 2)
return 8;
115 if (v >= 1)
return 7;
116 if (d >= 1)
return 6;
119 if (v == 2)
return 4;
120 if (v == 1)
return 3;
121 if (d >= 2)
return 2;
122 if (d == 1)
return 1;
124 if (d >= 3)
return 8;
126 if (h+v >= 1)
return 7;
130 if (h+v >= 2)
return 5;
131 if (h+v == 1)
return 4;
134 if (h+v >= 2)
return 2;
135 if (h+v == 1)
return 1;
142 static const int contribtab[3][3] = { { 0, -1, 1 }, { -1, -1, 0 }, { 1, 0, 1 } };
143 static const int ctxlbltab[3][3] = { { 13, 12, 11 }, { 10, 9, 10 }, { 11, 12, 13 } };
144 static const int xorbittab[3][3] = { { 1, 1, 1 }, { 1, 0, 0 }, { 0, 0, 0 } };
148 int vcontrib, hcontrib;
162 for (i = 0; i < 256; i++)
163 for (j = 0; j < 4; j++)
165 for (i = 0; i < 16; i++)
166 for (j = 0; j < 16; j++)
200 int bandno,
int gbandno,
int reslevelno,
235 switch (bandno + (reslevelno > 0)) {
261 int precno,
int bandno,
int reslevelno,
262 int log2_band_prec_width,
263 int log2_band_prec_height)
266 int nb_codeblocks, cblkno;
275 (1 << log2_band_prec_width);
279 (1 << log2_band_prec_height);
283 (1 << log2_band_prec_width);
289 (1 << log2_band_prec_height);
324 for (cblkno = 0; cblkno < nb_codeblocks; cblkno++) {
347 if ((bandno + !!reslevelno) & 1) {
353 if ((bandno + !!reslevelno) & 2) {
375 int bandno,
int gbandno,
int reslevelno,
376 int cbps,
int dx,
int dy)
379 uint8_t log2_band_prec_width, log2_band_prec_height;
391 if (reslevelno == 0) {
393 for (i = 0; i < 2; i++)
394 for (j = 0; j < 2; j++)
408 for (i = 0; i < 2; i++)
409 for (j = 0; j < 2; j++)
413 (((bandno + 1 >> i) & 1LL) << declvl - 1),
437 for (precno = 0; precno < nb_precincts; precno++) {
439 precno, bandno, reslevelno,
440 log2_band_prec_width, log2_band_prec_height);
451 int cbps,
int dx,
int dy,
454 int reslevelno, bandno, gbandno = 0, ret, i, j;
468 comp->
coord[1][1] - comp->
coord[1][0], 0, avctx))
470 csize = (comp->
coord[0][1] - comp->
coord[0][0]) *
472 if (comp->
coord[0][1] - comp->
coord[0][0] > 32768 ||
473 comp->
coord[1][1] - comp->
coord[1][0] > 32768) {
495 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
502 for (i = 0; i < 2; i++)
503 for (j = 0; j < 2; j++)
504 reslevel->
coord[i][j] =
526 if (reslevel->
coord[0][1] == reslevel->
coord[0][0])
534 if (reslevel->
coord[1][1] == reslevel->
coord[1][0])
546 for (bandno = 0; bandno < reslevel->
nbands; bandno++, gbandno++) {
548 comp, codsty, qntsty,
549 bandno, gbandno, reslevelno,
560 int reslevelno, bandno, cblkno, precno;
561 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
563 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
581 int reslevelno, bandno, precno;
590 reslevel = comp->
reslevel + reslevelno;
591 for (bandno = 0; bandno < reslevel->
nbands; bandno++) {
597 band = reslevel->
band + bandno;
uint8_t ff_jpeg2000_sgnctxno_lut[16][16]
const struct AVCodec * codec
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_cold ff_jpeg2000_init_tier1_luts(void)
void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
Jpeg2000TgtNode * cblkincl
static int init_prec(Jpeg2000Band *band, Jpeg2000ResLevel *reslevel, Jpeg2000Component *comp, int precno, int bandno, int reslevelno, int log2_band_prec_width, int log2_band_prec_height)
Memory handling functions.
uint16_t mant[JPEG2000_MAX_DECLEVELS *3]
static const int contribtab[3][3]
static const int xorbittab[3][3]
static void tag_tree_zero(Jpeg2000TgtNode *t, int w, int h)
static Jpeg2000TgtNode * ff_jpeg2000_tag_tree_init(int w, int h)
Macro definitions for various function/variable attributes.
int av_codec_is_encoder(const AVCodec *codec)
#define JPEG2000_T1_SIG_W
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Jpeg2000TgtNode * zerobits
#define JPEG2000_T1_SIG_NE
#define JPEG2000_T1_SIG_SE
static const int ctxlbltab[3][3]
uint8_t log2_prec_widths[JPEG2000_MAX_RESLEVELS]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ff_jpeg2000_dwt_init(DWTContext *s, int border[2][2], int decomp_levels, int type)
Initialize DWT.
static int init_band(AVCodecContext *avctx, Jpeg2000ResLevel *reslevel, Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int bandno, int gbandno, int reslevelno, int cbps, int dx, int dy)
void ff_jpeg2000_set_significance(Jpeg2000T1Context *t1, int x, int y, int negative)
uint8_t log2_prec_heights[JPEG2000_MAX_RESLEVELS]
simple assert() macros that are a bit more flexible than ISO C assert().
static void init_band_stepsize(AVCodecContext *avctx, Jpeg2000Band *band, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int bandno, int gbandno, int reslevelno, int cbps)
static av_always_inline float ff_exp2fi(int x)
2^(x) for integer x
static void * av_mallocz_array(size_t nmemb, size_t size)
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
struct Jpeg2000TgtNode * parent
#define JPEG2000_T1_SGN_S
JPEG 2000 structures and defines common to encoder and decoder.
void ff_dwt_destroy(DWTContext *s)
static int32_t tag_tree_size(int w, int h)
#define JPEG2000_T1_SIG_N
uint16_t lengthinc[JPEG2000_MAX_PASSES]
static int ff_jpeg2000_ceildivpow2(int a, int b)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Libavcodec external API header.
main external API structure.
#define JPEG2000_T1_SIG_S
Jpeg2000ResLevel * reslevel
void ff_jpeg2000_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
#define JPEG2000_T1_SGN_E
uint8_t expn[JPEG2000_MAX_DECLEVELS *3]
common internal api header.
common internal and external API header
uint16_t log2_cblk_height
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int ff_jpeg2000_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int cbps, int dx, int dy, AVCodecContext *avctx)
#define JPEG2000_T1_SIG_SW
#define JPEG2000_T1_SGN_N
static int getsgnctxno(int flag, uint8_t *xorbit)
#define JPEG2000_T1_SIG_E
static int getsigctxno(int flag, int bandno)
#define FFSWAP(type, a, b)
uint8_t ff_jpeg2000_sigctxno_lut[256][4]
#define JPEG2000_T1_SIG_NW
#define JPEG2000_T1_SGN_W
uint8_t ff_jpeg2000_xorbit_lut[16][16]