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

« back to all changes in this revision

Viewing changes to coders/pnm.c

  • Committer: Bazaar Package Importer
  • Author(s): Muharem Hrnjadovic
  • Date: 2009-06-04 13:01:13 UTC
  • mfrom: (1.1.5 upstream) (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090604130113-my9114jxmafpwew3
Tags: 7:6.5.1.0-1.1ubuntu1
* Merge from debian unstable, remaining changes:
  - (Build-)depend on libltdl7-dev instead of libltdl3-dev (the armel buildds
    currently have both available).
  - Don't build-dep on librsvg, it brings in excessive dependencies

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
%                                 July 1992                                   %
18
18
%                                                                             %
19
19
%                                                                             %
20
 
%  Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization      %
 
20
%  Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization      %
21
21
%  dedicated to making software imaging solutions freely available.           %
22
22
%                                                                             %
23
23
%  You may not use this file except in compliance with the License.  You may  %
42
42
#include "magick/studio.h"
43
43
#include "magick/blob.h"
44
44
#include "magick/blob-private.h"
 
45
#include "magick/cache.h"
45
46
#include "magick/color.h"
46
47
#include "magick/color-private.h"
47
48
#include "magick/colorspace.h"
84
85
%
85
86
%  The format of the IsPNM method is:
86
87
%
87
 
%      MagickBooleanType IsPNM(const unsigned char *magick,const size_t length)
 
88
%      MagickBooleanType IsPNM(const unsigned char *magick,const size_t extent)
88
89
%
89
90
%  A description of each parameter follows:
90
91
%
91
92
%    o magick: This string is generally the first few bytes of an image file
92
93
%      or blob.
93
94
%
94
 
%    o length: Specifies the length of the magick string.
 
95
%    o extent: Specifies the extent of the magick string.
95
96
%
96
97
*/
97
 
static MagickBooleanType IsPNM(const unsigned char *magick,const size_t length)
 
98
static MagickBooleanType IsPNM(const unsigned char *magick,const size_t extent)
98
99
{
99
 
  if (length < 2)
 
100
  if (extent < 2)
100
101
    return(MagickFalse);
101
102
  if ((*magick == (unsigned char) 'P') &&
102
103
      ((magick[1] == '1') || (magick[1] == '2') || (magick[1] == '3') ||
157
158
    *p;
158
159
 
159
160
  size_t
160
 
    length;
 
161
    extent;
161
162
 
162
163
  unsigned long
163
164
    value;
165
166
  /*
166
167
    Skip any leading whitespace.
167
168
  */
168
 
  length=MaxTextExtent;
 
169
  extent=MaxTextExtent;
169
170
  comment=(char *) NULL;
170
171
  p=comment;
171
172
  do
183
184
        p=comment+strlen(comment);
184
185
        for ( ; (c != EOF) && (c != (int) '\n'); p++)
185
186
        {
186
 
          if ((size_t) (p-comment+1) >= length)
 
187
          if ((size_t) (p-comment+1) >= extent)
187
188
            {
188
 
              length<<=1;
189
 
              comment=(char *) ResizeQuantumMemory(comment,length+MaxTextExtent,
 
189
              extent<<=1;
 
190
              comment=(char *) ResizeQuantumMemory(comment,extent+MaxTextExtent,
190
191
                sizeof(*comment));
191
192
              if (comment == (char *) NULL)
192
193
                break;
235
236
    *image;
236
237
 
237
238
  long
 
239
    row,
238
240
    y;
239
241
 
240
242
  MagickBooleanType
249
251
  QuantumType
250
252
    quantum_type;
251
253
 
252
 
  register const unsigned char
253
 
    *p;
254
 
 
255
254
  register long
256
255
    x;
257
256
 
262
261
    i;
263
262
 
264
263
  size_t
265
 
    length,
 
264
    extent,
266
265
    packet_size;
267
266
 
268
267
  ssize_t
269
268
    count;
270
269
 
271
 
  unsigned char
272
 
    *pixels;
273
 
 
274
270
  unsigned long
275
271
    depth,
276
272
    max_value;
277
273
 
 
274
  ViewInfo
 
275
    *image_view;
 
276
 
278
277
  /*
279
278
    Open image file.
280
279
  */
352
351
          p=keyword;
353
352
          do
354
353
          {
355
 
            if ((size_t) (p-keyword) < MaxTextExtent)
 
354
            if ((size_t) (p-keyword) < (MaxTextExtent-1))
356
355
              *p++=c;
357
356
            c=ReadBlobByte(image);
358
357
          } while (isalnum(c));
364
363
          p=value;
365
364
          while (isalnum(c) || (c == '_'))
366
365
          {
367
 
            if ((size_t) (p-value) < MaxTextExtent)
 
366
            if ((size_t) (p-value) < (MaxTextExtent-1))
368
367
              *p++=c;
369
368
            c=ReadBlobByte(image);
370
369
          }
424
423
    if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
425
424
      if (image->scene >= (image_info->scene+image_info->number_scenes-1))
426
425
        break;
427
 
    if (SetImageExtent(image,0,0) == MagickFalse)
428
 
      {
429
 
        InheritException(exception,&image->exception);
430
 
        return(DestroyImageList(image));
431
 
      }
432
426
    /*
433
 
      Convert PNM pixels to runlength-encoded MIFF packets.
 
427
      Convert PNM pixels to runextent-encoded MIFF packets.
434
428
    */
 
429
    status=MagickTrue;
 
430
    row=0;
435
431
    switch (format)
436
432
    {
437
433
      case '1':
441
437
        */
442
438
        for (y=0; y < (long) image->rows; y++)
443
439
        {
444
 
          q=SetImagePixels(image,0,y,image->columns,1);
 
440
          q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
445
441
          if (q == (PixelPacket *) NULL)
446
442
            break;
447
443
          for (x=0; x < (long) image->columns; x++)
451
447
            q->blue=q->red;
452
448
            q++;
453
449
          }
454
 
          if (SyncImagePixels(image) == MagickFalse)
 
450
          if (SyncAuthenticPixels(image,exception) == MagickFalse)
455
451
            break;
456
452
          if (image->previous == (Image *) NULL)
457
453
            {
486
482
          }
487
483
        for (y=0; y < (long) image->rows; y++)
488
484
        {
489
 
          q=SetImagePixels(image,0,y,image->columns,1);
 
485
          q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
490
486
          if (q == (PixelPacket *) NULL)
491
487
            break;
492
488
          for (x=0; x < (long) image->columns; x++)
500
496
            q->blue=q->red;
501
497
            q++;
502
498
          }
503
 
          if (SyncImagePixels(image) == MagickFalse)
 
499
          if (SyncAuthenticPixels(image,exception) == MagickFalse)
504
500
            break;
505
501
          if (image->previous == (Image *) NULL)
506
502
            {
537
533
          }
538
534
        for (y=0; y < (long) image->rows; y++)
539
535
        {
540
 
          q=SetImagePixels(image,0,y,image->columns,1);
 
536
          q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
541
537
          if (q == (PixelPacket *) NULL)
542
538
            break;
543
539
          for (x=0; x < (long) image->columns; x++)
559
555
            q->blue=(Quantum) pixel.blue;
560
556
            q++;
561
557
          }
562
 
          if (SyncImagePixels(image) == MagickFalse)
 
558
          if (SyncAuthenticPixels(image,exception) == MagickFalse)
563
559
            break;
564
560
          if (image->previous == (Image *) NULL)
565
561
            {
577
573
        /*
578
574
          Convert PBM raw image to pixel packets.
579
575
        */
580
 
        quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
581
 
        if (quantum_info == (QuantumInfo *) NULL)
582
 
          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
583
 
        quantum_info->min_is_white=MagickTrue;
584
576
        quantum_type=GrayQuantum;
585
577
        if (image->storage_class == PseudoClass)
586
578
          quantum_type=IndexQuantum;
587
 
        pixels=GetQuantumPixels(quantum_info);
588
 
        length=GetQuantumExtent(image,quantum_info,quantum_type);
 
579
        quantum_info=AcquireQuantumInfo(image_info,image);
 
580
        if (quantum_info == (QuantumInfo *) NULL)
 
581
          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
 
582
        SetQuantumMinIsWhite(quantum_info,MagickTrue);
 
583
        extent=GetQuantumExtent(image,quantum_info,quantum_type);
 
584
        image_view=AcquireCacheView(image);
 
585
#if defined(MAGICKCORE_OPENMP_SUPPORT)
 
586
  #pragma omp parallel for schedule(dynamic,1) shared(row,status,quantum_type)
 
587
#endif
589
588
        for (y=0; y < (long) image->rows; y++)
590
589
        {
591
 
          q=SetImagePixels(image,0,y,image->columns,1);
 
590
          long
 
591
            offset;
 
592
 
 
593
          MagickBooleanType
 
594
            sync;
 
595
 
 
596
          register PixelPacket
 
597
            *q;
 
598
 
 
599
          ssize_t
 
600
            count;
 
601
 
 
602
          size_t
 
603
            length;
 
604
 
 
605
          unsigned char
 
606
            *pixels;
 
607
 
 
608
          if (status == MagickFalse)
 
609
            continue;
 
610
          pixels=GetQuantumPixels(quantum_info);
 
611
#if defined(MAGICKCORE_OPENMP_SUPPORT)
 
612
          #pragma omp critical (MagickCore_ReadPNMImage)
 
613
#endif
 
614
          {
 
615
            count=ReadBlob(image,extent,pixels);
 
616
            if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
 
617
                (image->previous == (Image *) NULL))
 
618
              {
 
619
                MagickBooleanType
 
620
                  proceed;
 
621
 
 
622
                proceed=SetImageProgress(image,LoadImageTag,row,image->rows);
 
623
                if (proceed == MagickFalse)
 
624
                  status=MagickFalse;
 
625
              }
 
626
            offset=row++;
 
627
          }
 
628
          if (count != (ssize_t) extent)
 
629
            status=MagickFalse;
 
630
          q=QueueCacheViewAuthenticPixels(image_view,0,offset,image->columns,1,
 
631
            exception);
592
632
          if (q == (PixelPacket *) NULL)
593
 
            break;
594
 
          count=ReadBlob(image,length,pixels);
595
 
          if (count != (ssize_t) length)
596
 
            break;
597
 
          length=ImportQuantumPixels(image,quantum_info,quantum_type,pixels);
598
 
          if (count != (ssize_t) length)
599
 
            break;
600
 
          if (SyncImagePixels(image) == MagickFalse)
601
 
            break;
602
 
          if (image->previous == (Image *) NULL)
603
633
            {
604
 
              status=SetImageProgress(image,LoadImageTag,y,image->rows);
605
 
              if (status == MagickFalse)
606
 
                break;
 
634
              status=MagickFalse;
 
635
              continue;
607
636
            }
 
637
          length=ImportQuantumPixels(image,image_view,quantum_info,quantum_type,
 
638
            pixels,exception);
 
639
          if (length != extent)
 
640
            status=MagickFalse;
 
641
          sync=SyncCacheViewAuthenticPixels(image_view,exception);
 
642
          if (sync == MagickFalse)
 
643
            status=MagickFalse;
608
644
        }
 
645
        image_view=DestroyCacheView(image_view);
 
646
        quantum_info=DestroyQuantumInfo(quantum_info);
 
647
        if (status == MagickFalse)
 
648
          ThrowReaderException(CorruptImageError,"UnableToReadImageData");
609
649
        SetQuantumImageType(image,quantum_type);
610
 
        quantum_info=DestroyQuantumInfo(quantum_info);
611
650
        break;
612
651
      }
613
652
      case '5':
614
653
      {
615
654
        QuantumAny
616
 
          scale;
 
655
          range;
617
656
 
618
657
        /*
619
658
          Convert PGM raw image to pixel packets.
620
659
        */
621
 
        quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
 
660
        range=GetQuantumRange(image->depth);
 
661
        quantum_type=GrayQuantum;
 
662
        extent=(image->depth <= 8 ? 1 : 2)*image->columns;
 
663
        quantum_info=AcquireQuantumInfo(image_info,image);
622
664
        if (quantum_info == (QuantumInfo *) NULL)
623
665
          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
624
 
        quantum_type=GrayQuantum;
625
 
        scale=GetQuantumScale(image->depth);
626
 
        pixels=GetQuantumPixels(quantum_info);
627
 
        length=(image->depth <= 8 ? 1 : 2)*image->columns;
 
666
        image_view=AcquireCacheView(image);
 
667
#if defined(MAGICKCORE_OPENMP_SUPPORT)
 
668
  #pragma omp parallel for schedule(dynamic,1) shared(row,status,quantum_type)
 
669
#endif
628
670
        for (y=0; y < (long) image->rows; y++)
629
671
        {
630
 
          q=SetImagePixels(image,0,y,image->columns,1);
 
672
          long
 
673
            offset;
 
674
 
 
675
          MagickBooleanType
 
676
            sync;
 
677
 
 
678
          register const unsigned char
 
679
            *p;
 
680
 
 
681
          register long
 
682
            x;
 
683
 
 
684
          register PixelPacket
 
685
            *q;
 
686
 
 
687
          ssize_t
 
688
            count;
 
689
 
 
690
          unsigned char
 
691
            *pixels;
 
692
 
 
693
          if (status == MagickFalse)
 
694
            continue;
 
695
          pixels=GetQuantumPixels(quantum_info);
 
696
#if defined(MAGICKCORE_OPENMP_SUPPORT)
 
697
          #pragma omp critical (MagickCore_ReadPNMImage)
 
698
#endif
 
699
          {
 
700
            count=ReadBlob(image,extent,pixels);
 
701
            if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
 
702
                (image->previous == (Image *) NULL))
 
703
              {
 
704
                MagickBooleanType
 
705
                  proceed;
 
706
 
 
707
                proceed=SetImageProgress(image,LoadImageTag,row,image->rows);
 
708
                if (proceed == MagickFalse)
 
709
                  status=MagickFalse;
 
710
              }
 
711
            offset=row++;
 
712
          }
 
713
          if (count != (ssize_t) extent)
 
714
            status=MagickFalse;
 
715
          q=QueueCacheViewAuthenticPixels(image_view,0,offset,image->columns,1,
 
716
            exception);
631
717
          if (q == (PixelPacket *) NULL)
632
 
            break;
633
 
          count=ReadBlob(image,length,pixels);
634
 
          if (count != (ssize_t) length)
635
 
            ThrowReaderException(CorruptImageError,"UnableToReadImageData");
 
718
            {
 
719
              status=MagickFalse;
 
720
              continue;
 
721
            }
636
722
          p=pixels;
637
723
          if ((image->depth == 8) || (image->depth == 16))
638
 
            (void) ImportQuantumPixels(image,quantum_info,quantum_type,pixels);
 
724
            (void) ImportQuantumPixels(image,image_view,quantum_info,
 
725
              quantum_type,pixels,exception);
639
726
          else
640
727
            if (image->depth <= 8)
641
728
              {
645
732
                for (x=0; x < (long) image->columns; x++)
646
733
                {
647
734
                  p=PushCharPixel(p,&pixel);
648
 
                  q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
 
735
                  q->red=ScaleAnyToQuantum(pixel,range);
649
736
                  q->green=q->red;
650
737
                  q->blue=q->red;
651
738
                  q++;
659
746
                for (x=0; x < (long) image->columns; x++)
660
747
                {
661
748
                  p=PushShortPixel(MSBEndian,p,&pixel);
662
 
                  q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
 
749
                  q->red=ScaleAnyToQuantum(pixel,range);
663
750
                  q->green=q->red;
664
751
                  q->blue=q->red;
665
752
                  q++;
666
753
                }
667
754
              }
668
 
          if (SyncImagePixels(image) == MagickFalse)
669
 
            break;
670
 
          if (image->previous == (Image *) NULL)
671
 
            {
672
 
              status=SetImageProgress(image,LoadImageTag,y,image->rows);
673
 
              if (status == MagickFalse)
674
 
                break;
675
 
            }
 
755
          sync=SyncCacheViewAuthenticPixels(image_view,exception);
 
756
          if (sync == MagickFalse)
 
757
            status=MagickFalse;
676
758
        }
 
759
        image_view=DestroyCacheView(image_view);
 
760
        quantum_info=DestroyQuantumInfo(quantum_info);
 
761
        if (status == MagickFalse)
 
762
          ThrowReaderException(CorruptImageError,"UnableToReadImageData");
677
763
        SetQuantumImageType(image,quantum_type);
678
 
        quantum_info=DestroyQuantumInfo(quantum_info);
679
764
        break;
680
765
      }
681
766
      case '6':
684
769
          type;
685
770
 
686
771
        QuantumAny
687
 
          scale;
 
772
          range;
688
773
 
689
774
        /*
690
775
          Convert PNM raster image to pixel packets.
691
776
        */
692
777
        type=BilevelType;
693
 
        quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
694
 
        if (quantum_info == (QuantumInfo *) NULL)
695
 
          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
696
778
        quantum_type=RGBQuantum;
697
 
        pixels=GetQuantumPixels(quantum_info);
698
 
        length=3*(image->depth <= 8 ? 1 : 2)*image->columns;
699
 
        scale=GetQuantumScale(image->depth);
 
779
        extent=3*(image->depth <= 8 ? 1 : 2)*image->columns;
 
780
        range=GetQuantumRange(image->depth);
 
781
        quantum_info=AcquireQuantumInfo(image_info,image);
 
782
        if (quantum_info == (QuantumInfo *) NULL)
 
783
          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
 
784
        image_view=AcquireCacheView(image);
 
785
#if defined(MAGICKCORE_OPENMP_SUPPORT)
 
786
  #pragma omp parallel for schedule(dynamic,1) shared(row,status,type)
 
787
#endif
700
788
        for (y=0; y < (long) image->rows; y++)
701
789
        {
702
 
          q=SetImagePixels(image,0,y,image->columns,1);
 
790
          long
 
791
            offset;
 
792
 
 
793
          MagickBooleanType
 
794
            sync;
 
795
 
 
796
          register const unsigned char
 
797
            *p;
 
798
 
 
799
          register long
 
800
            x;
 
801
 
 
802
          register PixelPacket
 
803
            *q;
 
804
 
 
805
          ssize_t
 
806
            count;
 
807
 
 
808
          size_t
 
809
            length;
 
810
 
 
811
          unsigned char
 
812
            *pixels;
 
813
 
 
814
          if (status == MagickFalse)
 
815
            continue;
 
816
          pixels=GetQuantumPixels(quantum_info);
 
817
#if defined(MAGICKCORE_OPENMP_SUPPORT)
 
818
          #pragma omp critical (MagickCore_ReadPNMImage)
 
819
#endif
 
820
          {
 
821
            count=ReadBlob(image,extent,pixels);
 
822
            if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
 
823
                (image->previous == (Image *) NULL))
 
824
              {
 
825
                MagickBooleanType
 
826
                  proceed;
 
827
 
 
828
                proceed=SetImageProgress(image,LoadImageTag,row,image->rows);
 
829
                if (proceed == MagickFalse)
 
830
                  status=MagickFalse;
 
831
              }
 
832
            offset=row++;
 
833
          }
 
834
          if (count != (ssize_t) extent)
 
835
            status=MagickFalse;
 
836
          q=QueueCacheViewAuthenticPixels(image_view,0,offset,image->columns,1,
 
837
            exception);
703
838
          if (q == (PixelPacket *) NULL)
704
 
            break;
705
 
          count=ReadBlob(image,length,pixels);
706
 
          if (count != (ssize_t) length)
707
 
            ThrowReaderException(CorruptImageError,"UnableToReadImageData");
 
839
            {
 
840
              status=MagickFalse;
 
841
              continue;
 
842
            }
708
843
          p=pixels;
709
844
          if ((image->depth == 8) || (image->depth == 16))
710
 
            length=ImportQuantumPixels(image,quantum_info,quantum_type,pixels);
 
845
            {
 
846
              length=ImportQuantumPixels(image,image_view,quantum_info,
 
847
                quantum_type,pixels,exception);
 
848
              if (length != extent)
 
849
                status=MagickFalse;
 
850
            }
711
851
          else
712
852
            if (image->depth <= 8)
713
853
              {
721
861
                for (x=0; x < (long) image->columns; x++)
722
862
                {
723
863
                  p=PushCharPixel(p,&pixel);
724
 
                  r->red=ScaleAnyToQuantum(pixel,image->depth,scale);
725
 
                  p=PushCharPixel(p,&pixel);
726
 
                  r->green=ScaleAnyToQuantum(pixel,image->depth,scale);
727
 
                  p=PushCharPixel(p,&pixel);
728
 
                  r->blue=ScaleAnyToQuantum(pixel,image->depth,scale);
 
864
                  r->red=ScaleAnyToQuantum(pixel,range);
 
865
                  p=PushCharPixel(p,&pixel);
 
866
                  r->green=ScaleAnyToQuantum(pixel,range);
 
867
                  p=PushCharPixel(p,&pixel);
 
868
                  r->blue=ScaleAnyToQuantum(pixel,range);
729
869
                  r++;
730
870
                }
731
871
              }
741
881
                for (x=0; x < (long) image->columns; x++)
742
882
                {
743
883
                  p=PushShortPixel(MSBEndian,p,&pixel);
744
 
                  r->red=ScaleAnyToQuantum(pixel,image->depth,scale);
745
 
                  p=PushShortPixel(MSBEndian,p,&pixel);
746
 
                  r->green=ScaleAnyToQuantum(pixel,image->depth,scale);
747
 
                  p=PushShortPixel(MSBEndian,p,&pixel);
748
 
                  r->blue=ScaleAnyToQuantum(pixel,image->depth,scale);
 
884
                  r->red=ScaleAnyToQuantum(pixel,range);
 
885
                  p=PushShortPixel(MSBEndian,p,&pixel);
 
886
                  r->green=ScaleAnyToQuantum(pixel,range);
 
887
                  p=PushShortPixel(MSBEndian,p,&pixel);
 
888
                  r->blue=ScaleAnyToQuantum(pixel,range);
749
889
                  r++;
750
890
                }
751
891
              }
762
902
                break;
763
903
              q++;
764
904
            }
765
 
          if (SyncImagePixels(image) == MagickFalse)
766
 
            break;
767
 
          if (image->previous == (Image *) NULL)
768
 
            {
769
 
              status=SetImageProgress(image,LoadImageTag,y,image->rows);
770
 
              if (status == MagickFalse)
771
 
                break;
772
 
            }
 
905
          sync=SyncCacheViewAuthenticPixels(image_view,exception);
 
906
          if (sync == MagickFalse)
 
907
            status=MagickFalse;
773
908
        }
 
909
        image_view=DestroyCacheView(image_view);
774
910
        quantum_info=DestroyQuantumInfo(quantum_info);
 
911
        if (status == MagickFalse)
 
912
          ThrowReaderException(CorruptImageError,"UnableToReadImageData");
775
913
        if (type != UndefinedType)
776
914
          image->type=type;
777
915
        break;
782
920
          *indexes;
783
921
 
784
922
        QuantumAny
785
 
          scale;
 
923
          range;
 
924
 
 
925
        unsigned long
 
926
          channels;
786
927
 
787
928
        /*
788
929
          Convert PAM raster image to pixel packets.
789
930
        */
790
 
        quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
791
 
        if (quantum_info == (QuantumInfo *) NULL)
792
 
          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
793
 
        pixels=GetQuantumPixels(quantum_info);
794
 
        scale=GetQuantumScale(image->depth);
 
931
        range=GetQuantumRange(image->depth);
795
932
        switch (quantum_type)
796
933
        {
797
934
          case GrayQuantum:
798
935
          case GrayAlphaQuantum:
799
936
          {
800
 
            length=(image->depth <= 8 ? 1 : 2)*image->columns;
 
937
            channels=1;
801
938
            break;
802
939
          }
803
940
          case CMYKQuantum:
804
941
          case CMYKAQuantum:
805
942
          {
806
 
            length=4*(image->depth <= 8 ? 1 : 2)*image->columns;
 
943
            channels=4;
807
944
            break;
808
945
          }
809
946
          default:
810
947
          {
811
 
            length=3*(image->depth <= 8 ? 1 : 2)*image->columns;
 
948
            channels=3;
812
949
            break;
813
950
          }
814
951
        }
 
952
        if (image->matte != MagickFalse)
 
953
          channels++;
 
954
        extent=channels*(image->depth <= 8 ? 1 : 2)*image->columns;
 
955
        quantum_info=AcquireQuantumInfo(image_info,image);
 
956
        if (quantum_info == (QuantumInfo *) NULL)
 
957
          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
 
958
        image_view=AcquireCacheView(image);
 
959
#if defined(MAGICKCORE_OPENMP_SUPPORT)
 
960
  #pragma omp parallel for schedule(dynamic,1) shared(row,status,quantum_type)
 
961
#endif
815
962
        for (y=0; y < (long) image->rows; y++)
816
963
        {
817
 
          q=SetImagePixels(image,0,y,image->columns,1);
 
964
          long
 
965
            offset;
 
966
 
 
967
          MagickBooleanType
 
968
            sync;
 
969
 
 
970
          register const unsigned char
 
971
            *p;
 
972
 
 
973
          register long
 
974
            x;
 
975
 
 
976
          register PixelPacket
 
977
            *q;
 
978
 
 
979
          ssize_t
 
980
            count;
 
981
 
 
982
          unsigned char
 
983
            *pixels;
 
984
 
 
985
          if (status == MagickFalse)
 
986
            continue;
 
987
          pixels=GetQuantumPixels(quantum_info);
 
988
#if defined(MAGICKCORE_OPENMP_SUPPORT)
 
989
          #pragma omp critical (MagickCore_ReadPNMImage)
 
990
#endif
 
991
          {
 
992
            count=ReadBlob(image,extent,pixels);
 
993
            if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
 
994
                (image->previous == (Image *) NULL))
 
995
              {
 
996
                MagickBooleanType
 
997
                  proceed;
 
998
 
 
999
                proceed=SetImageProgress(image,LoadImageTag,row,image->rows);
 
1000
                if (proceed == MagickFalse)
 
1001
                  status=MagickFalse;
 
1002
              }
 
1003
            offset=row++;
 
1004
          }
 
1005
          if (count != (ssize_t) extent)
 
1006
            status=MagickFalse;
 
1007
          q=QueueCacheViewAuthenticPixels(image_view,0,offset,image->columns,1,
 
1008
            exception);
818
1009
          if (q == (PixelPacket *) NULL)
819
 
            break;
820
 
          indexes=GetIndexes(image);
821
 
          count=ReadBlob(image,length,pixels);
822
 
          if (count != (ssize_t) length)
823
 
            ThrowReaderException(CorruptImageError,"UnableToReadImageData");
 
1010
            {
 
1011
              status=MagickFalse;
 
1012
              continue;
 
1013
            }
 
1014
          indexes=GetCacheViewAuthenticIndexQueue(image_view);
824
1015
          p=pixels;
825
1016
          if ((image->depth == 8) || (image->depth == 16))
826
 
            (void) ImportQuantumPixels(image,quantum_info,quantum_type,pixels);
 
1017
            (void) ImportQuantumPixels(image,image_view,quantum_info,
 
1018
              quantum_type,pixels,exception);
827
1019
          else
828
1020
            switch (quantum_type)
829
1021
            {
838
1030
                    for (x=0; x < (long) image->columns; x++)
839
1031
                    {
840
1032
                      p=PushCharPixel(p,&pixel);
841
 
                      q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
 
1033
                      q->red=ScaleAnyToQuantum(pixel,range);
842
1034
                      q->green=q->red;
843
1035
                      q->blue=q->red;
 
1036
                      q->opacity=OpaqueOpacity;
844
1037
                      if (image->matte != MagickFalse)
845
1038
                        {
846
1039
                          p=PushCharPixel(p,&pixel);
847
 
                          q->opacity=ScaleAnyToQuantum(pixel,image->depth,scale);
 
1040
                          q->opacity=ScaleAnyToQuantum(pixel,range);
848
1041
                        }
849
1042
                      q++;
850
1043
                    }
857
1050
                    for (x=0; x < (long) image->columns; x++)
858
1051
                    {
859
1052
                      p=PushShortPixel(MSBEndian,p,&pixel);
860
 
                      q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
 
1053
                      q->red=ScaleAnyToQuantum(pixel,range);
861
1054
                      q->green=q->red;
862
1055
                      q->blue=q->red;
 
1056
                      q->opacity=OpaqueOpacity;
863
1057
                      if (image->matte != MagickFalse)
864
1058
                        {
865
1059
                          p=PushShortPixel(MSBEndian,p,&pixel);
866
 
                          q->opacity=ScaleAnyToQuantum(pixel,image->depth,scale);
 
1060
                          q->opacity=ScaleAnyToQuantum(pixel,range);
867
1061
                        }
868
1062
                      q++;
869
1063
                    }
881
1075
                    for (x=0; x < (long) image->columns; x++)
882
1076
                    {
883
1077
                      p=PushCharPixel(p,&pixel);
884
 
                      q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
885
 
                      p=PushCharPixel(p,&pixel);
886
 
                      q->green=ScaleAnyToQuantum(pixel,image->depth,scale);
887
 
                      p=PushCharPixel(p,&pixel);
888
 
                      q->blue=ScaleAnyToQuantum(pixel,image->depth,scale);
889
 
                      p=PushCharPixel(p,&pixel);
890
 
                      indexes[x]=ScaleAnyToQuantum(pixel,image->depth,scale);
 
1078
                      q->red=ScaleAnyToQuantum(pixel,range);
 
1079
                      p=PushCharPixel(p,&pixel);
 
1080
                      q->green=ScaleAnyToQuantum(pixel,range);
 
1081
                      p=PushCharPixel(p,&pixel);
 
1082
                      q->blue=ScaleAnyToQuantum(pixel,range);
 
1083
                      p=PushCharPixel(p,&pixel);
 
1084
                      indexes[x]=ScaleAnyToQuantum(pixel,range);
 
1085
                      q->opacity=OpaqueOpacity;
891
1086
                      if (image->matte != MagickFalse)
892
1087
                        {
893
1088
                          p=PushCharPixel(p,&pixel);
894
 
                          q->opacity=ScaleAnyToQuantum(pixel,image->depth,scale);
 
1089
                          q->opacity=ScaleAnyToQuantum(pixel,range);
895
1090
                        }
896
1091
                      q++;
897
1092
                    }
904
1099
                    for (x=0; x < (long) image->columns; x++)
905
1100
                    {
906
1101
                      p=PushShortPixel(MSBEndian,p,&pixel);
907
 
                      q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
908
 
                      p=PushShortPixel(MSBEndian,p,&pixel);
909
 
                      q->green=ScaleAnyToQuantum(pixel,image->depth,scale);
910
 
                      p=PushShortPixel(MSBEndian,p,&pixel);
911
 
                      q->blue=ScaleAnyToQuantum(pixel,image->depth,scale);
912
 
                      p=PushShortPixel(MSBEndian,p,&pixel);
913
 
                      indexes[x]=ScaleAnyToQuantum(pixel,image->depth,scale);
 
1102
                      q->red=ScaleAnyToQuantum(pixel,range);
 
1103
                      p=PushShortPixel(MSBEndian,p,&pixel);
 
1104
                      q->green=ScaleAnyToQuantum(pixel,range);
 
1105
                      p=PushShortPixel(MSBEndian,p,&pixel);
 
1106
                      q->blue=ScaleAnyToQuantum(pixel,range);
 
1107
                      p=PushShortPixel(MSBEndian,p,&pixel);
 
1108
                      indexes[x]=ScaleAnyToQuantum(pixel,range);
 
1109
                      q->opacity=OpaqueOpacity;
914
1110
                      if (image->matte != MagickFalse)
915
1111
                        {
916
1112
                          p=PushShortPixel(MSBEndian,p,&pixel);
917
 
                          q->opacity=ScaleAnyToQuantum(pixel,image->depth,scale);
 
1113
                          q->opacity=ScaleAnyToQuantum(pixel,range);
918
1114
                        }
919
1115
                      q++;
920
1116
                    }
931
1127
                    for (x=0; x < (long) image->columns; x++)
932
1128
                    {
933
1129
                      p=PushCharPixel(p,&pixel);
934
 
                      q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
935
 
                      p=PushCharPixel(p,&pixel);
936
 
                      q->green=ScaleAnyToQuantum(pixel,image->depth,scale);
937
 
                      p=PushCharPixel(p,&pixel);
938
 
                      q->blue=ScaleAnyToQuantum(pixel,image->depth,scale);
 
1130
                      q->red=ScaleAnyToQuantum(pixel,range);
 
1131
                      p=PushCharPixel(p,&pixel);
 
1132
                      q->green=ScaleAnyToQuantum(pixel,range);
 
1133
                      p=PushCharPixel(p,&pixel);
 
1134
                      q->blue=ScaleAnyToQuantum(pixel,range);
 
1135
                      q->opacity=OpaqueOpacity;
939
1136
                      if (image->matte != MagickFalse)
940
1137
                        {
941
1138
                          p=PushCharPixel(p,&pixel);
942
 
                          q->opacity=ScaleAnyToQuantum(pixel,image->depth,scale);
 
1139
                          q->opacity=ScaleAnyToQuantum(pixel,range);
943
1140
                        }
944
1141
                      q++;
945
1142
                    }
952
1149
                    for (x=0; x < (long) image->columns; x++)
953
1150
                    {
954
1151
                      p=PushShortPixel(MSBEndian,p,&pixel);
955
 
                      q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
956
 
                      p=PushShortPixel(MSBEndian,p,&pixel);
957
 
                      q->green=ScaleAnyToQuantum(pixel,image->depth,scale);
958
 
                      p=PushShortPixel(MSBEndian,p,&pixel);
959
 
                      q->blue=ScaleAnyToQuantum(pixel,image->depth,scale);
 
1152
                      q->red=ScaleAnyToQuantum(pixel,range);
 
1153
                      p=PushShortPixel(MSBEndian,p,&pixel);
 
1154
                      q->green=ScaleAnyToQuantum(pixel,range);
 
1155
                      p=PushShortPixel(MSBEndian,p,&pixel);
 
1156
                      q->blue=ScaleAnyToQuantum(pixel,range);
 
1157
                      q->opacity=OpaqueOpacity;
960
1158
                      if (image->matte != MagickFalse)
961
1159
                        {
962
1160
                          p=PushShortPixel(MSBEndian,p,&pixel);
963
 
                          q->opacity=ScaleAnyToQuantum(pixel,image->depth,scale);
 
1161
                          q->opacity=ScaleAnyToQuantum(pixel,range);
964
1162
                        }
965
1163
                      q++;
966
1164
                    }
968
1166
                break;
969
1167
              }
970
1168
            }
971
 
          if (SyncImagePixels(image) == MagickFalse)
972
 
            break;
973
 
          if (image->previous == (Image *) NULL)
974
 
            {
975
 
              status=SetImageProgress(image,LoadImageTag,y,image->rows);
976
 
              if (status == MagickFalse)
977
 
                break;
978
 
            }
 
1169
          sync=SyncCacheViewAuthenticPixels(image_view,exception);
 
1170
          if (sync == MagickFalse)
 
1171
            status=MagickFalse;
979
1172
        }
 
1173
        image_view=DestroyCacheView(image_view);
 
1174
        quantum_info=DestroyQuantumInfo(quantum_info);
 
1175
        if (status == MagickFalse)
 
1176
          ThrowReaderException(CorruptImageError,"UnableToReadImageData");
980
1177
        SetQuantumImageType(image,quantum_type);
981
 
        quantum_info=DestroyQuantumInfo(quantum_info);
982
1178
        break;
983
1179
      }
984
1180
      case 'F':
985
1181
      case 'f':
986
1182
      {
987
 
        image->depth=32;
988
 
        quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
989
 
        if (quantum_info == (QuantumInfo *) NULL)
990
 
          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
991
 
        quantum_info->format=FloatingPointQuantumFormat;
992
 
        quantum_info->scale=(MagickRealType) QuantumRange*fabs(quantum_scale);
 
1183
        /*
 
1184
          Convert PFM raster image to pixel packets.
 
1185
        */
993
1186
        quantum_type=format == 'f' ? GrayQuantum : RGBQuantum;
994
1187
        image->endian=quantum_scale < 0.0 ? LSBEndian : MSBEndian;
995
 
        pixels=GetQuantumPixels(quantum_info);
996
 
        length=GetQuantumExtent(image,quantum_info,quantum_type);
997
 
        for (y=(long) image->rows-1; y >= 0; y--)
 
1188
        image->depth=32;
 
1189
        quantum_info=AcquireQuantumInfo(image_info,image);
 
1190
        if (quantum_info == (QuantumInfo *) NULL)
 
1191
          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
 
1192
        status=SetQuantumDepth(image,quantum_info,32);
 
1193
        if (status == MagickFalse)
 
1194
          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
 
1195
        status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);
 
1196
        if (status == MagickFalse)
 
1197
          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
 
1198
        SetQuantumScale(quantum_info,(MagickRealType) QuantumRange*
 
1199
          fabs(quantum_scale));
 
1200
        extent=GetQuantumExtent(image,quantum_info,quantum_type);
 
1201
        image_view=AcquireCacheView(image);
 
1202
#if defined(MAGICKCORE_OPENMP_SUPPORT)
 
1203
  #pragma omp parallel for schedule(dynamic,1) shared(row,status,quantum_type)
 
1204
#endif
 
1205
        for (y=0; y < (long) image->rows; y++)
998
1206
        {
999
 
          q=SetImagePixels(image,0,y,image->columns,1);
 
1207
          long
 
1208
            offset;
 
1209
 
 
1210
          MagickBooleanType
 
1211
            sync;
 
1212
 
 
1213
          register PixelPacket
 
1214
            *q;
 
1215
 
 
1216
          ssize_t
 
1217
            count;
 
1218
 
 
1219
          size_t
 
1220
            length;
 
1221
 
 
1222
          unsigned char
 
1223
            *pixels;
 
1224
 
 
1225
          if (status == MagickFalse)
 
1226
            continue;
 
1227
          pixels=GetQuantumPixels(quantum_info);
 
1228
#if defined(MAGICKCORE_OPENMP_SUPPORT)
 
1229
          #pragma omp critical (MagickCore_ReadPNMImage)
 
1230
#endif
 
1231
          {
 
1232
            count=ReadBlob(image,extent,pixels);
 
1233
            if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
 
1234
                (image->previous == (Image *) NULL))
 
1235
              {
 
1236
                MagickBooleanType
 
1237
                  proceed;
 
1238
 
 
1239
                proceed=SetImageProgress(image,LoadImageTag,row,image->rows);
 
1240
                if (proceed == MagickFalse)
 
1241
                  status=MagickFalse;
 
1242
              }
 
1243
            offset=row++;
 
1244
          }
 
1245
          if ((size_t) count != extent)
 
1246
            status=MagickFalse;
 
1247
          q=QueueCacheViewAuthenticPixels(image_view,0,(long) (image->rows-
 
1248
            offset-1),image->columns,1,exception);
1000
1249
          if (q == (PixelPacket *) NULL)
1001
 
            break;
1002
 
          count=ReadBlob(image,length,pixels);
1003
 
          if ((size_t) count != length)
1004
 
            break;
1005
 
          length=ImportQuantumPixels(image,quantum_info,quantum_type,pixels);
1006
 
          if (count != (ssize_t) length)
1007
 
            ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1008
 
          if (SyncImagePixels(image) == MagickFalse)
1009
 
            break;
1010
 
          if (image->previous == (Image *) NULL)
1011
1250
            {
1012
 
              status=SetImageProgress(image,LoadImageTag,y,image->rows);
1013
 
              if (status == MagickFalse)
1014
 
                break;
 
1251
              status=MagickFalse;
 
1252
              continue;
1015
1253
            }
 
1254
          length=ImportQuantumPixels(image,image_view,quantum_info,quantum_type,
 
1255
            pixels,exception);
 
1256
          if (length != extent)
 
1257
            status=MagickFalse;
 
1258
          sync=SyncCacheViewAuthenticPixels(image_view,exception);
 
1259
          if (sync == MagickFalse)
 
1260
            status=MagickFalse;
1016
1261
        }
 
