cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % SSSSS TTTTT RRRR EEEEE AAA M M % |
| 7 | % SS T R R E A A MM MM % |
| 8 | % SSS T RRRR EEE AAAAA M M M % |
| 9 | % SS T R R E A A M M % |
| 10 | % SSSSS T R R EEEEE A A M M % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Pixel Stream Methods % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % March 2000 % |
| 18 | % % |
| 19 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | % |
| 38 | */ |
| 39 | |
| 40 | /* |
| 41 | Include declarations. |
| 42 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 43 | #include "MagickCore/studio.h" |
| 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/blob-private.h" |
| 46 | #include "MagickCore/cache.h" |
| 47 | #include "MagickCore/cache-private.h" |
| 48 | #include "MagickCore/color-private.h" |
| 49 | #include "MagickCore/composite-private.h" |
| 50 | #include "MagickCore/constitute.h" |
| 51 | #include "MagickCore/exception.h" |
| 52 | #include "MagickCore/exception-private.h" |
| 53 | #include "MagickCore/geometry.h" |
| 54 | #include "MagickCore/memory_.h" |
| 55 | #include "MagickCore/pixel.h" |
| 56 | #include "MagickCore/pixel-accessor.h" |
| 57 | #include "MagickCore/quantum.h" |
| 58 | #include "MagickCore/quantum-private.h" |
| 59 | #include "MagickCore/semaphore.h" |
| 60 | #include "MagickCore/stream.h" |
| 61 | #include "MagickCore/stream-private.h" |
| 62 | #include "MagickCore/string_.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | Typedef declaractions. |
| 66 | */ |
| 67 | struct _StreamInfo |
| 68 | { |
| 69 | const ImageInfo |
| 70 | *image_info; |
| 71 | |
| 72 | const Image |
| 73 | *image; |
| 74 | |
| 75 | Image |
| 76 | *stream; |
| 77 | |
| 78 | QuantumInfo |
| 79 | *quantum_info; |
| 80 | |
| 81 | char |
| 82 | *map; |
| 83 | |
| 84 | StorageType |
| 85 | storage_type; |
| 86 | |
| 87 | unsigned char |
| 88 | *pixels; |
| 89 | |
| 90 | RectangleInfo |
| 91 | extract_info; |
| 92 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 93 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 94 | y; |
| 95 | |
| 96 | ExceptionInfo |
| 97 | *exception; |
| 98 | |
| 99 | const void |
| 100 | *client_data; |
| 101 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 102 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 | signature; |
| 104 | }; |
| 105 | |
| 106 | /* |
| 107 | Declare pixel cache interfaces. |
| 108 | */ |
| 109 | #if defined(__cplusplus) || defined(c_plusplus) |
| 110 | extern "C" { |
| 111 | #endif |
| 112 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 113 | static const Quantum |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 114 | *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t, |
| 115 | const ssize_t,const size_t,const size_t,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 116 | |
| 117 | static MagickBooleanType |
| 118 | StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *), |
| 119 | SyncAuthenticPixelsStream(Image *,ExceptionInfo *); |
| 120 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 121 | static Quantum |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 122 | *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t, |
| 123 | const size_t,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 124 | |
| 125 | #if defined(__cplusplus) || defined(c_plusplus) |
| 126 | } |
| 127 | #endif |
| 128 | |
| 129 | /* |
| 130 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 131 | % % |
| 132 | % % |
| 133 | % % |
| 134 | + A c q u i r e S t r e a m I n f o % |
| 135 | % % |
| 136 | % % |
| 137 | % % |
| 138 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 139 | % |
| 140 | % AcquireStreamInfo() allocates the StreamInfo structure. |
| 141 | % |
| 142 | % The format of the AcquireStreamInfo method is: |
| 143 | % |
| 144 | % StreamInfo *AcquireStreamInfo(const ImageInfo *image_info) |
| 145 | % |
| 146 | % A description of each parameter follows: |
| 147 | % |
| 148 | % o image_info: the image info. |
| 149 | % |
| 150 | */ |
| 151 | MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info) |
| 152 | { |
| 153 | StreamInfo |
| 154 | *stream_info; |
| 155 | |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 156 | stream_info=(StreamInfo *) AcquireMagickMemory(sizeof(*stream_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 157 | if (stream_info == (StreamInfo *) NULL) |
| 158 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 159 | (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info)); |
| 160 | stream_info->pixels=(unsigned char *) AcquireMagickMemory( |
| 161 | sizeof(*stream_info->pixels)); |
| 162 | if (stream_info->pixels == (unsigned char *) NULL) |
| 163 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 164 | stream_info->map=ConstantString("RGB"); |
| 165 | stream_info->storage_type=CharPixel; |
| 166 | stream_info->stream=AcquireImage(image_info); |
| 167 | stream_info->signature=MagickSignature; |
| 168 | return(stream_info); |
| 169 | } |
| 170 | |
| 171 | /* |
| 172 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 173 | % % |
| 174 | % % |
| 175 | % % |
| 176 | + D e s t r o y P i x e l S t r e a m % |
| 177 | % % |
| 178 | % % |
| 179 | % % |
| 180 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 181 | % |
| 182 | % DestroyPixelStream() deallocates memory associated with the pixel stream. |
| 183 | % |
| 184 | % The format of the DestroyPixelStream() method is: |
| 185 | % |
| 186 | % void DestroyPixelStream(Image *image) |
| 187 | % |
| 188 | % A description of each parameter follows: |
| 189 | % |
| 190 | % o image: the image. |
| 191 | % |
| 192 | */ |
| 193 | |
| 194 | static inline void RelinquishStreamPixels(CacheInfo *cache_info) |
| 195 | { |
| 196 | assert(cache_info != (CacheInfo *) NULL); |
| 197 | if (cache_info->mapped == MagickFalse) |
| 198 | (void) RelinquishMagickMemory(cache_info->pixels); |
| 199 | else |
| 200 | (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 201 | cache_info->pixels=(Quantum *) NULL; |
| 202 | cache_info->metacontent=(void *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 203 | cache_info->length=0; |
| 204 | cache_info->mapped=MagickFalse; |
| 205 | } |
| 206 | |
| 207 | static void DestroyPixelStream(Image *image) |
| 208 | { |
| 209 | CacheInfo |
| 210 | *cache_info; |
| 211 | |
| 212 | MagickBooleanType |
| 213 | destroy; |
| 214 | |
| 215 | assert(image != (Image *) NULL); |
| 216 | assert(image->signature == MagickSignature); |
| 217 | if (image->debug != MagickFalse) |
| 218 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 219 | cache_info=(CacheInfo *) image->cache; |
| 220 | assert(cache_info->signature == MagickSignature); |
| 221 | destroy=MagickFalse; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 222 | LockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 223 | cache_info->reference_count--; |
| 224 | if (cache_info->reference_count == 0) |
| 225 | destroy=MagickTrue; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 226 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 227 | if (destroy == MagickFalse) |
| 228 | return; |
| 229 | RelinquishStreamPixels(cache_info); |
| 230 | if (cache_info->nexus_info != (NexusInfo **) NULL) |
| 231 | cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info, |
| 232 | cache_info->number_threads); |
| 233 | if (cache_info->disk_semaphore != (SemaphoreInfo *) NULL) |
| 234 | DestroySemaphoreInfo(&cache_info->disk_semaphore); |
| 235 | if (cache_info->semaphore != (SemaphoreInfo *) NULL) |
| 236 | DestroySemaphoreInfo(&cache_info->semaphore); |
| 237 | cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info); |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 242 | % % |
| 243 | % % |
| 244 | % % |
| 245 | + D e s t r o y S t r e a m I n f o % |
| 246 | % % |
| 247 | % % |
| 248 | % % |
| 249 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 250 | % |
| 251 | % DestroyStreamInfo() destroys memory associated with the StreamInfo |
| 252 | % structure. |
| 253 | % |
| 254 | % The format of the DestroyStreamInfo method is: |
| 255 | % |
| 256 | % StreamInfo *DestroyStreamInfo(StreamInfo *stream_info) |
| 257 | % |
| 258 | % A description of each parameter follows: |
| 259 | % |
| 260 | % o stream_info: the stream info. |
| 261 | % |
| 262 | */ |
| 263 | MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info) |
| 264 | { |
| 265 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 266 | assert(stream_info != (StreamInfo *) NULL); |
| 267 | assert(stream_info->signature == MagickSignature); |
| 268 | if (stream_info->map != (char *) NULL) |
| 269 | stream_info->map=DestroyString(stream_info->map); |
| 270 | if (stream_info->pixels != (unsigned char *) NULL) |
| 271 | stream_info->pixels=(unsigned char *) RelinquishMagickMemory( |
| 272 | stream_info->pixels); |
| 273 | if (stream_info->stream != (Image *) NULL) |
| 274 | { |
| 275 | (void) CloseBlob(stream_info->stream); |
| 276 | stream_info->stream=DestroyImage(stream_info->stream); |
| 277 | } |
| 278 | if (stream_info->quantum_info != (QuantumInfo *) NULL) |
| 279 | stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info); |
| 280 | stream_info->signature=(~MagickSignature); |
| 281 | stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info); |
| 282 | return(stream_info); |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 287 | % % |
| 288 | % % |
| 289 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 290 | + G e t A u t h e n t i c M e t a c o n t e n t F r o m S t r e a m % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 291 | % % |
| 292 | % % |
| 293 | % % |
| 294 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 295 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 296 | % GetAuthenticMetacontentFromStream() returns the metacontent corresponding |
| 297 | % with the last call to QueueAuthenticPixelsStream() or |
| 298 | % GetAuthenticPixelsStream(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 299 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 300 | % The format of the GetAuthenticMetacontentFromStream() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 301 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 302 | % void *GetAuthenticMetacontentFromStream(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 303 | % |
| 304 | % A description of each parameter follows: |
| 305 | % |
| 306 | % o image: the image. |
| 307 | % |
| 308 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 309 | static void *GetAuthenticMetacontentFromStream(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 310 | { |
| 311 | CacheInfo |
| 312 | *cache_info; |
| 313 | |
| 314 | assert(image != (Image *) NULL); |
| 315 | assert(image->signature == MagickSignature); |
| 316 | if (image->debug != MagickFalse) |
| 317 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 318 | cache_info=(CacheInfo *) image->cache; |
| 319 | assert(cache_info->signature == MagickSignature); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 320 | return(cache_info->metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /* |
| 324 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 325 | % % |
| 326 | % % |
| 327 | % % |
| 328 | + G e t A u t h e n t i c P i x e l S t r e a m % |
| 329 | % % |
| 330 | % % |
| 331 | % % |
| 332 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 333 | % |
| 334 | % GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel |
| 335 | % cache as defined by the geometry parameters. A pointer to the pixels is |
| 336 | % returned if the pixels are transferred, otherwise a NULL is returned. For |
| 337 | % streams this method is a no-op. |
| 338 | % |
| 339 | % The format of the GetAuthenticPixelsStream() method is: |
| 340 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 341 | % Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 342 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 343 | % ExceptionInfo *exception) |
| 344 | % |
| 345 | % A description of each parameter follows: |
| 346 | % |
| 347 | % o image: the image. |
| 348 | % |
| 349 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 350 | % pixels. |
| 351 | % |
| 352 | % o exception: return any errors or warnings in this structure. |
| 353 | % |
| 354 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 355 | static Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 356 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 357 | ExceptionInfo *exception) |
| 358 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 359 | Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 360 | *pixels; |
| 361 | |
| 362 | assert(image != (Image *) NULL); |
| 363 | assert(image->signature == MagickSignature); |
| 364 | if (image->debug != MagickFalse) |
| 365 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 366 | pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception); |
| 367 | return(pixels); |
| 368 | } |
| 369 | |
| 370 | /* |
| 371 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 372 | % % |
| 373 | % % |
| 374 | % % |
| 375 | + G e t A u t h e n t i c P i x e l F r o m S t e a m % |
| 376 | % % |
| 377 | % % |
| 378 | % % |
| 379 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 380 | % |
| 381 | % GetAuthenticPixelsFromStream() returns the pixels associated with the last |
| 382 | % call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream(). |
| 383 | % |
| 384 | % The format of the GetAuthenticPixelsFromStream() method is: |
| 385 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 386 | % Quantum *GetAuthenticPixelsFromStream(const Image image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 387 | % |
| 388 | % A description of each parameter follows: |
| 389 | % |
| 390 | % o image: the image. |
| 391 | % |
| 392 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 393 | static Quantum *GetAuthenticPixelsFromStream(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 394 | { |
| 395 | CacheInfo |
| 396 | *cache_info; |
| 397 | |
| 398 | assert(image != (Image *) NULL); |
| 399 | assert(image->signature == MagickSignature); |
| 400 | if (image->debug != MagickFalse) |
| 401 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 402 | cache_info=(CacheInfo *) image->cache; |
| 403 | assert(cache_info->signature == MagickSignature); |
| 404 | return(cache_info->pixels); |
| 405 | } |
| 406 | |
| 407 | /* |
| 408 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 409 | % % |
| 410 | % % |
| 411 | % % |
| 412 | + G e t O n e A u t h e n t i c P i x e l F r o m S t r e a m % |
| 413 | % % |
| 414 | % % |
| 415 | % % |
| 416 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 417 | % |
| 418 | % GetOneAuthenticPixelFromStream() returns a single pixel at the specified |
| 419 | % (x,y) location. The image background color is returned if an error occurs. |
| 420 | % |
| 421 | % The format of the GetOneAuthenticPixelFromStream() method is: |
| 422 | % |
| 423 | % MagickBooleanType GetOneAuthenticPixelFromStream(const Image image, |
cristy | cfae90a | 2010-10-04 14:43:33 +0000 | [diff] [blame] | 424 | % const ssize_t x,const ssize_t y,PixelPacket *pixel, |
| 425 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 426 | % |
| 427 | % A description of each parameter follows: |
| 428 | % |
| 429 | % o image: the image. |
| 430 | % |
| 431 | % o pixel: return a pixel at the specified (x,y) location. |
| 432 | % |
| 433 | % o x,y: These values define the location of the pixel to return. |
| 434 | % |
| 435 | % o exception: return any errors or warnings in this structure. |
| 436 | % |
| 437 | */ |
| 438 | static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 439 | const ssize_t x,const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 440 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 441 | register Quantum |
| 442 | *q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 443 | |
| 444 | assert(image != (Image *) NULL); |
| 445 | assert(image->signature == MagickSignature); |
| 446 | *pixel=image->background_color; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 447 | q=GetAuthenticPixelsStream(image,x,y,1,1,exception); |
| 448 | if (q != (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 449 | return(MagickFalse); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 450 | GetPixelPacket(image,q,pixel); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 451 | return(MagickTrue); |
| 452 | } |
| 453 | |
| 454 | /* |
| 455 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 456 | % % |
| 457 | % % |
| 458 | % % |
| 459 | + G e t O n e V i r t u a l P i x e l F r o m S t r e a m % |
| 460 | % % |
| 461 | % % |
| 462 | % % |
| 463 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 464 | % |
| 465 | % GetOneVirtualPixelFromStream() returns a single pixel at the specified |
| 466 | % (x.y) location. The image background color is returned if an error occurs. |
| 467 | % |
| 468 | % The format of the GetOneVirtualPixelFromStream() method is: |
| 469 | % |
| 470 | % MagickBooleanType GetOneVirtualPixelFromStream(const Image image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 471 | % const VirtualPixelMethod virtual_pixel_method,const ssize_t x, |
| 472 | % const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 473 | % |
| 474 | % A description of each parameter follows: |
| 475 | % |
| 476 | % o image: the image. |
| 477 | % |
| 478 | % o virtual_pixel_method: the virtual pixel method. |
| 479 | % |
| 480 | % o x,y: These values define the location of the pixel to return. |
| 481 | % |
| 482 | % o pixel: return a pixel at the specified (x,y) location. |
| 483 | % |
| 484 | % o exception: return any errors or warnings in this structure. |
| 485 | % |
| 486 | */ |
| 487 | static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 488 | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 489 | PixelPacket *pixel,ExceptionInfo *exception) |
| 490 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 491 | const Quantum |
| 492 | *q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 493 | |
| 494 | assert(image != (Image *) NULL); |
| 495 | assert(image->signature == MagickSignature); |
| 496 | *pixel=image->background_color; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 497 | q=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception); |
| 498 | if (q != (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 499 | return(MagickFalse); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 500 | GetPixelPacket(image,q,pixel); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 501 | return(MagickTrue); |
| 502 | } |
| 503 | |
| 504 | /* |
| 505 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 506 | % % |
| 507 | % % |
| 508 | % % |
| 509 | + G e t S t r e a m I n f o C l i e n t D a t a % |
| 510 | % % |
| 511 | % % |
| 512 | % % |
| 513 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 514 | % |
| 515 | % GetStreamInfoClientData() gets the stream info client data. |
| 516 | % |
| 517 | % The format of the SetStreamInfoClientData method is: |
| 518 | % |
| 519 | % const void *GetStreamInfoClientData(StreamInfo *stream_info) |
| 520 | % |
| 521 | % A description of each parameter follows: |
| 522 | % |
| 523 | % o stream_info: the stream info. |
| 524 | % |
| 525 | */ |
| 526 | MagickExport const void *GetStreamInfoClientData(StreamInfo *stream_info) |
| 527 | { |
| 528 | assert(stream_info != (StreamInfo *) NULL); |
| 529 | assert(stream_info->signature == MagickSignature); |
| 530 | return(stream_info->client_data); |
| 531 | } |
| 532 | |
| 533 | /* |
| 534 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 535 | % % |
| 536 | % % |
| 537 | % % |
| 538 | + G e t V i r t u a l P i x e l s F r o m S t r e a m % |
| 539 | % % |
| 540 | % % |
| 541 | % % |
| 542 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 543 | % |
| 544 | % GetVirtualPixelsStream() returns the pixels associated with the last |
| 545 | % call to QueueAuthenticPixelsStream() or GetVirtualPixelStream(). |
| 546 | % |
| 547 | % The format of the GetVirtualPixelsStream() method is: |
| 548 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 549 | % const Quantum *GetVirtualPixelsStream(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 550 | % |
| 551 | % A description of each parameter follows: |
| 552 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 553 | % o pixels: return the pixels associated corresponding with the last call to |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 554 | % QueueAuthenticPixelsStream() or GetVirtualPixelStream(). |
| 555 | % |
| 556 | % o image: the image. |
| 557 | % |
| 558 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 559 | static const Quantum *GetVirtualPixelsStream(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 560 | { |
| 561 | CacheInfo |
| 562 | *cache_info; |
| 563 | |
| 564 | assert(image != (Image *) NULL); |
| 565 | assert(image->signature == MagickSignature); |
| 566 | if (image->debug != MagickFalse) |
| 567 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 568 | cache_info=(CacheInfo *) image->cache; |
| 569 | assert(cache_info->signature == MagickSignature); |
| 570 | return(cache_info->pixels); |
| 571 | } |
| 572 | |
| 573 | /* |
| 574 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 575 | % % |
| 576 | % % |
| 577 | % % |
| 578 | + G e t V i r t u a l I n d e x e s F r o m S t r e a m % |
| 579 | % % |
| 580 | % % |
| 581 | % % |
| 582 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 583 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 584 | % GetVirtualMetacontentFromStream() returns the associated pixel |
| 585 | % channels corresponding with the last call to QueueAuthenticPixelsStream() or |
| 586 | % GetVirtualPixelStream(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 587 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 588 | % The format of the GetVirtualMetacontentFromStream() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 589 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 590 | % const void *GetVirtualMetacontentFromStream(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 591 | % |
| 592 | % A description of each parameter follows: |
| 593 | % |
| 594 | % o image: the image. |
| 595 | % |
| 596 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 597 | static const void *GetVirtualMetacontentFromStream( |
| 598 | const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 599 | { |
| 600 | CacheInfo |
| 601 | *cache_info; |
| 602 | |
| 603 | assert(image != (Image *) NULL); |
| 604 | assert(image->signature == MagickSignature); |
| 605 | if (image->debug != MagickFalse) |
| 606 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 607 | cache_info=(CacheInfo *) image->cache; |
| 608 | assert(cache_info->signature == MagickSignature); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 609 | return(cache_info->metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /* |
| 613 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 614 | % % |
| 615 | % % |
| 616 | % % |
| 617 | + G e t V i r t u a l P i x e l S t r e a m % |
| 618 | % % |
| 619 | % % |
| 620 | % % |
| 621 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 622 | % |
| 623 | % GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as |
| 624 | % defined by the geometry parameters. A pointer to the pixels is returned if |
| 625 | % the pixels are transferred, otherwise a NULL is returned. For streams this |
| 626 | % method is a no-op. |
| 627 | % |
| 628 | % The format of the GetVirtualPixelStream() method is: |
| 629 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 630 | % const Quantum *GetVirtualPixelStream(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 631 | % const VirtualPixelMethod virtual_pixel_method,const ssize_t x, |
| 632 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 633 | % ExceptionInfo *exception) |
| 634 | % |
| 635 | % A description of each parameter follows: |
| 636 | % |
| 637 | % o image: the image. |
| 638 | % |
| 639 | % o virtual_pixel_method: the virtual pixel method. |
| 640 | % |
| 641 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 642 | % pixels. |
| 643 | % |
| 644 | % o exception: return any errors or warnings in this structure. |
| 645 | % |
| 646 | */ |
| 647 | |
| 648 | static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info, |
| 649 | ExceptionInfo *exception) |
| 650 | { |
| 651 | if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length)) |
| 652 | return(MagickFalse); |
| 653 | cache_info->mapped=MagickFalse; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 654 | cache_info->pixels=(Quantum *) AcquireMagickMemory((size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 655 | cache_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 656 | if (cache_info->pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 657 | { |
| 658 | cache_info->mapped=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 659 | cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 660 | cache_info->length); |
| 661 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 662 | if (cache_info->pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 663 | { |
| 664 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 665 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 666 | cache_info->filename); |
| 667 | return(MagickFalse); |
| 668 | } |
| 669 | return(MagickTrue); |
| 670 | } |
| 671 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 672 | static const Quantum *GetVirtualPixelStream(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 673 | const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x, |
| 674 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 675 | ExceptionInfo *exception) |
| 676 | { |
| 677 | CacheInfo |
| 678 | *cache_info; |
| 679 | |
| 680 | MagickBooleanType |
| 681 | status; |
| 682 | |
| 683 | MagickSizeType |
| 684 | number_pixels; |
| 685 | |
| 686 | size_t |
| 687 | length; |
| 688 | |
| 689 | /* |
| 690 | Validate pixel cache geometry. |
| 691 | */ |
| 692 | assert(image != (const Image *) NULL); |
| 693 | assert(image->signature == MagickSignature); |
| 694 | if (image->debug != MagickFalse) |
| 695 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 5dd7188 | 2010-08-01 20:53:13 +0000 | [diff] [blame] | 696 | if ((x < 0) || (y < 0) || |
| 697 | ((x+(ssize_t) columns) > (ssize_t) image->columns) || |
| 698 | ((y+(ssize_t) rows) > (ssize_t) image->rows) || |
| 699 | (columns == 0) || (rows == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 700 | { |
| 701 | (void) ThrowMagickException(exception,GetMagickModule(),StreamError, |
| 702 | "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 703 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 704 | } |
| 705 | cache_info=(CacheInfo *) image->cache; |
| 706 | assert(cache_info->signature == MagickSignature); |
| 707 | /* |
| 708 | Pixels are stored in a temporary buffer until they are synced to the cache. |
| 709 | */ |
| 710 | number_pixels=(MagickSizeType) columns*rows; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame^] | 711 | length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 712 | if (cache_info->metacontent_extent != 0) |
| 713 | length+=number_pixels*cache_info->metacontent_extent; |
| 714 | if (cache_info->pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 715 | { |
| 716 | cache_info->length=length; |
| 717 | status=AcquireStreamPixels(cache_info,exception); |
| 718 | if (status == MagickFalse) |
cristy | 33503f5 | 2010-10-04 17:32:27 +0000 | [diff] [blame] | 719 | { |
| 720 | cache_info->length=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 721 | return((Quantum *) NULL); |
cristy | 33503f5 | 2010-10-04 17:32:27 +0000 | [diff] [blame] | 722 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 723 | } |
| 724 | else |
| 725 | if (cache_info->length != length) |
| 726 | { |
| 727 | RelinquishStreamPixels(cache_info); |
| 728 | cache_info->length=length; |
| 729 | status=AcquireStreamPixels(cache_info,exception); |
| 730 | if (status == MagickFalse) |
cristy | 33503f5 | 2010-10-04 17:32:27 +0000 | [diff] [blame] | 731 | { |
| 732 | cache_info->length=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 733 | return((Quantum *) NULL); |
cristy | 33503f5 | 2010-10-04 17:32:27 +0000 | [diff] [blame] | 734 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 735 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 736 | cache_info->metacontent=(void *) NULL; |
| 737 | if (cache_info->metacontent_extent != 0) |
| 738 | cache_info->metacontent=(void *) (cache_info->pixels+number_pixels* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame^] | 739 | cache_info->number_channels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 740 | return(cache_info->pixels); |
| 741 | } |
| 742 | |
| 743 | /* |
| 744 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 745 | % % |
| 746 | % % |
| 747 | % % |
| 748 | + O p e n S t r e a m % |
| 749 | % % |
| 750 | % % |
| 751 | % % |
| 752 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 753 | % |
| 754 | % OpenStream() opens a stream for writing by the StreamImage() method. |
| 755 | % |
| 756 | % The format of the OpenStream method is: |
| 757 | % |
| 758 | % MagickBooleanType OpenStream(const ImageInfo *image_info, |
| 759 | % StreamInfo *stream_info,const char *filename,ExceptionInfo *exception) |
| 760 | % |
| 761 | % A description of each parameter follows: |
| 762 | % |
| 763 | % o image_info: the image info. |
| 764 | % |
| 765 | % o stream_info: the stream info. |
| 766 | % |
| 767 | % o filename: the stream filename. |
| 768 | % |
| 769 | % o exception: return any errors or warnings in this structure. |
| 770 | % |
| 771 | */ |
| 772 | MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info, |
| 773 | StreamInfo *stream_info,const char *filename,ExceptionInfo *exception) |
| 774 | { |
| 775 | MagickBooleanType |
| 776 | status; |
| 777 | |
| 778 | (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent); |
| 779 | status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception); |
| 780 | return(status); |
| 781 | } |
| 782 | |
| 783 | /* |
| 784 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 785 | % % |
| 786 | % % |
| 787 | % % |
| 788 | + Q u e u e A u t h e n t i c P i x e l s S t r e a m % |
| 789 | % % |
| 790 | % % |
| 791 | % % |
| 792 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 793 | % |
| 794 | % QueueAuthenticPixelsStream() allocates an area to store image pixels as |
| 795 | % defined by the region rectangle and returns a pointer to the area. This |
| 796 | % area is subsequently transferred from the pixel cache with method |
| 797 | % SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the |
| 798 | % pixels are transferred, otherwise a NULL is returned. |
| 799 | % |
| 800 | % The format of the QueueAuthenticPixelsStream() method is: |
| 801 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 802 | % Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 803 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 804 | % ExceptionInfo *exception) |
| 805 | % |
| 806 | % A description of each parameter follows: |
| 807 | % |
| 808 | % o image: the image. |
| 809 | % |
| 810 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 811 | % pixels. |
| 812 | % |
| 813 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 814 | static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 815 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 816 | ExceptionInfo *exception) |
| 817 | { |
| 818 | CacheInfo |
| 819 | *cache_info; |
| 820 | |
| 821 | MagickSizeType |
| 822 | number_pixels; |
| 823 | |
| 824 | size_t |
| 825 | length; |
| 826 | |
| 827 | StreamHandler |
| 828 | stream_handler; |
| 829 | |
| 830 | /* |
| 831 | Validate pixel cache geometry. |
| 832 | */ |
| 833 | assert(image != (Image *) NULL); |
cristy | cfae90a | 2010-10-04 14:43:33 +0000 | [diff] [blame] | 834 | if ((x < 0) || (y < 0) || |
| 835 | ((x+(ssize_t) columns) > (ssize_t) image->columns) || |
| 836 | ((y+(ssize_t) rows) > (ssize_t) image->rows) || |
| 837 | (columns == 0) || (rows == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 838 | { |
| 839 | (void) ThrowMagickException(exception,GetMagickModule(),StreamError, |
| 840 | "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 841 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 842 | } |
| 843 | stream_handler=GetBlobStreamHandler(image); |
| 844 | if (stream_handler == (StreamHandler) NULL) |
| 845 | { |
| 846 | (void) ThrowMagickException(exception,GetMagickModule(),StreamError, |
| 847 | "NoStreamHandlerIsDefined","`%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 848 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 849 | } |
| 850 | cache_info=(CacheInfo *) image->cache; |
| 851 | assert(cache_info->signature == MagickSignature); |
| 852 | if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) || |
| 853 | (image->colorspace != GetPixelCacheColorspace(image->cache))) |
| 854 | { |
| 855 | if (GetPixelCacheStorageClass(image->cache) == UndefinedClass) |
| 856 | (void) stream_handler(image,(const void *) NULL,(size_t) |
| 857 | cache_info->columns); |
| 858 | cache_info->storage_class=image->storage_class; |
| 859 | cache_info->colorspace=image->colorspace; |
| 860 | cache_info->columns=image->columns; |
| 861 | cache_info->rows=image->rows; |
| 862 | image->cache=cache_info; |
| 863 | } |
| 864 | /* |
| 865 | Pixels are stored in a temporary buffer until they are synced to the cache. |
| 866 | */ |
| 867 | cache_info->columns=columns; |
| 868 | cache_info->rows=rows; |
| 869 | number_pixels=(MagickSizeType) columns*rows; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame^] | 870 | length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 871 | if (cache_info->metacontent_extent != 0) |
| 872 | length+=number_pixels*cache_info->metacontent_extent; |
| 873 | if (cache_info->pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 874 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 875 | cache_info->pixels=(Quantum *) AcquireMagickMemory(length); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 876 | cache_info->length=(MagickSizeType) length; |
| 877 | } |
| 878 | else |
| 879 | if (cache_info->length < (MagickSizeType) length) |
| 880 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 881 | cache_info->pixels=(Quantum *) ResizeMagickMemory( |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 882 | cache_info->pixels,length); |
| 883 | cache_info->length=(MagickSizeType) length; |
| 884 | } |
| 885 | if (cache_info->pixels == (void *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 886 | return((Quantum *) NULL); |
| 887 | cache_info->metacontent=(void *) NULL; |
| 888 | if (cache_info->metacontent_extent != 0) |
| 889 | cache_info->metacontent=(void *) (cache_info->pixels+number_pixels* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame^] | 890 | cache_info->number_channels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 891 | return(cache_info->pixels); |
| 892 | } |
| 893 | |
| 894 | /* |
| 895 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 896 | % % |
| 897 | % % |
| 898 | % % |
| 899 | % R e a d S t r e a m % |
| 900 | % % |
| 901 | % % |
| 902 | % % |
| 903 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 904 | % |
| 905 | % ReadStream() makes the image pixels available to a user supplied callback |
| 906 | % method immediately upon reading a scanline with the ReadImage() method. |
| 907 | % |
| 908 | % The format of the ReadStream() method is: |
| 909 | % |
| 910 | % Image *ReadStream(const ImageInfo *image_info,StreamHandler stream, |
| 911 | % ExceptionInfo *exception) |
| 912 | % |
| 913 | % A description of each parameter follows: |
| 914 | % |
| 915 | % o image_info: the image info. |
| 916 | % |
| 917 | % o stream: a callback method. |
| 918 | % |
| 919 | % o exception: return any errors or warnings in this structure. |
| 920 | % |
| 921 | */ |
| 922 | MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream, |
| 923 | ExceptionInfo *exception) |
| 924 | { |
| 925 | CacheMethods |
| 926 | cache_methods; |
| 927 | |
| 928 | Image |
| 929 | *image; |
| 930 | |
| 931 | ImageInfo |
| 932 | *read_info; |
| 933 | |
| 934 | /* |
| 935 | Stream image pixels. |
| 936 | */ |
| 937 | assert(image_info != (ImageInfo *) NULL); |
| 938 | assert(image_info->signature == MagickSignature); |
| 939 | if (image_info->debug != MagickFalse) |
| 940 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 941 | image_info->filename); |
| 942 | assert(exception != (ExceptionInfo *) NULL); |
| 943 | assert(exception->signature == MagickSignature); |
| 944 | read_info=CloneImageInfo(image_info); |
| 945 | read_info->cache=AcquirePixelCache(0); |
| 946 | GetPixelCacheMethods(&cache_methods); |
| 947 | cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 948 | cache_methods.get_virtual_metacontent_from_handler= |
| 949 | GetVirtualMetacontentFromStream; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 950 | cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream; |
| 951 | cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream; |
| 952 | cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream; |
| 953 | cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream; |
| 954 | cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 955 | cache_methods.get_authentic_metacontent_from_handler= |
| 956 | GetAuthenticMetacontentFromStream; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 957 | cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream; |
| 958 | cache_methods.get_one_authentic_pixel_from_handler= |
| 959 | GetOneAuthenticPixelFromStream; |
| 960 | cache_methods.destroy_pixel_handler=DestroyPixelStream; |
| 961 | SetPixelCacheMethods(read_info->cache,&cache_methods); |
| 962 | read_info->stream=stream; |
| 963 | image=ReadImage(read_info,exception); |
| 964 | read_info=DestroyImageInfo(read_info); |
| 965 | return(image); |
| 966 | } |
| 967 | |
| 968 | /* |
| 969 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 970 | % % |
| 971 | % % |
| 972 | % % |
| 973 | + S e t S t r e a m I n f o C l i e n t D a t a % |
| 974 | % % |
| 975 | % % |
| 976 | % % |
| 977 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 978 | % |
| 979 | % SetStreamInfoClientData() sets the stream info client data. |
| 980 | % |
| 981 | % The format of the SetStreamInfoClientData method is: |
| 982 | % |
| 983 | % void SetStreamInfoClientData(StreamInfo *stream_info, |
| 984 | % const void *client_data) |
| 985 | % |
| 986 | % A description of each parameter follows: |
| 987 | % |
| 988 | % o stream_info: the stream info. |
| 989 | % |
| 990 | % o client_data: the client data. |
| 991 | % |
| 992 | */ |
| 993 | MagickExport void SetStreamInfoClientData(StreamInfo *stream_info, |
| 994 | const void *client_data) |
| 995 | { |
| 996 | assert(stream_info != (StreamInfo *) NULL); |
| 997 | assert(stream_info->signature == MagickSignature); |
| 998 | stream_info->client_data=client_data; |
| 999 | } |
| 1000 | |
| 1001 | /* |
| 1002 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1003 | % % |
| 1004 | % % |
| 1005 | % % |
| 1006 | + S e t S t r e a m I n f o M a p % |
| 1007 | % % |
| 1008 | % % |
| 1009 | % % |
| 1010 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1011 | % |
| 1012 | % SetStreamInfoMap() sets the stream info map member. |
| 1013 | % |
| 1014 | % The format of the SetStreamInfoMap method is: |
| 1015 | % |
| 1016 | % void SetStreamInfoMap(StreamInfo *stream_info,const char *map) |
| 1017 | % |
| 1018 | % A description of each parameter follows: |
| 1019 | % |
| 1020 | % o stream_info: the stream info. |
| 1021 | % |
| 1022 | % o map: the map. |
| 1023 | % |
| 1024 | */ |
| 1025 | MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map) |
| 1026 | { |
| 1027 | assert(stream_info != (StreamInfo *) NULL); |
| 1028 | assert(stream_info->signature == MagickSignature); |
| 1029 | (void) CloneString(&stream_info->map,map); |
| 1030 | } |
| 1031 | |
| 1032 | /* |
| 1033 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1034 | % % |
| 1035 | % % |
| 1036 | % % |
| 1037 | + S e t S t r e a m I n f o S t o r a g e T y p e % |
| 1038 | % % |
| 1039 | % % |
| 1040 | % % |
| 1041 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1042 | % |
| 1043 | % SetStreamInfoStorageType() sets the stream info storage type member. |
| 1044 | % |
| 1045 | % The format of the SetStreamInfoStorageType method is: |
| 1046 | % |
| 1047 | % void SetStreamInfoStorageType(StreamInfo *stream_info, |
| 1048 | % const StoreageType *storage_type) |
| 1049 | % |
| 1050 | % A description of each parameter follows: |
| 1051 | % |
| 1052 | % o stream_info: the stream info. |
| 1053 | % |
| 1054 | % o storage_type: the storage type. |
| 1055 | % |
| 1056 | */ |
| 1057 | MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info, |
| 1058 | const StorageType storage_type) |
| 1059 | { |
| 1060 | assert(stream_info != (StreamInfo *) NULL); |
| 1061 | assert(stream_info->signature == MagickSignature); |
| 1062 | stream_info->storage_type=storage_type; |
| 1063 | } |
| 1064 | |
| 1065 | /* |
| 1066 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1067 | % % |
| 1068 | % % |
| 1069 | % % |
| 1070 | + S t r e a m I m a g e % |
| 1071 | % % |
| 1072 | % % |
| 1073 | % % |
| 1074 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1075 | % |
| 1076 | % StreamImage() streams pixels from an image and writes them in a user |
| 1077 | % defined format and storage type (e.g. RGBA as 8-bit unsigned char). |
| 1078 | % |
cristy | d212bd0 | 2011-02-13 17:08:57 +0000 | [diff] [blame] | 1079 | % The format of the StreamImage() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1080 | % |
| 1081 | % Image *StreamImage(const ImageInfo *image_info, |
| 1082 | % StreamInfo *stream_info,ExceptionInfo *exception) |
| 1083 | % |
| 1084 | % A description of each parameter follows: |
| 1085 | % |
| 1086 | % o image_info: the image info. |
| 1087 | % |
| 1088 | % o stream_info: the stream info. |
| 1089 | % |
| 1090 | % o exception: return any errors or warnings in this structure. |
| 1091 | % |
| 1092 | */ |
| 1093 | |
| 1094 | #if defined(__cplusplus) || defined(c_plusplus) |
| 1095 | extern "C" { |
| 1096 | #endif |
| 1097 | |
| 1098 | static size_t WriteStreamImage(const Image *image,const void *pixels, |
| 1099 | const size_t columns) |
| 1100 | { |
cristy | e3664f4 | 2010-05-14 00:59:57 +0000 | [diff] [blame] | 1101 | CacheInfo |
| 1102 | *cache_info; |
| 1103 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1104 | RectangleInfo |
| 1105 | extract_info; |
| 1106 | |
| 1107 | size_t |
| 1108 | length, |
| 1109 | packet_size; |
| 1110 | |
| 1111 | ssize_t |
| 1112 | count; |
| 1113 | |
| 1114 | StreamInfo |
| 1115 | *stream_info; |
| 1116 | |
cristy | 654fdaf | 2011-02-24 15:24:33 +0000 | [diff] [blame] | 1117 | (void) pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1118 | stream_info=(StreamInfo *) image->client_data; |
| 1119 | switch (stream_info->storage_type) |
| 1120 | { |
| 1121 | default: packet_size=sizeof(char); break; |
| 1122 | case CharPixel: packet_size=sizeof(char); break; |
| 1123 | case DoublePixel: packet_size=sizeof(double); break; |
| 1124 | case FloatPixel: packet_size=sizeof(float); break; |
| 1125 | case IntegerPixel: packet_size=sizeof(int); break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1126 | case LongPixel: packet_size=sizeof(ssize_t); break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1127 | case QuantumPixel: packet_size=sizeof(Quantum); break; |
| 1128 | case ShortPixel: packet_size=sizeof(unsigned short); break; |
| 1129 | } |
cristy | e3664f4 | 2010-05-14 00:59:57 +0000 | [diff] [blame] | 1130 | cache_info=(CacheInfo *) image->cache; |
| 1131 | assert(cache_info->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1132 | packet_size*=strlen(stream_info->map); |
cristy | e3664f4 | 2010-05-14 00:59:57 +0000 | [diff] [blame] | 1133 | length=packet_size*cache_info->columns*cache_info->rows; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1134 | if (image != stream_info->image) |
| 1135 | { |
| 1136 | ImageInfo |
| 1137 | *write_info; |
| 1138 | |
| 1139 | /* |
| 1140 | Prepare stream for writing. |
| 1141 | */ |
| 1142 | stream_info->pixels=(unsigned char *) ResizeQuantumMemory( |
| 1143 | stream_info->pixels,length,sizeof(*stream_info->pixels)); |
cristy | 5dd7188 | 2010-08-01 20:53:13 +0000 | [diff] [blame] | 1144 | if (stream_info->pixels == (unsigned char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1145 | return(0); |
| 1146 | stream_info->image=image; |
| 1147 | write_info=CloneImageInfo(stream_info->image_info); |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 1148 | (void) SetImageInfo(write_info,1,stream_info->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1149 | if (write_info->extract != (char *) NULL) |
| 1150 | (void) ParseAbsoluteGeometry(write_info->extract, |
| 1151 | &stream_info->extract_info); |
| 1152 | stream_info->y=0; |
| 1153 | write_info=DestroyImageInfo(write_info); |
| 1154 | } |
| 1155 | extract_info=stream_info->extract_info; |
cristy | d212bd0 | 2011-02-13 17:08:57 +0000 | [diff] [blame] | 1156 | if ((extract_info.width == 0) || (extract_info.height == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1157 | { |
| 1158 | /* |
| 1159 | Write all pixels to stream. |
| 1160 | */ |
| 1161 | (void) StreamImagePixels(stream_info,image,stream_info->exception); |
| 1162 | count=WriteBlob(stream_info->stream,length,stream_info->pixels); |
| 1163 | stream_info->y++; |
| 1164 | return(count == 0 ? 0 : columns); |
| 1165 | } |
| 1166 | if ((stream_info->y < extract_info.y) || |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1167 | (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1168 | { |
| 1169 | stream_info->y++; |
| 1170 | return(columns); |
| 1171 | } |
| 1172 | /* |
| 1173 | Write a portion of the pixel row to the stream. |
| 1174 | */ |
| 1175 | (void) StreamImagePixels(stream_info,image,stream_info->exception); |
| 1176 | length=packet_size*extract_info.width; |
cristy | 5dd7188 | 2010-08-01 20:53:13 +0000 | [diff] [blame] | 1177 | count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size* |
| 1178 | extract_info.x); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1179 | stream_info->y++; |
| 1180 | return(count == 0 ? 0 : columns); |
| 1181 | } |
| 1182 | |
| 1183 | #if defined(__cplusplus) || defined(c_plusplus) |
| 1184 | } |
| 1185 | #endif |
| 1186 | |
| 1187 | MagickExport Image *StreamImage(const ImageInfo *image_info, |
| 1188 | StreamInfo *stream_info,ExceptionInfo *exception) |
| 1189 | { |
| 1190 | Image |
| 1191 | *image; |
| 1192 | |
| 1193 | ImageInfo |
| 1194 | *read_info; |
| 1195 | |
| 1196 | assert(image_info != (const ImageInfo *) NULL); |
| 1197 | assert(image_info->signature == MagickSignature); |
| 1198 | if (image_info->debug != MagickFalse) |
| 1199 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 1200 | image_info->filename); |
| 1201 | assert(stream_info != (StreamInfo *) NULL); |
| 1202 | assert(stream_info->signature == MagickSignature); |
| 1203 | assert(exception != (ExceptionInfo *) NULL); |
| 1204 | read_info=CloneImageInfo(image_info); |
| 1205 | stream_info->image_info=image_info; |
| 1206 | stream_info->exception=exception; |
| 1207 | read_info->client_data=(void *) stream_info; |
| 1208 | image=ReadStream(read_info,&WriteStreamImage,exception); |
| 1209 | read_info=DestroyImageInfo(read_info); |
| 1210 | stream_info->quantum_info=AcquireQuantumInfo(image_info,image); |
| 1211 | if (stream_info->quantum_info == (QuantumInfo *) NULL) |
| 1212 | image=DestroyImage(image); |
| 1213 | return(image); |
| 1214 | } |
| 1215 | |
| 1216 | /* |
| 1217 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1218 | % % |
| 1219 | % % |
| 1220 | % % |
| 1221 | + S t r e a m I m a g e P i x e l s % |
| 1222 | % % |
| 1223 | % % |
| 1224 | % % |
| 1225 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1226 | % |
| 1227 | % StreamImagePixels() extracts pixel data from an image and returns it in the |
| 1228 | % stream_info->pixels structure in the format as defined by |
| 1229 | % stream_info->quantum_info->map and stream_info->quantum_info->storage_type. |
| 1230 | % |
| 1231 | % The format of the StreamImagePixels method is: |
| 1232 | % |
| 1233 | % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, |
| 1234 | % const Image *image,ExceptionInfo *exception) |
| 1235 | % |
| 1236 | % A description of each parameter follows: |
| 1237 | % |
| 1238 | % o stream_info: the stream info. |
| 1239 | % |
| 1240 | % o image: the image. |
| 1241 | % |
| 1242 | % o exception: return any errors or warnings in this structure. |
| 1243 | % |
| 1244 | */ |
| 1245 | static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, |
| 1246 | const Image *image,ExceptionInfo *exception) |
| 1247 | { |
| 1248 | QuantumInfo |
| 1249 | *quantum_info; |
| 1250 | |
| 1251 | QuantumType |
| 1252 | *quantum_map; |
| 1253 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1254 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1255 | *p; |
| 1256 | |
cristy | d212bd0 | 2011-02-13 17:08:57 +0000 | [diff] [blame] | 1257 | register ssize_t |
| 1258 | i, |
| 1259 | x; |
| 1260 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1261 | size_t |
| 1262 | length; |
| 1263 | |
| 1264 | assert(stream_info != (StreamInfo *) NULL); |
| 1265 | assert(stream_info->signature == MagickSignature); |
| 1266 | assert(image != (Image *) NULL); |
| 1267 | assert(image->signature == MagickSignature); |
| 1268 | if (image->debug != MagickFalse) |
| 1269 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1270 | length=strlen(stream_info->map); |
| 1271 | quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map)); |
| 1272 | if (quantum_map == (QuantumType *) NULL) |
| 1273 | { |
| 1274 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 1275 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
| 1276 | return(MagickFalse); |
| 1277 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1278 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1279 | { |
| 1280 | switch (stream_info->map[i]) |
| 1281 | { |
| 1282 | case 'A': |
| 1283 | case 'a': |
| 1284 | { |
| 1285 | quantum_map[i]=AlphaQuantum; |
| 1286 | break; |
| 1287 | } |
| 1288 | case 'B': |
| 1289 | case 'b': |
| 1290 | { |
| 1291 | quantum_map[i]=BlueQuantum; |
| 1292 | break; |
| 1293 | } |
| 1294 | case 'C': |
| 1295 | case 'c': |
| 1296 | { |
| 1297 | quantum_map[i]=CyanQuantum; |
| 1298 | if (image->colorspace == CMYKColorspace) |
| 1299 | break; |
| 1300 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1301 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
| 1302 | "ColorSeparatedImageRequired","`%s'",stream_info->map); |
| 1303 | return(MagickFalse); |
| 1304 | } |
| 1305 | case 'g': |
| 1306 | case 'G': |
| 1307 | { |
| 1308 | quantum_map[i]=GreenQuantum; |
| 1309 | break; |
| 1310 | } |
| 1311 | case 'I': |
| 1312 | case 'i': |
| 1313 | { |
| 1314 | quantum_map[i]=IndexQuantum; |
| 1315 | break; |
| 1316 | } |
| 1317 | case 'K': |
| 1318 | case 'k': |
| 1319 | { |
| 1320 | quantum_map[i]=BlackQuantum; |
| 1321 | if (image->colorspace == CMYKColorspace) |
| 1322 | break; |
| 1323 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1324 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
| 1325 | "ColorSeparatedImageRequired","`%s'",stream_info->map); |
| 1326 | return(MagickFalse); |
| 1327 | } |
| 1328 | case 'M': |
| 1329 | case 'm': |
| 1330 | { |
| 1331 | quantum_map[i]=MagentaQuantum; |
| 1332 | if (image->colorspace == CMYKColorspace) |
| 1333 | break; |
| 1334 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1335 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
| 1336 | "ColorSeparatedImageRequired","`%s'",stream_info->map); |
| 1337 | return(MagickFalse); |
| 1338 | } |
| 1339 | case 'o': |
| 1340 | case 'O': |
| 1341 | { |
| 1342 | quantum_map[i]=OpacityQuantum; |
| 1343 | break; |
| 1344 | } |
| 1345 | case 'P': |
| 1346 | case 'p': |
| 1347 | { |
| 1348 | quantum_map[i]=UndefinedQuantum; |
| 1349 | break; |
| 1350 | } |
| 1351 | case 'R': |
| 1352 | case 'r': |
| 1353 | { |
| 1354 | quantum_map[i]=RedQuantum; |
| 1355 | break; |
| 1356 | } |
| 1357 | case 'Y': |
| 1358 | case 'y': |
| 1359 | { |
| 1360 | quantum_map[i]=YellowQuantum; |
| 1361 | if (image->colorspace == CMYKColorspace) |
| 1362 | break; |
| 1363 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1364 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
| 1365 | "ColorSeparatedImageRequired","`%s'",stream_info->map); |
| 1366 | return(MagickFalse); |
| 1367 | } |
| 1368 | default: |
| 1369 | { |
| 1370 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1371 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 1372 | "UnrecognizedPixelMap","`%s'",stream_info->map); |
| 1373 | return(MagickFalse); |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | quantum_info=stream_info->quantum_info; |
| 1378 | switch (stream_info->storage_type) |
| 1379 | { |
| 1380 | case CharPixel: |
| 1381 | { |
| 1382 | register unsigned char |
| 1383 | *q; |
| 1384 | |
| 1385 | q=(unsigned char *) stream_info->pixels; |
| 1386 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
| 1387 | { |
| 1388 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1389 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1390 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1391 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1392 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1393 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 1394 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 1395 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1396 | p++; |
| 1397 | } |
| 1398 | break; |
| 1399 | } |
| 1400 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
| 1401 | { |
| 1402 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1403 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1404 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1405 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1406 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1407 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 1408 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 1409 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 1410 | *q++=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1411 | p++; |
| 1412 | } |
| 1413 | break; |
| 1414 | } |
| 1415 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
| 1416 | { |
| 1417 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1418 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1419 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1420 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1421 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1422 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 1423 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 1424 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1425 | *q++=ScaleQuantumToChar((Quantum) 0); |
| 1426 | p++; |
| 1427 | } |
| 1428 | break; |
| 1429 | } |
| 1430 | if (LocaleCompare(stream_info->map,"I") == 0) |
| 1431 | { |
| 1432 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1433 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1434 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1435 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1436 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1437 | *q++=ScaleQuantumToChar(GetPixelIntensity(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1438 | p++; |
| 1439 | } |
| 1440 | break; |
| 1441 | } |
| 1442 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
| 1443 | { |
| 1444 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1445 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1446 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1447 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1448 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1449 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 1450 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 1451 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1452 | p++; |
| 1453 | } |
| 1454 | break; |
| 1455 | } |
| 1456 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
| 1457 | { |
| 1458 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1459 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1460 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1461 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1462 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1463 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 1464 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 1465 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 1466 | *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1467 | p++; |
| 1468 | } |
| 1469 | break; |
| 1470 | } |
| 1471 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
| 1472 | { |
| 1473 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1474 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1475 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1476 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1477 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1478 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 1479 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 1480 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1481 | *q++=ScaleQuantumToChar((Quantum) 0); |
| 1482 | p++; |
| 1483 | } |
| 1484 | break; |
| 1485 | } |
| 1486 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1487 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1488 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1489 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1490 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1491 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1492 | { |
| 1493 | *q=0; |
| 1494 | switch (quantum_map[i]) |
| 1495 | { |
| 1496 | case RedQuantum: |
| 1497 | case CyanQuantum: |
| 1498 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1499 | *q=ScaleQuantumToChar(GetPixelRed(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1500 | break; |
| 1501 | } |
| 1502 | case GreenQuantum: |
| 1503 | case MagentaQuantum: |
| 1504 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1505 | *q=ScaleQuantumToChar(GetPixelGreen(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1506 | break; |
| 1507 | } |
| 1508 | case BlueQuantum: |
| 1509 | case YellowQuantum: |
| 1510 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1511 | *q=ScaleQuantumToChar(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1512 | break; |
| 1513 | } |
| 1514 | case AlphaQuantum: |
| 1515 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1516 | *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1517 | break; |
| 1518 | } |
| 1519 | case OpacityQuantum: |
| 1520 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1521 | *q=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1522 | break; |
| 1523 | } |
| 1524 | case BlackQuantum: |
| 1525 | { |
| 1526 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1527 | *q=ScaleQuantumToChar(GetPixelBlack(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1528 | break; |
| 1529 | } |
| 1530 | case IndexQuantum: |
| 1531 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1532 | *q=ScaleQuantumToChar(GetPixelIntensity(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1533 | break; |
| 1534 | } |
| 1535 | default: |
| 1536 | break; |
| 1537 | } |
| 1538 | q++; |
| 1539 | } |
| 1540 | p++; |
| 1541 | } |
| 1542 | break; |
| 1543 | } |
| 1544 | case DoublePixel: |
| 1545 | { |
| 1546 | register double |
| 1547 | *q; |
| 1548 | |
| 1549 | q=(double *) stream_info->pixels; |
| 1550 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
| 1551 | { |
| 1552 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1553 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1554 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1555 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1556 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1557 | *q++=(double) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1558 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1559 | *q++=(double) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1560 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1561 | *q++=(double) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1562 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1563 | p++; |
| 1564 | } |
| 1565 | break; |
| 1566 | } |
| 1567 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
| 1568 | { |
| 1569 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1570 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1571 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1572 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1573 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1574 | *q++=(double) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1575 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1576 | *q++=(double) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1577 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1578 | *q++=(double) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1579 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1580 | *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1581 | quantum_info->scale+quantum_info->minimum); |
| 1582 | p++; |
| 1583 | } |
| 1584 | break; |
| 1585 | } |
| 1586 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
| 1587 | { |
| 1588 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1589 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1590 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1591 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1592 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1593 | *q++=(double) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1594 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1595 | *q++=(double) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1596 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1597 | *q++=(double) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1598 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1599 | *q++=0.0; |
| 1600 | p++; |
| 1601 | } |
| 1602 | break; |
| 1603 | } |
| 1604 | if (LocaleCompare(stream_info->map,"I") == 0) |
| 1605 | { |
| 1606 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1607 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1608 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1609 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1610 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1611 | *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1612 | quantum_info->scale+quantum_info->minimum); |
| 1613 | p++; |
| 1614 | } |
| 1615 | break; |
| 1616 | } |
| 1617 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
| 1618 | { |
| 1619 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1620 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1621 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1622 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1623 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1624 | *q++=(double) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1625 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1626 | *q++=(double) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1627 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1628 | *q++=(double) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1629 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1630 | p++; |
| 1631 | } |
| 1632 | break; |
| 1633 | } |
| 1634 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
| 1635 | { |
| 1636 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1637 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1638 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1639 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1640 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1641 | *q++=(double) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1642 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1643 | *q++=(double) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1644 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1645 | *q++=(double) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1646 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1647 | *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1648 | quantum_info->scale+quantum_info->minimum); |
| 1649 | p++; |
| 1650 | } |
| 1651 | break; |
| 1652 | } |
| 1653 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
| 1654 | { |
| 1655 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1656 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1657 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1658 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1659 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1660 | *q++=(double) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1661 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1662 | *q++=(double) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1663 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1664 | *q++=(double) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1665 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1666 | *q++=0.0; |
| 1667 | p++; |
| 1668 | } |
| 1669 | break; |
| 1670 | } |
| 1671 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1672 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1673 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1674 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1675 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1676 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1677 | { |
| 1678 | *q=0; |
| 1679 | switch (quantum_map[i]) |
| 1680 | { |
| 1681 | case RedQuantum: |
| 1682 | case CyanQuantum: |
| 1683 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1684 | *q=(double) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1685 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1686 | break; |
| 1687 | } |
| 1688 | case GreenQuantum: |
| 1689 | case MagentaQuantum: |
| 1690 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1691 | *q=(double) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1692 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1693 | break; |
| 1694 | } |
| 1695 | case BlueQuantum: |
| 1696 | case YellowQuantum: |
| 1697 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1698 | *q=(double) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1699 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1700 | break; |
| 1701 | } |
| 1702 | case AlphaQuantum: |
| 1703 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1704 | *q=(double) ((QuantumScale*GetPixelAlpha(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1705 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1706 | break; |
| 1707 | } |
| 1708 | case OpacityQuantum: |
| 1709 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1710 | *q=(double) ((QuantumScale*GetPixelAlpha(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1711 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1712 | break; |
| 1713 | } |
| 1714 | case BlackQuantum: |
| 1715 | { |
| 1716 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1717 | *q=(double) ((QuantumScale*GetPixelBlack(image,p))* |
cristy | fba5a8b | 2011-05-03 17:12:12 +0000 | [diff] [blame] | 1718 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1719 | break; |
| 1720 | } |
| 1721 | case IndexQuantum: |
| 1722 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1723 | *q=(double) ((QuantumScale*GetPixelIntensity(image,p))* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1724 | quantum_info->scale+quantum_info->minimum); |
| 1725 | break; |
| 1726 | } |
| 1727 | default: |
| 1728 | *q=0; |
| 1729 | } |
| 1730 | q++; |
| 1731 | } |
| 1732 | p++; |
| 1733 | } |
| 1734 | break; |
| 1735 | } |
| 1736 | case FloatPixel: |
| 1737 | { |
| 1738 | register float |
| 1739 | *q; |
| 1740 | |
| 1741 | q=(float *) stream_info->pixels; |
| 1742 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
| 1743 | { |
| 1744 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1745 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1746 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1747 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1748 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1749 | *q++=(float) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1750 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1751 | *q++=(float) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1752 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1753 | *q++=(float) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1754 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1755 | p++; |
| 1756 | } |
| 1757 | break; |
| 1758 | } |
| 1759 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
| 1760 | { |
| 1761 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1762 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1763 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1764 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1765 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1766 | *q++=(float) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1767 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1768 | *q++=(float) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1769 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1770 | *q++=(float) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1771 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1772 | *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1773 | quantum_info->scale+quantum_info->minimum); |
| 1774 | p++; |
| 1775 | } |
| 1776 | break; |
| 1777 | } |
| 1778 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
| 1779 | { |
| 1780 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1781 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1782 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1783 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1784 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1785 | *q++=(float) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1786 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1787 | *q++=(float) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1788 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1789 | *q++=(float) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1790 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1791 | *q++=0.0; |
| 1792 | p++; |
| 1793 | } |
| 1794 | break; |
| 1795 | } |
| 1796 | if (LocaleCompare(stream_info->map,"I") == 0) |
| 1797 | { |
| 1798 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1799 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1800 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1801 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1802 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1803 | *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1804 | quantum_info->scale+quantum_info->minimum); |
| 1805 | p++; |
| 1806 | } |
| 1807 | break; |
| 1808 | } |
| 1809 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
| 1810 | { |
| 1811 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1812 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1813 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1814 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1815 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1816 | *q++=(float) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1817 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1818 | *q++=(float) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1819 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1820 | *q++=(float) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1821 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1822 | p++; |
| 1823 | } |
| 1824 | break; |
| 1825 | } |
| 1826 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
| 1827 | { |
| 1828 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1829 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1830 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1831 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1832 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1833 | *q++=(float) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1834 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1835 | *q++=(float) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1836 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1837 | *q++=(float) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1838 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1839 | *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1840 | quantum_info->scale+quantum_info->minimum); |
| 1841 | p++; |
| 1842 | } |
| 1843 | break; |
| 1844 | } |
| 1845 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
| 1846 | { |
| 1847 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1848 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1849 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1850 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1851 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1852 | *q++=(float) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1853 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1854 | *q++=(float) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1855 | quantum_info->scale+quantum_info->minimum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1856 | *q++=(float) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1857 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1858 | *q++=0.0; |
| 1859 | p++; |
| 1860 | } |
| 1861 | break; |
| 1862 | } |
| 1863 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1864 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1865 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1866 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1867 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1868 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1869 | { |
| 1870 | *q=0; |
| 1871 | switch (quantum_map[i]) |
| 1872 | { |
| 1873 | case RedQuantum: |
| 1874 | case CyanQuantum: |
| 1875 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1876 | *q=(float) ((QuantumScale*GetPixelRed(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1877 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1878 | break; |
| 1879 | } |
| 1880 | case GreenQuantum: |
| 1881 | case MagentaQuantum: |
| 1882 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1883 | *q=(float) ((QuantumScale*GetPixelGreen(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1884 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1885 | break; |
| 1886 | } |
| 1887 | case BlueQuantum: |
| 1888 | case YellowQuantum: |
| 1889 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1890 | *q=(float) ((QuantumScale*GetPixelBlue(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1891 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1892 | break; |
| 1893 | } |
| 1894 | case AlphaQuantum: |
| 1895 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1896 | *q=(float) ((QuantumScale*GetPixelAlpha(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1897 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1898 | break; |
| 1899 | } |
| 1900 | case OpacityQuantum: |
| 1901 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1902 | *q=(float) ((QuantumScale*GetPixelAlpha(image,p))* |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 1903 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1904 | break; |
| 1905 | } |
| 1906 | case BlackQuantum: |
| 1907 | { |
| 1908 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1909 | *q=(float) ((QuantumScale*GetPixelBlack(image,p))* |
cristy | fba5a8b | 2011-05-03 17:12:12 +0000 | [diff] [blame] | 1910 | quantum_info->scale+quantum_info->minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1911 | break; |
| 1912 | } |
| 1913 | case IndexQuantum: |
| 1914 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1915 | *q=(float) ((QuantumScale*GetPixelIntensity(image,p))* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1916 | quantum_info->scale+quantum_info->minimum); |
| 1917 | break; |
| 1918 | } |
| 1919 | default: |
| 1920 | *q=0; |
| 1921 | } |
| 1922 | q++; |
| 1923 | } |
| 1924 | p++; |
| 1925 | } |
| 1926 | break; |
| 1927 | } |
| 1928 | case IntegerPixel: |
| 1929 | { |
| 1930 | register unsigned int |
| 1931 | *q; |
| 1932 | |
| 1933 | q=(unsigned int *) stream_info->pixels; |
| 1934 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
| 1935 | { |
| 1936 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1937 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1938 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1939 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1940 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1941 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1942 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1943 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1944 | p++; |
| 1945 | } |
| 1946 | break; |
| 1947 | } |
| 1948 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
| 1949 | { |
| 1950 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1951 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1952 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1953 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1954 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1955 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1956 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1957 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1958 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1959 | p++; |
| 1960 | } |
| 1961 | break; |
| 1962 | } |
| 1963 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
| 1964 | { |
| 1965 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1966 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1967 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1968 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1969 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1970 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1971 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1972 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1973 | *q++=0U; |
| 1974 | p++; |
| 1975 | } |
| 1976 | break; |
| 1977 | } |
| 1978 | if (LocaleCompare(stream_info->map,"I") == 0) |
| 1979 | { |
| 1980 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1981 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1982 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1983 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1984 | { |
| 1985 | *q++=(unsigned int) ScaleQuantumToLong( |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1986 | GetPixelIntensity(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1987 | p++; |
| 1988 | } |
| 1989 | break; |
| 1990 | } |
| 1991 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
| 1992 | { |
| 1993 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1994 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1995 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1996 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1997 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1998 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1999 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 2000 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2001 | p++; |
| 2002 | } |
| 2003 | break; |
| 2004 | } |
| 2005 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
| 2006 | { |
| 2007 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2008 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2009 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2010 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2011 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2012 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
| 2013 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 2014 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2015 | *q++=(unsigned int) ScaleQuantumToLong((Quantum) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2016 | (GetPixelAlpha(image,p))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2017 | p++; |
| 2018 | } |
| 2019 | break; |
| 2020 | } |
| 2021 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
| 2022 | { |
| 2023 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2024 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2025 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2026 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2027 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2028 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
| 2029 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 2030 | *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2031 | *q++=0U; |
| 2032 | p++; |
| 2033 | } |
| 2034 | break; |
| 2035 | } |
| 2036 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2037 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2038 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2039 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2040 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2041 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2042 | { |
| 2043 | *q=0; |
| 2044 | switch (quantum_map[i]) |
| 2045 | { |
| 2046 | case RedQuantum: |
| 2047 | case CyanQuantum: |
| 2048 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2049 | *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2050 | break; |
| 2051 | } |
| 2052 | case GreenQuantum: |
| 2053 | case MagentaQuantum: |
| 2054 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2055 | *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2056 | break; |
| 2057 | } |
| 2058 | case BlueQuantum: |
| 2059 | case YellowQuantum: |
| 2060 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2061 | *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2062 | break; |
| 2063 | } |
| 2064 | case AlphaQuantum: |
| 2065 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2066 | *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2067 | break; |
| 2068 | } |
| 2069 | case OpacityQuantum: |
| 2070 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2071 | *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2072 | break; |
| 2073 | } |
| 2074 | case BlackQuantum: |
| 2075 | { |
| 2076 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2077 | *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2078 | break; |
| 2079 | } |
| 2080 | case IndexQuantum: |
| 2081 | { |
| 2082 | *q=(unsigned int) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2083 | ScaleQuantumToLong(GetPixelIntensity(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2084 | break; |
| 2085 | } |
| 2086 | default: |
| 2087 | *q=0; |
| 2088 | } |
| 2089 | q++; |
| 2090 | } |
| 2091 | p++; |
| 2092 | } |
| 2093 | break; |
| 2094 | } |
| 2095 | case LongPixel: |
| 2096 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2097 | register size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2098 | *q; |
| 2099 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2100 | q=(size_t *) stream_info->pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2101 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
| 2102 | { |
| 2103 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2104 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2105 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2106 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2107 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2108 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 2109 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 2110 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2111 | p++; |
| 2112 | } |
| 2113 | break; |
| 2114 | } |
| 2115 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
| 2116 | { |
| 2117 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2118 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2119 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2120 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2121 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2122 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 2123 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 2124 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 2125 | *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2126 | p++; |
| 2127 | } |
| 2128 | break; |
| 2129 | } |
| 2130 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
| 2131 | { |
| 2132 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2133 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2134 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2135 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2136 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2137 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 2138 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 2139 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2140 | *q++=0; |
| 2141 | p++; |
| 2142 | } |
| 2143 | break; |
| 2144 | } |
| 2145 | if (LocaleCompare(stream_info->map,"I") == 0) |
| 2146 | { |
| 2147 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2148 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2149 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2150 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2151 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2152 | *q++=ScaleQuantumToLong(GetPixelIntensity(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2153 | p++; |
| 2154 | } |
| 2155 | break; |
| 2156 | } |
| 2157 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
| 2158 | { |
| 2159 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2160 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2161 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2162 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2163 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2164 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 2165 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 2166 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2167 | p++; |
| 2168 | } |
| 2169 | break; |
| 2170 | } |
| 2171 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
| 2172 | { |
| 2173 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2174 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2175 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2176 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2177 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2178 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 2179 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 2180 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 2181 | *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2182 | p++; |
| 2183 | } |
| 2184 | break; |
| 2185 | } |
| 2186 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
| 2187 | { |
| 2188 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2189 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2190 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2191 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2192 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2193 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 2194 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 2195 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2196 | *q++=0; |
| 2197 | p++; |
| 2198 | } |
| 2199 | break; |
| 2200 | } |
| 2201 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2202 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2203 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2204 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2205 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2206 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2207 | { |
| 2208 | *q=0; |
| 2209 | switch (quantum_map[i]) |
| 2210 | { |
| 2211 | case RedQuantum: |
| 2212 | case CyanQuantum: |
| 2213 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2214 | *q=ScaleQuantumToLong(GetPixelRed(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2215 | break; |
| 2216 | } |
| 2217 | case GreenQuantum: |
| 2218 | case MagentaQuantum: |
| 2219 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2220 | *q=ScaleQuantumToLong(GetPixelGreen(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2221 | break; |
| 2222 | } |
| 2223 | case BlueQuantum: |
| 2224 | case YellowQuantum: |
| 2225 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2226 | *q=ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2227 | break; |
| 2228 | } |
| 2229 | case AlphaQuantum: |
| 2230 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2231 | *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2232 | break; |
| 2233 | } |
| 2234 | case OpacityQuantum: |
| 2235 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2236 | *q=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2237 | break; |
| 2238 | } |
| 2239 | case BlackQuantum: |
| 2240 | { |
| 2241 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2242 | *q=ScaleQuantumToLong(GetPixelBlack(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2243 | break; |
| 2244 | } |
| 2245 | case IndexQuantum: |
| 2246 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2247 | *q=ScaleQuantumToLong(GetPixelIntensity(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2248 | break; |
| 2249 | } |
| 2250 | default: |
| 2251 | break; |
| 2252 | } |
| 2253 | q++; |
| 2254 | } |
| 2255 | p++; |
| 2256 | } |
| 2257 | break; |
| 2258 | } |
| 2259 | case QuantumPixel: |
| 2260 | { |
| 2261 | register Quantum |
| 2262 | *q; |
| 2263 | |
| 2264 | q=(Quantum *) stream_info->pixels; |
| 2265 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
| 2266 | { |
| 2267 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2268 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2269 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2270 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2271 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2272 | *q++=GetPixelBlue(image,p); |
| 2273 | *q++=GetPixelGreen(image,p); |
| 2274 | *q++=GetPixelRed(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2275 | p++; |
| 2276 | } |
| 2277 | break; |
| 2278 | } |
| 2279 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
| 2280 | { |
| 2281 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2282 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2283 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2284 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2285 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2286 | *q++=GetPixelBlue(image,p); |
| 2287 | *q++=GetPixelGreen(image,p); |
| 2288 | *q++=GetPixelRed(image,p); |
| 2289 | *q++=(Quantum) (GetPixelAlpha(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2290 | p++; |
| 2291 | } |
| 2292 | break; |
| 2293 | } |
| 2294 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
| 2295 | { |
| 2296 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2297 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2298 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2299 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2300 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2301 | *q++=GetPixelBlue(image,p); |
| 2302 | *q++=GetPixelGreen(image,p); |
| 2303 | *q++=GetPixelRed(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2304 | *q++=0; |
| 2305 | p++; |
| 2306 | } |
| 2307 | break; |
| 2308 | } |
| 2309 | if (LocaleCompare(stream_info->map,"I") == 0) |
| 2310 | { |
| 2311 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2312 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2313 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2314 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2315 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2316 | *q++=GetPixelIntensity(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2317 | p++; |
| 2318 | } |
| 2319 | break; |
| 2320 | } |
| 2321 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
| 2322 | { |
| 2323 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2324 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2325 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2326 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2327 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2328 | *q++=GetPixelRed(image,p); |
| 2329 | *q++=GetPixelGreen(image,p); |
| 2330 | *q++=GetPixelBlue(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2331 | p++; |
| 2332 | } |
| 2333 | break; |
| 2334 | } |
| 2335 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
| 2336 | { |
| 2337 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2338 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2339 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2340 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2341 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2342 | *q++=GetPixelRed(image,p); |
| 2343 | *q++=GetPixelGreen(image,p); |
| 2344 | *q++=GetPixelBlue(image,p); |
| 2345 | *q++=(Quantum) (GetPixelAlpha(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2346 | p++; |
| 2347 | } |
| 2348 | break; |
| 2349 | } |
| 2350 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
| 2351 | { |
| 2352 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2353 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2354 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2355 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2356 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2357 | *q++=GetPixelRed(image,p); |
| 2358 | *q++=GetPixelGreen(image,p); |
| 2359 | *q++=GetPixelBlue(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2360 | *q++=0U; |
| 2361 | p++; |
| 2362 | } |
| 2363 | break; |
| 2364 | } |
| 2365 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2366 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2367 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2368 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2369 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2370 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2371 | { |
| 2372 | *q=(Quantum) 0; |
| 2373 | switch (quantum_map[i]) |
| 2374 | { |
| 2375 | case RedQuantum: |
| 2376 | case CyanQuantum: |
| 2377 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2378 | *q=GetPixelRed(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2379 | break; |
| 2380 | } |
| 2381 | case GreenQuantum: |
| 2382 | case MagentaQuantum: |
| 2383 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2384 | *q=GetPixelGreen(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2385 | break; |
| 2386 | } |
| 2387 | case BlueQuantum: |
| 2388 | case YellowQuantum: |
| 2389 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2390 | *q=GetPixelBlue(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2391 | break; |
| 2392 | } |
| 2393 | case AlphaQuantum: |
| 2394 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2395 | *q=(Quantum) (GetPixelAlpha(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2396 | break; |
| 2397 | } |
| 2398 | case OpacityQuantum: |
| 2399 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2400 | *q=GetPixelAlpha(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2401 | break; |
| 2402 | } |
| 2403 | case BlackQuantum: |
| 2404 | { |
| 2405 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2406 | *q=GetPixelBlack(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2407 | break; |
| 2408 | } |
| 2409 | case IndexQuantum: |
| 2410 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2411 | *q=(GetPixelIntensity(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2412 | break; |
| 2413 | } |
| 2414 | default: |
| 2415 | *q=0; |
| 2416 | } |
| 2417 | q++; |
| 2418 | } |
| 2419 | p++; |
| 2420 | } |
| 2421 | break; |
| 2422 | } |
| 2423 | case ShortPixel: |
| 2424 | { |
| 2425 | register unsigned short |
| 2426 | *q; |
| 2427 | |
| 2428 | q=(unsigned short *) stream_info->pixels; |
| 2429 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
| 2430 | { |
| 2431 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2432 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2433 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2434 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2435 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2436 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 2437 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 2438 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2439 | p++; |
| 2440 | } |
| 2441 | break; |
| 2442 | } |
| 2443 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
| 2444 | { |
| 2445 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2446 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2447 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2448 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2449 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2450 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 2451 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 2452 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 2453 | *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2454 | p++; |
| 2455 | } |
| 2456 | break; |
| 2457 | } |
| 2458 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
| 2459 | { |
| 2460 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2461 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2462 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2463 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2464 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2465 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 2466 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 2467 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2468 | *q++=0; |
| 2469 | p++; |
| 2470 | } |
| 2471 | break; |
| 2472 | } |
| 2473 | if (LocaleCompare(stream_info->map,"I") == 0) |
| 2474 | { |
| 2475 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2476 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2477 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2478 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2479 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2480 | *q++=ScaleQuantumToShort(GetPixelIntensity(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2481 | p++; |
| 2482 | } |
| 2483 | break; |
| 2484 | } |
| 2485 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
| 2486 | { |
| 2487 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2488 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2489 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2490 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2491 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2492 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 2493 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 2494 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2495 | p++; |
| 2496 | } |
| 2497 | break; |
| 2498 | } |
| 2499 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
| 2500 | { |
| 2501 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2502 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2503 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2504 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2505 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2506 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 2507 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 2508 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 2509 | *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2510 | p++; |
| 2511 | } |
| 2512 | break; |
| 2513 | } |
| 2514 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
| 2515 | { |
| 2516 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2517 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2518 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2519 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2520 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2521 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 2522 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 2523 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2524 | *q++=0; |
| 2525 | p++; |
| 2526 | } |
| 2527 | break; |
| 2528 | } |
| 2529 | p=GetAuthenticPixelQueue(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2530 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2531 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2532 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2533 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2534 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2535 | { |
| 2536 | *q=0; |
| 2537 | switch (quantum_map[i]) |
| 2538 | { |
| 2539 | case RedQuantum: |
| 2540 | case CyanQuantum: |
| 2541 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2542 | *q=ScaleQuantumToShort(GetPixelRed(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2543 | break; |
| 2544 | } |
| 2545 | case GreenQuantum: |
| 2546 | case MagentaQuantum: |
| 2547 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2548 | *q=ScaleQuantumToShort(GetPixelGreen(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | } |
| 2551 | case BlueQuantum: |
| 2552 | case YellowQuantum: |
| 2553 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2554 | *q=ScaleQuantumToShort(GetPixelBlue(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2555 | break; |
| 2556 | } |
| 2557 | case AlphaQuantum: |
| 2558 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2559 | *q=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2560 | break; |
| 2561 | } |
| 2562 | case OpacityQuantum: |
| 2563 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2564 | *q=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2565 | break; |
| 2566 | } |
| 2567 | case BlackQuantum: |
| 2568 | { |
| 2569 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2570 | *q=ScaleQuantumToShort(GetPixelBlack(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2571 | break; |
| 2572 | } |
| 2573 | case IndexQuantum: |
| 2574 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2575 | *q=ScaleQuantumToShort(GetPixelIntensity(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2576 | break; |
| 2577 | } |
| 2578 | default: |
| 2579 | break; |
| 2580 | } |
| 2581 | q++; |
| 2582 | } |
| 2583 | p++; |
| 2584 | } |
| 2585 | break; |
| 2586 | } |
| 2587 | default: |
| 2588 | { |
| 2589 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 2590 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 2591 | "UnrecognizedPixelMap","`%s'",stream_info->map); |
| 2592 | break; |
| 2593 | } |
| 2594 | } |
| 2595 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 2596 | return(MagickTrue); |
| 2597 | } |
| 2598 | |
| 2599 | /* |
| 2600 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2601 | % % |
| 2602 | % % |
| 2603 | % % |
| 2604 | + S y n c A u t h e n t i c P i x e l s S t r e a m % |
| 2605 | % % |
| 2606 | % % |
| 2607 | % % |
| 2608 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2609 | % |
| 2610 | % SyncAuthenticPixelsStream() calls the user supplied callback method with |
| 2611 | % the latest stream of pixels. |
| 2612 | % |
| 2613 | % The format of the SyncAuthenticPixelsStream method is: |
| 2614 | % |
| 2615 | % MagickBooleanType SyncAuthenticPixelsStream(Image *image, |
| 2616 | % ExceptionInfo *exception) |
| 2617 | % |
| 2618 | % A description of each parameter follows: |
| 2619 | % |
| 2620 | % o image: the image. |
| 2621 | % |
| 2622 | % o exception: return any errors or warnings in this structure. |
| 2623 | % |
| 2624 | */ |
| 2625 | static MagickBooleanType SyncAuthenticPixelsStream(Image *image, |
| 2626 | ExceptionInfo *exception) |
| 2627 | { |
| 2628 | CacheInfo |
| 2629 | *cache_info; |
| 2630 | |
| 2631 | size_t |
| 2632 | length; |
| 2633 | |
| 2634 | StreamHandler |
| 2635 | stream_handler; |
| 2636 | |
| 2637 | assert(image != (Image *) NULL); |
| 2638 | assert(image->signature == MagickSignature); |
| 2639 | if (image->debug != MagickFalse) |
| 2640 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 2641 | cache_info=(CacheInfo *) image->cache; |
| 2642 | assert(cache_info->signature == MagickSignature); |
| 2643 | stream_handler=GetBlobStreamHandler(image); |
| 2644 | if (stream_handler == (StreamHandler) NULL) |
| 2645 | { |
| 2646 | (void) ThrowMagickException(exception,GetMagickModule(),StreamError, |
| 2647 | "NoStreamHandlerIsDefined","`%s'",image->filename); |
| 2648 | return(MagickFalse); |
| 2649 | } |
| 2650 | length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns); |
| 2651 | return(length == cache_info->columns ? MagickTrue : MagickFalse); |
| 2652 | } |
| 2653 | |
| 2654 | /* |
| 2655 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2656 | % % |
| 2657 | % % |
| 2658 | % % |
| 2659 | % W r i t e S t r e a m % |
| 2660 | % % |
| 2661 | % % |
| 2662 | % % |
| 2663 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2664 | % |
| 2665 | % WriteStream() makes the image pixels available to a user supplied callback |
| 2666 | % method immediately upon writing pixel data with the WriteImage() method. |
| 2667 | % |
| 2668 | % The format of the WriteStream() method is: |
| 2669 | % |
| 2670 | % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *, |
| 2671 | % StreamHandler stream) |
| 2672 | % |
| 2673 | % A description of each parameter follows: |
| 2674 | % |
| 2675 | % o image_info: the image info. |
| 2676 | % |
| 2677 | % o stream: A callback method. |
| 2678 | % |
| 2679 | */ |
| 2680 | MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info, |
| 2681 | Image *image,StreamHandler stream) |
| 2682 | { |
| 2683 | ImageInfo |
| 2684 | *write_info; |
| 2685 | |
| 2686 | MagickBooleanType |
| 2687 | status; |
| 2688 | |
| 2689 | assert(image_info != (ImageInfo *) NULL); |
| 2690 | assert(image_info->signature == MagickSignature); |
| 2691 | if (image_info->debug != MagickFalse) |
| 2692 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 2693 | image_info->filename); |
| 2694 | assert(image != (Image *) NULL); |
| 2695 | assert(image->signature == MagickSignature); |
| 2696 | write_info=CloneImageInfo(image_info); |
| 2697 | write_info->stream=stream; |
| 2698 | status=WriteImage(write_info,image); |
| 2699 | write_info=DestroyImageInfo(write_info); |
| 2700 | return(status); |
| 2701 | } |