35 #define NMSEDEC_BITS 7    36 #define NMSEDEC_FRACBITS (NMSEDEC_BITS-1)    37 #define WMSEDEC_SHIFT 13     38 #define LAMBDA_SCALE (100000000LL << (WMSEDEC_SHIFT - 13))
    46     {{10000, 19650, 41770,  84030, 169000, 338400,  676900, 1353000, 2706000, 5409000},
    47      {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
    48      {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
    49      {20800, 38650, 83070, 171800, 347100, 695900, 1393000, 2786000, 5572000}},
    51     {{10000, 15000, 27500, 53750, 106800, 213400, 426700, 853300, 1707000, 3413000},
    52      {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
    53      {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
    54      { 7186,  9218, 15860, 30430,  60190, 120100, 240000, 479700,  959300}}
    92 static void nspaces(FILE *fd, 
int n)
    94     while(n--) putc(
' ', fd);
   100     for (i = 0; i < comp->y1 - comp->y0; i++)
   101         ff_j2k_printv(comp->
data + i * (comp->x1 - comp->x0), comp->x1 - comp->x0);
   106     int tileno, compno, reslevelno, bandno, precno;
   107     fprintf(fd, 
"XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n"   108                 "numXtiles = %d, numYtiles = %d, ncomponents = %d\n"   115         fprintf(fd, 
"tile %d:\n", tileno);
   116         for(compno = 0; compno < s->
ncomponents; compno++){
   119             fprintf(fd, 
"component %d:\n", compno);
   121             fprintf(fd, 
"x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
   122                         comp->x0, comp->x1, comp->y0, comp->y1);
   123             for(reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
   126                 fprintf(fd, 
"reslevel %d:\n", reslevelno);
   128                 fprintf(fd, 
"x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n",
   129                         reslevel->x0, reslevel->x1, reslevel->y0,
   130                         reslevel->y1, reslevel->
nbands);
   131                 for(bandno = 0; bandno < reslevel->
nbands; bandno++){
   134                     fprintf(fd, 
"band %d:\n", bandno);
   136                     fprintf(fd, 
"x0 = %d, x1 = %d, y0 = %d, y1 = %d,"   137                                 "codeblock_width = %d, codeblock_height = %d cblknx = %d cblkny = %d\n",
   145                         fprintf(fd, 
"prec %d:\n", precno);
   147                         fprintf(fd, 
"xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n",
   194     int sp = 1, curval = 0;
   208         if (stack[sp]->
val >= threshold){
   214         curval = stack[
sp]->
val;
   240     bytestream_put_be16(&s->
buf, 0); 
   241     bytestream_put_be32(&s->
buf, s->
width); 
   243     bytestream_put_be32(&s->
buf, 0); 
   244     bytestream_put_be32(&s->
buf, 0); 
   248     bytestream_put_be32(&s->
buf, 0); 
   249     bytestream_put_be32(&s->
buf, 0); 
   253         bytestream_put_byte(&s->
buf, 7);
   268     bytestream_put_be16(&s->
buf, 12); 
   269     bytestream_put_byte(&s->
buf, 0);  
   271     bytestream_put_byte(&s->
buf, 0); 
   272     bytestream_put_be16(&s->
buf, 1); 
   274         bytestream_put_byte(&s->
buf, 2); 
   276         bytestream_put_byte(&s->
buf, 0); 
   282     bytestream_put_byte(&s->
buf, 0); 
   302     bytestream_put_be16(&s->
buf, size);  
   305         for (i = 0; i < codsty->
nreslevels * 3 - 2; i++)
   306             bytestream_put_byte(&s->
buf, qntsty->
expn[i] << 3);
   308         for (i = 0; i < codsty->
nreslevels * 3 - 2; i++)
   309             bytestream_put_be16(&s->
buf, (qntsty->
expn[i] << 11) | qntsty->
mant[i]);
   321     bytestream_put_be16(&s->
buf, 10); 
   322     bytestream_put_be16(&s->
buf, tileno); 
   325     bytestream_put_be32(&s->
buf, 0); 
   327     bytestream_put_byte(&s->
buf, 0); 
   328     bytestream_put_byte(&s->
buf, 1); 
   339     int tileno, tilex, tiley, compno;
   349     for (tileno = 0, tiley = 0; tiley < s->
numYtiles; tiley++)
   350         for (tilex = 0; tilex < s->
numXtiles; tilex++, tileno++){
   356             for (compno = 0; compno < s->
ncomponents; compno++){
   365                     for (i = 0; i < 2; i++)
   366                         for (j = 0; j < 2; j++)
   378     int tileno, compno, 
i, 
y, 
x;
   383             for (compno = 0; compno < s->
ncomponents; compno++){
   389                 for (y = comp->
coord[1][0]; y < comp->coord[1][1]; y++){
   391                     for (x = comp->
coord[0][0]; x < comp->coord[0][1]; x++)
   392                         *dst++ = *ptr++ - (1 << 7);
   401             for (y = tile->
comp[0].
coord[1][0]; y < tile->comp[0].
coord[1][1]; y++){
   403                 for (x = tile->
comp[0].
coord[0][0]; x < tile->comp[0].
coord[0][1]; x++, i++){
   404                     for (compno = 0; compno < s->
ncomponents; compno++){
   405                         tile->
comp[compno].
data[
i] = *ptr++  - (1 << 7);
   416     int compno, reslevelno, bandno;
   420     for (compno = 0; compno < s->
ncomponents; compno++){
   422         for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
   423             int nbands, lev = codsty->
nreslevels - reslevelno - 1;
   424             nbands = reslevelno ? 3 : 1;
   425             for (bandno = 0; bandno < nbands; bandno++, gbandno++){
   429                     int bandpos = bandno + (reslevelno>0),
   430                         ss = 81920000 / 
dwt_norms[0][bandpos][lev],
   432                     mant = (11 - log < 0 ? ss >> log - 11 : ss << 11 - log) & 0x7ff;
   433                     expn = s->
cbps[compno] - log + 13;
   435                     expn = ((bandno&2)>>1) + (reslevelno>0) + s->
cbps[compno];
   437                 qntsty->
expn[gbandno] = expn;
   438                 qntsty->
mant[gbandno] = mant;
   479     int vert_causal_ctx_csty_loc_symbol;
   480     for (y0 = 0; y0 < 
height; y0 += 4)
   481         for (x = 0; x < 
width; x++)
   482             for (y = y0; y < height && y < y0+4; y++){
   485                         bit = t1->
data[
y][
x] & mask ? 1 : 0;
   502     for (y0 = 0; y0 < 
height; y0 += 4)
   503         for (x = 0; x < 
width; x++)
   504             for (y = y0; y < height && y < y0+4; y++)
   516     int vert_causal_ctx_csty_loc_symbol;
   517     for (y0 = 0; y0 < 
height; y0 += 4)
   518         for (x = 0; x < 
width; x++){
   519             if (y0 + 3 < height && !(
   527                 for (rlen = 0; rlen < 4; rlen++)
   528                     if (t1->
data[y0+rlen][x] & mask)
   535                 for (y = y0 + rlen; y < y0 + 4; y++){
   540                         if (t1->
data[y][x] & mask){ 
   551                 for (y = y0; y < y0 + 4 && y < 
height; y++){
   555                         if (t1->
data[y][x] & mask){ 
   572     int pass_t = 2, passno, 
x, 
y, 
max=0, nmsedec, bpno;
   575     for (y = 0; y < height+2; y++)
   576         memset(t1->
flags[y], 0, (width+2)*
sizeof(
int));
   578     for (y = 0; y < 
height; y++){
   579         for (x = 0; x < 
width; x++){
   580             if (t1->
data[y][x] < 0){
   598     for (passno = 0; bpno >= 0; passno++){
   602             case 0: 
encode_sigpass(t1, width, height, bandpos, &nmsedec, bpno);
   606             case 2: 
encode_clnpass(t1, width, height, bandpos, &nmsedec, bpno);
   611         wmsedec += (int64_t)nmsedec << (2*bpno);
   639         put_num(s, 0xff80 | (n-37), 16);
   646     int bandno, empty = 1;
   655     for (bandno = 0; bandno < rlevel->
nbands; bandno++){
   669     for (bandno = 0; bandno < rlevel->
nbands; bandno++){
   673         int cblknw = prec->
xi1 - prec->
xi0;
   679         for (pos=0, yi = prec->
yi0; yi < prec->yi1; yi++){
   680             for (xi = prec->
xi0; xi < prec->xi1; xi++, pos++){
   688         for (pos=0, yi = prec->
yi0; yi < prec->yi1; yi++){
   689             for (xi = prec->
xi0; xi < prec->xi1; xi++, pos++){
   690                 int pad = 0, llen, 
length;
   719     for (bandno = 0; bandno < rlevel->
nbands; bandno++){
   722         int yi, cblknw = prec->
xi1 - prec->
xi0;
   723         for (yi = prec->
yi0; yi < prec->yi1; yi++){
   725             for (xi = prec->
xi0; xi < prec->xi1; xi++){
   740     int compno, reslevelno, 
ret;
   746     for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
   747         for (compno = 0; compno < s->
ncomponents; compno++){
   751                 if (ret = 
encode_packet(s, reslevel, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
   764     for (passno = 0; passno < cblk->
npasses; passno++){
   773         if (((dd * dwt_norm) >> 
WMSEDEC_SHIFT) * dwt_norm >= dr * lambda)
   781     int compno, reslevelno, bandno, cblkno, lev;
   784     for (compno = 0; compno < s->
ncomponents; compno++){
   787         for (reslevelno = 0, lev = codsty->
nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++, lev--){
   790             for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
   791                 int bandpos = bandno + (reslevelno > 0);
   794                 for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){
   795                     J2kCblk *cblk = band->cblk + cblkno;
   807     int compno, reslevelno, bandno, 
ret;
   810     for (compno = 0; compno < s->
ncomponents; compno++){
   818         for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
   821             for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
   823                 int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
   832                 bandpos = bandno + (reslevelno > 0);
   834                 for (cblky = 0; cblky < band->
cblkny; cblky++){
   835                     if (reslevelno == 0 || bandno == 1)
   843                     for (cblkx = 0; cblkx < band->
cblknx; cblkx++, cblkno++){
   846                             for (y = yy0; y < yy1; y++){
   847                                 int *ptr = t1.
data[y-yy0];
   848                                 for (x = xx0; x < xx1; x++){
   853                             for (y = yy0; y < yy1; y++){
   854                                 int *ptr = t1.
data[y-yy0];
   855                                 for (x = xx0; x < xx1; x++){
   856                                     *ptr = (comp->
data[(comp->
coord[0][1] - comp->
coord[0][0]) * y + x]);
   863                                     bandpos, codsty->
nreslevels - reslevelno - 1);
   889         for (compno = 0; compno < s->
ncomponents; compno++){
   903         for (compno = 0; compno < s->
ncomponents; compno++)
   909                         const AVFrame *pict, 
int *got_packet)
   941         if (!(psotptr = 
put_sot(s, tileno)))
   948         bytestream_put_be32(&psotptr, s->
buf - psotptr + 6);
   994     for (i = 0; i < 3; i++)
 static int ff_j2k_getsgnctxno(int flag, int *xorbit)
static int encode_packets(J2kEncoderContext *s, J2kTile *tile, int tileno)
This structure describes decoded (raw) audio or video data. 
uint8_t log2_prec_height
precinct size 
static int init_tiles(J2kEncoderContext *s)
compute the sizes of tiles, resolution levels, bands, etc. 
static void tag_tree_update(J2kTgtNode *node)
update the value in node 
AVCodec ff_jpeg2000_encoder
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples) 
packed RGB 8:8:8, 24bpp, RGBRGB... 
static int put_siz(J2kEncoderContext *s)
AVFrame * coded_frame
the picture in the bitstream 
if max(w)>1 w=0.9 *w/max(w)
static av_cold int init(AVCodecContext *avctx)
static int lut_nmsedec_ref[1<< NMSEDEC_BITS]
uint8_t log2_cblk_height
exponent of codeblock size 
static av_cold int j2kenc_init(AVCodecContext *avctx)
uint16_t num_precincts_y
number of precincts in x/y direction 
static int put_qcd(J2kEncoderContext *s, int compno)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx. 
void ff_mqc_initenc(MqcState *mqc, uint8_t *bp)
initialize the encoder 
static int ff_j2k_ceildivpow2(int a, int b)
void ff_j2k_reinit(J2kComponent *comp, J2kCodingStyle *codsty)
static int encode_packet(J2kEncoderContext *s, J2kResLevel *rlevel, int precno, uint8_t *expn, int numgbits)
uint32_t stepsize
quantization stepsize (* 2^13) 
struct J2kTgtNode * parent
void ff_j2k_cleanup(J2kComponent *comp, J2kCodingStyle *codsty)
uint16_t yi1
codeblock indexes ([xi0, xi1)) 
static int getnmsedec_ref(int x, int bpno)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int height
image width and height 
static int lut_nmsedec_ref0[1<< NMSEDEC_BITS]
uint8_t transform
DWT type. 
static uint8_t * put_sot(J2kEncoderContext *s, int tileno)
static int encode_tile(J2kEncoderContext *s, J2kTile *tile, int tileno)
void ff_j2k_set_significant(J2kT1Context *t1, int x, int y, int negative)
static void put_num(J2kEncoderContext *s, int num, int n)
put n least significant bits of a number num 
int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantStyle *qntsty, int cbps, int dx, int dy)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe. 
static void encode_cblk(J2kEncoderContext *s, J2kT1Context *t1, J2kCblk *cblk, J2kTile *tile, int width, int height, int bandpos, int lev)
int flags[J2K_MAX_CBLKW+2][J2K_MAX_CBLKH+2]
static const uint16_t mask[17]
static int getcut(J2kCblk *cblk, int64_t lambda, int dwt_norm)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static void cleanup(J2kEncoderContext *s)
int data[J2K_MAX_CBLKW][J2K_MAX_CBLKH]
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation. 
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static void put_bits(J2kEncoderContext *s, int val, int n)
put n times val bit 
int flags
A combination of AV_PKT_FLAG values. 
uint8_t cbps[4]
bits per sample in particular components 
uint16_t codeblock_height
static int lut_nmsedec_sig0[1<< NMSEDEC_BITS]
static void tag_tree_code(J2kEncoderContext *s, J2kTgtNode *node, int threshold)
code the value stored in node 
static int getnmsedec_sig(int x, int bpno)
#define FF_MIN_BUFFER_SIZE
minimum encoding buffer size Used to avoid some checks during header writing. 
int width
picture width / height. 
static int ff_j2k_getnbctxno(int flag, int bandno, int vert_causal_ctx_csty_symbol)
static int put_cod(J2kEncoderContext *s)
static int j2kenc_destroy(AVCodecContext *avctx)
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad)) 
uint16_t mant[32 *3]
quantization mantissa 
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 void j2k_flush(J2kEncoderContext *s)
flush the bitstream 
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data. 
uint8_t nreslevels
number of resolution levels 
static void truncpasses(J2kEncoderContext *s, J2kTile *tile)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line. 
static void encode_clnpass(J2kT1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
main external API structure. 
static void close(AVCodecParserContext *s)
static int ff_j2k_ceildiv(int a, int b)
static void encode_sigpass(J2kT1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
static void init_luts(void)
static void copy_frame(J2kEncoderContext *s)
BYTE int const BYTE int int int height
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
synthesis window for stochastic i
int ff_j2k_dwt_encode(DWTContext *s, int *t)
static void init_quantization(J2kEncoderContext *s)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes. 
static void putnumpasses(J2kEncoderContext *s, int n)
common internal api header. 
int ff_mqc_flush(MqcState *mqc)
flush the encoder [returns number of bytes encoded] 
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers. 
common internal and external API header 
int ff_mqc_length(MqcState *mqc)
number of encoded bytes 
uint16_t coord[2][2]
border coordinates {{x0, x1}, {y0, y1}} 
#define CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders. 
uint8_t ninclpasses
number coding of passes included in codestream 
uint16_t coord[2][2]
border coordinates {{x0, x1}, {y0, y1}} 
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
uint8_t nguardbits
number of guard bits 
void ff_j2k_init_tier1_luts(void)
static void reinit(J2kEncoderContext *s)
else dst[i][x+y *dst_stride[i]]
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip please avoid problems through this extra level of scrutiny For cosmetics only commits you should e g by running git config global user name My Name git config global user email my email which is either set in your personal configuration file through git config core editor or set by one of the following environment VISUAL or EDITOR Log messages should be concise but descriptive Explain why you made a what you did will be obvious from the changes themselves most of the time Saying just bug fix or is bad Remember that people of varying skill levels look at and educate themselves while reading through your code Don t include filenames in log Git provides that information Possibly make the commit message have a descriptive first line
uint8_t quantsty
quantization style 
static int lut_nmsedec_sig[1<< NMSEDEC_BITS]
uint8_t expn[32 *3]
quantization exponent 
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
static int ff_j2k_getrefctxno(int flag)
uint16_t coord[2][2]
border coordinates {{x0, x1}, {y0, y1}} 
static const int dwt_norms[2][4][10]
AVPixelFormat
Pixel format. 
This structure stores compressed data. 
static void encode_refpass(J2kT1Context *t1, int width, int height, int *nmsedec, int bpno)
#define WMSEDEC_SHIFT
must be >= 13 
void ff_mqc_encode(MqcState *mqc, uint8_t *cxstate, int d)
code bit d with context cx