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
132 #ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista.
133 #define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows.
138 #include <afxdtctl.h>
139 #ifndef _AFX_NO_AFXCMN_SUPPORT
141 #endif // _AFX_NO_AFXCMN_SUPPORT
151 #define DllExport __declspec( dllexport )
156 typedef unsigned char UINT8;
157 typedef unsigned char BYTE;
158 typedef unsigned short UINT16;
159 typedef unsigned short WORD;
160 typedef unsigned int UINT32;
161 typedef unsigned long DWORD;
162 typedef unsigned long ULONG;
163 typedef unsigned __int64 UINT64;
164 typedef unsigned __int64 ULONGLONG;
169 typedef signed char INT8;
170 typedef signed short INT16;
171 typedef signed int INT32;
172 typedef signed int BOOL;
173 typedef signed long LONG;
174 typedef signed __int64 INT64;
175 typedef signed __int64 LONGLONG;
181 typedef bool (__cdecl *CallbackPtr)(
double percent,
bool escapeAllowed,
void *data);
192 #define ASSERT(x) assert(x)
194 #if defined(__GNUC__)
195 #define ASSERT(ignore)((void) 0)
196 #elif _MSC_VER >= 1300
197 #define ASSERT __noop
199 #define ASSERT ((void)0)
208 extern OSError _PGF_Error_;
209 extern OSError GetLastPGFError();
211 #define ReturnWithError(err) { _PGF_Error_ = err; return; }
212 #define ReturnWithError2(err, ret) { _PGF_Error_ = err; return ret; }
214 #define ReturnWithError(err) throw IOException(err)
215 #define ReturnWithError2(err, ret) throw IOException(err)
221 #define FSFromStart FILE_BEGIN // 0
222 #define FSFromCurrent FILE_CURRENT // 1
223 #define FSFromEnd FILE_END // 2
225 #define INVALID_SET_FILE_POINTER ((DWORD)-1)
230 #define NoError ERROR_SUCCESS
231 #define AppError 0x20000000
232 #define InsufficientMemory 0x20000001
233 #define InvalidStreamPos 0x20000002
234 #define EscapePressed 0x20000003
235 #define WrongVersion 0x20000004
236 #define FormatCannotRead 0x20000005
237 #define ImageTooSmall 0x20000006
238 #define ZlibError 0x20000007
239 #define ColorTableError 0x20000008
240 #define PNGError 0x20000009
241 #define MissingData 0x2000000A
246 inline OSError FileRead(HANDLE hFile,
int *count,
void *buffPtr) {
247 if (ReadFile(hFile, buffPtr, *count, (ULONG *)count,
nullptr)) {
250 return GetLastError();
254 inline OSError FileWrite(HANDLE hFile,
int *count,
void *buffPtr) {
255 if (WriteFile(hFile, buffPtr, *count, (ULONG *)count,
nullptr)) {
258 return GetLastError();
262 inline OSError GetFPos(HANDLE hFile, UINT64 *pos) {
267 li.LowPart = SetFilePointer (hFile, li.LowPart, &li.HighPart, FILE_CURRENT);
268 if (li.LowPart == INVALID_SET_FILE_POINTER) {
269 OSError err = GetLastError();
270 if (err != NoError) {
279 if (SetFilePointerEx(hFile, li, (PLARGE_INTEGER)pos, FILE_CURRENT)) {
282 return GetLastError();
287 inline OSError SetFPos(HANDLE hFile,
int posMode, INT64 posOff) {
290 li.QuadPart = posOff;
292 if (SetFilePointer (hFile, li.LowPart, &li.HighPart, posMode) == INVALID_SET_FILE_POINTER) {
293 OSError err = GetLastError();
294 if (err != NoError) {
301 li.QuadPart = posOff;
302 if (SetFilePointerEx(hFile, li,
nullptr, posMode)) {
305 return GetLastError();
323 #if defined(__linux__) || defined(__GLIBC__)
325 #endif // __linux__ or __GLIBC__
339 #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
345 #define off64_t off_t
349 #define lseek64 lseek
352 #endif // __NetBSD__ or __OpenBSD__ or __FreeBSD__
371 typedef unsigned char UINT8;
372 typedef unsigned char BYTE;
373 typedef unsigned short UINT16;
374 typedef unsigned short WORD;
375 typedef unsigned int UINT32;
376 typedef unsigned int DWORD;
377 typedef unsigned long ULONG;
378 typedef unsigned long long __Uint64;
379 typedef __Uint64 UINT64;
380 typedef __Uint64 ULONGLONG;
385 typedef signed char INT8;
386 typedef signed short INT16;
387 typedef signed int INT32;
388 typedef signed int BOOL;
389 typedef signed long LONG;
390 typedef int64_t INT64;
391 typedef int64_t LONGLONG;
398 typedef unsigned long ULONG_PTR;
400 typedef char* LPTSTR;
401 typedef bool (*CallbackPtr)(
double percent,
bool escapeAllowed,
void *data);
406 typedef struct tagRGBTRIPLE {
412 typedef struct tagRGBQUAD {
419 typedef union _LARGE_INTEGER {
425 } LARGE_INTEGER, *PLARGE_INTEGER;
429 #if defined(__POSIX__) || defined(WINCE)
431 #define GetKValue(cmyk) ((BYTE)(cmyk))
432 #define GetYValue(cmyk) ((BYTE)((cmyk)>> 8))
433 #define GetMValue(cmyk) ((BYTE)((cmyk)>>16))
434 #define GetCValue(cmyk) ((BYTE)((cmyk)>>24))
435 #define CMYK(c,m,y,k) ((COLORREF)((((BYTE)(k)|((WORD)((BYTE)(y))<<8))|(((DWORD)(BYTE)(m))<<16))|(((DWORD)(BYTE)(c))<<24)))
445 __inline
int MulDiv(
int nNumber,
int nNumerator,
int nDenominator) {
446 INT64 multRes = nNumber*nNumerator;
447 INT32 divRes = INT32(multRes/nDenominator);
450 #endif // __POSIX__ or WINCE
459 #define ASSERT(x) assert(x)
469 extern OSError _PGF_Error_;
470 extern OSError GetLastPGFError();
472 #define ReturnWithError(err) { _PGF_Error_ = err; return; }
473 #define ReturnWithError2(err, ret) { _PGF_Error_ = err; return ret; }
475 #define ReturnWithError(err) throw IOException(err)
476 #define ReturnWithError2(err, ret) throw IOException(err)
479 #define THROW_ throw(IOException)
485 #define FSFromStart SEEK_SET
486 #define FSFromCurrent SEEK_CUR
487 #define FSFromEnd SEEK_END
493 #define NoError 0x0000
494 #define AppError 0x2000
495 #define InsufficientMemory 0x2001
496 #define InvalidStreamPos 0x2002
497 #define EscapePressed 0x2003
498 #define WrongVersion 0x2004
499 #define FormatCannotRead 0x2005
500 #define ImageTooSmall 0x2006
501 #define ZlibError 0x2007
502 #define ColorTableError 0x2008
503 #define PNGError 0x2009
504 #define MissingData 0x200A
509 __inline OSError FileRead(HANDLE hFile,
int *count,
void *buffPtr) {
510 *count = (int)read(hFile, buffPtr, *count);
518 __inline OSError FileWrite(HANDLE hFile,
int *count,
void *buffPtr) {
519 *count = (int)write(hFile, buffPtr, (
size_t)*count);
527 __inline OSError GetFPos(HANDLE hFile, UINT64 *pos) {
530 if ((ret = lseek(hFile, 0, SEEK_CUR)) == -1) {
538 if ((ret = lseek64(hFile, 0, SEEK_CUR)) == -1) {
547 __inline OSError SetFPos(HANDLE hFile,
int posMode, INT64 posOff) {
549 if ((lseek(hFile, (off_t)posOff, posMode)) == -1) {
555 if ((lseek64(hFile, (off64_t)posOff, posMode)) == -1) {
570 #ifdef PGF_USE_BIG_ENDIAN
573 #define _lrotl(x,n) (((x) << ((UINT32)(n))) | ((x) >> (32 - (UINT32)(n))))
576 __inline UINT16 ByteSwap(UINT16 wX) {
577 return ((wX & 0xFF00) >> 8) | ((wX & 0x00FF) << 8);
580 __inline UINT32 ByteSwap(UINT32 dwX) {
587 return _lrotl(((dwX & 0xFF00FF00) >> 8) | ((dwX & 0x00FF00FF) << 8), 16);
591 #if defined(WIN32) || defined(WIN64)
592 __inline UINT64 ByteSwap(UINT64 ui64) {
593 return _byteswap_uint64(ui64);
597 #define __VAL(x) ByteSwap(x)
599 #else //PGF_USE_BIG_ENDIAN
603 #endif //PGF_USE_BIG_ENDIAN
607 #ifndef LIBPGF_DISABLE_OPENMP
608 # if defined (_OPENMP)
609 # if defined (WIN32) || defined(WIN64)
610 # if defined (_MSC_VER) && (_MSC_VER >= 1500)
612 # define LIBPGF_USE_OPENMP
613 # elif defined (__INTEL_COMPILER) && (__INTEL_COMPILER >=910)
615 # define LIBPGF_USE_OPENMP
617 # undef LIBPGF_USE_OPENMP
620 # elif (defined(__APPLE__) || defined(__MACOSX__)) && defined(_REENTRANT)
621 # undef LIBPGF_USE_OPENMP
623 # define LIBPGF_USE_OPENMP
625 # endif // defined (_OPENMP)
626 #endif // ifndef LIBPGF_DISABLE_OPENMP
627 #ifdef LIBPGF_USE_OPENMP
631 #endif //PGF_PGFPLATFORM_H