Subversion Repositories Scribus

Rev

Rev 16911 | Rev 19721 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
15796 fschmid 1
/*
2
 * The Progressive Graphics File; http://www.libpgf.org
16771 fschmid 3
 *
15796 fschmid 4
 * $Date: 2007-06-12 19:27:47 +0200 (Di, 12 Jun 2007) $
5
 * $Revision: 307 $
16771 fschmid 6
 *
15796 fschmid 7
 * This file Copyright (C) 2006 xeraina GmbH, Switzerland
16771 fschmid 8
 *
15796 fschmid 9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
11
 * as published by the Free Software Foundation; either version 2.1
12
 * of the License, or (at your option) any later version.
16771 fschmid 13
 *
15796 fschmid 14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
16771 fschmid 18
 *
15796 fschmid 19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
18122 mrdocs 21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
15796 fschmid 22
 */
23
 
16771 fschmid 24
//////////////////////////////////////////////////////////////////////
25
/// @file PGFplatform.h
26
/// @brief PGF platform specific definitions
27
/// @author C. Stamm
28
 
15796 fschmid 29
#ifndef PGF_PGFPLATFORM_H
30
#define PGF_PGFPLATFORM_H
31
 
32
#include <cassert>
16771 fschmid 33
#include <cmath>
34
#include <cstdlib>
15796 fschmid 35
 
36
//-------------------------------------------------------------------------------
16771 fschmid 37
// Endianess detection taken from lcms2 header.
38
// This list can be endless, so only some checks are performed over here.
15796 fschmid 39
//-------------------------------------------------------------------------------
40
#if defined(_HOST_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || defined(WORDS_BIGENDIAN)
16771 fschmid 41
#define PGF_USE_BIG_ENDIAN 1
15796 fschmid 42
#endif
43
 
16771 fschmid 44
#if defined(__sgi__) || defined(__sgi) || defined(__powerpc__) || defined(__sparc) || defined(__sparc__)
45
#define PGF_USE_BIG_ENDIAN 1
15796 fschmid 46
#endif
47
 
48
#if defined(__ppc__) || defined(__s390__) || defined(__s390x__)
16771 fschmid 49
#define PGF_USE_BIG_ENDIAN 1
15796 fschmid 50
#endif
51
 
52
#ifdef TARGET_CPU_PPC
16771 fschmid 53
#define PGF_USE_BIG_ENDIAN 1
15796 fschmid 54
#endif
55
 
56
//-------------------------------------------------------------------------------
57
// ROI support
58
//-------------------------------------------------------------------------------
59
#ifndef NPGFROI
60
#define __PGFROISUPPORT__ // without ROI support the program code gets simpler and smaller
61
#endif
62
 
63
//-------------------------------------------------------------------------------
64
// 32 bit per channel support
65
//-------------------------------------------------------------------------------
66
#ifndef NPGF32
67
#define __PGF32SUPPORT__ // without 32 bit the memory consumption during encoding and decoding is much lesser
68
#endif
69
 
70
//-------------------------------------------------------------------------------
71
//      32 Bit platform constants
72
//-------------------------------------------------------------------------------
73
#define WordWidth                       32                                      // WordBytes*8
74
#define WordWidthLog            5                                       // ld of WordWidth
16771 fschmid 75
#define WordMask                        0xFFFFFFE0                      // least WordWidthLog bits are zero
15796 fschmid 76
#define WordBytes                       4                                       // sizeof(UINT32)
77
#define WordBytesLog            2                                       // ld of WordBytes
78
 
79
//-------------------------------------------------------------------------------
80
// Macros
81
//-------------------------------------------------------------------------------
16771 fschmid 82
//#define DWWIDTH(bytes)                ((((bytes) + WordBytes - 1) >> WordBytesLog) << WordBytesLog)   // aligns scanline width in bytes to DWORD value
83
//#define DWWIDTHBITS(bits)     ((((bits) + WordWidth - 1) >> WordWidthLog) << WordBytesLog)    // aligns scanline width in bits to DWORD value
84
//#define DWWIDTHREST(bytes)    ((WordBytes - (bytes)%WordBytes)%WordBytes)                                             // DWWIDTHBITS(bytes*8) - bytes
15796 fschmid 85
 
86
//-------------------------------------------------------------------------------
87
// Min-Max macros
88
//-------------------------------------------------------------------------------
89
#ifndef __min
90
        #define __min(x, y)             ((x) <= (y) ? (x) : (y))
