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