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