91
        #define __max(x, y)             ((x) >= (y) ? (x) : (y))
92
#endif // __min
93
 
94
//-------------------------------------------------------------------------------
95
//      Defines -- Adobe image modes.
96
//-------------------------------------------------------------------------------
97
#define ImageModeBitmap                         0
98
#define ImageModeGrayScale                      1
99
#define ImageModeIndexedColor           2
100
#define ImageModeRGBColor                       3
101
#define ImageModeCMYKColor                      4
102
#define ImageModeHSLColor                       5
103
#define ImageModeHSBColor                       6
104
#define ImageModeMultichannel           7
105
#define ImageModeDuotone                        8
106
#define ImageModeLabColor                       9
107
#define ImageModeGray16                         10
108
#define ImageModeRGB48                          11
109
#define ImageModeLab48                          12
110
#define ImageModeCMYK64                         13
111
#define ImageModeDeepMultichannel       14
112
#define ImageModeDuotone16                      15
113
// pgf extension
114
#define ImageModeRGBA                           17
115
#define ImageModeGray31                         18
116
#define ImageModeRGB12                          19
117
#define ImageModeRGB16                          20
118
#define ImageModeUnknown                        255
119
 
120
 
121
//-------------------------------------------------------------------------------
122
// WINDOWS 32
123
//-------------------------------------------------------------------------------
124
#if defined(WIN32) || defined(WINCE)
125
#define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
126
 
127
//-------------------------------------------------------------------------------
128
// MFC
129
//-------------------------------------------------------------------------------
130
#ifdef _MFC_VER
131
 
132
#include <afxwin.h>         // MFC core and standard components
133
#include <afxext.h>         // MFC extensions
134
#include <afxdtctl.h>           // MFC support for Internet Explorer 4 Common Controls
135
#ifndef _AFX_NO_AFXCMN_SUPPORT
136
#include <afxcmn.h>                     // MFC support for Windows Common Controls
137
#endif // _AFX_NO_AFXCMN_SUPPORT
138
#include <afx.h>
139
 
140
#else
141
 
142
#include <windows.h>
143
#include <ole2.h>
144
 
16771 fschmid 145
#endif // _MFC_VER
15796 fschmid 146
//-------------------------------------------------------------------------------
147
 
16771 fschmid 148
#define DllExport   __declspec( dllexport )
15796 fschmid 149
 
150
//-------------------------------------------------------------------------------
151
// unsigned number type definitions
152
//-------------------------------------------------------------------------------
153
typedef unsigned char           UINT8;
154
typedef unsigned char           BYTE;
155
typedef unsigned short          UINT16;
156
typedef unsigned short      WORD;
157
typedef unsigned int            UINT32;
158
typedef unsigned long       DWORD;
159
typedef unsigned long       ULONG;
16771 fschmid 160
typedef unsigned __int64        UINT64;
161
typedef unsigned __int64        ULONGLONG;
15796 fschmid 162
 
163
//-------------------------------------------------------------------------------
164
// signed number type definitions
165
//-------------------------------------------------------------------------------
166
typedef signed char                     INT8;
167
typedef signed short            INT16;
168
typedef signed int                      INT32;
169
typedef signed int                      BOOL;
170
typedef signed long                     LONG;
171
typedef signed __int64          INT64;
172
typedef signed __int64          LONGLONG;
173
 
174
//-------------------------------------------------------------------------------
175
// other types
176
//-------------------------------------------------------------------------------
177
typedef int OSError;
178
typedef bool (__cdecl *CallbackPtr)(double percent, bool escapeAllowed, void *data);
179
 
180
//-------------------------------------------------------------------------------
181
// struct type definitions
182
//-------------------------------------------------------------------------------
183
 
184
//-------------------------------------------------------------------------------
185
// DEBUG macros
186
//-------------------------------------------------------------------------------
187
#ifndef ASSERT
188
        #ifdef _DEBUG
189
                #define ASSERT(x)       assert(x)
190
        #else
16771 fschmid 191
                #if defined(__GNUC__)
192
                        #define ASSERT(ignore)((void) 0)
193
                #elif _MSC_VER >= 1300
15796 fschmid 194
                        #define ASSERT          __noop
195
                #else
196
                        #define ASSERT ((void)0)
197
                #endif
198
        #endif //_DEBUG
199
#endif //ASSERT
200
 
201
//-------------------------------------------------------------------------------
202
// Exception handling macros
203
//-------------------------------------------------------------------------------
204
#ifdef NEXCEPTIONS
205
        extern OSError _PGF_Error_;
