From ff024b4e60135e0134e077a47d446a7c50a3d9d3 Mon Sep 17 00:00:00 2001 From: cristy Date: Sun, 21 Feb 2010 22:55:09 +0000 Subject: [PATCH] --- ChangeLog | 3 + Magick++/ChangeLog | 6 +- Magick++/lib/Image.cpp | 2 +- coders/dpx.c | 208 +++++++++++++--------------------------- magick/quantum-export.c | 28 ++++-- magick/quantum-import.c | 6 +- 6 files changed, 98 insertions(+), 155 deletions(-) diff --git a/ChangeLog b/ChangeLog index ec1bdfb53c..f3acd5fa54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2010-02-20 6.5.9-10 Cristy + * Write 10-bit grayscale DPX images properly. + 2010-02-18 6.5.9-8 Cristy * Detect PDF ICCBased colorspace. diff --git a/Magick++/ChangeLog b/Magick++/ChangeLog index 77b3abd182..c9357bbd19 100644 --- a/Magick++/ChangeLog +++ b/Magick++/ChangeLog @@ -1,6 +1,6 @@ -2009-12-06 6.5.8-4 Cristy - * Add Magick::Options::file() method to read or write an image from an - existing file handle. +2010-02-21 6.5.9-10 Cristy + * Add extent() to extend the image as defined by the geometry, gravity, and + image background color. 2009-11-14 6.5.7-8 Cristy * Add forwardFourierTransform(), inverseFourierTransform(), and diff --git a/Magick++/lib/Image.cpp b/Magick++/lib/Image.cpp index b76bb6510f..4677bb2a46 100644 --- a/Magick++/lib/Image.cpp +++ b/Magick++/lib/Image.cpp @@ -876,7 +876,7 @@ void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundC backgroundColor ( backgroundColor_ ); extent ( geometry_ ); } -void Magick::Image::extent ( const Geometry &geometry_, const GravityType &gravity_ ) +void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ ) { image()->gravity = gravity_; extent ( geometry_ ); diff --git a/coders/dpx.c b/coders/dpx.c index f37e3b5555..b474ee1987 100644 --- a/coders/dpx.c +++ b/coders/dpx.c @@ -400,7 +400,7 @@ static size_t GetBytesPerRow(unsigned long columns, bits_per_pixel+31)/32); break; } - bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns)/3))+31)/32); + bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32); break; } case 12: @@ -539,6 +539,9 @@ static void TimeCodeToString(const unsigned long timestamp,char *code) static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception) { + CacheView + *image_view; + char magick[4], value[MaxTextExtent]; @@ -550,6 +553,7 @@ static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception) *image; long + row, y; MagickBooleanType @@ -558,6 +562,9 @@ static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception) MagickOffsetType offset; + QuantumInfo + *quantum_info; + QuantumType quantum_type; @@ -1064,159 +1071,80 @@ static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception) } extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth, dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue); - if ((quantum_type == GrayQuantum) && - (dpx.image.image_element[0].packing != 0) && (image->depth == 10) && - (image->endian == MSBEndian)) - { - QuantumAny - range; - - QuantumInfo - *quantum_info; - - register long - x; - - unsigned char - *pixels; - - unsigned long - pixel; - - quantum_info=AcquireQuantumInfo(image_info,image); - if (quantum_info == (QuantumInfo *) NULL) - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - SetQuantumQuantum(quantum_info,32); - SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ? - MagickTrue : MagickFalse); - pixels=GetQuantumPixels(quantum_info); - pixel=0U; - i=0; - range=GetQuantumRange(image->depth); - for (y=0; y < (long) image->rows; y++) - { - q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); - if (q == (PixelPacket *) NULL) - break; - for (x=0; x < (long) image->columns; x++) - { - switch (i++ % 3) - { - case 0: - { - pixel=ReadBlobMSBLong(image); - q->red=ScaleAnyToQuantum((pixel >> 0) & 0x3ff,range); - break; - } - case 1: - { - q->red=ScaleAnyToQuantum((pixel >> 10) & 0x3ff,range); - break; - } - case 2: - { - q->red=ScaleAnyToQuantum((pixel >> 20) & 0x3ff,range); - break; - } - } - q->green=q->red; - q->blue=q->red; - q++; - } - if (SyncAuthenticPixels(image,exception) == MagickFalse) - break; - status=SetImageProgress(image,LoadImageTag,y,image->rows); - if (status == MagickFalse) - break; - } - quantum_info=DestroyQuantumInfo(quantum_info); - } - else - { - long - row; - - QuantumInfo - *quantum_info; - - CacheView - *image_view; - - /* - DPX any-bit pixel format. - */ - status=MagickTrue; - row=0; - quantum_info=AcquireQuantumInfo(image_info,image); - if (quantum_info == (QuantumInfo *) NULL) - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - SetQuantumQuantum(quantum_info,32); - SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ? - MagickTrue : MagickFalse); - image_view=AcquireCacheView(image); + /* + DPX any-bit pixel format. + */ + status=MagickTrue; + row=0; + quantum_info=AcquireQuantumInfo(image_info,image); + if (quantum_info == (QuantumInfo *) NULL) + ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); + SetQuantumQuantum(quantum_info,32); + SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ? + MagickTrue : MagickFalse); + image_view=AcquireCacheView(image); #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505) #pragma omp parallel for schedule(static) shared(row,status,quantum_type) #endif - for (y=0; y < (long) image->rows; y++) - { - long - offset; + for (y=0; y < (long) image->rows; y++) + { + long + offset; - MagickBooleanType - sync; + MagickBooleanType + sync; - register PixelPacket - *q; + register PixelPacket + *q; - ssize_t - count; + ssize_t + count; - size_t - length; + size_t + length; - unsigned char - *pixels; + unsigned char + *pixels; - if (status == MagickFalse) - continue; - pixels=GetQuantumPixels(quantum_info); + if (status == MagickFalse) + continue; + pixels=GetQuantumPixels(quantum_info); #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505) #pragma omp critical (MagickCore_ReadDPXImage) #endif + { + count=ReadBlob(image,extent,pixels); + if ((image->progress_monitor != (MagickProgressMonitor) NULL) && + (image->previous == (Image *) NULL)) { - count=ReadBlob(image,extent,pixels); - if ((image->progress_monitor != (MagickProgressMonitor) NULL) && - (image->previous == (Image *) NULL)) - { - MagickBooleanType - proceed; + MagickBooleanType + proceed; - proceed=SetImageProgress(image,LoadImageTag,row,image->rows); - if (proceed == MagickFalse) - status=MagickFalse; - } - offset=row++; - } - if (count != (ssize_t) extent) - status=MagickFalse; - q=QueueCacheViewAuthenticPixels(image_view,0,offset,image->columns,1, - exception); - if (q == (PixelPacket *) NULL) - { + proceed=SetImageProgress(image,LoadImageTag,row,image->rows); + if (proceed == MagickFalse) status=MagickFalse; - continue; - } - length=ImportQuantumPixels(image,image_view,quantum_info,quantum_type, - pixels,exception); - sync=SyncCacheViewAuthenticPixels(image_view,exception); - if (sync == MagickFalse) - status=MagickFalse; - } - image_view=DestroyCacheView(image_view); - quantum_info=DestroyQuantumInfo(quantum_info); - if (status == MagickFalse) - ThrowReaderException(CorruptImageError,"UnableToReadImageData"); + } + offset=row++; } + if (count != (ssize_t) extent) + status=MagickFalse; + q=QueueCacheViewAuthenticPixels(image_view,0,offset,image->columns,1, + exception); + if (q == (PixelPacket *) NULL) + { + status=MagickFalse; + continue; + } + length=ImportQuantumPixels(image,image_view,quantum_info,quantum_type, + pixels,exception); + sync=SyncCacheViewAuthenticPixels(image_view,exception); + if (sync == MagickFalse) + status=MagickFalse; + } + image_view=DestroyCacheView(image_view); + quantum_info=DestroyQuantumInfo(quantum_info); + if (status == MagickFalse) + ThrowReaderException(CorruptImageError,"UnableToReadImageData"); SetQuantumImageType(image,quantum_type); if (EOFBlob(image) != MagickFalse) ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", @@ -1884,8 +1812,8 @@ static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image) } extent=GetBytesPerRow(image->columns,image->matte != MagickFalse ? 4UL : 3UL, image->depth,MagickTrue); - if ((IsGrayImage(image,&image->exception) != MagickFalse) && - (image->matte == MagickFalse)) + if ((IsGrayImage(image,&image->exception) != MagickFalse) && + (image->matte == MagickFalse)) { quantum_type=GrayQuantum; extent=GetBytesPerRow(image->columns,1UL,image->depth,MagickTrue); diff --git a/magick/quantum-export.c b/magick/quantum-export.c index 876e58fffa..beafad98dd 100644 --- a/magick/quantum-export.c +++ b/magick/quantum-export.c @@ -774,14 +774,25 @@ MagickExport size_t ExportQuantumPixels(const Image *image, range=GetQuantumRange(image->depth); if (quantum_info->pack == MagickFalse) { - for (x=0; x < (long) number_pixels; x++) + register unsigned long + pixel; + + for (x=0; x < (long) number_pixels; x+=3) { - pixel=ScaleQuantumToShort(PixelIntensityToQuantum(p)); - q=PopShortPixel(endian,(unsigned short) ScaleQuantumToAny( - (Quantum) pixel,range),q); - p++; + pixel=(unsigned long) ( + ScaleQuantumToAny(PixelIntensityToQuantum(p+2),range) << 22 | + ScaleQuantumToAny(PixelIntensityToQuantum(p+1),range) << 12 | + ScaleQuantumToAny(PixelIntensityToQuantum(p+0),range) << 2); + q=PopLongPixel(endian,pixel,q); + p+=3; q+=quantum_info->pad; } + if (x++ < (long) (number_pixels-1)) + q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny( + PixelIntensityToQuantum(p+1),range),q); + if (x++ < (long) number_pixels) + q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny( + PixelIntensityToQuantum(p+0),range),q); break; } for (x=0; x < (long) number_pixels; x++) @@ -791,6 +802,7 @@ MagickExport size_t ExportQuantumPixels(const Image *image, p++; q+=quantum_info->pad; } +printf("%d\n",q-pixels); break; } case 12: @@ -1723,7 +1735,7 @@ MagickExport size_t ExportQuantumPixels(const Image *image, for (x=0; x < (long) number_pixels; x++) { pixel=(unsigned long) (ScaleQuantumToAny(p->red,range) << 22 | - ScaleQuantumToAny(p->green,range) << 12 | + ScaleQuantumToAny(p->green,range) << 12 | ScaleQuantumToAny(p->blue,range) << 2); q=PopLongPixel(endian,pixel,q); p++; @@ -2475,12 +2487,12 @@ MagickExport size_t ExportQuantumPixels(const Image *image, n++; } pixel=(unsigned long) ((unsigned long) (cbcr[1]) << 22 | - (unsigned long) (cbcr[0]) << 12 | + (unsigned long) (cbcr[0]) << 12 | (unsigned long) (cbcr[2]) << 2); q=PopLongPixel(endian,pixel,q); p++; pixel=(unsigned long) ((unsigned long) (cbcr[3]) << 22 | - (unsigned long) (cbcr[0]) << 12 | + (unsigned long) (cbcr[0]) << 12 | (unsigned long) (cbcr[2]) << 2); q=PopLongPixel(endian,pixel,q); p++; diff --git a/magick/quantum-import.c b/magick/quantum-import.c index d69626fd4e..8a2721173f 100644 --- a/magick/quantum-import.c +++ b/magick/quantum-import.c @@ -810,15 +810,15 @@ MagickExport size_t ImportQuantumPixels(Image *image,CacheView *image_view, for (x=0; x < (long) number_pixels/3; x++) { p=PushLongPixel(endian,p,&pixel); - q->red=ScaleAnyToQuantum((pixel >> 0) & 0x3ff,range); + q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range); q->green=q->red; q->blue=q->red; q++; - q->red=ScaleAnyToQuantum((pixel >> 10) & 0x3ff,range); + q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range); q->green=q->red; q->blue=q->red; q++; - q->red=ScaleAnyToQuantum((pixel >> 20) & 0x3ff,range); + q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range); q->green=q->red; q->blue=q->red; p+=quantum_info->pad;