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 | 1454be7 | 2011-12-19 01:52:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2012 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" |
cristy | cca1bfa | 2011-09-12 12:39:53 +0000 | [diff] [blame] | 55 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 56 | #include "MagickCore/composite.h" |
| 57 | #include "MagickCore/composite-private.h" |
| 58 | #include "MagickCore/constitute.h" |
| 59 | #include "MagickCore/draw.h" |
| 60 | #include "MagickCore/draw-private.h" |
| 61 | #include "MagickCore/effect.h" |
| 62 | #include "MagickCore/enhance.h" |
| 63 | #include "MagickCore/exception.h" |
| 64 | #include "MagickCore/exception-private.h" |
| 65 | #include "MagickCore/geometry.h" |
| 66 | #include "MagickCore/histogram.h" |
| 67 | #include "MagickCore/identify.h" |
| 68 | #include "MagickCore/image.h" |
| 69 | #include "MagickCore/image-private.h" |
| 70 | #include "MagickCore/list.h" |
| 71 | #include "MagickCore/log.h" |
| 72 | #include "MagickCore/memory_.h" |
| 73 | #include "MagickCore/magick.h" |
| 74 | #include "MagickCore/monitor.h" |
| 75 | #include "MagickCore/monitor-private.h" |
| 76 | #include "MagickCore/paint.h" |
| 77 | #include "MagickCore/pixel.h" |
| 78 | #include "MagickCore/pixel-accessor.h" |
| 79 | #include "MagickCore/property.h" |
| 80 | #include "MagickCore/quantize.h" |
| 81 | #include "MagickCore/quantum-private.h" |
| 82 | #include "MagickCore/random_.h" |
| 83 | #include "MagickCore/resource_.h" |
| 84 | #include "MagickCore/semaphore.h" |
| 85 | #include "MagickCore/segment.h" |
| 86 | #include "MagickCore/splay-tree.h" |
| 87 | #include "MagickCore/string_.h" |
| 88 | #include "MagickCore/thread-private.h" |
| 89 | #include "MagickCore/threshold.h" |
| 90 | #include "MagickCore/transform.h" |
| 91 | #include "MagickCore/utility.h" |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 92 | |
| 93 | /* |
| 94 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 95 | % % |
| 96 | % % |
| 97 | % % |
| 98 | + G e t I m a g e B o u n d i n g B o x % |
| 99 | % % |
| 100 | % % |
| 101 | % % |
| 102 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 103 | % |
| 104 | % GetImageBoundingBox() returns the bounding box of an image canvas. |
| 105 | % |
| 106 | % The format of the GetImageBoundingBox method is: |
| 107 | % |
| 108 | % RectangleInfo GetImageBoundingBox(const Image *image, |
| 109 | % ExceptionInfo *exception) |
| 110 | % |
| 111 | % A description of each parameter follows: |
| 112 | % |
| 113 | % o bounds: Method GetImageBoundingBox returns the bounding box of an |
| 114 | % image canvas. |
| 115 | % |
| 116 | % o image: the image. |
| 117 | % |
| 118 | % o exception: return any errors or warnings in this structure. |
| 119 | % |
| 120 | */ |
| 121 | MagickExport RectangleInfo GetImageBoundingBox(const Image *image, |
| 122 | ExceptionInfo *exception) |
| 123 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 124 | CacheView |
| 125 | *image_view; |
| 126 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 127 | MagickBooleanType |
| 128 | status; |
| 129 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 130 | PixelInfo |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 131 | target[3], |
| 132 | zero; |
| 133 | |
| 134 | RectangleInfo |
| 135 | bounds; |
| 136 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 137 | register const Quantum |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 138 | *p; |
| 139 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 140 | ssize_t |
| 141 | y; |
| 142 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 143 | assert(image != (Image *) NULL); |
| 144 | assert(image->signature == MagickSignature); |
| 145 | if (image->debug != MagickFalse) |
| 146 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 147 | bounds.width=0; |
| 148 | bounds.height=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 149 | bounds.x=(ssize_t) image->columns; |
| 150 | bounds.y=(ssize_t) image->rows; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 151 | GetPixelInfo(image,&target[0]); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 152 | image_view=AcquireCacheView(image); |
| 153 | p=GetCacheViewVirtualPixels(image_view,0,0,1,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 154 | if (p == (const Quantum *) NULL) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 155 | { |
| 156 | image_view=DestroyCacheView(image_view); |
| 157 | return(bounds); |
| 158 | } |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 159 | GetPixelInfoPixel(image,p,&target[0]); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 160 | GetPixelInfo(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); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 163 | GetPixelInfoPixel(image,p,&target[1]); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 164 | GetPixelInfo(image,&target[2]); |
cristy | 4cb39ab | 2010-06-07 13:59:16 +0000 | [diff] [blame] | 165 | p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) image->rows-1,1,1, |
| 166 | exception); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 167 | GetPixelInfoPixel(image,p,&target[2]); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 168 | status=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 169 | GetPixelInfo(image,&zero); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 170 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 171 | #pragma omp parallel for schedule(static,4) shared(status) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 172 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 173 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 174 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 175 | PixelInfo |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 176 | pixel; |
| 177 | |
| 178 | RectangleInfo |
| 179 | bounding_box; |
| 180 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 181 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 182 | *restrict p; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 183 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 184 | register ssize_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 185 | x; |
| 186 | |
| 187 | if (status == MagickFalse) |
| 188 | continue; |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 189 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 190 | # pragma omp critical (MagickCore_GetImageBoundingBox) |
| 191 | #endif |
| 192 | bounding_box=bounds; |
| 193 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 194 | if (p == (const Quantum *) NULL) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 195 | { |
| 196 | status=MagickFalse; |
| 197 | continue; |
| 198 | } |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 199 | pixel=zero; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 200 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 201 | { |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 202 | GetPixelInfoPixel(image,p,&pixel); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 203 | if ((x < bounding_box.x) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 204 | (IsFuzzyEquivalencePixelInfo(&pixel,&target[0]) == MagickFalse)) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 205 | bounding_box.x=x; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 206 | if ((x > (ssize_t) bounding_box.width) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 207 | (IsFuzzyEquivalencePixelInfo(&pixel,&target[1]) == MagickFalse)) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 208 | bounding_box.width=(size_t) x; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 209 | if ((y < bounding_box.y) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 210 | (IsFuzzyEquivalencePixelInfo(&pixel,&target[0]) == MagickFalse)) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 211 | bounding_box.y=y; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 212 | if ((y > (ssize_t) bounding_box.height) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 213 | (IsFuzzyEquivalencePixelInfo(&pixel,&target[2]) == MagickFalse)) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 214 | bounding_box.height=(size_t) y; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 215 | p+=GetPixelChannels(image); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 216 | } |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 217 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 218 | # pragma omp critical (MagickCore_GetImageBoundingBox) |
| 219 | #endif |
| 220 | { |
| 221 | if (bounding_box.x < bounds.x) |
| 222 | bounds.x=bounding_box.x; |
| 223 | if (bounding_box.y < bounds.y) |
| 224 | bounds.y=bounding_box.y; |
| 225 | if (bounding_box.width > bounds.width) |
| 226 | bounds.width=bounding_box.width; |
| 227 | if (bounding_box.height > bounds.height) |
| 228 | bounds.height=bounding_box.height; |
| 229 | } |
| 230 | } |
| 231 | image_view=DestroyCacheView(image_view); |
| 232 | if ((bounds.width == 0) || (bounds.height == 0)) |
| 233 | (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, |
| 234 | "GeometryDoesNotContainImage","`%s'",image->filename); |
| 235 | else |
| 236 | { |
| 237 | bounds.width-=(bounds.x-1); |
| 238 | bounds.height-=(bounds.y-1); |
| 239 | } |
| 240 | return(bounds); |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 245 | % % |
| 246 | % % |
| 247 | % % |
cristy | fefab1b | 2011-07-05 00:33:22 +0000 | [diff] [blame] | 248 | % G e t I m a g e D e p t h % |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 249 | % % |
| 250 | % % |
| 251 | % % |
| 252 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 253 | % |
cristy | fefab1b | 2011-07-05 00:33:22 +0000 | [diff] [blame] | 254 | % GetImageDepth() returns the depth of a particular image channel. |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 255 | % |
cristy | fefab1b | 2011-07-05 00:33:22 +0000 | [diff] [blame] | 256 | % The format of the GetImageDepth method is: |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 257 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 258 | % size_t GetImageDepth(const Image *image,ExceptionInfo *exception) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 259 | % |
| 260 | % A description of each parameter follows: |
| 261 | % |
| 262 | % o image: the image. |
| 263 | % |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 264 | % o exception: return any errors or warnings in this structure. |
| 265 | % |
| 266 | */ |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 267 | MagickExport size_t GetImageDepth(const Image *image,ExceptionInfo *exception) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 268 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 269 | CacheView |
| 270 | *image_view; |
| 271 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 272 | MagickBooleanType |
| 273 | status; |
| 274 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 275 | register ssize_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 276 | id; |
| 277 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 278 | size_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 279 | *current_depth, |
| 280 | depth, |
| 281 | number_threads; |
| 282 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 283 | ssize_t |
| 284 | y; |
| 285 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 286 | /* |
| 287 | Compute image depth. |
| 288 | */ |
| 289 | assert(image != (Image *) NULL); |
| 290 | assert(image->signature == MagickSignature); |
| 291 | if (image->debug != MagickFalse) |
| 292 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 293 | number_threads=GetOpenMPMaximumThreads(); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 294 | current_depth=(size_t *) AcquireQuantumMemory(number_threads, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 295 | sizeof(*current_depth)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 296 | if (current_depth == (size_t *) NULL) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 297 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 298 | status=MagickTrue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 299 | for (id=0; id < (ssize_t) number_threads; id++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 300 | current_depth[id]=1; |
| 301 | if ((image->storage_class == PseudoClass) && (image->matte == MagickFalse)) |
| 302 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 303 | register ssize_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 304 | i; |
| 305 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 306 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 307 | #pragma omp parallel for schedule(static) shared(status) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 308 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 309 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 310 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 311 | const int |
| 312 | id = GetOpenMPThreadId(); |
| 313 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 314 | if (status == MagickFalse) |
| 315 | continue; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 316 | while (current_depth[id] < MAGICKCORE_QUANTUM_DEPTH) |
| 317 | { |
| 318 | MagickStatusType |
| 319 | status; |
| 320 | |
| 321 | QuantumAny |
cristy | b6d6f7c | 2010-06-09 13:17:57 +0000 | [diff] [blame] | 322 | range; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 323 | |
| 324 | status=0; |
cristy | b6d6f7c | 2010-06-09 13:17:57 +0000 | [diff] [blame] | 325 | range=GetQuantumRange(current_depth[id]); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 326 | if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 327 | status|=ClampToQuantum(image->colormap[i].red) != |
| 328 | ScaleAnyToQuantum(ScaleQuantumToAny(ClampToQuantum( |
| 329 | image->colormap[i].red),range),range); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 330 | if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 331 | status|=ClampToQuantum(image->colormap[i].green) != |
| 332 | ScaleAnyToQuantum(ScaleQuantumToAny(ClampToQuantum( |
| 333 | image->colormap[i].green),range),range); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 334 | if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 335 | status|=ClampToQuantum(image->colormap[i].blue) != |
| 336 | ScaleAnyToQuantum(ScaleQuantumToAny(ClampToQuantum( |
| 337 | image->colormap[i].blue),range),range); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 338 | if (status == 0) |
| 339 | break; |
| 340 | current_depth[id]++; |
| 341 | } |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 342 | } |
| 343 | depth=current_depth[0]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 344 | for (id=1; id < (ssize_t) number_threads; id++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 345 | if (depth < current_depth[id]) |
| 346 | depth=current_depth[id]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 347 | current_depth=(size_t *) RelinquishMagickMemory(current_depth); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 348 | return(depth); |
| 349 | } |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 350 | image_view=AcquireCacheView(image); |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 351 | #if !defined(MAGICKCORE_HDRI_SUPPORT) |
| 352 | if (QuantumRange <= MaxMap) |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 353 | { |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 354 | register ssize_t |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 355 | i; |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 356 | |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 357 | size_t |
| 358 | *depth_map; |
| 359 | |
| 360 | /* |
| 361 | Scale pixels to desired (optimized with depth map). |
| 362 | */ |
| 363 | depth_map=(size_t *) AcquireQuantumMemory(MaxMap+1,sizeof(*depth_map)); |
| 364 | if (depth_map == (size_t *) NULL) |
| 365 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 366 | for (i=0; i <= (ssize_t) MaxMap; i++) |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 367 | { |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 368 | unsigned int |
| 369 | depth; |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 370 | |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 371 | for (depth=1; depth < MAGICKCORE_QUANTUM_DEPTH; depth++) |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 372 | { |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 373 | Quantum |
| 374 | pixel; |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 375 | |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 376 | QuantumAny |
| 377 | range; |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 378 | |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 379 | range=GetQuantumRange(depth); |
| 380 | pixel=(Quantum) i; |
| 381 | if (pixel == ScaleAnyToQuantum(ScaleQuantumToAny(pixel,range),range)) |
| 382 | break; |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 383 | } |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 384 | depth_map[i]=depth; |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 385 | } |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 386 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 387 | #pragma omp parallel for schedule(static,4) shared(status) |
| 388 | #endif |
| 389 | for (y=0; y < (ssize_t) image->rows; y++) |
| 390 | { |
| 391 | const int |
| 392 | id = GetOpenMPThreadId(); |
| 393 | |
| 394 | register const Quantum |
| 395 | *restrict p; |
| 396 | |
| 397 | register ssize_t |
| 398 | x; |
| 399 | |
| 400 | if (status == MagickFalse) |
| 401 | continue; |
| 402 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 403 | if (p == (const Quantum *) NULL) |
| 404 | continue; |
| 405 | for (x=0; x < (ssize_t) image->columns; x++) |
| 406 | { |
| 407 | register ssize_t |
| 408 | i; |
| 409 | |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 410 | if (GetPixelMask(image,p) != 0) |
| 411 | { |
| 412 | p+=GetPixelChannels(image); |
| 413 | continue; |
| 414 | } |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 415 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 416 | { |
| 417 | PixelChannel |
| 418 | channel; |
| 419 | |
| 420 | PixelTrait |
| 421 | traits; |
| 422 | |
| 423 | channel=GetPixelChannelMapChannel(image,i); |
| 424 | traits=GetPixelChannelMapTraits(image,channel); |
| 425 | if ((traits == UndefinedPixelTrait) || |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 426 | (channel == IndexPixelChannel) || (channel == MaskPixelChannel)) |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 427 | continue; |
| 428 | if (depth_map[ScaleQuantumToMap(p[i])] > current_depth[id]) |
| 429 | current_depth[id]=depth_map[ScaleQuantumToMap(p[i])]; |
| 430 | } |
| 431 | p+=GetPixelChannels(image); |
| 432 | } |
| 433 | if (current_depth[id] == MAGICKCORE_QUANTUM_DEPTH) |
| 434 | status=MagickFalse; |
| 435 | } |
| 436 | image_view=DestroyCacheView(image_view); |
| 437 | depth=current_depth[0]; |
| 438 | for (id=1; id < (ssize_t) number_threads; id++) |
| 439 | if (depth < current_depth[id]) |
| 440 | depth=current_depth[id]; |
| 441 | depth_map=(size_t *) RelinquishMagickMemory(depth_map); |
| 442 | current_depth=(size_t *) RelinquishMagickMemory(current_depth); |
| 443 | return(depth); |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 444 | } |
cristy | 1386801 | 2012-01-08 21:44:07 +0000 | [diff] [blame] | 445 | #endif |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 446 | /* |
| 447 | Compute pixel depth. |
| 448 | */ |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 449 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 450 | #pragma omp parallel for schedule(static,4) shared(status) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 451 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 452 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 453 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 454 | const int |
| 455 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 456 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 457 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 458 | *restrict p; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 459 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 460 | register ssize_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 461 | x; |
| 462 | |
| 463 | if (status == MagickFalse) |
| 464 | continue; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 465 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 466 | if (p == (const Quantum *) NULL) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 467 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 468 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 469 | { |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 470 | register ssize_t |
| 471 | i; |
| 472 | |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 473 | if (GetPixelMask(image,p) != 0) |
| 474 | { |
| 475 | p+=GetPixelChannels(image); |
| 476 | continue; |
| 477 | } |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 478 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 479 | { |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 480 | PixelChannel |
| 481 | channel; |
| 482 | |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 483 | PixelTrait |
| 484 | traits; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 485 | |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 486 | channel=GetPixelChannelMapChannel(image,i); |
| 487 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 488 | if ((traits == UndefinedPixelTrait) || (channel == IndexPixelChannel) || |
| 489 | (channel == MaskPixelChannel)) |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 490 | continue; |
| 491 | while (current_depth[id] < MAGICKCORE_QUANTUM_DEPTH) |
| 492 | { |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 493 | QuantumAny |
| 494 | range; |
| 495 | |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 496 | range=GetQuantumRange(current_depth[id]); |
cristy | 3b2b171 | 2012-01-08 21:52:15 +0000 | [diff] [blame] | 497 | if (p[i] == ScaleAnyToQuantum(ScaleQuantumToAny(p[i],range),range)) |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 498 | break; |
| 499 | current_depth[id]++; |
| 500 | } |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 501 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 502 | p+=GetPixelChannels(image); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 503 | } |
| 504 | if (current_depth[id] == MAGICKCORE_QUANTUM_DEPTH) |
| 505 | status=MagickFalse; |
| 506 | } |
| 507 | image_view=DestroyCacheView(image_view); |
| 508 | depth=current_depth[0]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 509 | for (id=1; id < (ssize_t) number_threads; id++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 510 | if (depth < current_depth[id]) |
| 511 | depth=current_depth[id]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 512 | current_depth=(size_t *) RelinquishMagickMemory(current_depth); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 513 | return(depth); |
| 514 | } |
| 515 | |
| 516 | /* |
| 517 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 518 | % % |
| 519 | % % |
| 520 | % % |
| 521 | % G e t I m a g e Q u a n t u m D e p t h % |
| 522 | % % |
| 523 | % % |
| 524 | % % |
| 525 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 526 | % |
| 527 | % GetImageQuantumDepth() returns the depth of the image rounded to a legal |
| 528 | % quantum depth: 8, 16, or 32. |
| 529 | % |
| 530 | % The format of the GetImageQuantumDepth method is: |
| 531 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 532 | % size_t GetImageQuantumDepth(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 533 | % const MagickBooleanType constrain) |
| 534 | % |
| 535 | % A description of each parameter follows: |
| 536 | % |
| 537 | % o image: the image. |
| 538 | % |
| 539 | % o constrain: A value other than MagickFalse, constrains the depth to |
| 540 | % a maximum of MAGICKCORE_QUANTUM_DEPTH. |
| 541 | % |
| 542 | */ |
| 543 | |
| 544 | static inline double MagickMin(const double x,const double y) |
| 545 | { |
| 546 | if (x < y) |
| 547 | return(x); |
| 548 | return(y); |
| 549 | } |
| 550 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 551 | MagickExport size_t GetImageQuantumDepth(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 552 | const MagickBooleanType constrain) |
| 553 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 554 | size_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 555 | depth; |
| 556 | |
| 557 | depth=image->depth; |
| 558 | if (depth <= 8) |
| 559 | depth=8; |
| 560 | else |
| 561 | if (depth <= 16) |
| 562 | depth=16; |
| 563 | else |
| 564 | if (depth <= 32) |
| 565 | depth=32; |
| 566 | else |
| 567 | if (depth <= 64) |
| 568 | depth=64; |
| 569 | if (constrain != MagickFalse) |
cristy | 9e940dd | 2011-12-13 01:22:25 +0000 | [diff] [blame] | 570 | depth=(size_t) MagickMin((double) depth,(double) MAGICKCORE_QUANTUM_DEPTH); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 571 | return(depth); |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 576 | % % |
| 577 | % % |
| 578 | % % |
| 579 | % G e t I m a g e T y p e % |
| 580 | % % |
| 581 | % % |
| 582 | % % |
| 583 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 584 | % |
| 585 | % GetImageType() returns the potential type of image: |
| 586 | % |
| 587 | % Bilevel Grayscale GrayscaleMatte |
| 588 | % Palette PaletteMatte TrueColor |
| 589 | % TrueColorMatte ColorSeparation ColorSeparationMatte |
| 590 | % |
| 591 | % To ensure the image type matches its potential, use SetImageType(): |
| 592 | % |
| 593 | % (void) SetImageType(image,GetImageType(image)); |
| 594 | % |
| 595 | % The format of the GetImageType method is: |
| 596 | % |
| 597 | % ImageType GetImageType(const Image *image,ExceptionInfo *exception) |
| 598 | % |
| 599 | % A description of each parameter follows: |
| 600 | % |
| 601 | % o image: the image. |
| 602 | % |
| 603 | % o exception: return any errors or warnings in this structure. |
| 604 | % |
| 605 | */ |
| 606 | MagickExport ImageType GetImageType(const Image *image,ExceptionInfo *exception) |
| 607 | { |
| 608 | assert(image != (Image *) NULL); |
| 609 | assert(image->signature == MagickSignature); |
| 610 | if (image->debug != MagickFalse) |
| 611 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 612 | if (image->colorspace == CMYKColorspace) |
| 613 | { |
| 614 | if (image->matte == MagickFalse) |
| 615 | return(ColorSeparationType); |
| 616 | return(ColorSeparationMatteType); |
| 617 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 618 | if (IsImageMonochrome(image,exception) != MagickFalse) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 619 | return(BilevelType); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 620 | if (IsImageGray(image,exception) != MagickFalse) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 621 | { |
| 622 | if (image->matte != MagickFalse) |
| 623 | return(GrayscaleMatteType); |
| 624 | return(GrayscaleType); |
| 625 | } |
| 626 | if (IsPaletteImage(image,exception) != MagickFalse) |
| 627 | { |
| 628 | if (image->matte != MagickFalse) |
| 629 | return(PaletteMatteType); |
| 630 | return(PaletteType); |
| 631 | } |
| 632 | if (image->matte != MagickFalse) |
| 633 | return(TrueColorMatteType); |
| 634 | return(TrueColorType); |
| 635 | } |
| 636 | |
| 637 | /* |
| 638 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 639 | % % |
| 640 | % % |
| 641 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 642 | % I s I m a g e G r a y % |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 643 | % % |
| 644 | % % |
| 645 | % % |
| 646 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 647 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 648 | % IsImageGray() returns MagickTrue if all the pixels in the image have the |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 649 | % same red, green, and blue intensities. |
| 650 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 651 | % The format of the IsImageGray method is: |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 652 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 653 | % MagickBooleanType IsImageGray(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 654 | % ExceptionInfo *exception) |
| 655 | % |
| 656 | % A description of each parameter follows: |
| 657 | % |
| 658 | % o image: the image. |
| 659 | % |
| 660 | % o exception: return any errors or warnings in this structure. |
| 661 | % |
| 662 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 663 | MagickExport MagickBooleanType IsImageGray(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 664 | ExceptionInfo *exception) |
| 665 | { |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 666 | CacheView |
| 667 | *image_view; |
| 668 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 669 | ImageType |
| 670 | type; |
| 671 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 672 | register const Quantum |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 673 | *p; |
| 674 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 675 | register ssize_t |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 676 | x; |
| 677 | |
cristy | 95802a7 | 2010-09-05 19:07:17 +0000 | [diff] [blame] | 678 | ssize_t |
| 679 | y; |
| 680 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 681 | assert(image != (Image *) NULL); |
| 682 | assert(image->signature == MagickSignature); |
| 683 | if (image->debug != MagickFalse) |
| 684 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 685 | if ((image->type == BilevelType) || (image->type == GrayscaleType) || |
| 686 | (image->type == GrayscaleMatteType)) |
| 687 | return(MagickTrue); |
cristy | 501c559 | 2012-04-18 12:45:09 +0000 | [diff] [blame^] | 688 | if (IssRGBColorspace(image->colorspace) == MagickFalse) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 689 | return(MagickFalse); |
| 690 | type=BilevelType; |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 691 | image_view=AcquireCacheView(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 692 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 693 | { |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 694 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 695 | if (p == (const Quantum *) NULL) |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 696 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 697 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 698 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 699 | if (IsPixelGray(image,p) == MagickFalse) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 700 | { |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 701 | type=UndefinedType; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 702 | break; |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 703 | } |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 704 | if ((type == BilevelType) && |
| 705 | (IsPixelMonochrome(image,p) == MagickFalse)) |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 706 | type=GrayscaleType; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 707 | p+=GetPixelChannels(image); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 708 | } |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 709 | if (type == UndefinedType) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 710 | break; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 711 | } |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 712 | image_view=DestroyCacheView(image_view); |
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 | return(MagickFalse); |
| 715 | ((Image *) image)->type=type; |
| 716 | if ((type == GrayscaleType) && (image->matte != MagickFalse)) |
| 717 | ((Image *) image)->type=GrayscaleMatteType; |
| 718 | return(MagickTrue); |
| 719 | } |
| 720 | |
| 721 | /* |
| 722 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 723 | % % |
| 724 | % % |
| 725 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 726 | % 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] | 727 | % % |
| 728 | % % |
| 729 | % % |
| 730 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 731 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 732 | % IsImageMonochrome() returns MagickTrue if all the pixels in the image have |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 733 | % the same red, green, and blue intensities and the intensity is either |
| 734 | % 0 or QuantumRange. |
| 735 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 736 | % The format of the IsImageMonochrome method is: |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 737 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 738 | % MagickBooleanType IsImageMonochrome(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 739 | % ExceptionInfo *exception) |
| 740 | % |
| 741 | % A description of each parameter follows: |
| 742 | % |
| 743 | % o image: the image. |
| 744 | % |
| 745 | % o exception: return any errors or warnings in this structure. |
| 746 | % |
| 747 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 748 | MagickExport MagickBooleanType IsImageMonochrome(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 749 | ExceptionInfo *exception) |
| 750 | { |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 751 | CacheView |
| 752 | *image_view; |
| 753 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 754 | ImageType |
| 755 | type; |
| 756 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 757 | register ssize_t |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 758 | x; |
| 759 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 760 | register const Quantum |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 761 | *p; |
| 762 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 763 | ssize_t |
| 764 | y; |
| 765 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 766 | assert(image != (Image *) NULL); |
| 767 | assert(image->signature == MagickSignature); |
| 768 | if (image->debug != MagickFalse) |
| 769 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 770 | if (image->type == BilevelType) |
| 771 | return(MagickTrue); |
cristy | 501c559 | 2012-04-18 12:45:09 +0000 | [diff] [blame^] | 772 | if (IssRGBColorspace(image->colorspace) == MagickFalse) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 773 | return(MagickFalse); |
| 774 | type=BilevelType; |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 775 | image_view=AcquireCacheView(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 776 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 777 | { |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 778 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 779 | if (p == (const Quantum *) NULL) |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 780 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 781 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 782 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 783 | if (IsPixelMonochrome(image,p) == MagickFalse) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 784 | { |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 785 | type=UndefinedType; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 786 | break; |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 787 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 788 | p+=GetPixelChannels(image); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 789 | } |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 790 | if (type == UndefinedType) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 791 | break; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 792 | } |
cristy | 0910f24 | 2010-04-01 18:55:09 +0000 | [diff] [blame] | 793 | image_view=DestroyCacheView(image_view); |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 794 | if (type == UndefinedType) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 795 | return(MagickFalse); |
| 796 | ((Image *) image)->type=type; |
| 797 | return(MagickTrue); |
| 798 | } |
| 799 | |
| 800 | /* |
| 801 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 802 | % % |
| 803 | % % |
| 804 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 805 | % I s I m a g e O p a q u e % |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 806 | % % |
| 807 | % % |
| 808 | % % |
| 809 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 810 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 811 | % IsImageOpaque() returns MagickTrue if none of the pixels in the image have |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 812 | % an opacity value other than opaque (0). |
| 813 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 814 | % The format of the IsImageOpaque method is: |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 815 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 816 | % MagickBooleanType IsImageOpaque(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 817 | % ExceptionInfo *exception) |
| 818 | % |
| 819 | % A description of each parameter follows: |
| 820 | % |
| 821 | % o image: the image. |
| 822 | % |
| 823 | % o exception: return any errors or warnings in this structure. |
| 824 | % |
| 825 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 826 | MagickExport MagickBooleanType IsImageOpaque(const Image *image, |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 827 | ExceptionInfo *exception) |
| 828 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 829 | CacheView |
| 830 | *image_view; |
| 831 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 832 | register const Quantum |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 833 | *p; |
| 834 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 835 | register ssize_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 836 | x; |
| 837 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 838 | ssize_t |
| 839 | y; |
| 840 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 841 | /* |
| 842 | Determine if image is opaque. |
| 843 | */ |
| 844 | assert(image != (Image *) NULL); |
| 845 | assert(image->signature == MagickSignature); |
| 846 | if (image->debug != MagickFalse) |
| 847 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 848 | if (image->matte == MagickFalse) |
| 849 | return(MagickTrue); |
| 850 | image_view=AcquireCacheView(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 851 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 852 | { |
| 853 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 854 | if (p == (const Quantum *) NULL) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 855 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 856 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 857 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 858 | if (GetPixelAlpha(image,p) != OpaqueAlpha) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 859 | break; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 860 | p+=GetPixelChannels(image); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 861 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 862 | if (x < (ssize_t) image->columns) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 863 | break; |
| 864 | } |
| 865 | image_view=DestroyCacheView(image_view); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 866 | return(y < (ssize_t) image->rows ? MagickFalse : MagickTrue); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | /* |
| 870 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 871 | % % |
| 872 | % % |
| 873 | % % |
cristy | fefab1b | 2011-07-05 00:33:22 +0000 | [diff] [blame] | 874 | % S e t I m a g e D e p t h % |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 875 | % % |
| 876 | % % |
| 877 | % % |
| 878 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 879 | % |
cristy | fefab1b | 2011-07-05 00:33:22 +0000 | [diff] [blame] | 880 | % SetImageDepth() sets the depth of the image. |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 881 | % |
cristy | fefab1b | 2011-07-05 00:33:22 +0000 | [diff] [blame] | 882 | % The format of the SetImageDepth method is: |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 883 | % |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 884 | % MagickBooleanType SetImageDepth(Image *image,const size_t depth, |
| 885 | % ExceptionInfo *exception) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 886 | % |
| 887 | % A description of each parameter follows: |
| 888 | % |
| 889 | % o image: the image. |
| 890 | % |
| 891 | % o channel: the channel. |
| 892 | % |
| 893 | % o depth: the image depth. |
| 894 | % |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 895 | % o exception: return any errors or warnings in this structure. |
| 896 | % |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 897 | */ |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 898 | MagickExport MagickBooleanType SetImageDepth(Image *image, |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 899 | const size_t depth,ExceptionInfo *exception) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 900 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 901 | CacheView |
| 902 | *image_view; |
| 903 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 904 | MagickBooleanType |
| 905 | status; |
| 906 | |
| 907 | QuantumAny |
cristy | b6d6f7c | 2010-06-09 13:17:57 +0000 | [diff] [blame] | 908 | range; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 909 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 910 | ssize_t |
| 911 | y; |
| 912 | |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 913 | assert(image != (Image *) NULL); |
| 914 | if (image->debug != MagickFalse) |
| 915 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 916 | assert(image->signature == MagickSignature); |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 917 | if (depth >= MAGICKCORE_QUANTUM_DEPTH) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 918 | { |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 919 | image->depth=MAGICKCORE_QUANTUM_DEPTH; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 920 | return(MagickTrue); |
| 921 | } |
cristy | 5d6f7ed | 2012-01-08 02:53:08 +0000 | [diff] [blame] | 922 | range=GetQuantumRange(depth); |
| 923 | if (image->storage_class == PseudoClass) |
| 924 | { |
cristy | 5d6f7ed | 2012-01-08 02:53:08 +0000 | [diff] [blame] | 925 | register ssize_t |
| 926 | i; |
| 927 | |
cristy | 5d6f7ed | 2012-01-08 02:53:08 +0000 | [diff] [blame] | 928 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 929 | #pragma omp parallel for schedule(static) shared(status) |
cristy | 5d6f7ed | 2012-01-08 02:53:08 +0000 | [diff] [blame] | 930 | #endif |
| 931 | for (i=0; i < (ssize_t) image->colors; i++) |
| 932 | { |
| 933 | if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 934 | image->colormap[i].red=(double) ScaleAnyToQuantum(ScaleQuantumToAny( |
| 935 | ClampToQuantum(image->colormap[i].red),range),range); |
cristy | 5d6f7ed | 2012-01-08 02:53:08 +0000 | [diff] [blame] | 936 | if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 937 | image->colormap[i].green=(double) ScaleAnyToQuantum(ScaleQuantumToAny( ClampToQuantum(image->colormap[i].green),range),range); |
cristy | 5d6f7ed | 2012-01-08 02:53:08 +0000 | [diff] [blame] | 938 | if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 939 | image->colormap[i].blue=(double) ScaleAnyToQuantum(ScaleQuantumToAny( |
| 940 | ClampToQuantum(image->colormap[i].blue),range),range); |
cristy | 5d6f7ed | 2012-01-08 02:53:08 +0000 | [diff] [blame] | 941 | if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 942 | image->colormap[i].alpha=(double) ScaleAnyToQuantum(ScaleQuantumToAny( |
| 943 | ClampToQuantum(image->colormap[i].alpha),range),range); |
cristy | 5d6f7ed | 2012-01-08 02:53:08 +0000 | [diff] [blame] | 944 | } |
| 945 | status=SyncImage(image,exception); |
| 946 | if (status != MagickFalse) |
| 947 | image->depth=depth; |
| 948 | return(status); |
| 949 | } |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 950 | status=MagickTrue; |
| 951 | image_view=AcquireCacheView(image); |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 952 | #if !defined(MAGICKCORE_HDRI_SUPPORT) |
| 953 | if (QuantumRange <= MaxMap) |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 954 | { |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 955 | Quantum |
| 956 | *depth_map; |
| 957 | |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 958 | register ssize_t |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 959 | i; |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 960 | |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 961 | /* |
| 962 | Scale pixels to desired (optimized with depth map). |
| 963 | */ |
| 964 | depth_map=(Quantum *) AcquireQuantumMemory(MaxMap+1,sizeof(*depth_map)); |
| 965 | if (depth_map == (Quantum *) NULL) |
| 966 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 967 | for (i=0; i <= (ssize_t) MaxMap; i++) |
| 968 | depth_map[i]=ScaleAnyToQuantum(ScaleQuantumToAny((Quantum) i,range), |
| 969 | range); |
| 970 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 971 | #pragma omp parallel for schedule(static,4) shared(status) |
| 972 | #endif |
| 973 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 974 | { |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 975 | register ssize_t |
| 976 | x; |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 977 | |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 978 | register Quantum |
| 979 | *restrict q; |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 980 | |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 981 | if (status == MagickFalse) |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 982 | continue; |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 983 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 984 | exception); |
| 985 | if (q == (Quantum *) NULL) |
| 986 | { |
| 987 | status=MagickFalse; |
| 988 | continue; |
| 989 | } |
| 990 | for (x=0; x < (ssize_t) image->columns; x++) |
| 991 | { |
cristy | aa874e1 | 2012-01-20 21:00:51 +0000 | [diff] [blame] | 992 | register ssize_t |
| 993 | i; |
| 994 | |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 995 | if (GetPixelMask(image,q) != 0) |
| 996 | { |
| 997 | q+=GetPixelChannels(image); |
| 998 | continue; |
| 999 | } |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 1000 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 1001 | { |
| 1002 | PixelChannel |
| 1003 | channel; |
| 1004 | |
| 1005 | PixelTrait |
| 1006 | traits; |
| 1007 | |
| 1008 | channel=GetPixelChannelMapChannel(image,i); |
| 1009 | traits=GetPixelChannelMapTraits(image,channel); |
| 1010 | if ((traits == UndefinedPixelTrait) || |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1011 | (channel == IndexPixelChannel) || (channel == MaskPixelChannel)) |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 1012 | continue; |
| 1013 | q[i]=depth_map[ScaleQuantumToMap(q[i])]; |
| 1014 | } |
| 1015 | q+=GetPixelChannels(image); |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 1016 | } |
cristy | 5293620 | 2012-01-12 12:07:45 +0000 | [diff] [blame] | 1017 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 1018 | { |
| 1019 | status=MagickFalse; |
| 1020 | continue; |
| 1021 | } |
| 1022 | } |
| 1023 | image_view=DestroyCacheView(image_view); |
| 1024 | depth_map=(Quantum *) RelinquishMagickMemory(depth_map); |
| 1025 | if (status != MagickFalse) |
| 1026 | image->depth=depth; |
| 1027 | return(status); |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 1028 | } |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 1029 | #endif |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 1030 | /* |
| 1031 | Scale pixels to desired depth. |
| 1032 | */ |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1033 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 1034 | #pragma omp parallel for schedule(static,4) shared(status) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 1035 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1036 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 1037 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1038 | register ssize_t |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 1039 | x; |
| 1040 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1041 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1042 | *restrict q; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 1043 | |
| 1044 | if (status == MagickFalse) |
| 1045 | continue; |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 1046 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1047 | if (q == (Quantum *) NULL) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 1048 | { |
| 1049 | status=MagickFalse; |
| 1050 | continue; |
| 1051 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1052 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 1053 | { |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 1054 | register ssize_t |
| 1055 | i; |
| 1056 | |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1057 | if (GetPixelMask(image,q) != 0) |
| 1058 | { |
| 1059 | q+=GetPixelChannels(image); |
| 1060 | continue; |
| 1061 | } |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 1062 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 1063 | { |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 1064 | PixelChannel |
| 1065 | channel; |
| 1066 | |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 1067 | PixelTrait |
| 1068 | traits; |
| 1069 | |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 1070 | channel=GetPixelChannelMapChannel(image,i); |
| 1071 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1072 | if ((traits == UndefinedPixelTrait) || (channel == IndexPixelChannel) || |
| 1073 | (channel == MaskPixelChannel)) |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 1074 | continue; |
cristy | 0aa82c1 | 2012-01-08 18:22:09 +0000 | [diff] [blame] | 1075 | q[i]=ScaleAnyToQuantum(ScaleQuantumToAny(q[i],range),range); |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 1076 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1077 | q+=GetPixelChannels(image); |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 1078 | } |
| 1079 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 1080 | { |
| 1081 | status=MagickFalse; |
| 1082 | continue; |
| 1083 | } |
| 1084 | } |
| 1085 | image_view=DestroyCacheView(image_view); |
cristy | 5d6f7ed | 2012-01-08 02:53:08 +0000 | [diff] [blame] | 1086 | if (status != MagickFalse) |
| 1087 | image->depth=depth; |
cristy | da06ed1 | 2009-10-14 18:36:54 +0000 | [diff] [blame] | 1088 | return(status); |
| 1089 | } |