206
        extern OSError GetLastPGFError();
207
 
208
        #define ReturnWithError(err) { _PGF_Error_ = err; return; }
209
        #define ReturnWithError2(err, ret) { _PGF_Error_ = err; return ret; }
210
#else
211
        #define ReturnWithError(err) throw IOException(err)
212
        #define ReturnWithError2(err, ret) throw IOException(err)
213
#endif //NEXCEPTIONS
214
 
215
#if _MSC_VER >= 1300
216
        //#define THROW_ throw(...)
217
        #pragma warning( disable : 4290 )
218
        #define THROW_ throw(IOException)
219
#else
220
        #define THROW_
221
#endif
222
 
223
//-------------------------------------------------------------------------------
224
// constants
225
//-------------------------------------------------------------------------------
226
#define FSFromStart             FILE_BEGIN                              // 0
227
#define FSFromCurrent   FILE_CURRENT                    // 1
228
#define FSFromEnd               FILE_END                                // 2
229
 
230
#define INVALID_SET_FILE_POINTER ((DWORD)-1)
231
 
232
//-------------------------------------------------------------------------------
233
// IO Error constants
234
//-------------------------------------------------------------------------------
235
#define NoError                         ERROR_SUCCESS           // no error
236
#define AppError                        0x20000000                      // all application error messages must be larger than this value
237
#define InsufficientMemory      0x20000001                      // memory allocation wasn't successfull
238
#define EndOfMemory                     0x20000002                      // like end-of-file (EOF) for memory stream
239
#define EscapePressed           0x20000003                      // user break by ESC
16771 fschmid 240
#define WrongVersion            0x20000004                      // wrong pgf version
15796 fschmid 241
#define FormatCannotRead        0x20000005                      // wrong data file format
242
#define ImageTooSmall           0x20000006                      // image is too small
243
#define ZlibError                       0x20000007                      // error in zlib functions
244
#define ColorTableError         0x20000008                      // errors related to color table size
245
#define PNGError                        0x20000009                      // errors in png functions
16771 fschmid 246
#define MissingData                     0x2000000A                      // expected data cannot be read
15796 fschmid 247
 
248
//-------------------------------------------------------------------------------
249
// methods
250
//-------------------------------------------------------------------------------
251
inline OSError FileRead(HANDLE hFile, int *count, void *buffPtr) {
252
        if (ReadFile(hFile, buffPtr, *count, (ULONG *)count, NULL)) {
253
                return NoError;
254
        } else {
255
                return GetLastError();
256
        }
257
}
258
 
259
inline OSError FileWrite(HANDLE hFile, int *count, void *buffPtr) {
260
        if (WriteFile(hFile, buffPtr, *count, (ULONG *)count, NULL)) {
261
                return NoError;
262
        } else {
263
                return GetLastError();
264
        }
265
}
266
 
267
inline OSError GetFPos(HANDLE hFile, UINT64 *pos) {
268
#ifdef WINCE
269
        LARGE_INTEGER li;
270
        li.QuadPart = 0;
271
 
272
        li.LowPart = SetFilePointer (hFile, li.LowPart, &li.HighPart, FILE_CURRENT);
273
        if (li.LowPart == INVALID_SET_FILE_POINTER) {
274
                OSError err = GetLastError();
275
                if (err != NoError) {
276
                        return err;
277
                }
278
        }
279
        *pos = li.QuadPart;
280
        return NoError;
281
#else
282
        LARGE_INTEGER li;
283
        li.QuadPart = 0;
284
        if (SetFilePointerEx(hFile, li, (PLARGE_INTEGER)pos, FILE_CURRENT)) {
285
                return NoError;
286
        } else {
287
                return GetLastError();
288
        }
289
#endif
290
}
291
 
292
inline OSError SetFPos(HANDLE hFile, int posMode, INT64 posOff) {
293
#ifdef WINCE
294
        LARGE_INTEGER li;
295
        li.QuadPart = posOff;
296
 
297
        if (SetFilePointer (hFile, li.LowPart, &li.HighPart, posMode) == INVALID_SET_FILE_POINTER) {
298
                OSError err = GetLastError();
299
                if (err != NoError) {
300
                        return err;
301
                }
302
        }
303
        return NoError;
304
#else
305
        LARGE_INTEGER li;
306
        li.QuadPart = posOff;
307
        if (SetFilePointerEx(hFile, li, NULL, posMode)) {
308
                return NoError;
309
        } else {
310
                return GetLastError();
311
        }
312
#endif
313
}
314
#endif //WIN32
315
 
