~ubuntu-branches/ubuntu/quantal/aqsis/quantal

« back to all changes in this revision

Viewing changes to tools/displays/sdcBMP/d_sdcBMP.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-08-06 04:53:26 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806045326-z6xeaaao62idxcc6
Tags: 1.6.0-0ubuntu1
* New upstream release
* debian/control:
  - changed name of lib package to libaqsis1 instead of aqsis-libsc2a
  - changed name of dev package to libaqsis-dev instead of aqsis-libs-dev
  - Added aqsis-data package
  - Revised summary text according to that specified by the RISpec (Pixar)
* Moved examples installation from aqsis.install to aqsis-data.install
* debian/rules: 
  - added content to binary-indep target
* debian/rules: added explicit name of mime file to force dh_installmime
  to generate postinst and prerm scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************/
 
2
/* COPYRIGHT                                                                  */
 
3
/*                                                                            */
 
4
/* Copyright 2000 by Schroff Development Corporation, Shawnee-Mission,        */
 
5
/* Kansas, United States of America. All rights reserved.                     */
 
6
/*                                                                            */
 
7
/******************************************************************************/
 
8
/*                                                                            */
 
9
/* This Display Driver is distributed as "freeware". There are no             */
 
10
/* restrictions on its' usage.                                                */
 
11
/*                                                                            */
 
12
/******************************************************************************/
 
13
/*                                                                            */
 
14
/* DISCLAIMER OF ALL WARRANTIES AND LIABILITY                                 */
 
15
/*                                                                            */
 
16
/* Schroff Development Corporation makes no warranties, either expressed      */
 
17
/* or implied, with respect to the programs contained within this file, or    */
 
18
/* with respect to software used in conjunction with these programs. The      */
 
19
/* programs are distributed 'as is'.  The entire risk as to its quality and   */
 
20
/* performance is assumed by the purchaser.  Schroff  Development Corporation */
 
21
/* does not guarantee, warrant or make any representation regarding the       */
 
22
/* use of, or the results of the use of the programs in terms of correctness, */
 
23
/* accuracy, reliability, or performance. Schroff Development Corporation     */
 
24
/* assumes no liability for any direct, indirect, or consquential, special    */
 
25
/* or exemplary damages, regardless of its having been advised of the         */
 
26
/* possibility of such damage.                                                */
 
27
/*                                                                            */
 
28
/******************************************************************************/
 
29
 
 
30
 
 
31
//
 
32
// This is a Display Driver that was written to comply with the PhotoRealistic
 
33
// RenderMan Display Driver Implementation Guide (on the web at:
 
34
// www.pixar.com/products/rendermandocs/toolkit/Toolkit/dspy.html).
 
35
//
 
36
// This driver places image data into a Windows .BMP file. It writes this data
 
37
// one scanline at a time and tries to minimize memory consumption.
 
38
//
 
39
 
 
40
#include <string.h>
 
41
#include <stdio.h>
 
42
#include <stdlib.h>
 
43
 
 
44
 
 
45
#include <aqsis/ri/ndspy.h>  // NOTE: Use Pixar's ndspy.h if you've got it.
 
46
 
 
47
 
 
48
typedef struct tagBITMAPFILEHEADER { // bmfh 
 
49
    short   bfType; 
 
50
    int     bfSize; 
 
51
    short   bfReserved1; 
 
52
    short   bfReserved2; 
 
53
    int     bfOffBits; 
 
54
} BITMAPFILEHEADER; 
 
55
 
 
56
/* instead of sizeof(BITMAPFILEHEADER) since this must be 14 */
 
57
#define BITMAPFILEHEADER_SIZEOF 14 
 
58
 
 
59
typedef struct tagRGBQUAD { // rgbq 
 
60
    unsigned char rgbBlue; 
 
61
    unsigned char rgbGreen; 
 
62
    unsigned char rgbRed; 
 
63
    unsigned char rgbReserved; 
 
64
} RGBQUAD; 
 
65
 
 
66
typedef struct tagBITMAPINFOHEADER{ // bmih 
 
67
    int     biSize; 
 
68
    long    biWidth; 
 
69
    long    biHeight; 
 
70
    short   biPlanes; 
 
71
    short   biBitCount;
 
72
    int     biCompression; 
 
73
    int     biSizeImage; 
 
74
    long    biXPelsPerMeter; 
 
75
    long    biYPelsPerMeter; 
 
76
    int     biClrUsed; 
 
77
    int     biClrImportant; 
 
78
} BITMAPINFOHEADER; 
 