1262
        image_view=DestroyCacheView(image_view);
 
1263
        quantum_info=DestroyQuantumInfo(quantum_info);
 
1264
        if (status == MagickFalse)
 
1265
          ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1017
1266
        SetQuantumImageType(image,quantum_type);
1018
 
        quantum_info=DestroyQuantumInfo(quantum_info);
1019
1267
        break;
1020
1268
      }
1021
1269
      default:
1217
1465
  QuantumType
1218
1466
    quantum_type;
1219
1467
 
 
1468
  register const IndexPacket
 
1469
    *indexes;
 
1470
 
1220
1471
  register const PixelPacket
1221
1472
    *p;
1222
1473
 
1223
 
  register IndexPacket
1224
 
    *indexes;
1225
 
 
1226
1474
  register long
1227
1475
    i,
1228
1476
    x;
1235
1483
    count;
1236
1484
 
1237
1485
  size_t
1238
 
    length,
 
1486
    extent,
1239
1487
    packet_size;
1240
1488
 
1241
1489
  /*
1378
1626
          default:
1379
1627
          {
1380
1628
            quantum_type=RGBQuantum;
 
1629
            if (image->matte != MagickFalse)
 
1630
              quantum_type=RGBAQuantum;
1381
1631
            packet_size=3;
1382
1632
            (void) CopyMagickString(type,"RGB",MaxTextExtent);
1383
1633
            break;
1399
1649
        (void) WriteBlobString(image,buffer);
1400
1650
      }
1401
1651
    /*
1402
 
      Convert runlength encoded to PNM raster pixels.
 
1652
      Convert runextent encoded to PNM raster pixels.
1403
1653
    */
1404
1654
    switch (format)
1405
1655
    {
1414
1664
        q=pixels;
1415
1665
        for (y=0; y < (long) image->rows; y++)
1416
1666
        {
1417
 
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
1667
          p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1418
1668
          if (p == (const PixelPacket *) NULL)
1419
1669
            break;
1420
 
          indexes=GetIndexes(image);
 
1670
          indexes=GetVirtualIndexQueue(image);
1421
1671
          for (x=0; x < (long) image->columns; x++)
1422
1672
          {
1423
1673
            pixel=PixelIntensityToQuantum(p);
1462
1712
        q=pixels;
1463
1713
        for (y=0; y < (long) image->rows; y++)
1464
1714
        {
1465
 
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
1715
          p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1466
1716
          if (p == (const PixelPacket *) NULL)
1467
1717
            break;
1468
1718
          for (x=0; x < (long) image->columns; x++)
1474
1724
            else
1475
1725
              count=(ssize_t) FormatMagickString(buffer,MaxTextExtent,"%u ",
1476
1726
                ScaleQuantumToShort(index));
1477
 
            length=(size_t) count;
1478
 
            (void) strncpy((char *) q,buffer,length);
1479
 
            q+=length;
1480
 
            if ((q-pixels+length) >= 80)
 
1727
            extent=(size_t) count;
 
1728
            (void) strncpy((char *) q,buffer,extent);
 
1729
            q+=extent;
 
1730
            if ((q-pixels+extent) >= 80)
1481
1731
              {
1482
1732
                *q++='\n';
1483
1733
                (void) WriteBlob(image,q-pixels,pixels);
1514
1764
        q=pixels;
1515
1765
        for (y=0; y < (long) image->rows; y++)
1516
1766
        {
1517
 
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
1767
          p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1518
1768
          if (p == (const PixelPacket *) NULL)
1519
1769
            break;
1520
1770
          for (x=0; x < (long) image->columns; x++)
1527
1777
              count=(ssize_t) FormatMagickString(buffer,MaxTextExtent,
1528
1778
                "%u %u %u ",ScaleQuantumToShort(p->red),
1529
1779
                ScaleQuantumToShort(p->green),ScaleQuantumToShort(p->blue));
1530
 
            length=(size_t) count;
1531
 
            (void) strncpy((char *) q,buffer,length);
1532
 
            q+=length;
1533
 
            if ((q-pixels+length) >= 80)
 
1780
            extent=(size_t) count;
 
1781
            (void) strncpy((char *) q,buffer,extent);
 
1782
            q+=extent;
 
1783
            if ((q-pixels+extent) >= 80)
1534
1784
              {
1535
1785
                *q++='\n';
1536
1786
                (void) WriteBlob(image,q-pixels,pixels);
1565
1815
        pixels=GetQuantumPixels(quantum_info);
1566
1816
        for (y=0; y < (long) image->rows; y++)
1567
1817
        {
1568
 
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
1818
          p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1569
1819
          if (p == (const PixelPacket *) NULL)
1570
1820
            break;
1571
 
          length=ExportQuantumPixels(image,quantum_info,GrayQuantum,pixels);
1572
 
          count=WriteBlob(image,length,pixels);
1573
 
          if (count != (ssize_t) length)
 
1821
          extent=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
 
1822
            GrayQuantum,pixels,&image->exception);
 
1823
          count=WriteBlob(image,extent,pixels);
 
1824
          if (count != (ssize_t) extent)
1574
1825
            break;
1575
1826
          if (image->previous == (Image *) NULL)
1576
1827
            {
1585
1836
      case '5':
1586
1837
      {
1587
1838
        QuantumAny
1588
 
          scale;
 
1839
          range;
1589
1840
 
1590
1841
        /*
1591
1842
          Convert image to a PGM image.
1600
1851
          ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1601
1852
        quantum_info->min_is_white=MagickTrue;
1602
1853
        pixels=GetQuantumPixels(quantum_info);
1603
 
        length=GetQuantumExtent(image,quantum_info,GrayQuantum);
1604
 
        scale=GetQuantumScale(image->depth);
 
1854
        extent=GetQuantumExtent(image,quantum_info,GrayQuantum);
 
1855
        range=GetQuantumRange(image->depth);
1605
1856
        for (y=0; y < (long) image->rows; y++)
1606
1857
        {
1607
 
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
1858
          p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1608
1859
          if (p == (const PixelPacket *) NULL)
1609
1860
            break;
1610
1861
          q=pixels;
1611
1862
          if ((image->depth == 8) || (image->depth == 16))
1612
 
            length=ExportQuantumPixels(image,quantum_info,GrayQuantum,pixels);
 
1863
            extent=ExportQuantumPixels(image,(const ViewInfo *) NULL,
 
1864
              quantum_info,GrayQuantum,pixels,&image->exception);
1613
1865
          else
1614
1866
            {
1615
1867
              if (image->depth <= 8)
1616
1868
                for (x=0; x < (long) image->columns; x++)
1617
1869
                {
1618
1870
                  if (IsGrayPixel(p) == MagickFalse)
1619
 
                    pixel=ScaleQuantumToAny(PixelIntensityToQuantum(p),
1620
 
                      image->depth,scale);
 
1871
                    pixel=ScaleQuantumToAny(PixelIntensityToQuantum(p),range);
1621
1872
                  else
1622
1873
                    {
1623
1874
                      if (image->depth == 8)
1624
1875
                        pixel=ScaleQuantumToChar(p->red);
1625
1876
                      else
1626
 
                        pixel=ScaleQuantumToAny(p->red,image->depth,scale);
 
1877
                        pixel=ScaleQuantumToAny(p->red,range);
1627
1878
                    }
1628
1879
                  q=PopCharPixel((unsigned char) pixel,q);
1629
1880
                  p++;
1632
1883
                for (x=0; x < (long) image->columns; x++)
1633
1884
                {
1634
1885
                  if (IsGrayPixel(p) == MagickFalse)
1635
 
                    pixel=ScaleQuantumToAny(PixelIntensityToQuantum(p),
1636
 
                      image->depth,scale);
 
1886
                    pixel=ScaleQuantumToAny(PixelIntensityToQuantum(p),range);
1637
1887
                  else
1638
1888
                    {
1639
1889
                      if (image->depth == 16)
1640
1890
                        pixel=ScaleQuantumToShort(p->red);
1641
1891
                      else
1642
 
                        pixel=ScaleQuantumToAny(p->red,image->depth,scale);
 
1892
                        pixel=ScaleQuantumToAny(p->red,range);
1643
1893
                    }
1644
1894
                  q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1645
1895
                  p++;
1646
1896
                }
1647
 
              length=(size_t) (q-pixels);
 
1897
              extent=(size_t) (q-pixels);
1648
1898
            }
1649
 
          count=WriteBlob(image,length,pixels);
1650
 
          if (count != (ssize_t) length)
 
1899
          count=WriteBlob(image,extent,pixels);
 
1900
          if (count != (ssize_t) extent)
1651
1901
            break;
1652
1902
          if (image->previous == (Image *) NULL)
1653
1903
            {
1662
1912
      case '6':
1663
1913
      {
1664
1914
        QuantumAny
1665
 
          scale;
 
1915
          range;
1666
1916
 
1667
1917
        /*
1668
1918
          Convert image to a PNM image.
1676
1926
        if (quantum_info == (QuantumInfo *) NULL)
1677
1927
          ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1678
1928
        pixels=GetQuantumPixels(quantum_info);
1679
 
        length=GetQuantumExtent(image,quantum_info,quantum_type);
1680
 
        scale=GetQuantumScale(image->depth);
 
1929
        extent=GetQuantumExtent(image,quantum_info,quantum_type);
 
1930
        range=GetQuantumRange(image->depth);
1681
1931
        for (y=0; y < (long) image->rows; y++)
1682
1932
        {
1683
 
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
1933
          p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1684
1934
          if (p == (const PixelPacket *) NULL)
1685
1935
            break;
1686
1936
          q=pixels;
1687
1937
          if ((image->depth == 8) || (image->depth == 16))
1688
 
            length=ExportQuantumPixels(image,quantum_info,quantum_type,pixels);
 
1938
            extent=ExportQuantumPixels(image,(const ViewInfo *) NULL,
 
1939
              quantum_info,quantum_type,pixels,&image->exception);
1689
1940
          else
1690
1941
            {
1691
1942
              if (image->depth <= 8)
1692
1943
                for (x=0; x < (long) image->columns; x++)
1693
1944
                {
1694
 
                  pixel=ScaleQuantumToAny(p->red,image->depth,scale);
1695
 
                  q=PopCharPixel((unsigned char) pixel,q);
1696
 
                  pixel=ScaleQuantumToAny(p->green,image->depth,scale);
1697
 
                  q=PopCharPixel((unsigned char) pixel,q);
1698
 
                  pixel=ScaleQuantumToAny(p->blue,image->depth,scale);
 
1945
                  pixel=ScaleQuantumToAny(p->red,range);
 
1946
                  q=PopCharPixel((unsigned char) pixel,q);
 
1947
                  pixel=ScaleQuantumToAny(p->green,range);
 
1948
                  q=PopCharPixel((unsigned char) pixel,q);
 
1949
                  pixel=ScaleQuantumToAny(p->blue,range);
1699
1950
                  q=PopCharPixel((unsigned char) pixel,q);
1700
1951
                  if (image->matte != MagickFalse)
1701
1952
                    {
1702
1953
                      pixel=ScaleQuantumToAny((Quantum) (QuantumRange-
1703
 
                        p->opacity),image->depth,scale);
 
1954
                        p->opacity),range);
1704
1955
                      q=PopCharPixel((unsigned char) pixel,q);
1705
1956
                    }
1706
1957
                  p++;
1708
1959
              else
1709
1960
                for (x=0; x < (long) image->columns; x++)
1710
1961
                {
1711
 
                  pixel=ScaleQuantumToAny(p->red,image->depth,scale);
1712
 
                  q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1713
 
                  pixel=ScaleQuantumToAny(p->green,image->depth,scale);
1714
 
                  q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1715
 
                  pixel=ScaleQuantumToAny(p->blue,image->depth,scale);
 
1962
                  pixel=ScaleQuantumToAny(p->red,range);
 
1963
                  q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
 
1964
                  pixel=ScaleQuantumToAny(p->green,range);
 
1965
                  q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
 
1966
                  pixel=ScaleQuantumToAny(p->blue,range);
1716
1967
                  q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1717
1968
                  if (image->matte != MagickFalse)
1718
1969
                    {
1719
1970
                      pixel=ScaleQuantumToAny((Quantum) (QuantumRange-
1720
 
                        p->opacity),image->depth,scale);
 
1971
                        p->opacity),range);
1721
1972
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1722
1973
                    }
1723
1974
                  p++;
1724
1975
                }
1725
 
              length=(size_t) (q-pixels);
 
1976
              extent=(size_t) (q-pixels);
1726
1977
            }
1727
 
          count=WriteBlob(image,length,pixels);
1728
 
          if (count != (ssize_t) length)
 
1978
          count=WriteBlob(image,extent,pixels);
 
1979
          if (count != (ssize_t) extent)
1729
1980
            break;
1730
1981
          if (image->previous == (Image *) NULL)
1731
1982
            {
1740
1991
      case '7':
1741
1992
      {
1742
1993
        QuantumAny
1743
 
          scale;
 
1994
          range;
1744
1995
 
1745
1996
        /*
1746
1997
          Convert image to a PAM.
1750
2001
        quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
1751
2002
        if ((quantum_info->format == UndefinedQuantumFormat) &&
1752
2003
            (IsHighDynamicRangeImage(image,&image->exception) != MagickFalse))
1753
 
          (void) SetQuantumFormat(image,FloatingPointQuantumFormat,quantum_info);
 
2004
          {
 
2005
            status=SetQuantumFormat(image,quantum_info,
 
2006
              FloatingPointQuantumFormat);
 
2007
            if (status == MagickFalse)
 
2008
              ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
 
2009
          }
1754
2010
        pixels=GetQuantumPixels(quantum_info);
1755
 
        scale=GetQuantumScale(image->depth);
 
2011
        range=GetQuantumRange(image->depth);
1756
2012
        for (y=0; y < (long) image->rows; y++)
1757
2013
        {
1758
 
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
2014
          p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1759
2015
          if (p == (const PixelPacket *) NULL)
1760
2016
            break;
1761
 
          indexes=GetIndexes(image);
 
2017
          indexes=GetVirtualIndexQueue(image);
1762
2018
          q=pixels;
1763
2019
          if ((image->depth == 8) || (image->depth == 16))
1764
 
            length=ExportQuantumPixels(image,quantum_info,quantum_type,pixels);
 
2020
            extent=ExportQuantumPixels(image,(const ViewInfo *) NULL,
 
2021
              quantum_info,quantum_type,pixels,&image->exception);
1765
2022
          else
1766
2023
            {
1767
2024
              switch (quantum_type)
1772
2029
                  if (image->depth <= 8)
1773
2030
                    for (x=0; x < (long) image->columns; x++)
1774
2031
                    {
1775
 
                      pixel=ScaleQuantumToAny(PixelIntensityToQuantum(p),
1776
 
                        image->depth,scale);
 
2032
                      pixel=ScaleQuantumToAny(PixelIntensityToQuantum(p),range);
1777
2033
                      q=PopCharPixel((unsigned char) pixel,q);
1778
2034
                      if (image->matte != MagickFalse)
1779
2035
                        {
1780
2036
                          pixel=(unsigned char) ScaleQuantumToAny(p->opacity,
1781
 
                            image->depth,scale);
 
2037
                            range);
1782
2038
                          q=PopCharPixel((unsigned char) pixel,q);
1783
2039
                        }
1784
2040
                      p++;
1786
2042
                  else
1787
2043
                    for (x=0; x < (long) image->columns; x++)
1788
2044
                    {
1789
 
                      pixel=ScaleQuantumToAny(PixelIntensityToQuantum(p),
1790
 
                        image->depth,scale);
 
2045
                      pixel=ScaleQuantumToAny(PixelIntensityToQuantum(p),range);
1791
2046
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1792
2047
                      if (image->matte != MagickFalse)
1793
2048
                        {
1794
2049
                          pixel=(unsigned char) ScaleQuantumToAny(p->opacity,
1795
 
                            image->depth,scale);
 
2050
                            range);
1796
2051
                          q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1797
2052
                        }
1798
2053
                      p++;
1805
2060
                  if (image->depth <= 8)
1806
2061
                    for (x=0; x < (long) image->columns; x++)
1807
2062
                    {
1808
 
                      pixel=ScaleQuantumToAny(p->red,image->depth,scale);
1809
 
                      q=PopCharPixel((unsigned char) pixel,q);
1810
 
                      pixel=ScaleQuantumToAny(p->green,image->depth,scale);
1811
 
                      q=PopCharPixel((unsigned char) pixel,q);
1812
 
                      pixel=ScaleQuantumToAny(p->blue,image->depth,scale);
1813
 
                      q=PopCharPixel((unsigned char) pixel,q);
1814
 
                      pixel=ScaleQuantumToAny(indexes[x],image->depth,scale);
 
2063
                      pixel=ScaleQuantumToAny(p->red,range);
 
2064
                      q=PopCharPixel((unsigned char) pixel,q);
 
2065
                      pixel=ScaleQuantumToAny(p->green,range);
 
2066
                      q=PopCharPixel((unsigned char) pixel,q);
 
2067
                      pixel=ScaleQuantumToAny(p->blue,range);
 
2068
                      q=PopCharPixel((unsigned char) pixel,q);
 
2069
                      pixel=ScaleQuantumToAny(indexes[x],range);
1815
2070
                      q=PopCharPixel((unsigned char) pixel,q);
1816
2071
                      if (image->matte != MagickFalse)
1817
2072
                        {
1818
2073
                          pixel=ScaleQuantumToAny((Quantum) (QuantumRange-
1819
 
                            p->opacity),image->depth,scale);
 
2074
                            p->opacity),range);
1820
2075
                          q=PopCharPixel((unsigned char) pixel,q);
1821
2076
                        }
1822
2077
                      p++;
1824
2079
                  else
1825
2080
                    for (x=0; x < (long) image->columns; x++)
1826
2081
                    {
1827
 
                      pixel=ScaleQuantumToAny(p->red,image->depth,scale);
1828
 
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1829
 
                      pixel=ScaleQuantumToAny(p->green,image->depth,scale);
1830
 
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1831
 
                      pixel=ScaleQuantumToAny(p->blue,image->depth,scale);
1832
 
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1833
 
                      pixel=ScaleQuantumToAny(indexes[x],image->depth,scale);
 
2082
                      pixel=ScaleQuantumToAny(p->red,range);
 
2083
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
 
2084
                      pixel=ScaleQuantumToAny(p->green,range);
 
2085
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
 
2086
                      pixel=ScaleQuantumToAny(p->blue,range);
 
2087
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
 
2088
                      pixel=ScaleQuantumToAny(indexes[x],range);
1834
2089
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1835
2090
                      if (image->matte != MagickFalse)
1836
2091
                        {
1837
2092
                          pixel=ScaleQuantumToAny((Quantum) (QuantumRange-
1838
 
                            p->opacity),image->depth,scale);
 
2093
                            p->opacity),range);
1839
2094
                          q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1840
2095
                        }
1841
2096
                      p++;
1847
2102
                  if (image->depth <= 8)
1848
2103
                    for (x=0; x < (long) image->columns; x++)
1849
2104
                    {
1850
 
                      pixel=ScaleQuantumToAny(p->red,image->depth,scale);
1851
 
                      q=PopCharPixel((unsigned char) pixel,q);
1852
 
                      pixel=ScaleQuantumToAny(p->green,image->depth,scale);
1853
 
                      q=PopCharPixel((unsigned char) pixel,q);
1854
 
                      pixel=ScaleQuantumToAny(p->blue,image->depth,scale);
 
2105
                      pixel=ScaleQuantumToAny(p->red,range);
 
2106
                      q=PopCharPixel((unsigned char) pixel,q);
 
2107
                      pixel=ScaleQuantumToAny(p->green,range);
 
2108
                      q=PopCharPixel((unsigned char) pixel,q);
 
2109
                      pixel=ScaleQuantumToAny(p->blue,range);
1855
2110
                      q=PopCharPixel((unsigned char) pixel,q);
1856
2111
                      if (image->matte != MagickFalse)
1857
2112
                        {
1858
2113
                          pixel=ScaleQuantumToAny((Quantum) (QuantumRange-
1859
 
                            p->opacity),image->depth,scale);
 
2114
                            p->opacity),range);
1860
2115
                          q=PopCharPixel((unsigned char) pixel,q);
1861
2116
                        }
1862
2117
                      p++;
1864
2119
                  else
1865
2120
                    for (x=0; x < (long) image->columns; x++)
1866
2121
                    {
1867
 
                      pixel=ScaleQuantumToAny(p->red,image->depth,scale);
1868
 
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1869
 
                      pixel=ScaleQuantumToAny(p->green,image->depth,scale);
1870
 
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1871
 
                      pixel=ScaleQuantumToAny(p->blue,image->depth,scale);
 
2122
                      pixel=ScaleQuantumToAny(p->red,range);
 
2123
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
 
2124
                      pixel=ScaleQuantumToAny(p->green,range);
 
2125
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
 
2126
                      pixel=ScaleQuantumToAny(p->blue,range);
1872
2127
                      q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1873
2128
                      if (image->matte != MagickFalse)
1874
2129
                        {
1875
2130
                          pixel=ScaleQuantumToAny((Quantum) (QuantumRange-
1876
 
                            p->opacity),image->depth,scale);
 
2131
                            p->opacity),range);
1877
2132
                          q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
1878
2133
                        }
1879
2134
                      p++;
1881
2136
                  break;
1882
2137
                }
1883
2138
              }
1884
 
              length=(size_t) (q-pixels);
 
2139
              extent=(size_t) (q-pixels);
1885
2140
            }
1886
 
          count=WriteBlob(image,length,pixels);
1887
 
          if (count != (ssize_t) length)
 
2141
          count=WriteBlob(image,extent,pixels);
 
2142
          if (count != (ssize_t) extent)
1888
2143
            break;
1889
2144
          if (image->previous == (Image *) NULL)
1890
2145
            {
1906
2161
        quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
1907
2162
        if (quantum_info == (QuantumInfo *) NULL)
1908
2163
          ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1909
 
        (void) SetQuantumFormat(image,FloatingPointQuantumFormat,quantum_info);
 
2164
        status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);
 
2165
        if (status == MagickFalse)
 
2166
          ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1910
2167
        pixels=GetQuantumPixels(quantum_info);
1911
2168
        for (y=(long) image->rows-1; y >= 0; y--)
1912
2169
        {
1913
 
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
2170
          p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1914
2171
          if (p == (const PixelPacket *) NULL)
1915
2172
            break;
1916
 
          length=ExportQuantumPixels(image,quantum_info,quantum_type,pixels);
1917
 
          (void) WriteBlob(image,length,pixels);
 
2173
          extent=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
 
2174
            quantum_type,pixels,&image->exception);
 
2175
          (void) WriteBlob(image,extent,pixels);
1918
2176
          if (image->previous == (Image *) NULL)
1919
2177
            {
1920
2178
              status=SetImageProgress(image,SaveImageTag,y,image->rows);