316
 
317
//-------------------------------------------------------------------------------
318
// Apple OSX
319
//-------------------------------------------------------------------------------
320
#ifdef __APPLE__
16771 fschmid 321
#define __POSIX__
15796 fschmid 322
#endif // __APPLE__
323
 
324
 
325
//-------------------------------------------------------------------------------
16771 fschmid 326
// LINUX
15796 fschmid 327
//-------------------------------------------------------------------------------
328
#if defined(__linux__) || defined(__GLIBC__)
329
#define __POSIX__
16771 fschmid 330
#endif // __linux__ or __GLIBC__
15796 fschmid 331
 
332
 
333
//-------------------------------------------------------------------------------
16771 fschmid 334
// SOLARIS
335
//-------------------------------------------------------------------------------
336
#ifdef __sun
337
#define __POSIX__
338
#endif // __sun
339
 
340
 
341
//-------------------------------------------------------------------------------
16911 jghali 342
// *BSD
15796 fschmid 343
//-------------------------------------------------------------------------------
16911 jghali 344
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
16771 fschmid 345
#ifndef __POSIX__
346
#define __POSIX__
347
#endif
15796 fschmid 348
 
16771 fschmid 349
#ifndef off64_t
350
#define off64_t off_t
351
#endif
15796 fschmid 352
 
16771 fschmid 353
#ifndef lseek64
354
#define lseek64 lseek
355
#endif
15796 fschmid 356
 
16911 jghali 357
#endif // __NetBSD__ or __OpenBSD__ or __FreeBSD__
15796 fschmid 358
 
359
 
360
//-------------------------------------------------------------------------------
361
// POSIX *NIXes
362
//-------------------------------------------------------------------------------
363
 
364
#ifdef __POSIX__
365
#include <unistd.h>
366
#include <errno.h>
367
#include <stdint.h>             // for int64_t and uint64_t
368
#include <string.h>             // memcpy()
369
 
370
//-------------------------------------------------------------------------------
371
// unsigned number type definitions
372
//-------------------------------------------------------------------------------
373
 
374
typedef unsigned char           UINT8;
375
typedef unsigned char           BYTE;
376
typedef unsigned short          UINT16;
377
typedef unsigned short          WORD;
378
typedef unsigned int            UINT32;
379
typedef unsigned int            DWORD;
380
typedef unsigned long           ULONG;
381
typedef unsigned long long  __Uint64;
382
typedef __Uint64                        UINT64;
383
typedef __Uint64                        ULONGLONG;
384
 
385
//-------------------------------------------------------------------------------
386
// signed number type definitions
387
//-------------------------------------------------------------------------------
388
typedef signed char                     INT8;
389
typedef signed short            INT16;
390
typedef signed int                      INT32;
391
typedef signed int                      BOOL;
392
typedef signed long                     LONG;
393
typedef int64_t                         INT64;
394
typedef int64_t                         LONGLONG;
395
 
396
//-------------------------------------------------------------------------------
397
// other types
398
//-------------------------------------------------------------------------------
399
typedef int                                     OSError;
16771 fschmid 400
typedef int                                     HANDLE;
15796 fschmid 401
typedef unsigned long           ULONG_PTR;
402
typedef void*                           PVOID;
403
typedef char*                           LPTSTR;
404
typedef bool (*CallbackPtr)(double percent, bool escapeAllowed, void *data);
405
 
406
//-------------------------------------------------------------------------------
407
// struct type definitions
408
//-------------------------------------------------------------------------------
409
typedef struct tagRGBTRIPLE {
410
        BYTE rgbtBlue;
411
        BYTE rgbtGreen;
412
        BYTE rgbtRed;
413
} RGBTRIPLE;
414
 
415
typedef struct tagRGBQUAD {
416
        BYTE rgbBlue;
417
        BYTE rgbGreen;
418
        BYTE rgbRed;
419
        BYTE rgbReserved;
420
} RGBQUAD;
421
 
422
typedef union _LARGE_INTEGER {
423
  struct {
424
    DWORD LowPart;
425
    LONG HighPart;
426
  };
427
  struct {
428
    DWORD LowPart;
429
    LONG HighPart;
430
  } u;
431
  LONGLONG QuadPart;
432
} LARGE_INTEGER, *PLARGE_INTEGER;
433
#endif // __POSIX__
434
 
