| /* |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % % |
| % % |
| % % |
| % AAA TTTTT TTTTT RRRR IIIII BBBB U U TTTTT EEEEE % |
| % A A T T R R I B B U U T E % |
| % AAAAA T T RRRR I BBBB U U T EEE % |
| % A A T T R R I B B U U T E % |
| % A A T T R R IIIII BBBB UUU T EEEEE % |
| % % |
| % % |
| % MagickCore Get / Set Image Attributes % |
| % % |
| % Software Design % |
| % John Cristy % |
| % October 2002 % |
| % % |
| % % |
| % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization % |
| % dedicated to making software imaging solutions freely available. % |
| % % |
| % You may not use this file except in compliance with the License. You may % |
| % obtain a copy of the License at % |
| % % |
| % http://www.imagemagick.org/script/license.php % |
| % % |
| % Unless required by applicable law or agreed to in writing, software % |
| % distributed under the License is distributed on an "AS IS" BASIS, % |
| % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| % See the License for the specific language governing permissions and % |
| % limitations under the License. % |
| % % |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % |
| % |
| % |
| */ |
| |
| /* |
| Include declarations. |
| */ |
| #include "MagickCore/studio.h" |
| #include "MagickCore/attribute.h" |
| #include "MagickCore/blob.h" |
| #include "MagickCore/blob-private.h" |
| #include "MagickCore/cache.h" |
| #include "MagickCore/cache-view.h" |
| #include "MagickCore/client.h" |
| #include "MagickCore/color.h" |
| #include "MagickCore/color-private.h" |
| #include "MagickCore/colormap.h" |
| #include "MagickCore/colormap-private.h" |
| #include "MagickCore/colorspace.h" |
| #include "MagickCore/colorspace-private.h" |
| #include "MagickCore/composite.h" |
| #include "MagickCore/composite-private.h" |
| #include "MagickCore/constitute.h" |
| #include "MagickCore/draw.h" |
| #include "MagickCore/draw-private.h" |
| #include "MagickCore/effect.h" |
| #include "MagickCore/enhance.h" |
| #include "MagickCore/exception.h" |
| #include "MagickCore/exception-private.h" |
| #include "MagickCore/geometry.h" |
| #include "MagickCore/histogram.h" |
| #include "MagickCore/identify.h" |
| #include "MagickCore/image.h" |
| #include "MagickCore/image-private.h" |
| #include "MagickCore/list.h" |
| #include "MagickCore/log.h" |
| #include "MagickCore/memory_.h" |
| #include "MagickCore/magick.h" |
| #include "MagickCore/monitor.h" |
| #include "MagickCore/monitor-private.h" |
| #include "MagickCore/paint.h" |
| #include "MagickCore/pixel.h" |
| #include "MagickCore/pixel-accessor.h" |
| #include "MagickCore/property.h" |
| #include "MagickCore/quantize.h" |
| #include "MagickCore/quantum-private.h" |
| #include "MagickCore/random_.h" |
| #include "MagickCore/resource_.h" |
| #include "MagickCore/semaphore.h" |
| #include "MagickCore/segment.h" |
| #include "MagickCore/splay-tree.h" |
| #include "MagickCore/string_.h" |
| #include "MagickCore/thread-private.h" |
| #include "MagickCore/threshold.h" |
| #include "MagickCore/transform.h" |
| #include "MagickCore/utility.h" |
| |
| /* |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % % |
| % % |
| % % |
| + G e t I m a g e B o u n d i n g B o x % |
| % % |
| % % |
| % % |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % |
| % GetImageBoundingBox() returns the bounding box of an image canvas. |
| % |
| % The format of the GetImageBoundingBox method is: |
| % |
| % RectangleInfo GetImageBoundingBox(const Image *image, |
| % ExceptionInfo *exception) |
| % |
| % A description of each parameter follows: |
| % |
| % o bounds: Method GetImageBoundingBox returns the bounding box of an |
| % image canvas. |
| % |
| % o image: the image. |
| % |
| % o exception: return any errors or warnings in this structure. |
| % |
| */ |
| MagickExport RectangleInfo GetImageBoundingBox(const Image *image, |
| ExceptionInfo *exception) |
| { |
| CacheView |
| *image_view; |
| |
| MagickBooleanType |
| status; |
| |
| PixelInfo |
| target[3], |
| zero; |
| |
| RectangleInfo |
| bounds; |
| |
| register const Quantum |
| *p; |
| |
| ssize_t |
| y; |
| |
| assert(image != (Image *) NULL); |
| assert(image->signature == MagickSignature); |
| if (image->debug != MagickFalse) |
| (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| bounds.width=0; |
| bounds.height=0; |
| bounds.x=(ssize_t) image->columns; |
| bounds.y=(ssize_t) image->rows; |
| GetPixelInfo(image,&target[0]); |
| image_view=AcquireCacheView(image); |
| p=GetCacheViewVirtualPixels(image_view,0,0,1,1,exception); |
| if (p == (const Quantum *) NULL) |
| { |
| image_view=DestroyCacheView(image_view); |
| return(bounds); |
| } |
| GetPixelInfoPixel(image,p,&target[0]); |
| GetPixelInfo(image,&target[1]); |
| p=GetCacheViewVirtualPixels(image_view,(ssize_t) image->columns-1,0,1,1, |
| exception); |
| GetPixelInfoPixel(image,p,&target[1]); |
| GetPixelInfo(image,&target[2]); |
| p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) image->rows-1,1,1, |
| exception); |
| GetPixelInfoPixel(image,p,&target[2]); |
| status=MagickTrue; |
| GetPixelInfo(image,&zero); |
| #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| #pragma omp parallel for schedule(static,4) shared(status) |
| #endif |
| for (y=0; y < (ssize_t) image->rows; y++) |
| { |
| PixelInfo |
| pixel; |
| |
| RectangleInfo |
| bounding_box; |
| |
| register const Quantum |
| *restrict p; |
| |
| register ssize_t |
| x; |
| |
| if (status == MagickFalse) |
| continue; |
| #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| # pragma omp critical (MagickCore_GetImageBoundingBox) |
| #endif |
| bounding_box=bounds; |
| p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| if (p == (const Quantum *) NULL) |
| { |
| status=MagickFalse; |
| continue; |
| } |
| pixel=zero; |
| for (x=0; x < (ssize_t) image->columns; x++) |
| { |
| GetPixelInfoPixel(image,p,&pixel); |
| if ((x < bounding_box.x) && |
| (IsFuzzyEquivalencePixelInfo(&pixel,&target[0]) == MagickFalse)) |
| bounding_box.x=x; |
| if ((x > (ssize_t) bounding_box.width) && |
| (IsFuzzyEquivalencePixelInfo(&pixel,&target[1]) == MagickFalse)) |
| bounding_box.width=(size_t) x; |
| if ((y < bounding_box.y) && |
| (IsFuzzyEquivalencePixelInfo(&pixel,&target[0]) == MagickFalse)) |
| bounding_box.y=y; |
| if ((y > (ssize_t) bounding_box.height) && |
| (IsFuzzyEquivalencePixelInfo(&pixel,&target[2]) == MagickFalse)) |
| bounding_box.height=(size_t) y; |
| p+=GetPixelChannels(image); |
| } |
| #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| # pragma omp critical (MagickCore_GetImageBoundingBox) |
| #endif |
| { |
| if (bounding_box.x < bounds.x) |
| bounds.x=bounding_box.x; |
| if (bounding_box.y < bounds.y) |
| bounds.y=bounding_box.y; |
| if (bounding_box.width > bounds.width) |
| bounds.width=bounding_box.width; |
| if (bounding_box.height > bounds.height) |
| bounds.height=bounding_box.height; |
| } |
| } |
| image_view=DestroyCacheView(image_view); |
| if ((bounds.width == 0) || (bounds.height == 0)) |
| (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, |
| "GeometryDoesNotContainImage","`%s'",image->filename); |
| else |
| { |
| bounds.width-=(bounds.x-1); |
| bounds.height-=(bounds.y-1); |
| } |
| return(bounds); |
| } |
| |
| /* |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % % |
| % % |
| % % |
| % G e t I m a g e D e p t h % |
| % % |
| % % |
| % % |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % |
| % GetImageDepth() returns the depth of a particular image channel. |
| % |
| % The format of the GetImageDepth method is: |
| % |
| % size_t GetImageDepth(const Image *image,ExceptionInfo *exception) |
| % |
| % A description of each parameter follows: |
| % |
| % o image: the image. |
| % |
| % o exception: return any errors or warnings in this structure. |
| % |
| */ |
| MagickExport size_t GetImageDepth(const Image *image,ExceptionInfo *exception) |
| { |
| CacheView |
| *image_view; |
| |
| MagickBooleanType |
| status; |
| |
| register ssize_t |
| id; |
| |
| size_t |
| *current_depth, |
| depth, |
| number_threads; |
| |
| ssize_t |
| y; |
| |
| /* |
| Compute image depth. |
| */ |
| assert(image != (Image *) NULL); |
| assert(image->signature == MagickSignature); |
| if (image->debug != MagickFalse) |
| (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| number_threads=GetOpenMPMaximumThreads(); |
| current_depth=(size_t *) AcquireQuantumMemory(number_threads, |
| sizeof(*current_depth)); |
| if (current_depth == (size_t *) NULL) |
| ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| status=MagickTrue; |
| for (id=0; id < (ssize_t) number_threads; id++) |
| current_depth[id]=1; |
| if ((image->storage_class == PseudoClass) && (image->matte == MagickFalse)) |
| { |
| register ssize_t |
| i; |
| |
| #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| #pragma omp parallel for schedule(static) shared(status) |
| #endif |
| for (i=0; i < (ssize_t) image->colors; i++) |
| { |
| const int |
| id = GetOpenMPThreadId(); |
| |
| if (status == MagickFalse) |
| continue; |
| while (current_depth[id] < MAGICKCORE_QUANTUM_DEPTH) |
| { |
| MagickStatusType |
| status; |
| |
| QuantumAny |
| range; |
| |
| status=0; |
| range=GetQuantumRange(current_depth[id]); |
| if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) |
| status|=ClampToQuantum(image->colormap[i].red) != |
| ScaleAnyToQuantum(ScaleQuantumToAny(ClampToQuantum( |
| image->colormap[i].red),range),range); |
| if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) |
| status|=ClampToQuantum(image->colormap[i].green) != |
| ScaleAnyToQuantum(ScaleQuantumToAny(ClampToQuantum( |
| image->colormap[i].green),range),range); |
| if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) |
| status|=ClampToQuantum(image->colormap[i].blue) != |
| ScaleAnyToQuantum(ScaleQuantumToAny(ClampToQuantum( |
| image->colormap[i].blue),range),range); |
| if (status == 0) |
| break; |
| current_depth[id]++; |
| } |
| } |
| depth=current_depth[0]; |
| for (id=1; id < (ssize_t) number_threads; id++) |
| if (depth < current_depth[id]) |
| depth=current_depth[id]; |
| current_depth=(size_t *) RelinquishMagickMemory(current_depth); |
| return(depth); |
| } |
| image_view=AcquireCacheView(image); |
| #if !defined(MAGICKCORE_HDRI_SUPPORT) |
| if (QuantumRange <= MaxMap) |
| { |
| register ssize_t |
| i; |
| |
| size_t |
| *depth_map; |
| |
| /* |
| Scale pixels to desired (optimized with depth map). |
| */ |
| depth_map=(size_t *) AcquireQuantumMemory(MaxMap+1,sizeof(*depth_map)); |
| if (depth_map == (size_t *) NULL) |
| ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| for (i=0; i <= (ssize_t) MaxMap; i++) |
| { |
| unsigned int |
| depth; |
| |
| for (depth=1; depth < MAGICKCORE_QUANTUM_DEPTH; depth++) |
| { |
| Quantum |
| pixel; |
| |
| QuantumAny |
| range; |
| |
| range=GetQuantumRange(depth); |
| pixel=(Quantum) i; |
| if (pixel == ScaleAnyToQuantum(ScaleQuantumToAny(pixel,range),range)) |
| break; |
| } |
| depth_map[i]=depth; |
| } |
| #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| #pragma omp parallel for schedule(static,4) shared(status) |
| #endif |
| for (y=0; y < (ssize_t) image->rows; y++) |
| { |
| const int |
| id = GetOpenMPThreadId(); |
| |
| register const Quantum |
| *restrict p; |
| |
| register ssize_t |
| x; |
| |
| if (status == MagickFalse) |
| continue; |
| p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| if (p == (const Quantum *) NULL) |
| continue; |
| for (x=0; x < (ssize_t) image->columns; x++) |
| { |
| register ssize_t |
| i; |
| |
| for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| { |
| PixelChannel |
| channel; |
| |
| PixelTrait |
| traits; |
| |
| channel=GetPixelChannelMapChannel(image,i); |
| traits=GetPixelChannelMapTraits(image,channel); |
| if ((traits == UndefinedPixelTrait) || |
| (channel == IndexPixelChannel)) |
| continue; |
| if (depth_map[ScaleQuantumToMap(p[i])] > current_depth[id]) |
| current_depth[id]=depth_map[ScaleQuantumToMap(p[i])]; |
| } |
| p+=GetPixelChannels(image); |
| } |
| if (current_depth[id] == MAGICKCORE_QUANTUM_DEPTH) |
| status=MagickFalse; |
| } |
| image_view=DestroyCacheView(image_view); |
| depth=current_depth[0]; |
| for (id=1; id < (ssize_t) number_threads; id++) |
| if (depth < current_depth[id]) |
| depth=current_depth[id]; |
| depth_map=(size_t *) RelinquishMagickMemory(depth_map); |
| current_depth=(size_t *) RelinquishMagickMemory(current_depth); |
| return(depth); |
| } |
| #endif |
| /* |
| Compute pixel depth. |
| */ |
| #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| #pragma omp parallel for schedule(static,4) shared(status) |
| #endif |
| for (y=0; y < (ssize_t) image->rows; y++) |
| { |
| const int |
| id = GetOpenMPThreadId(); |
| |
| register const Quantum |
| *restrict p; |
| |
| register ssize_t |
| x; |
| |
| if (status == MagickFalse) |
| continue; |
| p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| if (p == (const Quantum *) NULL) |
| continue; |
| for (x=0; x < (ssize_t) image->columns; x++) |
| { |
| register ssize_t |
| i; |
| |
| for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| { |
| PixelChannel |
| channel; |
| |
| PixelTrait |
| traits; |
| |
| channel=GetPixelChannelMapChannel(image,i); |
| traits=GetPixelChannelMapTraits(image,channel); |
| if ((traits == UndefinedPixelTrait) || |
| (channel == IndexPixelChannel)) |
| continue; |
| while (current_depth[id] < MAGICKCORE_QUANTUM_DEPTH) |
| { |
| QuantumAny |
| range; |
| |
| range=GetQuantumRange(current_depth[id]); |
| if (p[i] == ScaleAnyToQuantum(ScaleQuantumToAny(p[i],range),range)) |
| break; |
| current_depth[id]++; |
| } |
| } |
| p+=GetPixelChannels(image); |
| } |
| if (current_depth[id] == MAGICKCORE_QUANTUM_DEPTH) |
| status=MagickFalse; |
| } |
| image_view=DestroyCacheView(image_view); |
| depth=current_depth[0]; |
| for (id=1; id < (ssize_t) number_threads; id++) |
| if (depth < current_depth[id]) |
| depth=current_depth[id]; |
| current_depth=(size_t *) RelinquishMagickMemory(current_depth); |
| return(depth); |
| } |
| |
| /* |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % % |
| % % |
| % % |
| % G e t I m a g e Q u a n t u m D e p t h % |
| % % |
| % % |
| % % |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % |
| % GetImageQuantumDepth() returns the depth of the image rounded to a legal |
| % quantum depth: 8, 16, or 32. |
| % |
| % The format of the GetImageQuantumDepth method is: |
| % |
| % size_t GetImageQuantumDepth(const Image *image, |
| % const MagickBooleanType constrain) |
| % |
| % A description of each parameter follows: |
| % |
| % o image: the image. |
| % |
| % o constrain: A value other than MagickFalse, constrains the depth to |
| % a maximum of MAGICKCORE_QUANTUM_DEPTH. |
| % |
| */ |
| |
| static inline double MagickMin(const double x,const double y) |
| { |
| if (x < y) |
| return(x); |
| return(y); |
| } |
| |
| MagickExport size_t GetImageQuantumDepth(const Image *image, |
| const MagickBooleanType constrain) |
| { |
| size_t |
| depth; |
| |
| depth=image->depth; |
| if (depth <= 8) |
| depth=8; |
| else |
| if (depth <= 16) |
| depth=16; |
| else |
| if (depth <= 32) |
| depth=32; |
| else |
| if (depth <= 64) |
| depth=64; |
| if (constrain != MagickFalse) |
| depth=(size_t) MagickMin((double) depth,(double) MAGICKCORE_QUANTUM_DEPTH); |
| return(depth); |
| } |
| |
| /* |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % % |
| % % |
| % % |
| % G e t I m a g e T y p e % |
| % % |
| % % |
| % % |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % |
| % GetImageType() returns the potential type of image: |
| % |
| % Bilevel Grayscale GrayscaleMatte |
| % Palette PaletteMatte TrueColor |
| % TrueColorMatte ColorSeparation ColorSeparationMatte |
| % |
| % To ensure the image type matches its potential, use SetImageType(): |
| % |
| % (void) SetImageType(image,GetImageType(image)); |
| % |
| % The format of the GetImageType method is: |
| % |
| % ImageType GetImageType(const Image *image,ExceptionInfo *exception) |
| % |
| % A description of each parameter follows: |
| % |
| % o image: the image. |
| % |
| % o exception: return any errors or warnings in this structure. |
| % |
| */ |
| MagickExport ImageType GetImageType(const Image *image,ExceptionInfo *exception) |
| { |
| assert(image != (Image *) NULL); |
| assert(image->signature == MagickSignature); |
| if (image->debug != MagickFalse) |
| (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| if (image->colorspace == CMYKColorspace) |
| { |
| if (image->matte == MagickFalse) |
| return(ColorSeparationType); |
| return(ColorSeparationMatteType); |
| } |
| if (IsImageMonochrome(image,exception) != MagickFalse) |
| return(BilevelType); |
| if (IsImageGray(image,exception) != MagickFalse) |
| { |
| if (image->matte != MagickFalse) |
| return(GrayscaleMatteType); |
| return(GrayscaleType); |
| } |
| if (IsPaletteImage(image,exception) != MagickFalse) |
| { |
| if (image->matte != MagickFalse) |
| return(PaletteMatteType); |
| return(PaletteType); |
| } |
| if (image->matte != MagickFalse) |
| return(TrueColorMatteType); |
| return(TrueColorType); |
| } |
| |
| /* |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % % |
| % % |
| % % |
| % I s I m a g e G r a y % |
| % % |
| % % |
| % % |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % |
| % IsImageGray() returns MagickTrue if all the pixels in the image have the |
| % same red, green, and blue intensities. |
| % |
| % The format of the IsImageGray method is: |
| % |
| % MagickBooleanType IsImageGray(const Image *image, |
| % ExceptionInfo *exception) |
| % |
| % A description of each parameter follows: |
| % |
| % o image: the image. |
| % |
| % o exception: return any errors or warnings in this structure. |
| % |
| */ |
| MagickExport MagickBooleanType IsImageGray(const Image *image, |
| ExceptionInfo *exception) |
| { |
| CacheView |
| *image_view; |
| |
| ImageType |
| type; |
| |
| register const Quantum |
| *p; |
| |
| register ssize_t |
| x; |
| |
| ssize_t |
| y; |
| |
| assert(image != (Image *) NULL); |
| assert(image->signature == MagickSignature); |
| if (image->debug != MagickFalse) |
| (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| if ((image->type == BilevelType) || (image->type == GrayscaleType) || |
| (image->type == GrayscaleMatteType)) |
| return(MagickTrue); |
| if (IsRGBColorspace(image->colorspace) == MagickFalse) |
| return(MagickFalse); |
| type=BilevelType; |
| image_view=AcquireCacheView(image); |
| for (y=0; y < (ssize_t) image->rows; y++) |
| { |
| p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| if (p == (const Quantum *) NULL) |
| break; |
| for (x=0; x < (ssize_t) image->columns; x++) |
| { |
| if (IsPixelGray(image,p) == MagickFalse) |
| { |
| type=UndefinedType; |
| break; |
| } |
| if ((type == BilevelType) && |
| (IsPixelMonochrome(image,p) == MagickFalse)) |
| type=GrayscaleType; |
| p+=GetPixelChannels(image); |
| } |
| if (type == UndefinedType) |
| break; |
| } |
| image_view=DestroyCacheView(image_view); |
| if (type == UndefinedType) |
| return(MagickFalse); |
| ((Image *) image)->type=type; |
| if ((type == GrayscaleType) && (image->matte != MagickFalse)) |
| ((Image *) image)->type=GrayscaleMatteType; |
| return(MagickTrue); |
| } |
| |
| /* |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % % |
| % % |
| % % |
| % I s I m a g e M o n o c h r o m e % |
| % % |
| % % |
| % % |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % |
| % IsImageMonochrome() returns MagickTrue if all the pixels in the image have |
| % the same red, green, and blue intensities and the intensity is either |
| % 0 or QuantumRange. |
| % |
| % The format of the IsImageMonochrome method is: |
| % |
| % MagickBooleanType IsImageMonochrome(const Image *image, |
| % ExceptionInfo *exception) |
| % |
| % A description of each parameter follows: |
| % |
| % o image: the image. |
| % |
| % o exception: return any errors or warnings in this structure. |
| % |
| */ |
| MagickExport MagickBooleanType IsImageMonochrome(const Image *image, |
| ExceptionInfo *exception) |
| { |
| CacheView |
| *image_view; |
| |
| ImageType |
| type; |
| |
| register ssize_t |
| x; |
| |
| register const Quantum |
| *p; |
| |
| ssize_t |
| y; |
| |
| assert(image != (Image *) NULL); |
| assert(image->signature == MagickSignature); |
| if (image->debug != MagickFalse) |
| (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| if (image->type == BilevelType) |
| return(MagickTrue); |
| if (IsRGBColorspace(image->colorspace) == MagickFalse) |
| return(MagickFalse); |
| type=BilevelType; |
| image_view=AcquireCacheView(image); |
| for (y=0; y < (ssize_t) image->rows; y++) |
| { |
| p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| if (p == (const Quantum *) NULL) |
| break; |
| for (x=0; x < (ssize_t) image->columns; x++) |
| { |
| if (IsPixelMonochrome(image,p) == MagickFalse) |
| { |
| type=UndefinedType; |
| break; |
| } |
| p+=GetPixelChannels(image); |
| } |
| if (type == UndefinedType) |
| break; |
| } |
| image_view=DestroyCacheView(image_view); |
| if (type == UndefinedType) |
| return(MagickFalse); |
| ((Image *) image)->type=type; |
| return(MagickTrue); |
| } |
| |
| /* |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % % |
| % % |
| % % |
| % I s I m a g e O p a q u e % |
| % % |
| % % |
| % % |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % |
| % IsImageOpaque() returns MagickTrue if none of the pixels in the image have |
| % an opacity value other than opaque (0). |
| % |
| % The format of the IsImageOpaque method is: |
| % |
| % MagickBooleanType IsImageOpaque(const Image *image, |
| % ExceptionInfo *exception) |
| % |
| % A description of each parameter follows: |
| % |
| % o image: the image. |
| % |
| % o exception: return any errors or warnings in this structure. |
| % |
| */ |
| MagickExport MagickBooleanType IsImageOpaque(const Image *image, |
| ExceptionInfo *exception) |
| { |
| CacheView |
| *image_view; |
| |
| register const Quantum |
| *p; |
| |
| register ssize_t |
| x; |
| |
| ssize_t |
| y; |
| |
| /* |
| Determine if image is opaque. |
| */ |
| assert(image != (Image *) NULL); |
| assert(image->signature == MagickSignature); |
| if (image->debug != MagickFalse) |
| (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| if (image->matte == MagickFalse) |
| return(MagickTrue); |
| image_view=AcquireCacheView(image); |
| for (y=0; y < (ssize_t) image->rows; y++) |
| { |
| p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| if (p == (const Quantum *) NULL) |
| break; |
| for (x=0; x < (ssize_t) image->columns; x++) |
| { |
| if (GetPixelAlpha(image,p) != OpaqueAlpha) |
| break; |
| p+=GetPixelChannels(image); |
| } |
| if (x < (ssize_t) image->columns) |
| break; |
| } |
| image_view=DestroyCacheView(image_view); |
| return(y < (ssize_t) image->rows ? MagickFalse : MagickTrue); |
| } |
| |
| /* |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % % |
| % % |
| % % |
| % S e t I m a g e D e p t h % |
| % % |
| % % |
| % % |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % |
| % SetImageDepth() sets the depth of the image. |
| % |
| % The format of the SetImageDepth method is: |
| % |
| % MagickBooleanType SetImageDepth(Image *image,const size_t depth, |
| % ExceptionInfo *exception) |
| % |
| % A description of each parameter follows: |
| % |
| % o image: the image. |
| % |
| % o channel: the channel. |
| % |
| % o depth: the image depth. |
| % |
| % o exception: return any errors or warnings in this structure. |
| % |
| */ |
| MagickExport MagickBooleanType SetImageDepth(Image *image, |
| const size_t depth,ExceptionInfo *exception) |
| { |
| CacheView |
| *image_view; |
| |
| MagickBooleanType |
| status; |
| |
| QuantumAny |
| range; |
| |
| ssize_t |
| y; |
| |
| assert(image != (Image *) NULL); |
| if (image->debug != MagickFalse) |
| (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| assert(image->signature == MagickSignature); |
| if (depth >= MAGICKCORE_QUANTUM_DEPTH) |
| { |
| image->depth=MAGICKCORE_QUANTUM_DEPTH; |
| return(MagickTrue); |
| } |
| range=GetQuantumRange(depth); |
| if (image->storage_class == PseudoClass) |
| { |
| register ssize_t |
| i; |
| |
| #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| #pragma omp parallel for schedule(static) shared(status) |
| #endif |
| for (i=0; i < (ssize_t) image->colors; i++) |
| { |
| if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) |
| image->colormap[i].red=(double) ScaleAnyToQuantum(ScaleQuantumToAny( |
| ClampToQuantum(image->colormap[i].red),range),range); |
| if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) |
| image->colormap[i].green=(double) ScaleAnyToQuantum(ScaleQuantumToAny( ClampToQuantum(image->colormap[i].green),range),range); |
| if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) |
| image->colormap[i].blue=(double) ScaleAnyToQuantum(ScaleQuantumToAny( |
| ClampToQuantum(image->colormap[i].blue),range),range); |
| if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) |
| image->colormap[i].alpha=(double) ScaleAnyToQuantum(ScaleQuantumToAny( |
| ClampToQuantum(image->colormap[i].alpha),range),range); |
| } |
| status=SyncImage(image,exception); |
| if (status != MagickFalse) |
| image->depth=depth; |
| return(status); |
| } |
| status=MagickTrue; |
| image_view=AcquireCacheView(image); |
| #if !defined(MAGICKCORE_HDRI_SUPPORT) |
| if (QuantumRange <= MaxMap) |
| { |
| Quantum |
| *depth_map; |
| |
| register ssize_t |
| i; |
| |
| /* |
| Scale pixels to desired (optimized with depth map). |
| */ |
| depth_map=(Quantum *) AcquireQuantumMemory(MaxMap+1,sizeof(*depth_map)); |
| if (depth_map == (Quantum *) NULL) |
| ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| for (i=0; i <= (ssize_t) MaxMap; i++) |
| depth_map[i]=ScaleAnyToQuantum(ScaleQuantumToAny((Quantum) i,range), |
| range); |
| #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| #pragma omp parallel for schedule(static,4) shared(status) |
| #endif |
| for (y=0; y < (ssize_t) image->rows; y++) |
| { |
| register ssize_t |
| x; |
| |
| register Quantum |
| *restrict q; |
| |
| if (status == MagickFalse) |
| continue; |
| q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| exception); |
| if (q == (Quantum *) NULL) |
| { |
| status=MagickFalse; |
| continue; |
| } |
| for (x=0; x < (ssize_t) image->columns; x++) |
| { |
| register ssize_t |
| i; |
| |
| for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| { |
| PixelChannel |
| channel; |
| |
| PixelTrait |
| traits; |
| |
| channel=GetPixelChannelMapChannel(image,i); |
| traits=GetPixelChannelMapTraits(image,channel); |
| if ((traits == UndefinedPixelTrait) || |
| (channel == IndexPixelChannel)) |
| continue; |
| q[i]=depth_map[ScaleQuantumToMap(q[i])]; |
| } |
| q+=GetPixelChannels(image); |
| } |
| if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| { |
| status=MagickFalse; |
| continue; |
| } |
| } |
| image_view=DestroyCacheView(image_view); |
| depth_map=(Quantum *) RelinquishMagickMemory(depth_map); |
| if (status != MagickFalse) |
| image->depth=depth; |
| return(status); |
| } |
| #endif |
| /* |
| Scale pixels to desired depth. |
| */ |
| #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| #pragma omp parallel for schedule(static,4) shared(status) |
| #endif |
| for (y=0; y < (ssize_t) image->rows; y++) |
| { |
| register ssize_t |
| x; |
| |
| register Quantum |
| *restrict q; |
| |
| if (status == MagickFalse) |
| continue; |
| q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
| if (q == (Quantum *) NULL) |
| { |
| status=MagickFalse; |
| continue; |
| } |
| for (x=0; x < (ssize_t) image->columns; x++) |
| { |
| register ssize_t |
| i; |
| |
| for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| { |
| PixelChannel |
| channel; |
| |
| PixelTrait |
| traits; |
| |
| channel=GetPixelChannelMapChannel(image,i); |
| traits=GetPixelChannelMapTraits(image,channel); |
| if ((traits == UndefinedPixelTrait) || (channel == IndexPixelChannel)) |
| continue; |
| q[i]=ScaleAnyToQuantum(ScaleQuantumToAny(q[i],range),range); |
| } |
| q+=GetPixelChannels(image); |
| } |
| if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| { |
| status=MagickFalse; |
| continue; |
| } |
| } |
| image_view=DestroyCacheView(image_view); |
| if (status != MagickFalse) |
| image->depth=depth; |
| return(status); |
| } |