28 #include "libavutil/avassert.h"
29 #include "libavutil/common.h"
30 #include "libavutil/mem.h"
34 #define SHL(a, n) ((n) >= 0 ? (a) << (n) : (a) >> -(n))
42 while (w > 1 || h > 1) {
63 while (w > 1 || h > 1) {
72 for (i = 0; i < ph; i++)
73 for (j = 0; j < pw; j++)
74 t[i * pw + j].parent = &t2[(i >> 1) * w + (j >> 1)];
86 for (i = 0; i < siz; i++) {
110 if (h == 2)
return 8;
112 if (v >= 1)
return 7;
113 if (d >= 1)
return 6;
116 if (v == 2)
return 4;
117 if (v == 1)
return 3;
118 if (d >= 2)
return 2;
119 if (d == 1)
return 1;
121 if (d >= 3)
return 8;
123 if (h+v >= 1)
return 7;
127 if (h+v >= 2)
return 5;
128 if (h+v == 1)
return 4;
131 if (h+v >= 2)
return 2;
132 if (h+v == 1)
return 1;
139 static const int contribtab[3][3] = { { 0, -1, 1 }, { -1, -1, 0 }, { 1, 0, 1 } };
140 static const int ctxlbltab[3][3] = { { 13, 12, 11 }, { 10, 9, 10 }, { 11, 12, 13 } };
141 static const int xorbittab[3][3] = { { 1, 1, 1 }, { 1, 0, 0 }, { 0, 0, 0 } };
145 int vcontrib, hcontrib;
159 for (i = 0; i < 256; i++)
160 for (j = 0; j < 4; j++)
162 for (i = 0; i < 16; i++)
163 for (j = 0; j < 16; j++)
196 int cbps,
int dx,
int dy,
199 uint8_t log2_band_prec_width, log2_band_prec_height;
200 int reslevelno, bandno, gbandno = 0,
ret, i, j;
213 csize = (comp->
coord[0][1] - comp->
coord[0][0]) *
231 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
238 for (i = 0; i < 2; i++)
239 for (j = 0; j < 2; j++)
240 reslevel->
coord[i][j] =
259 if (reslevel->
coord[0][1] == reslevel->
coord[0][0])
267 if (reslevel->
coord[1][1] == reslevel->
coord[1][0])
279 for (bandno = 0; bandno < reslevel->
nbands; bandno++, gbandno++) {
298 2 + numbps - qntsty->
expn[gbandno]);
329 if (reslevelno == 0) {
331 for (i = 0; i < 2; i++)
332 for (j = 0; j < 2; j++)
346 for (i = 0; i < 2; i++)
347 for (j = 0; j < 2; j++)
351 (((bandno + 1 >> i) & 1) << declvl - 1),
366 for (j = 0; j < 2; j++)
368 for (j = 0; j < 2; j++)
373 sizeof(*band->
prec));
379 for (precno = 0; precno < nb_precincts; precno++) {
387 (1 << log2_band_prec_width);
392 (1 << log2_band_prec_height);
397 (1 << log2_band_prec_width);
402 (1 << log2_band_prec_height);
429 sizeof(*prec->
cblk));
455 if ((bandno + !!reslevelno) & 1) {
461 if ((bandno + !!reslevelno) & 2) {
482 int reslevelno, bandno, cblkno, precno;
483 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
485 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
503 int reslevelno, bandno, precno;
509 for (bandno = 0; bandno < reslevel->
nbands; bandno++) {
510 if (reslevel->
band) {
uint8_t ff_jpeg2000_sgnctxno_lut[16][16]
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
int flags[JPEG2000_MAX_CBLKW+2][JPEG2000_MAX_CBLKH+2]
void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
Jpeg2000TgtNode * cblkincl
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
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)
uint16_t nb_codeblocks_height
static Jpeg2000TgtNode * ff_jpeg2000_tag_tree_init(int w, int h)
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int av_codec_is_encoder(const AVCodec *codec)
#define JPEG2000_T1_SIG_W
static const uint8_t lut_gain[2][4]
Jpeg2000TgtNode * zerobits
int ff_jpeg2000_dwt_init(DWTContext *s, uint16_t border[2][2], int decomp_levels, int type)
Initialize DWT.
#define JPEG2000_T1_SIG_NE
#define FFSWAP(type, a, b)
#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.
void ff_jpeg2000_set_significance(Jpeg2000T1Context *t1, int x, int y, int negative)
uint8_t log2_prec_heights[JPEG2000_MAX_RESLEVELS]
Libavcodec external API header.
struct Jpeg2000TgtNode * parent
void ff_jpeg2000_init_tier1_luts(void)
#define JPEG2000_T1_SGN_S
JPEG 2000 structures and defines common to encoder and decoder.
void ff_dwt_destroy(DWTContext *s)
#define JPEG2000_T1_SIG_N
static int ff_jpeg2000_ceildivpow2(int a, int b)
main external API structure.
uint16_t nb_codeblocks_width
#define JPEG2000_T1_SIG_S
Jpeg2000ResLevel * reslevel
static int ff_jpeg2000_ceildiv(int a, int b)
void ff_jpeg2000_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
#define JPEG2000_T1_SGN_E
uint8_t expn[JPEG2000_MAX_DECLEVELS *3]
uint16_t log2_cblk_height
static int32_t tag_tree_size(uint16_t w, uint16_t h)
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
#define AVERROR_INVALIDDATA
static int getsgnctxno(int flag, uint8_t *xorbit)
#define JPEG2000_T1_SIG_E
static void * av_mallocz_array(size_t nmemb, size_t size)
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
static int getsigctxno(int flag, int bandno)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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]