435
 
436
#if defined(__POSIX__) || defined(WINCE)
437
// CMYK macros
438
#define GetKValue(cmyk)      ((BYTE)(cmyk))
439
#define GetYValue(cmyk)      ((BYTE)((cmyk)>> 8))
440
#define GetMValue(cmyk)      ((BYTE)((cmyk)>>16))
441
#define GetCValue(cmyk)      ((BYTE)((cmyk)>>24))
442
#define CMYK(c,m,y,k)            ((COLORREF)((((BYTE)(k)|((WORD)((BYTE)(y))<<8))|(((DWORD)(BYTE)(m))<<16))|(((DWORD)(BYTE)(c))<<24)))
443
 
444
//-------------------------------------------------------------------------------
445
// methods
446
//-------------------------------------------------------------------------------
16771 fschmid 447
/* The MulDiv function multiplies two 32-bit values and then divides the 64-bit
448
 * result by a third 32-bit value. The return value is rounded up or down to
15796 fschmid 449
 * the nearest integer.
450
 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/muldiv.asp
451
 * */
452
__inline int MulDiv(int nNumber, int nNumerator, int nDenominator) {
453
        INT64 multRes = nNumber*nNumerator;
454
        INT32 divRes = INT32(multRes/nDenominator);
455
        return divRes;
456
}
457
#endif // __POSIX__ or WINCE
458
 
459
 
460
#ifdef __POSIX__
461
//-------------------------------------------------------------------------------
462
// DEBUG macros
463
//-------------------------------------------------------------------------------
464
#ifndef ASSERT
465
        #ifdef _DEBUG
466
                #define ASSERT(x)       assert(x)
467
        #else
16771 fschmid 468
                #define ASSERT(x)
15796 fschmid 469
        #endif //_DEBUG
470
#endif //ASSERT
471
 
472
//-------------------------------------------------------------------------------
473
// Exception handling macros
474
//-------------------------------------------------------------------------------
475
#ifdef NEXCEPTIONS
476
        extern OSError _PGF_Error_;
477
        extern OSError GetLastPGFError();
478
 
479
        #define ReturnWithError(err) { _PGF_Error_ = err; return; }
480
        #define ReturnWithError2(err, ret) { _PGF_Error_ = err; return ret; }
481
#else
482
        #define ReturnWithError(err) throw IOException(err)
483
        #define ReturnWithError2(err, ret) throw IOException(err)
484
#endif //NEXCEPTIONS
485
 
486
#define THROW_ throw(IOException)
487
#define CONST const
488
 
489
//-------------------------------------------------------------------------------
490
// constants
491
//-------------------------------------------------------------------------------
492
#define FSFromStart                     SEEK_SET
493
#define FSFromCurrent           SEEK_CUR
494
#define FSFromEnd                       SEEK_END
495
 
496
//-------------------------------------------------------------------------------
497
// IO Error constants
498
//-------------------------------------------------------------------------------
499
#define NoError                                 0x0000
500
#define AppError                                0x2000                  // all application error messages must be larger than this value
501
#define InsufficientMemory              0x2001                  // memory allocation wasn't successfull
502
#define EndOfMemory                             0x2002                  // like end-of-file (EOF) for memory stream
503
#define EscapePressed                   0x2003                  // user break by ESC
16771 fschmid 504
#define WrongVersion                    0x2004                  // wrong pgf version
15796 fschmid 505
#define FormatCannotRead                0x2005                  // wrong data file format
506
#define ImageTooSmall                   0x2006                  // image is too small
507
#define ZlibError                               0x2007                  // error in zlib functions
508
#define ColorTableError                 0x2008                  // errors related to color table size
509
#define PNGError                                0x2009                  // errors in png functions
16771 fschmid 510
#define MissingData                             0x200A                  // expected data cannot be read
15796 fschmid 511
 
512
//-------------------------------------------------------------------------------
513
// methods
514
//-------------------------------------------------------------------------------
515
__inline OSError FileRead(HANDLE hFile, int *count, void *buffPtr) {
516
        *count = (int)read(hFile, buffPtr, *count);
517
        if (*count != -1) {
518
                return NoError;
519
        } else {
520
                return errno;
521
        }
522
}
523
 
524
__inline OSError FileWrite(HANDLE hFile, int *count, void *buffPtr) {
525
        *count = (int)write(hFile, buffPtr, (size_t)*count);
526
        if (*count != -1) {
527
                return NoError;
528
        } else {
529
                return errno;
530
        }
531
}
532
 
