29 #ifndef PGF_PGFPLATFORM_H
30 #define PGF_PGFPLATFORM_H
40 #if defined(_HOST_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || defined(WORDS_BIGENDIAN)
41 #define PGF_USE_BIG_ENDIAN 1
44 #if defined(__sgi__) || defined(__sgi) || defined(__powerpc__) || defined(__sparc) || defined(__sparc__)
45 #define PGF_USE_BIG_ENDIAN 1
48 #if defined(__ppc__) || defined(__s390__) || defined(__s390x__)
49 #define PGF_USE_BIG_ENDIAN 1
53 #define PGF_USE_BIG_ENDIAN 1
60 #define __PGFROISUPPORT__ // without ROI support the program code gets simpler and smaller
67 #define __PGF32SUPPORT__ // without 32 bit the memory consumption during encoding and decoding is much lesser
74 #define WordWidthLog 5
75 #define WordMask 0xFFFFFFE0
77 #define WordBytesMask 0xFFFFFFFC
78 #define WordBytesLog 2
83 #define DWWIDTHBITS(bits) (((bits) + WordWidth - 1) & WordMask)
84 #define DWWIDTH(bytes) (((bytes) + WordBytes - 1) & WordBytesMask)
85 #define DWWIDTHREST(bytes) ((WordBytes - (bytes)%WordBytes)%WordBytes)
91 #define __min(x, y) ((x) <= (y) ? (x) : (y))
92 #define __max(x, y) ((x) >= (y) ? (x) : (y))
98 #define ImageModeBitmap 0
99 #define ImageModeGrayScale 1
100 #define ImageModeIndexedColor 2
101 #define ImageModeRGBColor 3
102 #define ImageModeCMYKColor 4
103 #define ImageModeHSLColor 5
104 #define ImageModeHSBColor 6
105 #define ImageModeMultichannel 7
106 #define ImageModeDuotone 8
107 #define ImageModeLabColor 9
108 #define ImageModeGray16 10
109 #define ImageModeRGB48 11
110 #define ImageModeLab48 12
111 #define ImageModeCMYK64 13
112 #define ImageModeDeepMultichannel 14
113 #define ImageModeDuotone16 15
115 #define ImageModeRGBA 17
116 #define ImageModeGray32 18
117 #define ImageModeRGB12 19
118 #define ImageModeRGB16 20
119 #define ImageModeUnknown 255
125 #if defined(WIN32) || defined(WINCE)
126 #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
135 #include <afxdtctl.h>
136 #ifndef _AFX_NO_AFXCMN_SUPPORT
138 #endif // _AFX_NO_AFXCMN_SUPPORT
149 #define DllExport __declspec( dllexport )
154 typedef unsigned char UINT8;
155 typedef unsigned char BYTE;
156 typedef unsigned short UINT16;
157 typedef unsigned short WORD;
158 typedef unsigned int UINT32;
159 typedef unsigned long DWORD;
160 typedef unsigned long ULONG;
161 typedef unsigned __int64 UINT64;
162 typedef unsigned __int64 ULONGLONG;
167 typedef signed char INT8;
168 typedef signed short INT16;
169 typedef signed int INT32;
170 typedef signed int BOOL;
171 typedef signed long LONG;
172 typedef signed __int64 INT64;
173 typedef signed __int64 LONGLONG;
179 typedef bool (__cdecl *CallbackPtr)(
double percent,
bool escapeAllowed,
void *data);
190 #define ASSERT(x) assert(x)
192 #if defined(__GNUC__)
193 #define ASSERT(ignore)((void) 0)
194 #elif _MSC_VER >= 1300
195 #define ASSERT __noop
197 #define ASSERT ((void)0)
206 extern OSError _PGF_Error_;
207 extern OSError GetLastPGFError();
209 #define ReturnWithError(err) { _PGF_Error_ = err; return; }
210 #define ReturnWithError2(err, ret) { _PGF_Error_ = err; return ret; }
212 #define ReturnWithError(err) throw IOException(err)
213 #define ReturnWithError2(err, ret) throw IOException(err)
218 #pragma warning( disable : 4290 )
219 #define THROW_ throw(IOException)
227 #define FSFromStart FILE_BEGIN // 0
228 #define FSFromCurrent FILE_CURRENT // 1
229 #define FSFromEnd FILE_END // 2
231 #define INVALID_SET_FILE_POINTER ((DWORD)-1)
236 #define NoError ERROR_SUCCESS
237 #define AppError 0x20000000
238 #define InsufficientMemory 0x20000001
239 #define InvalidStreamPos 0x20000002
240 #define EscapePressed 0x20000003
241 #define WrongVersion 0x20000004
242 #define FormatCannotRead 0x20000005
243 #define ImageTooSmall 0x20000006
244 #define ZlibError 0x20000007
245 #define ColorTableError 0x20000008
246 #define PNGError 0x20000009
247 #define MissingData 0x2000000A
252 inline OSError FileRead(HANDLE hFile,
int *count,
void *buffPtr) {
253 if (ReadFile(hFile, buffPtr, *count, (ULONG *)count, NULL)) {
256 return GetLastError();
260 inline OSError FileWrite(HANDLE hFile,
int *count,
void *buffPtr) {
261 if (WriteFile(hFile, buffPtr, *count, (ULONG *)count, NULL)) {
264 return GetLastError();
268 inline OSError GetFPos(HANDLE hFile, UINT64 *pos) {
273 li.LowPart = SetFilePointer (hFile, li.LowPart, &li.HighPart, FILE_CURRENT);
274 if (li.LowPart == INVALID_SET_FILE_POINTER) {
275 OSError err = GetLastError();
276 if (err != NoError) {
285 if (SetFilePointerEx(hFile, li, (PLARGE_INTEGER)pos, FILE_CURRENT)) {
288 return GetLastError();
293 inline OSError SetFPos(HANDLE hFile,
int posMode, INT64 posOff) {
296 li.QuadPart = posOff;
298 if (SetFilePointer (hFile, li.LowPart, &li.HighPart, posMode) == INVALID_SET_FILE_POINTER) {
299 OSError err = GetLastError();
300 if (err != NoError) {
307 li.QuadPart = posOff;
308 if (SetFilePointerEx(hFile, li, NULL, posMode)) {
311 return GetLastError();
329 #if defined(__linux__) || defined(__GLIBC__)
331 #endif // __linux__ or __GLIBC__
345 #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
351 #define off64_t off_t
355 #define lseek64 lseek
358 #endif // __NetBSD__ or __OpenBSD__ or __FreeBSD__
375 typedef unsigned char UINT8;
376 typedef unsigned char BYTE;
377 typedef unsigned short UINT16;
378 typedef unsigned short WORD;
379 typedef unsigned int UINT32;
380 typedef unsigned int DWORD;
381 typedef unsigned long ULONG;
382 typedef unsigned long long __Uint64;
383 typedef __Uint64 UINT64;
384 typedef __Uint64 ULONGLONG;
389 typedef signed char INT8;
390 typedef signed short INT16;
391 typedef signed int INT32;
392 typedef signed int BOOL;
393 typedef signed long LONG;
394 typedef int64_t INT64;
395 typedef int64_t LONGLONG;
402 typedef unsigned long ULONG_PTR;
404 typedef char* LPTSTR;
405 typedef bool (*CallbackPtr)(
double percent,
bool escapeAllowed,
void *data);
410 typedef struct tagRGBTRIPLE {
416 typedef struct tagRGBQUAD {
423 typedef union _LARGE_INTEGER {
433 } LARGE_INTEGER, *PLARGE_INTEGER;
437 #if defined(__POSIX__) || defined(WINCE)
439 #define GetKValue(cmyk) ((BYTE)(cmyk))
440 #define GetYValue(cmyk) ((BYTE)((cmyk)>> 8))
441 #define GetMValue(cmyk) ((BYTE)((cmyk)>>16))
442 #define GetCValue(cmyk) ((BYTE)((cmyk)>>24))
443 #define CMYK(c,m,y,k) ((COLORREF)((((BYTE)(k)|((WORD)((BYTE)(y))<<8))|(((DWORD)(BYTE)(m))<<16))|(((DWORD)(BYTE)(c))<<24)))
453 __inline
int MulDiv(
int nNumber,
int nNumerator,
int nDenominator) {
454 INT64 multRes = nNumber*nNumerator;
455 INT32 divRes = INT32(multRes/nDenominator);
458 #endif // __POSIX__ or WINCE
467 #define ASSERT(x) assert(x)
477 extern OSError _PGF_Error_;
478 extern OSError GetLastPGFError();
480 #define ReturnWithError(err) { _PGF_Error_ = err; return; }
481 #define ReturnWithError2(err, ret) { _PGF_Error_ = err; return ret; }
483 #define ReturnWithError(err) throw IOException(err)
484 #define ReturnWithError2(err, ret) throw IOException(err)
487 #define THROW_ throw(IOException)
493 #define FSFromStart SEEK_SET
494 #define FSFromCurrent SEEK_CUR
495 #define FSFromEnd SEEK_END
500 #define NoError 0x0000
501 #define AppError 0x2000
502 #define InsufficientMemory 0x2001
503 #define InvalidStreamPos 0x2002
504 #define EscapePressed 0x2003
505 #define WrongVersion 0x2004
506 #define FormatCannotRead 0x2005
507 #define ImageTooSmall 0x2006
508 #define ZlibError 0x2007
509 #define ColorTableError 0x2008
510 #define PNGError 0x2009
511 #define MissingData 0x200A
516 __inline OSError FileRead(HANDLE hFile,
int *count,
void *buffPtr) {
517 *count = (int)read(hFile, buffPtr, *count);
525 __inline OSError FileWrite(HANDLE hFile,
int *count,
void *buffPtr) {
526 *count = (int)write(hFile, buffPtr, (
size_t)*count);
534 __inline OSError GetFPos(HANDLE hFile, UINT64 *pos) {
537 if ((ret = lseek(hFile, 0, SEEK_CUR)) == -1) {
545 if ((ret = lseek64(hFile, 0, SEEK_CUR)) == -1) {
554 __inline OSError SetFPos(HANDLE hFile,
int posMode, INT64 posOff) {
556 if ((lseek(hFile, (off_t)posOff, posMode)) == -1) {
562 if ((lseek64(hFile, (off64_t)posOff, posMode)) == -1) {
577 #ifdef PGF_USE_BIG_ENDIAN
580 #define _lrotl(x,n) (((x) << ((UINT32)(n))) | ((x) >> (32 - (UINT32)(n))))
583 __inline UINT16 ByteSwap(UINT16 wX) {
584 return ((wX & 0xFF00) >> 8) | ((wX & 0x00FF) << 8);
587 __inline UINT32 ByteSwap(UINT32 dwX) {
594 return _lrotl(((dwX & 0xFF00FF00) >> 8) | ((dwX & 0x00FF00FF) << 8), 16);
599 __inline UINT64 ByteSwap(UINT64 ui64) {
600 return _byteswap_uint64(ui64);
604 #define __VAL(x) ByteSwap(x)
606 #else //PGF_USE_BIG_ENDIAN
610 #endif //PGF_USE_BIG_ENDIAN
614 #ifndef LIBPGF_DISABLE_OPENMP
615 #if defined (_OPENMP)
617 # if defined (_MSC_VER) && (_MSC_VER >= 1500)
619 # define LIBPGF_USE_OPENMP
620 # elif defined (__INTEL_COMPILER) && (__INTEL_COMPILER >=910)
622 # define LIBPGF_USE_OPENMP
624 # undef LIBPGF_USE_OPENMP
627 # elif (defined(__APPLE__) || defined(__MACOSX__)) && defined(_REENTRANT)
628 # undef LIBPGF_USE_OPENMP
630 # define LIBPGF_USE_OPENMP
632 #endif // defined (_OPENMP)
633 #endif // ifndef LIBPGF_DISABLE_OPENMP
634 #ifdef LIBPGF_USE_OPENMP
638 #endif //PGF_PGFPLATFORM_H