• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/j2k.h

Go to the documentation of this file.
00001 /*
00002  * JPEG2000 tables
00003  * Copyright (c) 2007 Kamil Nowosad
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #ifndef AVCODEC_J2K_H
00023 #define AVCODEC_J2K_H
00024 
00031 #include "mqc.h"
00032 #include "j2k_dwt.h"
00033 
00034 enum J2kMarkers{
00035     J2K_SOC = 0xff4f, 
00036     J2K_SIZ = 0xff51, 
00037     J2K_COD,          
00038     J2K_COC,          
00039     J2K_TLM = 0xff55, 
00040     J2K_PLM = 0xff57, 
00041     J2K_PLT,          
00042     J2K_QCD = 0xff5c, 
00043     J2K_QCC,          
00044     J2K_RGN,          
00045     J2K_POC,          
00046     J2K_PPM,          
00047     J2K_PPT,          
00048     J2K_CRG = 0xff63, 
00049     J2K_COM,          
00050     J2K_SOT = 0xff90, 
00051     J2K_SOP,          
00052     J2K_EPH,          
00053     J2K_SOD,          
00054     J2K_EOC = 0xffd9, 
00055 };
00056 
00057 enum J2kQuantsty{ 
00058     J2K_QSTY_NONE, 
00059     J2K_QSTY_SI,   
00060     J2K_QSTY_SE    
00061 };
00062 
00063 #define J2K_MAX_CBLKW 64
00064 #define J2K_MAX_CBLKH 64
00065 
00066 // T1 flags
00067 // flags determining significance of neighbour coefficients
00068 #define J2K_T1_SIG_N  0x0001
00069 #define J2K_T1_SIG_E  0x0002
00070 #define J2K_T1_SIG_W  0x0004
00071 #define J2K_T1_SIG_S  0x0008
00072 #define J2K_T1_SIG_NE 0x0010
00073 #define J2K_T1_SIG_NW 0x0020
00074 #define J2K_T1_SIG_SE 0x0040
00075 #define J2K_T1_SIG_SW 0x0080
00076 #define J2K_T1_SIG_NB (J2K_T1_SIG_N | J2K_T1_SIG_E | J2K_T1_SIG_S | J2K_T1_SIG_W \
00077                       |J2K_T1_SIG_NE | J2K_T1_SIG_NW | J2K_T1_SIG_SE | J2K_T1_SIG_SW)
00078 // flags determining sign bit of neighbour coefficients
00079 #define J2K_T1_SGN_N  0x0100
00080 #define J2K_T1_SGN_S  0x0200
00081 #define J2K_T1_SGN_W  0x0400
00082 #define J2K_T1_SGN_E  0x0800
00083 
00084 #define J2K_T1_VIS    0x1000
00085 #define J2K_T1_SIG    0x2000
00086 #define J2K_T1_REF    0x4000
00087 
00088 #define J2K_T1_SGN    0x8000
00089 
00090 // Codeblock coding styles
00091 #define J2K_CBLK_BYPASS    0x01 // Selective arithmetic coding bypass
00092 #define J2K_CBLK_RESET     0x02 // Reset context probabilities
00093 #define J2K_CBLK_TERMALL   0x04 // Terminate after each coding pass
00094 #define J2K_CBLK_VSC       0x08 // Vertical stripe causal context formation
00095 #define J2K_CBLK_PREDTERM  0x10 // Predictable termination
00096 #define J2K_CBLK_SEGSYM    0x20 // Segmentation symbols present
00097 
00098 // Coding styles
00099 #define J2K_CSTY_PREC      0x01 // Precincts defined in coding style
00100 #define J2K_CSTY_SOP       0x02 // SOP marker present
00101 #define J2K_CSTY_EPH       0x04 // EPH marker present
00102 
00103 typedef struct {
00104     int data[J2K_MAX_CBLKW][J2K_MAX_CBLKH];
00105     int flags[J2K_MAX_CBLKW+2][J2K_MAX_CBLKH+2];
00106     MqcState mqc;
00107 } J2kT1Context;
00108 
00109 typedef struct J2kTgtNode {
00110     uint8_t val;
00111     uint8_t vis;
00112     struct J2kTgtNode *parent;
00113 } J2kTgtNode;
00114 
00115 typedef struct {
00116     uint8_t nreslevels;       
00117     uint8_t log2_cblk_width,
00118             log2_cblk_height; 
00119     uint8_t transform;        
00120     uint8_t csty;             
00121     uint8_t log2_prec_width,
00122             log2_prec_height; 
00123     uint8_t nlayers;          
00124     uint8_t mct;              
00125     uint8_t cblk_style;       
00126 } J2kCodingStyle;
00127 
00128 typedef struct {
00129     uint8_t  expn[32 * 3]; 
00130     uint16_t mant[32 * 3]; 
00131     uint8_t  quantsty;     
00132     uint8_t  nguardbits;   
00133 } J2kQuantStyle;
00134 
00135 typedef struct {
00136     uint16_t rate;
00137     int64_t disto;
00138 } J2kPass;
00139 
00140 typedef struct {
00141     uint8_t npasses;
00142     uint8_t ninclpasses; 
00143     uint8_t nonzerobits;
00144     uint16_t length;
00145     uint16_t lengthinc;
00146     uint8_t lblock;
00147     uint8_t zero;
00148     uint8_t data[8192];
00149     J2kPass passes[100];
00150 } J2kCblk; 
00151 
00152 typedef struct {
00153     uint16_t xi0, xi1, yi0, yi1; 
00154     J2kTgtNode *zerobits;
00155     J2kTgtNode *cblkincl;
00156 } J2kPrec; 
00157 
00158 typedef struct {
00159     uint16_t coord[2][2]; 
00160     uint16_t codeblock_width, codeblock_height;
00161     uint16_t cblknx, cblkny;
00162     uint32_t stepsize; 
00163     J2kPrec *prec;
00164     J2kCblk *cblk;
00165 } J2kBand; 
00166 
00167 typedef struct {
00168     uint8_t nbands;
00169     uint16_t coord[2][2]; 
00170     uint16_t num_precincts_x, num_precincts_y; 
00171     uint8_t log2_prec_width, log2_prec_height; 
00172     J2kBand *band;
00173 } J2kResLevel; 
00174 
00175 typedef struct {
00176    J2kResLevel *reslevel;
00177    DWTContext dwt;
00178    int *data;
00179    uint16_t coord[2][2]; 
00180 } J2kComponent;
00181 
00182 /* debug routines */
00183 #if 0
00184 #undef fprintf
00185 #undef printf
00186 void ff_j2k_printv(int *tab, int l);
00187 void ff_j2k_printu(uint8_t *tab, int l);
00188 #endif
00189 
00190 /* misc tools */
00191 static inline int ff_j2k_ceildivpow2(int a, int b)
00192 {
00193     return (a + (1 << b) - 1)>> b;
00194 }
00195 
00196 static inline int ff_j2k_ceildiv(int a, int b)
00197 {
00198     return (a + b - 1) / b;
00199 }
00200 
00201 /* tag tree routines */
00202 J2kTgtNode *ff_j2k_tag_tree_init(int w, int h);
00203 
00204 /* TIER-1 routines */
00205 void ff_j2k_init_tier1_luts(void);
00206 
00207 void ff_j2k_set_significant(J2kT1Context *t1, int x, int y, int negative);
00208 
00209 extern uint8_t ff_j2k_nbctxno_lut[256][4];
00210 
00211 static inline int ff_j2k_getnbctxno(int flag, int bandno, int vert_causal_ctx_csty_symbol)
00212 {
00213     return ff_j2k_nbctxno_lut[flag&255][bandno];
00214 }
00215 
00216 static inline int ff_j2k_getrefctxno(int flag)
00217 {
00218     static const uint8_t refctxno_lut[2][2] = {{14, 15}, {16, 16}};
00219     return refctxno_lut[(flag>>14)&1][(flag & 255) != 0];
00220 }
00221 
00222 extern uint8_t ff_j2k_sgnctxno_lut[16][16], ff_j2k_xorbit_lut[16][16];
00223 
00224 static inline int ff_j2k_getsgnctxno(int flag, int *xorbit)
00225 {
00226     *xorbit = ff_j2k_xorbit_lut[flag&15][(flag>>8)&15];
00227     return  ff_j2k_sgnctxno_lut[flag&15][(flag>>8)&15];
00228 }
00229 
00230 int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantStyle *qntsty, int cbps, int dx, int dy);
00231 void ff_j2k_reinit(J2kComponent *comp, J2kCodingStyle *codsty);
00232 void ff_j2k_cleanup(J2kComponent *comp, J2kCodingStyle *codsty);
00233 
00234 #endif /* AVCODEC_J2K_H */
Generated on Fri Feb 1 2013 14:34:37 for FFmpeg by doxygen 1.7.1