533
__inline OSError GetFPos(HANDLE hFile, UINT64 *pos) {
534
        #ifdef __APPLE__
535
                off_t ret;
536
                if ((ret = lseek(hFile, 0, SEEK_CUR)) == -1) {
537
                        return errno;
538
                } else {
539
                        *pos = (UINT64)ret;
540
                        return NoError;
541
                }
542
        #else
543
                off64_t ret;
544
                if ((ret = lseek64(hFile, 0, SEEK_CUR)) == -1) {
545
                        return errno;
546
                } else {
547
                        *pos = (UINT64)ret;
548
                        return NoError;
549
                }
550
        #endif
551
}
552
 
553
__inline OSError SetFPos(HANDLE hFile, int posMode, INT64 posOff) {
554
        #ifdef __APPLE__
555
                if ((lseek(hFile, (off_t)posOff, posMode)) == -1) {
556
                        return errno;
557
                } else {
558
                        return NoError;
559
                }
560
        #else
561
                if ((lseek64(hFile, (off64_t)posOff, posMode)) == -1) {
562
                        return errno;
563
                } else {
564
                        return NoError;
565
                }
566
        #endif
567
}
568
 
569
#endif /* __POSIX__ */
570
//-------------------------------------------------------------------------------
571
 
572
 
573
//-------------------------------------------------------------------------------
574
//      Big Endian
575
//-------------------------------------------------------------------------------
16771 fschmid 576
#ifdef PGF_USE_BIG_ENDIAN
15796 fschmid 577
 
578
#ifndef _lrotl
579
        #define _lrotl(x,n)     (((x) << ((UINT32)(n))) | ((x) >> (32 - (UINT32)(n))))
580
#endif
581
 
582
__inline UINT16 ByteSwap(UINT16 wX) {
583
        return ((wX & 0xFF00) >> 8) | ((wX & 0x00FF) << 8);
584
}
585
 
16771 fschmid 586
__inline UINT32 ByteSwap(UINT32 dwX) {
587
#ifdef _X86_
588
        _asm mov eax, dwX
15796 fschmid 589
        _asm bswap eax
16771 fschmid 590
        _asm mov dwX, eax
591
        return dwX;
592
#else
593
        return _lrotl(((dwX & 0xFF00FF00) >> 8) | ((dwX & 0x00FF00FF) << 8), 16);
594
#endif
15796 fschmid 595
}
596
 
597
#if defined WIN32
16771 fschmid 598
__inline UINT64 ByteSwap(UINT64 ui64) {
15796 fschmid 599
        return _byteswap_uint64(ui64);
600
}
601
#endif
602
 
603
#define __VAL(x) ByteSwap(x)
604
 
16771 fschmid 605
#else //PGF_USE_BIG_ENDIAN
15796 fschmid 606
 
607
        #define __VAL(x) (x)
608
 
16771 fschmid 609
#endif //PGF_USE_BIG_ENDIAN
15796 fschmid 610
 
16771 fschmid 611
// NOTE: Use LIBPGF_DISABLE_OPENMP to disable OpenMP support in whole libpgf
612
#ifndef LIBPGF_DISABLE_OPENMP
613
 
614
// OpenMP rules (inspired from libraw project)
615
#if defined (_OPENMP)
616
 
617
#if defined(WIN32)
618
# if defined (_MSC_VER) && (_MSC_VER >= 1500)
619
// VS2008 SP1 and VS2010+ : OpenMP works OK
620
#   define LIBPGF_USE_OPENMP
621
#elif defined (__INTEL_COMPILER) && (__INTEL_COMPILER >=910)
622
//  Have not tested on 9.x and 10.x, but Intel documentation claims OpenMP 2.5 support in 9.1
623
#   define LIBPGF_USE_OPENMP
624
#else
625
#  undef LIBPGF_USE_OPENMP
626
#endif
627
// Not Win32
628
# elif (defined(__APPLE__) || defined(__MACOSX__)) && defined(_REENTRANT)
629
#   undef LIBPGF_USE_OPENMP
630
# else
631
#   define LIBPGF_USE_OPENMP
632
# endif
633
 
634
#endif // defined (_OPENMP)
635
 
636
#endif // ifndef LIBPGF_DISABLE_OPENMP
637
 
638
#ifdef LIBPGF_USE_OPENMP
639
#include <omp.h>
640
#endif
641
 
642
 
15796 fschmid 643
#endif //PGF_PGFPLATFORM_H