00001 
00002 #ifndef  __JBXL_JP2K_TOOL_H_
00003 #define  __JBXL_JP2K_TOOL_H_
00004 
00018 #include "xtools.h"
00019 
00020 #ifndef HAVE_OPENJPEG_H
00021 #ifndef DISABLE_OPENJPEG
00022 #define DISABLE_OPENJPEG
00023 #endif
00024 #endif
00025 
00026 #ifdef  DISABLE_OPENJPEG
00027 #undef  ENABLE_OPENJPEG
00028 #endif
00029 
00030 
00031 #ifdef  ENABLE_OPENJPEG
00032 
00033 #ifndef OPENJPEG_VER
00034   #define OPENJPEG_VER  12
00035 #endif
00036 
00037 #define JP2K_VER_12     12
00038 #define JP2K_VER_14     14
00039 #define JP2K_VER_15     15
00040 #define JP2K_VER_20     20
00041 #define JP2K_VER_21     21
00042 
00043 
00044 #include "gdata.h"
00045 
00046 
00047 #if OPENJPEG_VER <= JP2K_VER_15
00048   #undef OFF
00049   #ifdef WIN32
00050     #ifdef _DEBUG
00051       #pragma  comment(lib, "LibOpenJPEGd.lib")
00052     #else
00053       #pragma  comment(lib, "LibOpenJPEG.lib")
00054     #endif
00055   #endif
00056 #elif OPENJPEG_VER == JP2K_VER_21
00057   #ifdef WIN32
00058     #pragma  comment(lib, "openjp2.lib")
00059   #endif
00060 #else       // default JP2K_VER_20
00061   #ifdef WIN32
00062     #pragma  comment(lib, "openjp2.lib")
00063   #endif
00064 #endif
00065 
00066 #include <openjpeg.h>
00067 
00068 
00069 #define JP2K_MAGIC_RFC3745_JP2  "\x00\x00\x00\x0c\x6a\x50\x20\x20\x0d\x0a\x87\x0a"
00070 #define JP2K_MAGIC_JP2          "\x0d\x0a\x87\x0a"
00071 #define JP2K_MAGIC_J2K          "\xff\x4f\xff\x51"
00072 
00073 #define JP2K_FMT_NONE           0
00074 #define JP2K_FMT_JP2            1
00075 #define JP2K_FMT_J2K            2
00076 #define JP2K_FMT_JPT            3
00077 
00078 
00079 typedef struct
00080 {
00081     int             xs;
00082     int             ys;
00083     int             ws;
00084     int             hs;
00085     int             col;
00086     int             cmode;
00087     int             state;
00088     opj_image_t*    image;
00089     
00090 } JP2KImage;
00091 
00092 
00094 
00095 void      init_jp2k(JP2KImage* jp);
00096 void      free_jp2k(JP2KImage* jp);
00097 void      setup_jp2k(JP2KImage* jp);
00098 int       get_jp2k_format(uByte* header);
00099 
00100 JP2KImage read_jp2k_file(const char* fname);
00101 
00102 
00103 #if   OPENJPEG_VER <= JP2K_VER_15
00104 JP2KImage read_jp2k_data(unsigned char* data, int len, int format);
00105 #elif OPENJPEG_VER == JP2K_VER_21
00106 JP2KImage read_jp2k_data(const char* fname, int format);
00107 #else               //JP2K_VER_20
00108 JP2KImage read_jp2k_data(FILE* fp, int format);
00109 #endif
00110 
00111 
00112 
00113 
00114 BSGraph   jp2k_toBSGraph(JP2KImage jp);
00115 
00116 
00117 
00118 
00119 #endif      // ENABLE_OPENJPEG
00120 
00121 #endif      // __JBXL_JP2K_TOOL_H_
00122