cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % AAA TTTTT TTTTT RRRR IIIII BBBB U U TTTTT EEEEE % |
| 7 | % A A T T R R I B B U U T E % |
| 8 | % AAAAA T T RRRR I BBBB U U T EEE % |
| 9 | % A A T T R R I B B U U T E % |
| 10 | % A A T T R R IIIII BBBB UUU T EEEEE % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Get / Set Image Attributes % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % October 2002 % |
| 18 | % % |
| 19 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | % |
| 38 | */ |
| 39 | |
| 40 | /* |
| 41 | Include declarations. |
| 42 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 43 | #include "MagickCore/studio.h" |
| 44 | #include "MagickCore/attribute.h" |
| 45 | #include "MagickCore/blob.h" |
| 46 | #include "MagickCore/blob-private.h" |
| 47 | #include "MagickCore/cache.h" |
| 48 | #include "MagickCore/cache-view.h" |
| 49 | #include "MagickCore/client.h" |
| 50 | #include "MagickCore/color.h" |
| 51 | #include "MagickCore/color-private.h" |
| 52 | #include "MagickCore/colormap.h" |
| 53 | #include "MagickCore/colormap-private.h" |
| 54 | #include "MagickCore/colorspace.h" |
| 55 | #include "MagickCore/composite.h" |
| 56 | #include "MagickCore/composite-private.h" |
| 57 | #include "MagickCore/constitute.h" |
| 58 | #include "MagickCore/draw.h" |
| 59 | #include "MagickCore/draw-private.h" |
| 60 | #include "MagickCore/effect.h" |
| 61 | #include "MagickCore/enhance.h" |
| 62 | #include "MagickCore/exception.h" |
| 63 | #include "MagickCore/exception-private.h" |
| 64 | #include "MagickCore/geometry.h" |
| 65 | #include "MagickCore/histogram.h" |
| 66 | #include "MagickCore/identify.h" |
| 67 | #include "MagickCore/image.h" |
| 68 | #include "MagickCore/image-private.h" |
| 69 | #include "MagickCore/list.h" |
| 70 | #include "MagickCore/log.h" |
| 71 | #include "MagickCore/memory_.h" |
| 72 | #include "MagickCore/magick.h" |
| 73 | #include "MagickCore/monitor.h" |
| 74 | #include "MagickCore/monitor-private.h" |
| 75 | #include "MagickCore/paint.h" |
| 76 | #include "MagickCore/pixel.h" |
| 77 | #include "MagickCore/pixel-accessor.h" |
| 78 | #include "MagickCore/property.h" |
| 79 | #include "MagickCore/quantize.h" |
| 80 | #include "MagickCore/quantum-private.h" |
| 81 | #include "MagickCore/random_.h" |
| 82 | #include "MagickCore/resource_.h" |
| 83 | #include "MagickCore/semaphore.h" |
| 84 | #include "MagickCore/segment.h" |
| 85 | #include "MagickCore/splay-tree.h" |
| 86 | #include "MagickCore/string_.h" |
| 87 | #include "MagickCore/thread-private.h" |
| 88 | #include "MagickCore/threshold.h" |
| 89 | #include "MagickCore/transform.h" |
| 90 | #include "MagickCore/utility.h" |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 91 | |
| 92 | /* |
| 93 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 94 | % % |
| 95 | % % |
| 96 | % % |
| 97 | + G e t I m a g e B o u n d i n g B o x % |
| 98 | % % |
| 99 | % % |
| 100 | % % |
| 101 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 102 | % |
| 103 | % GetImageBoundingBox() returns the bounding box of an image canvas. |
| 104 | % |
| 105 | % The format of the GetImageBoundingBox method is: |
| 106 | % |
| 107 | % RectangleInfo GetImageBoundingBox(const Image *image, |
| 108 | % ExceptionInfo *exception) |
| 109 | % |
| 110 | % A description of each parameter follows: |
| 111 | % |
| 112 | % o bounds: Method GetImageBoundingBox returns the bounding box of an |
| 113 | % image canvas. |
| 114 | % |
| 115 | % o image: the image. |
| 116 | % |
| 117 | % o exception: return any errors or warnings in this structure. |
| 118 | % |
| 119 | */ |
| 120 | MagickExport RectangleInfo GetImageBoundingBox(const Image *image, |
| 121 | ExceptionInfo *exception) |
| 122 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 123 | CacheView |
| 124 | *image_view; |
| 125 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 126 | MagickBooleanType |
| 127 | status; |
| 128 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 129 | PixelInfo |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 130 | target[3], |
| 131 | zero; |
| 132 | |
| 133 | RectangleInfo |
| 134 | bounds; |
| 135 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 136 | register const Quantum |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 137 | *p; |
| 138 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 139 | ssize_t |
| 140 | y; |
| 141 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 142 | assert(image != (Image *) NULL); |
| 143 | assert(image->signature == MagickSignature); |
| 144 | if (image->debug != MagickFalse) |
| 145 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 146 | bounds.width=0; |
| 147 | bounds.height=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 148 | bounds.x=(ssize_t) image->columns; |
| 149 | bounds.y=(ssize_t) image->rows; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 150 | GetPixelInfo(image,&target[0]); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 151 | image_view=AcquireCacheView(image); |
| 152 | p=GetCacheViewVirtualPixels(image_view,0,0,1,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 153 | if (p == (const Quantum *) NULL) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 154 | { |
| 155 | image_view=DestroyCacheView(image_view); |
| 156 | return(bounds); |
| 157 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 158 | SetPixelInfo(image,p,&target[0]); |
| 159 | GetPixelInfo(image,&target[1]); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 160 | p=GetCacheViewVirtualPixels(image_view,(ssize_t) image->columns-1,0,1,1, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 161 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 162 | SetPixelInfo(image,p,&target[1]); |
| 163 | GetPixelInfo(image,&target[2]); |
cristy | 4cb39ab | 2010-06-07 13:59:16 +0000 | [diff] [blame] | 164 | p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) image->rows-1,1,1, |
| 165 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 166 | SetPixelInfo(image,p,&target[2]); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 167 | status=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 168 | GetPixelInfo(image,&zero); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 169 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 170 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 171 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 172 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 173 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 174 | PixelInfo |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 175 | pixel; |
| 176 | |
| 177 | RectangleInfo |
| 178 | bounding_box; |
| 179 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 180 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 181 | *restrict p; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 182 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 183 | register ssize_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 184 | x; |
| 185 | |
| 186 | if (status == MagickFalse) |
| 187 | continue; |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 188 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 189 | # pragma omp critical (MagickCore_GetImageBoundingBox) |
| 190 | #endif |
| 191 | bounding_box=bounds; |
| 192 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 193 | if (p == (const Quantum *) NULL) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 194 | { |
| 195 | status=MagickFalse; |
| 196 | continue; |
| 197 | } |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 198 | pixel=zero; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 199 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 200 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 201 | SetPixelInfo(image,p,&pixel); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 202 | if ((x < bounding_box.x) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 203 | (IsFuzzyEquivalencePixelInfo(&pixel,&target[0]) == MagickFalse)) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 204 | bounding_box.x=x; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 205 | if ((x > (ssize_t) bounding_box.width) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 206 | (IsFuzzyEquivalencePixelInfo(&pixel,&target[1]) == MagickFalse)) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 207 | bounding_box.width=(size_t) x; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 208 | if ((y < bounding_box.y) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 209 | (IsFuzzyEquivalencePixelInfo(&pixel,&target[0]) == MagickFalse)) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 210 | bounding_box.y=y; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 211 | if ((y > (ssize_t) bounding_box.height) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 212 | (IsFuzzyEquivalencePixelInfo(&pixel,&target[2]) == MagickFalse)) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 213 | bounding_box.height=(size_t) y; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 214 | p+=GetPixelChannels(image); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 215 | } |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 216 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 217 | # pragma omp critical (MagickCore_GetImageBoundingBox) |
| 218 | #endif |
| 219 | { |
| 220 | if (bounding_box.x < bounds.x) |
| 221 | bounds.x=bounding_box.x; |
| 222 | if (bounding_box.y < bounds.y) |
| 223 | bounds.y=bounding_box.y; |
| 224 | if (bounding_box.width > bounds.width) |
| 225 | bounds.width=bounding_box.width; |
| 226 | if (bounding_box.height > bounds.height) |
| 227 | bounds.height=bounding_box.height; |
| 228 | } |
| 229 | } |
| 230 | image_view=DestroyCacheView(image_view); |
| 231 | if ((bounds.width == 0) || (bounds.height == 0)) |
| 232 | (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, |
| 233 | "GeometryDoesNotContainImage","`%s'",image->filename); |
| 234 | else |
| 235 | { |
| 236 | bounds.width-=(bounds.x-1); |
| 237 | bounds.height-=(bounds.y-1); |
| 238 | } |
| 239 | return(bounds); |
| 240 | } |
| 241 | |
| 242 | /* |
| 243 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 244 | % % |
| 245 | % % |
| 246 | % % |
| 247 | % G e t I m a g e C h a n n e l D e p t h % |
| 248 | % % |
| 249 | % % |
| 250 | % % |
| 251 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 252 | % |
| 253 | % GetImageChannelDepth() returns the depth of a particular image channel. |
| 254 | % |
| 255 | % The format of the GetImageChannelDepth method is: |
| 256 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 257 | % size_t GetImageDepth(const Image *image,ExceptionInfo *exception) |
| 258 | % size_t GetImageChannelDepth(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 259 | % const ChannelType channel,ExceptionInfo *exception) |
| 260 | % |
| 261 | % A description of each parameter follows: |
| 262 | % |
| 263 | % o image: the image. |
| 264 | % |
| 265 | % o channel: the channel. |
| 266 | % |
| 267 | % o exception: return any errors or warnings in this structure. |
| 268 | % |
| 269 | */ |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 270 | MagickExport size_t GetImageDepth(const Image *image,ExceptionInfo *exception) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 271 | { |
cristy | 9a9230e | 2011-04-26 14:56:14 +0000 | [diff] [blame] | 272 | return(GetImageChannelDepth(image,CompositeChannels,exception)); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 273 | } |
| 274 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 275 | MagickExport size_t GetImageChannelDepth(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 276 | const ChannelType channel,ExceptionInfo *exception) |
| 277 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 278 | CacheView |
| 279 | *image_view; |
| 280 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 281 | MagickBooleanType |
| 282 | status; |
| 283 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 284 | register ssize_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 285 | id; |
| 286 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 287 | size_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 288 | *current_depth, |
| 289 | depth, |
| 290 | number_threads; |
| 291 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 292 | ssize_t |
| 293 | y; |
| 294 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 295 | /* |
| 296 | Compute image depth. |
| 297 | */ |
| 298 | assert(image != (Image *) NULL); |
| 299 | assert(image->signature == MagickSignature); |
| 300 | if (image->debug != MagickFalse) |
| 301 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 302 | number_threads=GetOpenMPMaximumThreads(); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 303 | current_depth=(size_t *) AcquireQuantumMemory(number_threads, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 304 | sizeof(*current_depth)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 305 | if (current_depth == (size_t *) NULL) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 306 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 307 | status=MagickTrue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 308 | for (id=0; id < (ssize_t) number_threads; id++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 309 | current_depth[id]=1; |
| 310 | if ((image->storage_class == PseudoClass) && (image->matte == MagickFalse)) |
| 311 | { |
| 312 | register const PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 313 | *restrict p; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 314 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 315 | register ssize_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 316 | i; |
| 317 | |
| 318 | p=image->colormap; |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 319 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 320 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 321 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 322 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 323 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 324 | const int |
| 325 | id = GetOpenMPThreadId(); |
| 326 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 327 | if (status == MagickFalse) |
| 328 | continue; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 329 | while (current_depth[id] < MAGICKCORE_QUANTUM_DEPTH) |
| 330 | { |
| 331 | MagickStatusType |
| 332 | status; |
| 333 | |
| 334 | QuantumAny |
cristy | b6d6f7c | 2010-06-09 13:17:57 +0000 | [diff] [blame] | 335 | range; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 336 | |
| 337 | status=0; |
cristy | b6d6f7c | 2010-06-09 13:17:57 +0000 | [diff] [blame] | 338 | range=GetQuantumRange(current_depth[id]); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 339 | if ((GetPixelRedTraits(image) & ActivePixelTrait) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 340 | status|=p->red != ScaleAnyToQuantum(ScaleQuantumToAny(p->red, |
cristy | b6d6f7c | 2010-06-09 13:17:57 +0000 | [diff] [blame] | 341 | range),range); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 342 | if ((GetPixelGreenTraits(image) & ActivePixelTrait) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 343 | status|=p->green != ScaleAnyToQuantum(ScaleQuantumToAny(p->green, |
cristy | b6d6f7c | 2010-06-09 13:17:57 +0000 | [diff] [blame] | 344 | range),range); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 345 | if ((GetPixelBlueTraits(image) & ActivePixelTrait) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 346 | status|=p->blue != ScaleAnyToQuantum(ScaleQuantumToAny(p->blue, |
cristy | b6d6f7c | 2010-06-09 13:17:57 +0000 | [diff] [blame] | 347 | range),range); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 348 | if (status == 0) |
| 349 | break; |
| 350 | current_depth[id]++; |
| 351 | } |
| 352 | p++; |
| 353 | } |
| 354 | depth=current_depth[0]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 355 | for (id=1; id < (ssize_t) number_threads; id++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 356 | if (depth < current_depth[id]) |
| 357 | depth=current_depth[id]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 358 | current_depth=(size_t *) RelinquishMagickMemory(current_depth); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 359 | return(depth); |
| 360 | } |
| 361 | image_view=AcquireCacheView(image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 362 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 363 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 364 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 365 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 366 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 367 | const int |
| 368 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 369 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 370 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 371 | *restrict p; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 372 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 373 | register ssize_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 374 | x; |
| 375 | |
| 376 | if (status == MagickFalse) |
| 377 | continue; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 378 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 379 | if (p == (const Quantum *) NULL) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 380 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 381 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 382 | { |
| 383 | while (current_depth[id] < MAGICKCORE_QUANTUM_DEPTH) |
| 384 | { |
| 385 | MagickStatusType |
| 386 | status; |
| 387 | |
| 388 | QuantumAny |
cristy | b6d6f7c | 2010-06-09 13:17:57 +0000 | [diff] [blame] | 389 | range; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 390 | |
| 391 | status=0; |
cristy | b6d6f7c | 2010-06-09 13:17:57 +0000 | [diff] [blame] | 392 | range=GetQuantumRange(current_depth[id]); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 393 | if ((GetPixelRedTraits(image) & ActivePixelTrait) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 394 | status|=GetPixelRed(image,p) != ScaleAnyToQuantum(ScaleQuantumToAny( |
| 395 | GetPixelRed(image,p),range),range); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 396 | if ((GetPixelGreenTraits(image) & ActivePixelTrait) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 397 | status|=GetPixelGreen(image,p) != ScaleAnyToQuantum(ScaleQuantumToAny( |
| 398 | GetPixelGreen(image,p),range),range); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 399 | if ((GetPixelBlueTraits(image) & ActivePixelTrait) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 400 | status|=GetPixelBlue(image,p) != ScaleAnyToQuantum(ScaleQuantumToAny( |
| 401 | GetPixelBlue(image,p),range),range); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 402 | if (((GetPixelAlphaTraits(image) & ActivePixelTrait) != 0) && |
| 403 | (image->matte != MagickFalse)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 404 | status|=GetPixelAlpha(image,p) != ScaleAnyToQuantum(ScaleQuantumToAny( |
| 405 | GetPixelAlpha(image,p),range),range); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 406 | if (((GetPixelBlackTraits(image) & ActivePixelTrait) != 0) && |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 407 | (image->colorspace == CMYKColorspace)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 408 | status|=GetPixelBlack(image,p) != ScaleAnyToQuantum(ScaleQuantumToAny( |
| 409 | GetPixelBlack(image,p),range),range); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 410 | if (status == 0) |
| 411 | break; |
| 412 | current_depth[id]++; |
| 413 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 414 | p+=GetPixelChannels(image); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 415 | } |
| 416 | if (current_depth[id] == MAGICKCORE_QUANTUM_DEPTH) |
| 417 | status=MagickFalse; |
| 418 | } |
| 419 | image_view=DestroyCacheView(image_view); |
| 420 | depth=current_depth[0]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 421 | for (id=1; id < (ssize_t) number_threads; id++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 422 | if (depth < current_depth[id]) |
| 423 | depth=current_depth[id]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 424 | current_depth=(size_t *) RelinquishMagickMemory(current_depth); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 425 | return(depth); |
| 426 | } |
| 427 | |
| 428 | /* |
| 429 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 430 | % % |
| 431 | % % |
| 432 | % % |
| 433 | % G e t I m a g e Q u a n t u m D e p t h % |
| 434 | % % |
| 435 | % % |
| 436 | % % |
| 437 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 438 | % |
| 439 | % GetImageQuantumDepth() returns the depth of the image rounded to a legal |
| 440 | % quantum depth: 8, 16, or 32. |
| 441 | % |
| 442 | % The format of the GetImageQuantumDepth method is: |
| 443 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 444 | % size_t GetImageQuantumDepth(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 445 | % const MagickBooleanType constrain) |
| 446 | % |
| 447 | % A description of each parameter follows: |
| 448 | % |
| 449 | % o image: the image. |
| 450 | % |
| 451 | % o constrain: A value other than MagickFalse, constrains the depth to |
| 452 | % a maximum of MAGICKCORE_QUANTUM_DEPTH. |
| 453 | % |
| 454 | */ |
| 455 | |
| 456 | static inline double MagickMin(const double x,const double y) |
| 457 | { |
| 458 | if (x < y) |
| 459 | return(x); |
| 460 | return(y); |
| 461 | } |
| 462 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 463 | MagickExport size_t GetImageQuantumDepth(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 464 | const MagickBooleanType constrain) |
| 465 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 466 | size_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 467 | depth; |
| 468 | |
| 469 | depth=image->depth; |
| 470 | if (depth <= 8) |
| 471 | depth=8; |
| 472 | else |
| 473 | if (depth <= 16) |
| 474 | depth=16; |
| 475 | else |
| 476 | if (depth <= 32) |
| 477 | depth=32; |
| 478 | else |
| 479 | if (depth <= 64) |
| 480 | depth=64; |
| 481 | if (constrain != MagickFalse) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 482 | depth=(size_t) MagickMin((double) depth,(double) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 483 | MAGICKCORE_QUANTUM_DEPTH); |
| 484 | return(depth); |
| 485 | } |
| 486 | |
| 487 | /* |
| 488 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 489 | % % |
| 490 | % % |
| 491 | % % |
| 492 | % G e t I m a g e T y p e % |
| 493 | % % |
| 494 | % % |
| 495 | % % |
| 496 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 497 | % |
| 498 | % GetImageType() returns the potential type of image: |
| 499 | % |
| 500 | % Bilevel Grayscale GrayscaleMatte |
| 501 | % Palette PaletteMatte TrueColor |
| 502 | % TrueColorMatte ColorSeparation ColorSeparationMatte |
| 503 | % |
| 504 | % To ensure the image type matches its potential, use SetImageType(): |
| 505 | % |
| 506 | % (void) SetImageType(image,GetImageType(image)); |
| 507 | % |
| 508 | % The format of the GetImageType method is: |
| 509 | % |
| 510 | % ImageType GetImageType(const Image *image,ExceptionInfo *exception) |
| 511 | % |
| 512 | % A description of each parameter follows: |
| 513 | % |
| 514 | % o image: the image. |
| 515 | % |
| 516 | % o exception: return any errors or warnings in this structure. |
| 517 | % |
| 518 | */ |
| 519 | MagickExport ImageType GetImageType(const Image *image,ExceptionInfo *exception) |
| 520 | { |
| 521 | assert(image != (Image *) NULL); |
| 522 | assert(image->signature == MagickSignature); |
| 523 | if (image->debug != MagickFalse) |
| 524 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 525 | if (image->colorspace == CMYKColorspace) |
| 526 | { |
| 527 | if (image->matte == MagickFalse) |
| 528 | return(ColorSeparationType); |
| 529 | return(ColorSeparationMatteType); |
| 530 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 531 | if (IsImageMonochrome(image,exception) != MagickFalse) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 532 | return(BilevelType); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 533 | if (IsImageGray(image,exception) != MagickFalse) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 534 | { |
| 535 | if (image->matte != MagickFalse) |
| 536 | return(GrayscaleMatteType); |
| 537 | return(GrayscaleType); |
| 538 | } |
| 539 | if (IsPaletteImage(image,exception) != MagickFalse) |
| 540 | { |
| 541 | if (image->matte != MagickFalse) |
| 542 | return(PaletteMatteType); |
| 543 | return(PaletteType); |
| 544 | } |
| 545 | if (image->matte != MagickFalse) |
| 546 | return(TrueColorMatteType); |
| 547 | return(TrueColorType); |
| 548 | } |
| 549 | |
| 550 | /* |
| 551 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 552 | % % |
| 553 | % % |
| 554 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 555 | % I s I m a g e G r a y % |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 556 | % % |
| 557 | % % |
| 558 | % % |
| 559 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 560 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 561 | % IsImageGray() returns MagickTrue if all the pixels in the image have the |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 562 | % same red, green, and blue intensities. |
| 563 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 564 | % The format of the IsImageGray method is: |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 565 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 566 | % MagickBooleanType IsImageGray(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 567 | % ExceptionInfo *exception) |
| 568 | % |
| 569 | % A description of each parameter follows: |
| 570 | % |
| 571 | % o image: the image. |
| 572 | % |
| 573 | % o exception: return any errors or warnings in this structure. |
| 574 | % |
| 575 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 576 | MagickExport MagickBooleanType IsImageGray(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 577 | ExceptionInfo *exception) |
| 578 | { |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 579 | CacheView |
| 580 | *image_view; |
| 581 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 582 | ImageType |
| 583 | type; |
| 584 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 585 | register const Quantum |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 586 | *p; |
| 587 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 588 | register ssize_t |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 589 | x; |
| 590 | |
cristy | 95802a7 | 2010-09-05 19:07:17 +0000 | [diff] [blame] | 591 | ssize_t |
| 592 | y; |
| 593 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 594 | assert(image != (Image *) NULL); |
| 595 | assert(image->signature == MagickSignature); |
| 596 | if (image->debug != MagickFalse) |
| 597 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 598 | if ((image->type == BilevelType) || (image->type == GrayscaleType) || |
| 599 | (image->type == GrayscaleMatteType)) |
| 600 | return(MagickTrue); |
| 601 | if (image->colorspace == CMYKColorspace) |
| 602 | return(MagickFalse); |
| 603 | type=BilevelType; |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 604 | image_view=AcquireCacheView(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 605 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 606 | { |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 607 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 608 | if (p == (const Quantum *) NULL) |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 609 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 610 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 611 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 612 | if (IsPixelGray(image,p) == MagickFalse) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 613 | { |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 614 | type=UndefinedType; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 615 | break; |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 616 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 617 | if ((type == BilevelType) && |
| 618 | (IsPixelMonochrome(image,p) == MagickFalse)) |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 619 | type=GrayscaleType; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 620 | p+=GetPixelChannels(image); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 621 | } |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 622 | if (type == UndefinedType) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 623 | break; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 624 | } |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 625 | image_view=DestroyCacheView(image_view); |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 626 | if (type == UndefinedType) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 627 | return(MagickFalse); |
| 628 | ((Image *) image)->type=type; |
| 629 | if ((type == GrayscaleType) && (image->matte != MagickFalse)) |
| 630 | ((Image *) image)->type=GrayscaleMatteType; |
| 631 | return(MagickTrue); |
| 632 | } |
| 633 | |
| 634 | /* |
| 635 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 636 | % % |
| 637 | % % |
| 638 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 639 | % I s I m a g e M o n o c h r o m e % |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 640 | % % |
| 641 | % % |
| 642 | % % |
| 643 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 644 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 645 | % IsImageMonochrome() returns MagickTrue if all the pixels in the image have |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 646 | % the same red, green, and blue intensities and the intensity is either |
| 647 | % 0 or QuantumRange. |
| 648 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 649 | % The format of the IsImageMonochrome method is: |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 650 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 651 | % MagickBooleanType IsImageMonochrome(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 652 | % ExceptionInfo *exception) |
| 653 | % |
| 654 | % A description of each parameter follows: |
| 655 | % |
| 656 | % o image: the image. |
| 657 | % |
| 658 | % o exception: return any errors or warnings in this structure. |
| 659 | % |
| 660 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 661 | MagickExport MagickBooleanType IsImageMonochrome(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 662 | ExceptionInfo *exception) |
| 663 | { |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 664 | CacheView |
| 665 | *image_view; |
| 666 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 667 | ImageType |
| 668 | type; |
| 669 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 670 | register ssize_t |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 671 | x; |
| 672 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 673 | register const Quantum |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 674 | *p; |
| 675 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 676 | ssize_t |
| 677 | y; |
| 678 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 679 | assert(image != (Image *) NULL); |
| 680 | assert(image->signature == MagickSignature); |
| 681 | if (image->debug != MagickFalse) |
| 682 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 683 | if (image->type == BilevelType) |
| 684 | return(MagickTrue); |
| 685 | if (image->colorspace == CMYKColorspace) |
| 686 | return(MagickFalse); |
| 687 | type=BilevelType; |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 688 | image_view=AcquireCacheView(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 689 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 690 | { |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 691 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 692 | if (p == (const Quantum *) NULL) |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 693 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 694 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 695 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 696 | if (IsPixelMonochrome(image,p) == MagickFalse) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 697 | { |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 698 | type=UndefinedType; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 699 | break; |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 700 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 701 | p+=GetPixelChannels(image); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 702 | } |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 703 | if (type == UndefinedType) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 704 | break; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 705 | } |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 706 | image_view=DestroyCacheView(image_view); |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 707 | if (type == UndefinedType) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 708 | return(MagickFalse); |
| 709 | ((Image *) image)->type=type; |
| 710 | return(MagickTrue); |
| 711 | } |
| 712 | |
| 713 | /* |
| 714 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 715 | % % |
| 716 | % % |
| 717 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 718 | % I s I m a g e O p a q u e % |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 719 | % % |
| 720 | % % |
| 721 | % % |
| 722 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 723 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 724 | % IsImageOpaque() returns MagickTrue if none of the pixels in the image have |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 725 | % an opacity value other than opaque (0). |
| 726 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 727 | % The format of the IsImageOpaque method is: |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 728 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 729 | % MagickBooleanType IsImageOpaque(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 730 | % ExceptionInfo *exception) |
| 731 | % |
| 732 | % A description of each parameter follows: |
| 733 | % |
| 734 | % o image: the image. |
| 735 | % |
| 736 | % o exception: return any errors or warnings in this structure. |
| 737 | % |
| 738 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 739 | MagickExport MagickBooleanType IsImageOpaque(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 740 | ExceptionInfo *exception) |
| 741 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 742 | CacheView |
| 743 | *image_view; |
| 744 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 745 | register const Quantum |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 746 | *p; |
| 747 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 748 | register ssize_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 749 | x; |
| 750 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 751 | ssize_t |
| 752 | y; |
| 753 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 754 | /* |
| 755 | Determine if image is opaque. |
| 756 | */ |
| 757 | assert(image != (Image *) NULL); |
| 758 | assert(image->signature == MagickSignature); |
| 759 | if (image->debug != MagickFalse) |
| 760 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 761 | if (image->matte == MagickFalse) |
| 762 | return(MagickTrue); |
| 763 | image_view=AcquireCacheView(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 764 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 765 | { |
| 766 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 767 | if (p == (const Quantum *) NULL) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 768 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 769 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 770 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 771 | if (GetPixelAlpha(image,p) != OpaqueAlpha) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 772 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 773 | p+=GetPixelChannels(image); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 774 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 775 | if (x < (ssize_t) image->columns) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 776 | break; |
| 777 | } |
| 778 | image_view=DestroyCacheView(image_view); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 779 | return(y < (ssize_t) image->rows ? MagickFalse : MagickTrue); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | /* |
| 783 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 784 | % % |
| 785 | % % |
| 786 | % % |
| 787 | % S e t I m a g e C h a n n e l D e p t h % |
| 788 | % % |
| 789 | % % |
| 790 | % % |
| 791 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 792 | % |
| 793 | % SetImageChannelDepth() sets the depth of the image. |
| 794 | % |
| 795 | % The format of the SetImageChannelDepth method is: |
| 796 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 797 | % MagickBooleanType SetImageDepth(Image *image,const size_t depth) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 798 | % MagickBooleanType SetImageChannelDepth(Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 799 | % const ChannelType channel,const size_t depth) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 800 | % |
| 801 | % A description of each parameter follows: |
| 802 | % |
| 803 | % o image: the image. |
| 804 | % |
| 805 | % o channel: the channel. |
| 806 | % |
| 807 | % o depth: the image depth. |
| 808 | % |
| 809 | */ |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 810 | MagickExport MagickBooleanType SetImageDepth(Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 811 | const size_t depth) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 812 | { |
cristy | 9a9230e | 2011-04-26 14:56:14 +0000 | [diff] [blame] | 813 | return(SetImageChannelDepth(image,CompositeChannels,depth)); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | MagickExport MagickBooleanType SetImageChannelDepth(Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 817 | const ChannelType channel,const size_t depth) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 818 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 819 | CacheView |
| 820 | *image_view; |
| 821 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 822 | ExceptionInfo |
| 823 | *exception; |
| 824 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 825 | MagickBooleanType |
| 826 | status; |
| 827 | |
| 828 | QuantumAny |
cristy | b6d6f7c | 2010-06-09 13:17:57 +0000 | [diff] [blame] | 829 | range; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 830 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 831 | ssize_t |
| 832 | y; |
| 833 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 834 | assert(image != (Image *) NULL); |
| 835 | if (image->debug != MagickFalse) |
| 836 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 837 | assert(image->signature == MagickSignature); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 838 | if (GetImageDepth(image,&image->exception) <= (size_t) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 839 | MagickMin((double) depth,(double) MAGICKCORE_QUANTUM_DEPTH)) |
| 840 | { |
| 841 | image->depth=depth; |
| 842 | return(MagickTrue); |
| 843 | } |
| 844 | /* |
| 845 | Scale pixels to desired depth. |
| 846 | */ |
| 847 | status=MagickTrue; |
cristy | b6d6f7c | 2010-06-09 13:17:57 +0000 | [diff] [blame] | 848 | range=GetQuantumRange(depth); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 849 | exception=(&image->exception); |
| 850 | image_view=AcquireCacheView(image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 851 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 852 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 853 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 854 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 855 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 856 | register ssize_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 857 | x; |
| 858 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 859 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 860 | *restrict q; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 861 | |
| 862 | if (status == MagickFalse) |
| 863 | continue; |
| 864 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 865 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 866 | if (q == (const Quantum *) NULL) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 867 | { |
| 868 | status=MagickFalse; |
| 869 | continue; |
| 870 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 871 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 872 | { |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 873 | if ((GetPixelRedTraits(image) & ActivePixelTrait) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 874 | SetPixelRed(image,ScaleAnyToQuantum(ScaleQuantumToAny( |
| 875 | GetPixelRed(image,q),range),range),q); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 876 | if ((GetPixelGreenTraits(image) & ActivePixelTrait) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 877 | SetPixelGreen(image,ScaleAnyToQuantum(ScaleQuantumToAny( |
| 878 | GetPixelGreen(image,q),range),range),q); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 879 | if ((GetPixelBlueTraits(image) & ActivePixelTrait) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 880 | SetPixelBlue(image,ScaleAnyToQuantum(ScaleQuantumToAny( |
| 881 | GetPixelBlue(image,q),range),range),q); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 882 | if (((GetPixelBlackTraits(image) & ActivePixelTrait) != 0) && |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 883 | (image->colorspace == CMYKColorspace)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 884 | SetPixelBlack(image,ScaleAnyToQuantum(ScaleQuantumToAny( |
| 885 | GetPixelBlack(image,q),range),range),q); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 886 | if (((GetPixelAlphaTraits(image) & ActivePixelTrait) != 0) && |
| 887 | (image->matte != MagickFalse)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 888 | SetPixelAlpha(image,ScaleAnyToQuantum(ScaleQuantumToAny( |
| 889 | GetPixelAlpha(image,q),range),range),q); |
| 890 | q+=GetPixelChannels(image); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 891 | } |
| 892 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 893 | { |
| 894 | status=MagickFalse; |
| 895 | continue; |
| 896 | } |
| 897 | } |
| 898 | image_view=DestroyCacheView(image_view); |
| 899 | if (image->storage_class == PseudoClass) |
| 900 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 901 | register ssize_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 902 | i; |
| 903 | |
| 904 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 905 | *restrict p; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 906 | |
| 907 | p=image->colormap; |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 908 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 909 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 910 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 911 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 912 | { |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 913 | if ((GetPixelRedTraits(image) & ActivePixelTrait) != 0) |
cristy | 9384eed | 2011-06-13 14:16:32 +0000 | [diff] [blame] | 914 | p->red=ScaleAnyToQuantum(ScaleQuantumToAny(p->red,range),range); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 915 | if ((GetPixelGreenTraits(image) & ActivePixelTrait) != 0) |
cristy | 9384eed | 2011-06-13 14:16:32 +0000 | [diff] [blame] | 916 | p->green=ScaleAnyToQuantum(ScaleQuantumToAny(p->green,range),range); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 917 | if ((GetPixelBlueTraits(image) & ActivePixelTrait) != 0) |
cristy | 9384eed | 2011-06-13 14:16:32 +0000 | [diff] [blame] | 918 | p->blue=ScaleAnyToQuantum(ScaleQuantumToAny(p->blue,range),range); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame^] | 919 | if ((GetPixelAlphaTraits(image) & ActivePixelTrait) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 920 | p->alpha=ScaleAnyToQuantum(ScaleQuantumToAny(p->alpha,range),range); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 921 | p++; |
| 922 | } |
| 923 | } |
| 924 | image->depth=depth; |
| 925 | return(status); |
| 926 | } |