cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % PPPP IIIII X X EEEEE L % |
| 7 | % P P I X X E L % |
| 8 | % PPPP I X EEE L % |
| 9 | % P I X X E L % |
| 10 | % P IIIII X X EEEEE LLLLL % |
| 11 | % % |
| 12 | % MagickCore Methods to Import/Export Pixels % |
| 13 | % % |
| 14 | % Software Design % |
| 15 | % John Cristy % |
| 16 | % October 1998 % |
| 17 | % % |
| 18 | % % |
| 19 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
| 20 | % dedicated to making software imaging solutions freely available. % |
| 21 | % % |
| 22 | % You may not use this file except in compliance with the License. You may % |
| 23 | % obtain a copy of the License at % |
| 24 | % % |
| 25 | % http://www.imagemagick.org/script/license.php % |
| 26 | % % |
| 27 | % Unless required by applicable law or agreed to in writing, software % |
| 28 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 29 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 30 | % See the License for the specific language governing permissions and % |
| 31 | % limitations under the License. % |
| 32 | % % |
| 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 34 | % |
| 35 | % |
| 36 | */ |
| 37 | |
| 38 | /* |
| 39 | Include declarations. |
| 40 | */ |
| 41 | #include "MagickCore/studio.h" |
| 42 | #include "MagickCore/property.h" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/blob-private.h" |
| 45 | #include "MagickCore/color-private.h" |
| 46 | #include "MagickCore/draw.h" |
| 47 | #include "MagickCore/exception.h" |
| 48 | #include "MagickCore/exception-private.h" |
| 49 | #include "MagickCore/cache.h" |
| 50 | #include "MagickCore/constitute.h" |
| 51 | #include "MagickCore/delegate.h" |
| 52 | #include "MagickCore/geometry.h" |
| 53 | #include "MagickCore/image-private.h" |
| 54 | #include "MagickCore/list.h" |
| 55 | #include "MagickCore/magick.h" |
| 56 | #include "MagickCore/memory_.h" |
| 57 | #include "MagickCore/monitor.h" |
| 58 | #include "MagickCore/option.h" |
| 59 | #include "MagickCore/pixel.h" |
| 60 | #include "MagickCore/pixel-accessor.h" |
| 61 | #include "MagickCore/quantum.h" |
| 62 | #include "MagickCore/quantum-private.h" |
| 63 | #include "MagickCore/resource_.h" |
| 64 | #include "MagickCore/semaphore.h" |
| 65 | #include "MagickCore/statistic.h" |
| 66 | #include "MagickCore/stream.h" |
| 67 | #include "MagickCore/string_.h" |
| 68 | #include "MagickCore/transform.h" |
| 69 | #include "MagickCore/utility.h" |
| 70 | |
| 71 | /* |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 72 | Define declarations. |
| 73 | */ |
| 74 | #define LogPixelChannels(image) \ |
| 75 | { \ |
| 76 | register ssize_t \ |
| 77 | i; \ |
| 78 | \ |
| 79 | (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]", \ |
| 80 | image->filename,(double) image->number_channels); \ |
| 81 | for (i=0; i < (ssize_t) image->number_channels; i++) \ |
| 82 | { \ |
| 83 | char \ |
| 84 | traits[MaxTextExtent]; \ |
| 85 | \ |
| 86 | const char \ |
| 87 | *channel; \ |
| 88 | \ |
| 89 | switch (image->channel_map[i].channel) \ |
| 90 | { \ |
| 91 | case RedPixelChannel: \ |
| 92 | { \ |
| 93 | channel="red"; \ |
| 94 | if (image->colorspace == CMYKColorspace) \ |
| 95 | channel="cyan"; \ |
| 96 | if (image->colorspace == GRAYColorspace) \ |
| 97 | channel="gray"; \ |
| 98 | break; \ |
| 99 | } \ |
| 100 | case GreenPixelChannel: \ |
| 101 | { \ |
| 102 | channel="green"; \ |
| 103 | if (image->colorspace == CMYKColorspace) \ |
| 104 | channel="magenta"; \ |
| 105 | break; \ |
| 106 | } \ |
| 107 | case BluePixelChannel: \ |
| 108 | { \ |
| 109 | channel="blue"; \ |
| 110 | if (image->colorspace == CMYKColorspace) \ |
| 111 | channel="yellow"; \ |
| 112 | break; \ |
| 113 | } \ |
| 114 | case BlackPixelChannel: \ |
| 115 | { \ |
| 116 | channel="black"; \ |
| 117 | if (image->storage_class == PseudoClass) \ |
| 118 | channel="index"; \ |
| 119 | break; \ |
| 120 | } \ |
| 121 | case AlphaPixelChannel: \ |
| 122 | { \ |
| 123 | channel="alpha"; \ |
| 124 | break; \ |
| 125 | } \ |
| 126 | case MaskPixelChannel: \ |
| 127 | { \ |
| 128 | channel="mask"; \ |
| 129 | break; \ |
| 130 | } \ |
| 131 | default: \ |
| 132 | { \ |
| 133 | channel="undefined"; \ |
| 134 | } \ |
| 135 | } \ |
| 136 | *traits='\0'; \ |
| 137 | if ((image->channel_map[i].traits & UpdatePixelTrait) != 0) \ |
| 138 | (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \ |
| 139 | if ((image->channel_map[i].traits & BlendPixelTrait) != 0) \ |
| 140 | (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \ |
| 141 | if ((image->channel_map[i].traits & CopyPixelTrait) != 0) \ |
| 142 | (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \ |
| 143 | if (*traits == '\0') \ |
| 144 | (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \ |
| 145 | traits[strlen(traits)-1]='\0'; \ |
| 146 | (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", \ |
| 147 | (double) i,channel,traits); \ |
| 148 | } \ |
| 149 | } |
| 150 | |
| 151 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 152 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 153 | % % |
| 154 | % % |
| 155 | % % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 156 | + A c q u i r e P i x e l C h a n n e l M a p % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 157 | % % |
| 158 | % % |
| 159 | % % |
| 160 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 161 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 162 | % AcquirePixelChannelMap() acquires a pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 163 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 164 | % The format of the AcquirePixelChannelMap() method is: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 165 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 166 | % PixelChannelMap *AcquirePixelChannelMap(void) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 167 | % |
| 168 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 169 | MagickExport PixelChannelMap *AcquirePixelChannelMap(void) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 170 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 171 | PixelChannelMap |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 172 | *channel_map; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 173 | |
| 174 | register ssize_t |
| 175 | i; |
| 176 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 177 | channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels, |
| 178 | sizeof(*channel_map)); |
| 179 | if (channel_map == (PixelChannelMap *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 180 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 181 | (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map)); |
| 182 | for (i=0; i < MaxPixelChannels; i++) |
| 183 | channel_map[i].channel=(PixelChannel) i; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 184 | return(channel_map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* |
| 188 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 189 | % % |
| 190 | % % |
| 191 | % % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 192 | + C l o n e P i x e l C h a n n e l M a p % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 193 | % % |
| 194 | % % |
| 195 | % % |
| 196 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 197 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 198 | % ClonePixelChannelMap() clones a pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 199 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 200 | % The format of the ClonePixelChannelMap() method is: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 201 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 202 | % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 203 | % |
| 204 | % A description of each parameter follows: |
| 205 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 206 | % o channel_map: the pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 207 | % |
| 208 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 209 | MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 210 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 211 | PixelChannelMap |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 212 | *clone_map; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 213 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 214 | assert(channel_map != (PixelChannelMap *) NULL); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 215 | clone_map=AcquirePixelChannelMap(); |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 216 | if (clone_map == (PixelChannelMap *) NULL) |
| 217 | return((PixelChannelMap *) NULL); |
| 218 | (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels* |
| 219 | sizeof(*channel_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 220 | return(clone_map); |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 225 | % % |
| 226 | % % |
| 227 | % % |
| 228 | + C l o n e P i x e l I n f o % |
| 229 | % % |
| 230 | % % |
| 231 | % % |
| 232 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 233 | % |
| 234 | % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if |
| 235 | % pixel info is NULL, a new one. |
| 236 | % |
| 237 | % The format of the ClonePixelInfo method is: |
| 238 | % |
| 239 | % PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info) |
| 240 | % |
| 241 | % A description of each parameter follows: |
| 242 | % |
| 243 | % o pixel_info: the pixel info. |
| 244 | % |
| 245 | */ |
| 246 | MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel) |
| 247 | { |
| 248 | PixelInfo |
| 249 | *pixel_info; |
| 250 | |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 251 | pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 252 | if (pixel_info == (PixelInfo *) NULL) |
| 253 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 254 | *pixel_info=(*pixel); |
| 255 | return(pixel_info); |
| 256 | } |
| 257 | |
| 258 | /* |
| 259 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 260 | % % |
| 261 | % % |
| 262 | % % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 263 | + D e s t r o y P i x e l C h a n n e l M a p % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 264 | % % |
| 265 | % % |
| 266 | % % |
| 267 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 268 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 269 | % DestroyPixelChannelMap() deallocates memory associated with the pixel |
| 270 | % channel map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 271 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 272 | % The format of the DestroyPixelChannelMap() method is: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 273 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 274 | % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 275 | % |
| 276 | % A description of each parameter follows: |
| 277 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 278 | % o channel_map: the pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 279 | % |
| 280 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 281 | MagickExport PixelChannelMap *DestroyPixelChannelMap( |
| 282 | PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 283 | { |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 284 | assert(channel_map != (PixelChannelMap *) NULL); |
| 285 | channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map); |
| 286 | return((PixelChannelMap *) RelinquishMagickMemory(channel_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /* |
| 290 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 291 | % % |
| 292 | % % |
| 293 | % % |
| 294 | % E x p o r t I m a g e P i x e l s % |
| 295 | % % |
| 296 | % % |
| 297 | % % |
| 298 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 299 | % |
| 300 | % ExportImagePixels() extracts pixel data from an image and returns it to you. |
| 301 | % The method returns MagickTrue on success otherwise MagickFalse if an error is |
| 302 | % encountered. The data is returned as char, short int, int, ssize_t, float, |
| 303 | % or double in the order specified by map. |
| 304 | % |
| 305 | % Suppose you want to extract the first scanline of a 640x480 image as |
| 306 | % character data in red-green-blue order: |
| 307 | % |
| 308 | % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception); |
| 309 | % |
| 310 | % The format of the ExportImagePixels method is: |
| 311 | % |
| 312 | % MagickBooleanType ExportImagePixels(const Image *image, |
| 313 | % const ssize_t x_offset,const ssize_t y_offset,const size_t columns, |
| 314 | % const size_t rows,const char *map,const StorageType type, |
| 315 | % void *pixels,ExceptionInfo *exception) |
| 316 | % |
| 317 | % A description of each parameter follows: |
| 318 | % |
| 319 | % o image: the image. |
| 320 | % |
| 321 | % o x_offset,y_offset,columns,rows: These values define the perimeter |
| 322 | % of a region of pixels you want to extract. |
| 323 | % |
| 324 | % o map: This string reflects the expected ordering of the pixel array. |
| 325 | % It can be any combination or order of R = red, G = green, B = blue, |
| 326 | % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan, |
| 327 | % Y = yellow, M = magenta, K = black, I = intensity (for grayscale), |
| 328 | % P = pad. |
| 329 | % |
| 330 | % o type: Define the data type of the pixels. Float and double types are |
| 331 | % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these |
| 332 | % types: CharPixel, DoublePixel, FloatPixel, IntegerPixel, LongPixel, |
| 333 | % QuantumPixel, or ShortPixel. |
| 334 | % |
| 335 | % o pixels: This array of values contain the pixel components as defined by |
| 336 | % map and type. You must preallocate this array where the expected |
| 337 | % length varies depending on the values of width, height, map, and type. |
| 338 | % |
| 339 | % o exception: return any errors or warnings in this structure. |
| 340 | % |
| 341 | */ |
| 342 | MagickExport MagickBooleanType ExportImagePixels(const Image *image, |
| 343 | const ssize_t x_offset,const ssize_t y_offset,const size_t columns, |
| 344 | const size_t rows,const char *map,const StorageType type,void *pixels, |
| 345 | ExceptionInfo *exception) |
| 346 | { |
| 347 | QuantumType |
| 348 | *quantum_map; |
| 349 | |
| 350 | register ssize_t |
| 351 | i, |
| 352 | x; |
| 353 | |
| 354 | register const Quantum |
| 355 | *p; |
| 356 | |
| 357 | size_t |
| 358 | length; |
| 359 | |
| 360 | ssize_t |
| 361 | y; |
| 362 | |
| 363 | assert(image != (Image *) NULL); |
| 364 | assert(image->signature == MagickSignature); |
| 365 | if (image->debug != MagickFalse) |
| 366 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 367 | length=strlen(map); |
| 368 | quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map)); |
| 369 | if (quantum_map == (QuantumType *) NULL) |
| 370 | { |
| 371 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 372 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
| 373 | return(MagickFalse); |
| 374 | } |
| 375 | for (i=0; i < (ssize_t) length; i++) |
| 376 | { |
| 377 | switch (map[i]) |
| 378 | { |
| 379 | case 'A': |
| 380 | case 'a': |
| 381 | { |
| 382 | quantum_map[i]=AlphaQuantum; |
| 383 | break; |
| 384 | } |
| 385 | case 'B': |
| 386 | case 'b': |
| 387 | { |
| 388 | quantum_map[i]=BlueQuantum; |
| 389 | break; |
| 390 | } |
| 391 | case 'C': |
| 392 | case 'c': |
| 393 | { |
| 394 | quantum_map[i]=CyanQuantum; |
| 395 | if (image->colorspace == CMYKColorspace) |
| 396 | break; |
| 397 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 398 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
| 399 | "ColorSeparatedImageRequired","`%s'",map); |
| 400 | return(MagickFalse); |
| 401 | } |
| 402 | case 'g': |
| 403 | case 'G': |
| 404 | { |
| 405 | quantum_map[i]=GreenQuantum; |
| 406 | break; |
| 407 | } |
| 408 | case 'I': |
| 409 | case 'i': |
| 410 | { |
| 411 | quantum_map[i]=IndexQuantum; |
| 412 | break; |
| 413 | } |
| 414 | case 'K': |
| 415 | case 'k': |
| 416 | { |
| 417 | quantum_map[i]=BlackQuantum; |
| 418 | if (image->colorspace == CMYKColorspace) |
| 419 | break; |
| 420 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 421 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
| 422 | "ColorSeparatedImageRequired","`%s'",map); |
| 423 | return(MagickFalse); |
| 424 | } |
| 425 | case 'M': |
| 426 | case 'm': |
| 427 | { |
| 428 | quantum_map[i]=MagentaQuantum; |
| 429 | if (image->colorspace == CMYKColorspace) |
| 430 | break; |
| 431 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 432 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
| 433 | "ColorSeparatedImageRequired","`%s'",map); |
| 434 | return(MagickFalse); |
| 435 | } |
| 436 | case 'o': |
| 437 | case 'O': |
| 438 | { |
| 439 | quantum_map[i]=OpacityQuantum; |
| 440 | break; |
| 441 | } |
| 442 | case 'P': |
| 443 | case 'p': |
| 444 | { |
| 445 | quantum_map[i]=UndefinedQuantum; |
| 446 | break; |
| 447 | } |
| 448 | case 'R': |
| 449 | case 'r': |
| 450 | { |
| 451 | quantum_map[i]=RedQuantum; |
| 452 | break; |
| 453 | } |
| 454 | case 'Y': |
| 455 | case 'y': |
| 456 | { |
| 457 | quantum_map[i]=YellowQuantum; |
| 458 | if (image->colorspace == CMYKColorspace) |
| 459 | break; |
| 460 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 461 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
| 462 | "ColorSeparatedImageRequired","`%s'",map); |
| 463 | return(MagickFalse); |
| 464 | } |
| 465 | default: |
| 466 | { |
| 467 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 468 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 469 | "UnrecognizedPixelMap","`%s'",map); |
| 470 | return(MagickFalse); |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | switch (type) |
| 475 | { |
| 476 | case CharPixel: |
| 477 | { |
| 478 | register unsigned char |
| 479 | *q; |
| 480 | |
| 481 | q=(unsigned char *) pixels; |
| 482 | if (LocaleCompare(map,"BGR") == 0) |
| 483 | { |
| 484 | for (y=0; y < (ssize_t) rows; y++) |
| 485 | { |
| 486 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 487 | if (p == (const Quantum *) NULL) |
| 488 | break; |
| 489 | for (x=0; x < (ssize_t) columns; x++) |
| 490 | { |
| 491 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 492 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 493 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 494 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | break; |
| 498 | } |
| 499 | if (LocaleCompare(map,"BGRA") == 0) |
| 500 | { |
| 501 | for (y=0; y < (ssize_t) rows; y++) |
| 502 | { |
| 503 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 504 | if (p == (const Quantum *) NULL) |
| 505 | break; |
| 506 | for (x=0; x < (ssize_t) columns; x++) |
| 507 | { |
| 508 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 509 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 510 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 511 | *q++=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 512 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | break; |
| 516 | } |
| 517 | if (LocaleCompare(map,"BGRP") == 0) |
| 518 | { |
| 519 | for (y=0; y < (ssize_t) rows; y++) |
| 520 | { |
| 521 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 522 | if (p == (const Quantum *) NULL) |
| 523 | break; |
| 524 | for (x=0; x < (ssize_t) columns; x++) |
| 525 | { |
| 526 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 527 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 528 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 529 | *q++=ScaleQuantumToChar((Quantum) 0); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 530 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | break; |
| 534 | } |
| 535 | if (LocaleCompare(map,"I") == 0) |
| 536 | { |
| 537 | for (y=0; y < (ssize_t) rows; y++) |
| 538 | { |
| 539 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 540 | if (p == (const Quantum *) NULL) |
| 541 | break; |
| 542 | for (x=0; x < (ssize_t) columns; x++) |
| 543 | { |
| 544 | *q++=ScaleQuantumToChar(GetPixelIntensity(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 545 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | break; |
| 549 | } |
| 550 | if (LocaleCompare(map,"RGB") == 0) |
| 551 | { |
| 552 | for (y=0; y < (ssize_t) rows; y++) |
| 553 | { |
| 554 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 555 | if (p == (const Quantum *) NULL) |
| 556 | break; |
| 557 | for (x=0; x < (ssize_t) columns; x++) |
| 558 | { |
| 559 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 560 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 561 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 562 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | break; |
| 566 | } |
| 567 | if (LocaleCompare(map,"RGBA") == 0) |
| 568 | { |
| 569 | for (y=0; y < (ssize_t) rows; y++) |
| 570 | { |
| 571 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 572 | if (p == (const Quantum *) NULL) |
| 573 | break; |
| 574 | for (x=0; x < (ssize_t) columns; x++) |
| 575 | { |
| 576 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 577 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 578 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 579 | *q++=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 580 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | break; |
| 584 | } |
| 585 | if (LocaleCompare(map,"RGBP") == 0) |
| 586 | { |
| 587 | for (y=0; y < (ssize_t) rows; y++) |
| 588 | { |
| 589 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 590 | if (p == (const Quantum *) NULL) |
| 591 | break; |
| 592 | for (x=0; x < (ssize_t) columns; x++) |
| 593 | { |
| 594 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 595 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 596 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 597 | *q++=ScaleQuantumToChar((Quantum) 0); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 598 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | break; |
| 602 | } |
| 603 | for (y=0; y < (ssize_t) rows; y++) |
| 604 | { |
| 605 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 606 | if (p == (const Quantum *) NULL) |
| 607 | break; |
| 608 | for (x=0; x < (ssize_t) columns; x++) |
| 609 | { |
| 610 | for (i=0; i < (ssize_t) length; i++) |
| 611 | { |
| 612 | *q=0; |
| 613 | switch (quantum_map[i]) |
| 614 | { |
| 615 | case RedQuantum: |
| 616 | case CyanQuantum: |
| 617 | { |
| 618 | *q=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 619 | break; |
| 620 | } |
| 621 | case GreenQuantum: |
| 622 | case MagentaQuantum: |
| 623 | { |
| 624 | *q=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 625 | break; |
| 626 | } |
| 627 | case BlueQuantum: |
| 628 | case YellowQuantum: |
| 629 | { |
| 630 | *q=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 631 | break; |
| 632 | } |
| 633 | case AlphaQuantum: |
| 634 | { |
| 635 | *q=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 636 | break; |
| 637 | } |
| 638 | case OpacityQuantum: |
| 639 | { |
| 640 | *q=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 641 | break; |
| 642 | } |
| 643 | case BlackQuantum: |
| 644 | { |
| 645 | if (image->colorspace == CMYKColorspace) |
| 646 | *q=ScaleQuantumToChar(GetPixelBlack(image,p)); |
| 647 | break; |
| 648 | } |
| 649 | case IndexQuantum: |
| 650 | { |
| 651 | *q=ScaleQuantumToChar(GetPixelIntensity(image,p)); |
| 652 | break; |
| 653 | } |
| 654 | default: |
| 655 | break; |
| 656 | } |
| 657 | q++; |
| 658 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 659 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | break; |
| 663 | } |
| 664 | case DoublePixel: |
| 665 | { |
| 666 | register double |
| 667 | *q; |
| 668 | |
| 669 | q=(double *) pixels; |
| 670 | if (LocaleCompare(map,"BGR") == 0) |
| 671 | { |
| 672 | for (y=0; y < (ssize_t) rows; y++) |
| 673 | { |
| 674 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 675 | if (p == (const Quantum *) NULL) |
| 676 | break; |
| 677 | for (x=0; x < (ssize_t) columns; x++) |
| 678 | { |
| 679 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 680 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 681 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 682 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | break; |
| 686 | } |
| 687 | if (LocaleCompare(map,"BGRA") == 0) |
| 688 | { |
| 689 | for (y=0; y < (ssize_t) rows; y++) |
| 690 | { |
| 691 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 692 | if (p == (const Quantum *) NULL) |
| 693 | break; |
| 694 | for (x=0; x < (ssize_t) columns; x++) |
| 695 | { |
| 696 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 697 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 698 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 699 | *q++=(double) (QuantumScale*GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 700 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 701 | } |
| 702 | } |
| 703 | break; |
| 704 | } |
| 705 | if (LocaleCompare(map,"BGRP") == 0) |
| 706 | { |
| 707 | for (y=0; y < (ssize_t) rows; y++) |
| 708 | { |
| 709 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 710 | if (p == (const Quantum *) NULL) |
| 711 | break; |
| 712 | for (x=0; x < (ssize_t) columns; x++) |
| 713 | { |
| 714 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 715 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 716 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 717 | *q++=0.0; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 718 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | break; |
| 722 | } |
| 723 | if (LocaleCompare(map,"I") == 0) |
| 724 | { |
| 725 | for (y=0; y < (ssize_t) rows; y++) |
| 726 | { |
| 727 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 728 | if (p == (const Quantum *) NULL) |
| 729 | break; |
| 730 | for (x=0; x < (ssize_t) columns; x++) |
| 731 | { |
| 732 | *q++=(double) (QuantumScale*GetPixelIntensity(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 733 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | break; |
| 737 | } |
| 738 | if (LocaleCompare(map,"RGB") == 0) |
| 739 | { |
| 740 | for (y=0; y < (ssize_t) rows; y++) |
| 741 | { |
| 742 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 743 | if (p == (const Quantum *) NULL) |
| 744 | break; |
| 745 | for (x=0; x < (ssize_t) columns; x++) |
| 746 | { |
| 747 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 748 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 749 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 750 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | break; |
| 754 | } |
| 755 | if (LocaleCompare(map,"RGBA") == 0) |
| 756 | { |
| 757 | for (y=0; y < (ssize_t) rows; y++) |
| 758 | { |
| 759 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 760 | if (p == (const Quantum *) NULL) |
| 761 | break; |
| 762 | for (x=0; x < (ssize_t) columns; x++) |
| 763 | { |
| 764 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 765 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 766 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 767 | *q++=(double) (QuantumScale*GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 768 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | break; |
| 772 | } |
| 773 | if (LocaleCompare(map,"RGBP") == 0) |
| 774 | { |
| 775 | for (y=0; y < (ssize_t) rows; y++) |
| 776 | { |
| 777 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 778 | if (p == (const Quantum *) NULL) |
| 779 | break; |
| 780 | for (x=0; x < (ssize_t) columns; x++) |
| 781 | { |
| 782 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 783 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 784 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 785 | *q++=0.0; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 786 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | break; |
| 790 | } |
| 791 | for (y=0; y < (ssize_t) rows; y++) |
| 792 | { |
| 793 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 794 | if (p == (const Quantum *) NULL) |
| 795 | break; |
| 796 | for (x=0; x < (ssize_t) columns; x++) |
| 797 | { |
| 798 | for (i=0; i < (ssize_t) length; i++) |
| 799 | { |
| 800 | *q=0; |
| 801 | switch (quantum_map[i]) |
| 802 | { |
| 803 | case RedQuantum: |
| 804 | case CyanQuantum: |
| 805 | { |
| 806 | *q=(double) (QuantumScale*GetPixelRed(image,p)); |
| 807 | break; |
| 808 | } |
| 809 | case GreenQuantum: |
| 810 | case MagentaQuantum: |
| 811 | { |
| 812 | *q=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 813 | break; |
| 814 | } |
| 815 | case BlueQuantum: |
| 816 | case YellowQuantum: |
| 817 | { |
| 818 | *q=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 819 | break; |
| 820 | } |
| 821 | case AlphaQuantum: |
| 822 | { |
| 823 | *q=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 824 | break; |
| 825 | } |
| 826 | case OpacityQuantum: |
| 827 | { |
| 828 | *q=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 829 | break; |
| 830 | } |
| 831 | case BlackQuantum: |
| 832 | { |
| 833 | if (image->colorspace == CMYKColorspace) |
| 834 | *q=(double) (QuantumScale* |
| 835 | GetPixelBlack(image,p)); |
| 836 | break; |
| 837 | } |
| 838 | case IndexQuantum: |
| 839 | { |
| 840 | *q=(double) (QuantumScale*GetPixelIntensity(image,p)); |
| 841 | break; |
| 842 | } |
| 843 | default: |
| 844 | *q=0; |
| 845 | } |
| 846 | q++; |
| 847 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 848 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | break; |
| 852 | } |
| 853 | case FloatPixel: |
| 854 | { |
| 855 | register float |
| 856 | *q; |
| 857 | |
| 858 | q=(float *) pixels; |
| 859 | if (LocaleCompare(map,"BGR") == 0) |
| 860 | { |
| 861 | for (y=0; y < (ssize_t) rows; y++) |
| 862 | { |
| 863 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 864 | if (p == (const Quantum *) NULL) |
| 865 | break; |
| 866 | for (x=0; x < (ssize_t) columns; x++) |
| 867 | { |
| 868 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 869 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 870 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 871 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | break; |
| 875 | } |
| 876 | if (LocaleCompare(map,"BGRA") == 0) |
| 877 | { |
| 878 | for (y=0; y < (ssize_t) rows; y++) |
| 879 | { |
| 880 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 881 | if (p == (const Quantum *) NULL) |
| 882 | break; |
| 883 | for (x=0; x < (ssize_t) columns; x++) |
| 884 | { |
| 885 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 886 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 887 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 888 | *q++=(float) (QuantumScale*GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 889 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | break; |
| 893 | } |
| 894 | if (LocaleCompare(map,"BGRP") == 0) |
| 895 | { |
| 896 | for (y=0; y < (ssize_t) rows; y++) |
| 897 | { |
| 898 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 899 | if (p == (const Quantum *) NULL) |
| 900 | break; |
| 901 | for (x=0; x < (ssize_t) columns; x++) |
| 902 | { |
| 903 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 904 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 905 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 906 | *q++=0.0; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 907 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | break; |
| 911 | } |
| 912 | if (LocaleCompare(map,"I") == 0) |
| 913 | { |
| 914 | for (y=0; y < (ssize_t) rows; y++) |
| 915 | { |
| 916 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 917 | if (p == (const Quantum *) NULL) |
| 918 | break; |
| 919 | for (x=0; x < (ssize_t) columns; x++) |
| 920 | { |
| 921 | *q++=(float) (QuantumScale*GetPixelIntensity(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 922 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | break; |
| 926 | } |
| 927 | if (LocaleCompare(map,"RGB") == 0) |
| 928 | { |
| 929 | for (y=0; y < (ssize_t) rows; y++) |
| 930 | { |
| 931 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 932 | if (p == (const Quantum *) NULL) |
| 933 | break; |
| 934 | for (x=0; x < (ssize_t) columns; x++) |
| 935 | { |
| 936 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 937 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 938 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 939 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 940 | } |
| 941 | } |
| 942 | break; |
| 943 | } |
| 944 | if (LocaleCompare(map,"RGBA") == 0) |
| 945 | { |
| 946 | for (y=0; y < (ssize_t) rows; y++) |
| 947 | { |
| 948 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 949 | if (p == (const Quantum *) NULL) |
| 950 | break; |
| 951 | for (x=0; x < (ssize_t) columns; x++) |
| 952 | { |
| 953 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 954 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 955 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 956 | *q++=(float) (QuantumScale*GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 957 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | break; |
| 961 | } |
| 962 | if (LocaleCompare(map,"RGBP") == 0) |
| 963 | { |
| 964 | for (y=0; y < (ssize_t) rows; y++) |
| 965 | { |
| 966 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 967 | if (p == (const Quantum *) NULL) |
| 968 | break; |
| 969 | for (x=0; x < (ssize_t) columns; x++) |
| 970 | { |
| 971 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 972 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 973 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 974 | *q++=0.0; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 975 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 976 | } |
| 977 | } |
| 978 | break; |
| 979 | } |
| 980 | for (y=0; y < (ssize_t) rows; y++) |
| 981 | { |
| 982 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 983 | if (p == (const Quantum *) NULL) |
| 984 | break; |
| 985 | for (x=0; x < (ssize_t) columns; x++) |
| 986 | { |
| 987 | for (i=0; i < (ssize_t) length; i++) |
| 988 | { |
| 989 | *q=0; |
| 990 | switch (quantum_map[i]) |
| 991 | { |
| 992 | case RedQuantum: |
| 993 | case CyanQuantum: |
| 994 | { |
| 995 | *q=(float) (QuantumScale*GetPixelRed(image,p)); |
| 996 | break; |
| 997 | } |
| 998 | case GreenQuantum: |
| 999 | case MagentaQuantum: |
| 1000 | { |
| 1001 | *q=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 1002 | break; |
| 1003 | } |
| 1004 | case BlueQuantum: |
| 1005 | case YellowQuantum: |
| 1006 | { |
| 1007 | *q=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 1008 | break; |
| 1009 | } |
| 1010 | case AlphaQuantum: |
| 1011 | { |
| 1012 | *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p)))); |
| 1013 | break; |
| 1014 | } |
| 1015 | case OpacityQuantum: |
| 1016 | { |
| 1017 | *q=(float) (QuantumScale*GetPixelAlpha(image,p)); |
| 1018 | break; |
| 1019 | } |
| 1020 | case BlackQuantum: |
| 1021 | { |
| 1022 | if (image->colorspace == CMYKColorspace) |
| 1023 | *q=(float) (QuantumScale* GetPixelBlack(image,p)); |
| 1024 | break; |
| 1025 | } |
| 1026 | case IndexQuantum: |
| 1027 | { |
| 1028 | *q=(float) (QuantumScale*GetPixelIntensity(image,p)); |
| 1029 | break; |
| 1030 | } |
| 1031 | default: |
| 1032 | *q=0; |
| 1033 | } |
| 1034 | q++; |
| 1035 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1036 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1037 | } |
| 1038 | } |
| 1039 | break; |
| 1040 | } |
| 1041 | case IntegerPixel: |
| 1042 | { |
| 1043 | register unsigned int |
| 1044 | *q; |
| 1045 | |
| 1046 | q=(unsigned int *) pixels; |
| 1047 | if (LocaleCompare(map,"BGR") == 0) |
| 1048 | { |
| 1049 | for (y=0; y < (ssize_t) rows; y++) |
| 1050 | { |
| 1051 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1052 | if (p == (const Quantum *) NULL) |
| 1053 | break; |
| 1054 | for (x=0; x < (ssize_t) columns; x++) |
| 1055 | { |
| 1056 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1057 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1058 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1059 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1060 | } |
| 1061 | } |
| 1062 | break; |
| 1063 | } |
| 1064 | if (LocaleCompare(map,"BGRA") == 0) |
| 1065 | { |
| 1066 | for (y=0; y < (ssize_t) rows; y++) |
| 1067 | { |
| 1068 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1069 | if (p == (const Quantum *) NULL) |
| 1070 | break; |
| 1071 | for (x=0; x < (ssize_t) columns; x++) |
| 1072 | { |
| 1073 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1074 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1075 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1076 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1077 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | break; |
| 1081 | } |
| 1082 | if (LocaleCompare(map,"BGRP") == 0) |
| 1083 | { |
| 1084 | for (y=0; y < (ssize_t) rows; y++) |
| 1085 | { |
| 1086 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1087 | if (p == (const Quantum *) NULL) |
| 1088 | break; |
| 1089 | for (x=0; x < (ssize_t) columns; x++) |
| 1090 | { |
| 1091 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1092 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1093 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1094 | *q++=0U; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1095 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | break; |
| 1099 | } |
| 1100 | if (LocaleCompare(map,"I") == 0) |
| 1101 | { |
| 1102 | for (y=0; y < (ssize_t) rows; y++) |
| 1103 | { |
| 1104 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1105 | if (p == (const Quantum *) NULL) |
| 1106 | break; |
| 1107 | for (x=0; x < (ssize_t) columns; x++) |
| 1108 | { |
| 1109 | *q++=(unsigned int) ScaleQuantumToLong( |
| 1110 | GetPixelIntensity(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1111 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | break; |
| 1115 | } |
| 1116 | if (LocaleCompare(map,"RGB") == 0) |
| 1117 | { |
| 1118 | for (y=0; y < (ssize_t) rows; y++) |
| 1119 | { |
| 1120 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1121 | if (p == (const Quantum *) NULL) |
| 1122 | break; |
| 1123 | for (x=0; x < (ssize_t) columns; x++) |
| 1124 | { |
| 1125 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1126 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1127 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1128 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1129 | } |
| 1130 | } |
| 1131 | break; |
| 1132 | } |
| 1133 | if (LocaleCompare(map,"RGBA") == 0) |
| 1134 | { |
| 1135 | for (y=0; y < (ssize_t) rows; y++) |
| 1136 | { |
| 1137 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1138 | if (p == (const Quantum *) NULL) |
| 1139 | break; |
| 1140 | for (x=0; x < (ssize_t) columns; x++) |
| 1141 | { |
| 1142 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1143 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1144 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1145 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1146 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1147 | } |
| 1148 | } |
| 1149 | break; |
| 1150 | } |
| 1151 | if (LocaleCompare(map,"RGBP") == 0) |
| 1152 | { |
| 1153 | for (y=0; y < (ssize_t) rows; y++) |
| 1154 | { |
| 1155 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1156 | if (p == (const Quantum *) NULL) |
| 1157 | break; |
| 1158 | for (x=0; x < (ssize_t) columns; x++) |
| 1159 | { |
| 1160 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1161 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1162 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1163 | *q++=0U; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1164 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | break; |
| 1168 | } |
| 1169 | for (y=0; y < (ssize_t) rows; y++) |
| 1170 | { |
| 1171 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1172 | if (p == (const Quantum *) NULL) |
| 1173 | break; |
| 1174 | for (x=0; x < (ssize_t) columns; x++) |
| 1175 | { |
| 1176 | for (i=0; i < (ssize_t) length; i++) |
| 1177 | { |
| 1178 | *q=0; |
| 1179 | switch (quantum_map[i]) |
| 1180 | { |
| 1181 | case RedQuantum: |
| 1182 | case CyanQuantum: |
| 1183 | { |
| 1184 | *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1185 | break; |
| 1186 | } |
| 1187 | case GreenQuantum: |
| 1188 | case MagentaQuantum: |
| 1189 | { |
| 1190 | *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1191 | break; |
| 1192 | } |
| 1193 | case BlueQuantum: |
| 1194 | case YellowQuantum: |
| 1195 | { |
| 1196 | *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1197 | break; |
| 1198 | } |
| 1199 | case AlphaQuantum: |
| 1200 | { |
| 1201 | *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p)); |
| 1202 | break; |
| 1203 | } |
| 1204 | case OpacityQuantum: |
| 1205 | { |
| 1206 | *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p)); |
| 1207 | break; |
| 1208 | } |
| 1209 | case BlackQuantum: |
| 1210 | { |
| 1211 | if (image->colorspace == CMYKColorspace) |
| 1212 | *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p)); |
| 1213 | break; |
| 1214 | } |
| 1215 | case IndexQuantum: |
| 1216 | { |
| 1217 | *q=(unsigned int) ScaleQuantumToLong( |
| 1218 | GetPixelIntensity(image,p)); |
| 1219 | break; |
| 1220 | } |
| 1221 | default: |
| 1222 | *q=0; |
| 1223 | } |
| 1224 | q++; |
| 1225 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1226 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | break; |
| 1230 | } |
| 1231 | case LongPixel: |
| 1232 | { |
| 1233 | register size_t |
| 1234 | *q; |
| 1235 | |
| 1236 | q=(size_t *) pixels; |
| 1237 | if (LocaleCompare(map,"BGR") == 0) |
| 1238 | { |
| 1239 | for (y=0; y < (ssize_t) rows; y++) |
| 1240 | { |
| 1241 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1242 | if (p == (const Quantum *) NULL) |
| 1243 | break; |
| 1244 | for (x=0; x < (ssize_t) columns; x++) |
| 1245 | { |
| 1246 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1247 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1248 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1249 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | break; |
| 1253 | } |
| 1254 | if (LocaleCompare(map,"BGRA") == 0) |
| 1255 | { |
| 1256 | for (y=0; y < (ssize_t) rows; y++) |
| 1257 | { |
| 1258 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1259 | if (p == (const Quantum *) NULL) |
| 1260 | break; |
| 1261 | for (x=0; x < (ssize_t) columns; x++) |
| 1262 | { |
| 1263 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1264 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1265 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1266 | *q++=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1267 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1268 | } |
| 1269 | } |
| 1270 | break; |
| 1271 | } |
| 1272 | if (LocaleCompare(map,"BGRP") == 0) |
| 1273 | { |
| 1274 | for (y=0; y < (ssize_t) rows; y++) |
| 1275 | { |
| 1276 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1277 | if (p == (const Quantum *) NULL) |
| 1278 | break; |
| 1279 | for (x=0; x < (ssize_t) columns; x++) |
| 1280 | { |
| 1281 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1282 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1283 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1284 | *q++=0; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1285 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1286 | } |
| 1287 | } |
| 1288 | break; |
| 1289 | } |
| 1290 | if (LocaleCompare(map,"I") == 0) |
| 1291 | { |
| 1292 | for (y=0; y < (ssize_t) rows; y++) |
| 1293 | { |
| 1294 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1295 | if (p == (const Quantum *) NULL) |
| 1296 | break; |
| 1297 | for (x=0; x < (ssize_t) columns; x++) |
| 1298 | { |
| 1299 | *q++=ScaleQuantumToLong(GetPixelIntensity(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1300 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | break; |
| 1304 | } |
| 1305 | if (LocaleCompare(map,"RGB") == 0) |
| 1306 | { |
| 1307 | for (y=0; y < (ssize_t) rows; y++) |
| 1308 | { |
| 1309 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1310 | if (p == (const Quantum *) NULL) |
| 1311 | break; |
| 1312 | for (x=0; x < (ssize_t) columns; x++) |
| 1313 | { |
| 1314 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1315 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1316 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1317 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | break; |
| 1321 | } |
| 1322 | if (LocaleCompare(map,"RGBA") == 0) |
| 1323 | { |
| 1324 | for (y=0; y < (ssize_t) rows; y++) |
| 1325 | { |
| 1326 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1327 | if (p == (const Quantum *) NULL) |
| 1328 | break; |
| 1329 | for (x=0; x < (ssize_t) columns; x++) |
| 1330 | { |
| 1331 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1332 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1333 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1334 | *q++=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1335 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | break; |
| 1339 | } |
| 1340 | if (LocaleCompare(map,"RGBP") == 0) |
| 1341 | { |
| 1342 | for (y=0; y < (ssize_t) rows; y++) |
| 1343 | { |
| 1344 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1345 | if (p == (const Quantum *) NULL) |
| 1346 | break; |
| 1347 | for (x=0; x < (ssize_t) columns; x++) |
| 1348 | { |
| 1349 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1350 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1351 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1352 | *q++=0; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1353 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | break; |
| 1357 | } |
| 1358 | for (y=0; y < (ssize_t) rows; y++) |
| 1359 | { |
| 1360 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1361 | if (p == (const Quantum *) NULL) |
| 1362 | break; |
| 1363 | for (x=0; x < (ssize_t) columns; x++) |
| 1364 | { |
| 1365 | for (i=0; i < (ssize_t) length; i++) |
| 1366 | { |
| 1367 | *q=0; |
| 1368 | switch (quantum_map[i]) |
| 1369 | { |
| 1370 | case RedQuantum: |
| 1371 | case CyanQuantum: |
| 1372 | { |
| 1373 | *q=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1374 | break; |
| 1375 | } |
| 1376 | case GreenQuantum: |
| 1377 | case MagentaQuantum: |
| 1378 | { |
| 1379 | *q=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1380 | break; |
| 1381 | } |
| 1382 | case BlueQuantum: |
| 1383 | case YellowQuantum: |
| 1384 | { |
| 1385 | *q=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1386 | break; |
| 1387 | } |
| 1388 | case AlphaQuantum: |
| 1389 | { |
| 1390 | *q=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
| 1391 | break; |
| 1392 | } |
| 1393 | case OpacityQuantum: |
| 1394 | { |
| 1395 | *q=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
| 1396 | break; |
| 1397 | } |
| 1398 | case BlackQuantum: |
| 1399 | { |
| 1400 | if (image->colorspace == CMYKColorspace) |
| 1401 | *q=ScaleQuantumToLong(GetPixelBlack(image,p)); |
| 1402 | break; |
| 1403 | } |
| 1404 | case IndexQuantum: |
| 1405 | { |
| 1406 | *q=ScaleQuantumToLong(GetPixelIntensity(image,p)); |
| 1407 | break; |
| 1408 | } |
| 1409 | default: |
| 1410 | break; |
| 1411 | } |
| 1412 | q++; |
| 1413 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1414 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1415 | } |
| 1416 | } |
| 1417 | break; |
| 1418 | } |
| 1419 | case QuantumPixel: |
| 1420 | { |
| 1421 | register Quantum |
| 1422 | *q; |
| 1423 | |
| 1424 | q=(Quantum *) pixels; |
| 1425 | if (LocaleCompare(map,"BGR") == 0) |
| 1426 | { |
| 1427 | for (y=0; y < (ssize_t) rows; y++) |
| 1428 | { |
| 1429 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1430 | if (p == (const Quantum *) NULL) |
| 1431 | break; |
| 1432 | for (x=0; x < (ssize_t) columns; x++) |
| 1433 | { |
| 1434 | *q++=GetPixelBlue(image,p); |
| 1435 | *q++=GetPixelGreen(image,p); |
| 1436 | *q++=GetPixelRed(image,p); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1437 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1438 | } |
| 1439 | } |
| 1440 | break; |
| 1441 | } |
| 1442 | if (LocaleCompare(map,"BGRA") == 0) |
| 1443 | { |
| 1444 | for (y=0; y < (ssize_t) rows; y++) |
| 1445 | { |
| 1446 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1447 | if (p == (const Quantum *) NULL) |
| 1448 | break; |
| 1449 | for (x=0; x < (ssize_t) columns; x++) |
| 1450 | { |
| 1451 | *q++=GetPixelBlue(image,p); |
| 1452 | *q++=GetPixelGreen(image,p); |
| 1453 | *q++=GetPixelRed(image,p); |
| 1454 | *q++=(Quantum) (GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1455 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1456 | } |
| 1457 | } |
| 1458 | break; |
| 1459 | } |
| 1460 | if (LocaleCompare(map,"BGRP") == 0) |
| 1461 | { |
| 1462 | for (y=0; y < (ssize_t) rows; y++) |
| 1463 | { |
| 1464 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1465 | if (p == (const Quantum *) NULL) |
| 1466 | break; |
| 1467 | for (x=0; x < (ssize_t) columns; x++) |
| 1468 | { |
| 1469 | *q++=GetPixelBlue(image,p); |
| 1470 | *q++=GetPixelGreen(image,p); |
| 1471 | *q++=GetPixelRed(image,p); |
| 1472 | *q++=(Quantum) 0; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1473 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1474 | } |
| 1475 | } |
| 1476 | break; |
| 1477 | } |
| 1478 | if (LocaleCompare(map,"I") == 0) |
| 1479 | { |
| 1480 | for (y=0; y < (ssize_t) rows; y++) |
| 1481 | { |
| 1482 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1483 | if (p == (const Quantum *) NULL) |
| 1484 | break; |
| 1485 | for (x=0; x < (ssize_t) columns; x++) |
| 1486 | { |
| 1487 | *q++=GetPixelIntensity(image,p); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1488 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1489 | } |
| 1490 | } |
| 1491 | break; |
| 1492 | } |
| 1493 | if (LocaleCompare(map,"RGB") == 0) |
| 1494 | { |
| 1495 | for (y=0; y < (ssize_t) rows; y++) |
| 1496 | { |
| 1497 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1498 | if (p == (const Quantum *) NULL) |
| 1499 | break; |
| 1500 | for (x=0; x < (ssize_t) columns; x++) |
| 1501 | { |
| 1502 | *q++=GetPixelRed(image,p); |
| 1503 | *q++=GetPixelGreen(image,p); |
| 1504 | *q++=GetPixelBlue(image,p); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1505 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1506 | } |
| 1507 | } |
| 1508 | break; |
| 1509 | } |
| 1510 | if (LocaleCompare(map,"RGBA") == 0) |
| 1511 | { |
| 1512 | for (y=0; y < (ssize_t) rows; y++) |
| 1513 | { |
| 1514 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1515 | if (p == (const Quantum *) NULL) |
| 1516 | break; |
| 1517 | for (x=0; x < (ssize_t) columns; x++) |
| 1518 | { |
| 1519 | *q++=GetPixelRed(image,p); |
| 1520 | *q++=GetPixelGreen(image,p); |
| 1521 | *q++=GetPixelBlue(image,p); |
| 1522 | *q++=(Quantum) (GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1523 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1524 | } |
| 1525 | } |
| 1526 | break; |
| 1527 | } |
| 1528 | if (LocaleCompare(map,"RGBP") == 0) |
| 1529 | { |
| 1530 | for (y=0; y < (ssize_t) rows; y++) |
| 1531 | { |
| 1532 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1533 | if (p == (const Quantum *) NULL) |
| 1534 | break; |
| 1535 | for (x=0; x < (ssize_t) columns; x++) |
| 1536 | { |
| 1537 | *q++=GetPixelRed(image,p); |
| 1538 | *q++=GetPixelGreen(image,p); |
| 1539 | *q++=GetPixelBlue(image,p); |
| 1540 | *q++=(Quantum) 0; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1541 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | break; |
| 1545 | } |
| 1546 | for (y=0; y < (ssize_t) rows; y++) |
| 1547 | { |
| 1548 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1549 | if (p == (const Quantum *) NULL) |
| 1550 | break; |
| 1551 | for (x=0; x < (ssize_t) columns; x++) |
| 1552 | { |
| 1553 | for (i=0; i < (ssize_t) length; i++) |
| 1554 | { |
| 1555 | *q=(Quantum) 0; |
| 1556 | switch (quantum_map[i]) |
| 1557 | { |
| 1558 | case RedQuantum: |
| 1559 | case CyanQuantum: |
| 1560 | { |
| 1561 | *q=GetPixelRed(image,p); |
| 1562 | break; |
| 1563 | } |
| 1564 | case GreenQuantum: |
| 1565 | case MagentaQuantum: |
| 1566 | { |
| 1567 | *q=GetPixelGreen(image,p); |
| 1568 | break; |
| 1569 | } |
| 1570 | case BlueQuantum: |
| 1571 | case YellowQuantum: |
| 1572 | { |
| 1573 | *q=GetPixelBlue(image,p); |
| 1574 | break; |
| 1575 | } |
| 1576 | case AlphaQuantum: |
| 1577 | { |
| 1578 | *q=(Quantum) (GetPixelAlpha(image,p)); |
| 1579 | break; |
| 1580 | } |
| 1581 | case OpacityQuantum: |
| 1582 | { |
| 1583 | *q=GetPixelAlpha(image,p); |
| 1584 | break; |
| 1585 | } |
| 1586 | case BlackQuantum: |
| 1587 | { |
| 1588 | if (image->colorspace == CMYKColorspace) |
| 1589 | *q=GetPixelBlack(image,p); |
| 1590 | break; |
| 1591 | } |
| 1592 | case IndexQuantum: |
| 1593 | { |
| 1594 | *q=(GetPixelIntensity(image,p)); |
| 1595 | break; |
| 1596 | } |
| 1597 | default: |
| 1598 | *q=(Quantum) 0; |
| 1599 | } |
| 1600 | q++; |
| 1601 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1602 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1603 | } |
| 1604 | } |
| 1605 | break; |
| 1606 | } |
| 1607 | case ShortPixel: |
| 1608 | { |
| 1609 | register unsigned short |
| 1610 | *q; |
| 1611 | |
| 1612 | q=(unsigned short *) pixels; |
| 1613 | if (LocaleCompare(map,"BGR") == 0) |
| 1614 | { |
| 1615 | for (y=0; y < (ssize_t) rows; y++) |
| 1616 | { |
| 1617 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1618 | if (p == (const Quantum *) NULL) |
| 1619 | break; |
| 1620 | for (x=0; x < (ssize_t) columns; x++) |
| 1621 | { |
| 1622 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1623 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1624 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1625 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1626 | } |
| 1627 | } |
| 1628 | break; |
| 1629 | } |
| 1630 | if (LocaleCompare(map,"BGRA") == 0) |
| 1631 | { |
| 1632 | for (y=0; y < (ssize_t) rows; y++) |
| 1633 | { |
| 1634 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1635 | if (p == (const Quantum *) NULL) |
| 1636 | break; |
| 1637 | for (x=0; x < (ssize_t) columns; x++) |
| 1638 | { |
| 1639 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1640 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1641 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1642 | *q++=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1643 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1644 | } |
| 1645 | } |
| 1646 | break; |
| 1647 | } |
| 1648 | if (LocaleCompare(map,"BGRP") == 0) |
| 1649 | { |
| 1650 | for (y=0; y < (ssize_t) rows; y++) |
| 1651 | { |
| 1652 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1653 | if (p == (const Quantum *) NULL) |
| 1654 | break; |
| 1655 | for (x=0; x < (ssize_t) columns; x++) |
| 1656 | { |
| 1657 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1658 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1659 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1660 | *q++=0; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1661 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1662 | } |
| 1663 | } |
| 1664 | break; |
| 1665 | } |
| 1666 | if (LocaleCompare(map,"I") == 0) |
| 1667 | { |
| 1668 | for (y=0; y < (ssize_t) rows; y++) |
| 1669 | { |
| 1670 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1671 | if (p == (const Quantum *) NULL) |
| 1672 | break; |
| 1673 | for (x=0; x < (ssize_t) columns; x++) |
| 1674 | { |
| 1675 | *q++=ScaleQuantumToShort(GetPixelIntensity(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1676 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1677 | } |
| 1678 | } |
| 1679 | break; |
| 1680 | } |
| 1681 | if (LocaleCompare(map,"RGB") == 0) |
| 1682 | { |
| 1683 | for (y=0; y < (ssize_t) rows; y++) |
| 1684 | { |
| 1685 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1686 | if (p == (const Quantum *) NULL) |
| 1687 | break; |
| 1688 | for (x=0; x < (ssize_t) columns; x++) |
| 1689 | { |
| 1690 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1691 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1692 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1693 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1694 | } |
| 1695 | } |
| 1696 | break; |
| 1697 | } |
| 1698 | if (LocaleCompare(map,"RGBA") == 0) |
| 1699 | { |
| 1700 | for (y=0; y < (ssize_t) rows; y++) |
| 1701 | { |
| 1702 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1703 | if (p == (const Quantum *) NULL) |
| 1704 | break; |
| 1705 | for (x=0; x < (ssize_t) columns; x++) |
| 1706 | { |
| 1707 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1708 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1709 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1710 | *q++=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1711 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1712 | } |
| 1713 | } |
| 1714 | break; |
| 1715 | } |
| 1716 | if (LocaleCompare(map,"RGBP") == 0) |
| 1717 | { |
| 1718 | for (y=0; y < (ssize_t) rows; y++) |
| 1719 | { |
| 1720 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1721 | if (p == (const Quantum *) NULL) |
| 1722 | break; |
| 1723 | for (x=0; x < (ssize_t) columns; x++) |
| 1724 | { |
| 1725 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1726 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1727 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1728 | *q++=0; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1729 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1730 | } |
| 1731 | } |
| 1732 | break; |
| 1733 | } |
| 1734 | for (y=0; y < (ssize_t) rows; y++) |
| 1735 | { |
| 1736 | p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 1737 | if (p == (const Quantum *) NULL) |
| 1738 | break; |
| 1739 | for (x=0; x < (ssize_t) columns; x++) |
| 1740 | { |
| 1741 | for (i=0; i < (ssize_t) length; i++) |
| 1742 | { |
| 1743 | *q=0; |
| 1744 | switch (quantum_map[i]) |
| 1745 | { |
| 1746 | case RedQuantum: |
| 1747 | case CyanQuantum: |
| 1748 | { |
| 1749 | *q=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1750 | break; |
| 1751 | } |
| 1752 | case GreenQuantum: |
| 1753 | case MagentaQuantum: |
| 1754 | { |
| 1755 | *q=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1756 | break; |
| 1757 | } |
| 1758 | case BlueQuantum: |
| 1759 | case YellowQuantum: |
| 1760 | { |
| 1761 | *q=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1762 | break; |
| 1763 | } |
| 1764 | case AlphaQuantum: |
| 1765 | { |
| 1766 | *q=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1767 | break; |
| 1768 | } |
| 1769 | case OpacityQuantum: |
| 1770 | { |
| 1771 | *q=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1772 | break; |
| 1773 | } |
| 1774 | case BlackQuantum: |
| 1775 | { |
| 1776 | if (image->colorspace == CMYKColorspace) |
| 1777 | *q=ScaleQuantumToShort(GetPixelBlack(image,p)); |
| 1778 | break; |
| 1779 | } |
| 1780 | case IndexQuantum: |
| 1781 | { |
| 1782 | *q=ScaleQuantumToShort(GetPixelIntensity(image,p)); |
| 1783 | break; |
| 1784 | } |
| 1785 | default: |
| 1786 | break; |
| 1787 | } |
| 1788 | q++; |
| 1789 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1790 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1791 | } |
| 1792 | } |
| 1793 | break; |
| 1794 | } |
| 1795 | default: |
| 1796 | { |
| 1797 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1798 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 1799 | "UnrecognizedPixelMap","`%s'",map); |
| 1800 | break; |
| 1801 | } |
| 1802 | } |
| 1803 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1804 | return(MagickTrue); |
| 1805 | } |
| 1806 | |
| 1807 | /* |
| 1808 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1809 | % % |
| 1810 | % % |
| 1811 | % % |
cristy | aa8634f | 2011-10-01 13:25:12 +0000 | [diff] [blame] | 1812 | % G e t P i x e l I n f o % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1813 | % % |
| 1814 | % % |
| 1815 | % % |
| 1816 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1817 | % |
| 1818 | % GetPixelInfo() initializes the PixelInfo structure. |
| 1819 | % |
| 1820 | % The format of the GetPixelInfo method is: |
| 1821 | % |
| 1822 | % GetPixelInfo(const Image *image,PixelInfo *pixel) |
| 1823 | % |
| 1824 | % A description of each parameter follows: |
| 1825 | % |
| 1826 | % o image: the image. |
| 1827 | % |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 1828 | % o pixel: Specifies a pointer to a PixelInfo structure. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1829 | % |
| 1830 | */ |
cristy | aa8634f | 2011-10-01 13:25:12 +0000 | [diff] [blame] | 1831 | MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1832 | { |
| 1833 | pixel->storage_class=DirectClass; |
| 1834 | pixel->colorspace=RGBColorspace; |
| 1835 | pixel->matte=MagickFalse; |
| 1836 | pixel->fuzz=0.0; |
| 1837 | pixel->depth=MAGICKCORE_QUANTUM_DEPTH; |
| 1838 | pixel->red=0.0; |
| 1839 | pixel->green=0.0; |
| 1840 | pixel->blue=0.0; |
| 1841 | pixel->black=0.0; |
| 1842 | pixel->alpha=(MagickRealType) OpaqueAlpha; |
| 1843 | pixel->index=0.0; |
| 1844 | if (image == (const Image *) NULL) |
| 1845 | return; |
| 1846 | pixel->storage_class=image->storage_class; |
| 1847 | pixel->colorspace=image->colorspace; |
| 1848 | pixel->matte=image->matte; |
| 1849 | pixel->depth=image->depth; |
| 1850 | pixel->fuzz=image->fuzz; |
| 1851 | } |
| 1852 | |
| 1853 | /* |
| 1854 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1855 | % % |
| 1856 | % % |
| 1857 | % % |
| 1858 | % I m p o r t I m a g e P i x e l s % |
| 1859 | % % |
| 1860 | % % |
| 1861 | % % |
| 1862 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1863 | % |
| 1864 | % ImportImagePixels() accepts pixel data and stores in the image at the |
| 1865 | % location you specify. The method returns MagickTrue on success otherwise |
| 1866 | % MagickFalse if an error is encountered. The pixel data can be either char, |
| 1867 | % short int, int, ssize_t, float, or double in the order specified by map. |
| 1868 | % |
| 1869 | % Suppose your want to upload the first scanline of a 640x480 image from |
| 1870 | % character data in red-green-blue order: |
| 1871 | % |
| 1872 | % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels); |
| 1873 | % |
| 1874 | % The format of the ImportImagePixels method is: |
| 1875 | % |
| 1876 | % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x_offset, |
| 1877 | % const ssize_t y_offset,const size_t columns, |
| 1878 | % const size_t rows,const char *map,const StorageType type, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1879 | % const void *pixels,ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1880 | % |
| 1881 | % A description of each parameter follows: |
| 1882 | % |
| 1883 | % o image: the image. |
| 1884 | % |
| 1885 | % o x_offset,y_offset,columns,rows: These values define the perimeter |
| 1886 | % of a region of pixels you want to define. |
| 1887 | % |
| 1888 | % o map: This string reflects the expected ordering of the pixel array. |
| 1889 | % It can be any combination or order of R = red, G = green, B = blue, |
| 1890 | % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan, |
| 1891 | % Y = yellow, M = magenta, K = black, I = intensity (for grayscale), |
| 1892 | % P = pad. |
| 1893 | % |
| 1894 | % o type: Define the data type of the pixels. Float and double types are |
| 1895 | % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these |
| 1896 | % types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or |
| 1897 | % DoublePixel. |
| 1898 | % |
| 1899 | % o pixels: This array of values contain the pixel components as defined by |
| 1900 | % map and type. You must preallocate this array where the expected |
| 1901 | % length varies depending on the values of width, height, map, and type. |
| 1902 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1903 | % o exception: return any errors or warnings in this structure. |
| 1904 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1905 | */ |
| 1906 | MagickExport MagickBooleanType ImportImagePixels(Image *image, |
| 1907 | const ssize_t x_offset,const ssize_t y_offset,const size_t columns, |
| 1908 | const size_t rows,const char *map,const StorageType type, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1909 | const void *pixels,ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1910 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1911 | QuantumType |
| 1912 | *quantum_map; |
| 1913 | |
| 1914 | register Quantum |
| 1915 | *q; |
| 1916 | |
| 1917 | register ssize_t |
| 1918 | i, |
| 1919 | x; |
| 1920 | |
| 1921 | size_t |
| 1922 | length; |
| 1923 | |
| 1924 | ssize_t |
| 1925 | y; |
| 1926 | |
| 1927 | /* |
| 1928 | Allocate image structure. |
| 1929 | */ |
| 1930 | assert(image != (Image *) NULL); |
| 1931 | assert(image->signature == MagickSignature); |
| 1932 | if (image->debug != MagickFalse) |
| 1933 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1934 | length=strlen(map); |
| 1935 | quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map)); |
| 1936 | if (quantum_map == (QuantumType *) NULL) |
| 1937 | ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", |
| 1938 | image->filename); |
| 1939 | for (i=0; i < (ssize_t) length; i++) |
| 1940 | { |
| 1941 | switch (map[i]) |
| 1942 | { |
| 1943 | case 'a': |
| 1944 | case 'A': |
| 1945 | { |
| 1946 | quantum_map[i]=AlphaQuantum; |
| 1947 | image->matte=MagickTrue; |
| 1948 | break; |
| 1949 | } |
| 1950 | case 'B': |
| 1951 | case 'b': |
| 1952 | { |
| 1953 | quantum_map[i]=BlueQuantum; |
| 1954 | break; |
| 1955 | } |
| 1956 | case 'C': |
| 1957 | case 'c': |
| 1958 | { |
| 1959 | quantum_map[i]=CyanQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 1960 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1961 | break; |
| 1962 | } |
| 1963 | case 'g': |
| 1964 | case 'G': |
| 1965 | { |
| 1966 | quantum_map[i]=GreenQuantum; |
| 1967 | break; |
| 1968 | } |
| 1969 | case 'K': |
| 1970 | case 'k': |
| 1971 | { |
| 1972 | quantum_map[i]=BlackQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 1973 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1974 | break; |
| 1975 | } |
| 1976 | case 'I': |
| 1977 | case 'i': |
| 1978 | { |
| 1979 | quantum_map[i]=IndexQuantum; |
| 1980 | break; |
| 1981 | } |
| 1982 | case 'm': |
| 1983 | case 'M': |
| 1984 | { |
| 1985 | quantum_map[i]=MagentaQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 1986 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1987 | break; |
| 1988 | } |
| 1989 | case 'O': |
| 1990 | case 'o': |
| 1991 | { |
| 1992 | quantum_map[i]=OpacityQuantum; |
| 1993 | image->matte=MagickTrue; |
| 1994 | break; |
| 1995 | } |
| 1996 | case 'P': |
| 1997 | case 'p': |
| 1998 | { |
| 1999 | quantum_map[i]=UndefinedQuantum; |
| 2000 | break; |
| 2001 | } |
| 2002 | case 'R': |
| 2003 | case 'r': |
| 2004 | { |
| 2005 | quantum_map[i]=RedQuantum; |
| 2006 | break; |
| 2007 | } |
| 2008 | case 'Y': |
| 2009 | case 'y': |
| 2010 | { |
| 2011 | quantum_map[i]=YellowQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 2012 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2013 | break; |
| 2014 | } |
| 2015 | default: |
| 2016 | { |
| 2017 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 2018 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 2019 | "UnrecognizedPixelMap","`%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2020 | return(MagickFalse); |
| 2021 | } |
| 2022 | } |
| 2023 | } |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 2024 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2025 | return(MagickFalse); |
| 2026 | /* |
| 2027 | Transfer the pixels from the pixel datarray to the image. |
| 2028 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2029 | switch (type) |
| 2030 | { |
| 2031 | case CharPixel: |
| 2032 | { |
| 2033 | register const unsigned char |
| 2034 | *p; |
| 2035 | |
| 2036 | p=(const unsigned char *) pixels; |
| 2037 | if (LocaleCompare(map,"BGR") == 0) |
| 2038 | { |
| 2039 | for (y=0; y < (ssize_t) rows; y++) |
| 2040 | { |
| 2041 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2042 | if (q == (Quantum *) NULL) |
| 2043 | break; |
| 2044 | for (x=0; x < (ssize_t) columns; x++) |
| 2045 | { |
| 2046 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2047 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2048 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2049 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2050 | } |
| 2051 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2052 | break; |
| 2053 | } |
| 2054 | break; |
| 2055 | } |
| 2056 | if (LocaleCompare(map,"BGRA") == 0) |
| 2057 | { |
| 2058 | for (y=0; y < (ssize_t) rows; y++) |
| 2059 | { |
| 2060 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2061 | if (q == (Quantum *) NULL) |
| 2062 | break; |
| 2063 | for (x=0; x < (ssize_t) columns; x++) |
| 2064 | { |
| 2065 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2066 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2067 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2068 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2069 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2070 | } |
| 2071 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2072 | break; |
| 2073 | } |
| 2074 | break; |
| 2075 | } |
| 2076 | if (LocaleCompare(map,"BGRO") == 0) |
| 2077 | { |
| 2078 | for (y=0; y < (ssize_t) rows; y++) |
| 2079 | { |
| 2080 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2081 | if (q == (Quantum *) NULL) |
| 2082 | break; |
| 2083 | for (x=0; x < (ssize_t) columns; x++) |
| 2084 | { |
| 2085 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2086 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2087 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2088 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2089 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2090 | } |
| 2091 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2092 | break; |
| 2093 | } |
| 2094 | break; |
| 2095 | } |
| 2096 | if (LocaleCompare(map,"BGRP") == 0) |
| 2097 | { |
| 2098 | for (y=0; y < (ssize_t) rows; y++) |
| 2099 | { |
| 2100 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2101 | if (q == (Quantum *) NULL) |
| 2102 | break; |
| 2103 | for (x=0; x < (ssize_t) columns; x++) |
| 2104 | { |
| 2105 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2106 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2107 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2108 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2109 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2110 | } |
| 2111 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2112 | break; |
| 2113 | } |
| 2114 | break; |
| 2115 | } |
| 2116 | if (LocaleCompare(map,"I") == 0) |
| 2117 | { |
| 2118 | for (y=0; y < (ssize_t) rows; y++) |
| 2119 | { |
| 2120 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2121 | if (q == (Quantum *) NULL) |
| 2122 | break; |
| 2123 | for (x=0; x < (ssize_t) columns; x++) |
| 2124 | { |
| 2125 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2126 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 2127 | SetPixelBlue(image,GetPixelRed(image,q),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2128 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2129 | } |
| 2130 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2131 | break; |
| 2132 | } |
| 2133 | break; |
| 2134 | } |
| 2135 | if (LocaleCompare(map,"RGB") == 0) |
| 2136 | { |
| 2137 | for (y=0; y < (ssize_t) rows; y++) |
| 2138 | { |
| 2139 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2140 | if (q == (Quantum *) NULL) |
| 2141 | break; |
| 2142 | for (x=0; x < (ssize_t) columns; x++) |
| 2143 | { |
| 2144 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2145 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2146 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2147 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2148 | } |
| 2149 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2150 | break; |
| 2151 | } |
| 2152 | break; |
| 2153 | } |
| 2154 | if (LocaleCompare(map,"RGBA") == 0) |
| 2155 | { |
| 2156 | for (y=0; y < (ssize_t) rows; y++) |
| 2157 | { |
| 2158 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2159 | if (q == (Quantum *) NULL) |
| 2160 | break; |
| 2161 | for (x=0; x < (ssize_t) columns; x++) |
| 2162 | { |
| 2163 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2164 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2165 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2166 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2167 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2168 | } |
| 2169 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2170 | break; |
| 2171 | } |
| 2172 | break; |
| 2173 | } |
| 2174 | if (LocaleCompare(map,"RGBO") == 0) |
| 2175 | { |
| 2176 | for (y=0; y < (ssize_t) rows; y++) |
| 2177 | { |
| 2178 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2179 | if (q == (Quantum *) NULL) |
| 2180 | break; |
| 2181 | for (x=0; x < (ssize_t) columns; x++) |
| 2182 | { |
| 2183 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2184 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2185 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2186 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2187 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2188 | } |
| 2189 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2190 | break; |
| 2191 | } |
| 2192 | break; |
| 2193 | } |
| 2194 | if (LocaleCompare(map,"RGBP") == 0) |
| 2195 | { |
| 2196 | for (y=0; y < (ssize_t) rows; y++) |
| 2197 | { |
| 2198 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2199 | if (q == (Quantum *) NULL) |
| 2200 | break; |
| 2201 | for (x=0; x < (ssize_t) columns; x++) |
| 2202 | { |
| 2203 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2204 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2205 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2206 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2207 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2208 | } |
| 2209 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2210 | break; |
| 2211 | } |
| 2212 | break; |
| 2213 | } |
| 2214 | for (y=0; y < (ssize_t) rows; y++) |
| 2215 | { |
| 2216 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2217 | if (q == (Quantum *) NULL) |
| 2218 | break; |
| 2219 | for (x=0; x < (ssize_t) columns; x++) |
| 2220 | { |
| 2221 | for (i=0; i < (ssize_t) length; i++) |
| 2222 | { |
| 2223 | switch (quantum_map[i]) |
| 2224 | { |
| 2225 | case RedQuantum: |
| 2226 | case CyanQuantum: |
| 2227 | { |
| 2228 | SetPixelRed(image,ScaleCharToQuantum(*p),q); |
| 2229 | break; |
| 2230 | } |
| 2231 | case GreenQuantum: |
| 2232 | case MagentaQuantum: |
| 2233 | { |
| 2234 | SetPixelGreen(image,ScaleCharToQuantum(*p),q); |
| 2235 | break; |
| 2236 | } |
| 2237 | case BlueQuantum: |
| 2238 | case YellowQuantum: |
| 2239 | { |
| 2240 | SetPixelBlue(image,ScaleCharToQuantum(*p),q); |
| 2241 | break; |
| 2242 | } |
| 2243 | case AlphaQuantum: |
| 2244 | { |
| 2245 | SetPixelAlpha(image,ScaleCharToQuantum(*p),q); |
| 2246 | break; |
| 2247 | } |
| 2248 | case OpacityQuantum: |
| 2249 | { |
| 2250 | SetPixelAlpha(image,ScaleCharToQuantum(*p),q); |
| 2251 | break; |
| 2252 | } |
| 2253 | case BlackQuantum: |
| 2254 | { |
| 2255 | SetPixelBlack(image,ScaleCharToQuantum(*p),q); |
| 2256 | break; |
| 2257 | } |
| 2258 | case IndexQuantum: |
| 2259 | { |
| 2260 | SetPixelRed(image,ScaleCharToQuantum(*p),q); |
| 2261 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 2262 | SetPixelBlue(image,GetPixelRed(image,q),q); |
| 2263 | break; |
| 2264 | } |
| 2265 | default: |
| 2266 | break; |
| 2267 | } |
| 2268 | p++; |
| 2269 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2270 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2271 | } |
| 2272 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2273 | break; |
| 2274 | } |
| 2275 | break; |
| 2276 | } |
| 2277 | case DoublePixel: |
| 2278 | { |
| 2279 | register const double |
| 2280 | *p; |
| 2281 | |
| 2282 | p=(const double *) pixels; |
| 2283 | if (LocaleCompare(map,"BGR") == 0) |
| 2284 | { |
| 2285 | for (y=0; y < (ssize_t) rows; y++) |
| 2286 | { |
| 2287 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2288 | if (q == (Quantum *) NULL) |
| 2289 | break; |
| 2290 | for (x=0; x < (ssize_t) columns; x++) |
| 2291 | { |
| 2292 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2293 | (*p)),q); |
| 2294 | p++; |
| 2295 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2296 | (*p)),q); |
| 2297 | p++; |
| 2298 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2299 | (*p)),q); |
| 2300 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2301 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2302 | } |
| 2303 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2304 | break; |
| 2305 | } |
| 2306 | break; |
| 2307 | } |
| 2308 | if (LocaleCompare(map,"BGRA") == 0) |
| 2309 | { |
| 2310 | for (y=0; y < (ssize_t) rows; y++) |
| 2311 | { |
| 2312 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2313 | if (q == (Quantum *) NULL) |
| 2314 | break; |
| 2315 | for (x=0; x < (ssize_t) columns; x++) |
| 2316 | { |
| 2317 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2318 | (*p)),q); |
| 2319 | p++; |
| 2320 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2321 | (*p)),q); |
| 2322 | p++; |
| 2323 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2324 | (*p)),q); |
| 2325 | p++; |
| 2326 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2327 | (*p)),q); |
| 2328 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2329 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2330 | } |
| 2331 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2332 | break; |
| 2333 | } |
| 2334 | break; |
| 2335 | } |
| 2336 | if (LocaleCompare(map,"BGRP") == 0) |
| 2337 | { |
| 2338 | for (y=0; y < (ssize_t) rows; y++) |
| 2339 | { |
| 2340 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2341 | if (q == (Quantum *) NULL) |
| 2342 | break; |
| 2343 | for (x=0; x < (ssize_t) columns; x++) |
| 2344 | { |
| 2345 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2346 | (*p)),q); |
| 2347 | p++; |
| 2348 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2349 | (*p)),q); |
| 2350 | p++; |
| 2351 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2352 | (*p)),q); |
| 2353 | p++; |
| 2354 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2355 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2356 | } |
| 2357 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2358 | break; |
| 2359 | } |
| 2360 | break; |
| 2361 | } |
| 2362 | if (LocaleCompare(map,"I") == 0) |
| 2363 | { |
| 2364 | for (y=0; y < (ssize_t) rows; y++) |
| 2365 | { |
| 2366 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2367 | if (q == (Quantum *) NULL) |
| 2368 | break; |
| 2369 | for (x=0; x < (ssize_t) columns; x++) |
| 2370 | { |
| 2371 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2372 | (*p)),q); |
| 2373 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 2374 | SetPixelBlue(image,GetPixelRed(image,q),q); |
| 2375 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2376 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2377 | } |
| 2378 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2379 | break; |
| 2380 | } |
| 2381 | break; |
| 2382 | } |
| 2383 | if (LocaleCompare(map,"RGB") == 0) |
| 2384 | { |
| 2385 | for (y=0; y < (ssize_t) rows; y++) |
| 2386 | { |
| 2387 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2388 | if (q == (Quantum *) NULL) |
| 2389 | break; |
| 2390 | for (x=0; x < (ssize_t) columns; x++) |
| 2391 | { |
| 2392 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2393 | (*p)),q); |
| 2394 | p++; |
| 2395 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2396 | (*p)),q); |
| 2397 | p++; |
| 2398 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2399 | (*p)),q); |
| 2400 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2401 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2402 | } |
| 2403 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2404 | break; |
| 2405 | } |
| 2406 | break; |
| 2407 | } |
| 2408 | if (LocaleCompare(map,"RGBA") == 0) |
| 2409 | { |
| 2410 | for (y=0; y < (ssize_t) rows; y++) |
| 2411 | { |
| 2412 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2413 | if (q == (Quantum *) NULL) |
| 2414 | break; |
| 2415 | for (x=0; x < (ssize_t) columns; x++) |
| 2416 | { |
| 2417 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2418 | (*p)),q); |
| 2419 | p++; |
| 2420 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2421 | (*p)),q); |
| 2422 | p++; |
| 2423 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2424 | (*p)),q); |
| 2425 | p++; |
| 2426 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2427 | (*p)),q); |
| 2428 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2429 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2430 | } |
| 2431 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2432 | break; |
| 2433 | } |
| 2434 | break; |
| 2435 | } |
| 2436 | if (LocaleCompare(map,"RGBP") == 0) |
| 2437 | { |
| 2438 | for (y=0; y < (ssize_t) rows; y++) |
| 2439 | { |
| 2440 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2441 | if (q == (Quantum *) NULL) |
| 2442 | break; |
| 2443 | for (x=0; x < (ssize_t) columns; x++) |
| 2444 | { |
| 2445 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2446 | (*p)),q); |
| 2447 | p++; |
| 2448 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2449 | (*p)),q); |
| 2450 | p++; |
| 2451 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2452 | (*p)),q); |
| 2453 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2454 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2455 | } |
| 2456 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2457 | break; |
| 2458 | } |
| 2459 | break; |
| 2460 | } |
| 2461 | for (y=0; y < (ssize_t) rows; y++) |
| 2462 | { |
| 2463 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2464 | if (q == (Quantum *) NULL) |
| 2465 | break; |
| 2466 | for (x=0; x < (ssize_t) columns; x++) |
| 2467 | { |
| 2468 | for (i=0; i < (ssize_t) length; i++) |
| 2469 | { |
| 2470 | switch (quantum_map[i]) |
| 2471 | { |
| 2472 | case RedQuantum: |
| 2473 | case CyanQuantum: |
| 2474 | { |
| 2475 | SetPixelRed(image,ClampToQuantum((MagickRealType) |
| 2476 | QuantumRange*(*p)),q); |
| 2477 | break; |
| 2478 | } |
| 2479 | case GreenQuantum: |
| 2480 | case MagentaQuantum: |
| 2481 | { |
| 2482 | SetPixelGreen(image,ClampToQuantum((MagickRealType) |
| 2483 | QuantumRange*(*p)),q); |
| 2484 | break; |
| 2485 | } |
| 2486 | case BlueQuantum: |
| 2487 | case YellowQuantum: |
| 2488 | { |
| 2489 | SetPixelBlue(image,ClampToQuantum((MagickRealType) |
| 2490 | QuantumRange*(*p)),q); |
| 2491 | break; |
| 2492 | } |
| 2493 | case AlphaQuantum: |
| 2494 | { |
| 2495 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) |
| 2496 | QuantumRange*(*p)),q); |
| 2497 | break; |
| 2498 | } |
| 2499 | case OpacityQuantum: |
| 2500 | { |
| 2501 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) |
| 2502 | QuantumRange*(*p)),q); |
| 2503 | break; |
| 2504 | } |
| 2505 | case BlackQuantum: |
| 2506 | { |
| 2507 | SetPixelBlack(image,ClampToQuantum((MagickRealType) |
| 2508 | QuantumRange*(*p)),q); |
| 2509 | break; |
| 2510 | } |
| 2511 | case IndexQuantum: |
| 2512 | { |
| 2513 | SetPixelRed(image,ClampToQuantum((MagickRealType) |
| 2514 | QuantumRange*(*p)),q); |
| 2515 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 2516 | SetPixelBlue(image,GetPixelRed(image,q),q); |
| 2517 | break; |
| 2518 | } |
| 2519 | default: |
| 2520 | break; |
| 2521 | } |
| 2522 | p++; |
| 2523 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2524 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2525 | } |
| 2526 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2527 | break; |
| 2528 | } |
| 2529 | break; |
| 2530 | } |
| 2531 | case FloatPixel: |
| 2532 | { |
| 2533 | register const float |
| 2534 | *p; |
| 2535 | |
| 2536 | p=(const float *) pixels; |
| 2537 | if (LocaleCompare(map,"BGR") == 0) |
| 2538 | { |
| 2539 | for (y=0; y < (ssize_t) rows; y++) |
| 2540 | { |
| 2541 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2542 | if (q == (Quantum *) NULL) |
| 2543 | break; |
| 2544 | for (x=0; x < (ssize_t) columns; x++) |
| 2545 | { |
| 2546 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2547 | (*p)),q); |
| 2548 | p++; |
| 2549 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2550 | (*p)),q); |
| 2551 | p++; |
| 2552 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2553 | (*p)),q); |
| 2554 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2555 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2556 | } |
| 2557 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2558 | break; |
| 2559 | } |
| 2560 | break; |
| 2561 | } |
| 2562 | if (LocaleCompare(map,"BGRA") == 0) |
| 2563 | { |
| 2564 | for (y=0; y < (ssize_t) rows; y++) |
| 2565 | { |
| 2566 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2567 | if (q == (Quantum *) NULL) |
| 2568 | break; |
| 2569 | for (x=0; x < (ssize_t) columns; x++) |
| 2570 | { |
| 2571 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2572 | (*p)),q); |
| 2573 | p++; |
| 2574 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2575 | (*p)),q); |
| 2576 | p++; |
| 2577 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2578 | (*p)),q); |
| 2579 | p++; |
| 2580 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2581 | (*p)),q); |
| 2582 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2583 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2584 | } |
| 2585 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2586 | break; |
| 2587 | } |
| 2588 | break; |
| 2589 | } |
| 2590 | if (LocaleCompare(map,"BGRP") == 0) |
| 2591 | { |
| 2592 | for (y=0; y < (ssize_t) rows; y++) |
| 2593 | { |
| 2594 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2595 | if (q == (Quantum *) NULL) |
| 2596 | break; |
| 2597 | for (x=0; x < (ssize_t) columns; x++) |
| 2598 | { |
| 2599 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2600 | (*p)),q); |
| 2601 | p++; |
| 2602 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2603 | (*p)),q); |
| 2604 | p++; |
| 2605 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2606 | (*p)),q); |
| 2607 | p++; |
| 2608 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2609 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2610 | } |
| 2611 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2612 | break; |
| 2613 | } |
| 2614 | break; |
| 2615 | } |
| 2616 | if (LocaleCompare(map,"I") == 0) |
| 2617 | { |
| 2618 | for (y=0; y < (ssize_t) rows; y++) |
| 2619 | { |
| 2620 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2621 | if (q == (Quantum *) NULL) |
| 2622 | break; |
| 2623 | for (x=0; x < (ssize_t) columns; x++) |
| 2624 | { |
| 2625 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2626 | (*p)),q); |
| 2627 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 2628 | SetPixelBlue(image,GetPixelRed(image,q),q); |
| 2629 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2630 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2631 | } |
| 2632 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2633 | break; |
| 2634 | } |
| 2635 | break; |
| 2636 | } |
| 2637 | if (LocaleCompare(map,"RGB") == 0) |
| 2638 | { |
| 2639 | for (y=0; y < (ssize_t) rows; y++) |
| 2640 | { |
| 2641 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2642 | if (q == (Quantum *) NULL) |
| 2643 | break; |
| 2644 | for (x=0; x < (ssize_t) columns; x++) |
| 2645 | { |
| 2646 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2647 | (*p)),q); |
| 2648 | p++; |
| 2649 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2650 | (*p)),q); |
| 2651 | p++; |
| 2652 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2653 | (*p)),q); |
| 2654 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2655 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2656 | } |
| 2657 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2658 | break; |
| 2659 | } |
| 2660 | break; |
| 2661 | } |
| 2662 | if (LocaleCompare(map,"RGBA") == 0) |
| 2663 | { |
| 2664 | for (y=0; y < (ssize_t) rows; y++) |
| 2665 | { |
| 2666 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2667 | if (q == (Quantum *) NULL) |
| 2668 | break; |
| 2669 | for (x=0; x < (ssize_t) columns; x++) |
| 2670 | { |
| 2671 | SetPixelRed(image,ClampToQuantum((MagickRealType) |
| 2672 | QuantumRange*(*p)),q); |
| 2673 | p++; |
| 2674 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2675 | (*p)),q); |
| 2676 | p++; |
| 2677 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2678 | (*p)),q); |
| 2679 | p++; |
| 2680 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2681 | (*p)),q); |
| 2682 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2683 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2684 | } |
| 2685 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2686 | break; |
| 2687 | } |
| 2688 | break; |
| 2689 | } |
| 2690 | if (LocaleCompare(map,"RGBP") == 0) |
| 2691 | { |
| 2692 | for (y=0; y < (ssize_t) rows; y++) |
| 2693 | { |
| 2694 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2695 | if (q == (Quantum *) NULL) |
| 2696 | break; |
| 2697 | for (x=0; x < (ssize_t) columns; x++) |
| 2698 | { |
| 2699 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2700 | (*p)),q); |
| 2701 | p++; |
| 2702 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2703 | (*p)),q); |
| 2704 | p++; |
| 2705 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2706 | (*p)),q); |
| 2707 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2708 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2709 | } |
| 2710 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2711 | break; |
| 2712 | } |
| 2713 | break; |
| 2714 | } |
| 2715 | for (y=0; y < (ssize_t) rows; y++) |
| 2716 | { |
| 2717 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2718 | if (q == (Quantum *) NULL) |
| 2719 | break; |
| 2720 | for (x=0; x < (ssize_t) columns; x++) |
| 2721 | { |
| 2722 | for (i=0; i < (ssize_t) length; i++) |
| 2723 | { |
| 2724 | switch (quantum_map[i]) |
| 2725 | { |
| 2726 | case RedQuantum: |
| 2727 | case CyanQuantum: |
| 2728 | { |
| 2729 | SetPixelRed(image,ClampToQuantum((MagickRealType) |
| 2730 | QuantumRange*(*p)),q); |
| 2731 | break; |
| 2732 | } |
| 2733 | case GreenQuantum: |
| 2734 | case MagentaQuantum: |
| 2735 | { |
| 2736 | SetPixelGreen(image,ClampToQuantum((MagickRealType) |
| 2737 | QuantumRange*(*p)),q); |
| 2738 | break; |
| 2739 | } |
| 2740 | case BlueQuantum: |
| 2741 | case YellowQuantum: |
| 2742 | { |
| 2743 | SetPixelBlue(image,ClampToQuantum((MagickRealType) |
| 2744 | QuantumRange*(*p)),q); |
| 2745 | break; |
| 2746 | } |
| 2747 | case AlphaQuantum: |
| 2748 | { |
| 2749 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) |
| 2750 | QuantumRange*(*p)),q); |
| 2751 | break; |
| 2752 | } |
| 2753 | case OpacityQuantum: |
| 2754 | { |
| 2755 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) |
| 2756 | QuantumRange*(*p)),q); |
| 2757 | break; |
| 2758 | } |
| 2759 | case BlackQuantum: |
| 2760 | { |
| 2761 | SetPixelBlack(image,ClampToQuantum((MagickRealType) |
| 2762 | QuantumRange*(*p)),q); |
| 2763 | break; |
| 2764 | } |
| 2765 | case IndexQuantum: |
| 2766 | { |
| 2767 | SetPixelRed(image,ClampToQuantum((MagickRealType) |
| 2768 | QuantumRange*(*p)),q); |
| 2769 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 2770 | SetPixelBlue(image,GetPixelRed(image,q),q); |
| 2771 | break; |
| 2772 | } |
| 2773 | default: |
| 2774 | break; |
| 2775 | } |
| 2776 | p++; |
| 2777 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2778 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2779 | } |
| 2780 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2781 | break; |
| 2782 | } |
| 2783 | break; |
| 2784 | } |
| 2785 | case IntegerPixel: |
| 2786 | { |
| 2787 | register const unsigned int |
| 2788 | *p; |
| 2789 | |
| 2790 | p=(const unsigned int *) pixels; |
| 2791 | if (LocaleCompare(map,"BGR") == 0) |
| 2792 | { |
| 2793 | for (y=0; y < (ssize_t) rows; y++) |
| 2794 | { |
| 2795 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2796 | if (q == (Quantum *) NULL) |
| 2797 | break; |
| 2798 | for (x=0; x < (ssize_t) columns; x++) |
| 2799 | { |
| 2800 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2801 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2802 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2803 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2804 | } |
| 2805 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2806 | break; |
| 2807 | } |
| 2808 | break; |
| 2809 | } |
| 2810 | if (LocaleCompare(map,"BGRA") == 0) |
| 2811 | { |
| 2812 | for (y=0; y < (ssize_t) rows; y++) |
| 2813 | { |
| 2814 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2815 | if (q == (Quantum *) NULL) |
| 2816 | break; |
| 2817 | for (x=0; x < (ssize_t) columns; x++) |
| 2818 | { |
| 2819 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2820 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2821 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2822 | SetPixelAlpha(image,ScaleLongToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2823 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2824 | } |
| 2825 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2826 | break; |
| 2827 | } |
| 2828 | break; |
| 2829 | } |
| 2830 | if (LocaleCompare(map,"BGRP") == 0) |
| 2831 | { |
| 2832 | for (y=0; y < (ssize_t) rows; y++) |
| 2833 | { |
| 2834 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2835 | if (q == (Quantum *) NULL) |
| 2836 | break; |
| 2837 | for (x=0; x < (ssize_t) columns; x++) |
| 2838 | { |
| 2839 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2840 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2841 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2842 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2843 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2844 | } |
| 2845 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2846 | break; |
| 2847 | } |
| 2848 | break; |
| 2849 | } |
| 2850 | if (LocaleCompare(map,"I") == 0) |
| 2851 | { |
| 2852 | for (y=0; y < (ssize_t) rows; y++) |
| 2853 | { |
| 2854 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2855 | if (q == (Quantum *) NULL) |
| 2856 | break; |
| 2857 | for (x=0; x < (ssize_t) columns; x++) |
| 2858 | { |
| 2859 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2860 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 2861 | SetPixelBlue(image,GetPixelRed(image,q),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2862 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2863 | } |
| 2864 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2865 | break; |
| 2866 | } |
| 2867 | break; |
| 2868 | } |
| 2869 | if (LocaleCompare(map,"RGB") == 0) |
| 2870 | { |
| 2871 | for (y=0; y < (ssize_t) rows; y++) |
| 2872 | { |
| 2873 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2874 | if (q == (Quantum *) NULL) |
| 2875 | break; |
| 2876 | for (x=0; x < (ssize_t) columns; x++) |
| 2877 | { |
| 2878 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2879 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2880 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2881 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2882 | } |
| 2883 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2884 | break; |
| 2885 | } |
| 2886 | break; |
| 2887 | } |
| 2888 | if (LocaleCompare(map,"RGBA") == 0) |
| 2889 | { |
| 2890 | for (y=0; y < (ssize_t) rows; y++) |
| 2891 | { |
| 2892 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2893 | if (q == (Quantum *) NULL) |
| 2894 | break; |
| 2895 | for (x=0; x < (ssize_t) columns; x++) |
| 2896 | { |
| 2897 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2898 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2899 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2900 | SetPixelAlpha(image,ScaleLongToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2901 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2902 | } |
| 2903 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2904 | break; |
| 2905 | } |
| 2906 | break; |
| 2907 | } |
| 2908 | if (LocaleCompare(map,"RGBP") == 0) |
| 2909 | { |
| 2910 | for (y=0; y < (ssize_t) rows; y++) |
| 2911 | { |
| 2912 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2913 | if (q == (Quantum *) NULL) |
| 2914 | break; |
| 2915 | for (x=0; x < (ssize_t) columns; x++) |
| 2916 | { |
| 2917 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2918 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2919 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2920 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2921 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2922 | } |
| 2923 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2924 | break; |
| 2925 | } |
| 2926 | break; |
| 2927 | } |
| 2928 | for (y=0; y < (ssize_t) rows; y++) |
| 2929 | { |
| 2930 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 2931 | if (q == (Quantum *) NULL) |
| 2932 | break; |
| 2933 | for (x=0; x < (ssize_t) columns; x++) |
| 2934 | { |
| 2935 | for (i=0; i < (ssize_t) length; i++) |
| 2936 | { |
| 2937 | switch (quantum_map[i]) |
| 2938 | { |
| 2939 | case RedQuantum: |
| 2940 | case CyanQuantum: |
| 2941 | { |
| 2942 | SetPixelRed(image,ScaleLongToQuantum(*p),q); |
| 2943 | break; |
| 2944 | } |
| 2945 | case GreenQuantum: |
| 2946 | case MagentaQuantum: |
| 2947 | { |
| 2948 | SetPixelGreen(image,ScaleLongToQuantum(*p),q); |
| 2949 | break; |
| 2950 | } |
| 2951 | case BlueQuantum: |
| 2952 | case YellowQuantum: |
| 2953 | { |
| 2954 | SetPixelBlue(image,ScaleLongToQuantum(*p),q); |
| 2955 | break; |
| 2956 | } |
| 2957 | case AlphaQuantum: |
| 2958 | { |
| 2959 | SetPixelAlpha(image,ScaleLongToQuantum(*p),q); |
| 2960 | break; |
| 2961 | } |
| 2962 | case OpacityQuantum: |
| 2963 | { |
| 2964 | SetPixelAlpha(image,ScaleLongToQuantum(*p),q); |
| 2965 | break; |
| 2966 | } |
| 2967 | case BlackQuantum: |
| 2968 | { |
| 2969 | SetPixelBlack(image,ScaleLongToQuantum(*p),q); |
| 2970 | break; |
| 2971 | } |
| 2972 | case IndexQuantum: |
| 2973 | { |
| 2974 | SetPixelRed(image,ScaleLongToQuantum(*p),q); |
| 2975 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 2976 | SetPixelBlue(image,GetPixelRed(image,q),q); |
| 2977 | break; |
| 2978 | } |
| 2979 | default: |
| 2980 | break; |
| 2981 | } |
| 2982 | p++; |
| 2983 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2984 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2985 | } |
| 2986 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2987 | break; |
| 2988 | } |
| 2989 | break; |
| 2990 | } |
| 2991 | case LongPixel: |
| 2992 | { |
| 2993 | register const unsigned int |
| 2994 | *p; |
| 2995 | |
| 2996 | p=(const unsigned int *) pixels; |
| 2997 | if (LocaleCompare(map,"BGR") == 0) |
| 2998 | { |
| 2999 | for (y=0; y < (ssize_t) rows; y++) |
| 3000 | { |
| 3001 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3002 | if (q == (Quantum *) NULL) |
| 3003 | break; |
| 3004 | for (x=0; x < (ssize_t) columns; x++) |
| 3005 | { |
| 3006 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 3007 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 3008 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3009 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3010 | } |
| 3011 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3012 | break; |
| 3013 | } |
| 3014 | break; |
| 3015 | } |
| 3016 | if (LocaleCompare(map,"BGRA") == 0) |
| 3017 | { |
| 3018 | for (y=0; y < (ssize_t) rows; y++) |
| 3019 | { |
| 3020 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3021 | if (q == (Quantum *) NULL) |
| 3022 | break; |
| 3023 | for (x=0; x < (ssize_t) columns; x++) |
| 3024 | { |
| 3025 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 3026 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 3027 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 3028 | SetPixelAlpha(image,ScaleLongToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3029 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3030 | } |
| 3031 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3032 | break; |
| 3033 | } |
| 3034 | break; |
| 3035 | } |
| 3036 | if (LocaleCompare(map,"BGRP") == 0) |
| 3037 | { |
| 3038 | for (y=0; y < (ssize_t) rows; y++) |
| 3039 | { |
| 3040 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3041 | if (q == (Quantum *) NULL) |
| 3042 | break; |
| 3043 | for (x=0; x < (ssize_t) columns; x++) |
| 3044 | { |
| 3045 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 3046 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 3047 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 3048 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3049 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3050 | } |
| 3051 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3052 | break; |
| 3053 | } |
| 3054 | break; |
| 3055 | } |
| 3056 | if (LocaleCompare(map,"I") == 0) |
| 3057 | { |
| 3058 | for (y=0; y < (ssize_t) rows; y++) |
| 3059 | { |
| 3060 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3061 | if (q == (Quantum *) NULL) |
| 3062 | break; |
| 3063 | for (x=0; x < (ssize_t) columns; x++) |
| 3064 | { |
| 3065 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 3066 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 3067 | SetPixelBlue(image,GetPixelRed(image,q),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3068 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3069 | } |
| 3070 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3071 | break; |
| 3072 | } |
| 3073 | break; |
| 3074 | } |
| 3075 | if (LocaleCompare(map,"RGB") == 0) |
| 3076 | { |
| 3077 | for (y=0; y < (ssize_t) rows; y++) |
| 3078 | { |
| 3079 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3080 | if (q == (Quantum *) NULL) |
| 3081 | break; |
| 3082 | for (x=0; x < (ssize_t) columns; x++) |
| 3083 | { |
| 3084 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 3085 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 3086 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3087 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3088 | } |
| 3089 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3090 | break; |
| 3091 | } |
| 3092 | break; |
| 3093 | } |
| 3094 | if (LocaleCompare(map,"RGBA") == 0) |
| 3095 | { |
| 3096 | for (y=0; y < (ssize_t) rows; y++) |
| 3097 | { |
| 3098 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3099 | if (q == (Quantum *) NULL) |
| 3100 | break; |
| 3101 | for (x=0; x < (ssize_t) columns; x++) |
| 3102 | { |
| 3103 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 3104 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 3105 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 3106 | SetPixelAlpha(image,ScaleLongToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3107 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3108 | } |
| 3109 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3110 | break; |
| 3111 | } |
| 3112 | break; |
| 3113 | } |
| 3114 | if (LocaleCompare(map,"RGBP") == 0) |
| 3115 | { |
| 3116 | for (y=0; y < (ssize_t) rows; y++) |
| 3117 | { |
| 3118 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3119 | if (q == (Quantum *) NULL) |
| 3120 | break; |
| 3121 | for (x=0; x < (ssize_t) columns; x++) |
| 3122 | { |
| 3123 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 3124 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 3125 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 3126 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3127 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3128 | } |
| 3129 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3130 | break; |
| 3131 | } |
| 3132 | break; |
| 3133 | } |
| 3134 | for (y=0; y < (ssize_t) rows; y++) |
| 3135 | { |
| 3136 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3137 | if (q == (Quantum *) NULL) |
| 3138 | break; |
| 3139 | for (x=0; x < (ssize_t) columns; x++) |
| 3140 | { |
| 3141 | for (i=0; i < (ssize_t) length; i++) |
| 3142 | { |
| 3143 | switch (quantum_map[i]) |
| 3144 | { |
| 3145 | case RedQuantum: |
| 3146 | case CyanQuantum: |
| 3147 | { |
| 3148 | SetPixelRed(image,ScaleLongToQuantum(*p),q); |
| 3149 | break; |
| 3150 | } |
| 3151 | case GreenQuantum: |
| 3152 | case MagentaQuantum: |
| 3153 | { |
| 3154 | SetPixelGreen(image,ScaleLongToQuantum(*p),q); |
| 3155 | break; |
| 3156 | } |
| 3157 | case BlueQuantum: |
| 3158 | case YellowQuantum: |
| 3159 | { |
| 3160 | SetPixelBlue(image,ScaleLongToQuantum(*p),q); |
| 3161 | break; |
| 3162 | } |
| 3163 | case AlphaQuantum: |
| 3164 | { |
| 3165 | SetPixelAlpha(image,ScaleLongToQuantum(*p),q); |
| 3166 | break; |
| 3167 | } |
| 3168 | case OpacityQuantum: |
| 3169 | { |
| 3170 | SetPixelAlpha(image,ScaleLongToQuantum(*p),q); |
| 3171 | break; |
| 3172 | } |
| 3173 | case BlackQuantum: |
| 3174 | { |
| 3175 | SetPixelBlack(image,ScaleLongToQuantum(*p),q); |
| 3176 | break; |
| 3177 | } |
| 3178 | case IndexQuantum: |
| 3179 | { |
| 3180 | SetPixelRed(image,ScaleLongToQuantum(*p),q); |
| 3181 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 3182 | SetPixelBlue(image,GetPixelRed(image,q),q); |
| 3183 | break; |
| 3184 | } |
| 3185 | default: |
| 3186 | break; |
| 3187 | } |
| 3188 | p++; |
| 3189 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3190 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3191 | } |
| 3192 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3193 | break; |
| 3194 | } |
| 3195 | break; |
| 3196 | } |
| 3197 | case QuantumPixel: |
| 3198 | { |
| 3199 | register const Quantum |
| 3200 | *p; |
| 3201 | |
| 3202 | p=(const Quantum *) pixels; |
| 3203 | if (LocaleCompare(map,"BGR") == 0) |
| 3204 | { |
| 3205 | for (y=0; y < (ssize_t) rows; y++) |
| 3206 | { |
| 3207 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3208 | if (q == (Quantum *) NULL) |
| 3209 | break; |
| 3210 | for (x=0; x < (ssize_t) columns; x++) |
| 3211 | { |
| 3212 | SetPixelBlue(image,*p++,q); |
| 3213 | SetPixelGreen(image,*p++,q); |
| 3214 | SetPixelRed(image,*p++,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3215 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3216 | } |
| 3217 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3218 | break; |
| 3219 | } |
| 3220 | break; |
| 3221 | } |
| 3222 | if (LocaleCompare(map,"BGRA") == 0) |
| 3223 | { |
| 3224 | for (y=0; y < (ssize_t) rows; y++) |
| 3225 | { |
| 3226 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3227 | if (q == (Quantum *) NULL) |
| 3228 | break; |
| 3229 | for (x=0; x < (ssize_t) columns; x++) |
| 3230 | { |
| 3231 | SetPixelBlue(image,*p++,q); |
| 3232 | SetPixelGreen(image,*p++,q); |
| 3233 | SetPixelRed(image,*p++,q); |
| 3234 | SetPixelAlpha(image,*p++,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3235 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3236 | } |
| 3237 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3238 | break; |
| 3239 | } |
| 3240 | break; |
| 3241 | } |
| 3242 | if (LocaleCompare(map,"BGRP") == 0) |
| 3243 | { |
| 3244 | for (y=0; y < (ssize_t) rows; y++) |
| 3245 | { |
| 3246 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3247 | if (q == (Quantum *) NULL) |
| 3248 | break; |
| 3249 | for (x=0; x < (ssize_t) columns; x++) |
| 3250 | { |
| 3251 | SetPixelBlue(image,*p++,q); |
| 3252 | SetPixelGreen(image,*p++,q); |
| 3253 | SetPixelRed(image,*p++,q); |
| 3254 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3255 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3256 | } |
| 3257 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3258 | break; |
| 3259 | } |
| 3260 | break; |
| 3261 | } |
| 3262 | if (LocaleCompare(map,"I") == 0) |
| 3263 | { |
| 3264 | for (y=0; y < (ssize_t) rows; y++) |
| 3265 | { |
| 3266 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3267 | if (q == (Quantum *) NULL) |
| 3268 | break; |
| 3269 | for (x=0; x < (ssize_t) columns; x++) |
| 3270 | { |
| 3271 | SetPixelRed(image,*p++,q); |
| 3272 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 3273 | SetPixelBlue(image,GetPixelRed(image,q),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3274 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3275 | } |
| 3276 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3277 | break; |
| 3278 | } |
| 3279 | break; |
| 3280 | } |
| 3281 | if (LocaleCompare(map,"RGB") == 0) |
| 3282 | { |
| 3283 | for (y=0; y < (ssize_t) rows; y++) |
| 3284 | { |
| 3285 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3286 | if (q == (Quantum *) NULL) |
| 3287 | break; |
| 3288 | for (x=0; x < (ssize_t) columns; x++) |
| 3289 | { |
| 3290 | SetPixelRed(image,*p++,q); |
| 3291 | SetPixelGreen(image,*p++,q); |
| 3292 | SetPixelBlue(image,*p++,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3293 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3294 | } |
| 3295 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3296 | break; |
| 3297 | } |
| 3298 | break; |
| 3299 | } |
| 3300 | if (LocaleCompare(map,"RGBA") == 0) |
| 3301 | { |
| 3302 | for (y=0; y < (ssize_t) rows; y++) |
| 3303 | { |
| 3304 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3305 | if (q == (Quantum *) NULL) |
| 3306 | break; |
| 3307 | for (x=0; x < (ssize_t) columns; x++) |
| 3308 | { |
| 3309 | SetPixelRed(image,*p++,q); |
| 3310 | SetPixelGreen(image,*p++,q); |
| 3311 | SetPixelBlue(image,*p++,q); |
| 3312 | SetPixelAlpha(image,*p++,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3313 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3314 | } |
| 3315 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3316 | break; |
| 3317 | } |
| 3318 | break; |
| 3319 | } |
| 3320 | if (LocaleCompare(map,"RGBP") == 0) |
| 3321 | { |
| 3322 | for (y=0; y < (ssize_t) rows; y++) |
| 3323 | { |
| 3324 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3325 | if (q == (Quantum *) NULL) |
| 3326 | break; |
| 3327 | for (x=0; x < (ssize_t) columns; x++) |
| 3328 | { |
| 3329 | SetPixelRed(image,*p++,q); |
| 3330 | SetPixelGreen(image,*p++,q); |
| 3331 | SetPixelBlue(image,*p++,q); |
| 3332 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3333 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3334 | } |
| 3335 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3336 | break; |
| 3337 | } |
| 3338 | break; |
| 3339 | } |
| 3340 | for (y=0; y < (ssize_t) rows; y++) |
| 3341 | { |
| 3342 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3343 | if (q == (Quantum *) NULL) |
| 3344 | break; |
| 3345 | for (x=0; x < (ssize_t) columns; x++) |
| 3346 | { |
| 3347 | for (i=0; i < (ssize_t) length; i++) |
| 3348 | { |
| 3349 | switch (quantum_map[i]) |
| 3350 | { |
| 3351 | case RedQuantum: |
| 3352 | case CyanQuantum: |
| 3353 | { |
| 3354 | SetPixelRed(image,*p,q); |
| 3355 | break; |
| 3356 | } |
| 3357 | case GreenQuantum: |
| 3358 | case MagentaQuantum: |
| 3359 | { |
| 3360 | SetPixelGreen(image,*p,q); |
| 3361 | break; |
| 3362 | } |
| 3363 | case BlueQuantum: |
| 3364 | case YellowQuantum: |
| 3365 | { |
| 3366 | SetPixelBlue(image,*p,q); |
| 3367 | break; |
| 3368 | } |
| 3369 | case AlphaQuantum: |
| 3370 | { |
| 3371 | SetPixelAlpha(image,*p,q); |
| 3372 | break; |
| 3373 | } |
| 3374 | case OpacityQuantum: |
| 3375 | { |
| 3376 | SetPixelAlpha(image,*p,q); |
| 3377 | break; |
| 3378 | } |
| 3379 | case BlackQuantum: |
| 3380 | { |
| 3381 | SetPixelBlack(image,*p,q); |
| 3382 | break; |
| 3383 | } |
| 3384 | case IndexQuantum: |
| 3385 | { |
| 3386 | SetPixelRed(image,*p,q); |
| 3387 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 3388 | SetPixelBlue(image,GetPixelRed(image,q),q); |
| 3389 | break; |
| 3390 | } |
| 3391 | default: |
| 3392 | break; |
| 3393 | } |
| 3394 | p++; |
| 3395 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3396 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3397 | } |
| 3398 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3399 | break; |
| 3400 | } |
| 3401 | break; |
| 3402 | } |
| 3403 | case ShortPixel: |
| 3404 | { |
| 3405 | register const unsigned short |
| 3406 | *p; |
| 3407 | |
| 3408 | p=(const unsigned short *) pixels; |
| 3409 | if (LocaleCompare(map,"BGR") == 0) |
| 3410 | { |
| 3411 | for (y=0; y < (ssize_t) rows; y++) |
| 3412 | { |
| 3413 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3414 | if (q == (Quantum *) NULL) |
| 3415 | break; |
| 3416 | for (x=0; x < (ssize_t) columns; x++) |
| 3417 | { |
| 3418 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3419 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3420 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3421 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3422 | } |
| 3423 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3424 | break; |
| 3425 | } |
| 3426 | break; |
| 3427 | } |
| 3428 | if (LocaleCompare(map,"BGRA") == 0) |
| 3429 | { |
| 3430 | for (y=0; y < (ssize_t) rows; y++) |
| 3431 | { |
| 3432 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3433 | if (q == (Quantum *) NULL) |
| 3434 | break; |
| 3435 | for (x=0; x < (ssize_t) columns; x++) |
| 3436 | { |
| 3437 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3438 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3439 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3440 | SetPixelAlpha(image,ScaleShortToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3441 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3442 | } |
| 3443 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3444 | break; |
| 3445 | } |
| 3446 | break; |
| 3447 | } |
| 3448 | if (LocaleCompare(map,"BGRP") == 0) |
| 3449 | { |
| 3450 | for (y=0; y < (ssize_t) rows; y++) |
| 3451 | { |
| 3452 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3453 | if (q == (Quantum *) NULL) |
| 3454 | break; |
| 3455 | for (x=0; x < (ssize_t) columns; x++) |
| 3456 | { |
| 3457 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3458 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3459 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3460 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3461 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3462 | } |
| 3463 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3464 | break; |
| 3465 | } |
| 3466 | break; |
| 3467 | } |
| 3468 | if (LocaleCompare(map,"I") == 0) |
| 3469 | { |
| 3470 | for (y=0; y < (ssize_t) rows; y++) |
| 3471 | { |
| 3472 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3473 | if (q == (Quantum *) NULL) |
| 3474 | break; |
| 3475 | for (x=0; x < (ssize_t) columns; x++) |
| 3476 | { |
| 3477 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3478 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 3479 | SetPixelBlue(image,GetPixelRed(image,q),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3480 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3481 | } |
| 3482 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3483 | break; |
| 3484 | } |
| 3485 | break; |
| 3486 | } |
| 3487 | if (LocaleCompare(map,"RGB") == 0) |
| 3488 | { |
| 3489 | for (y=0; y < (ssize_t) rows; y++) |
| 3490 | { |
| 3491 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3492 | if (q == (Quantum *) NULL) |
| 3493 | break; |
| 3494 | for (x=0; x < (ssize_t) columns; x++) |
| 3495 | { |
| 3496 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3497 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3498 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3499 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3500 | } |
| 3501 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3502 | break; |
| 3503 | } |
| 3504 | break; |
| 3505 | } |
| 3506 | if (LocaleCompare(map,"RGBA") == 0) |
| 3507 | { |
| 3508 | for (y=0; y < (ssize_t) rows; y++) |
| 3509 | { |
| 3510 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3511 | if (q == (Quantum *) NULL) |
| 3512 | break; |
| 3513 | for (x=0; x < (ssize_t) columns; x++) |
| 3514 | { |
| 3515 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3516 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3517 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3518 | SetPixelAlpha(image,ScaleShortToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3519 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3520 | } |
| 3521 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3522 | break; |
| 3523 | } |
| 3524 | break; |
| 3525 | } |
| 3526 | if (LocaleCompare(map,"RGBP") == 0) |
| 3527 | { |
| 3528 | for (y=0; y < (ssize_t) rows; y++) |
| 3529 | { |
| 3530 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3531 | if (q == (Quantum *) NULL) |
| 3532 | break; |
| 3533 | for (x=0; x < (ssize_t) columns; x++) |
| 3534 | { |
| 3535 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3536 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3537 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3538 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3539 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3540 | } |
| 3541 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3542 | break; |
| 3543 | } |
| 3544 | break; |
| 3545 | } |
| 3546 | for (y=0; y < (ssize_t) rows; y++) |
| 3547 | { |
| 3548 | q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception); |
| 3549 | if (q == (Quantum *) NULL) |
| 3550 | break; |
| 3551 | for (x=0; x < (ssize_t) columns; x++) |
| 3552 | { |
| 3553 | for (i=0; i < (ssize_t) length; i++) |
| 3554 | { |
| 3555 | switch (quantum_map[i]) |
| 3556 | { |
| 3557 | case RedQuantum: |
| 3558 | case CyanQuantum: |
| 3559 | { |
| 3560 | SetPixelRed(image,ScaleShortToQuantum(*p),q); |
| 3561 | break; |
| 3562 | } |
| 3563 | case GreenQuantum: |
| 3564 | case MagentaQuantum: |
| 3565 | { |
| 3566 | SetPixelGreen(image,ScaleShortToQuantum(*p),q); |
| 3567 | break; |
| 3568 | } |
| 3569 | case BlueQuantum: |
| 3570 | case YellowQuantum: |
| 3571 | { |
| 3572 | SetPixelBlue(image,ScaleShortToQuantum(*p),q); |
| 3573 | break; |
| 3574 | } |
| 3575 | case AlphaQuantum: |
| 3576 | { |
| 3577 | SetPixelAlpha(image,ScaleShortToQuantum(*p),q); |
| 3578 | break; |
| 3579 | } |
| 3580 | case OpacityQuantum: |
| 3581 | { |
| 3582 | SetPixelAlpha(image,ScaleShortToQuantum(*p),q); |
| 3583 | break; |
| 3584 | } |
| 3585 | case BlackQuantum: |
| 3586 | { |
| 3587 | SetPixelBlack(image,ScaleShortToQuantum(*p),q); |
| 3588 | break; |
| 3589 | } |
| 3590 | case IndexQuantum: |
| 3591 | { |
| 3592 | SetPixelRed(image,ScaleShortToQuantum(*p),q); |
| 3593 | SetPixelGreen(image,GetPixelRed(image,q),q); |
| 3594 | SetPixelBlue(image,GetPixelRed(image,q),q); |
| 3595 | break; |
| 3596 | } |
| 3597 | default: |
| 3598 | break; |
| 3599 | } |
| 3600 | p++; |
| 3601 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3602 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3603 | } |
| 3604 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3605 | break; |
| 3606 | } |
| 3607 | break; |
| 3608 | } |
| 3609 | default: |
| 3610 | { |
| 3611 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 3612 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 3613 | "UnrecognizedPixelMap","`%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3614 | break; |
| 3615 | } |
| 3616 | } |
| 3617 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 3618 | return(MagickTrue); |
| 3619 | } |
| 3620 | |
| 3621 | /* |
| 3622 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3623 | % % |
| 3624 | % % |
| 3625 | % % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 3626 | + I n i t i a l i z e P i x e l C h a n n e l M a p % |
| 3627 | % % |
| 3628 | % % |
| 3629 | % % |
| 3630 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3631 | % |
| 3632 | % InitializePixelChannelMap() defines the standard pixel component map. |
| 3633 | % |
| 3634 | % The format of the InitializePixelChannelMap() method is: |
| 3635 | % |
| 3636 | % void InitializePixelChannelMap(Image *image) |
| 3637 | % |
| 3638 | % A description of each parameter follows: |
| 3639 | % |
| 3640 | % o image: the image. |
| 3641 | % |
| 3642 | */ |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3643 | |
| 3644 | MagickExport void PendInitializePixelChannelMap(Image *image) |
| 3645 | { |
| 3646 | register ssize_t |
| 3647 | i; |
| 3648 | |
| 3649 | size_t |
| 3650 | n; |
| 3651 | |
| 3652 | assert(image != (Image *) NULL); |
| 3653 | assert(image->signature == MagickSignature); |
| 3654 | for (i=0; i < (ssize_t) MaxPixelChannels; i++) |
| 3655 | { |
| 3656 | SetPixelChannelMapChannel(image,(PixelChannel) i,(PixelTrait) 0); |
| 3657 | SetPixelChannelMapTraits(image,(PixelChannel) i,UndefinedPixelTrait); |
| 3658 | } |
| 3659 | n=0; |
| 3660 | SetPixelChannelMapChannel(image,RedPixelChannel,(PixelTrait) n++); |
| 3661 | SetPixelChannelMapTraits(image,RedPixelChannel,(PixelTrait) |
| 3662 | (UpdatePixelTrait | BlendPixelTrait)); |
| 3663 | SetPixelChannelMapChannel(image,GreenPixelChannel,(PixelTrait) n++); |
| 3664 | SetPixelChannelMapTraits(image,GreenPixelChannel,(PixelTrait) |
| 3665 | (UpdatePixelTrait | BlendPixelTrait)); |
| 3666 | SetPixelChannelMapChannel(image,BluePixelChannel,(PixelTrait) n++); |
| 3667 | SetPixelChannelMapTraits(image,BluePixelChannel,(PixelTrait) |
| 3668 | (UpdatePixelTrait | BlendPixelTrait)); |
| 3669 | if (image->colorspace == GRAYColorspace) |
| 3670 | { |
| 3671 | n=0; |
| 3672 | SetPixelChannelMapChannel(image,RedPixelChannel,(PixelTrait) n); |
| 3673 | SetPixelChannelMapChannel(image,GreenPixelChannel,(PixelTrait) n); |
| 3674 | SetPixelChannelMapChannel(image,BluePixelChannel,(PixelTrait) n++); |
| 3675 | } |
| 3676 | if (image->colorspace == CMYKColorspace) |
| 3677 | { |
| 3678 | SetPixelChannelMapChannel(image,BlackPixelChannel,(PixelTrait) n++); |
| 3679 | SetPixelChannelMapTraits(image,BlackPixelChannel,(PixelTrait) |
| 3680 | (UpdatePixelTrait | BlendPixelTrait)); |
| 3681 | } |
| 3682 | if (image->storage_class == PseudoClass) |
| 3683 | { |
| 3684 | SetPixelChannelMapChannel(image,IndexPixelChannel,(PixelTrait) n++); |
| 3685 | SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait); |
| 3686 | } |
| 3687 | if (image->matte != MagickFalse) |
| 3688 | { |
| 3689 | SetPixelChannelMapChannel(image,AlphaPixelChannel,(PixelTrait) n++); |
| 3690 | SetPixelChannelMapTraits(image,AlphaPixelChannel,CopyPixelTrait); |
| 3691 | } |
| 3692 | n+=image->number_meta_channels; |
| 3693 | for ( ; i < (ssize_t) n; i++) |
| 3694 | SetPixelChannelMapTraits(image,(PixelChannel) i,CopyPixelTrait); |
| 3695 | image->number_channels=n; |
| 3696 | if (image->debug != MagickFalse) |
| 3697 | LogPixelChannels(image); |
| 3698 | (void) SetPixelChannelMask(image,image->channel_mask); |
| 3699 | } |
| 3700 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 3701 | MagickExport void InitializePixelChannelMap(Image *image) |
| 3702 | { |
| 3703 | PixelChannel |
| 3704 | alpha_channel; |
| 3705 | |
| 3706 | register ssize_t |
| 3707 | i; |
| 3708 | |
cristy | 6dcb9b8 | 2011-10-23 23:21:25 +0000 | [diff] [blame] | 3709 | assert(image != (Image *) NULL); |
| 3710 | assert(image->signature == MagickSignature); |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 3711 | for (i=0; i < (ssize_t) MaxPixelChannels; i++) |
| 3712 | { |
| 3713 | SetPixelChannelMapChannel(image,(PixelChannel) i,(PixelChannel) i); |
| 3714 | SetPixelChannelMapTraits(image,(PixelChannel) i,UndefinedPixelTrait); |
| 3715 | } |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 3716 | image->number_channels=4; |
| 3717 | if (0 && image->colorspace == GRAYColorspace) |
| 3718 | image->number_channels=2; |
| 3719 | if (image->colorspace == CMYKColorspace) |
| 3720 | image->number_channels++; |
| 3721 | if (image->storage_class == PseudoClass) |
| 3722 | image->number_channels++; |
| 3723 | for (i=0; i < (ssize_t) image->number_channels; i++) |
| 3724 | SetPixelChannelMapTraits(image,(PixelChannel) i,(PixelTrait) |
| 3725 | UpdatePixelTrait); |
| 3726 | alpha_channel=GetPixelChannelMapChannel(image,AlphaPixelChannel); |
cristy | 069450c | 2011-08-24 17:54:58 +0000 | [diff] [blame] | 3727 | if (image->matte == MagickFalse) |
| 3728 | SetPixelChannelMapTraits(image,AlphaPixelChannel,CopyPixelTrait); |
| 3729 | else |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 3730 | for (i=0; i < (ssize_t) image->number_channels; i++) |
| 3731 | if ((PixelChannel) i != alpha_channel) |
| 3732 | SetPixelChannelMapTraits(image,(PixelChannel) i,(PixelTrait) |
| 3733 | (UpdatePixelTrait | BlendPixelTrait)); |
| 3734 | if (0 && image->colorspace == GRAYColorspace) |
| 3735 | { |
| 3736 | image->number_channels=2; |
| 3737 | SetPixelChannelMapChannel(image,GreenPixelChannel,RedPixelChannel); |
| 3738 | SetPixelChannelMapChannel(image,BluePixelChannel,RedPixelChannel); |
| 3739 | } |
| 3740 | if (image->storage_class == PseudoClass) |
| 3741 | { |
| 3742 | SetPixelChannelMapChannel(image,IndexPixelChannel,IndexPixelChannel); |
| 3743 | SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait); |
| 3744 | } |
| 3745 | image->number_channels+=image->number_meta_channels; |
| 3746 | for ( ; i < (ssize_t) image->number_channels; i++) |
| 3747 | SetPixelChannelMapTraits(image,(PixelChannel) i,CopyPixelTrait); |
cristy | 6dcb9b8 | 2011-10-23 23:21:25 +0000 | [diff] [blame] | 3748 | if (image->debug != MagickFalse) |
| 3749 | LogPixelChannels(image); |
cristy | 480f49f | 2011-08-26 13:29:49 +0000 | [diff] [blame] | 3750 | (void) SetPixelChannelMask(image,image->channel_mask); |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 3751 | } |
| 3752 | |
| 3753 | /* |
| 3754 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3755 | % % |
| 3756 | % % |
| 3757 | % % |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3758 | % I n t e r p o l a t e P i x e l C h a n n e l % |
| 3759 | % % |
| 3760 | % % |
| 3761 | % % |
| 3762 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3763 | % |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3764 | % InterpolatePixelChannel() applies a pixel interpolation method between a |
| 3765 | % floating point coordinate and the pixels surrounding that coordinate. No |
| 3766 | % pixel area resampling, or scaling of the result is performed. |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3767 | % |
| 3768 | % The format of the InterpolatePixelChannel method is: |
| 3769 | % |
| 3770 | % MagickBooleanType InterpolatePixelChannel(const Image *image, |
cristy | 444eda6 | 2011-08-10 02:07:46 +0000 | [diff] [blame] | 3771 | % const CacheView *image_view,const PixelChannel channel, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 3772 | % const PixelInterpolateMethod method,const double x,const double y, |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3773 | % double *pixel,ExceptionInfo *exception) |
| 3774 | % |
| 3775 | % A description of each parameter follows: |
| 3776 | % |
| 3777 | % o image: the image. |
| 3778 | % |
| 3779 | % o image_view: the image view. |
| 3780 | % |
| 3781 | % o channel: the pixel channel to interpolate. |
| 3782 | % |
| 3783 | % o method: the pixel color interpolation method. |
| 3784 | % |
| 3785 | % o x,y: A double representing the current (x,y) position of the pixel. |
| 3786 | % |
| 3787 | % o pixel: return the interpolated pixel here. |
| 3788 | % |
| 3789 | % o exception: return any errors or warnings in this structure. |
| 3790 | % |
| 3791 | */ |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 3792 | |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3793 | static inline double MagickMax(const MagickRealType x,const MagickRealType y) |
| 3794 | { |
| 3795 | if (x > y) |
| 3796 | return(x); |
| 3797 | return(y); |
| 3798 | } |
| 3799 | |
| 3800 | static inline MagickRealType CubicWeightingFunction(const MagickRealType x) |
| 3801 | { |
| 3802 | MagickRealType |
| 3803 | alpha, |
| 3804 | gamma; |
| 3805 | |
| 3806 | alpha=MagickMax(x+2.0,0.0); |
| 3807 | gamma=1.0*alpha*alpha*alpha; |
| 3808 | alpha=MagickMax(x+1.0,0.0); |
| 3809 | gamma-=4.0*alpha*alpha*alpha; |
| 3810 | alpha=MagickMax(x+0.0,0.0); |
| 3811 | gamma+=6.0*alpha*alpha*alpha; |
| 3812 | alpha=MagickMax(x-1.0,0.0); |
| 3813 | gamma-=4.0*alpha*alpha*alpha; |
| 3814 | return(gamma/6.0); |
| 3815 | } |
| 3816 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 3817 | static inline double MeshInterpolate(const PointInfo *delta,const double p, |
| 3818 | const double x,const double y) |
| 3819 | { |
| 3820 | return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p); |
| 3821 | } |
| 3822 | |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3823 | static inline ssize_t NearestNeighbor(const MagickRealType x) |
| 3824 | { |
| 3825 | if (x >= 0.0) |
| 3826 | return((ssize_t) (x+0.5)); |
| 3827 | return((ssize_t) (x-0.5)); |
| 3828 | } |
| 3829 | |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3830 | MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image, |
| 3831 | const CacheView *image_view,const PixelChannel channel, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 3832 | const PixelInterpolateMethod method,const double x,const double y, |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3833 | double *pixel,ExceptionInfo *exception) |
| 3834 | { |
| 3835 | MagickBooleanType |
| 3836 | status; |
| 3837 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 3838 | MagickRealType |
| 3839 | alpha[16], |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3840 | gamma, |
| 3841 | pixels[16]; |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 3842 | |
| 3843 | PixelTrait |
| 3844 | traits; |
| 3845 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 3846 | register const Quantum |
| 3847 | *p; |
| 3848 | |
| 3849 | register ssize_t |
| 3850 | i; |
| 3851 | |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3852 | ssize_t |
| 3853 | x_offset, |
| 3854 | y_offset; |
| 3855 | |
| 3856 | assert(image != (Image *) NULL); |
| 3857 | assert(image != (Image *) NULL); |
| 3858 | assert(image->signature == MagickSignature); |
| 3859 | assert(image_view != (CacheView *) NULL); |
| 3860 | status=MagickTrue; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3861 | *pixel=0.0; |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 3862 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3863 | x_offset=(ssize_t) floor(x); |
| 3864 | y_offset=(ssize_t) floor(y); |
| 3865 | switch (method == UndefinedInterpolatePixel ? image->interpolate : method) |
| 3866 | { |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3867 | case AverageInterpolatePixel: |
| 3868 | { |
| 3869 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 3870 | exception); |
| 3871 | if (p == (const Quantum *) NULL) |
| 3872 | { |
| 3873 | status=MagickFalse; |
| 3874 | break; |
| 3875 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 3876 | if ((traits & BlendPixelTrait) == 0) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3877 | for (i=0; i < 16; i++) |
| 3878 | { |
| 3879 | alpha[i]=1.0; |
| 3880 | pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel]; |
| 3881 | } |
| 3882 | else |
| 3883 | for (i=0; i < 16; i++) |
| 3884 | { |
| 3885 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 3886 | GetPixelChannels(image)); |
| 3887 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 3888 | } |
| 3889 | for (i=0; i < 16; i++) |
| 3890 | { |
| 3891 | gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]); |
| 3892 | *pixel+=gamma*0.0625*pixels[i]; |
| 3893 | } |
| 3894 | break; |
| 3895 | } |
| 3896 | case BicubicInterpolatePixel: |
| 3897 | { |
| 3898 | MagickRealType |
| 3899 | u[4], |
| 3900 | v[4]; |
| 3901 | |
| 3902 | PointInfo |
| 3903 | delta; |
| 3904 | |
| 3905 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 3906 | exception); |
| 3907 | if (p == (const Quantum *) NULL) |
| 3908 | { |
| 3909 | status=MagickFalse; |
| 3910 | break; |
| 3911 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 3912 | if ((traits & BlendPixelTrait) == 0) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3913 | for (i=0; i < 16; i++) |
| 3914 | { |
| 3915 | alpha[i]=1.0; |
| 3916 | pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel]; |
| 3917 | } |
| 3918 | else |
| 3919 | for (i=0; i < 16; i++) |
| 3920 | { |
| 3921 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 3922 | GetPixelChannels(image)); |
| 3923 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 3924 | } |
| 3925 | delta.x=x-x_offset; |
| 3926 | delta.y=y-y_offset; |
| 3927 | for (i=0; i < 4; i++) |
| 3928 | { |
| 3929 | u[0]=(pixels[4*i+3]-pixels[4*i+2])-(pixels[4*i+0]-pixels[4*i+1]); |
| 3930 | u[1]=(pixels[4*i+0]-pixels[4*i+1])-u[0]; |
| 3931 | u[2]=pixels[4*i+2]-pixels[4*i+0]; |
| 3932 | u[3]=pixels[4*i+1]; |
| 3933 | v[i]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x* |
| 3934 | u[2])+u[3]; |
| 3935 | } |
| 3936 | u[0]=(v[3]-v[2])-(v[0]-v[1]); |
| 3937 | u[1]=(v[0]-v[1])-u[0]; |
| 3938 | u[2]=v[2]-v[0]; |
| 3939 | u[3]=v[1]; |
| 3940 | *pixel=(delta.y*delta.y*delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y* |
| 3941 | u[2])+u[3]; |
| 3942 | break; |
| 3943 | } |
| 3944 | case BilinearInterpolatePixel: |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 3945 | default: |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3946 | { |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 3947 | PointInfo |
| 3948 | delta, |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3949 | epsilon; |
| 3950 | |
| 3951 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 3952 | if (p == (const Quantum *) NULL) |
| 3953 | { |
| 3954 | status=MagickFalse; |
| 3955 | break; |
| 3956 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 3957 | if ((traits & BlendPixelTrait) == 0) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3958 | for (i=0; i < 4; i++) |
| 3959 | { |
| 3960 | alpha[i]=1.0; |
| 3961 | pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel]; |
| 3962 | } |
| 3963 | else |
| 3964 | for (i=0; i < 4; i++) |
| 3965 | { |
| 3966 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 3967 | GetPixelChannels(image)); |
| 3968 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 3969 | } |
| 3970 | delta.x=x-x_offset; |
| 3971 | delta.y=y-y_offset; |
| 3972 | epsilon.x=1.0-delta.x; |
| 3973 | epsilon.y=1.0-delta.y; |
| 3974 | gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* |
| 3975 | (epsilon.x*alpha[2]+delta.x*alpha[3]))); |
| 3976 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 3977 | *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y* |
| 3978 | (epsilon.x*pixels[2]+delta.x*pixels[3])); |
| 3979 | break; |
| 3980 | } |
| 3981 | case FilterInterpolatePixel: |
| 3982 | { |
| 3983 | CacheView |
| 3984 | *filter_view; |
| 3985 | |
| 3986 | Image |
| 3987 | *excerpt_image, |
| 3988 | *filter_image; |
| 3989 | |
| 3990 | RectangleInfo |
| 3991 | geometry; |
| 3992 | |
| 3993 | geometry.width=4L; |
| 3994 | geometry.height=4L; |
| 3995 | geometry.x=x_offset-1; |
| 3996 | geometry.y=y_offset-1; |
| 3997 | excerpt_image=ExcerptImage(image,&geometry,exception); |
| 3998 | if (excerpt_image == (Image *) NULL) |
| 3999 | { |
| 4000 | status=MagickFalse; |
| 4001 | break; |
| 4002 | } |
| 4003 | filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur, |
| 4004 | exception); |
| 4005 | excerpt_image=DestroyImage(excerpt_image); |
| 4006 | if (filter_image == (Image *) NULL) |
| 4007 | break; |
| 4008 | filter_view=AcquireCacheView(filter_image); |
| 4009 | p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception); |
| 4010 | if (p == (const Quantum *) NULL) |
| 4011 | status=MagickFalse; |
| 4012 | else |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 4013 | *pixel=(double) GetPixelChannel(image,channel,p); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4014 | filter_view=DestroyCacheView(filter_view); |
| 4015 | filter_image=DestroyImage(filter_image); |
| 4016 | break; |
| 4017 | } |
| 4018 | case IntegerInterpolatePixel: |
| 4019 | { |
| 4020 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception); |
| 4021 | if (p == (const Quantum *) NULL) |
| 4022 | { |
| 4023 | status=MagickFalse; |
| 4024 | break; |
| 4025 | } |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 4026 | *pixel=(double) GetPixelChannel(image,channel,p); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4027 | break; |
| 4028 | } |
| 4029 | case NearestNeighborInterpolatePixel: |
| 4030 | { |
| 4031 | p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x), |
| 4032 | NearestNeighbor(y),1,1,exception); |
| 4033 | if (p == (const Quantum *) NULL) |
| 4034 | { |
| 4035 | status=MagickFalse; |
| 4036 | break; |
| 4037 | } |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 4038 | *pixel=(double) GetPixelChannel(image,channel,p); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4039 | break; |
| 4040 | } |
| 4041 | case MeshInterpolatePixel: |
| 4042 | { |
| 4043 | PointInfo |
| 4044 | delta, |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4045 | luminance; |
| 4046 | |
| 4047 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 4048 | if (p == (const Quantum *) NULL) |
| 4049 | { |
| 4050 | status=MagickFalse; |
| 4051 | break; |
| 4052 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4053 | if ((traits & BlendPixelTrait) == 0) |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4054 | for (i=0; i < 4; i++) |
| 4055 | { |
| 4056 | alpha[i]=1.0; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4057 | pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel]; |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4058 | } |
| 4059 | else |
| 4060 | for (i=0; i < 4; i++) |
| 4061 | { |
| 4062 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4063 | GetPixelChannels(image)); |
| 4064 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4065 | } |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4066 | delta.x=x-x_offset; |
| 4067 | delta.y=y-y_offset; |
| 4068 | luminance.x=GetPixelLuminance(image,p)-(double) |
| 4069 | GetPixelLuminance(image,p+3*GetPixelChannels(image)); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4070 | luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4071 | GetPixelLuminance(image,p+2*GetPixelChannels(image)); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4072 | if (fabs(luminance.x) < fabs(luminance.y)) |
| 4073 | { |
| 4074 | /* |
| 4075 | Diagonal 0-3 NW-SE. |
| 4076 | */ |
| 4077 | if (delta.x <= delta.y) |
| 4078 | { |
| 4079 | /* |
| 4080 | Bottom-left triangle (pixel: 2, diagonal: 0-3). |
| 4081 | */ |
| 4082 | delta.y=1.0-delta.y; |
| 4083 | gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); |
| 4084 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4085 | *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3], |
| 4086 | pixels[0]); |
| 4087 | } |
| 4088 | else |
| 4089 | { |
| 4090 | /* |
| 4091 | Top-right triangle (pixel: 1, diagonal: 0-3). |
| 4092 | */ |
| 4093 | delta.x=1.0-delta.x; |
| 4094 | gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); |
| 4095 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4096 | *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0], |
| 4097 | pixels[3]); |
| 4098 | } |
| 4099 | } |
| 4100 | else |
| 4101 | { |
| 4102 | /* |
| 4103 | Diagonal 1-2 NE-SW. |
| 4104 | */ |
| 4105 | if (delta.x <= (1.0-delta.y)) |
| 4106 | { |
| 4107 | /* |
| 4108 | Top-left triangle (pixel: 0, diagonal: 1-2). |
| 4109 | */ |
| 4110 | gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); |
| 4111 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4112 | *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1], |
| 4113 | pixels[2]); |
| 4114 | } |
| 4115 | else |
| 4116 | { |
| 4117 | /* |
| 4118 | Bottom-right triangle (pixel: 3, diagonal: 1-2). |
| 4119 | */ |
| 4120 | delta.x=1.0-delta.x; |
| 4121 | delta.y=1.0-delta.y; |
| 4122 | gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); |
| 4123 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4124 | *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2], |
| 4125 | pixels[1]); |
| 4126 | } |
| 4127 | } |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4128 | break; |
| 4129 | } |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4130 | case SplineInterpolatePixel: |
| 4131 | { |
| 4132 | MagickRealType |
| 4133 | dx, |
| 4134 | dy; |
| 4135 | |
| 4136 | PointInfo |
| 4137 | delta; |
| 4138 | |
| 4139 | ssize_t |
| 4140 | j, |
| 4141 | n; |
| 4142 | |
| 4143 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 4144 | exception); |
| 4145 | if (p == (const Quantum *) NULL) |
| 4146 | { |
| 4147 | status=MagickFalse; |
| 4148 | break; |
| 4149 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4150 | if ((traits & BlendPixelTrait) == 0) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4151 | for (i=0; i < 16; i++) |
| 4152 | { |
| 4153 | alpha[i]=1.0; |
| 4154 | pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel]; |
| 4155 | } |
| 4156 | else |
| 4157 | for (i=0; i < 16; i++) |
| 4158 | { |
| 4159 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4160 | GetPixelChannels(image)); |
| 4161 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4162 | } |
| 4163 | delta.x=x-x_offset; |
| 4164 | delta.y=y-y_offset; |
| 4165 | n=0; |
| 4166 | for (i=(-1); i < 3L; i++) |
| 4167 | { |
| 4168 | dy=CubicWeightingFunction((MagickRealType) i-delta.y); |
| 4169 | for (j=(-1); j < 3L; j++) |
| 4170 | { |
| 4171 | dx=CubicWeightingFunction(delta.x-(MagickRealType) j); |
| 4172 | gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]); |
| 4173 | *pixel+=gamma*dx*dy*pixels[n]; |
| 4174 | n++; |
| 4175 | } |
| 4176 | } |
| 4177 | break; |
| 4178 | } |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4179 | } |
| 4180 | return(status); |
| 4181 | } |
| 4182 | |
| 4183 | /* |
| 4184 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4185 | % % |
| 4186 | % % |
| 4187 | % % |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4188 | % I n t e r p o l a t e P i x e l C h a n n e l s % |
| 4189 | % % |
| 4190 | % % |
| 4191 | % % |
| 4192 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4193 | % |
| 4194 | % InterpolatePixelChannels() applies a pixel interpolation method between a |
| 4195 | % floating point coordinate and the pixels surrounding that coordinate. No |
| 4196 | % pixel area resampling, or scaling of the result is performed. |
| 4197 | % |
| 4198 | % The format of the InterpolatePixelChannels method is: |
| 4199 | % |
| 4200 | % MagickBooleanType InterpolatePixelChannels(const Image *source, |
| 4201 | % const CacheView *source_view,const Image *destination, |
| 4202 | % const PixelInterpolateMethod method,const double x,const double y, |
| 4203 | % Quantum *pixel,ExceptionInfo *exception) |
| 4204 | % |
| 4205 | % A description of each parameter follows: |
| 4206 | % |
| 4207 | % o source: the source. |
| 4208 | % |
| 4209 | % o source_view: the source view. |
| 4210 | % |
| 4211 | % o destination: the destination image. |
| 4212 | % |
| 4213 | % o method: the pixel color interpolation method. |
| 4214 | % |
| 4215 | % o x,y: A double representing the current (x,y) position of the pixel. |
| 4216 | % |
| 4217 | % o pixel: return the interpolated pixel here. |
| 4218 | % |
| 4219 | % o exception: return any errors or warnings in this structure. |
| 4220 | % |
| 4221 | */ |
| 4222 | MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source, |
| 4223 | const CacheView *source_view,const Image *destination, |
| 4224 | const PixelInterpolateMethod method,const double x,const double y, |
| 4225 | Quantum *pixel,ExceptionInfo *exception) |
| 4226 | { |
| 4227 | MagickBooleanType |
| 4228 | status; |
| 4229 | |
| 4230 | MagickRealType |
| 4231 | alpha[16], |
| 4232 | gamma, |
| 4233 | pixels[16]; |
| 4234 | |
| 4235 | PixelChannel |
| 4236 | channel; |
| 4237 | |
| 4238 | PixelTrait |
| 4239 | destination_traits, |
| 4240 | traits; |
| 4241 | |
| 4242 | register const Quantum |
| 4243 | *p; |
| 4244 | |
| 4245 | register ssize_t |
| 4246 | i; |
| 4247 | |
| 4248 | ssize_t |
| 4249 | x_offset, |
| 4250 | y_offset; |
| 4251 | |
| 4252 | assert(source != (Image *) NULL); |
| 4253 | assert(source != (Image *) NULL); |
| 4254 | assert(source->signature == MagickSignature); |
| 4255 | assert(source_view != (CacheView *) NULL); |
| 4256 | status=MagickTrue; |
| 4257 | x_offset=(ssize_t) floor(x); |
| 4258 | y_offset=(ssize_t) floor(y); |
| 4259 | switch (method == UndefinedInterpolatePixel ? source->interpolate : method) |
| 4260 | { |
| 4261 | case AverageInterpolatePixel: |
| 4262 | { |
| 4263 | p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4, |
| 4264 | exception); |
| 4265 | if (p == (const Quantum *) NULL) |
| 4266 | { |
| 4267 | status=MagickFalse; |
| 4268 | break; |
| 4269 | } |
| 4270 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4271 | { |
| 4272 | double |
| 4273 | sum; |
| 4274 | |
| 4275 | register ssize_t |
| 4276 | j; |
| 4277 | |
| 4278 | traits=GetPixelChannelMapTraits(source,(PixelChannel) i); |
| 4279 | channel=GetPixelChannelMapChannel(source,(PixelChannel) i); |
| 4280 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4281 | if ((traits == UndefinedPixelTrait) || |
| 4282 | (destination_traits == UndefinedPixelTrait)) |
| 4283 | continue; |
| 4284 | for (j=0; j < 16; j++) |
| 4285 | pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i]; |
| 4286 | if ((traits & BlendPixelTrait) == 0) |
| 4287 | { |
| 4288 | for (j=0; j < 16; j++) |
| 4289 | pixel[channel]+=0.0625*pixels[j]; |
| 4290 | continue; |
| 4291 | } |
| 4292 | sum=0.0; |
| 4293 | for (j=0; j < 16; j++) |
| 4294 | { |
| 4295 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 4296 | GetPixelChannels(source)); |
| 4297 | pixels[j]*=alpha[j]; |
| 4298 | gamma=1.0/(fabs((double) alpha[j]) <= MagickEpsilon ? 1.0 : alpha[j]); |
| 4299 | sum+=gamma*0.0625*pixels[j]; |
| 4300 | } |
| 4301 | pixel[channel]=ClampToQuantum(sum); |
| 4302 | } |
| 4303 | break; |
| 4304 | } |
| 4305 | case BicubicInterpolatePixel: |
| 4306 | { |
| 4307 | MagickRealType |
| 4308 | u[4], |
| 4309 | v[4]; |
| 4310 | |
| 4311 | PointInfo |
| 4312 | delta; |
| 4313 | |
| 4314 | p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4, |
| 4315 | exception); |
| 4316 | if (p == (const Quantum *) NULL) |
| 4317 | { |
| 4318 | status=MagickFalse; |
| 4319 | break; |
| 4320 | } |
| 4321 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4322 | { |
| 4323 | register ssize_t |
| 4324 | j; |
| 4325 | |
| 4326 | traits=GetPixelChannelMapTraits(source,(PixelChannel) i); |
| 4327 | channel=GetPixelChannelMapChannel(source,(PixelChannel) i); |
| 4328 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4329 | if ((traits == UndefinedPixelTrait) || |
| 4330 | (destination_traits == UndefinedPixelTrait)) |
| 4331 | continue; |
| 4332 | if ((traits & BlendPixelTrait) == 0) |
| 4333 | for (j=0; j < 16; j++) |
| 4334 | { |
| 4335 | alpha[j]=1.0; |
| 4336 | pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i]; |
| 4337 | } |
| 4338 | else |
| 4339 | for (j=0; j < 16; j++) |
| 4340 | { |
| 4341 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 4342 | GetPixelChannels(source)); |
| 4343 | pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i]; |
| 4344 | } |
| 4345 | delta.x=x-x_offset; |
| 4346 | delta.y=y-y_offset; |
| 4347 | for (j=0; j < 4; j++) |
| 4348 | { |
| 4349 | u[0]=(pixels[4*j+3]-pixels[4*j+2])-(pixels[4*j+0]-pixels[4*j+1]); |
| 4350 | u[1]=(pixels[4*j+0]-pixels[4*j+1])-u[0]; |
| 4351 | u[2]=pixels[4*j+2]-pixels[4*j+0]; |
| 4352 | u[3]=pixels[4*j+1]; |
| 4353 | v[j]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x* |
| 4354 | u[2])+u[3]; |
| 4355 | } |
| 4356 | u[0]=(v[3]-v[2])-(v[0]-v[1]); |
| 4357 | u[1]=(v[0]-v[1])-u[0]; |
| 4358 | u[2]=v[2]-v[0]; |
| 4359 | u[3]=v[1]; |
| 4360 | pixel[channel]=ClampToQuantum((delta.y*delta.y*delta.y*u[0])+(delta.y* |
| 4361 | delta.y*u[1])+(delta.y*u[2])+u[3]); |
| 4362 | } |
| 4363 | break; |
| 4364 | } |
| 4365 | case BilinearInterpolatePixel: |
| 4366 | default: |
| 4367 | { |
| 4368 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception); |
| 4369 | if (p == (const Quantum *) NULL) |
| 4370 | { |
| 4371 | status=MagickFalse; |
| 4372 | break; |
| 4373 | } |
| 4374 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4375 | { |
| 4376 | PointInfo |
| 4377 | delta, |
| 4378 | epsilon; |
| 4379 | |
| 4380 | traits=GetPixelChannelMapTraits(source,(PixelChannel) i); |
| 4381 | channel=GetPixelChannelMapChannel(source,(PixelChannel) i); |
| 4382 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4383 | if ((traits == UndefinedPixelTrait) || |
| 4384 | (destination_traits == UndefinedPixelTrait)) |
| 4385 | continue; |
| 4386 | delta.x=x-x_offset; |
| 4387 | delta.y=y-y_offset; |
| 4388 | epsilon.x=1.0-delta.x; |
| 4389 | epsilon.y=1.0-delta.y; |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4390 | pixels[0]=(MagickRealType) p[i]; |
| 4391 | pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i]; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4392 | pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i]; |
| 4393 | pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i]; |
| 4394 | if ((traits & BlendPixelTrait) == 0) |
| 4395 | { |
| 4396 | gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x))); |
| 4397 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4398 | pixel[channel]=ClampToQuantum(gamma*(epsilon.y*(epsilon.x*pixels[0]+ |
| 4399 | delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+delta.x* |
| 4400 | pixels[3]))); |
| 4401 | continue; |
| 4402 | } |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4403 | alpha[0]=QuantumScale*GetPixelAlpha(source,p); |
| 4404 | alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source)); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4405 | alpha[2]=QuantumScale*GetPixelAlpha(source,p+2* |
| 4406 | GetPixelChannels(source)); |
| 4407 | alpha[3]=QuantumScale*GetPixelAlpha(source,p+3* |
| 4408 | GetPixelChannels(source)); |
| 4409 | pixels[0]*=alpha[0]; |
| 4410 | pixels[1]*=alpha[1]; |
| 4411 | pixels[2]*=alpha[2]; |
| 4412 | pixels[3]*=alpha[3]; |
| 4413 | gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* |
| 4414 | (epsilon.x*alpha[2]+delta.x*alpha[3]))); |
| 4415 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4416 | pixel[channel]=ClampToQuantum(gamma*(epsilon.y*(epsilon.x*pixels[0]+ |
| 4417 | delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+delta.x*pixels[3]))); |
| 4418 | } |
| 4419 | break; |
| 4420 | } |
| 4421 | case FilterInterpolatePixel: |
| 4422 | { |
| 4423 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4424 | { |
| 4425 | CacheView |
| 4426 | *filter_view; |
| 4427 | |
| 4428 | Image |
| 4429 | *excerpt_source, |
| 4430 | *filter_source; |
| 4431 | |
| 4432 | RectangleInfo |
| 4433 | geometry; |
| 4434 | |
| 4435 | traits=GetPixelChannelMapTraits(source,(PixelChannel) i); |
| 4436 | channel=GetPixelChannelMapChannel(source,(PixelChannel) i); |
| 4437 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4438 | if ((traits == UndefinedPixelTrait) || |
| 4439 | (destination_traits == UndefinedPixelTrait)) |
| 4440 | continue; |
| 4441 | geometry.width=4L; |
| 4442 | geometry.height=4L; |
| 4443 | geometry.x=x_offset-1; |
| 4444 | geometry.y=y_offset-1; |
| 4445 | excerpt_source=ExcerptImage(source,&geometry,exception); |
| 4446 | if (excerpt_source == (Image *) NULL) |
| 4447 | { |
| 4448 | status=MagickFalse; |
| 4449 | continue; |
| 4450 | } |
| 4451 | filter_source=ResizeImage(excerpt_source,1,1,source->filter, |
| 4452 | source->blur,exception); |
| 4453 | excerpt_source=DestroyImage(excerpt_source); |
| 4454 | if (filter_source == (Image *) NULL) |
| 4455 | continue; |
| 4456 | filter_view=AcquireCacheView(filter_source); |
| 4457 | p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception); |
| 4458 | if (p == (const Quantum *) NULL) |
| 4459 | status=MagickFalse; |
| 4460 | else |
| 4461 | pixel[channel]=p[i]; |
| 4462 | filter_view=DestroyCacheView(filter_view); |
| 4463 | filter_source=DestroyImage(filter_source); |
| 4464 | } |
| 4465 | break; |
| 4466 | } |
| 4467 | case IntegerInterpolatePixel: |
| 4468 | { |
| 4469 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception); |
| 4470 | if (p == (const Quantum *) NULL) |
| 4471 | { |
| 4472 | status=MagickFalse; |
| 4473 | break; |
| 4474 | } |
| 4475 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4476 | { |
| 4477 | traits=GetPixelChannelMapTraits(source,(PixelChannel) i); |
| 4478 | channel=GetPixelChannelMapChannel(source,(PixelChannel) i); |
| 4479 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4480 | if ((traits == UndefinedPixelTrait) || |
| 4481 | (destination_traits == UndefinedPixelTrait)) |
| 4482 | continue; |
| 4483 | pixel[channel]=p[i]; |
| 4484 | } |
| 4485 | break; |
| 4486 | } |
| 4487 | case NearestNeighborInterpolatePixel: |
| 4488 | { |
| 4489 | p=GetCacheViewVirtualPixels(source_view,NearestNeighbor(x), |
| 4490 | NearestNeighbor(y),1,1,exception); |
| 4491 | if (p == (const Quantum *) NULL) |
| 4492 | { |
| 4493 | status=MagickFalse; |
| 4494 | break; |
| 4495 | } |
| 4496 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4497 | { |
| 4498 | traits=GetPixelChannelMapTraits(source,(PixelChannel) i); |
| 4499 | channel=GetPixelChannelMapChannel(source,(PixelChannel) i); |
| 4500 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4501 | if ((traits == UndefinedPixelTrait) || |
| 4502 | (destination_traits == UndefinedPixelTrait)) |
| 4503 | continue; |
| 4504 | pixel[channel]=p[i]; |
| 4505 | } |
| 4506 | break; |
| 4507 | } |
| 4508 | case MeshInterpolatePixel: |
| 4509 | { |
| 4510 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception); |
| 4511 | if (p == (const Quantum *) NULL) |
| 4512 | { |
| 4513 | status=MagickFalse; |
| 4514 | break; |
| 4515 | } |
| 4516 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4517 | { |
| 4518 | PointInfo |
| 4519 | delta, |
| 4520 | luminance; |
| 4521 | |
| 4522 | traits=GetPixelChannelMapTraits(source,(PixelChannel) i); |
| 4523 | channel=GetPixelChannelMapChannel(source,(PixelChannel) i); |
| 4524 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4525 | if ((traits == UndefinedPixelTrait) || |
| 4526 | (destination_traits == UndefinedPixelTrait)) |
| 4527 | continue; |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4528 | pixels[0]=(MagickRealType) p[i]; |
| 4529 | pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i]; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4530 | pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i]; |
| 4531 | pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i]; |
| 4532 | if ((traits & BlendPixelTrait) == 0) |
| 4533 | { |
| 4534 | alpha[0]=1.0; |
| 4535 | alpha[1]=1.0; |
| 4536 | alpha[2]=1.0; |
| 4537 | alpha[3]=1.0; |
| 4538 | } |
| 4539 | else |
| 4540 | { |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4541 | alpha[0]=QuantumScale*GetPixelAlpha(source,p); |
| 4542 | alpha[1]=QuantumScale*GetPixelAlpha(source,p+ |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4543 | GetPixelChannels(source)); |
| 4544 | alpha[2]=QuantumScale*GetPixelAlpha(source,p+2* |
| 4545 | GetPixelChannels(source)); |
| 4546 | alpha[3]=QuantumScale*GetPixelAlpha(source,p+3* |
| 4547 | GetPixelChannels(source)); |
| 4548 | } |
| 4549 | delta.x=x-x_offset; |
| 4550 | delta.y=y-y_offset; |
| 4551 | luminance.x=GetPixelLuminance(source,p)-(double) |
| 4552 | GetPixelLuminance(source,p+3*GetPixelChannels(source)); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4553 | luminance.y=GetPixelLuminance(source,p+GetPixelChannels(source))- |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4554 | (double) GetPixelLuminance(source,p+2*GetPixelChannels(source)); |
| 4555 | if (fabs(luminance.x) < fabs(luminance.y)) |
| 4556 | { |
| 4557 | /* |
| 4558 | Diagonal 0-3 NW-SE. |
| 4559 | */ |
| 4560 | if (delta.x <= delta.y) |
| 4561 | { |
| 4562 | /* |
| 4563 | Bottom-left triangle (pixel: 2, diagonal: 0-3). |
| 4564 | */ |
| 4565 | delta.y=1.0-delta.y; |
| 4566 | gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); |
| 4567 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4568 | pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta, |
| 4569 | pixels[2],pixels[3],pixels[0])); |
| 4570 | } |
| 4571 | else |
| 4572 | { |
| 4573 | /* |
| 4574 | Top-right triangle (pixel: 1, diagonal: 0-3). |
| 4575 | */ |
| 4576 | delta.x=1.0-delta.x; |
| 4577 | gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); |
| 4578 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4579 | pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta, |
| 4580 | pixels[1],pixels[0],pixels[3])); |
| 4581 | } |
| 4582 | } |
| 4583 | else |
| 4584 | { |
| 4585 | /* |
| 4586 | Diagonal 1-2 NE-SW. |
| 4587 | */ |
| 4588 | if (delta.x <= (1.0-delta.y)) |
| 4589 | { |
| 4590 | /* |
| 4591 | Top-left triangle (pixel: 0, diagonal: 1-2). |
| 4592 | */ |
| 4593 | gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); |
| 4594 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4595 | pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta, |
| 4596 | pixels[0],pixels[1],pixels[2])); |
| 4597 | } |
| 4598 | else |
| 4599 | { |
| 4600 | /* |
| 4601 | Bottom-right triangle (pixel: 3, diagonal: 1-2). |
| 4602 | */ |
| 4603 | delta.x=1.0-delta.x; |
| 4604 | delta.y=1.0-delta.y; |
| 4605 | gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); |
| 4606 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4607 | pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta, |
| 4608 | pixels[3],pixels[2],pixels[1])); |
| 4609 | } |
| 4610 | } |
| 4611 | } |
| 4612 | break; |
| 4613 | } |
| 4614 | case SplineInterpolatePixel: |
| 4615 | { |
| 4616 | p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4, |
| 4617 | exception); |
| 4618 | if (p == (const Quantum *) NULL) |
| 4619 | { |
| 4620 | status=MagickFalse; |
| 4621 | break; |
| 4622 | } |
| 4623 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4624 | { |
| 4625 | double |
| 4626 | sum; |
| 4627 | |
| 4628 | MagickRealType |
| 4629 | dx, |
| 4630 | dy; |
| 4631 | |
| 4632 | PointInfo |
| 4633 | delta; |
| 4634 | |
| 4635 | register ssize_t |
| 4636 | j; |
| 4637 | |
| 4638 | ssize_t |
| 4639 | k, |
| 4640 | n; |
| 4641 | |
| 4642 | traits=GetPixelChannelMapTraits(source,(PixelChannel) i); |
| 4643 | channel=GetPixelChannelMapChannel(source,(PixelChannel) i); |
| 4644 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4645 | if ((traits == UndefinedPixelTrait) || |
| 4646 | (destination_traits == UndefinedPixelTrait)) |
| 4647 | continue; |
| 4648 | if ((traits & BlendPixelTrait) == 0) |
| 4649 | for (j=0; j < 16; j++) |
| 4650 | { |
| 4651 | alpha[j]=1.0; |
| 4652 | pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i]; |
| 4653 | } |
| 4654 | else |
| 4655 | for (j=0; j < 16; j++) |
| 4656 | { |
| 4657 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 4658 | GetPixelChannels(source)); |
| 4659 | pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i]; |
| 4660 | } |
| 4661 | delta.x=x-x_offset; |
| 4662 | delta.y=y-y_offset; |
| 4663 | sum=0.0; |
| 4664 | n=0; |
| 4665 | for (j=(-1); j < 3L; j++) |
| 4666 | { |
| 4667 | dy=CubicWeightingFunction((MagickRealType) j-delta.y); |
| 4668 | for (k=(-1); k < 3L; k++) |
| 4669 | { |
| 4670 | dx=CubicWeightingFunction(delta.x-(MagickRealType) k); |
| 4671 | gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : |
| 4672 | alpha[n]); |
| 4673 | sum+=gamma*dx*dy*pixels[n]; |
| 4674 | n++; |
| 4675 | } |
| 4676 | } |
| 4677 | pixel[channel]=ClampToQuantum(sum); |
| 4678 | } |
| 4679 | break; |
| 4680 | } |
| 4681 | } |
| 4682 | return(status); |
| 4683 | } |
| 4684 | |
| 4685 | /* |
| 4686 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4687 | % % |
| 4688 | % % |
| 4689 | % % |
cristy | 9075cdb | 2011-07-30 01:06:23 +0000 | [diff] [blame] | 4690 | % I n t e r p o l a t e P i x e l I n f o % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4691 | % % |
| 4692 | % % |
| 4693 | % % |
| 4694 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4695 | % |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4696 | % InterpolatePixelInfo() applies a pixel interpolation method between a |
| 4697 | % floating point coordinate and the pixels surrounding that coordinate. No |
| 4698 | % pixel area resampling, or scaling of the result is performed. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4699 | % |
| 4700 | % The format of the InterpolatePixelInfo method is: |
| 4701 | % |
| 4702 | % MagickBooleanType InterpolatePixelInfo(const Image *image, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4703 | % const CacheView *image_view,const PixelInterpolateMethod method, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4704 | % const double x,const double y,PixelInfo *pixel, |
| 4705 | % ExceptionInfo *exception) |
| 4706 | % |
| 4707 | % A description of each parameter follows: |
| 4708 | % |
| 4709 | % o image: the image. |
| 4710 | % |
| 4711 | % o image_view: the image view. |
| 4712 | % |
| 4713 | % o method: the pixel color interpolation method. |
| 4714 | % |
| 4715 | % o x,y: A double representing the current (x,y) position of the pixel. |
| 4716 | % |
| 4717 | % o pixel: return the interpolated pixel here. |
| 4718 | % |
| 4719 | % o exception: return any errors or warnings in this structure. |
| 4720 | % |
| 4721 | */ |
| 4722 | |
| 4723 | static inline void AlphaBlendPixelInfo(const Image *image, |
| 4724 | const Quantum *pixel,PixelInfo *pixel_info,MagickRealType *alpha) |
| 4725 | { |
| 4726 | if (image->matte == MagickFalse) |
| 4727 | { |
| 4728 | *alpha=1.0; |
| 4729 | pixel_info->red=(MagickRealType) GetPixelRed(image,pixel); |
| 4730 | pixel_info->green=(MagickRealType) GetPixelGreen(image,pixel); |
| 4731 | pixel_info->blue=(MagickRealType) GetPixelBlue(image,pixel); |
| 4732 | pixel_info->black=0.0; |
| 4733 | if (image->colorspace == CMYKColorspace) |
| 4734 | pixel_info->black=(MagickRealType) GetPixelBlack(image,pixel); |
| 4735 | pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel); |
| 4736 | return; |
| 4737 | } |
| 4738 | *alpha=QuantumScale*GetPixelAlpha(image,pixel); |
| 4739 | pixel_info->red=(*alpha*GetPixelRed(image,pixel)); |
| 4740 | pixel_info->green=(*alpha*GetPixelGreen(image,pixel)); |
| 4741 | pixel_info->blue=(*alpha*GetPixelBlue(image,pixel)); |
| 4742 | pixel_info->black=0.0; |
| 4743 | if (image->colorspace == CMYKColorspace) |
| 4744 | pixel_info->black=(*alpha*GetPixelBlack(image,pixel)); |
| 4745 | pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel); |
| 4746 | } |
| 4747 | |
| 4748 | static void BicubicInterpolate(const PixelInfo *pixels,const double dx, |
| 4749 | PixelInfo *pixel) |
| 4750 | { |
| 4751 | MagickRealType |
| 4752 | dx2, |
| 4753 | p, |
| 4754 | q, |
| 4755 | r, |
| 4756 | s; |
| 4757 | |
| 4758 | dx2=dx*dx; |
| 4759 | p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red); |
| 4760 | q=(pixels[0].red-pixels[1].red)-p; |
| 4761 | r=pixels[2].red-pixels[0].red; |
| 4762 | s=pixels[1].red; |
| 4763 | pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 4764 | p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green); |
| 4765 | q=(pixels[0].green-pixels[1].green)-p; |
| 4766 | r=pixels[2].green-pixels[0].green; |
| 4767 | s=pixels[1].green; |
| 4768 | pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 4769 | p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue); |
| 4770 | q=(pixels[0].blue-pixels[1].blue)-p; |
| 4771 | r=pixels[2].blue-pixels[0].blue; |
| 4772 | s=pixels[1].blue; |
| 4773 | pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 4774 | p=(pixels[3].alpha-pixels[2].alpha)-(pixels[0].alpha-pixels[1].alpha); |
| 4775 | q=(pixels[0].alpha-pixels[1].alpha)-p; |
| 4776 | r=pixels[2].alpha-pixels[0].alpha; |
| 4777 | s=pixels[1].alpha; |
| 4778 | pixel->alpha=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 4779 | if (pixel->colorspace == CMYKColorspace) |
| 4780 | { |
| 4781 | p=(pixels[3].black-pixels[2].black)-(pixels[0].black-pixels[1].black); |
| 4782 | q=(pixels[0].black-pixels[1].black)-p; |
| 4783 | r=pixels[2].black-pixels[0].black; |
| 4784 | s=pixels[1].black; |
| 4785 | pixel->black=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 4786 | } |
| 4787 | } |
| 4788 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4789 | MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4790 | const CacheView *image_view,const PixelInterpolateMethod method, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4791 | const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception) |
| 4792 | { |
| 4793 | MagickBooleanType |
| 4794 | status; |
| 4795 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4796 | MagickRealType |
| 4797 | alpha[16], |
| 4798 | gamma; |
| 4799 | |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4800 | PixelInfo |
| 4801 | pixels[16]; |
| 4802 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4803 | register const Quantum |
| 4804 | *p; |
| 4805 | |
| 4806 | register ssize_t |
| 4807 | i; |
| 4808 | |
| 4809 | ssize_t |
| 4810 | x_offset, |
| 4811 | y_offset; |
| 4812 | |
| 4813 | assert(image != (Image *) NULL); |
| 4814 | assert(image->signature == MagickSignature); |
| 4815 | assert(image_view != (CacheView *) NULL); |
| 4816 | status=MagickTrue; |
| 4817 | x_offset=(ssize_t) floor(x); |
| 4818 | y_offset=(ssize_t) floor(y); |
| 4819 | switch (method == UndefinedInterpolatePixel ? image->interpolate : method) |
| 4820 | { |
| 4821 | case AverageInterpolatePixel: |
| 4822 | { |
| 4823 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 4824 | exception); |
| 4825 | if (p == (const Quantum *) NULL) |
| 4826 | { |
| 4827 | status=MagickFalse; |
| 4828 | break; |
| 4829 | } |
cristy | 5ce8df8 | 2011-07-07 14:52:23 +0000 | [diff] [blame] | 4830 | AlphaBlendPixelInfo(image,p,pixels+0,alpha+0); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4831 | AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4832 | AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2); |
| 4833 | AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3); |
| 4834 | AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4); |
| 4835 | AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5); |
| 4836 | AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6); |
| 4837 | AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7); |
| 4838 | AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8); |
| 4839 | AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9); |
| 4840 | AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4841 | 10); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4842 | AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4843 | 11); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4844 | AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4845 | 12); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4846 | AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4847 | 13); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4848 | AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4849 | 14); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4850 | AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4851 | 15); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4852 | pixel->red=0.0; |
| 4853 | pixel->green=0.0; |
| 4854 | pixel->blue=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4855 | pixel->black=0.0; |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4856 | pixel->alpha=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4857 | for (i=0; i < 16L; i++) |
| 4858 | { |
| 4859 | gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]); |
| 4860 | pixel->red+=gamma*0.0625*pixels[i].red; |
| 4861 | pixel->green+=gamma*0.0625*pixels[i].green; |
| 4862 | pixel->blue+=gamma*0.0625*pixels[i].blue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4863 | if (image->colorspace == CMYKColorspace) |
| 4864 | pixel->black+=gamma*0.0625*pixels[i].black; |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4865 | pixel->alpha+=0.0625*pixels[i].alpha; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4866 | } |
| 4867 | break; |
| 4868 | } |
| 4869 | case BicubicInterpolatePixel: |
| 4870 | { |
| 4871 | PixelInfo |
| 4872 | u[4]; |
| 4873 | |
| 4874 | PointInfo |
| 4875 | delta; |
| 4876 | |
| 4877 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 4878 | exception); |
| 4879 | if (p == (const Quantum *) NULL) |
| 4880 | { |
| 4881 | status=MagickFalse; |
| 4882 | break; |
| 4883 | } |
cristy | 5ce8df8 | 2011-07-07 14:52:23 +0000 | [diff] [blame] | 4884 | AlphaBlendPixelInfo(image,p,pixels+0,alpha+0); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4885 | AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4886 | AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2); |
| 4887 | AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3); |
| 4888 | AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4); |
| 4889 | AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5); |
| 4890 | AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6); |
| 4891 | AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7); |
| 4892 | AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8); |
| 4893 | AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9); |
| 4894 | AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4895 | 10); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4896 | AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4897 | 11); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4898 | AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4899 | 12); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4900 | AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4901 | 13); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4902 | AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4903 | 14); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4904 | AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4905 | 15); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4906 | delta.x=x-x_offset; |
| 4907 | delta.y=y-y_offset; |
| 4908 | for (i=0; i < 4L; i++) |
| 4909 | BicubicInterpolate(pixels+4*i,delta.x,u+i); |
| 4910 | BicubicInterpolate(u,delta.y,pixel); |
| 4911 | break; |
| 4912 | } |
| 4913 | case BilinearInterpolatePixel: |
| 4914 | default: |
| 4915 | { |
| 4916 | PointInfo |
| 4917 | delta, |
| 4918 | epsilon; |
| 4919 | |
| 4920 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 4921 | if (p == (const Quantum *) NULL) |
| 4922 | { |
| 4923 | status=MagickFalse; |
| 4924 | break; |
| 4925 | } |
cristy | 5ce8df8 | 2011-07-07 14:52:23 +0000 | [diff] [blame] | 4926 | AlphaBlendPixelInfo(image,p,pixels+0,alpha+0); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4927 | AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4928 | AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2); |
| 4929 | AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4930 | delta.x=x-x_offset; |
| 4931 | delta.y=y-y_offset; |
| 4932 | epsilon.x=1.0-delta.x; |
| 4933 | epsilon.y=1.0-delta.y; |
| 4934 | gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* |
| 4935 | (epsilon.x*alpha[2]+delta.x*alpha[3]))); |
| 4936 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4937 | pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x* |
| 4938 | pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red)); |
| 4939 | pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x* |
| 4940 | pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x* |
| 4941 | pixels[3].green)); |
| 4942 | pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x* |
| 4943 | pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x* |
| 4944 | pixels[3].blue)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4945 | if (image->colorspace == CMYKColorspace) |
| 4946 | pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x* |
| 4947 | pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x* |
| 4948 | pixels[3].black)); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4949 | gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x))); |
| 4950 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4951 | pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x* |
| 4952 | pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x* |
| 4953 | pixels[3].alpha)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4954 | break; |
| 4955 | } |
| 4956 | case FilterInterpolatePixel: |
| 4957 | { |
| 4958 | CacheView |
| 4959 | *filter_view; |
| 4960 | |
| 4961 | Image |
| 4962 | *excerpt_image, |
| 4963 | *filter_image; |
| 4964 | |
| 4965 | RectangleInfo |
| 4966 | geometry; |
| 4967 | |
| 4968 | geometry.width=4L; |
| 4969 | geometry.height=4L; |
| 4970 | geometry.x=x_offset-1; |
| 4971 | geometry.y=y_offset-1; |
| 4972 | excerpt_image=ExcerptImage(image,&geometry,exception); |
| 4973 | if (excerpt_image == (Image *) NULL) |
| 4974 | { |
| 4975 | status=MagickFalse; |
| 4976 | break; |
| 4977 | } |
| 4978 | filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur, |
| 4979 | exception); |
| 4980 | excerpt_image=DestroyImage(excerpt_image); |
| 4981 | if (filter_image == (Image *) NULL) |
| 4982 | break; |
| 4983 | filter_view=AcquireCacheView(filter_image); |
| 4984 | p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception); |
| 4985 | if (p != (const Quantum *) NULL) |
| 4986 | SetPixelInfo(image,p,pixel); |
| 4987 | filter_view=DestroyCacheView(filter_view); |
| 4988 | filter_image=DestroyImage(filter_image); |
| 4989 | break; |
| 4990 | } |
| 4991 | case IntegerInterpolatePixel: |
| 4992 | { |
| 4993 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception); |
| 4994 | if (p == (const Quantum *) NULL) |
| 4995 | { |
| 4996 | status=MagickFalse; |
| 4997 | break; |
| 4998 | } |
| 4999 | SetPixelInfo(image,p,pixel); |
| 5000 | break; |
| 5001 | } |
| 5002 | case MeshInterpolatePixel: |
| 5003 | { |
| 5004 | PointInfo |
| 5005 | delta, |
| 5006 | luminance; |
| 5007 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5008 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5009 | if (p == (const Quantum *) NULL) |
| 5010 | { |
| 5011 | status=MagickFalse; |
| 5012 | break; |
| 5013 | } |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5014 | delta.x=x-x_offset; |
| 5015 | delta.y=y-y_offset; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 5016 | luminance.x=GetPixelLuminance(image,p)-(double) |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5017 | GetPixelLuminance(image,p+3*GetPixelChannels(image)); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5018 | luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double) |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5019 | GetPixelLuminance(image,p+2*GetPixelChannels(image)); |
cristy | 5ce8df8 | 2011-07-07 14:52:23 +0000 | [diff] [blame] | 5020 | AlphaBlendPixelInfo(image,p,pixels+0,alpha+0); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5021 | AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5022 | AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2); |
| 5023 | AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5024 | if (fabs(luminance.x) < fabs(luminance.y)) |
| 5025 | { |
| 5026 | /* |
| 5027 | Diagonal 0-3 NW-SE. |
| 5028 | */ |
| 5029 | if (delta.x <= delta.y) |
| 5030 | { |
| 5031 | /* |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5032 | Bottom-left triangle (pixel: 2, diagonal: 0-3). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5033 | */ |
| 5034 | delta.y=1.0-delta.y; |
| 5035 | gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); |
| 5036 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 5037 | pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red, |
| 5038 | pixels[3].red,pixels[0].red); |
| 5039 | pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green, |
| 5040 | pixels[3].green,pixels[0].green); |
| 5041 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue, |
| 5042 | pixels[3].blue,pixels[0].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5043 | if (image->colorspace == CMYKColorspace) |
| 5044 | pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black, |
| 5045 | pixels[3].black,pixels[0].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5046 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5047 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha, |
| 5048 | pixels[3].alpha,pixels[0].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5049 | } |
| 5050 | else |
| 5051 | { |
| 5052 | /* |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5053 | Top-right triangle (pixel:1 , diagonal: 0-3). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5054 | */ |
| 5055 | delta.x=1.0-delta.x; |
| 5056 | gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); |
| 5057 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 5058 | pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red, |
| 5059 | pixels[0].red,pixels[3].red); |
| 5060 | pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green, |
| 5061 | pixels[0].green,pixels[3].green); |
| 5062 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue, |
| 5063 | pixels[0].blue,pixels[3].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5064 | if (image->colorspace == CMYKColorspace) |
| 5065 | pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black, |
| 5066 | pixels[0].black,pixels[3].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5067 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5068 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha, |
| 5069 | pixels[0].alpha,pixels[3].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5070 | } |
| 5071 | } |
| 5072 | else |
| 5073 | { |
| 5074 | /* |
| 5075 | Diagonal 1-2 NE-SW. |
| 5076 | */ |
| 5077 | if (delta.x <= (1.0-delta.y)) |
| 5078 | { |
| 5079 | /* |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5080 | Top-left triangle (pixel: 0, diagonal: 1-2). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5081 | */ |
| 5082 | gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); |
| 5083 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 5084 | pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red, |
| 5085 | pixels[1].red,pixels[2].red); |
| 5086 | pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green, |
| 5087 | pixels[1].green,pixels[2].green); |
| 5088 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue, |
| 5089 | pixels[1].blue,pixels[2].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5090 | if (image->colorspace == CMYKColorspace) |
| 5091 | pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black, |
| 5092 | pixels[1].black,pixels[2].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5093 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5094 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha, |
| 5095 | pixels[1].alpha,pixels[2].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5096 | } |
| 5097 | else |
| 5098 | { |
| 5099 | /* |
| 5100 | Bottom-right triangle (pixel: 3, diagonal: 1-2). |
| 5101 | */ |
| 5102 | delta.x=1.0-delta.x; |
| 5103 | delta.y=1.0-delta.y; |
| 5104 | gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); |
| 5105 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 5106 | pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red, |
| 5107 | pixels[2].red,pixels[1].red); |
| 5108 | pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green, |
| 5109 | pixels[2].green,pixels[1].green); |
| 5110 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue, |
| 5111 | pixels[2].blue,pixels[1].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5112 | if (image->colorspace == CMYKColorspace) |
| 5113 | pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black, |
| 5114 | pixels[2].black,pixels[1].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5115 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5116 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha, |
| 5117 | pixels[2].alpha,pixels[1].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5118 | } |
| 5119 | } |
| 5120 | break; |
| 5121 | } |
| 5122 | case NearestNeighborInterpolatePixel: |
| 5123 | { |
| 5124 | p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x), |
| 5125 | NearestNeighbor(y),1,1,exception); |
| 5126 | if (p == (const Quantum *) NULL) |
| 5127 | { |
| 5128 | status=MagickFalse; |
| 5129 | break; |
| 5130 | } |
| 5131 | SetPixelInfo(image,p,pixel); |
| 5132 | break; |
| 5133 | } |
| 5134 | case SplineInterpolatePixel: |
| 5135 | { |
| 5136 | MagickRealType |
| 5137 | dx, |
| 5138 | dy; |
| 5139 | |
| 5140 | PointInfo |
| 5141 | delta; |
| 5142 | |
| 5143 | ssize_t |
| 5144 | j, |
| 5145 | n; |
| 5146 | |
| 5147 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 5148 | exception); |
| 5149 | if (p == (const Quantum *) NULL) |
| 5150 | { |
| 5151 | status=MagickFalse; |
| 5152 | break; |
| 5153 | } |
cristy | 5ce8df8 | 2011-07-07 14:52:23 +0000 | [diff] [blame] | 5154 | AlphaBlendPixelInfo(image,p,pixels+0,alpha+0); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5155 | AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5156 | AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2); |
| 5157 | AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3); |
| 5158 | AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4); |
| 5159 | AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5); |
| 5160 | AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6); |
| 5161 | AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7); |
| 5162 | AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8); |
| 5163 | AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9); |
| 5164 | AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5165 | 10); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5166 | AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5167 | 11); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5168 | AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5169 | 12); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5170 | AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5171 | 13); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5172 | AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5173 | 14); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5174 | AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5175 | 15); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5176 | pixel->red=0.0; |
| 5177 | pixel->green=0.0; |
| 5178 | pixel->blue=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5179 | pixel->black=0.0; |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5180 | pixel->alpha=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5181 | delta.x=x-x_offset; |
| 5182 | delta.y=y-y_offset; |
| 5183 | n=0; |
| 5184 | for (i=(-1); i < 3L; i++) |
| 5185 | { |
| 5186 | dy=CubicWeightingFunction((MagickRealType) i-delta.y); |
| 5187 | for (j=(-1); j < 3L; j++) |
| 5188 | { |
| 5189 | dx=CubicWeightingFunction(delta.x-(MagickRealType) j); |
| 5190 | gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]); |
| 5191 | pixel->red+=gamma*dx*dy*pixels[n].red; |
| 5192 | pixel->green+=gamma*dx*dy*pixels[n].green; |
| 5193 | pixel->blue+=gamma*dx*dy*pixels[n].blue; |
| 5194 | if (image->colorspace == CMYKColorspace) |
| 5195 | pixel->black+=gamma*dx*dy*pixels[n].black; |
| 5196 | pixel->alpha+=dx*dy*pixels[n].alpha; |
| 5197 | n++; |
| 5198 | } |
| 5199 | } |
| 5200 | break; |
| 5201 | } |
| 5202 | } |
| 5203 | return(status); |
| 5204 | } |
| 5205 | |
| 5206 | /* |
| 5207 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5208 | % % |
| 5209 | % % |
| 5210 | % % |
| 5211 | + I s F u z z y E q u i v a l e n c e P i x e l % |
| 5212 | % % |
| 5213 | % % |
| 5214 | % % |
| 5215 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5216 | % |
| 5217 | % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two |
| 5218 | % pixels is less than the specified distance in a linear three (or four)u |
| 5219 | % dimensional color space. |
| 5220 | % |
| 5221 | % The format of the IsFuzzyEquivalencePixel method is: |
| 5222 | % |
| 5223 | % void IsFuzzyEquivalencePixel(const Image *image,const Quantum *p, |
| 5224 | % const Quantum *q) |
| 5225 | % |
| 5226 | % A description of each parameter follows: |
| 5227 | % |
| 5228 | % o image: the image. |
| 5229 | % |
| 5230 | % o p: Pixel p. |
| 5231 | % |
| 5232 | % o q: Pixel q. |
| 5233 | % |
| 5234 | */ |
| 5235 | MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *image, |
| 5236 | const Quantum *p,const Quantum *q) |
| 5237 | { |
| 5238 | MagickRealType |
| 5239 | fuzz, |
| 5240 | pixel; |
| 5241 | |
| 5242 | register MagickRealType |
| 5243 | distance, |
| 5244 | scale; |
| 5245 | |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5246 | fuzz=MagickMax(image->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax( |
| 5247 | image->fuzz,(MagickRealType) MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5248 | scale=1.0; |
| 5249 | distance=0.0; |
| 5250 | if (image->matte != MagickFalse) |
| 5251 | { |
| 5252 | /* |
| 5253 | Transparencies are involved - set alpha distance |
| 5254 | */ |
| 5255 | pixel=(MagickRealType) ((image->matte != MagickFalse ? |
| 5256 | GetPixelAlpha(image,p) : OpaqueAlpha)-(image->matte != MagickFalse ? |
| 5257 | GetPixelAlpha(image,q) : OpaqueAlpha)); |
| 5258 | distance=pixel*pixel; |
| 5259 | if (distance > fuzz) |
| 5260 | return(MagickFalse); |
| 5261 | /* |
| 5262 | Generate a alpha scaling factor to generate a 4D cone on colorspace |
| 5263 | Note that if one color is transparent, distance has no color component. |
| 5264 | */ |
| 5265 | scale=QuantumScale*GetPixelAlpha(image,p); |
| 5266 | scale*=QuantumScale*GetPixelAlpha(image,q); |
| 5267 | if (scale <= MagickEpsilon) |
| 5268 | return(MagickTrue); |
| 5269 | } |
| 5270 | /* |
| 5271 | RGB or CMY color cube |
| 5272 | */ |
| 5273 | distance*=3.0; /* rescale appropriately */ |
| 5274 | fuzz*=3.0; |
| 5275 | pixel=GetPixelRed(image,p)-(MagickRealType) GetPixelRed(image,q); |
| 5276 | if ((image->colorspace == HSLColorspace) || |
| 5277 | (image->colorspace == HSBColorspace) || |
| 5278 | (image->colorspace == HWBColorspace)) |
| 5279 | { |
| 5280 | /* |
| 5281 | Compute an arc distance for hue. It should be a vector angle of |
| 5282 | 'S'/'W' length with 'L'/'B' forming appropriate cones. |
| 5283 | */ |
| 5284 | if (fabs((double) pixel) > (QuantumRange/2)) |
| 5285 | pixel-=QuantumRange; |
| 5286 | pixel*=2; |
| 5287 | } |
| 5288 | distance+=scale*pixel*pixel; |
| 5289 | if (distance > fuzz) |
| 5290 | return(MagickFalse); |
| 5291 | pixel=GetPixelGreen(image,p)-(MagickRealType) GetPixelGreen(image,q); |
| 5292 | distance+=scale*pixel*pixel; |
| 5293 | if (distance > fuzz) |
| 5294 | return(MagickFalse); |
| 5295 | pixel=GetPixelBlue(image,p)-(MagickRealType) GetPixelBlue(image,q); |
| 5296 | distance+=scale*pixel*pixel; |
| 5297 | if (distance > fuzz) |
| 5298 | return(MagickFalse); |
| 5299 | return(MagickTrue); |
| 5300 | } |
| 5301 | |
| 5302 | /* |
| 5303 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5304 | % % |
| 5305 | % % |
| 5306 | % % |
| 5307 | + I s F u z z y E q u i v a l e n c e P i x e l I n f o % |
| 5308 | % % |
| 5309 | % % |
| 5310 | % % |
| 5311 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5312 | % |
| 5313 | % IsFuzzyEquivalencePixelInfo() returns true if the distance between two |
| 5314 | % colors is less than the specified distance in a linear three (or four) |
| 5315 | % dimensional color space. |
| 5316 | % |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5317 | % This implements the equivalent of: |
| 5318 | % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5319 | % |
| 5320 | % Which produces a multi-dimensional cone for that colorspace along the |
| 5321 | % transparency vector. |
| 5322 | % |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5323 | % For example for an RGB: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5324 | % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3 |
| 5325 | % |
| 5326 | % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/ |
| 5327 | % |
| 5328 | % Hue colorspace distances need more work. Hue is not a distance, it is an |
| 5329 | % angle! |
| 5330 | % |
| 5331 | % A check that q is in the same color space as p should be made and the |
| 5332 | % appropriate mapping made. -- Anthony Thyssen 8 December 2010 |
| 5333 | % |
| 5334 | % The format of the IsFuzzyEquivalencePixelInfo method is: |
| 5335 | % |
| 5336 | % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p, |
| 5337 | % const PixelInfo *q) |
| 5338 | % |
| 5339 | % A description of each parameter follows: |
| 5340 | % |
| 5341 | % o p: Pixel p. |
| 5342 | % |
| 5343 | % o q: Pixel q. |
| 5344 | % |
| 5345 | */ |
| 5346 | MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p, |
| 5347 | const PixelInfo *q) |
| 5348 | { |
| 5349 | MagickRealType |
| 5350 | fuzz, |
| 5351 | pixel; |
| 5352 | |
| 5353 | register MagickRealType |
| 5354 | scale, |
| 5355 | distance; |
| 5356 | |
| 5357 | if ((p->fuzz == 0.0) && (q->fuzz == 0.0)) |
| 5358 | return(IsPixelInfoEquivalent(p,q)); |
| 5359 | if (p->fuzz == 0.0) |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5360 | fuzz=MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz, |
| 5361 | (MagickRealType) MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5362 | else if (q->fuzz == 0.0) |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5363 | fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(p->fuzz, |
| 5364 | (MagickRealType) MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5365 | else |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5366 | fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz, |
| 5367 | (MagickRealType) MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5368 | scale=1.0; |
| 5369 | distance=0.0; |
| 5370 | if ((p->matte != MagickFalse) || (q->matte != MagickFalse)) |
| 5371 | { |
| 5372 | /* |
| 5373 | Transparencies are involved - set alpha distance. |
| 5374 | */ |
| 5375 | pixel=(p->matte != MagickFalse ? p->alpha : OpaqueAlpha)- |
| 5376 | (q->matte != MagickFalse ? q->alpha : OpaqueAlpha); |
| 5377 | distance=pixel*pixel; |
| 5378 | if (distance > fuzz) |
| 5379 | return(MagickFalse); |
| 5380 | /* |
| 5381 | Generate a alpha scaling factor to generate a 4D cone on colorspace. |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5382 | If one color is transparent, distance has no color component. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5383 | */ |
| 5384 | if (p->matte != MagickFalse) |
| 5385 | scale=(QuantumScale*p->alpha); |
| 5386 | if (q->matte != MagickFalse) |
| 5387 | scale*=(QuantumScale*q->alpha); |
| 5388 | if (scale <= MagickEpsilon ) |
| 5389 | return(MagickTrue); |
| 5390 | } |
| 5391 | /* |
| 5392 | CMYK create a CMY cube with a multi-dimensional cone toward black. |
| 5393 | */ |
| 5394 | if (p->colorspace == CMYKColorspace) |
| 5395 | { |
| 5396 | pixel=p->black-q->black; |
| 5397 | distance+=pixel*pixel*scale; |
| 5398 | if (distance > fuzz) |
| 5399 | return(MagickFalse); |
| 5400 | scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->black)); |
| 5401 | scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->black)); |
| 5402 | } |
| 5403 | /* |
| 5404 | RGB or CMY color cube. |
| 5405 | */ |
| 5406 | distance*=3.0; /* rescale appropriately */ |
| 5407 | fuzz*=3.0; |
| 5408 | pixel=p->red-q->red; |
| 5409 | if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) || |
| 5410 | (p->colorspace == HWBColorspace)) |
| 5411 | { |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5412 | /* |
| 5413 | This calculates a arc distance for hue-- it should be a vector angle |
| 5414 | of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other |
| 5415 | words this is a hack - Anthony. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5416 | */ |
| 5417 | if (fabs((double) pixel) > (QuantumRange/2)) |
| 5418 | pixel-=QuantumRange; |
| 5419 | pixel*=2; |
| 5420 | } |
| 5421 | distance+=pixel*pixel*scale; |
| 5422 | if (distance > fuzz) |
| 5423 | return(MagickFalse); |
| 5424 | pixel=p->green-q->green; |
| 5425 | distance+=pixel*pixel*scale; |
| 5426 | if (distance > fuzz) |
| 5427 | return(MagickFalse); |
| 5428 | pixel=p->blue-q->blue; |
| 5429 | distance+=pixel*pixel*scale; |
| 5430 | if (distance > fuzz) |
| 5431 | return(MagickFalse); |
| 5432 | return(MagickTrue); |
| 5433 | } |
| 5434 | |
| 5435 | /* |
| 5436 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5437 | % % |
| 5438 | % % |
| 5439 | % % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5440 | % S e t P i x e l C h a n n e l M a p % |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5441 | % % |
| 5442 | % % |
| 5443 | % % |
| 5444 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5445 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5446 | % SetPixelChannelMap() sets the pixel channel map from the specified channel |
| 5447 | % mask. |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5448 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5449 | % The format of the SetPixelChannelMap method is: |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5450 | % |
cristy | 07a6785 | 2011-08-26 13:25:03 +0000 | [diff] [blame] | 5451 | % void SetPixelChannelMap(Image *image,const ChannelType channel_mask) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5452 | % |
| 5453 | % A description of each parameter follows: |
| 5454 | % |
| 5455 | % o image: the image. |
| 5456 | % |
cristy | 4426146 | 2011-08-09 13:34:47 +0000 | [diff] [blame] | 5457 | % o mask: the channel mask. |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5458 | % |
| 5459 | */ |
cristy | 07a6785 | 2011-08-26 13:25:03 +0000 | [diff] [blame] | 5460 | MagickExport void SetPixelChannelMap(Image *image, |
| 5461 | const ChannelType channel_mask) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5462 | { |
cristy | 6a917d6 | 2011-08-24 17:31:30 +0000 | [diff] [blame] | 5463 | #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01) |
cristy | dafd287 | 2011-07-24 22:06:13 +0000 | [diff] [blame] | 5464 | |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5465 | register ssize_t |
| 5466 | i; |
| 5467 | |
cristy | 3c30981 | 2011-11-08 02:40:43 +0000 | [diff] [blame^] | 5468 | image->channel_mask=channel_mask; |
cristy | dafd287 | 2011-07-24 22:06:13 +0000 | [diff] [blame] | 5469 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
cristy | 07a6785 | 2011-08-26 13:25:03 +0000 | [diff] [blame] | 5470 | SetPixelChannelMapTraits(image,(PixelChannel) i, |
cristy | 902698c | 2011-10-24 17:51:16 +0000 | [diff] [blame] | 5471 | GetChannelBit(channel_mask,i) == 0 ? CopyPixelTrait : |
| 5472 | image->matte == MagickFalse ? UpdatePixelTrait : |
| 5473 | UpdatePixelTrait | BlendPixelTrait); |
cristy | dafd287 | 2011-07-24 22:06:13 +0000 | [diff] [blame] | 5474 | for ( ; i < MaxPixelChannels; i++) |
cristy | 2a14c94 | 2011-07-24 19:51:21 +0000 | [diff] [blame] | 5475 | SetPixelChannelMapTraits(image,(PixelChannel) i,UndefinedPixelTrait); |
cristy | 1685e72 | 2011-09-06 00:04:19 +0000 | [diff] [blame] | 5476 | if (image->storage_class == PseudoClass) |
| 5477 | SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait); |
cristy | 6dcb9b8 | 2011-10-23 23:21:25 +0000 | [diff] [blame] | 5478 | if (image->debug != MagickFalse) |
| 5479 | LogPixelChannels(image); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5480 | } |
| 5481 | |
| 5482 | /* |
| 5483 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5484 | % % |
| 5485 | % % |
| 5486 | % % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5487 | % S e t P i x e l C h a n n e l M a s k % |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5488 | % % |
| 5489 | % % |
| 5490 | % % |
| 5491 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5492 | % |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5493 | % SetPixelChannelMask() sets the pixel channel mask from the specified channel |
| 5494 | % mask. |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5495 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5496 | % The format of the SetPixelChannelMask method is: |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5497 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5498 | % ChannelType SetPixelChannelMask(Image *image, |
| 5499 | % const ChannelType channel_mask) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5500 | % |
| 5501 | % A description of each parameter follows: |
| 5502 | % |
| 5503 | % o image: the image. |
| 5504 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5505 | % o channel_mask: the channel mask. |
| 5506 | % |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5507 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5508 | MagickExport ChannelType SetPixelChannelMask(Image *image, |
| 5509 | const ChannelType channel_mask) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5510 | { |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5511 | ChannelType |
| 5512 | mask; |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 5513 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5514 | mask=image->channel_mask; |
| 5515 | image->channel_mask=channel_mask; |
| 5516 | SetPixelChannelMap(image,channel_mask); |
| 5517 | return(mask); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5518 | } |