]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/j2k.h
avcodec/vp8: Cosmetics, maintain alphabetical order in threading headers
[ffmpeg] / libavcodec / j2k.h
index d38c8f6e454a6b0be8be64aaa81878b751581767..aacd006a1da24d68e43a7e56925614ee051fe4d6 100644 (file)
 #define AVCODEC_J2K_H
 
 /**
- * JPEG2000 tables
  * @file
- * @author Kamil Nowosad
+ * JPEG 2000 structures and defines common
+ * to encoder and decoder
  */
 
+#include <stdint.h>
+
+#include "avcodec.h"
 #include "mqc.h"
-#include "j2k_dwt.h"
+#include "jpeg2000dwt.h"
 
 enum Jpeg2000Markers {
     JPEG2000_SOC = 0xff4f, // start of codestream
@@ -114,7 +117,7 @@ enum Jpeg2000Quantsty { // quantization style
 
 typedef struct Jpeg2000T1Context {
     int data[JPEG2000_MAX_CBLKW][JPEG2000_MAX_CBLKH];
-    int flags[JPEG2000_MAX_CBLKW+2][JPEG2000_MAX_CBLKH+2];
+    int flags[JPEG2000_MAX_CBLKW + 2][JPEG2000_MAX_CBLKH + 2];
     MqcState mqc;
 } Jpeg2000T1Context;
 
@@ -126,12 +129,11 @@ typedef struct Jpeg2000TgtNode {
 
 typedef struct Jpeg2000CodingStyle {
     uint8_t nreslevels;       // number of resolution levels
+    uint8_t nreslevels2decode; // number of resolution levels to decode
     uint8_t log2_cblk_width,
             log2_cblk_height; // exponent of codeblock size
     uint8_t transform;        // DWT type
     uint8_t csty;             // coding style
-    uint8_t log2_prec_width,
-            log2_prec_height; // precinct size
     uint8_t nlayers;          // number of layers
     uint8_t mct;              // multiple component transformation
     uint8_t cblk_style;       // codeblock coding style
@@ -141,10 +143,10 @@ typedef struct Jpeg2000CodingStyle {
 } Jpeg2000CodingStyle;
 
 typedef struct Jpeg2000QuantStyle {
-    uint8_t  expn[32 * 3]; // quantization exponent
+    uint8_t expn[32 * 3];  // quantization exponent
     uint16_t mant[32 * 3]; // quantization mantissa
-    uint8_t  quantsty;     // quantization style
-    uint8_t  nguardbits;   // number of guard bits
+    uint8_t quantsty;      // quantization style
+    uint8_t nguardbits;    // number of guard bits
 } Jpeg2000QuantStyle;
 
 typedef struct Jpeg2000Pass {
@@ -152,7 +154,7 @@ typedef struct Jpeg2000Pass {
     int64_t disto;
 } Jpeg2000Pass;
 
-typedef struct Jpeg2000Cblk  {
+typedef struct Jpeg2000Cblk {
     uint8_t npasses;
     uint8_t ninclpasses; // number coding of passes included in codestream
     uint8_t nonzerobits;
@@ -162,26 +164,28 @@ typedef struct Jpeg2000Cblk  {
     uint8_t zero;
     uint8_t data[8192];
     Jpeg2000Pass passes[100];
+    uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}}
 } Jpeg2000Cblk; // code block
 
 typedef struct Jpeg2000Prec {
-    uint16_t xi0, xi1, yi0, yi1; // codeblock indexes ([xi0, xi1))
+    uint16_t nb_codeblocks_width;
+    uint16_t nb_codeblocks_height;
     Jpeg2000TgtNode *zerobits;
     Jpeg2000TgtNode *cblkincl;
+    Jpeg2000Cblk *cblk;
+    uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}}
 } Jpeg2000Prec; // precinct
 
 typedef struct Jpeg2000Band {
     uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}}
-    uint16_t codeblock_width, codeblock_height;
-    uint16_t cblknx, cblkny;
+    uint16_t log2_cblk_width, log2_cblk_height;
     uint32_t stepsize; // quantization stepsize (* 2^13)
     Jpeg2000Prec *prec;
-    Jpeg2000Cblk *cblk;
 } Jpeg2000Band; // subband
 
 typedef struct Jpeg2000ResLevel {
     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
     uint8_t log2_prec_width, log2_prec_height; // exponent of precinct size
     Jpeg2000Band *band;
@@ -191,7 +195,8 @@ typedef struct Jpeg2000Component {
     Jpeg2000ResLevel *reslevel;
     DWTContext dwt;
     int *data;
-    uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}}
+    uint16_t coord[2][2];   // border coordinates {{x0, x1}, {y0, y1}} -- can be reduced with lowres option
+    uint16_t coord_o[2][2]; // border coordinates {{x0, x1}, {y0, y1}} -- original values from jpeg2000 headers
 } Jpeg2000Component;
 
 /* misc tools */
@@ -209,22 +214,30 @@ static inline int ff_jpeg2000_ceildiv(int a, int b)
 Jpeg2000TgtNode *ff_j2k_tag_tree_init(int w, int h);
 
 /* TIER-1 routines */
+
+/* Set up lookup tables used in TIER-1. */
 void ff_jpeg2000_init_tier1_luts(void);
 
-void ff_j2k_set_significant(Jpeg2000T1Context *t1, int x, int y, int negative);
+/* Update significance of a coefficient at current position (x,y) and
+ * for neighbors. */
+void ff_j2k_set_significant(Jpeg2000T1Context *t1,
+                            int x, int y, int negative);
 
 extern uint8_t ff_jpeg2000_sigctxno_lut[256][4];
 
-static inline int ff_j2k_getsigctxno(int flag, int bandno)
+/* Get context label (number in range[0..8]) of a coefficient for significance
+ * propagation and cleanup coding passes. */
+static inline int ff_jpeg2000_getsigctxno(int flag, int bandno)
 {
     return ff_jpeg2000_sigctxno_lut[flag & 255][bandno];
 }
 
+static const uint8_t refctxno_lut[2][2] = { { 14, 15 }, { 16, 16 } };
+
 /* Get context label (number in range[14..16]) of a coefficient for magnitude
  * refinement pass. */
 static inline int ff_jpeg2000_getrefctxno(int flag)
 {
-    static const uint8_t refctxno_lut[2][2] = { { 14, 15 }, { 16, 16 } };
     return refctxno_lut[(flag >> 14) & 1][(flag & 255) != 0];
 }
 
@@ -241,7 +254,8 @@ static inline int ff_jpeg2000_getsgnctxno(int flag, int *xorbit)
 int ff_j2k_init_component(Jpeg2000Component *comp,
                           Jpeg2000CodingStyle *codsty,
                           Jpeg2000QuantStyle *qntsty,
-                          int cbps, int dx, int dy);
+                          int cbps, int dx, int dy,
+                          AVCodecContext *avctx);
 void ff_j2k_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty);
 void ff_j2k_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty);