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 // 565
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 // MSB is 0 (can be interpreted as signed 15.16 fixed point format)
117 #define ImageModeRGB12 19
118 #define ImageModeRGB16 20
119 #define ImageModeUnknown 255
125 #if defined(WIN32) || defined(WINCE) || defined(WIN64)
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 {
429 } LARGE_INTEGER, *PLARGE_INTEGER;
433 #if defined(__POSIX__) || defined(WINCE)
435 #define GetKValue(cmyk) ((BYTE)(cmyk))
436 #define GetYValue(cmyk) ((BYTE)((cmyk)>> 8))
437 #define GetMValue(cmyk) ((BYTE)((cmyk)>>16))
438 #define GetCValue(cmyk) ((BYTE)((cmyk)>>24))
439 #define CMYK(c,m,y,k) ((COLORREF)((((BYTE)(k)|((WORD)((BYTE)(y))<<8))|(((DWORD)(BYTE)(m))<<16))|(((DWORD)(BYTE)(c))<<24)))
449 __inline
int MulDiv(
int nNumber,
int nNumerator,
int nDenominator) {
450 INT64 multRes = nNumber*nNumerator;
451 INT32 divRes = INT32(multRes/nDenominator);
454 #endif // __POSIX__ or WINCE
463 #define ASSERT(x) assert(x)
473 extern OSError _PGF_Error_;
474 extern OSError GetLastPGFError();
476 #define ReturnWithError(err) { _PGF_Error_ = err; return; }
477 #define ReturnWithError2(err, ret) { _PGF_Error_ = err; return ret; }
479 #define ReturnWithError(err) throw IOException(err)
480 #define ReturnWithError2(err, ret) throw IOException(err)
483 #define THROW_ throw(IOException)
489 #define FSFromStart SEEK_SET
490 #define FSFromCurrent SEEK_CUR
491 #define FSFromEnd SEEK_END
496 #define NoError 0x0000
497 #define AppError 0x2000
498 #define InsufficientMemory 0x2001
499 #define InvalidStreamPos 0x2002
500 #define EscapePressed 0x2003
501 #define WrongVersion 0x2004
502 #define FormatCannotRead 0x2005
503 #define ImageTooSmall 0x2006
504 #define ZlibError 0x2007
505 #define ColorTableError 0x2008
506 #define PNGError 0x2009
507 #define MissingData 0x200A
512 __inline OSError FileRead(HANDLE hFile,
int *count,
void *buffPtr) {
513 *count = (int)read(hFile, buffPtr, *count);
521 __inline OSError FileWrite(HANDLE hFile,
int *count,
void *buffPtr) {
522 *count = (int)write(hFile, buffPtr, (
size_t)*count);
530 __inline OSError GetFPos(HANDLE hFile, UINT64 *pos) {
533 if ((ret = lseek(hFile, 0, SEEK_CUR)) == -1) {
541 if ((ret = lseek64(hFile, 0, SEEK_CUR)) == -1) {
550 __inline OSError SetFPos(HANDLE hFile,
int posMode, INT64 posOff) {
552 if ((lseek(hFile, (off_t)posOff, posMode)) == -1) {
558 if ((lseek64(hFile, (off64_t)posOff, posMode)) == -1) {
573 #ifdef PGF_USE_BIG_ENDIAN
576 #define _lrotl(x,n) (((x) << ((UINT32)(n))) | ((x) >> (32 - (UINT32)(n))))
579 __inline UINT16 ByteSwap(UINT16 wX) {
580 return ((wX & 0xFF00) >> 8) | ((wX & 0x00FF) << 8);
583 __inline UINT32 ByteSwap(UINT32 dwX) {
590 return _lrotl(((dwX & 0xFF00FF00) >> 8) | ((dwX & 0x00FF00FF) << 8), 16);
594 #if defined(WIN32) || defined(WIN64)
595 __inline UINT64 ByteSwap(UINT64 ui64) {
596 return _byteswap_uint64(ui64);
600 #define __VAL(x) ByteSwap(x)
602 #else //PGF_USE_BIG_ENDIAN
606 #endif //PGF_USE_BIG_ENDIAN
610 #define LIBPGF_DISABLE_OPENMP
611 #undef LIBPGF_USE_OPENMP
613 #ifndef LIBPGF_DISABLE_OPENMP
614 # if defined (_OPENMP)
615 # if defined (WIN32) || defined(WIN64)
616 # if defined (_MSC_VER) && (_MSC_VER >= 1500)
618 # define LIBPGF_USE_OPENMP
619 # elif defined (__INTEL_COMPILER) && (__INTEL_COMPILER >=910)
621 # define LIBPGF_USE_OPENMP
623 # undef LIBPGF_USE_OPENMP
626 # elif (defined(__APPLE__) || defined(__MACOSX__)) && defined(_REENTRANT)
627 # undef LIBPGF_USE_OPENMP
629 # define LIBPGF_USE_OPENMP
631 # endif // defined (_OPENMP)
632 #endif // ifndef LIBPGF_DISABLE_OPENMP
633 #ifdef LIBPGF_USE_OPENMP
637 #endif //PGF_PGFPLATFORM_H