"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSImageLib/Src/Jpeg/LSIJp2.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) 2002-2003, Yannick Verschueren
00005  * Copyright (c) 2005, Herve Drolon, FreeImage Team
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 
00031 #ifndef __LSI_JP2_H__
00032 #define __LSI_JP2_H__
00033 
00034 #include "../LSIImageLib.h"
00035 #include "LSICio.h"
00036 #include "LSIJ2k.h"
00037 #include "LSIJpegCommonStructs.h"
00038 #include "LSIJpegImage.h"
00039 
00040 
00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00042 // MACROS
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00044 #define JPIP_JPIP       0x6A706970
00045 
00046 #define JP2_JP          0x6A502020                      
00047 #define JP2_FTYP        0x66747970                      
00048 #define JP2_JP2H        0x6A703268                      
00049 #define JP2_IHDR        0x69686472                      
00050 #define JP2_COLR        0x636F6C72                      
00051 #define JP2_JP2C        0x6A703263                      
00052 #define JP2_URL         0x75726C20                      
00053 #define JP2_DTBL        0x6474626C                      
00054 #define JP2_BPCC        0x62706363                      
00055 #define JP2_JP2         0x6A703220                      
00056 #define JP2_PCLR        0x70636C72                      
00057 #define JP2_CMAP        0x636D6170                      
00058 #define JP2_CDEF        0x63646566                      
00061 namespace lsi {
00062 
00069         class CJp2 {
00070         public :
00071                 // == Types.
00075                 typedef struct opj_jp2_cdef_info_t {
00076                         LSUINT16                                        cn, typ, asoc;
00077                 } * LPopj_jp2_cdef_info_t, * const LPCopj_jp2_cdef_info_t;
00078 
00082                 typedef struct opj_jp2_cdef {
00083                         opj_jp2_cdef_info_t *           info;
00084                         LSUINT16                                        n;
00085                 } opj_jp2_cdef_t;
00086 
00090                 typedef struct opj_jp2_cmap_comp {
00091                         LSUINT16                                        cmp;
00092                         LSUINT8                                         mtyp, pcol;
00093                 } opj_jp2_cmap_comp_t;
00094 
00098                 typedef struct opj_jp2_pclr {
00099                         LSUINT32 *                                      entries;
00100                         LSUINT8 *                                       channel_sign;
00101                         LSUINT8 *                                       channel_size;
00102                         opj_jp2_cmap_comp_t *           cmap;
00103                         LSUINT16                                        nr_entries, nr_channels;
00104                 } opj_jp2_pclr_t;
00105 
00109                 typedef struct opj_jp2_color {
00110                         LSUINT8 *                                       icc_profile_buf;
00111                         LSINT32                                         icc_profile_len;
00112 
00113                         opj_jp2_cdef_t *                        jp2_cdef;
00114                         opj_jp2_pclr_t *                        jp2_pclr;
00115                         LSUINT8                                         jp2_has_colr;
00116                 } opj_jp2_color_t;
00117 
00121                 typedef struct opj_jp2_comps {
00122                         LSINT32                                         depth;
00123                         LSINT32                                         sgnd;
00124                         LSINT32                                         bpcc;
00125                 } opj_jp2_comps_t;
00126 
00130                 typedef struct opj_jp2 {
00132                         CJpegCommonStructs::opj_common_ptr
00133                                                                                 cinfo;
00135                         CJ2k::opj_j2k_t *                       j2k;
00136                         LSUINT32                                        w;
00137                         LSUINT32                                        h;
00138                         LSUINT32                                        numcomps;
00139                         LSUINT32                                        bpc;
00140                         LSUINT32                                        C;
00141                         LSUINT32                                        UnkC;
00142                         LSUINT32                                        IPR;
00143                         LSUINT32                                        meth;
00144                         LSUINT32                                        approx;
00145                         LSUINT32                                        enumcs;
00146                         LSUINT32                                        precedence;
00147                         LSUINT32                                        brand;
00148                         LSUINT32                                        minversion;
00149                         LSUINT32                                        numcl;
00150                         LSUINT32 *                                      cl;
00151                         opj_jp2_comps_t *                       comps;
00152                         LSUINT32                                        j2k_codestream_offset;
00153                         LSUINT32                                        j2k_codestream_length;
00154                 } opj_jp2_t;
00155 
00159                 typedef struct opj_jp2_box {
00160                         LSINT32                                         length;
00161                         LSINT32                                         type;
00162                         LSINT32                                         init_pos;
00163                 } opj_jp2_box_t;
00164 
00165                 
00166 
00167                 // == Functions.
00174                 static LSVOID LSE_CALL                  jp2_write_jp2h( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio );
00175 
00184                 static LSBOOL LSE_CALL                  jp2_read_jp2h( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio, opj_jp2_color_t * _pjcColor );
00185 
00192                 static opj_jp2_t * LSE_CALL             jp2_create_decompress( CJpegCommonStructs::opj_common_ptr _cpInfo );
00193 
00199                 static LSVOID LSE_CALL                  jp2_destroy_decompress( opj_jp2_t * _pjJp2 );
00200 
00208                 static LSVOID LSE_CALL                  jp2_setup_decoder( opj_jp2_t * _pjJp2, CJpegCommonStructs::opj_dparameters_t * _pdParameters );
00209 
00218                 static CJpegImage::opj_image_t * LSE_CALL
00219                                                                                 jp2_decode( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio, CJpegCommonStructs::opj_codestream_info_t * _pciInfo );
00220 
00227                 static opj_jp2_t * LSE_CALL             jp2_create_compress( CJpegCommonStructs::opj_common_ptr _cpInfo );
00228 
00234                 static LSVOID LSE_CALL                  jp2_destroy_compress( opj_jp2_t * _pjJp2 );
00235 
00244                 static LSVOID LSE_CALL                  jp2_setup_encoder( opj_jp2_t * _pjJp2, CJpegCommonStructs::opj_cparameters_t * _pdParameters, CJpegImage::opj_image_t * _piImage );
00245 
00255                 static LSBOOL LSE_CALL                  jp2_encode( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio, CJpegImage::opj_image_t * _piImage, CJpegCommonStructs::opj_codestream_info_t * _pciInfo );
00256 
00257 
00258         protected :
00259                 // == Functions.
00268                 static LSBOOL LSE_CALL                  jp2_read_boxhdr( CJpegCommonStructs::opj_common_ptr _cpInfo, CCio::opj_cio_t * _pcCio, opj_jp2_box_t * _pjbBox );
00269 
00277                 static LSBOOL LSE_CALL                  jp2_read_ihdr( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio );
00278 
00285                 static LSVOID LSE_CALL                  jp2_write_ihdr( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio );
00286 
00293                 static LSVOID LSE_CALL                  jp2_write_bpcc( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio );
00294 
00302                 static LSBOOL LSE_CALL                  jp2_read_bpcc( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio );
00303 
00310                 static LSVOID LSE_CALL                  jp2_write_colr( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio );
00311 
00318                 static LSVOID LSE_CALL                  jp2_write_ftyp( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio );
00319 
00327                 static LSBOOL LSE_CALL                  jp2_read_ftyp( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio );
00328 
00338                 static LSINT32 LSE_CALL                 jp2_write_jp2c( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio, CJpegImage::opj_image_t * _piImage, CJpegCommonStructs::opj_codestream_info_t * _pciInfo );
00339 
00349                 static LSBOOL LSE_CALL                  jp2_read_jp2c( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio, LSUINT32 * _pui32CodeStreamLen, LSUINT32 * _pui32CodeStreamOffset );
00350 
00356                 static LSVOID LSE_CALL                  jp2_write_jp( CCio::opj_cio_t * _pcCio );
00357 
00365                 static LSBOOL LSE_CALL                  jp2_read_jp( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio );
00366 
00375                 static LSBOOL LSE_CALL                  jp2_read_struct( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio, 
00376                         opj_jp2_color_t * _pjcColor );
00377 
00384                 static LSVOID LSE_CALL                  jp2_apply_pclr( opj_jp2_color_t * _pjcColor, CJpegImage::opj_image_t * _piImage );
00385 
00395                 static LSBOOL LSE_CALL                  jp2_read_pclr( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio, 
00396                         opj_jp2_box_t * _pjbBox, opj_jp2_color_t * _pjcColor );
00397 
00407                 static LSBOOL LSE_CALL                  jp2_read_cmap( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio, 
00408                         opj_jp2_box_t * _pjbBox, opj_jp2_color_t * _pjcColor );
00409 
00419                 static LSBOOL LSE_CALL                  jp2_read_colr( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio, 
00420                         opj_jp2_box_t * _pjbBox, opj_jp2_color_t * _pjcColor );
00421 
00431                 static LSBOOL LSE_CALL                  jp2_read_cdef( opj_jp2_t * _pjJp2, CCio::opj_cio_t * _pcCio, 
00432                         opj_jp2_box_t * _pjbBox, opj_jp2_color_t * _pjcColor );
00433 
00439                 static LSVOID LSE_CALL                  free_color_data( opj_jp2_color_t * _pjcColor );
00440 
00447                 static LSVOID LSE_CALL                  jp2_apply_cdef( CJpegImage::opj_image_t * _piImage, opj_jp2_color_t * _pjcColor );
00448 
00454                 static LSVOID LSE_CALL                  jp2_free_pclr( opj_jp2_color_t * _pjcColor );
00455 
00456         };
00457 
00458 }       // namespace lsi
00459 
00460 #endif  // __LSI_JP2_H__
00461 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator