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