74 #define NMSEDEC_BITS 7
75 #define NMSEDEC_FRACBITS (NMSEDEC_BITS-1)
76 #define WMSEDEC_SHIFT 13
77 #define LAMBDA_SCALE (100000000LL << (WMSEDEC_SHIFT - 13))
88 {{10000, 19650, 41770, 84030, 169000, 338400, 676900, 1353000, 2706000, 5409000},
89 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
90 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
91 {20800, 38650, 83070, 171800, 347100, 695900, 1393000, 2786000, 5572000}},
93 {{10000, 15000, 27500, 53750, 106800, 213400, 426700, 853300, 1707000, 3413000},
94 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
95 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
96 { 7186, 9218, 15860, 30430, 60190, 120100, 240000, 479700, 959300}}
138 static void nspaces(FILE *fd,
int n)
140 while(n--) putc(
' ', fd);
146 for (i = 0; i < comp->y1 - comp->y0; i++)
147 ff_jpeg2000_printv(comp->
i_data + i * (comp->x1 - comp->x0), comp->x1 - comp->x0);
152 int tileno, compno, reslevelno, bandno, precno;
153 fprintf(fd,
"XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n"
154 "numXtiles = %d, numYtiles = %d, ncomponents = %d\n"
161 fprintf(fd,
"tile %d:\n", tileno);
162 for(compno = 0; compno < s->
ncomponents; compno++){
165 fprintf(fd,
"component %d:\n", compno);
167 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
168 comp->x0, comp->x1, comp->y0, comp->y1);
169 for(reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
172 fprintf(fd,
"reslevel %d:\n", reslevelno);
174 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n",
175 reslevel->x0, reslevel->x1, reslevel->y0,
176 reslevel->y1, reslevel->
nbands);
177 for(bandno = 0; bandno < reslevel->
nbands; bandno++){
180 fprintf(fd,
"band %d:\n", bandno);
182 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d,"
183 "codeblock_width = %d, codeblock_height = %d cblknx = %d cblkny = %d\n",
186 band->codeblock_width, band->codeblock_height,
187 band->cblknx, band->cblkny);
191 fprintf(fd,
"prec %d:\n", precno);
193 fprintf(fd,
"xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n",
194 prec->xi0, prec->xi1, prec->yi0, prec->yi1);
240 int sp = 1, curval = 0;
254 if (stack[sp]->
val >= threshold){
260 curval = stack[
sp]->
val;
286 bytestream_put_be16(&s->
buf, 0);
287 bytestream_put_be32(&s->
buf, s->
width);
289 bytestream_put_be32(&s->
buf, 0);
290 bytestream_put_be32(&s->
buf, 0);
294 bytestream_put_be32(&s->
buf, 0);
295 bytestream_put_be32(&s->
buf, 0);
299 bytestream_put_byte(&s->
buf, 7);
314 bytestream_put_be16(&s->
buf, 12);
315 bytestream_put_byte(&s->
buf, 0);
317 bytestream_put_byte(&s->
buf, 0);
318 bytestream_put_be16(&s->
buf, 1);
320 bytestream_put_byte(&s->
buf, 0);
322 bytestream_put_byte(&s->
buf, 0);
328 bytestream_put_byte(&s->
buf, 0);
348 bytestream_put_be16(&s->
buf, size);
351 for (i = 0; i < codsty->
nreslevels * 3 - 2; i++)
352 bytestream_put_byte(&s->
buf, qntsty->
expn[i] << 3);
354 for (i = 0; i < codsty->
nreslevels * 3 - 2; i++)
355 bytestream_put_be16(&s->
buf, (qntsty->
expn[i] << 11) | qntsty->
mant[i]);
370 bytestream_put_be16(&s->
buf, size);
371 bytestream_put_be16(&s->
buf, 1);
386 bytestream_put_be16(&s->
buf, 10);
387 bytestream_put_be16(&s->
buf, tileno);
390 bytestream_put_be32(&s->
buf, 0);
392 bytestream_put_byte(&s->
buf, 0);
393 bytestream_put_byte(&s->
buf, 1);
404 int tileno, tilex, tiley, compno;
414 for (tileno = 0, tiley = 0; tiley < s->
numYtiles; tiley++)
415 for (tilex = 0; tilex < s->
numXtiles; tilex++, tileno++){
421 for (compno = 0; compno < s->
ncomponents; compno++){
430 for (i = 0; i < 2; i++)
431 for (j = 0; j < 2; j++)
450 int tileno, compno, i, y, x;
455 for (compno = 0; compno < s->
ncomponents; compno++){
461 for (y = comp->
coord[1][0]; y < comp->coord[1][1]; y++){
463 for (x = comp->
coord[0][0]; x < comp->coord[0][1]; x++)
464 *dst++ = *ptr++ - (1 << 7);
473 for (y = tile->
comp[0].
coord[1][0]; y < tile->comp[0].
coord[1][1]; y++){
475 for (x = tile->
comp[0].
coord[0][0]; x < tile->comp[0].
coord[0][1]; x++, i++){
476 for (compno = 0; compno < s->
ncomponents; compno++){
477 tile->
comp[compno].
i_data[i] = *ptr++ - (1 << 7);
488 int compno, reslevelno, bandno;
492 for (compno = 0; compno < s->
ncomponents; compno++){
494 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
495 int nbands, lev = codsty->
nreslevels - reslevelno - 1;
496 nbands = reslevelno ? 3 : 1;
497 for (bandno = 0; bandno < nbands; bandno++, gbandno++){
501 int bandpos = bandno + (reslevelno>0),
504 mant = (11 - log < 0 ? ss >> log - 11 :
ss << 11 - log) & 0x7ff;
505 expn = s->
cbps[compno] - log + 13;
507 expn = ((bandno&2)>>1) + (reslevelno>0) + s->
cbps[compno];
509 qntsty->
expn[gbandno] = expn;
510 qntsty->
mant[gbandno] = mant;
551 for (y0 = 0; y0 <
height; y0 += 4)
552 for (x = 0; x <
width; x++)
553 for (y = y0; y < height && y < y0+4; y++){
556 bit = t1->
data[(y) * t1->
stride + x] & mask ? 1 : 0;
573 for (y0 = 0; y0 <
height; y0 += 4)
574 for (x = 0; x <
width; x++)
575 for (y = y0; y < height && y < y0+4; y++)
587 for (y0 = 0; y0 <
height; y0 += 4)
588 for (x = 0; x <
width; x++){
589 if (y0 + 3 < height && !(
597 for (rlen = 0; rlen < 4; rlen++)
605 for (y = y0 + rlen; y < y0 + 4; y++){
621 for (y = y0; y < y0 + 4 && y <
height; y++){
642 int pass_t = 2, passno, x, y, max=0, nmsedec, bpno;
647 for (y = 0; y <
height; y++){
648 for (x = 0; x <
width; x++){
667 for (passno = 0; bpno >= 0; passno++){
671 case 0:
encode_sigpass(t1, width, height, bandpos, &nmsedec, bpno);
675 case 2:
encode_clnpass(t1, width, height, bandpos, &nmsedec, bpno);
680 wmsedec += (int64_t)nmsedec << (2*bpno);
708 put_num(s, 0xff80 | (n-37), 16);
715 int bandno, empty = 1;
724 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
738 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
749 for (xi = 0; xi < cblknw; xi++, pos++){
758 for (xi = 0; xi < cblknw; xi++, pos++){
759 int pad = 0, llen,
length;
788 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
794 for (xi = 0; xi < cblknw; xi++){
812 int compno, reslevelno, ret;
818 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
819 for (compno = 0; compno < s->
ncomponents; compno++){
823 if ((ret =
encode_packet(s, reslevel, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
836 for (passno = 0; passno < cblk->
npasses; passno++){
845 if (((dd * dwt_norm) >>
WMSEDEC_SHIFT) * dwt_norm >= dr * lambda)
853 int precno, compno, reslevelno, bandno, cblkno, lev;
856 for (compno = 0; compno < s->
ncomponents; compno++){
859 for (reslevelno = 0, lev = codsty->
nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++, lev--){
863 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
864 int bandpos = bandno + (reslevelno > 0);
882 int compno, reslevelno, bandno, ret;
885 for (compno = 0; compno < s->
ncomponents; compno++){
895 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
898 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
901 int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
910 bandpos = bandno + (reslevelno > 0);
913 if (reslevelno == 0 || bandno == 1)
924 for (y = yy0; y < yy1; y++){
926 for (x = xx0; x < xx1; x++){
931 for (y = yy0; y < yy1; y++){
933 for (x = xx0; x < xx1; x++){
941 bandpos, codsty->
nreslevels - reslevelno - 1);
967 for (compno = 0; compno < s->
ncomponents; compno++){
981 for (compno = 0; compno < s->
ncomponents; compno++)
992 const AVFrame *pict,
int *got_packet)
996 uint8_t *chunkstart, *jp2cstart, *jp2hstart;
1015 bytestream_put_be32(&s->
buf, 0x0000000C);
1016 bytestream_put_be32(&s->
buf, 0x6A502020);
1017 bytestream_put_be32(&s->
buf, 0x0D0A870A);
1019 chunkstart = s->
buf;
1020 bytestream_put_be32(&s->
buf, 0);
1023 bytestream_put_be32(&s->
buf, 0);
1028 bytestream_put_be32(&s->
buf, 0);
1031 chunkstart = s->
buf;
1032 bytestream_put_be32(&s->
buf, 0);
1034 bytestream_put_be32(&s->
buf, avctx->
height);
1035 bytestream_put_be32(&s->
buf, avctx->
width);
1037 bytestream_put_byte(&s->
buf, s->
cbps[0]);
1038 bytestream_put_byte(&s->
buf, 7);
1039 bytestream_put_byte(&s->
buf, 0);
1040 bytestream_put_byte(&s->
buf, 0);
1043 chunkstart = s->
buf;
1044 bytestream_put_be32(&s->
buf, 0);
1046 bytestream_put_byte(&s->
buf, 1);
1047 bytestream_put_byte(&s->
buf, 0);
1048 bytestream_put_byte(&s->
buf, 0);
1050 bytestream_put_be32(&s->
buf, 17);
1052 bytestream_put_be32(&s->
buf, 16);
1054 bytestream_put_be32(&s->
buf, 18);
1060 bytestream_put_be32(&s->
buf, 0);
1071 if ((ret =
put_qcd(s, 0)) < 0)
1073 if ((ret =
put_com(s, 0)) < 0)
1078 if (!(psotptr =
put_sot(s, tileno)))
1085 bytestream_put_be32(&psotptr, s->
buf - psotptr + 6);
1112 #if FF_API_PRIVATE_OPT
1144 for (i = 0; i < 3; i++)
1181 #define OFFSET(x) offsetof(Jpeg2000EncoderContext, x)
1182 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
static int getcut(Jpeg2000Cblk *cblk, int64_t lambda, int dwt_norm)
const char const char void * val
void av_cold ff_jpeg2000_init_tier1_luts(void)
void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
This structure describes decoded (raw) audio or video data.
Jpeg2000TgtNode * cblkincl
static void cleanup(Jpeg2000EncoderContext *s)
#define JPEG2000_T1_SIG_NB
AVCodec ff_jpeg2000_encoder
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
packed RGB 8:8:8, 24bpp, RGBRGB...
static av_cold int init(AVCodecContext *avctx)
Jpeg2000QuantStyle qntsty
static int lut_nmsedec_ref[1<< NMSEDEC_BITS]
static av_cold int j2kenc_init(AVCodecContext *avctx)
static int put_com(Jpeg2000EncoderContext *s, int compno)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
uint16_t mant[JPEG2000_MAX_DECLEVELS *3]
void ff_mqc_initenc(MqcState *mqc, uint8_t *bp)
initialize the encoder
static void tag_tree_code(Jpeg2000EncoderContext *s, Jpeg2000TgtNode *node, int threshold)
code the value stored in node
static void tag_tree_update(Jpeg2000TgtNode *node)
update the value in node
static void update_size(uint8_t *size, const uint8_t *end)
static int getnmsedec_ref(int x, int bpno)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int lut_nmsedec_ref0[1<< NMSEDEC_BITS]
static int encode_packet(Jpeg2000EncoderContext *s, Jpeg2000ResLevel *rlevel, int precno, uint8_t *expn, int numgbits)
static av_cold int end(AVCodecContext *avctx)
static const AVClass j2k_class
Jpeg2000TgtNode * zerobits
static void j2k_flush(Jpeg2000EncoderContext *s)
flush the bitstream
static int init_tiles(Jpeg2000EncoderContext *s)
compute the sizes of tiles, resolution levels, bands, etc.
#define AV_INPUT_BUFFER_MIN_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
uint8_t log2_prec_widths[JPEG2000_MAX_RESLEVELS]
static const uint16_t mask[17]
void ff_jpeg2000_set_significance(Jpeg2000T1Context *t1, int x, int y, int negative)
static int put_cod(Jpeg2000EncoderContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
uint8_t log2_prec_heights[JPEG2000_MAX_RESLEVELS]
int flags
AV_CODEC_FLAG_*.
static void put_num(Jpeg2000EncoderContext *s, int num, int n)
put n least significant bits of a number num
const char * name
Name of the codec implementation.
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static void * av_mallocz_array(size_t nmemb, size_t size)
int flags
A combination of AV_PKT_FLAG values.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static int put_siz(Jpeg2000EncoderContext *s)
static int lut_nmsedec_sig0[1<< NMSEDEC_BITS]
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
static int put_qcd(Jpeg2000EncoderContext *s, int compno)
static int getnmsedec_sig(int x, int bpno)
struct Jpeg2000TgtNode * parent
static void encode_sigpass(Jpeg2000T1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
int width
picture width / height.
JPEG 2000 structures and defines common to encoder and decoder.
static int j2kenc_destroy(AVCodecContext *avctx)
static int ff_jpeg2000_getsigctxno(int flag, int bandno)
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
uint8_t cbps[4]
bits per sample in particular components
int ff_dwt_encode(DWTContext *s, void *t)
void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
static int encode_tile(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno)
static int ff_jpeg2000_ceildivpow2(int a, int b)
static const float pred[4]
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Libavcodec external API header.
static void encode_refpass(Jpeg2000T1Context *t1, int width, int height, int *nmsedec, int bpno)
attribute_deprecated int prediction_method
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Jpeg2000CodingStyle codsty
main external API structure.
void av_cold ff_mqc_init_context_tables(void)
MQ-coder Initialize context tables (QE, NLPS, NMPS)
static void init_luts(void)
static void encode_cblk(Jpeg2000EncoderContext *s, Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk, Jpeg2000Tile *tile, int width, int height, int bandpos, int lev)
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Jpeg2000Pass passes[JPEG2000_MAX_PASSES]
static const char * format
Describe the class of an AVClass context structure.
static const AVOption options[]
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
int height
image width and height
Jpeg2000ResLevel * reslevel
static enum AVPixelFormat pix_fmts[]
static int ff_jpeg2000_ceildiv(int a, int b)
void ff_jpeg2000_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint8_t expn[JPEG2000_MAX_DECLEVELS *3]
static void reinit(Jpeg2000EncoderContext *s)
static uint8_t * put_sot(Jpeg2000EncoderContext *s, int tileno)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
common internal and external API header
static void copy_frame(Jpeg2000EncoderContext *s)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
uint16_t log2_cblk_height
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
int ff_jpeg2000_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int cbps, int dx, int dy, AVCodecContext *avctx)
static void putnumpasses(Jpeg2000EncoderContext *s, int n)
int ff_mqc_flush_to(MqcState *mqc, uint8_t *dst, int *dst_len)
#define FF_ENABLE_DEPRECATION_WARNINGS
static void truncpasses(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile)
static void encode_clnpass(Jpeg2000T1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
static int lut_nmsedec_sig[1<< NMSEDEC_BITS]
static int ff_jpeg2000_getrefctxno(int flag)
#define av_malloc_array(a, b)
static void init_quantization(Jpeg2000EncoderContext *s)
static const int dwt_norms[2][4][10]
AVPixelFormat
Pixel format.
This structure stores compressed data.
#define WMSEDEC_SHIFT
must be >= 13
static int encode_packets(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno)
static int ff_jpeg2000_getsgnctxno(int flag, int *xorbit)
void ff_mqc_encode(MqcState *mqc, uint8_t *cxstate, int d)
code bit d with context cx