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