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