]> Creatis software - clitk.git/blob - utilities/CxImage/ximajas.h
ROI Debug
[clitk.git] / utilities / CxImage / ximajas.h
1 /*\r
2  * File:        ximajas.h\r
3  * Purpose:     Jasper Image Class Loader and Writer\r
4  */\r
5 /* ==========================================================\r
6  * CxImageJAS (c) 12/Apr/2003 Davide Pizzolato - www.xdp.it\r
7  * For conditions of distribution and use, see copyright notice in ximage.h\r
8  *\r
9  * based on JasPer Copyright (c) 2001-2003 Michael David Adams - All rights reserved.\r
10  * ==========================================================\r
11  */\r
12 #if !defined(__ximaJAS_h)\r
13 #define __ximaJAS_h\r
14 \r
15 #include "ximage.h"\r
16 \r
17 #if CXIMAGE_SUPPORT_JASPER\r
18 \r
19 #include "../jasper/include/jasper/jasper.h"\r
20 \r
21 class CxImageJAS: public CxImage\r
22 {\r
23 public:\r
24         CxImageJAS(): CxImage((DWORD)0) {}      // <vho> cast to DWORD\r
25 \r
26 //      bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,0);}\r
27 //      bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,0);}\r
28         bool Decode(CxFile * hFile, DWORD imagetype = 0);\r
29         bool Decode(FILE *hFile, DWORD imagetype = 0) { CxIOFile file(hFile); return Decode(&file,imagetype); }\r
30 \r
31 #if CXIMAGE_SUPPORT_ENCODE\r
32         bool Encode(CxFile * hFile, DWORD imagetype = 0);\r
33         bool Encode(FILE *hFile, DWORD imagetype = 0) { CxIOFile file(hFile); return Encode(&file,imagetype); }\r
34 #endif // CXIMAGE_SUPPORT_ENCODE\r
35 protected:\r
36 \r
37         class CxFileJas\r
38         {\r
39         public:\r
40                 CxFileJas(CxFile* pFile,jas_stream_t *stream)\r
41                 {\r
42                         if (stream->obj_) jas_free(stream->obj_);\r
43                         stream->obj_ = pFile;\r
44 \r
45                         // <vho> - cannot set the stream->ops_->functions here,\r
46                         // because this overwrites a static structure in the Jasper library.\r
47                         // This structure is used by Jasper for internal operations too, e.g. tempfile.\r
48                         // However the ops_ pointer in the stream can be overwritten.\r
49 \r
50                         //stream->ops_->close_ = JasClose;\r
51                         //stream->ops_->read_  = JasRead;\r
52                         //stream->ops_->seek_  = JasSeek;\r
53                         //stream->ops_->write_ = JasWrite;\r
54 \r
55                         jas_stream_CxFile.close_ = JasClose;\r
56                         jas_stream_CxFile.read_  = JasRead;\r
57                         jas_stream_CxFile.seek_  = JasSeek;\r
58                         jas_stream_CxFile.write_ = JasWrite;\r
59 \r
60                         stream->ops_ = &jas_stream_CxFile;\r
61 \r
62                         // <vho> - end\r
63                 }\r
64                 static int JasRead(jas_stream_obj_t *obj, char *buf, int cnt)\r
65                 {               return ((CxFile*)obj)->Read(buf,1,cnt); }\r
66                 static int JasWrite(jas_stream_obj_t *obj, char *buf, int cnt)\r
67                 {               return ((CxFile*)obj)->Write(buf,1,cnt); }\r
68                 static long JasSeek(jas_stream_obj_t *obj, long offset, int origin)\r
69                 {               return ((CxFile*)obj)->Seek(offset,origin); }\r
70                 static int JasClose(jas_stream_obj_t * /*obj*/)\r
71                 {               return 1; }\r
72 \r
73         // <vho>\r
74 private:\r
75                 jas_stream_ops_t jas_stream_CxFile;\r
76         // <vho> - end\r
77 \r
78         };\r
79 \r
80 };\r
81 \r
82 #endif\r
83 \r
84 #endif\r