79
 
 
80
typedef struct tagBITMAPINFO {
 
81
    BITMAPINFOHEADER    bmiHeader;
 
82
    RGBQUAD             bmiColors[1];
 
83
} BITMAPINFO;
 
84
 
 
85
#define BI_RGB 0
 
86
 
 
87
// -----------------------------------------------------------------------------
 
88
// Local structures
 
89
// -----------------------------------------------------------------------------
 
90
 
 
91
typedef struct
 
92
{
 
93
        // Bitmap data
 
94
 
 
95
        FILE              *fp;
 
96
        BITMAPFILEHEADER  bfh;
 
97
        char              *FileName;
 
98
        BITMAPINFO        bmi;
 
99
        char              *ImageData;
 
100
        int               Channels;
 
101
        int               RowSize;
 
102
        int               PixelBytes;
 
103
        long              TotalPixels;
 
104
}
 
105
AppData;
 
106
 
 
107
 
 
108
// -----------------------------------------------------------------------------
 
109
// Constants
 
110
// -----------------------------------------------------------------------------
 
111
 
 
112
static const int     DEFAULT_IMAGEWIDTH         = 512;   // Tiff display driver defaults are good enough for me.
 
113
static const int     DEFAULT_IMAGEHEIGHT        = 384;
 
114
static const float   DEFAULT_PIXELASPECTRATIO   = 1.0f;
 
115
 
 
116
 
 
117
//
 
118
// Set SHOW_CALLSTACK to 1 to see trace messages from the
 
119
// driver (which will be written to stderr).
 
120
//
 
121
 
 
122
#define SHOW_CALLSTACK 0
 
123
 
 
124
// -----------------------------------------------------------------------------
 
125
// Function Prototypes
 
126
// -----------------------------------------------------------------------------
 
127
 
 
128
static int  DWORDALIGN(int bits);
 
129
static bool bitmapfileheader(BITMAPFILEHEADER *bfh, FILE *fp);
 
130
static unsigned short swap2( unsigned short s );
 
131
static unsigned long  swap4( unsigned long l );
 
132
static bool lowendian();
 
133
 
 
134
// -----------------------------------------------------------------------------
 
135
// Global Data
 
136
// -----------------------------------------------------------------------------
 
137
 
 
138
 
 
139
//******************************************************************************
 
140
// DspyImageOpen
 
141
//
 
142
// Initializes the display driver, allocates necessary resources, checks image
 
143
// size, specifies format in which incoming data will arrive.
 
144
//******************************************************************************
 
145
 
 
146
extern "C" PtDspyError DspyImageOpen(PtDspyImageHandle    *image,
 
147
                                     const char           *drivername,
 
148
                                     const char           *filename,
 
149
                                     int                  width,
 
150
                                     int                  height,
 
151
                                     int                  paramCount,
 
152
                                     const UserParameter  *parameters,
 
153
                                     int                  formatCount,
 
154
                                     PtDspyDevFormat      *format,
 
155
                                     PtFlagStuff          *flagstuff)
 
