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