X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=coders%2Fpnm.c;h=91d67f33479193924e38bd93b521b27b6234d443;hb=2ea2cbfa1006eeda0d230955f9933062065b6aa1;hp=4ce534ff3d20464901685c93c7dd35c42e6779a9;hpb=375dc4b69fcf35155562f849783b01e31f3b4408;p=imagemagick diff --git a/coders/pnm.c b/coders/pnm.c index 4ce534ff3..91d67f334 100644 --- a/coders/pnm.c +++ b/coders/pnm.c @@ -134,10 +134,10 @@ static MagickBooleanType IsPNM(const unsigned char *magick,const size_t extent) % */ -static inline long ConstrainPixel(Image *image,const long offset, - const unsigned long extent) +static inline ssize_t ConstrainPixel(Image *image,const ssize_t offset, + const size_t extent) { - if ((offset < 0) || (offset > (long) extent)) + if ((offset < 0) || (offset > (ssize_t) extent)) { (void) ThrowMagickException(&image->exception,GetMagickModule(), CorruptImageError,"InvalidPixel","`%s'",image->filename); @@ -146,7 +146,7 @@ static inline long ConstrainPixel(Image *image,const long offset, return(offset); } -static unsigned long PNMInteger(Image *image,const unsigned int base) +static size_t PNMInteger(Image *image,const unsigned int base) { char *comment; @@ -160,7 +160,7 @@ static unsigned long PNMInteger(Image *image,const unsigned int base) size_t extent; - unsigned long + size_t value; /* @@ -208,7 +208,7 @@ static unsigned long PNMInteger(Image *image,const unsigned int base) comment=DestroyString(comment); } if (base == 2) - return((unsigned long) (c-(int) '0')); + return((size_t) (c-(int) '0')); /* Evaluate number. */ @@ -235,7 +235,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) Image *image; - long + ssize_t row, y; @@ -251,7 +251,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) QuantumType quantum_type; - register long + register ssize_t i; size_t @@ -261,13 +261,10 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) ssize_t count; - unsigned long + size_t depth, max_value; - CacheView - *image_view; - /* Open image file. */ @@ -429,9 +426,9 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) /* Convert PBM image to pixel packets. */ - for (y=0; y < (long) image->rows; y++) + for (y=0; y < (ssize_t) image->rows; y++) { - register long + register ssize_t x; register PixelPacket @@ -440,7 +437,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (PixelPacket *) NULL) break; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { q->red=(Quantum) (PNMInteger(image,2) == 0 ? QuantumRange : 0); q->green=q->red; @@ -451,7 +448,8 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) break; if (image->previous == (Image *) NULL) { - status=SetImageProgress(image,LoadImageTag,y,image->rows); + status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, + image->rows); if (status == MagickFalse) break; } @@ -461,7 +459,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) } case '2': { - unsigned long + size_t intensity; /* @@ -477,12 +475,12 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) sizeof(*scale)); if (scale == (Quantum *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - for (i=0; i <= (long) max_value; i++) + for (i=0; i <= (ssize_t) max_value; i++) scale[i]=(Quantum) (((double) QuantumRange*i)/max_value+0.5); } - for (y=0; y < (long) image->rows; y++) + for (y=0; y < (ssize_t) image->rows; y++) { - register long + register ssize_t x; register PixelPacket @@ -491,13 +489,12 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (PixelPacket *) NULL) break; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { intensity=PNMInteger(image,10); - if (scale != (Quantum *) NULL) - intensity=(unsigned long) scale[ConstrainPixel(image,(long) - intensity,max_value)]; q->red=(Quantum) intensity; + if (scale != (Quantum *) NULL) + q->red=scale[ConstrainPixel(image,(ssize_t) intensity,max_value)]; q->green=q->red; q->blue=q->red; q++; @@ -506,7 +503,8 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) break; if (image->previous == (Image *) NULL) { - status=SetImageProgress(image,LoadImageTag,y,image->rows); + status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, + image->rows); if (status == MagickFalse) break; } @@ -534,12 +532,12 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) sizeof(*scale)); if (scale == (Quantum *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - for (i=0; i <= (long) max_value; i++) + for (i=0; i <= (ssize_t) max_value; i++) scale[i]=(Quantum) (((double) QuantumRange*i)/max_value+0.5); } - for (y=0; y < (long) image->rows; y++) + for (y=0; y < (ssize_t) image->rows; y++) { - register long + register ssize_t x; register PixelPacket @@ -548,18 +546,18 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (PixelPacket *) NULL) break; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { pixel.red=(MagickRealType) PNMInteger(image,10); pixel.green=(MagickRealType) PNMInteger(image,10); pixel.blue=(MagickRealType) PNMInteger(image,10); if (scale != (Quantum *) NULL) { - pixel.red=(MagickRealType) scale[ConstrainPixel(image,(long) + pixel.red=(MagickRealType) scale[ConstrainPixel(image,(ssize_t) pixel.red,max_value)]; - pixel.green=(MagickRealType) scale[ConstrainPixel(image,(long) + pixel.green=(MagickRealType) scale[ConstrainPixel(image,(ssize_t) pixel.green,max_value)]; - pixel.blue=(MagickRealType) scale[ConstrainPixel(image,(long) + pixel.blue=(MagickRealType) scale[ConstrainPixel(image,(ssize_t) pixel.blue,max_value)]; } q->red=(Quantum) pixel.red; @@ -571,7 +569,8 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) break; if (image->previous == (Image *) NULL) { - status=SetImageProgress(image,LoadImageTag,y,image->rows); + status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, + image->rows); if (status == MagickFalse) break; } @@ -593,13 +592,9 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); SetQuantumMinIsWhite(quantum_info,MagickTrue); extent=GetQuantumExtent(image,quantum_info,quantum_type); - image_view=AcquireCacheView(image); -#if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505) - #pragma omp parallel for schedule(static,1) shared(row,status,quantum_type) -#endif - for (y=0; y < (long) image->rows; y++) + for (y=0; y < (ssize_t) image->rows; y++) { - long + ssize_t offset; MagickBooleanType @@ -620,9 +615,6 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) if (status == MagickFalse) continue; pixels=GetQuantumPixels(quantum_info); -#if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505) - #pragma omp critical (MagickCore_ReadPNMImage) -#endif { count=ReadBlob(image,extent,pixels); if ((image->progress_monitor != (MagickProgressMonitor) NULL) && @@ -631,7 +623,8 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) MagickBooleanType proceed; - proceed=SetImageProgress(image,LoadImageTag,row,image->rows); + proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) + row,image->rows); if (proceed == MagickFalse) status=MagickFalse; } @@ -639,22 +632,20 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) } if (count != (ssize_t) extent) status=MagickFalse; - q=QueueCacheViewAuthenticPixels(image_view,0,offset,image->columns,1, - exception); + q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); if (q == (PixelPacket *) NULL) { status=MagickFalse; continue; } - length=ImportQuantumPixels(image,image_view,quantum_info,quantum_type, - pixels,exception); + length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, + quantum_type,pixels,exception); if (length != extent) status=MagickFalse; - sync=SyncCacheViewAuthenticPixels(image_view,exception); + sync=SyncAuthenticPixels(image,exception); if (sync == MagickFalse) status=MagickFalse; } - image_view=DestroyCacheView(image_view); quantum_info=DestroyQuantumInfo(quantum_info); if (status == MagickFalse) ThrowReaderException(CorruptImageError,"UnableToReadImageData"); @@ -675,22 +666,18 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) quantum_info=AcquireQuantumInfo(image_info,image); if (quantum_info == (QuantumInfo *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - image_view=AcquireCacheView(image); -#if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505) - #pragma omp parallel for schedule(static,1) shared(row,status,quantum_type) -#endif - for (y=0; y < (long) image->rows; y++) + for (y=0; y < (ssize_t) image->rows; y++) { - long + ssize_t offset; MagickBooleanType sync; register const unsigned char - *p; + *restrict p; - register long + register ssize_t x; register PixelPacket @@ -705,9 +692,6 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) if (status == MagickFalse) continue; pixels=GetQuantumPixels(quantum_info); -#if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505) - #pragma omp critical (MagickCore_ReadPNMImage) -#endif { count=ReadBlob(image,extent,pixels); if ((image->progress_monitor != (MagickProgressMonitor) NULL) && @@ -716,7 +700,8 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) MagickBooleanType proceed; - proceed=SetImageProgress(image,LoadImageTag,row,image->rows); + proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row, + image->rows); if (proceed == MagickFalse) status=MagickFalse; } @@ -724,8 +709,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) } if (count != (ssize_t) extent) status=MagickFalse; - q=QueueCacheViewAuthenticPixels(image_view,0,offset,image->columns,1, - exception); + q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); if (q == (PixelPacket *) NULL) { status=MagickFalse; @@ -733,7 +717,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) } p=pixels; if ((image->depth == 8) || (image->depth == 16)) - (void) ImportQuantumPixels(image,image_view,quantum_info, + (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, quantum_type,pixels,exception); else if (image->depth <= 8) @@ -741,7 +725,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) unsigned char pixel; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { p=PushCharPixel(p,&pixel); SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range)); @@ -755,7 +739,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) unsigned short pixel; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { p=PushShortPixel(MSBEndian,p,&pixel); SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range)); @@ -764,11 +748,10 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) q++; } } - sync=SyncCacheViewAuthenticPixels(image_view,exception); + sync=SyncAuthenticPixels(image,exception); if (sync == MagickFalse) status=MagickFalse; } - image_view=DestroyCacheView(image_view); quantum_info=DestroyQuantumInfo(quantum_info); if (status == MagickFalse) ThrowReaderException(CorruptImageError,"UnableToReadImageData"); @@ -793,22 +776,18 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) quantum_info=AcquireQuantumInfo(image_info,image); if (quantum_info == (QuantumInfo *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - image_view=AcquireCacheView(image); -#if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505) - #pragma omp parallel for schedule(static,1) shared(row,status,type) -#endif - for (y=0; y < (long) image->rows; y++) + for (y=0; y < (ssize_t) image->rows; y++) { - long + ssize_t offset; MagickBooleanType sync; register const unsigned char - *p; + *restrict p; - register long + register ssize_t x; register PixelPacket @@ -817,18 +796,12 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) ssize_t count; - size_t - length; - unsigned char *pixels; if (status == MagickFalse) continue; pixels=GetQuantumPixels(quantum_info); -#if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505) - #pragma omp critical (MagickCore_ReadPNMImage) -#endif { count=ReadBlob(image,extent,pixels); if ((image->progress_monitor != (MagickProgressMonitor) NULL) && @@ -837,7 +810,8 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) MagickBooleanType proceed; - proceed=SetImageProgress(image,LoadImageTag,row,image->rows); + proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row, + image->rows); if (proceed == MagickFalse) status=MagickFalse; } @@ -845,80 +819,95 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) } if (count != (ssize_t) extent) status=MagickFalse; - q=QueueCacheViewAuthenticPixels(image_view,0,offset,image->columns,1, - exception); + q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); if (q == (PixelPacket *) NULL) { status=MagickFalse; continue; } p=pixels; - if ((image->depth == 8) || (image->depth == 16)) + if (image->depth == 8) + for (x=0; x < (ssize_t) image->columns; x++) { - length=ImportQuantumPixels(image,image_view,quantum_info, - quantum_type,pixels,exception); - if (length != extent) - status=MagickFalse; + q->red=ScaleCharToQuantum(*p++); + q->green=ScaleCharToQuantum(*p++); + q->blue=ScaleCharToQuantum(*p++); + q->opacity=OpaqueOpacity; + q++; } else - if (image->depth <= 8) - { - unsigned char - pixel; - - register PixelPacket - *restrict r; - - r=q; - for (x=0; x < (long) image->columns; x++) - { - p=PushCharPixel(p,&pixel); - r->red=ScaleAnyToQuantum(pixel,range); - p=PushCharPixel(p,&pixel); - r->green=ScaleAnyToQuantum(pixel,range); - p=PushCharPixel(p,&pixel); - r->blue=ScaleAnyToQuantum(pixel,range); - r++; - } - } - else + if (image->depth == 16) { unsigned short pixel; - register PixelPacket - *restrict r; - - r=q; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { p=PushShortPixel(MSBEndian,p,&pixel); - r->red=ScaleAnyToQuantum(pixel,range); + q->red=ScaleShortToQuantum(pixel); p=PushShortPixel(MSBEndian,p,&pixel); - r->green=ScaleAnyToQuantum(pixel,range); + q->green=ScaleShortToQuantum(pixel); p=PushShortPixel(MSBEndian,p,&pixel); - r->blue=ScaleAnyToQuantum(pixel,range); - r++; + q->blue=ScaleShortToQuantum(pixel); + q->opacity=OpaqueOpacity; + q++; } } + else + if (image->depth <= 8) + { + unsigned char + pixel; + + for (x=0; x < (ssize_t) image->columns; x++) + { + p=PushCharPixel(p,&pixel); + q->red=ScaleAnyToQuantum(pixel,range); + p=PushCharPixel(p,&pixel); + q->green=ScaleAnyToQuantum(pixel,range); + p=PushCharPixel(p,&pixel); + q->blue=ScaleAnyToQuantum(pixel,range); + q->opacity=OpaqueOpacity; + q++; + } + } + else + { + unsigned short + pixel; + + for (x=0; x < (ssize_t) image->columns; x++) + { + p=PushShortPixel(MSBEndian,p,&pixel); + q->red=ScaleAnyToQuantum(pixel,range); + p=PushShortPixel(MSBEndian,p,&pixel); + q->green=ScaleAnyToQuantum(pixel,range); + p=PushShortPixel(MSBEndian,p,&pixel); + q->blue=ScaleAnyToQuantum(pixel,range); + q->opacity=OpaqueOpacity; + q++; + } + } if ((type == BilevelType) || (type == GrayscaleType)) - for (x=0; x < (long) image->columns; x++) { - if ((type == BilevelType) && - (IsMonochromePixel(q) == MagickFalse)) - type=IsGrayPixel(q) == MagickFalse ? UndefinedType : - GrayscaleType; - if ((type == GrayscaleType) && (IsGrayPixel(q) == MagickFalse)) - type=UndefinedType; - if ((type != BilevelType) && (type != GrayscaleType)) - break; - q++; + q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); + for (x=0; x < (ssize_t) image->columns; x++) + { + if ((type == BilevelType) && + (IsMonochromePixel(q) == MagickFalse)) + type=IsGrayPixel(q) == MagickFalse ? UndefinedType : + GrayscaleType; + if ((type == GrayscaleType) && (IsGrayPixel(q) == MagickFalse)) + type=UndefinedType; + if ((type != BilevelType) && (type != GrayscaleType)) + break; + q++; + } } - sync=SyncCacheViewAuthenticPixels(image_view,exception); + sync=SyncAuthenticPixels(image,exception); if (sync == MagickFalse) status=MagickFalse; } - image_view=DestroyCacheView(image_view); quantum_info=DestroyQuantumInfo(quantum_info); if (status == MagickFalse) ThrowReaderException(CorruptImageError,"UnableToReadImageData"); @@ -934,7 +923,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) QuantumAny range; - unsigned long + size_t channels; /* @@ -967,22 +956,18 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) quantum_info=AcquireQuantumInfo(image_info,image); if (quantum_info == (QuantumInfo *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - image_view=AcquireCacheView(image); -#if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505) - #pragma omp parallel for schedule(static,1) shared(row,status,quantum_type) -#endif - for (y=0; y < (long) image->rows; y++) + for (y=0; y < (ssize_t) image->rows; y++) { - long + ssize_t offset; MagickBooleanType sync; register const unsigned char - *p; + *restrict p; - register long + register ssize_t x; register PixelPacket @@ -997,9 +982,6 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) if (status == MagickFalse) continue; pixels=GetQuantumPixels(quantum_info); -#if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505) - #pragma omp critical (MagickCore_ReadPNMImage) -#endif { count=ReadBlob(image,extent,pixels); if ((image->progress_monitor != (MagickProgressMonitor) NULL) && @@ -1008,7 +990,8 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) MagickBooleanType proceed; - proceed=SetImageProgress(image,LoadImageTag,row,image->rows); + proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row, + image->rows); if (proceed == MagickFalse) status=MagickFalse; } @@ -1016,17 +999,16 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) } if (count != (ssize_t) extent) status=MagickFalse; - q=QueueCacheViewAuthenticPixels(image_view,0,offset,image->columns,1, - exception); + q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); if (q == (PixelPacket *) NULL) { status=MagickFalse; continue; } - indexes=GetCacheViewAuthenticIndexQueue(image_view); + indexes=GetAuthenticIndexQueue(image); p=pixels; if ((image->depth == 8) || (image->depth == 16)) - (void) ImportQuantumPixels(image,image_view,quantum_info, + (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, quantum_type,pixels,exception); else switch (quantum_type) @@ -1039,7 +1021,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) unsigned char pixel; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { p=PushCharPixel(p,&pixel); SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range)); @@ -1059,7 +1041,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) unsigned short pixel; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { p=PushShortPixel(MSBEndian,p,&pixel); SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range)); @@ -1084,7 +1066,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) unsigned char pixel; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { p=PushCharPixel(p,&pixel); SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range)); @@ -1108,7 +1090,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) unsigned short pixel; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { p=PushShortPixel(MSBEndian,p,&pixel); SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range)); @@ -1136,7 +1118,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) unsigned char pixel; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { p=PushCharPixel(p,&pixel); SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range)); @@ -1158,7 +1140,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) unsigned short pixel; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { p=PushShortPixel(MSBEndian,p,&pixel); SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range)); @@ -1178,11 +1160,10 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) break; } } - sync=SyncCacheViewAuthenticPixels(image_view,exception); + sync=SyncAuthenticPixels(image,exception); if (sync == MagickFalse) status=MagickFalse; } - image_view=DestroyCacheView(image_view); quantum_info=DestroyQuantumInfo(quantum_info); if (status == MagickFalse) ThrowReaderException(CorruptImageError,"UnableToReadImageData"); @@ -1210,13 +1191,9 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) SetQuantumScale(quantum_info,(MagickRealType) QuantumRange* fabs(quantum_scale)); extent=GetQuantumExtent(image,quantum_info,quantum_type); - image_view=AcquireCacheView(image); -#if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505) - #pragma omp parallel for schedule(static,1) shared(row,status,quantum_type) -#endif - for (y=0; y < (long) image->rows; y++) + for (y=0; y < (ssize_t) image->rows; y++) { - long + ssize_t offset; MagickBooleanType @@ -1237,9 +1214,6 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) if (status == MagickFalse) continue; pixels=GetQuantumPixels(quantum_info); -#if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505) - #pragma omp critical (MagickCore_ReadPNMImage) -#endif { count=ReadBlob(image,extent,pixels); if ((image->progress_monitor != (MagickProgressMonitor) NULL) && @@ -1248,7 +1222,8 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) MagickBooleanType proceed; - proceed=SetImageProgress(image,LoadImageTag,row,image->rows); + proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row, + image->rows); if (proceed == MagickFalse) status=MagickFalse; } @@ -1256,22 +1231,21 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) } if ((size_t) count != extent) status=MagickFalse; - q=QueueCacheViewAuthenticPixels(image_view,0,(long) (image->rows- - offset-1),image->columns,1,exception); + q=QueueAuthenticPixels(image,0,(ssize_t) (image->rows-offset-1), + image->columns,1,exception); if (q == (PixelPacket *) NULL) { status=MagickFalse; continue; } - length=ImportQuantumPixels(image,image_view,quantum_info,quantum_type, - pixels,exception); + length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, + quantum_type,pixels,exception); if (length != extent) status=MagickFalse; - sync=SyncCacheViewAuthenticPixels(image_view,exception); + sync=SyncAuthenticPixels(image,exception); if (sync == MagickFalse) status=MagickFalse; } - image_view=DestroyCacheView(image_view); quantum_info=DestroyQuantumInfo(quantum_info); if (status == MagickFalse) ThrowReaderException(CorruptImageError,"UnableToReadImageData"); @@ -1345,10 +1319,10 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) % % The format of the RegisterPNMImage method is: % -% unsigned long RegisterPNMImage(void) +% size_t RegisterPNMImage(void) % */ -ModuleExport unsigned long RegisterPNMImage(void) +ModuleExport size_t RegisterPNMImage(void) { MagickInfo *entry; @@ -1368,6 +1342,7 @@ ModuleExport unsigned long RegisterPNMImage(void) entry=SetMagickInfo("PFM"); entry->decoder=(DecodeImageHandler *) ReadPNMImage; entry->encoder=(EncodeImageHandler *) WritePNMImage; + entry->endian_support=MagickTrue; entry->description=ConstantString("Portable float format"); entry->module=ConstantString("PFM"); (void) RegisterMagickInfo(entry); @@ -1432,8 +1407,7 @@ ModuleExport void UnregisterPNMImage(void) % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% Procedure WritePNMImage() writes an image to a file in the PNM rasterfile -% format. +% WritePNMImage() writes an image to a file in the PNM rasterfile format. % % The format of the WritePNMImage method is: % @@ -1459,7 +1433,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) IndexPacket index; - long + ssize_t y; MagickBooleanType @@ -1477,6 +1451,9 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) QuantumType quantum_type; + register ssize_t + i; + register unsigned char *pixels, *q; @@ -1593,8 +1570,8 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) { if (image->colorspace != RGBColorspace) (void) TransformImageColorspace(image,RGBColorspace); - (void) FormatMagickString(buffer,MaxTextExtent,"%lu %lu\n", - image->columns,image->rows); + (void) FormatMagickString(buffer,MaxTextExtent,"%.20g %.20g\n", + (double) image->columns,(double) image->rows); (void) WriteBlobString(image,buffer); } else @@ -1606,7 +1583,8 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) PAM header. */ (void) FormatMagickString(buffer,MaxTextExtent, - "WIDTH %lu\nHEIGHT %lu\n",image->columns,image->rows); + "WIDTH %.20g\nHEIGHT %.20g\n",(double) image->columns,(double) + image->rows); (void) WriteBlobString(image,buffer); quantum_type=GetQuantumType(image,&image->exception); switch (quantum_type) @@ -1643,7 +1621,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) if (image->depth > 16) image->depth=16; (void) FormatMagickString(buffer,MaxTextExtent, - "DEPTH %lu\nMAXVAL %lu\n",(unsigned long) packet_size,(unsigned long) + "DEPTH %.20g\nMAXVAL %.20g\n",(double) packet_size,(double) GetQuantumRange(image->depth)); (void) WriteBlobString(image,buffer); (void) FormatMagickString(buffer,MaxTextExtent,"TUPLTYPE %s\nENDHDR\n", @@ -1657,14 +1635,14 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) { case '1': { - char - *pixels; + unsigned char + pixels[2048]; /* Convert image to a PBM image. */ - pixels=AcquireString((const char *) NULL); - for (y=0; y < (long) image->rows; y++) + q=pixels; + for (y=0; y < (ssize_t) image->rows; y++) { register const IndexPacket *restrict indexes; @@ -1672,37 +1650,47 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) register const PixelPacket *restrict p; - register long + register ssize_t x; p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); if (p == (const PixelPacket *) NULL) break; indexes=GetVirtualIndexQueue(image); - *pixels='\0'; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { pixel=PixelIntensityToQuantum(p); - (void) ConcatenateString(&pixels, - pixel >= (Quantum) (QuantumRange/2) ? "0 " : "1 "); + *q++=(unsigned char) (pixel >= (Quantum) (QuantumRange/2) ? + '0' : '1'); + *q++=' '; + if ((q-pixels+2) >= 80) + { + *q++='\n'; + (void) WriteBlob(image,q-pixels,pixels); + q=pixels; + i=0; + } p++; } - (void) ConcatenateString(&pixels,"\n"); - (void) WriteBlob(image,strlen(pixels),(unsigned char *) pixels); if (image->previous == (Image *) NULL) { - status=SetImageProgress(image,SaveImageTag,y,image->rows); + status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, + image->rows); if (status == MagickFalse) break; } } - pixels=DestroyString(pixels); + if (q != pixels) + { + *q++='\n'; + (void) WriteBlob(image,q-pixels,pixels); + } break; } case '2': { - char - *pixels; + unsigned char + pixels[2048]; /* Convert image to a PGM image. @@ -1711,20 +1699,19 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) (void) WriteBlobString(image,"255\n"); else (void) WriteBlobString(image,"65535\n"); - pixels=AcquireString((const char *) NULL); - for (y=0; y < (long) image->rows; y++) + q=pixels; + for (y=0; y < (ssize_t) image->rows; y++) { register const PixelPacket *restrict p; - register long + register ssize_t x; p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); if (p == (const PixelPacket *) NULL) break; - *pixels='\0'; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { index=PixelIntensityToQuantum(p); if (image->depth <= 8) @@ -1733,25 +1720,36 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) else count=(ssize_t) FormatMagickString(buffer,MaxTextExtent,"%u ", ScaleQuantumToShort(index)); - (void) ConcatenateString(&pixels,buffer); + extent=(size_t) count; + (void) strncpy((char *) q,buffer,extent); + q+=extent; + if ((q-pixels+extent) >= 80) + { + *q++='\n'; + (void) WriteBlob(image,q-pixels,pixels); + q=pixels; + } p++; } - (void) ConcatenateString(&pixels,"\n"); - (void) WriteBlob(image,strlen(pixels),(unsigned char *) pixels); if (image->previous == (Image *) NULL) { - status=SetImageProgress(image,SaveImageTag,y,image->rows); + status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, + image->rows); if (status == MagickFalse) break; } } - pixels=DestroyString(pixels); + if (q != pixels) + { + *q++='\n'; + (void) WriteBlob(image,q-pixels,pixels); + } break; } case '3': { - char - *pixels; + unsigned char + pixels[2048]; /* Convert image to a PNM image. @@ -1760,20 +1758,19 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) (void) WriteBlobString(image,"255\n"); else (void) WriteBlobString(image,"65535\n"); - pixels=AcquireString((const char *) NULL); - for (y=0; y < (long) image->rows; y++) + q=pixels; + for (y=0; y < (ssize_t) image->rows; y++) { register const PixelPacket *restrict p; - register long + register ssize_t x; p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); if (p == (const PixelPacket *) NULL) break; - *pixels='\0'; - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { if (image->depth <= 8) count=(ssize_t) FormatMagickString(buffer,MaxTextExtent, @@ -1785,19 +1782,30 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) "%u %u %u ",ScaleQuantumToShort(GetRedPixelComponent(p)), ScaleQuantumToShort(GetGreenPixelComponent(p)), ScaleQuantumToShort(GetBluePixelComponent(p))); - (void) ConcatenateString(&pixels,buffer); + extent=(size_t) count; + (void) strncpy((char *) q,buffer,extent); + q+=extent; + if ((q-pixels+extent) >= 80) + { + *q++='\n'; + (void) WriteBlob(image,q-pixels,pixels); + q=pixels; + } p++; } - (void) ConcatenateString(&pixels,"\n"); - (void) WriteBlob(image,strlen(pixels),(unsigned char *) pixels); if (image->previous == (Image *) NULL) { - status=SetImageProgress(image,SaveImageTag,y,image->rows); + status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, + image->rows); if (status == MagickFalse) break; } } - pixels=DestroyString(pixels); + if (q != pixels) + { + *q++='\n'; + (void) WriteBlob(image,q-pixels,pixels); + } break; } case '4': @@ -1811,7 +1819,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); quantum_info->min_is_white=MagickTrue; pixels=GetQuantumPixels(quantum_info); - for (y=0; y < (long) image->rows; y++) + for (y=0; y < (ssize_t) image->rows; y++) { register const PixelPacket *restrict p; @@ -1826,7 +1834,8 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) break; if (image->previous == (Image *) NULL) { - status=SetImageProgress(image,SaveImageTag,y,image->rows); + status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, + image->rows); if (status == MagickFalse) break; } @@ -1844,7 +1853,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) */ if (image->depth > 8) image->depth=16; - (void) FormatMagickString(buffer,MaxTextExtent,"%lu\n",(unsigned long) + (void) FormatMagickString(buffer,MaxTextExtent,"%.20g\n",(double) GetQuantumRange(image->depth)); (void) WriteBlobString(image,buffer); quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image); @@ -1854,12 +1863,12 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) pixels=GetQuantumPixels(quantum_info); extent=GetQuantumExtent(image,quantum_info,GrayQuantum); range=GetQuantumRange(image->depth); - for (y=0; y < (long) image->rows; y++) + for (y=0; y < (ssize_t) image->rows; y++) { register const PixelPacket *restrict p; - register long + register ssize_t x; p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); @@ -1872,7 +1881,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) else { if (image->depth <= 8) - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { if (IsGrayPixel(p) == MagickFalse) pixel=ScaleQuantumToAny(PixelIntensityToQuantum(p),range); @@ -1887,7 +1896,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) p++; } else - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { if (IsGrayPixel(p) == MagickFalse) pixel=ScaleQuantumToAny(PixelIntensityToQuantum(p),range); @@ -1908,7 +1917,8 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) break; if (image->previous == (Image *) NULL) { - status=SetImageProgress(image,SaveImageTag,y,image->rows); + status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, + image->rows); if (status == MagickFalse) break; } @@ -1926,7 +1936,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) */ if (image->depth > 8) image->depth=16; - (void) FormatMagickString(buffer,MaxTextExtent,"%lu\n",(unsigned long) + (void) FormatMagickString(buffer,MaxTextExtent,"%.20g\n",(double) GetQuantumRange(image->depth)); (void) WriteBlobString(image,buffer); quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image); @@ -1935,12 +1945,12 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) pixels=GetQuantumPixels(quantum_info); extent=GetQuantumExtent(image,quantum_info,quantum_type); range=GetQuantumRange(image->depth); - for (y=0; y < (long) image->rows; y++) + for (y=0; y < (ssize_t) image->rows; y++) { register const PixelPacket *restrict p; - register long + register ssize_t x; p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); @@ -1953,7 +1963,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) else { if (image->depth <= 8) - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { pixel=ScaleQuantumToAny(p->red,range); q=PopCharPixel((unsigned char) pixel,q); @@ -1961,16 +1971,10 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) q=PopCharPixel((unsigned char) pixel,q); pixel=ScaleQuantumToAny(p->blue,range); q=PopCharPixel((unsigned char) pixel,q); - if (image->matte != MagickFalse) - { - pixel=ScaleQuantumToAny((Quantum) (QuantumRange- - GetOpacityPixelComponent(p)),range); - q=PopCharPixel((unsigned char) pixel,q); - } p++; } else - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { pixel=ScaleQuantumToAny(p->red,range); q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); @@ -1978,12 +1982,6 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); pixel=ScaleQuantumToAny(p->blue,range); q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); - if (image->matte != MagickFalse) - { - pixel=ScaleQuantumToAny((Quantum) (QuantumRange- - GetOpacityPixelComponent(p)),range); - q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); - } p++; } extent=(size_t) (q-pixels); @@ -1993,7 +1991,8 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) break; if (image->previous == (Image *) NULL) { - status=SetImageProgress(image,SaveImageTag,y,image->rows); + status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, + image->rows); if (status == MagickFalse) break; } @@ -2014,7 +2013,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image); pixels=GetQuantumPixels(quantum_info); range=GetQuantumRange(image->depth); - for (y=0; y < (long) image->rows; y++) + for (y=0; y < (ssize_t) image->rows; y++) { register const IndexPacket *restrict indexes; @@ -2022,7 +2021,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) register const PixelPacket *restrict p; - register long + register ssize_t x; p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); @@ -2041,7 +2040,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) case GrayAlphaQuantum: { if (image->depth <= 8) - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { pixel=ScaleQuantumToAny(PixelIntensityToQuantum(p),range); q=PopCharPixel((unsigned char) pixel,q); @@ -2054,7 +2053,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) p++; } else - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { pixel=ScaleQuantumToAny(PixelIntensityToQuantum(p),range); q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); @@ -2072,7 +2071,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) case CMYKAQuantum: { if (image->depth <= 8) - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { pixel=ScaleQuantumToAny(p->red,range); q=PopCharPixel((unsigned char) pixel,q); @@ -2091,7 +2090,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) p++; } else - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { pixel=ScaleQuantumToAny(p->red,range); q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); @@ -2114,7 +2113,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) default: { if (image->depth <= 8) - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { pixel=ScaleQuantumToAny(p->red,range); q=PopCharPixel((unsigned char) pixel,q); @@ -2131,7 +2130,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) p++; } else - for (x=0; x < (long) image->columns; x++) + for (x=0; x < (ssize_t) image->columns; x++) { pixel=ScaleQuantumToAny(p->red,range); q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); @@ -2157,7 +2156,8 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) break; if (image->previous == (Image *) NULL) { - status=SetImageProgress(image,SaveImageTag,y,image->rows); + status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, + image->rows); if (status == MagickFalse) break; } @@ -2179,7 +2179,7 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) if (status == MagickFalse) ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); pixels=GetQuantumPixels(quantum_info); - for (y=(long) image->rows-1; y >= 0; y--) + for (y=(ssize_t) image->rows-1; y >= 0; y--) { register const PixelPacket *restrict p; @@ -2192,7 +2192,8 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image) (void) WriteBlob(image,extent,pixels); if (image->previous == (Image *) NULL) { - status=SetImageProgress(image,SaveImageTag,y,image->rows); + status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, + image->rows); if (status == MagickFalse) break; }