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 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/blob-private.h" |
| 45 | #include "MagickCore/cache.h" |
| 46 | #include "MagickCore/colorspace.h" |
cristy | 510d06a | 2011-07-06 23:43:54 +0000 | [diff] [blame] | 47 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 48 | #include "MagickCore/constitute.h" |
| 49 | #include "MagickCore/exception.h" |
| 50 | #include "MagickCore/exception-private.h" |
| 51 | #include "MagickCore/image.h" |
| 52 | #include "MagickCore/image-private.h" |
| 53 | #include "MagickCore/list.h" |
| 54 | #include "MagickCore/magick.h" |
| 55 | #include "MagickCore/memory_.h" |
| 56 | #include "MagickCore/monitor.h" |
| 57 | #include "MagickCore/monitor-private.h" |
| 58 | #include "MagickCore/pixel-accessor.h" |
| 59 | #include "MagickCore/quantum-private.h" |
| 60 | #include "MagickCore/static.h" |
| 61 | #include "MagickCore/statistic.h" |
| 62 | #include "MagickCore/string_.h" |
| 63 | #include "MagickCore/module.h" |
| 64 | #include "MagickCore/utility.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 65 | |
| 66 | /* |
| 67 | Forward declarations. |
| 68 | */ |
| 69 | static MagickBooleanType |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 70 | WriteRGBImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 74 | % % |
| 75 | % % |
| 76 | % % |
| 77 | % R e a d R G B I m a g e % |
| 78 | % % |
| 79 | % % |
| 80 | % % |
| 81 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 82 | % |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 83 | % ReadRGBImage() reads an image of raw RGB, RGBA, or RGBO samples and returns |
| 84 | % it. It allocates the memory necessary for the new Image structure and |
| 85 | % returns a pointer to the new image. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 86 | % |
| 87 | % The format of the ReadRGBImage method is: |
| 88 | % |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 89 | % Image *ReadRGBImage(const ImageInfo *image_info, |
| 90 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 91 | % |
| 92 | % A description of each parameter follows: |
| 93 | % |
| 94 | % o image_info: the image info. |
| 95 | % |
| 96 | % o exception: return any errors or warnings in this structure. |
| 97 | % |
| 98 | */ |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 99 | static Image *ReadRGBImage(const ImageInfo *image_info, |
| 100 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 101 | { |
| 102 | Image |
| 103 | *canvas_image, |
| 104 | *image; |
| 105 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 | MagickBooleanType |
| 107 | status; |
| 108 | |
| 109 | MagickOffsetType |
| 110 | scene; |
| 111 | |
| 112 | QuantumInfo |
| 113 | *quantum_info; |
| 114 | |
| 115 | QuantumType |
| 116 | quantum_type; |
| 117 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 118 | register ssize_t |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 119 | i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 120 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 121 | size_t |
| 122 | length; |
| 123 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 124 | ssize_t |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 125 | count, |
| 126 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 127 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 128 | unsigned char |
| 129 | *pixels; |
| 130 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 131 | /* |
| 132 | Open image file. |
| 133 | */ |
| 134 | assert(image_info != (const ImageInfo *) NULL); |
| 135 | assert(image_info->signature == MagickSignature); |
| 136 | if (image_info->debug != MagickFalse) |
| 137 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 138 | image_info->filename); |
| 139 | assert(exception != (ExceptionInfo *) NULL); |
| 140 | assert(exception->signature == MagickSignature); |
| 141 | image=AcquireImage(image_info); |
| 142 | if ((image->columns == 0) || (image->rows == 0)) |
| 143 | ThrowReaderException(OptionError,"MustSpecifyImageSize"); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 144 | image->colorspace=RGBColorspace; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 145 | if (image_info->interlace != PartitionInterlace) |
| 146 | { |
| 147 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 148 | if (status == MagickFalse) |
| 149 | { |
| 150 | image=DestroyImageList(image); |
| 151 | return((Image *) NULL); |
| 152 | } |
cristy | d429702 | 2010-09-16 22:59:09 +0000 | [diff] [blame] | 153 | if (DiscardBlobBytes(image,image->offset) == MagickFalse) |
| 154 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 155 | image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 156 | } |
| 157 | /* |
| 158 | Create virtual canvas to support cropping (i.e. image.rgb[100x100+10+20]). |
| 159 | */ |
| 160 | canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse, |
| 161 | exception); |
| 162 | (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod); |
| 163 | quantum_info=AcquireQuantumInfo(image_info,canvas_image); |
| 164 | if (quantum_info == (QuantumInfo *) NULL) |
| 165 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 166 | pixels=GetQuantumPixels(quantum_info); |
| 167 | quantum_type=RGBQuantum; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 168 | if (LocaleCompare(image_info->magick,"RGBA") == 0) |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 169 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 170 | quantum_type=RGBAQuantum; |
| 171 | image->matte=MagickTrue; |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 172 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 173 | if (LocaleCompare(image_info->magick,"RGBO") == 0) |
| 174 | { |
| 175 | quantum_type=RGBOQuantum; |
| 176 | image->matte=MagickTrue; |
| 177 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 178 | if (image_info->number_scenes != 0) |
| 179 | while (image->scene < image_info->scene) |
| 180 | { |
| 181 | /* |
| 182 | Skip to next image. |
| 183 | */ |
| 184 | image->scene++; |
| 185 | length=GetQuantumExtent(canvas_image,quantum_info,quantum_type); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 186 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 187 | { |
| 188 | count=ReadBlob(image,length,pixels); |
| 189 | if (count != (ssize_t) length) |
| 190 | break; |
| 191 | } |
| 192 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 193 | count=0; |
| 194 | length=0; |
| 195 | scene=0; |
| 196 | do |
| 197 | { |
| 198 | /* |
| 199 | Read pixels to virtual canvas image then push to image. |
| 200 | */ |
| 201 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 202 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 203 | break; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 204 | image->colorspace=RGBColorspace; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 205 | switch (image_info->interlace) |
| 206 | { |
| 207 | case NoInterlace: |
| 208 | default: |
| 209 | { |
| 210 | /* |
| 211 | No interlacing: RGBRGBRGBRGBRGBRGB... |
| 212 | */ |
| 213 | if (scene == 0) |
| 214 | { |
| 215 | length=GetQuantumExtent(canvas_image,quantum_info,quantum_type); |
| 216 | count=ReadBlob(image,length,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 217 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 218 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 219 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 220 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 221 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 222 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 223 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 224 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 225 | |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 226 | register ssize_t |
| 227 | x; |
| 228 | |
cristy | 21da32d | 2009-09-12 14:56:09 +0000 | [diff] [blame] | 229 | if (count != (ssize_t) length) |
| 230 | { |
| 231 | ThrowFileException(exception,CorruptImageError, |
| 232 | "UnexpectedEndOfFile",image->filename); |
| 233 | break; |
| 234 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 235 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 236 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 237 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 238 | break; |
| 239 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 240 | quantum_info,quantum_type,pixels,exception); |
| 241 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 242 | break; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 243 | if (((y-image->extract_info.y) >= 0) && |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 244 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 245 | { |
| 246 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 247 | canvas_image->columns,1,exception); |
| 248 | q=QueueAuthenticPixels(image,0,y-image->extract_info.y, |
| 249 | image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 250 | if ((p == (const Quantum *) NULL) || |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 251 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 252 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 253 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 254 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 255 | SetPixelRed(image,GetPixelRed(canvas_image,p),q); |
| 256 | SetPixelGreen(image,GetPixelGreen(canvas_image,p),q); |
| 257 | SetPixelBlue(image,GetPixelBlue(canvas_image,p),q); |
| 258 | SetPixelAlpha(image,OpaqueAlpha,q); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 259 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 260 | SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 261 | p+=GetPixelChannels(canvas_image); |
| 262 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 263 | } |
| 264 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 265 | break; |
| 266 | } |
| 267 | if (image->previous == (Image *) NULL) |
| 268 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 269 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 270 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 271 | if (status == MagickFalse) |
| 272 | break; |
| 273 | } |
| 274 | count=ReadBlob(image,length,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 275 | } |
| 276 | break; |
| 277 | } |
| 278 | case LineInterlace: |
| 279 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 280 | static QuantumType |
| 281 | quantum_types[4] = |
| 282 | { |
| 283 | RedQuantum, |
| 284 | GreenQuantum, |
| 285 | BlueQuantum, |
| 286 | AlphaQuantum |
| 287 | }; |
| 288 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 289 | /* |
| 290 | Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB... |
| 291 | */ |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 292 | if (LocaleCompare(image_info->magick,"RGBO") == 0) |
| 293 | quantum_types[3]=OpacityQuantum; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 294 | if (scene == 0) |
| 295 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 296 | length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 297 | count=ReadBlob(image,length,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 298 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 299 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 300 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 301 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 302 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 303 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 304 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 305 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 306 | |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 307 | register ssize_t |
| 308 | x; |
| 309 | |
cristy | 21da32d | 2009-09-12 14:56:09 +0000 | [diff] [blame] | 310 | if (count != (ssize_t) length) |
| 311 | { |
| 312 | ThrowFileException(exception,CorruptImageError, |
| 313 | "UnexpectedEndOfFile",image->filename); |
| 314 | break; |
| 315 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 316 | for (i=0; i < (ssize_t) (image->matte != MagickFalse ? 4 : 3); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 317 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 318 | quantum_type=quantum_types[i]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 319 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 320 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 321 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 322 | break; |
| 323 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 324 | quantum_info,quantum_type,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 325 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 326 | break; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 327 | if (((y-image->extract_info.y) >= 0) && |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 328 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 329 | { |
| 330 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x, |
| 331 | 0,canvas_image->columns,1,exception); |
| 332 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 333 | image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 334 | if ((p == (const Quantum *) NULL) || |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 335 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 336 | break; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 337 | for (x=0; x < (ssize_t) image->columns; x++) |
| 338 | { |
| 339 | switch (quantum_type) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 340 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 341 | case RedQuantum: |
| 342 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 343 | SetPixelRed(image,GetPixelRed(canvas_image,p),q); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 344 | break; |
| 345 | } |
| 346 | case GreenQuantum: |
| 347 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 348 | SetPixelGreen(image,GetPixelGreen(canvas_image,p),q); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 349 | break; |
| 350 | } |
| 351 | case BlueQuantum: |
| 352 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 353 | SetPixelBlue(image,GetPixelBlue(canvas_image,p),q); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 354 | break; |
| 355 | } |
| 356 | case OpacityQuantum: |
| 357 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 358 | SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 359 | break; |
| 360 | } |
| 361 | case AlphaQuantum: |
| 362 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 363 | SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 364 | break; |
| 365 | } |
| 366 | default: |
| 367 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 368 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 369 | p+=GetPixelChannels(canvas_image); |
| 370 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 371 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 372 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 373 | break; |
| 374 | } |
| 375 | count=ReadBlob(image,length,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 376 | } |
| 377 | if (image->previous == (Image *) NULL) |
| 378 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 379 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 380 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 381 | if (status == MagickFalse) |
| 382 | break; |
| 383 | } |
| 384 | } |
| 385 | break; |
| 386 | } |
| 387 | case PlaneInterlace: |
| 388 | { |
| 389 | /* |
| 390 | Plane interlacing: RRRRRR...GGGGGG...BBBBBB... |
| 391 | */ |
| 392 | if (scene == 0) |
| 393 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 394 | length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 395 | count=ReadBlob(image,length,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 396 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 397 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 398 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 399 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 400 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 401 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 402 | register Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 403 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 404 | |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 405 | register ssize_t |
| 406 | x; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 407 | |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 408 | if (count != (ssize_t) length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 409 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 410 | ThrowFileException(exception,CorruptImageError, |
| 411 | "UnexpectedEndOfFile",image->filename); |
| 412 | break; |
| 413 | } |
| 414 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 415 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 416 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 417 | break; |
| 418 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 419 | quantum_info,RedQuantum,pixels,exception); |
| 420 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 421 | break; |
| 422 | if (((y-image->extract_info.y) >= 0) && |
| 423 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 424 | { |
| 425 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 426 | canvas_image->columns,1,exception); |
| 427 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 428 | image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 429 | if ((p == (const Quantum *) NULL) || |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 430 | (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 431 | break; |
| 432 | for (x=0; x < (ssize_t) image->columns; x++) |
| 433 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 434 | SetPixelRed(image,GetPixelRed(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 435 | p+=GetPixelChannels(canvas_image); |
| 436 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 437 | } |
| 438 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 439 | break; |
| 440 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 441 | count=ReadBlob(image,length,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 442 | } |
| 443 | if (image->previous == (Image *) NULL) |
| 444 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 445 | status=SetImageProgress(image,LoadImageTag,1,6); |
| 446 | if (status == MagickFalse) |
| 447 | break; |
| 448 | } |
| 449 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 450 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 451 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 452 | *restrict p; |
| 453 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 454 | register Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 455 | *restrict q; |
| 456 | |
| 457 | register ssize_t |
| 458 | x; |
| 459 | |
| 460 | if (count != (ssize_t) length) |
| 461 | { |
| 462 | ThrowFileException(exception,CorruptImageError, |
| 463 | "UnexpectedEndOfFile",image->filename); |
| 464 | break; |
| 465 | } |
| 466 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 467 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 468 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 469 | break; |
| 470 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 471 | quantum_info,GreenQuantum,pixels,exception); |
| 472 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 473 | break; |
| 474 | if (((y-image->extract_info.y) >= 0) && |
| 475 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 476 | { |
| 477 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 478 | canvas_image->columns,1,exception); |
| 479 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 480 | image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 481 | if ((p == (const Quantum *) NULL) || |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 482 | (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 483 | break; |
| 484 | for (x=0; x < (ssize_t) image->columns; x++) |
| 485 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 486 | SetPixelGreen(image, |
| 487 | GetPixelGreen(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 488 | p+=GetPixelChannels(canvas_image); |
| 489 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 490 | } |
| 491 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 492 | break; |
| 493 | } |
| 494 | count=ReadBlob(image,length,pixels); |
| 495 | } |
| 496 | if (image->previous == (Image *) NULL) |
| 497 | { |
| 498 | status=SetImageProgress(image,LoadImageTag,2,6); |
| 499 | if (status == MagickFalse) |
| 500 | break; |
| 501 | } |
| 502 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 503 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 504 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 505 | *restrict p; |
| 506 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 507 | register Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 508 | *restrict q; |
| 509 | |
| 510 | register ssize_t |
| 511 | x; |
| 512 | |
| 513 | if (count != (ssize_t) length) |
| 514 | { |
| 515 | ThrowFileException(exception,CorruptImageError, |
| 516 | "UnexpectedEndOfFile",image->filename); |
| 517 | break; |
| 518 | } |
| 519 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 520 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 521 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 522 | break; |
| 523 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 524 | quantum_info,BlueQuantum,pixels,exception); |
| 525 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 526 | break; |
| 527 | if (((y-image->extract_info.y) >= 0) && |
| 528 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 529 | { |
| 530 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 531 | canvas_image->columns,1,exception); |
| 532 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 533 | image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 534 | if ((p == (const Quantum *) NULL) || |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 535 | (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 536 | break; |
| 537 | for (x=0; x < (ssize_t) image->columns; x++) |
| 538 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 539 | SetPixelBlue(image, |
| 540 | GetPixelBlue(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 541 | p+=GetPixelChannels(canvas_image); |
| 542 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 543 | } |
| 544 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 545 | break; |
| 546 | } |
| 547 | count=ReadBlob(image,length,pixels); |
| 548 | } |
| 549 | if (image->previous == (Image *) NULL) |
| 550 | { |
| 551 | status=SetImageProgress(image,LoadImageTag,3,6); |
| 552 | if (status == MagickFalse) |
| 553 | break; |
| 554 | } |
| 555 | if (image->previous == (Image *) NULL) |
| 556 | { |
| 557 | status=SetImageProgress(image,LoadImageTag,4,6); |
| 558 | if (status == MagickFalse) |
| 559 | break; |
| 560 | } |
| 561 | if (image->matte != MagickFalse) |
| 562 | { |
| 563 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 564 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 565 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 566 | *restrict p; |
| 567 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 568 | register Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 569 | *restrict q; |
| 570 | |
| 571 | register ssize_t |
| 572 | x; |
| 573 | |
| 574 | if (count != (ssize_t) length) |
| 575 | { |
| 576 | ThrowFileException(exception,CorruptImageError, |
| 577 | "UnexpectedEndOfFile",image->filename); |
| 578 | break; |
| 579 | } |
| 580 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 581 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 582 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 583 | break; |
| 584 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 585 | quantum_info,AlphaQuantum,pixels,exception); |
| 586 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 587 | break; |
| 588 | if (((y-image->extract_info.y) >= 0) && |
| 589 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 590 | { |
| 591 | p=GetVirtualPixels(canvas_image, |
| 592 | canvas_image->extract_info.x,0,canvas_image->columns,1, |
| 593 | exception); |
| 594 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 595 | image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 596 | if ((p == (const Quantum *) NULL) || |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 597 | (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 598 | break; |
| 599 | for (x=0; x < (ssize_t) image->columns; x++) |
| 600 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 601 | SetPixelAlpha(image, |
| 602 | GetPixelAlpha(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 603 | p+=GetPixelChannels(canvas_image); |
| 604 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 605 | } |
| 606 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 607 | break; |
| 608 | } |
| 609 | count=ReadBlob(image,length,pixels); |
| 610 | } |
| 611 | if (image->previous == (Image *) NULL) |
| 612 | { |
| 613 | status=SetImageProgress(image,LoadImageTag,5,6); |
| 614 | if (status == MagickFalse) |
| 615 | break; |
| 616 | } |
| 617 | } |
| 618 | if (image->previous == (Image *) NULL) |
| 619 | { |
| 620 | status=SetImageProgress(image,LoadImageTag,6,6); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 621 | if (status == MagickFalse) |
| 622 | break; |
| 623 | } |
| 624 | break; |
| 625 | } |
| 626 | case PartitionInterlace: |
| 627 | { |
| 628 | /* |
| 629 | Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB... |
| 630 | */ |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 631 | AppendImageFormat("R",image->filename); |
| 632 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 633 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 634 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 635 | canvas_image=DestroyImageList(canvas_image); |
| 636 | image=DestroyImageList(image); |
| 637 | return((Image *) NULL); |
| 638 | } |
cristy | d429702 | 2010-09-16 22:59:09 +0000 | [diff] [blame] | 639 | if (DiscardBlobBytes(image,image->offset) == MagickFalse) |
| 640 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 641 | image->filename); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 642 | length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum); |
| 643 | for (i=0; i < (ssize_t) scene; i++) |
| 644 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 645 | if (ReadBlob(image,length,pixels) != (ssize_t) length) |
cristy | 21da32d | 2009-09-12 14:56:09 +0000 | [diff] [blame] | 646 | { |
| 647 | ThrowFileException(exception,CorruptImageError, |
| 648 | "UnexpectedEndOfFile",image->filename); |
| 649 | break; |
| 650 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 651 | count=ReadBlob(image,length,pixels); |
| 652 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 653 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 654 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 655 | *restrict p; |
| 656 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 657 | register Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 658 | *restrict q; |
| 659 | |
| 660 | register ssize_t |
| 661 | x; |
| 662 | |
| 663 | if (count != (ssize_t) length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 664 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 665 | ThrowFileException(exception,CorruptImageError, |
| 666 | "UnexpectedEndOfFile",image->filename); |
| 667 | break; |
| 668 | } |
| 669 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 670 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 671 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 672 | break; |
| 673 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 674 | quantum_info,RedQuantum,pixels,exception); |
| 675 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 676 | break; |
| 677 | if (((y-image->extract_info.y) >= 0) && |
| 678 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 679 | { |
| 680 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 681 | canvas_image->columns,1,exception); |
| 682 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 683 | image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 684 | if ((p == (const Quantum *) NULL) || |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 685 | (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 686 | break; |
| 687 | for (x=0; x < (ssize_t) image->columns; x++) |
| 688 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 689 | SetPixelRed(image,GetPixelRed(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 690 | p+=GetPixelChannels(canvas_image); |
| 691 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 692 | } |
| 693 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 694 | break; |
| 695 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 696 | count=ReadBlob(image,length,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 697 | } |
| 698 | if (image->previous == (Image *) NULL) |
| 699 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 700 | status=SetImageProgress(image,LoadImageTag,1,5); |
| 701 | if (status == MagickFalse) |
| 702 | break; |
| 703 | } |
| 704 | (void) CloseBlob(image); |
| 705 | AppendImageFormat("G",image->filename); |
| 706 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 707 | if (status == MagickFalse) |
| 708 | { |
| 709 | canvas_image=DestroyImageList(canvas_image); |
| 710 | image=DestroyImageList(image); |
| 711 | return((Image *) NULL); |
| 712 | } |
| 713 | length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum); |
| 714 | for (i=0; i < (ssize_t) scene; i++) |
| 715 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 716 | if (ReadBlob(image,length,pixels) != (ssize_t) length) |
| 717 | { |
| 718 | ThrowFileException(exception,CorruptImageError, |
| 719 | "UnexpectedEndOfFile",image->filename); |
| 720 | break; |
| 721 | } |
| 722 | count=ReadBlob(image,length,pixels); |
| 723 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 724 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 725 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 726 | *restrict p; |
| 727 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 728 | register Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 729 | *restrict q; |
| 730 | |
| 731 | register ssize_t |
| 732 | x; |
| 733 | |
| 734 | if (count != (ssize_t) length) |
| 735 | { |
| 736 | ThrowFileException(exception,CorruptImageError, |
| 737 | "UnexpectedEndOfFile",image->filename); |
| 738 | break; |
| 739 | } |
| 740 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 741 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 742 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 743 | break; |
| 744 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 745 | quantum_info,GreenQuantum,pixels,exception); |
| 746 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 747 | break; |
| 748 | if (((y-image->extract_info.y) >= 0) && |
| 749 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 750 | { |
| 751 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 752 | canvas_image->columns,1,exception); |
| 753 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 754 | image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 755 | if ((p == (const Quantum *) NULL) || |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 756 | (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 757 | break; |
| 758 | for (x=0; x < (ssize_t) image->columns; x++) |
| 759 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 760 | SetPixelGreen(image, |
| 761 | GetPixelGreen(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 762 | p+=GetPixelChannels(canvas_image); |
| 763 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 764 | } |
| 765 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 766 | break; |
| 767 | } |
| 768 | count=ReadBlob(image,length,pixels); |
| 769 | } |
| 770 | if (image->previous == (Image *) NULL) |
| 771 | { |
| 772 | status=SetImageProgress(image,LoadImageTag,2,5); |
| 773 | if (status == MagickFalse) |
| 774 | break; |
| 775 | } |
| 776 | (void) CloseBlob(image); |
| 777 | AppendImageFormat("B",image->filename); |
| 778 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 779 | if (status == MagickFalse) |
| 780 | { |
| 781 | canvas_image=DestroyImageList(canvas_image); |
| 782 | image=DestroyImageList(image); |
| 783 | return((Image *) NULL); |
| 784 | } |
| 785 | length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum); |
| 786 | for (i=0; i < (ssize_t) scene; i++) |
| 787 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 788 | if (ReadBlob(image,length,pixels) != (ssize_t) length) |
| 789 | { |
| 790 | ThrowFileException(exception,CorruptImageError, |
| 791 | "UnexpectedEndOfFile",image->filename); |
| 792 | break; |
| 793 | } |
| 794 | count=ReadBlob(image,length,pixels); |
| 795 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 796 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 797 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 798 | *restrict p; |
| 799 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 800 | register Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 801 | *restrict q; |
| 802 | |
| 803 | register ssize_t |
| 804 | x; |
| 805 | |
| 806 | if (count != (ssize_t) length) |
| 807 | { |
| 808 | ThrowFileException(exception,CorruptImageError, |
| 809 | "UnexpectedEndOfFile",image->filename); |
| 810 | break; |
| 811 | } |
| 812 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 813 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 814 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 815 | break; |
| 816 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 817 | quantum_info,BlueQuantum,pixels,exception); |
| 818 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 819 | break; |
| 820 | if (((y-image->extract_info.y) >= 0) && |
| 821 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 822 | { |
| 823 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 824 | canvas_image->columns,1,exception); |
| 825 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 826 | image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 827 | if ((p == (const Quantum *) NULL) || |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 828 | (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 829 | break; |
| 830 | for (x=0; x < (ssize_t) image->columns; x++) |
| 831 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 832 | SetPixelBlue(image, |
| 833 | GetPixelBlue(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 834 | p+=GetPixelChannels(canvas_image); |
| 835 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 836 | } |
| 837 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 838 | break; |
| 839 | } |
| 840 | count=ReadBlob(image,length,pixels); |
| 841 | } |
| 842 | if (image->previous == (Image *) NULL) |
| 843 | { |
| 844 | status=SetImageProgress(image,LoadImageTag,3,5); |
| 845 | if (status == MagickFalse) |
| 846 | break; |
| 847 | } |
| 848 | if (image->matte != MagickFalse) |
| 849 | { |
| 850 | (void) CloseBlob(image); |
| 851 | AppendImageFormat("A",image->filename); |
| 852 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 853 | if (status == MagickFalse) |
| 854 | { |
| 855 | canvas_image=DestroyImageList(canvas_image); |
| 856 | image=DestroyImageList(image); |
| 857 | return((Image *) NULL); |
| 858 | } |
| 859 | length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum); |
| 860 | for (i=0; i < (ssize_t) scene; i++) |
| 861 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 862 | if (ReadBlob(image,length,pixels) != (ssize_t) length) |
| 863 | { |
| 864 | ThrowFileException(exception,CorruptImageError, |
| 865 | "UnexpectedEndOfFile",image->filename); |
| 866 | break; |
| 867 | } |
| 868 | count=ReadBlob(image,length,pixels); |
| 869 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 870 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 871 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 872 | *restrict p; |
| 873 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 874 | register Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 875 | *restrict q; |
| 876 | |
| 877 | register ssize_t |
| 878 | x; |
| 879 | |
| 880 | if (count != (ssize_t) length) |
| 881 | { |
| 882 | ThrowFileException(exception,CorruptImageError, |
| 883 | "UnexpectedEndOfFile",image->filename); |
| 884 | break; |
| 885 | } |
| 886 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 887 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 888 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 889 | break; |
| 890 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 891 | quantum_info,BlueQuantum,pixels,exception); |
| 892 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 893 | break; |
| 894 | if (((y-image->extract_info.y) >= 0) && |
| 895 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 896 | { |
| 897 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x, |
| 898 | 0,canvas_image->columns,1,exception); |
| 899 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 900 | image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 901 | if ((p == (const Quantum *) NULL) || |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 902 | (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 903 | break; |
| 904 | for (x=0; x < (ssize_t) image->columns; x++) |
| 905 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 906 | SetPixelAlpha(image, |
| 907 | GetPixelAlpha(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 908 | p+=GetPixelChannels(canvas_image); |
| 909 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 910 | } |
| 911 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 912 | break; |
| 913 | } |
| 914 | count=ReadBlob(image,length,pixels); |
| 915 | } |
| 916 | if (image->previous == (Image *) NULL) |
| 917 | { |
| 918 | status=SetImageProgress(image,LoadImageTag,4,5); |
| 919 | if (status == MagickFalse) |
| 920 | break; |
| 921 | } |
| 922 | } |
| 923 | (void) CloseBlob(image); |
| 924 | if (image->previous == (Image *) NULL) |
| 925 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 926 | status=SetImageProgress(image,LoadImageTag,5,5); |
| 927 | if (status == MagickFalse) |
| 928 | break; |
| 929 | } |
| 930 | break; |
| 931 | } |
| 932 | } |
| 933 | SetQuantumImageType(image,quantum_type); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 934 | /* |
| 935 | Proceed to next image. |
| 936 | */ |
| 937 | if (image_info->number_scenes != 0) |
| 938 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 939 | break; |
| 940 | if (count == (ssize_t) length) |
| 941 | { |
| 942 | /* |
| 943 | Allocate next image structure. |
| 944 | */ |
| 945 | AcquireNextImage(image_info,image); |
| 946 | if (GetNextImageInList(image) == (Image *) NULL) |
| 947 | { |
| 948 | image=DestroyImageList(image); |
| 949 | return((Image *) NULL); |
| 950 | } |
| 951 | image=SyncNextImageInList(image); |
| 952 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 953 | GetBlobSize(image)); |
| 954 | if (status == MagickFalse) |
| 955 | break; |
| 956 | } |
| 957 | scene++; |
| 958 | } while (count == (ssize_t) length); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 959 | quantum_info=DestroyQuantumInfo(quantum_info); |
cristy | 01a3f33 | 2009-10-27 14:17:37 +0000 | [diff] [blame] | 960 | InheritException(&image->exception,&canvas_image->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 961 | canvas_image=DestroyImage(canvas_image); |
| 962 | (void) CloseBlob(image); |
| 963 | return(GetFirstImageInList(image)); |
| 964 | } |
| 965 | |
| 966 | /* |
| 967 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 968 | % % |
| 969 | % % |
| 970 | % % |
| 971 | % R e g i s t e r R G B I m a g e % |
| 972 | % % |
| 973 | % % |
| 974 | % % |
| 975 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 976 | % |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 977 | % RegisterRGBImage() adds attributes for the RGB image format to |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 978 | % the list of supported formats. The attributes include the image format |
| 979 | % tag, a method to read and/or write the format, whether the format |
| 980 | % supports the saving of more than one frame to the same file or blob, |
| 981 | % whether the format supports native in-memory I/O, and a brief |
| 982 | % description of the format. |
| 983 | % |
| 984 | % The format of the RegisterRGBImage method is: |
| 985 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 986 | % size_t RegisterRGBImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 987 | % |
| 988 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 989 | ModuleExport size_t RegisterRGBImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 990 | { |
| 991 | MagickInfo |
| 992 | *entry; |
| 993 | |
| 994 | entry=SetMagickInfo("RGB"); |
| 995 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 996 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
| 997 | entry->raw=MagickTrue; |
| 998 | entry->endian_support=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 999 | entry->description=ConstantString("Raw red, green, and blue samples"); |
| 1000 | entry->module=ConstantString("RGB"); |
| 1001 | (void) RegisterMagickInfo(entry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1002 | entry=SetMagickInfo("RGBA"); |
| 1003 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 1004 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
| 1005 | entry->raw=MagickTrue; |
| 1006 | entry->endian_support=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1007 | entry->description=ConstantString("Raw red, green, blue, and alpha samples"); |
| 1008 | entry->module=ConstantString("RGB"); |
| 1009 | (void) RegisterMagickInfo(entry); |
| 1010 | entry=SetMagickInfo("RGBO"); |
| 1011 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 1012 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
| 1013 | entry->raw=MagickTrue; |
| 1014 | entry->endian_support=MagickTrue; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1015 | entry->description=ConstantString("Raw red, green, blue, and opacity samples"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1016 | entry->module=ConstantString("RGB"); |
| 1017 | (void) RegisterMagickInfo(entry); |
| 1018 | return(MagickImageCoderSignature); |
| 1019 | } |
| 1020 | |
| 1021 | /* |
| 1022 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1023 | % % |
| 1024 | % % |
| 1025 | % % |
| 1026 | % U n r e g i s t e r R G B I m a g e % |
| 1027 | % % |
| 1028 | % % |
| 1029 | % % |
| 1030 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1031 | % |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1032 | % UnregisterRGBImage() removes format registrations made by the RGB module |
| 1033 | % from the list of supported formats. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1034 | % |
| 1035 | % The format of the UnregisterRGBImage method is: |
| 1036 | % |
| 1037 | % UnregisterRGBImage(void) |
| 1038 | % |
| 1039 | */ |
| 1040 | ModuleExport void UnregisterRGBImage(void) |
| 1041 | { |
| 1042 | (void) UnregisterMagickInfo("RGBO"); |
| 1043 | (void) UnregisterMagickInfo("RGBA"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1044 | (void) UnregisterMagickInfo("RGB"); |
| 1045 | } |
| 1046 | |
| 1047 | /* |
| 1048 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1049 | % % |
| 1050 | % % |
| 1051 | % % |
| 1052 | % W r i t e R G B I m a g e % |
| 1053 | % % |
| 1054 | % % |
| 1055 | % % |
| 1056 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1057 | % |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1058 | % WriteRGBImage() writes an image to a file in the RGB, RGBA, or RGBO |
| 1059 | % rasterfile format. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1060 | % |
| 1061 | % The format of the WriteRGBImage method is: |
| 1062 | % |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1063 | % MagickBooleanType WriteRGBImage(const ImageInfo *image_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1064 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1065 | % |
| 1066 | % A description of each parameter follows. |
| 1067 | % |
| 1068 | % o image_info: the image info. |
| 1069 | % |
| 1070 | % o image: The image. |
| 1071 | % |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1072 | % o exception: return any errors or warnings in this structure. |
| 1073 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1074 | */ |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1075 | static MagickBooleanType WriteRGBImage(const ImageInfo *image_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1076 | Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1077 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1078 | MagickBooleanType |
| 1079 | status; |
| 1080 | |
| 1081 | MagickOffsetType |
| 1082 | scene; |
| 1083 | |
| 1084 | QuantumInfo |
| 1085 | *quantum_info; |
| 1086 | |
| 1087 | QuantumType |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1088 | quantum_type; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1089 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 1090 | size_t |
| 1091 | length; |
| 1092 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1093 | ssize_t |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1094 | count, |
| 1095 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1096 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1097 | unsigned char |
| 1098 | *pixels; |
| 1099 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1100 | /* |
| 1101 | Allocate memory for pixels. |
| 1102 | */ |
| 1103 | assert(image_info != (const ImageInfo *) NULL); |
| 1104 | assert(image_info->signature == MagickSignature); |
| 1105 | assert(image != (Image *) NULL); |
| 1106 | assert(image->signature == MagickSignature); |
| 1107 | if (image->debug != MagickFalse) |
| 1108 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1109 | if (image_info->interlace != PartitionInterlace) |
| 1110 | { |
| 1111 | /* |
| 1112 | Open output image file. |
| 1113 | */ |
cristy | edf03fa | 2011-08-30 12:44:39 +0000 | [diff] [blame] | 1114 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1115 | if (status == MagickFalse) |
| 1116 | return(status); |
| 1117 | } |
| 1118 | quantum_type=RGBQuantum; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1119 | if (LocaleCompare(image_info->magick,"RGBA") == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1120 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1121 | quantum_type=RGBAQuantum; |
| 1122 | image->matte=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1123 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1124 | if (LocaleCompare(image_info->magick,"RGBO") == 0) |
| 1125 | { |
| 1126 | quantum_type=RGBOQuantum; |
| 1127 | image->matte=MagickTrue; |
| 1128 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1129 | scene=0; |
| 1130 | do |
| 1131 | { |
| 1132 | /* |
| 1133 | Convert MIFF to RGB raster pixels. |
| 1134 | */ |
cristy | 510d06a | 2011-07-06 23:43:54 +0000 | [diff] [blame] | 1135 | if (IsRGBColorspace(image->colorspace) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1136 | (void) TransformImageColorspace(image,RGBColorspace); |
| 1137 | if ((LocaleCompare(image_info->magick,"RGBA") == 0) && |
| 1138 | (image->matte == MagickFalse)) |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1139 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1140 | quantum_info=AcquireQuantumInfo(image_info,image); |
| 1141 | if (quantum_info == (QuantumInfo *) NULL) |
| 1142 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 1143 | pixels=GetQuantumPixels(quantum_info); |
| 1144 | switch (image_info->interlace) |
| 1145 | { |
| 1146 | case NoInterlace: |
| 1147 | default: |
| 1148 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1149 | /* |
| 1150 | No interlacing: RGBRGBRGBRGBRGBRGB... |
| 1151 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1152 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1153 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1154 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1155 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1156 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1157 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1158 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1159 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1160 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1161 | quantum_type,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1162 | count=WriteBlob(image,length,pixels); |
| 1163 | if (count != (ssize_t) length) |
| 1164 | break; |
| 1165 | if (image->previous == (Image *) NULL) |
| 1166 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1167 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 1168 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1169 | if (status == MagickFalse) |
| 1170 | break; |
| 1171 | } |
| 1172 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1173 | break; |
| 1174 | } |
| 1175 | case LineInterlace: |
| 1176 | { |
| 1177 | /* |
| 1178 | Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB... |
| 1179 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1180 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1181 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1182 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1183 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1184 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1185 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1186 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1187 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1188 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1189 | RedQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1190 | count=WriteBlob(image,length,pixels); |
| 1191 | if (count != (ssize_t) length) |
| 1192 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1193 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1194 | GreenQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1195 | count=WriteBlob(image,length,pixels); |
| 1196 | if (count != (ssize_t) length) |
| 1197 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1198 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1199 | BlueQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1200 | count=WriteBlob(image,length,pixels); |
| 1201 | if (count != (ssize_t) length) |
| 1202 | break; |
| 1203 | if (quantum_type == RGBAQuantum) |
| 1204 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1205 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1206 | AlphaQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1207 | count=WriteBlob(image,length,pixels); |
| 1208 | if (count != (ssize_t) length) |
| 1209 | break; |
| 1210 | } |
| 1211 | if (quantum_type == RGBOQuantum) |
| 1212 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1213 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1214 | OpacityQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1215 | count=WriteBlob(image,length,pixels); |
| 1216 | if (count != (ssize_t) length) |
| 1217 | break; |
| 1218 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1219 | if (image->previous == (Image *) NULL) |
| 1220 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1221 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 1222 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1223 | if (status == MagickFalse) |
| 1224 | break; |
| 1225 | } |
| 1226 | } |
| 1227 | break; |
| 1228 | } |
| 1229 | case PlaneInterlace: |
| 1230 | { |
| 1231 | /* |
| 1232 | Plane interlacing: RRRRRR...GGGGGG...BBBBBB... |
| 1233 | */ |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1234 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1235 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1236 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1237 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1238 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1239 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1240 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1241 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1242 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1243 | RedQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1244 | count=WriteBlob(image,length,pixels); |
| 1245 | if (count != (ssize_t) length) |
| 1246 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1247 | } |
| 1248 | if (image->previous == (Image *) NULL) |
| 1249 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1250 | status=SetImageProgress(image,SaveImageTag,1,6); |
| 1251 | if (status == MagickFalse) |
| 1252 | break; |
| 1253 | } |
| 1254 | for (y=0; y < (ssize_t) image->rows; y++) |
| 1255 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1256 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1257 | *restrict p; |
| 1258 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1259 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1260 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1261 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1262 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1263 | GreenQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1264 | count=WriteBlob(image,length,pixels); |
| 1265 | if (count != (ssize_t) length) |
| 1266 | break; |
| 1267 | } |
| 1268 | if (image->previous == (Image *) NULL) |
| 1269 | { |
| 1270 | status=SetImageProgress(image,SaveImageTag,2,6); |
| 1271 | if (status == MagickFalse) |
| 1272 | break; |
| 1273 | } |
| 1274 | for (y=0; y < (ssize_t) image->rows; y++) |
| 1275 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1276 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1277 | *restrict p; |
| 1278 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1279 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1280 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1281 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1282 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1283 | BlueQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1284 | count=WriteBlob(image,length,pixels); |
| 1285 | if (count != (ssize_t) length) |
| 1286 | break; |
| 1287 | } |
| 1288 | if (image->previous == (Image *) NULL) |
| 1289 | { |
| 1290 | status=SetImageProgress(image,SaveImageTag,3,6); |
| 1291 | if (status == MagickFalse) |
| 1292 | break; |
| 1293 | } |
| 1294 | if (quantum_type == RGBAQuantum) |
| 1295 | { |
| 1296 | for (y=0; y < (ssize_t) image->rows; y++) |
| 1297 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1298 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1299 | *restrict p; |
| 1300 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1301 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1302 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1303 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1304 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1305 | AlphaQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1306 | count=WriteBlob(image,length,pixels); |
| 1307 | if (count != (ssize_t) length) |
| 1308 | break; |
| 1309 | } |
| 1310 | if (image->previous == (Image *) NULL) |
| 1311 | { |
| 1312 | status=SetImageProgress(image,SaveImageTag,5,6); |
| 1313 | if (status == MagickFalse) |
| 1314 | break; |
| 1315 | } |
| 1316 | } |
| 1317 | if (image_info->interlace == PartitionInterlace) |
| 1318 | (void) CopyMagickString(image->filename,image_info->filename, |
| 1319 | MaxTextExtent); |
| 1320 | if (image->previous == (Image *) NULL) |
| 1321 | { |
| 1322 | status=SetImageProgress(image,SaveImageTag,6,6); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1323 | if (status == MagickFalse) |
| 1324 | break; |
| 1325 | } |
| 1326 | break; |
| 1327 | } |
| 1328 | case PartitionInterlace: |
| 1329 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1330 | /* |
| 1331 | Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB... |
| 1332 | */ |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1333 | AppendImageFormat("R",image->filename); |
| 1334 | status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode : |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1335 | AppendBinaryBlobMode,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1336 | if (status == MagickFalse) |
| 1337 | return(status); |
| 1338 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1339 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1340 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1341 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1342 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1343 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1344 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1345 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1346 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1347 | RedQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1348 | count=WriteBlob(image,length,pixels); |
| 1349 | if (count != (ssize_t) length) |
| 1350 | break; |
| 1351 | } |
| 1352 | if (image->previous == (Image *) NULL) |
| 1353 | { |
| 1354 | status=SetImageProgress(image,SaveImageTag,1,6); |
| 1355 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1356 | break; |
| 1357 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1358 | (void) CloseBlob(image); |
| 1359 | AppendImageFormat("G",image->filename); |
| 1360 | status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode : |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1361 | AppendBinaryBlobMode,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1362 | if (status == MagickFalse) |
| 1363 | return(status); |
| 1364 | for (y=0; y < (ssize_t) image->rows; y++) |
| 1365 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1366 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1367 | *restrict p; |
| 1368 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1369 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1370 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1371 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1372 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1373 | GreenQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1374 | count=WriteBlob(image,length,pixels); |
| 1375 | if (count != (ssize_t) length) |
| 1376 | break; |
| 1377 | } |
| 1378 | if (image->previous == (Image *) NULL) |
| 1379 | { |
| 1380 | status=SetImageProgress(image,SaveImageTag,2,6); |
| 1381 | if (status == MagickFalse) |
| 1382 | break; |
| 1383 | } |
| 1384 | (void) CloseBlob(image); |
| 1385 | AppendImageFormat("B",image->filename); |
| 1386 | status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode : |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1387 | AppendBinaryBlobMode,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1388 | if (status == MagickFalse) |
| 1389 | return(status); |
| 1390 | for (y=0; y < (ssize_t) image->rows; y++) |
| 1391 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1392 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1393 | *restrict p; |
| 1394 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1395 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1396 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1397 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1398 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1399 | BlueQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1400 | count=WriteBlob(image,length,pixels); |
| 1401 | if (count != (ssize_t) length) |
| 1402 | break; |
| 1403 | } |
| 1404 | if (image->previous == (Image *) NULL) |
| 1405 | { |
| 1406 | status=SetImageProgress(image,SaveImageTag,3,6); |
| 1407 | if (status == MagickFalse) |
| 1408 | break; |
| 1409 | } |
| 1410 | (void) CloseBlob(image); |
| 1411 | if (quantum_type == RGBAQuantum) |
| 1412 | { |
| 1413 | (void) CloseBlob(image); |
| 1414 | AppendImageFormat("A",image->filename); |
| 1415 | status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode : |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1416 | AppendBinaryBlobMode,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1417 | if (status == MagickFalse) |
| 1418 | return(status); |
| 1419 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1420 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1421 | register const Quantum |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1422 | *restrict p; |
| 1423 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1424 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1425 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1426 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1427 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1428 | AlphaQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1429 | count=WriteBlob(image,length,pixels); |
| 1430 | if (count != (ssize_t) length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1431 | break; |
| 1432 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1433 | if (image->previous == (Image *) NULL) |
| 1434 | { |
| 1435 | status=SetImageProgress(image,SaveImageTag,5,6); |
| 1436 | if (status == MagickFalse) |
| 1437 | break; |
| 1438 | } |
| 1439 | } |
| 1440 | (void) CloseBlob(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1441 | (void) CopyMagickString(image->filename,image_info->filename, |
| 1442 | MaxTextExtent); |
| 1443 | if (image->previous == (Image *) NULL) |
| 1444 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1445 | status=SetImageProgress(image,SaveImageTag,6,6); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1446 | if (status == MagickFalse) |
| 1447 | break; |
| 1448 | } |
| 1449 | break; |
| 1450 | } |
| 1451 | } |
| 1452 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 1453 | if (GetNextImageInList(image) == (Image *) NULL) |
| 1454 | break; |
| 1455 | image=SyncNextImageInList(image); |
| 1456 | status=SetImageProgress(image,SaveImagesTag,scene++, |
| 1457 | GetImageListLength(image)); |
| 1458 | if (status == MagickFalse) |
| 1459 | break; |
| 1460 | } while (image_info->adjoin != MagickFalse); |
| 1461 | (void) CloseBlob(image); |
| 1462 | return(MagickTrue); |
| 1463 | } |