cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % RRRR GGGG BBBB % |
| 7 | % R R G B B % |
| 8 | % RRRR G GG BBBB % |
| 9 | % R R G G B B % |
| 10 | % R R GGG BBBB % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write Raw RGB Image Format % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
| 20 | % Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization % |
| 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 | Include declarations. |
| 41 | */ |
| 42 | #include "magick/studio.h" |
| 43 | #include "magick/blob.h" |
| 44 | #include "magick/blob-private.h" |
| 45 | #include "magick/cache.h" |
| 46 | #include "magick/colorspace.h" |
| 47 | #include "magick/constitute.h" |
| 48 | #include "magick/exception.h" |
| 49 | #include "magick/exception-private.h" |
| 50 | #include "magick/image.h" |
| 51 | #include "magick/image-private.h" |
| 52 | #include "magick/list.h" |
| 53 | #include "magick/magick.h" |
| 54 | #include "magick/memory_.h" |
| 55 | #include "magick/monitor.h" |
| 56 | #include "magick/monitor-private.h" |
| 57 | #include "magick/pixel-private.h" |
| 58 | #include "magick/quantum-private.h" |
| 59 | #include "magick/static.h" |
| 60 | #include "magick/statistic.h" |
| 61 | #include "magick/string_.h" |
| 62 | #include "magick/module.h" |
| 63 | #include "magick/utility.h" |
| 64 | |
| 65 | /* |
| 66 | Forward declarations. |
| 67 | */ |
| 68 | static MagickBooleanType |
| 69 | WriteRGBImage(const ImageInfo *,Image *); |
| 70 | |
| 71 | /* |
| 72 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 73 | % % |
| 74 | % % |
| 75 | % % |
| 76 | % R e a d R G B I m a g e % |
| 77 | % % |
| 78 | % % |
| 79 | % % |
| 80 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 81 | % |
| 82 | % ReadRGBImage() reads an image of raw RGB or RGBA samples and returns it. It |
| 83 | % allocates the memory necessary for the new Image structure and returns a |
| 84 | % pointer to the new image. |
| 85 | % |
| 86 | % The format of the ReadRGBImage method is: |
| 87 | % |
| 88 | % Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 89 | % |
| 90 | % A description of each parameter follows: |
| 91 | % |
| 92 | % o image_info: the image info. |
| 93 | % |
| 94 | % o exception: return any errors or warnings in this structure. |
| 95 | % |
| 96 | */ |
| 97 | static Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 98 | { |
| 99 | Image |
| 100 | *canvas_image, |
| 101 | *image; |
| 102 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 | MagickBooleanType |
| 104 | status; |
| 105 | |
| 106 | MagickOffsetType |
| 107 | scene; |
| 108 | |
| 109 | QuantumInfo |
| 110 | *quantum_info; |
| 111 | |
| 112 | QuantumType |
| 113 | quantum_type; |
| 114 | |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 115 | Quantum |
| 116 | qx[4]; |
| 117 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 118 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 119 | i, |
| 120 | j; |
| 121 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 122 | ssize_t |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 123 | count, |
| 124 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 125 | |
| 126 | size_t |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 127 | channels, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 128 | length; |
| 129 | |
| 130 | unsigned char |
| 131 | *pixels; |
| 132 | |
| 133 | QuantumType |
| 134 | quantum_types[4]; |
| 135 | |
| 136 | char |
| 137 | sfx[] = {0, 0}; |
| 138 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 139 | /* |
| 140 | Open image file. |
| 141 | */ |
| 142 | assert(image_info != (const ImageInfo *) NULL); |
| 143 | assert(image_info->signature == MagickSignature); |
| 144 | if (image_info->debug != MagickFalse) |
| 145 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 146 | image_info->filename); |
| 147 | assert(exception != (ExceptionInfo *) NULL); |
| 148 | assert(exception->signature == MagickSignature); |
| 149 | image=AcquireImage(image_info); |
| 150 | if ((image->columns == 0) || (image->rows == 0)) |
| 151 | ThrowReaderException(OptionError,"MustSpecifyImageSize"); |
| 152 | if (image_info->interlace != PartitionInterlace) |
| 153 | { |
| 154 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 155 | if (status == MagickFalse) |
| 156 | { |
| 157 | image=DestroyImageList(image); |
| 158 | return((Image *) NULL); |
| 159 | } |
| 160 | for (i=0; i < image->offset; i++) |
| 161 | if (ReadBlobByte(image) == EOF) |
| 162 | { |
| 163 | ThrowFileException(exception,CorruptImageError, |
| 164 | "UnexpectedEndOfFile",image->filename); |
| 165 | break; |
| 166 | } |
| 167 | } |
| 168 | /* |
| 169 | Create virtual canvas to support cropping (i.e. image.rgb[100x100+10+20]). |
| 170 | */ |
| 171 | canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse, |
| 172 | exception); |
| 173 | (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod); |
| 174 | quantum_info=AcquireQuantumInfo(image_info,canvas_image); |
| 175 | if (quantum_info == (QuantumInfo *) NULL) |
| 176 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 177 | pixels=GetQuantumPixels(quantum_info); |
| 178 | quantum_type=RGBQuantum; |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 179 | for (i=0; i < 4; i++) |
| 180 | { |
| 181 | if (image_info->magick[i] == '\0') |
| 182 | break; |
| 183 | switch(image_info->magick[i]) |
| 184 | { |
| 185 | case 'R': quantum_types[i]=RedQuantum; break; |
| 186 | case 'G': quantum_types[i]=GreenQuantum; break; |
| 187 | case 'B': quantum_types[i]=BlueQuantum; break; |
cristy | 2080f2b | 2010-08-21 18:43:15 +0000 | [diff] [blame^] | 188 | case 'A': |
| 189 | { |
| 190 | quantum_types[i]=AlphaQuantum; |
| 191 | quantum_type=RGBAQuantum; |
| 192 | break; |
| 193 | } |
| 194 | case 'O': |
| 195 | { |
| 196 | quantum_types[i]=OpacityQuantum; |
| 197 | quantum_type=RGBOQuantum; |
| 198 | break; |
| 199 | } |
| 200 | default: |
| 201 | break; |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | channels=i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 205 | if (image_info->number_scenes != 0) |
| 206 | while (image->scene < image_info->scene) |
| 207 | { |
| 208 | /* |
| 209 | Skip to next image. |
| 210 | */ |
| 211 | image->scene++; |
| 212 | length=GetQuantumExtent(canvas_image,quantum_info,quantum_type); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 213 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 214 | { |
| 215 | count=ReadBlob(image,length,pixels); |
| 216 | if (count != (ssize_t) length) |
| 217 | break; |
| 218 | } |
| 219 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 220 | count=0; |
| 221 | length=0; |
| 222 | scene=0; |
| 223 | do |
| 224 | { |
| 225 | /* |
| 226 | Read pixels to virtual canvas image then push to image. |
| 227 | */ |
| 228 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 229 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 230 | break; |
| 231 | switch (image_info->interlace) |
| 232 | { |
| 233 | case NoInterlace: |
| 234 | default: |
| 235 | { |
| 236 | /* |
| 237 | No interlacing: RGBRGBRGBRGBRGBRGB... |
| 238 | */ |
| 239 | if (scene == 0) |
| 240 | { |
| 241 | length=GetQuantumExtent(canvas_image,quantum_info,quantum_type); |
| 242 | count=ReadBlob(image,length,pixels); |
| 243 | if (count != (ssize_t) length) |
| 244 | break; |
| 245 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 246 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 247 | { |
| 248 | register const PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 249 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 250 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 251 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 252 | x; |
| 253 | |
| 254 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 255 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 256 | |
cristy | 21da32d | 2009-09-12 14:56:09 +0000 | [diff] [blame] | 257 | if (count != (ssize_t) length) |
| 258 | { |
| 259 | ThrowFileException(exception,CorruptImageError, |
| 260 | "UnexpectedEndOfFile",image->filename); |
| 261 | break; |
| 262 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 263 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 264 | exception); |
| 265 | if (q == (PixelPacket *) NULL) |
| 266 | break; |
| 267 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 268 | quantum_info,quantum_type,pixels,exception); |
| 269 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 270 | break; |
| 271 | if (((y-image->extract_info.y) >= 0) && |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 272 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 273 | { |
| 274 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 275 | canvas_image->columns,1,exception); |
| 276 | q=QueueAuthenticPixels(image,0,y-image->extract_info.y, |
| 277 | image->columns,1,exception); |
| 278 | if ((p == (const PixelPacket *) NULL) || |
| 279 | (q == (PixelPacket *) NULL)) |
| 280 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 281 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 282 | { |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 283 | qx[0]=GetRedPixelComponent(p); |
| 284 | qx[1]=GetGreenPixelComponent(p); |
| 285 | qx[2]=GetBluePixelComponent(p); |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 286 | qx[3]=GetOpacityPixelComponent(p); |
| 287 | for (i=0; i < channels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 288 | switch(quantum_types[i]) |
| 289 | { |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 290 | case RedQuantum: q->red=qx[i]; break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 291 | case GreenQuantum: q->green=qx[i]; break; |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 292 | case BlueQuantum: q->blue=qx[i]; break; |
| 293 | case AlphaQuantum: q->opacity=qx[i]; break; |
| 294 | case OpacityQuantum: q->opacity=qx[i]; break; |
| 295 | default: break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 296 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 297 | p++; |
| 298 | q++; |
| 299 | } |
| 300 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 301 | break; |
| 302 | } |
| 303 | if (image->previous == (Image *) NULL) |
| 304 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 305 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 306 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 307 | if (status == MagickFalse) |
| 308 | break; |
| 309 | } |
| 310 | count=ReadBlob(image,length,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 311 | } |
| 312 | break; |
| 313 | } |
| 314 | case LineInterlace: |
| 315 | { |
| 316 | /* |
| 317 | Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB... |
| 318 | */ |
| 319 | if (scene == 0) |
| 320 | { |
| 321 | length=GetQuantumExtent(canvas_image,quantum_info,quantum_types[0]); |
| 322 | count=ReadBlob(image,length,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 323 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 324 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 325 | { |
| 326 | register const PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 327 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 328 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 329 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 330 | x; |
| 331 | |
| 332 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 333 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 334 | |
cristy | 21da32d | 2009-09-12 14:56:09 +0000 | [diff] [blame] | 335 | if (count != (ssize_t) length) |
| 336 | { |
| 337 | ThrowFileException(exception,CorruptImageError, |
| 338 | "UnexpectedEndOfFile",image->filename); |
| 339 | break; |
| 340 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 341 | for (i=0; i < channels; i++) |
| 342 | { |
| 343 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 344 | exception); |
| 345 | if (q == (PixelPacket *) NULL) |
| 346 | break; |
| 347 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 348 | quantum_info,quantum_types[i],pixels,exception); |
| 349 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 350 | break; |
| 351 | if (((y-image->extract_info.y) >= 0) && |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 352 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 353 | { |
| 354 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x, |
| 355 | 0,canvas_image->columns,1,exception); |
| 356 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 357 | image->columns,1,exception); |
| 358 | if ((p == (const PixelPacket *) NULL) || |
| 359 | (q == (PixelPacket *) NULL)) |
| 360 | break; |
| 361 | if (i == (channels - 1)) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 362 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 363 | { |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 364 | SetRedPixelComponent(q,GetRedPixelComponent(p)); |
| 365 | SetGreenPixelComponent(q,GetGreenPixelComponent(p)); |
| 366 | SetBluePixelComponent(q,GetBluePixelComponent(p)); |
| 367 | SetOpacityPixelComponent(q,GetOpacityPixelComponent(p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 368 | p++; |
| 369 | q++; |
| 370 | } |
| 371 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 372 | break; |
| 373 | } |
| 374 | count=ReadBlob(image,length,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 375 | } |
| 376 | if (image->previous == (Image *) NULL) |
| 377 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 378 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 379 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 380 | if (status == MagickFalse) |
| 381 | break; |
| 382 | } |
| 383 | } |
| 384 | break; |
| 385 | } |
| 386 | case PlaneInterlace: |
| 387 | { |
| 388 | /* |
| 389 | Plane interlacing: RRRRRR...GGGGGG...BBBBBB... |
| 390 | */ |
| 391 | if (scene == 0) |
| 392 | { |
| 393 | length=GetQuantumExtent(canvas_image,quantum_info,quantum_types[0]); |
| 394 | count=ReadBlob(image,length,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 395 | } |
| 396 | for (i=0; i < channels; i++) |
| 397 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 398 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 399 | { |
| 400 | register const PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 401 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 402 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 403 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 404 | x; |
| 405 | |
| 406 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 407 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 408 | |
cristy | 21da32d | 2009-09-12 14:56:09 +0000 | [diff] [blame] | 409 | if (count != (ssize_t) length) |
| 410 | { |
| 411 | ThrowFileException(exception,CorruptImageError, |
| 412 | "UnexpectedEndOfFile",image->filename); |
| 413 | break; |
| 414 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 415 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 416 | exception); |
| 417 | if (q == (PixelPacket *) NULL) |
| 418 | break; |
| 419 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 420 | quantum_info,quantum_types[i],pixels,exception); |
| 421 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 422 | break; |
| 423 | if (((y-image->extract_info.y) >= 0) && |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 424 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 425 | { |
| 426 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 427 | canvas_image->columns,1,exception); |
| 428 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 429 | image->columns,1,exception); |
| 430 | if ((p == (const PixelPacket *) NULL) || |
| 431 | (q == (PixelPacket *) NULL)) |
| 432 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 433 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 434 | { |
| 435 | switch(quantum_types[i]) |
| 436 | { |
cristy | dd5f591 | 2010-07-31 23:37:23 +0000 | [diff] [blame] | 437 | case RedQuantum: |
| 438 | { |
| 439 | SetRedPixelComponent(q,GetRedPixelComponent(p)); |
| 440 | break; |
| 441 | } |
| 442 | case GreenQuantum: |
| 443 | { |
| 444 | SetGreenPixelComponent(q,GetGreenPixelComponent(p)); |
| 445 | break; |
| 446 | } |
| 447 | case BlueQuantum: |
| 448 | { |
| 449 | SetBluePixelComponent(q,GetBluePixelComponent(p)); |
| 450 | break; |
| 451 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 452 | case OpacityQuantum: |
cristy | dd5f591 | 2010-07-31 23:37:23 +0000 | [diff] [blame] | 453 | case AlphaQuantum: |
| 454 | { |
| 455 | SetOpacityPixelComponent(q,GetOpacityPixelComponent(p)); |
| 456 | break; |
| 457 | } |
| 458 | default: |
| 459 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 460 | } |
| 461 | p++; |
| 462 | q++; |
| 463 | } |
| 464 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 465 | break; |
| 466 | } |
| 467 | count=ReadBlob(image,length,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 468 | } |
| 469 | if (image->previous == (Image *) NULL) |
| 470 | { |
| 471 | status=SetImageProgress(image,LoadImageTag,(i+1),5); |
| 472 | if (status == MagickFalse) |
| 473 | break; |
| 474 | } |
| 475 | } |
| 476 | if (image->previous == (Image *) NULL) |
| 477 | { |
| 478 | status=SetImageProgress(image,LoadImageTag,5,5); |
| 479 | if (status == MagickFalse) |
| 480 | break; |
| 481 | } |
| 482 | break; |
| 483 | } |
| 484 | case PartitionInterlace: |
| 485 | { |
| 486 | /* |
| 487 | Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB... |
| 488 | */ |
| 489 | for (i=0; i < channels; i++) |
| 490 | { |
| 491 | sfx[0]=image_info->magick[i]; |
| 492 | AppendImageFormat(sfx,image->filename); |
| 493 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 494 | if (status == MagickFalse) |
| 495 | { |
| 496 | canvas_image=DestroyImageList(canvas_image); |
| 497 | image=DestroyImageList(image); |
| 498 | return((Image *) NULL); |
| 499 | } |
| 500 | if (i == 0) |
| 501 | for (j=0; j < image->offset; j++) |
| 502 | if (ReadBlobByte(image) == EOF) |
| 503 | { |
| 504 | ThrowFileException(exception,CorruptImageError, |
| 505 | "UnexpectedEndOfFile",image->filename); |
| 506 | break; |
| 507 | } |
| 508 | length=GetQuantumExtent(canvas_image,quantum_info,quantum_types[i]); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 509 | for (j=0; j < (ssize_t) scene; j++) |
| 510 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 511 | if (ReadBlob(image,length,pixels) != (ssize_t) length) |
| 512 | { |
| 513 | ThrowFileException(exception,CorruptImageError, |
| 514 | "UnexpectedEndOfFile",image->filename); |
| 515 | break; |
| 516 | } |
| 517 | count=ReadBlob(image,length,pixels); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 518 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 519 | { |
| 520 | register const PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 521 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 522 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 523 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 524 | x; |
| 525 | |
| 526 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 527 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 528 | |
cristy | 21da32d | 2009-09-12 14:56:09 +0000 | [diff] [blame] | 529 | if (count != (ssize_t) length) |
| 530 | { |
| 531 | ThrowFileException(exception,CorruptImageError, |
| 532 | "UnexpectedEndOfFile",image->filename); |
| 533 | break; |
| 534 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 535 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 536 | exception); |
| 537 | if (q == (PixelPacket *) NULL) |
| 538 | break; |
| 539 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 540 | quantum_info,quantum_types[i],pixels,exception); |
| 541 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 542 | break; |
| 543 | if (((y-image->extract_info.y) >= 0) && |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 544 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 545 | { |
| 546 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 547 | canvas_image->columns,1,exception); |
| 548 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 549 | image->columns,1,exception); |
| 550 | if ((p == (const PixelPacket *) NULL) || |
| 551 | (q == (PixelPacket *) NULL)) |
| 552 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 553 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 554 | { |
| 555 | switch(quantum_types[i]) |
| 556 | { |
cristy | ccf7deb | 2010-07-31 23:46:58 +0000 | [diff] [blame] | 557 | case RedQuantum: |
| 558 | { |
| 559 | SetRedPixelComponent(q,GetRedPixelComponent(p)); |
| 560 | break; |
| 561 | } |
| 562 | case GreenQuantum: |
| 563 | { |
| 564 | SetGreenPixelComponent(q,GetGreenPixelComponent(p)); |
| 565 | break; |
| 566 | } |
| 567 | case BlueQuantum: |
| 568 | { |
| 569 | SetBluePixelComponent(q,GetBluePixelComponent(p)); |
| 570 | break; |
| 571 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 572 | case OpacityQuantum: |
cristy | ccf7deb | 2010-07-31 23:46:58 +0000 | [diff] [blame] | 573 | case AlphaQuantum: |
| 574 | { |
| 575 | SetOpacityPixelComponent(q,GetOpacityPixelComponent(p)); |
| 576 | break; |
| 577 | } |
| 578 | default: |
| 579 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 580 | } |
| 581 | p++; |
| 582 | q++; |
| 583 | } |
| 584 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 585 | break; |
| 586 | } |
| 587 | count=ReadBlob(image,length,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 588 | } |
| 589 | if (image->previous == (Image *) NULL) |
| 590 | { |
| 591 | status=SetImageProgress(image,LoadImageTag,(i+1),5); |
| 592 | if (status == MagickFalse) |
| 593 | break; |
| 594 | } |
| 595 | if (i != (channels-1)) |
| 596 | (void) CloseBlob(image); |
| 597 | } |
| 598 | if (image->previous == (Image *) NULL) |
| 599 | { |
| 600 | status=SetImageProgress(image,LoadImageTag,5,5); |
| 601 | if (status == MagickFalse) |
| 602 | break; |
| 603 | } |
| 604 | break; |
| 605 | } |
| 606 | } |
| 607 | SetQuantumImageType(image,quantum_type); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 608 | /* |
| 609 | Proceed to next image. |
| 610 | */ |
| 611 | if (image_info->number_scenes != 0) |
| 612 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 613 | break; |
| 614 | if (count == (ssize_t) length) |
| 615 | { |
| 616 | /* |
| 617 | Allocate next image structure. |
| 618 | */ |
| 619 | AcquireNextImage(image_info,image); |
| 620 | if (GetNextImageInList(image) == (Image *) NULL) |
| 621 | { |
| 622 | image=DestroyImageList(image); |
| 623 | return((Image *) NULL); |
| 624 | } |
| 625 | image=SyncNextImageInList(image); |
| 626 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 627 | GetBlobSize(image)); |
| 628 | if (status == MagickFalse) |
| 629 | break; |
| 630 | } |
| 631 | scene++; |
| 632 | } while (count == (ssize_t) length); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 633 | quantum_info=DestroyQuantumInfo(quantum_info); |
cristy | 01a3f33 | 2009-10-27 14:17:37 +0000 | [diff] [blame] | 634 | InheritException(&image->exception,&canvas_image->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 635 | canvas_image=DestroyImage(canvas_image); |
| 636 | (void) CloseBlob(image); |
| 637 | return(GetFirstImageInList(image)); |
| 638 | } |
| 639 | |
| 640 | /* |
| 641 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 642 | % % |
| 643 | % % |
| 644 | % % |
| 645 | % R e g i s t e r R G B I m a g e % |
| 646 | % % |
| 647 | % % |
| 648 | % % |
| 649 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 650 | % |
| 651 | % RegisterRGBImage() adds attributes for the RGB or RGBA image format to |
| 652 | % the list of supported formats. The attributes include the image format |
| 653 | % tag, a method to read and/or write the format, whether the format |
| 654 | % supports the saving of more than one frame to the same file or blob, |
| 655 | % whether the format supports native in-memory I/O, and a brief |
| 656 | % description of the format. |
| 657 | % |
| 658 | % The format of the RegisterRGBImage method is: |
| 659 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 660 | % size_t RegisterRGBImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 661 | % |
| 662 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 663 | ModuleExport size_t RegisterRGBImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 664 | { |
| 665 | MagickInfo |
| 666 | *entry; |
| 667 | |
| 668 | entry=SetMagickInfo("RGB"); |
| 669 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 670 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
| 671 | entry->raw=MagickTrue; |
| 672 | entry->endian_support=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 673 | entry->description=ConstantString("Raw red, green, and blue samples"); |
| 674 | entry->module=ConstantString("RGB"); |
| 675 | (void) RegisterMagickInfo(entry); |
| 676 | entry=SetMagickInfo("RBG"); |
| 677 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 678 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
| 679 | entry->raw=MagickTrue; |
| 680 | entry->endian_support=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 681 | entry->description=ConstantString("Raw red, blue, and green samples"); |
| 682 | entry->module=ConstantString("RGB"); |
| 683 | (void) RegisterMagickInfo(entry); |
| 684 | entry=SetMagickInfo("GRB"); |
| 685 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 686 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
| 687 | entry->raw=MagickTrue; |
| 688 | entry->endian_support=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 689 | entry->description=ConstantString("Raw green, red, and blue samples"); |
| 690 | entry->module=ConstantString("RGB"); |
| 691 | (void) RegisterMagickInfo(entry); |
| 692 | entry=SetMagickInfo("GBR"); |
| 693 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 694 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
| 695 | entry->raw=MagickTrue; |
| 696 | entry->endian_support=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 697 | entry->description=ConstantString("Raw green, blue, and red samples"); |
| 698 | entry->module=ConstantString("RGB"); |
| 699 | (void) RegisterMagickInfo(entry); |
| 700 | entry=SetMagickInfo("BRG"); |
| 701 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 702 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
| 703 | entry->raw=MagickTrue; |
| 704 | entry->endian_support=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 705 | entry->description=ConstantString("Raw blue, red, and green samples"); |
| 706 | entry->module=ConstantString("RGB"); |
| 707 | (void) RegisterMagickInfo(entry); |
| 708 | entry=SetMagickInfo("BGR"); |
| 709 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 710 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
| 711 | entry->raw=MagickTrue; |
| 712 | entry->endian_support=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 713 | entry->description=ConstantString("Raw blue, green, and red samples"); |
| 714 | entry->module=ConstantString("RGB"); |
| 715 | (void) RegisterMagickInfo(entry); |
cristy | 4a16cd5 | 2010-01-05 14:04:01 +0000 | [diff] [blame] | 716 | entry=SetMagickInfo("BGRA"); |
| 717 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 718 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
| 719 | entry->raw=MagickTrue; |
| 720 | entry->endian_support=MagickTrue; |
cristy | 4a16cd5 | 2010-01-05 14:04:01 +0000 | [diff] [blame] | 721 | entry->description=ConstantString("Raw blue, green, red and alpha samples"); |
| 722 | entry->module=ConstantString("RGB"); |
| 723 | (void) RegisterMagickInfo(entry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 724 | entry=SetMagickInfo("RGBA"); |
| 725 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 726 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
| 727 | entry->raw=MagickTrue; |
| 728 | entry->endian_support=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 729 | entry->description=ConstantString("Raw red, green, blue, and alpha samples"); |
| 730 | entry->module=ConstantString("RGB"); |
| 731 | (void) RegisterMagickInfo(entry); |
| 732 | entry=SetMagickInfo("RGBO"); |
| 733 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 734 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
| 735 | entry->raw=MagickTrue; |
| 736 | entry->endian_support=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 737 | entry->description=ConstantString("Raw red, green, blue, and opacity " |
| 738 | "samples"); |
| 739 | entry->module=ConstantString("RGB"); |
| 740 | (void) RegisterMagickInfo(entry); |
| 741 | return(MagickImageCoderSignature); |
| 742 | } |
| 743 | |
| 744 | /* |
| 745 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 746 | % % |
| 747 | % % |
| 748 | % % |
| 749 | % U n r e g i s t e r R G B I m a g e % |
| 750 | % % |
| 751 | % % |
| 752 | % % |
| 753 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 754 | % |
| 755 | % UnregisterRGBImage() removes format registrations made by the |
| 756 | % RGB module from the list of supported formats. |
| 757 | % |
| 758 | % The format of the UnregisterRGBImage method is: |
| 759 | % |
| 760 | % UnregisterRGBImage(void) |
| 761 | % |
| 762 | */ |
| 763 | ModuleExport void UnregisterRGBImage(void) |
| 764 | { |
| 765 | (void) UnregisterMagickInfo("RGBO"); |
| 766 | (void) UnregisterMagickInfo("RGBA"); |
| 767 | (void) UnregisterMagickInfo("BGR"); |
cristy | 4a16cd5 | 2010-01-05 14:04:01 +0000 | [diff] [blame] | 768 | (void) UnregisterMagickInfo("BGRA"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 769 | (void) UnregisterMagickInfo("BRG"); |
| 770 | (void) UnregisterMagickInfo("GBR"); |
| 771 | (void) UnregisterMagickInfo("GRB"); |
| 772 | (void) UnregisterMagickInfo("RBG"); |
| 773 | (void) UnregisterMagickInfo("RGB"); |
| 774 | } |
| 775 | |
| 776 | /* |
| 777 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 778 | % % |
| 779 | % % |
| 780 | % % |
| 781 | % W r i t e R G B I m a g e % |
| 782 | % % |
| 783 | % % |
| 784 | % % |
| 785 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 786 | % |
| 787 | % WriteRGBImage() writes an image to a file in the RGB or RGBA rasterfile |
| 788 | % format. |
| 789 | % |
| 790 | % The format of the WriteRGBImage method is: |
| 791 | % |
| 792 | % MagickBooleanType WriteRGBImage(const ImageInfo *image_info,Image *image) |
| 793 | % |
| 794 | % A description of each parameter follows. |
| 795 | % |
| 796 | % o image_info: the image info. |
| 797 | % |
| 798 | % o image: The image. |
| 799 | % |
| 800 | */ |
| 801 | static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,Image *image) |
| 802 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 803 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 804 | y; |
| 805 | |
| 806 | MagickBooleanType |
| 807 | status; |
| 808 | |
| 809 | MagickOffsetType |
| 810 | scene; |
| 811 | |
| 812 | QuantumInfo |
| 813 | *quantum_info; |
| 814 | |
| 815 | QuantumType |
| 816 | quantum_type, |
| 817 | quantum_types[4]; |
| 818 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 819 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 820 | i; |
| 821 | |
| 822 | ssize_t |
| 823 | count; |
| 824 | |
| 825 | size_t |
| 826 | length; |
| 827 | |
| 828 | unsigned char |
| 829 | *pixels; |
| 830 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 831 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 832 | channels; |
| 833 | |
| 834 | /* |
| 835 | Allocate memory for pixels. |
| 836 | */ |
| 837 | assert(image_info != (const ImageInfo *) NULL); |
| 838 | assert(image_info->signature == MagickSignature); |
| 839 | assert(image != (Image *) NULL); |
| 840 | assert(image->signature == MagickSignature); |
| 841 | if (image->debug != MagickFalse) |
| 842 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 843 | if (image_info->interlace != PartitionInterlace) |
| 844 | { |
| 845 | /* |
| 846 | Open output image file. |
| 847 | */ |
| 848 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); |
| 849 | if (status == MagickFalse) |
| 850 | return(status); |
| 851 | } |
| 852 | quantum_type=RGBQuantum; |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 853 | for (i=0; i < 4; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 854 | { |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 855 | if (image_info->magick[i] == '\0') |
| 856 | break; |
| 857 | switch(image_info->magick[i]) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 858 | { |
cristy | 2080f2b | 2010-08-21 18:43:15 +0000 | [diff] [blame^] | 859 | case 'R': quantum_types[i]=RedQuantum; break; |
| 860 | case 'G': quantum_types[i]=GreenQuantum; break; |
| 861 | case 'B': quantum_types[i]=BlueQuantum; break; |
| 862 | case 'A': |
| 863 | { |
| 864 | quantum_types[i]=AlphaQuantum; |
| 865 | quantum_type=RGBAQuantum; |
| 866 | break; |
| 867 | } |
| 868 | case 'O': |
| 869 | { |
| 870 | quantum_types[i]=OpacityQuantum; |
| 871 | quantum_type=RGBOQuantum; |
| 872 | break; |
| 873 | } |
| 874 | default: |
| 875 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 876 | } |
| 877 | } |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 878 | channels=i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 879 | scene=0; |
| 880 | do |
| 881 | { |
| 882 | /* |
| 883 | Convert MIFF to RGB raster pixels. |
| 884 | */ |
| 885 | if (image->colorspace != RGBColorspace) |
| 886 | (void) TransformImageColorspace(image,RGBColorspace); |
| 887 | if ((LocaleCompare(image_info->magick,"RGBA") == 0) && |
| 888 | (image->matte == MagickFalse)) |
| 889 | (void) SetImageAlphaChannel(image,ResetAlphaChannel); |
| 890 | quantum_info=AcquireQuantumInfo(image_info,image); |
| 891 | if (quantum_info == (QuantumInfo *) NULL) |
| 892 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 893 | pixels=GetQuantumPixels(quantum_info); |
| 894 | switch (image_info->interlace) |
| 895 | { |
| 896 | case NoInterlace: |
| 897 | default: |
| 898 | { |
| 899 | CacheView |
| 900 | *image_view; |
| 901 | |
| 902 | PixelPacket |
| 903 | px; |
| 904 | |
| 905 | Quantum |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 906 | *qx[4]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 907 | |
| 908 | /* |
| 909 | No interlacing: RGBRGBRGBRGBRGBRGB... |
| 910 | */ |
| 911 | image_view=AcquireCacheView(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 912 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 913 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 914 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 915 | x; |
| 916 | |
| 917 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 918 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 919 | |
| 920 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 921 | &image->exception); |
| 922 | if (q == (PixelPacket *) NULL) |
| 923 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 924 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 925 | { |
| 926 | px=(*q); |
| 927 | qx[0]=&(q->red); |
| 928 | qx[1]=&(q->green); |
| 929 | qx[2]=&(q->blue); |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 930 | qx[3]=&(q->opacity); |
| 931 | for (i=0; i < channels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 932 | switch (quantum_types[i]) |
| 933 | { |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 934 | case RedQuantum: *qx[i]=px.red; break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 935 | case GreenQuantum: *qx[i]=px.green; break; |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 936 | case BlueQuantum: *qx[i]=px.blue; break; |
| 937 | case AlphaQuantum: *qx[i]=px.opacity; break; |
| 938 | case OpacityQuantum: *qx[i]=px.opacity; break; |
| 939 | default: break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 940 | } |
| 941 | q++; |
| 942 | } |
| 943 | length=ExportQuantumPixels(image,image_view,quantum_info,quantum_type, |
| 944 | pixels,&image->exception); |
| 945 | count=WriteBlob(image,length,pixels); |
| 946 | if (count != (ssize_t) length) |
| 947 | break; |
| 948 | if (image->previous == (Image *) NULL) |
| 949 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 950 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 951 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 952 | if (status == MagickFalse) |
| 953 | break; |
| 954 | } |
| 955 | } |
| 956 | image_view=DestroyCacheView(image_view); |
| 957 | break; |
| 958 | } |
| 959 | case LineInterlace: |
| 960 | { |
| 961 | /* |
| 962 | Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB... |
| 963 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 964 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 965 | { |
| 966 | register const PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 967 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 968 | |
| 969 | p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); |
| 970 | if (p == (const PixelPacket *) NULL) |
| 971 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 972 | for (i=0; i < (ssize_t) channels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 973 | { |
| 974 | length=ExportQuantumPixels(image,(const CacheView *) NULL, |
| 975 | quantum_info,quantum_types[i],pixels,&image->exception); |
| 976 | count=WriteBlob(image,length,pixels); |
| 977 | if (count != (ssize_t) length) |
| 978 | break; |
| 979 | } |
| 980 | if (image->previous == (Image *) NULL) |
| 981 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 982 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 983 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 984 | if (status == MagickFalse) |
| 985 | break; |
| 986 | } |
| 987 | } |
| 988 | break; |
| 989 | } |
| 990 | case PlaneInterlace: |
| 991 | { |
| 992 | /* |
| 993 | Plane interlacing: RRRRRR...GGGGGG...BBBBBB... |
| 994 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 995 | for (i=0; i < (ssize_t) channels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 996 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 997 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 998 | { |
| 999 | register const PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1000 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1001 | |
| 1002 | p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); |
| 1003 | if (p == (const PixelPacket *) NULL) |
| 1004 | break; |
| 1005 | length=ExportQuantumPixels(image,(const CacheView *) NULL, |
| 1006 | quantum_info,quantum_types[i],pixels,&image->exception); |
| 1007 | count=WriteBlob(image,length,pixels); |
| 1008 | if (count != (ssize_t) length) |
| 1009 | break; |
| 1010 | } |
| 1011 | if (image->previous == (Image *) NULL) |
| 1012 | { |
| 1013 | status=SetImageProgress(image,SaveImageTag,(i+1),5); |
| 1014 | if (status == MagickFalse) |
| 1015 | break; |
| 1016 | } |
| 1017 | } |
| 1018 | if (image->previous == (Image *) NULL) |
| 1019 | { |
| 1020 | status=SetImageProgress(image,SaveImageTag,5,5); |
| 1021 | if (status == MagickFalse) |
| 1022 | break; |
| 1023 | } |
| 1024 | break; |
| 1025 | } |
| 1026 | case PartitionInterlace: |
| 1027 | { |
| 1028 | char |
| 1029 | sfx[] = {0, 0}; |
| 1030 | |
| 1031 | /* |
| 1032 | Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB... |
| 1033 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1034 | for (i=0; i < (ssize_t) channels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1035 | { |
| 1036 | sfx[0]=image_info->magick[i]; |
| 1037 | AppendImageFormat(sfx,image->filename); |
| 1038 | status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode : |
| 1039 | AppendBinaryBlobMode,&image->exception); |
| 1040 | if (status == MagickFalse) |
| 1041 | return(status); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1042 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1043 | { |
| 1044 | register const PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1045 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1046 | |
| 1047 | p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); |
| 1048 | if (p == (const PixelPacket *) NULL) |
| 1049 | break; |
| 1050 | length=ExportQuantumPixels(image,(const CacheView *) NULL, |
| 1051 | quantum_info,quantum_types[i],pixels,&image->exception); |
| 1052 | count=WriteBlob(image,length,pixels); |
| 1053 | if (count != (ssize_t) length) |
| 1054 | break; |
| 1055 | } |
| 1056 | if (image->previous == (Image *) NULL) |
| 1057 | { |
| 1058 | status=SetImageProgress(image,SaveImageTag,(i+1),5); |
| 1059 | if (status == MagickFalse) |
| 1060 | break; |
| 1061 | } |
| 1062 | (void) CloseBlob(image); |
| 1063 | } |
| 1064 | (void) CopyMagickString(image->filename,image_info->filename, |
| 1065 | MaxTextExtent); |
| 1066 | if (image->previous == (Image *) NULL) |
| 1067 | { |
| 1068 | status=SetImageProgress(image,SaveImageTag,5,5); |
| 1069 | if (status == MagickFalse) |
| 1070 | break; |
| 1071 | } |
| 1072 | break; |
| 1073 | } |
| 1074 | } |
| 1075 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 1076 | if (GetNextImageInList(image) == (Image *) NULL) |
| 1077 | break; |
| 1078 | image=SyncNextImageInList(image); |
| 1079 | status=SetImageProgress(image,SaveImagesTag,scene++, |
| 1080 | GetImageListLength(image)); |
| 1081 | if (status == MagickFalse) |
| 1082 | break; |
| 1083 | } while (image_info->adjoin != MagickFalse); |
| 1084 | (void) CloseBlob(image); |
| 1085 | return(MagickTrue); |
| 1086 | } |