~ubuntu-branches/ubuntu/quantal/imagemagick/quantal

« back to all changes in this revision

Viewing changes to coders/wpg.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2011-06-15 11:05:28 UTC
  • mfrom: (6.2.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110615110528-08jgo07a4846xh8d
Tags: 8:6.6.0.4-3ubuntu1
* Resynchronise with Debian (LP: #797595).  Remaining changes:
  - Make ufraw-batch (universe) a suggestion instead of a recommendation.
  - Make debian/rules install target depend on check; they cannot reliably
    be run in parallel.
  - Don't set MAKEFLAGS in debian/rules; just pass it to the build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include "magick/blob.h"
43
43
#include "magick/blob-private.h"
44
44
#include "magick/color-private.h"
45
 
#include "magick/colormap.h"
46
45
#include "magick/colormap-private.h"
47
46
#include "magick/constitute.h"
48
47
#include "magick/exception.h"
239
238
}
240
239
 
241
240
 
242
 
static void Rd_WP_DWORD(Image *image,size_t *d)
 
241
static void Rd_WP_DWORD(Image *image,unsigned long *d)
243
242
{
244
243
  unsigned char
245
244
    b;
249
248
  if (b < 0xFFU)
250
249
    return;
251
250
  b=ReadBlobByte(image);
252
 
  *d=(size_t) b;
 
251
  *d=(unsigned long) b;
253
252
  b=ReadBlobByte(image);
254
 
  *d+=(size_t) b*256l;
 
253
  *d+=(unsigned long) b*256l;
255
254
  if (*d < 0x8000)
256
255
    return;
257
256
  *d=(*d & 0x7FFF) << 16;
258
257
  b=ReadBlobByte(image);
259
 
  *d+=(size_t) b;
 
258
  *d+=(unsigned long) b;
260
259
  b=ReadBlobByte(image);
261
 
  *d+=(size_t) b*256l;
 
260
  *d+=(unsigned long) b*256l;
262
261
  return;
263
262
}
264
263
 
265
 
static void InsertRow(unsigned char *p,ssize_t y,Image *image, int bpp)
 
264
static void InsertRow(unsigned char *p,long y,Image *image, int bpp)
266
265
{
267
266
  ExceptionInfo
268
267
    *exception;
270
269
  int
271
270
    bit;
272
271
 
273
 
  ssize_t
 
272
  long
274
273
    x;
275
274
 
276
275
  register PixelPacket
291
290
        if (q == (PixelPacket *) NULL)
292
291
          break;
293
292
        indexes=GetAuthenticIndexQueue(image);
294
 
        for (x=0; x < ((ssize_t) image->columns-7); x+=8)
 
293
        for (x=0; x < ((long) image->columns-7); x+=8)
295
294
          {
296
295
            for (bit=0; bit < 8; bit++)
297
296
              {
303
302
          }
304
303
        if ((image->columns % 8) != 0)
305
304
          {
306
 
            for (bit=0; bit < (ssize_t) (image->columns % 8); bit++)
 
305
            for (bit=0; bit < (long) (image->columns % 8); bit++)
307
306
              {
308
307
                index=((*p) & (0x80 >> bit) ? 0x01 : 0x00);
309
308
                indexes[x+bit]=index;
321
320
        if (q == (PixelPacket *) NULL)
322
321
          break;
323
322
        indexes=GetAuthenticIndexQueue(image);
324
 
        for (x=0; x < ((ssize_t) image->columns-1); x+=2)
 
323
        for (x=0; x < ((long) image->columns-1); x+=2)
325
324
        {
326
325
            index=ConstrainColormapIndex(image,(*p >> 6) & 0x3);
327
326
            indexes[x]=index;
328
 
            *q++=image->colormap[(ssize_t) index];
 
327
            *q++=image->colormap[(long) index];
329
328
            index=ConstrainColormapIndex(image,(*p >> 4) & 0x3);
330
329
            indexes[x]=index;
331
 
            *q++=image->colormap[(ssize_t) index];
 
330
            *q++=image->colormap[(long) index];
332
331
            index=ConstrainColormapIndex(image,(*p >> 2) & 0x3);
333
332
            indexes[x]=index;
334
 
            *q++=image->colormap[(ssize_t) index];
 
333
            *q++=image->colormap[(long) index];
335
334
            index=ConstrainColormapIndex(image,(*p) & 0x3);
336
335
            indexes[x+1]=index;
337
 
            *q++=image->colormap[(ssize_t) index];
 
336
            *q++=image->colormap[(long) index];
338
337
            p++;
339
338
        }
340
339
       if ((image->columns % 4) != 0)
341
340
          {
342
341
            index=ConstrainColormapIndex(image,(*p >> 6) & 0x3);
343
342
            indexes[x]=index;
344
 
            *q++=image->colormap[(ssize_t) index];
 
343
            *q++=image->colormap[(long) index];
345
344
            if ((image->columns % 4) >= 1)
346
345
 
347
346
              {
348
347
                index=ConstrainColormapIndex(image,(*p >> 4) & 0x3);
349
348
                indexes[x]=index;
350
 
                *q++=image->colormap[(ssize_t) index];
 
349
                *q++=image->colormap[(long) index];
351
350
                if ((image->columns % 4) >= 2)
352
351
 
353
352
                  {
354
353
                    index=ConstrainColormapIndex(image,(*p >> 2) & 0x3);
355
354
                    indexes[x]=index;
356
 
                    *q++=image->colormap[(ssize_t) index];
 
355
                    *q++=image->colormap[(long) index];
357
356
                  }
358
357
              }
359
358
            p++;
369
368
        if (q == (PixelPacket *) NULL)
370
369
          break;
371
370
        indexes=GetAuthenticIndexQueue(image);
372
 
        for (x=0; x < ((ssize_t) image->columns-1); x+=2)
 
371
        for (x=0; x < ((long) image->columns-1); x+=2)
373
372
          { 
374
373
            index=ConstrainColormapIndex(image,(*p >> 4) & 0x0f);
375
374
            indexes[x]=index;
376
 
            *q++=image->colormap[(ssize_t) index];
 
375
            *q++=image->colormap[(long) index];
377
376
            index=ConstrainColormapIndex(image,(*p) & 0x0f);
378
377
            indexes[x+1]=index;
379
 
            *q++=image->colormap[(ssize_t) index];
 
378
            *q++=image->colormap[(long) index];
380
379
            p++;
381
380
          }
382
381
        if ((image->columns % 2) != 0)
383
382
          {
384
383
            index=ConstrainColormapIndex(image,(*p >> 4) & 0x0f);
385
384
            indexes[x]=index;
386
 
            *q++=image->colormap[(ssize_t) index];
 
385
            *q++=image->colormap[(long) index];
387
386
            p++;
388
387
          }
389
388
        if (SyncAuthenticPixels(image,exception) == MagickFalse)
396
395
        if (q == (PixelPacket *) NULL) break;
397
396
        indexes=GetAuthenticIndexQueue(image);
398
397
 
399
 
        for (x=0; x < (ssize_t) image->columns; x++)
 
398
        for (x=0; x < (long) image->columns; x++)
400
399
          {
401
400
            index=ConstrainColormapIndex(image,*p);
402
401
            indexes[x]=index;
403
 
            *q++=image->colormap[(ssize_t) index];
 
402
            *q++=image->colormap[(long) index];
404
403
            p++;
405
404
          }
406
405
        if (SyncAuthenticPixels(image,exception) == MagickFalse)
412
411
      q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
413
412
      if (q == (PixelPacket *) NULL)
414
413
        break;
415
 
      for (x=0; x < (ssize_t) image->columns; x++)
 
414
      for (x=0; x < (long) image->columns; x++)
416
415
        {
417
416
          q->red=ScaleCharToQuantum(*p++);
418
417
          q->green=ScaleCharToQuantum(*p++);
431
430
{ \
432
431
  BImgBuff[x]=b; \
433
432
  x++; \
434
 
  if((ssize_t) x>=ldblk) \
 
433
  if((long) x>=ldblk) \
435
434
  { \
436
 
    InsertRow(BImgBuff,(ssize_t) y,image,bpp); \
 
435
    InsertRow(BImgBuff,(long) y,image,bpp); \
437
436
    x=0; \
438
437
    y++; \
439
438
    } \
451
450
    *BImgBuff,
452
451
    RunCount;
453
452
 
454
 
  ssize_t
 
453
  long
455
454
    ldblk;
456
455
 
457
456
  x=0;
458
457
  y=0;
459
458
 
460
 
  ldblk=(ssize_t) ((bpp*image->columns+7)/8);
 
459
  ldblk=(long) ((bpp*image->columns+7)/8);
461
460
  BImgBuff=(unsigned char *) AcquireQuantumMemory((size_t) ldblk,
462
461
    sizeof(*BImgBuff));
463
462
  if(BImgBuff==NULL) return(-2);
464
463
 
465
 
  while(y<(ssize_t) image->rows)
 
464
  while(y<(long) image->rows)
466
465
    {
467
466
      bbuf=ReadBlobByte(image);
468
467
 
500
499
              x=0;
501
500
              y++;    /* Here I need to duplicate previous row RUNCOUNT* */
502
501
              if(y<2) continue;
503
 
              if(y>(ssize_t) image->rows)
 
502
              if(y>(long) image->rows)
504
503
                {
505
504
                  BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff);
506
505
                  return(-4);
523
522
  else\
524
523
    BImgBuff[x] = b;\
525
524
  x++; \
526
 
  if((ssize_t) x >= ldblk) \
 
525
  if((long) x >= ldblk) \
527
526
  { \
528
 
    InsertRow(BImgBuff,(ssize_t) y,image,bpp); \
 
527
    InsertRow(BImgBuff,(long) y,image,bpp); \
529
528
    x=0; \
530
529
    y++; \
531
530
   } \
542
541
    RunCount,
543
542
    SampleBuffer[8];
544
543
 
545
 
  size_t
 
544
  unsigned long
546
545
    x,
547
546
    y;
548
547
 
549
548
  unsigned int
550
549
    i;
551
550
 
552
 
  ssize_t
 
551
  long
553
552
    ldblk;
554
553
 
555
554
  int XorMe = 0;
556
555
 
557
556
  x=0;
558
557
  y=0;
559
 
  ldblk=(ssize_t) ((bpp*image->columns+7)/8);
 
558
  ldblk=(long) ((bpp*image->columns+7)/8);
560
559
  BImgBuff=(unsigned char *) AcquireQuantumMemory((size_t) ldblk,
561
560
    sizeof(*BImgBuff));
562
561
  if(BImgBuff==NULL)
597
596
          if(x!=0)
598
597
            {
599
598
              (void) fprintf(stderr,
600
 
                             "\nUnsupported WPG2 unaligned token RST x=%.20g, please report!\n"
601
 
                             ,(double) x);
 
599
                             "\nUnsupported WPG2 unaligned token RST x=%lu, please report!\n"
 
600
                             ,x);
602
601
              return(-3);
603
602
            }
604
603
          {
605
604
            /* duplicate the previous row RunCount x */
606
605
            for(i=0;i<=RunCount;i++)
607
606
              {      
608
 
                InsertRow(BImgBuff,(ssize_t) (image->rows >= y ? y : image->rows-1),
 
607
                InsertRow(BImgBuff,(long) (image->rows >= y ? y : image->rows-1),
609
608
                          image,bpp);
610
609
                y++;
611
610
              }    
648
647
static unsigned LoadWPG2Flags(Image *image,char Precision,float *Angle,tCTM *CTM)
649
648
{
650
649
const unsigned char TPR=1,TRN=2,SKW=4,SCL=8,ROT=0x10,OID=0x20,LCK=0x80;
651
 
ssize_t x;
 
650
long x;
652
651
unsigned DenX;
653
652
unsigned Flags;
654
653
 
707
706
 
708
707
 
709
708
static Image *ExtractPostscript(Image *image,const ImageInfo *image_info,
710
 
  MagickOffsetType PS_Offset,ssize_t PS_Size,ExceptionInfo *exception)
 
709
  MagickOffsetType PS_Offset,long PS_Size,ExceptionInfo *exception)
711
710
{
712
711
  char
713
712
    postscript_file[MaxTextExtent];
825
824
{
826
825
  typedef struct
827
826
  {
828
 
    size_t FileId;
 
827
    unsigned long FileId;
829
828
    MagickOffsetType DataOffset;
830
829
    unsigned int ProductType;
831
830
    unsigned int FileType;
838
837
  typedef struct
839
838
  {
840
839
    unsigned char RecType;
841
 
    size_t RecordLength;
 
840
    unsigned long RecordLength;
842
841
  } WPGRecord;
843
842
 
844
843
  typedef struct
845
844
  {
846
845
    unsigned char Class;
847
846
    unsigned char RecType;
848
 
    size_t Extension;
849
 
    size_t RecordLength;
 
847
    unsigned long Extension;
 
848
    unsigned long RecordLength;
850
849
  } WPG2Record;
851
850
 
852
851
  typedef struct
894
893
  } WPGColorMapRec;
895
894
 
896
895
  typedef struct {
897
 
    size_t PS_unknown1;
 
896
    unsigned long PS_unknown1;
898
897
    unsigned int PS_unknown2;
899
898
    unsigned int PS_unknown3;
900
899
  } WPGPSl1Record;  
934
933
    bpp,
935
934
    WPG2Flags;
936
935
 
937
 
  ssize_t
 
936
  long
938
937
    ldblk;
939
938
 
940
 
  size_t
941
 
    one;
942
 
 
943
939
  unsigned char
944
940
    *BImgBuff;
945
941
 
952
948
  assert(image_info->signature == MagickSignature);
953
949
  assert(exception != (ExceptionInfo *) NULL);
954
950
  assert(exception->signature == MagickSignature);
955
 
  one=1;
956
951
  image=AcquireImage(image_info);
957
952
  image->depth=8;
958
953
  status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
1046
1041
              if(Rec.RecordLength > 8)
1047
1042
                image=ExtractPostscript(image,image_info,
1048
1043
                  TellBlob(image)+8,   /* skip PS header in the wpg */
1049
 
                  (ssize_t) Rec.RecordLength-8,exception);
 
1044
                  (long) Rec.RecordLength-8,exception);
1050
1045
              break;     
1051
1046
 
1052
1047
            case 0x14:  /* bitmap type 2 */
1080
1075
            UnpackRaster:      
1081
1076
              if ((image->colors == 0) && (bpp != 24))
1082
1077
                {
1083
 
                  image->colors=one << bpp;
 
1078
                  image->colors=1 << bpp;
1084
1079
                  if (!AcquireImageColormap(image,image->colors))
1085
1080
                    {
1086
1081
                    NoMemory:
1098
1093
              else
1099
1094
                {
1100
1095
                  if (bpp < 24)
1101
 
                    if ( (image->colors < (one << bpp)) && (bpp != 24) )
 
1096
                    if ( (image->colors < (1UL<<bpp)) && (bpp != 24) )
1102
1097
                      image->colormap=(PixelPacket *) ResizeQuantumMemory(
1103
 
                        image->colormap,(size_t) (one << bpp),
 
1098
                        image->colormap,(size_t) (1UL << bpp),
1104
1099
                        sizeof(*image->colormap));
1105
1100
                }
1106
1101
          
1172
1167
              if(Rec.RecordLength>0x3C)
1173
1168
                image=ExtractPostscript(image,image_info,
1174
1169
                  TellBlob(image)+0x3C,   /* skip PS l2 header in the wpg */
1175
 
                  (ssize_t) Rec.RecordLength-0x3C,exception);
 
1170
                  (long) Rec.RecordLength-0x3C,exception);
1176
1171
              break;
1177
1172
            }
1178
1173
        }
1260
1255
 
1261
1256
              if ((image->colors == 0) && (bpp != 24))
1262
1257
                {
1263
 
                  size_t
1264
 
                    one;
1265
 
 
1266
 
                  one=1;
1267
 
                  image->colors=one << bpp;
 
1258
                  image->colors=1 << bpp;
1268
1259
                  if (!AcquireImageColormap(image,image->colors))
1269
1260
                    goto NoMemory;
1270
1261
                }
1271
1262
              else
1272
1263
                {
1273
1264
                  if(bpp < 24)
1274
 
                    if( image->colors<(one << bpp) && bpp!=24 )
 
1265
                    if( image->colors<(1UL<<bpp) && bpp!=24 )
1275
1266
                      image->colormap=(PixelPacket *) ResizeQuantumMemory(
1276
 
                       image->colormap,(size_t) (one << bpp),
 
1267
                       image->colormap,(size_t) (1UL << bpp),
1277
1268
                       sizeof(*image->colormap));
1278
1269
                }
1279
1270
 
1282
1273
                {
1283
1274
                case 0:    /*Uncompressed raster*/
1284
1275
                  {
1285
 
                    ldblk=(ssize_t) ((bpp*image->columns+7)/8);
 
1276
                    ldblk=(long) ((bpp*image->columns+7)/8);
1286
1277
                    BImgBuff=(unsigned char *) AcquireQuantumMemory((size_t)
1287
1278
                      ldblk,sizeof(*BImgBuff));
1288
1279
                    if (BImgBuff == (unsigned char *) NULL)
1289
1280
                      goto NoMemory;
1290
1281
 
1291
 
                    for(i=0; i< (ssize_t) image->rows; i++)
 
1282
                    for(i=0; i< (long) image->rows; i++)
1292
1283
                      {
1293
1284
                        (void) ReadBlob(image,ldblk,BImgBuff);
1294
1285
                        InsertRow(BImgBuff,i,image,bpp);
1350
1341
              if(Rec2.RecordLength > (unsigned int) i)
1351
1342
                image=ExtractPostscript(image,image_info,
1352
1343
                  TellBlob(image)+i,    /*skip PS header in the wpg2*/
1353
 
                  (ssize_t) (Rec2.RecordLength-i-2),exception);
 
1344
                  (long) (Rec2.RecordLength-i-2),exception);
1354
1345
              break;
1355
1346
 
1356
1347
      case 0x1B:          /*bitmap rectangle*/
1374
1365
    Image
1375
1366
      *p;
1376
1367
 
1377
 
    ssize_t
 
1368
    long
1378
1369
      scene=0;
1379
1370
 
1380
1371
    /*
1397
1388
      Fix scene numbers.
1398
1389
    */
1399
1390
    for (p=image; p != (Image *) NULL; p=p->next)
1400
 
      p->scene=(size_t) scene++;
 
1391
      p->scene=(unsigned long) scene++;
1401
1392
  }
1402
1393
  if (image == (Image *) NULL)
1403
1394
    ThrowReaderException(CorruptImageError,
1425
1416
%
1426
1417
%  The format of the RegisterWPGImage method is:
1427
1418
%
1428
 
%      size_t RegisterWPGImage(void)
 
1419
%      unsigned long RegisterWPGImage(void)
1429
1420
%
1430
1421
*/
1431
 
ModuleExport size_t RegisterWPGImage(void)
 
1422
ModuleExport unsigned long RegisterWPGImage(void)
1432
1423
{
1433
1424
  MagickInfo
1434
1425
    *entry;