156
{
 
157
        PtDspyError rval = PkDspyErrorNone;
 
158
 
 
159
   static AppData g_Data;
 
160
   AppData *pData;
 
161
 
 
162
#if SHOW_CALLSTACK
 
163
 
 
164
        fprintf(stderr, "sdcBMP_DspyImageOpen called.\n");
 
165
#endif
 
166
 
 
167
   pData = (AppData *) calloc(1, sizeof(g_Data));
 
168
   *image = pData;
 
169
 
 
170
   // Initialize our global resources
 
171
 
 
172
        memset(&g_Data, sizeof(AppData), 0);
 
173
 
 
174
        flagstuff->flags = PkDspyFlagsWantsScanLineOrder;
 
175
 
 
176
        if ( width <= 0 )
 
177
                width = DEFAULT_IMAGEWIDTH;
 
178
 
 
179
        if ( height <= 0 )
 
180
                height = DEFAULT_IMAGEHEIGHT;
 
181
 
 
182
        
 
183
        g_Data.FileName = strdup(filename);
 
184
        g_Data.Channels = formatCount;
 
185
 
 
186
        g_Data.PixelBytes = 3; // One byte for red, one for green, and one for blue.
 
187
 
 
188
        g_Data.bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
 
189
        g_Data.bmi.bmiHeader.biWidth       = width;
 
190
        g_Data.bmi.bmiHeader.biHeight      = height;
 
191
        g_Data.bmi.bmiHeader.biPlanes      = 1;
 
192
        g_Data.bmi.bmiHeader.biBitCount    = 24;
 
193
        g_Data.bmi.bmiHeader.biCompression = BI_RGB;
 
194
 
 
195
        g_Data.RowSize                     = DWORDALIGN(width * g_Data.bmi.bmiHeader.biBitCount);
 
196
        g_Data.bmi.bmiHeader.biSizeImage   = g_Data.RowSize * height;
 
197
 
 
198
        g_Data.TotalPixels     = width * height;
 
199
 
 
200
 
 
201
        // Prepare the file header
 
202
 
 
203
        g_Data.bfh.bfType     = 0x4D42;    // ASCII "BM"
 
204
        g_Data.bfh.bfSize     = BITMAPFILEHEADER_SIZEOF +
 
205
                                sizeof(BITMAPINFOHEADER) +
 
206
                                g_Data.bmi.bmiHeader.biSizeImage;
 
207
        g_Data.bfh.bfOffBits  = BITMAPFILEHEADER_SIZEOF + sizeof(BITMAPINFOHEADER);
 
208
 
 
209
 
 
210
        // Create a buffer for the image data (calloc clears all pixels to black)
 
211
 
 
212
        g_Data.ImageData = (char *)calloc(1, g_Data.RowSize);
 
213
 
 
214
        if ( ! g_Data.ImageData )
 
215
        {
 
216
                fprintf(stderr, "sdcBMP_DspyImageOpen_sdcBMP: Insufficient Memory\n");
 
217
                rval = PkDspyErrorNoResource;
 
218
        }
 
219
 
 
220
 
 
221
        // Open the file and get ready to write.
 
222
 
 
223
        g_Data.fp = fopen(g_Data.FileName, "wb");
 
224
 
 
225
        if ( ! g_Data.fp )
 
226
        {
 
227
                fprintf(stderr, "sdcBMP_DspyImageOpen: Unable to open [%s]\n", g_Data.FileName);
 
228
                rval = PkDspyErrorNoResource;
 
229
                goto Exit;
 
230
        }
 
231
 
 
232
        // Write out the BITMAPFILEHEADER
 
233
        if (lowendian())
 
234
        {
 
235
                g_Data.bfh.bfType = swap2(g_Data.bfh.bfType);
 
236
                g_Data.bfh.bfSize = swap4(g_Data.bfh.bfSize);
 
237
                g_Data.bfh.bfOffBits = swap4(g_Data.bfh.bfOffBits);
 
238
        }
 
239
        if ( ! bitmapfileheader(&g_Data.bfh, g_Data.fp) )
 
240
      
 
241
        {
 
242
                fprintf(stderr, "sdcBMP_SaveBitmap: Error writing to [%s]\n", g_Data.FileName);
 
243
                goto Exit;
 
244
        }
 
245
 
 
246
        if (lowendian())
 
247
        {
 
248
                g_Data.bfh.bfType = swap2(g_Data.bfh.bfType);
 
249
                g_Data.bfh.bfSize = swap4(g_Data.bfh.bfSize);
 
250
                g_Data.bfh.bfOffBits = swap4(g_Data.bfh.bfOffBits);
 
251
        }
 
252
 
 
253
        if (lowendian())
 
254
        {
 
255
                g_Data.bmi.bmiHeader.biSize = swap4(g_Data.bmi.bmiHeader.biSize);
 
256
                   g_Data.bmi.bmiHeader.biWidth= swap4(g_Data.bmi.bmiHeader.biWidth);
 
257
                g_Data.bmi.bmiHeader.biHeight= swap4(g_Data.bmi.bmiHeader.biHeight);
 
258
                g_Data.bmi.bmiHeader.biPlanes = swap2(g_Data.bmi.bmiHeader.biPlanes);
 
259
                g_Data.bmi.bmiHeader.biBitCount = swap2(g_Data.bmi.bmiHeader.biBitCount);
 
260
                g_Data.bmi.bmiHeader.biCompression= swap4(g_Data.bmi.bmiHeader.biCompression); 
 
261
                g_Data.bmi.bmiHeader.biSizeImage= swap4(g_Data.bmi.bmiHeader.biSizeImage);
 
262
                g_Data.bmi.bmiHeader.biXPelsPerMeter= swap4(g_Data.bmi.bmiHeader.biXPelsPerMeter); 
 
263
                g_Data.bmi.bmiHeader.biYPelsPerMeter= swap4(g_Data.bmi.bmiHeader.biYPelsPerMeter); 
 
264
                g_Data.bmi.bmiHeader.biClrUsed= swap4(g_Data.bmi.bmiHeader.biClrUsed);
 
265
                g_Data.bmi.bmiHeader.biClrImportant= swap4(g_Data.bmi.bmiHeader.biClrImportant);
 
266
        }
 
267
        // Write out the BITMAPINFOHEADER
 
268
 
 
269
        if ( ! fwrite(&g_Data.bmi.bmiHeader,
 
270
                      sizeof(BITMAPINFOHEADER),
 
271
                      1,
 
272
                      g_Data.fp) )
 
273
        {
 
274
                fprintf(stderr, "sdcBMP_SaveBitmap: Error writing to [%s]\n", g_Data.FileName);
 
275
                rval = PkDspyErrorNoResource;
 
276
                goto Exit;
 
277
        }
 
278
 
 
279
        if (lowendian())
 
280
        {
 
281
                g_Data.bmi.bmiHeader.biSize = swap4(g_Data.bmi.bmiHeader.biSize);
 
282
                   g_Data.bmi.bmiHeader.biWidth= swap4(g_Data.bmi.bmiHeader.biWidth);
 
283
                g_Data.bmi.bmiHeader.biHeight= swap4(g_Data.bmi.bmiHeader.biHeight);
 
284
                g_Data.bmi.bmiHeader.biPlanes = swap2(g_Data.bmi.bmiHeader.biPlanes);
 
285
                g_Data.bmi.bmiHeader.biBitCount = swap2(g_Data.bmi.bmiHeader.biBitCount);
 
286
                g_Data.bmi.bmiHeader.biCompression= swap4(g_Data.bmi.bmiHeader.biCompression); 
 
287
                g_Data.bmi.bmiHeader.biSizeImage= swap4(g_Data.bmi.bmiHeader.biSizeImage);
 
288
                g_Data.bmi.bmiHeader.biXPelsPerMeter= swap4(g_Data.bmi.bmiHeader.biXPelsPerMeter); 
 
289
                g_Data.bmi.bmiHeader.biYPelsPerMeter= swap4(g_Data.bmi.bmiHeader.biYPelsPerMeter); 
 
290
                g_Data.bmi.bmiHeader.biClrUsed= swap4(g_Data.bmi.bmiHeader.biClrUsed);
 
291
                g_Data.bmi.bmiHeader.biClrImportant= swap4(g_Data.bmi.bmiHeader.biClrImportant);
 
292
        }
 
293
 
 
294
   
 
295
   memcpy((void*) pData, (void *) &g_Data, sizeof(AppData));
 
296
   
 
297
Exit:
 
298
 
 
299
        if ( rval != PkDspyErrorNone )
 
300
        {
 
301
                if ( g_Data.fp )
 
302
                        fclose(g_Data.fp);
 
303
                g_Data.fp = NULL;
 
304
        }
 
305
 
 
306
        return rval;
 
307
}
 
308
 
 
309
 
 
310
 
 
311
//******************************************************************************
 
312
// DspyImageQuery
 
313
//
 
314
// Query the display driver for image size (if not specified in the open call)
 
315
// and aspect ratio.
 
316
//******************************************************************************
 
317
 
 
318
extern "C" PtDspyError DspyImageQuery(PtDspyImageHandle image,
 
319
                                      PtDspyQueryType   type,
 
320
                                      size_t            size,
 
321
                                      void              *data)
 
322
{
 
323
#if SHOW_CALLSTACK
 
324
        fprintf(stderr, "sdcBMP_DspyImageQuery called, type: %d.\n", type);
 
325
#endif
 
326
 
 
327
   AppData *pData = (AppData *)image;
 
328
        PtDspyError          ret = PkDspyErrorNone;
 
329
        PtDspyOverwriteInfo  owi;
 
330
        PtDspySizeInfo       si;
 
331
 
 
332
        if ( size > 0 && data )
 
333
        {
 
334
                switch ( type )
 
335
                {
 
336
                                case PkOverwriteQuery:
 
337
 
 
338
                                if ( size > sizeof(owi) )
 
339
                                        size = sizeof(owi);
 
340
 
 
341
                                owi.overwrite   = 1;
 
342
                                owi.interactive = 0;
 
343
 
 
344
                                memcpy(data, &owi, size);
 
345
                                break;
 
346
 
 
347
                                case PkSizeQuery:
 
348
 
 
349
                                if ( size > sizeof(si) )
 
350
                                        size = sizeof(si);
 
351
 
 
352
                                if ( image )
 
353
                                {
 
354
                                        si.width       = pData->bmi.bmiHeader.biWidth;
 
355
                                        si.height      = pData->bmi.bmiHeader.biHeight;
 
356
                                        si.aspectRatio = DEFAULT_PIXELASPECTRATIO;
 
357
                                }
 
358
                                else
 
359
                                {
 
360
                                        si.width       = DEFAULT_IMAGEWIDTH;
 
361
                                        si.height      = DEFAULT_IMAGEHEIGHT;
 
362
                                        si.aspectRatio = DEFAULT_PIXELASPECTRATIO;
 
363
                                }
 
364
 
 
365
                                memcpy(data, &si, size);
 
366
                                break;
 
367
 
 
368
                                default:
 
369
                                ret = PkDspyErrorUnsupported;
 
370
                                break;
 
371
                }
 
372
        }
 
373
        else
 
374
                ret = PkDspyErrorBadParams;
 
375
 
 
376
        return ret;
 
377
}
 
378
 
 
379
 
 
380
 
 
381
 
 
382
//******************************************************************************
 
383
// DspyImageData
 
384
//
 
385
// Send data to the display driver.
 
386
//******************************************************************************
 
387
extern "C" PtDspyError DspyImageData(PtDspyImageHandle image,
 
388
                          int xmin,
 
389
                          int xmax_plusone,
 
390
                          int ymin,
 
391
                          int ymax_plusone,
 
392
                          int entrysize,
 
393
                          const unsigned char *data)
 
394
{
 
395
        int  x;
 
396
        int  r, g, b;
 
397
     
 
398
        char *to;
 
399
        long spot;
 
400
 
 
401
        AppData *pData = (AppData *)image;
 
402
        r = g = b = 0;
 
403
 
 
404
#if SHOW_CALLSTACK
 
405
 
 
406
        fprintf(stderr, "sdcBMP_DspyImageData called.\n");
 
407
#endif
 
408
 
 
409
        if ( (ymin+1) != ymax_plusone )
 
410
        {
 
411
                fprintf(stderr, "sdcBMP_DspyImageData: Image data not in scanline format\n");
 
412
                return PkDspyErrorBadParams;
 
413
        }
 
414
 
 
415
        spot  = pData->bfh.bfOffBits +
 
416
                (pData->RowSize * (pData->bmi.bmiHeader.biHeight - ymin - 1));
 
417
        spot += pData->PixelBytes * xmin;
 
418
 
 
419
        if ( fseek(pData->fp, spot, SEEK_SET) != 0 )
 
420
        {
 
421
                fprintf(stderr, "sdcBMP_DspyImageData: Seek failure\n");
 
422
                return PkDspyErrorUndefined;
 
423
        }
 
424
 
 
425
 
 
426
        to = pData->ImageData;
 
427
 
 
428
        for (x = xmin; x < xmax_plusone; x++)
 
429
        {
 
430
                // Extract the r, g, and b values from data
 
431
 
 
432
                if ( ! data )
 
433
                        r = g = b = 0;
 
434
                else
 
435
                        if ( pData->Channels == 1 )
 
436
                                r = g = b = data[0];
 
437
                        else
 
438
                                if ( pData->Channels >= 3 )
 
439
                                {
 
440
                                        r = data[pData->Channels - 1];
 
441
                                        g = data[pData->Channels - 2];
 
442
                                        b = data[pData->Channels - 3];
 
443
                                }
 
444
 
 
445
 
 
446
                if ( data )
 
447
                        data += entrysize;
 
448
 
 
449
                // Place the r, g, and b values into our bitmap
 
450
 
 
451
                *to++ = r;
 
452
                *to++ = g;
 
453
                *to++ = b;
 
454
        }
 
455
 
 
456
        if ( ! fwrite(pData->ImageData, int(to - pData->ImageData), 1, pData->fp) )
 
457
        {
 
458
                fprintf(stderr, "sdcBMP_DspyImageData: Error writing file\n");
 
459
                return PkDspyErrorUndefined;
 
460
        }
 
461
 
 
462
        return PkDspyErrorNone;
 
463
}
 
464
 
 
465
 
 
466
 
 
467
//******************************************************************************
 
468
// DspyImageClose
 
469
//******************************************************************************
 
470
 
 
471
extern "C" PtDspyError DspyImageClose(PtDspyImageHandle image)
 
472
{
 
473
#if SHOW_CALLSTACK
 
474
        fprintf(stderr, "sdcBMP_DspyImageClose called.\n");
 
475
#endif
 
476
 
 
477
   AppData *pData = (AppData *)image;
 
478
 
 
479
        if ( pData->fp )
 
480
                fclose(pData->fp);
 
481
        pData->fp = NULL;
 
482
 
 
483
        if ( pData->FileName )
 
484
                free(pData->FileName);
 
485
        pData->FileName = NULL;
 
486
 
 
487
        if ( pData->ImageData )
 
488
                free(pData->ImageData);
 
489
        pData->ImageData = NULL;
 
490
 
 
491
   free(pData);
 
492
 
 
493
        return PkDspyErrorNone;
 
494
}
 
495
 
 
496
 
 
497
 
 
498
//******************************************************************************
 
499
// DWORDALIGN
 
500
//******************************************************************************
 
501
 
 
502
static int DWORDALIGN(int bits)
 
503
{
 
504
        return int(((bits + 31) >> 5) << 2);
 
505
}
 
506
 
 
507
//******************************************************************************
 
508
// ExitApplication
 
509
//******************************************************************************
 
510
#if 0
 
511
static bool ExitApplication()
 
512
{
 
513
#if SHOW_CALLSTACK
 
514
        fprintf(stderr, "sdcBMP_ExitApplication called.\n");
 
515
#endif
 
516
 
 
517
        return true;
 
518
}
 
519
#endif
 
520
 
 
521
//******************************************************************************
 
522
// Save an header for bitmap; must be save field by field since the sizeof is 14
 
523
//******************************************************************************
 
524
 
 
525
static bool bitmapfileheader(BITMAPFILEHEADER *bfh, FILE *fp)
 
526
{
 
527
bool retval = true;
 
528
 
 
529
 
 
530
    retval = retval && (fwrite(&bfh->bfType, 1, 2, fp) == 2);
 
531
    retval = retval && (fwrite(&bfh->bfSize, 1, 4, fp) == 4);
 
532
    retval = retval && (fwrite(&bfh->bfReserved1, 1, 2, fp)== 2);
 
533
    retval = retval && (fwrite(&bfh->bfReserved2, 1, 2, fp)== 2);
 
534
    retval = retval && (fwrite(&bfh->bfOffBits, 1, 4, fp)== 4);
 
535
   
 
536
 
 
537
return retval;
 
538
}
 
539
 
 
540
 
 
541
//******************************************************************************
 
542
// Swap a short if you are not on NT/Pentium you must swap
 
543
//******************************************************************************
 
544
static unsigned short swap2( unsigned short s )
 
545
{
 
546
        unsigned short n;
 
547
        unsigned char *in, *out;
 
548
 
 
549
        out = ( unsigned char* ) & n;
 
550
        in = ( unsigned char* ) & s;
 
551
 
 
552
        out[ 0 ] = in[ 1 ];
 
553
        out[ 1 ] = in[ 0 ];
 
554
        return n;
 
555
 
 
556
}
 
557
 
 
558
//******************************************************************************
 
559
// Swap a long if you are not on NT/Pentium you must swap
 
560
//******************************************************************************
 
561
static unsigned long swap4(unsigned long l)
 
562
{
 
563
unsigned long n;
 
564
unsigned char *c, *d;
 
565
 
 
566
   c = (unsigned char*) &n;
 
567
   d = (unsigned char*) &l;
 
568
 
 
569
 
 
570
   c[0] = d[3];
 
571
   c[1] = d[2];
 
572
   c[2] = d[1];
 
573
   c[3] = d[0];
 
574
   return n;
 
575
 
 
576
}
 
577
 
 
578
//******************************************************************************
 
579
// Determine if we are low endian or big endian
 
580
//******************************************************************************
 
581
 
 
582
static bool lowendian()
 
583
{
 
584
 unsigned short low = 0xFFFE;
 
585
 unsigned char * pt = (unsigned char *) &low;
 
586
 
 
587
 return  (*pt == 0xFF); 
 
588
}