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