"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSImageLib/Src/Jpeg/LSITcd.h

00001 /*
00002  * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
00003  * Copyright (c) 2002-2007, Professor Benoit Macq
00004  * Copyright (c) 2001-2003, David Janssens
00005  * Copyright (c) 2002-2003, Yannick Verschueren
00006  * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
00007  * Copyright (c) 2005, Herve Drolon, FreeImage Team
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted provided that the following conditions
00012  * are met:
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #ifndef __LSI_TCD_H__
00033 #define __LSI_TCD_H__
00034 
00035 #include "../LSIImageLib.h"
00036 #include "LSIJ2k.h"
00037 #include "LSIJpegImage.h"
00038 #include "LSITgt.h"
00039 
00040 namespace lsi {
00041 
00048         class CTcd {
00049         public :
00050                 // == Types.
00054                 typedef struct opj_tcd_seg {
00055                         LSUINT8 **                                                      data;
00056                         LSINT32                                                         dataindex;
00057                         LSINT32                                                         numpasses;
00058                         LSINT32                                                         len;
00059                         LSINT32                                                         maxpasses;
00060                         LSINT32                                                         numnewpasses;
00061                         LSINT32                                                         newlen;
00062                 } opj_tcd_seg_t;
00063 
00067                 typedef struct opj_tcd_pass {
00068                         LSINT32                                                         rate;
00069                         LSDOUBLE                                                        distortiondec;
00070                         LSINT32                                                         term, len;
00071                 } opj_tcd_pass_t;
00072 
00076                 typedef struct opj_tcd_layer {
00077                         LSINT32                                                         numpasses;                      /* Number of passes in the layer. */
00078                         LSINT32                                                         len;                            /* Length of information. */
00079                         LSDOUBLE                                                        disto;                          /* Add for index (Cfr. Marcela). */
00080                         LSUINT8 *                                                       data;                           /* Data. */
00081                 } opj_tcd_layer_t;
00082 
00086                 typedef struct opj_tcd_cblk_enc {
00087                         LSUINT8 *                                                       data;                           /* Data. */
00088                         opj_tcd_layer_t *                                       layers;                         /* Layer information. */
00089                         opj_tcd_pass_t *                                        passes;                         /* Information about the passes. */
00090                         LSINT32                                                         x0, y0, x1, y1;         /* Dimension of the code-blocks: left upper corner (x0, y0) right low corner (x1, y1). */
00091                         LSINT32                                                         numbps;
00092                         LSINT32                                                         numlenbits;
00093                         LSINT32                                                         numpasses;                      /* Number of pass already done for the code-blocks. */
00094                         LSINT32                                                         numpassesinlayers;      /* Number of passes in the layer. */
00095                         LSINT32                                                         totalpasses;            /* Total number of passes. */
00096                 } opj_tcd_cblk_enc_t;
00097 
00101                 typedef struct opj_tcd_cblk_dec {
00102                         LSUINT8 *                                                       data;                           /* Data. */
00103                         opj_tcd_seg_t *                                         segs;                           /* Segments informations. */
00104                         LSINT32                                                         x0, y0, x1, y1;         /* Dimension of the code-blocks: left upper corner (x0, y0) right low corner (x1, y1). */
00105                         LSINT32                                                         numbps;
00106                         LSINT32                                                         numlenbits;
00107                         LSINT32                                                         len;                            /* Length. */
00108                         LSINT32                                                         numnewpasses;           /* Number of pass added to the code-blocks. */
00109                         LSINT32                                                         numsegs;                        /* Number of segments. */
00110                 } opj_tcd_cblk_dec_t;
00111 
00115                 typedef struct opj_tcd_precinct {
00116                         LSINT32                                                         x0, y0, x1, y1;         /* Dimension of the precinct: left upper corner (x0, y0) right low corner (x1, y1). */
00117                         LSINT32                                                         cw, ch;                         /* Number of precinct in width and heigth. */
00118                         union {                                                                                                 /* Code-blocks informations. */
00119                                 opj_tcd_cblk_enc_t *                    enc;
00120                                 opj_tcd_cblk_dec_t *                    dec;
00121                         }                                                                       cblks;
00122                         CTgt::opj_tgt_tree_t *                          incltree;                       /* Inclusion tree. */
00123                         CTgt::opj_tgt_tree_t *                          imsbtree;                       /* IMSB tree. */
00124                 } opj_tcd_precinct_t;
00125 
00129                 typedef struct opj_tcd_band {
00130                         LSINT32                                                         x0, y0, x1, y1;         /* Dimension of the subband: left upper corner (x0, y0) right low corner (x1, y1). */
00131                         LSINT32                                                         bandno;
00132                         opj_tcd_precinct_t *                            precincts;                      /* Precinct information. */
00133                         LSINT32                                                         numbps;
00134                         LSFLOAT                                                         stepsize;
00135                 } opj_tcd_band_t;
00136 
00140                 typedef struct opj_tcd_resolution {
00141                         LSINT32                                                         x0, y0, x1, y1;         /* Dimension of the resolution level: left upper corner (x0, y0) right low corner (x1, y1). */
00142                         LSINT32                                                         pw, ph;
00143                         LSINT32                                                         numbands;                       /* Number sub-band for the resolution level. */
00144                         opj_tcd_band_t                                          bands[3];                       /* Subband information. */
00145                 } opj_tcd_resolution_t;
00146 
00150                 typedef struct opj_tcd_tilecomp {
00151                         LSINT32                                                         x0, y0, x1, y1;         /* Dimension of component: left upper corner (x0, y0) right low corner (x1, y1). */
00152                         LSINT32                                                         numresolutions;         /* Number of resolutions level. */
00153                         opj_tcd_resolution_t *                          resolutions;            /* Resolutions information. */
00154                         LSINT32 *                                                       data;                           /* Data of the component. */
00155                         LSINT32                                                         numpix;                         /* Add fixed_quality. */
00156                 } opj_tcd_tilecomp_t;
00157 
00161                 typedef struct opj_tcd_tile {
00162                         LSINT32                                                         x0, y0, x1, y1;         /* Dimension of the tile: left upper corner (x0, y0) right low corner (x1, y1). */
00163                         LSINT32                                                         numcomps;                       /* Number of components in tile. */
00164                         opj_tcd_tilecomp_t *                            comps;                          /* Components information. */
00165                         LSINT32                                                         numpix;                         /* Add fixed_quality. */
00166                         LSDOUBLE                                                        distotile;                      /* Add fixed_quality. */
00167                         LSDOUBLE                                                        distolayer[100];        /* Add fixed_quality. */
00169                         LSINT32                                                         packno;
00170                 } opj_tcd_tile_t;
00171 
00175                 typedef struct opj_tcd_image {
00176                         LSINT32                                                         tw, th;                         /* Number of tiles in width and heigth. */
00177                         opj_tcd_tile_t *                                        tiles;                          /* Tiles information. */
00178                 } opj_tcd_image_t;
00179 
00183                 typedef struct opj_tcd_t {
00185                         LSINT32                                                         tp_pos;
00187                         LSINT32                                                         tp_num;
00189                         LSINT32                                                         cur_tp_num;
00191                         LSINT32                                                         cur_totnum_tp;
00193                         LSINT32                                                         cur_pino;
00195                         CJpegCommonStructs::opj_common_ptr      cinfo;
00196 
00198                         opj_tcd_image_t *                                       tcd_image;
00200                         CJpegImage::opj_image_t *                       image;
00202                         CJ2k::opj_cp_t *                                        cp;
00204                         opj_tcd_tile_t *                                        tcd_tile;
00206                         CJ2k::opj_tcp_t *                                       tcp;
00208                         LSINT32                                                         tcd_tileno;
00210                         LSDOUBLE                                                        encoding_time;
00211                 } * LPopj_tcd_t, * const LPCopj_tcd_t;
00212 
00213 
00214                 // == Functions.
00218                 //static LSVOID tcd_dump( FILE * fd, opj_tcd_t * _ptTcd, opj_tcd_image_t * img );
00219 
00226                 static opj_tcd_t * LSE_CALL                             tcd_create( CJpegCommonStructs::opj_common_ptr _cpCInfo );
00227 
00233                 static LSVOID LSE_CALL                                  tcd_destroy( opj_tcd_t * _ptTcd );
00234 
00243                 static LSVOID LSE_CALL                                  tcd_malloc_encode( opj_tcd_t * _ptTcd, CJpegImage::opj_image_t * _piImage, CJ2k::opj_cp_t * _pcCp, LSINT32 _i32CurtileNo );
00244 
00250                 static LSVOID LSE_CALL                                  tcd_free_encode( opj_tcd_t * _ptTcd );
00251 
00260                 static LSVOID LSE_CALL                                  tcd_init_encode( opj_tcd_t * _ptTcd, CJpegImage::opj_image_t * _piImage, CJ2k::opj_cp_t * _pcCp, LSINT32 _i32CurTileNo );
00261 
00269                 static LSVOID LSE_CALL                                  tcd_malloc_decode( opj_tcd_t * _ptTcd, CJpegImage::opj_image_t * _piImage, CJ2k::opj_cp_t * _pcCp );
00270 
00280                 static LSVOID LSE_CALL                                  tcd_malloc_decode_tile( opj_tcd_t * _ptTcd, CJpegImage::opj_image_t * _piImage, CJ2k::opj_cp_t * _pcCp, LSINT32 _i32TileNo, CJpegCommonStructs::opj_codestream_info_t * _pciInfoC );
00281 
00289                 static LSVOID LSE_CALL                                  tcd_makelayer_fixed( opj_tcd_t * _ptTcd, LSINT32 _i32LayNo, LSINT32 _i32Final );
00290 
00296                 static LSVOID LSE_CALL                                  tcd_rateallocate_fixed( opj_tcd_t * _ptTcd );
00297 
00306                 static LSVOID LSE_CALL                                  tcd_makelayer( opj_tcd_t * _ptTcd, LSINT32 _i32LayNo, LSDOUBLE _dThresh, LSINT32 _i32Final );
00307 
00316                 static LSBOOL LSE_CALL                                  tcd_rateallocate( opj_tcd_t * _ptTcd, LSUINT8 * _pui8Dest, LSINT32 _i32Len, CJpegCommonStructs::opj_codestream_info_t * _pciInfoC );
00317 
00328                 static LSINT32 LSE_CALL                                 tcd_encode_tile( opj_tcd_t * _ptTcd, LSINT32 _i32TileNo, LSUINT8 * _pui8Dest, LSINT32 _i32Len, CJpegCommonStructs::opj_codestream_info_t * _pciInfoC );
00329                 
00340                 static LSBOOL LSE_CALL                                  tcd_decode_tile( opj_tcd_t * _ptTcd, LSUINT8 * _pui8Src, LSINT32 _i32Len, LSINT32 _i32TileNo, CJpegCommonStructs::opj_codestream_info_t * _pciInfoC );
00341 
00347                 static LSVOID LSE_CALL                                  tcd_free_decode( opj_tcd_t * _ptTcd );
00348 
00355                 static LSVOID LSE_CALL                                  tcd_free_decode_tile( opj_tcd_t * _ptTcd, LSINT32 _i32TileNo );
00356         };
00357 
00358 }       // namespace lsi
00359 
00360 #endif  // __LSI_TCD_H__
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator