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 | 252dd2c | 2018-12-02 09:42:06 -0500 | [diff] [blame] | 20 | % Copyright 1999-2019 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 | 83d74de | 2018-10-13 10:17:25 -0400 | [diff] [blame] | 26 | % https://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 | b2d2441 | 2018-03-09 19:41:19 -0500 | [diff] [blame] | 152 | if (DiscardBlobBytes(image,(MagickSizeType) image->offset) == MagickFalse) |
cristy | d429702 | 2010-09-16 22:59:09 +0000 | [diff] [blame] | 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) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 167 | { |
| 168 | canvas_image=DestroyImage(canvas_image); |
| 169 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 170 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 171 | quantum_type=RGBQuantum; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 172 | if (LocaleCompare(image_info->magick,"RGBA") == 0) |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 173 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 174 | quantum_type=RGBAQuantum; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 175 | image->alpha_trait=BlendPixelTrait; |
| 176 | canvas_image->alpha_trait=BlendPixelTrait; |
cristy | a38675f | 2010-08-21 18:35:13 +0000 | [diff] [blame] | 177 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 178 | if (LocaleCompare(image_info->magick,"RGBO") == 0) |
| 179 | { |
| 180 | quantum_type=RGBOQuantum; |
dirk | 7000aae | 2015-02-24 11:56:06 +0000 | [diff] [blame] | 181 | image->alpha_trait=BlendPixelTrait; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 182 | canvas_image->alpha_trait=BlendPixelTrait; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 183 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 184 | pixels=(const unsigned char *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 185 | if (image_info->number_scenes != 0) |
| 186 | while (image->scene < image_info->scene) |
| 187 | { |
| 188 | /* |
| 189 | Skip to next image. |
| 190 | */ |
| 191 | image->scene++; |
| 192 | length=GetQuantumExtent(canvas_image,quantum_info,quantum_type); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 193 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 194 | { |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 195 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 196 | GetQuantumPixels(quantum_info),&count); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 197 | if (count != (ssize_t) length) |
| 198 | break; |
| 199 | } |
| 200 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 201 | count=0; |
| 202 | length=0; |
| 203 | scene=0; |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 204 | status=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 205 | do |
| 206 | { |
| 207 | /* |
| 208 | Read pixels to virtual canvas image then push to image. |
| 209 | */ |
| 210 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 211 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 212 | break; |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 213 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 214 | if (status == MagickFalse) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 215 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 216 | switch (image_info->interlace) |
| 217 | { |
| 218 | case NoInterlace: |
| 219 | default: |
| 220 | { |
| 221 | /* |
| 222 | No interlacing: RGBRGBRGBRGBRGBRGB... |
| 223 | */ |
| 224 | if (scene == 0) |
| 225 | { |
| 226 | length=GetQuantumExtent(canvas_image,quantum_info,quantum_type); |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 227 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 228 | GetQuantumPixels(quantum_info),&count); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 229 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 230 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 231 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 232 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 233 | *magick_restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 234 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 235 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 236 | *magick_restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 237 | |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 238 | register ssize_t |
| 239 | x; |
| 240 | |
cristy | 21da32d | 2009-09-12 14:56:09 +0000 | [diff] [blame] | 241 | if (count != (ssize_t) length) |
| 242 | { |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 243 | status=MagickFalse; |
cristy | 21da32d | 2009-09-12 14:56:09 +0000 | [diff] [blame] | 244 | ThrowFileException(exception,CorruptImageError, |
| 245 | "UnexpectedEndOfFile",image->filename); |
| 246 | break; |
| 247 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 248 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 249 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 250 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 251 | break; |
| 252 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 253 | quantum_info,quantum_type,pixels,exception); |
| 254 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 255 | break; |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 256 | if (((y-image->extract_info.y) >= 0) && |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 257 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 258 | { |
| 259 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 260 | canvas_image->columns,1,exception); |
| 261 | q=QueueAuthenticPixels(image,0,y-image->extract_info.y, |
| 262 | image->columns,1,exception); |
cristy | ddacdd1 | 2012-05-07 23:08:14 +0000 | [diff] [blame] | 263 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 264 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 265 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 266 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 267 | SetPixelRed(image,GetPixelRed(canvas_image,p),q); |
| 268 | SetPixelGreen(image,GetPixelGreen(canvas_image,p),q); |
| 269 | SetPixelBlue(image,GetPixelBlue(canvas_image,p),q); |
| 270 | SetPixelAlpha(image,OpaqueAlpha,q); |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 271 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 272 | SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 273 | p+=GetPixelChannels(canvas_image); |
| 274 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 275 | } |
| 276 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 277 | break; |
| 278 | } |
| 279 | if (image->previous == (Image *) NULL) |
| 280 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 281 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 282 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 283 | if (status == MagickFalse) |
| 284 | break; |
| 285 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 286 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 287 | GetQuantumPixels(quantum_info),&count); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 288 | } |
| 289 | break; |
| 290 | } |
| 291 | case LineInterlace: |
| 292 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 293 | static QuantumType |
| 294 | quantum_types[4] = |
| 295 | { |
| 296 | RedQuantum, |
| 297 | GreenQuantum, |
| 298 | BlueQuantum, |
| 299 | AlphaQuantum |
| 300 | }; |
| 301 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 302 | /* |
| 303 | Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB... |
| 304 | */ |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 305 | if (LocaleCompare(image_info->magick,"RGBO") == 0) |
| 306 | quantum_types[3]=OpacityQuantum; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 307 | if (scene == 0) |
| 308 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 309 | length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum); |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 310 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 311 | GetQuantumPixels(quantum_info),&count); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 312 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 313 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 314 | { |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 315 | for (i=0; i < (ssize_t) (image->alpha_trait != UndefinedPixelTrait ? 4 : 3); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 316 | { |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 317 | register const Quantum |
| 318 | *magick_restrict p; |
| 319 | |
| 320 | register Quantum |
| 321 | *magick_restrict q; |
| 322 | |
| 323 | register ssize_t |
| 324 | x; |
| 325 | |
| 326 | if (count != (ssize_t) length) |
| 327 | { |
| 328 | status=MagickFalse; |
| 329 | ThrowFileException(exception,CorruptImageError, |
| 330 | "UnexpectedEndOfFile",image->filename); |
| 331 | break; |
| 332 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 333 | quantum_type=quantum_types[i]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 334 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 335 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 336 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 337 | break; |
| 338 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 339 | quantum_info,quantum_type,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 340 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 341 | break; |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 342 | if (((y-image->extract_info.y) >= 0) && |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 343 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 344 | { |
| 345 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x, |
| 346 | 0,canvas_image->columns,1,exception); |
| 347 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 348 | image->columns,1,exception); |
cristy | ddacdd1 | 2012-05-07 23:08:14 +0000 | [diff] [blame] | 349 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 350 | break; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 351 | for (x=0; x < (ssize_t) image->columns; x++) |
| 352 | { |
| 353 | switch (quantum_type) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 354 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 355 | case RedQuantum: |
| 356 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 357 | SetPixelRed(image,GetPixelRed(canvas_image,p),q); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 358 | break; |
| 359 | } |
| 360 | case GreenQuantum: |
| 361 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 362 | SetPixelGreen(image,GetPixelGreen(canvas_image,p),q); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 363 | break; |
| 364 | } |
| 365 | case BlueQuantum: |
| 366 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 367 | SetPixelBlue(image,GetPixelBlue(canvas_image,p),q); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 368 | break; |
| 369 | } |
| 370 | case OpacityQuantum: |
| 371 | { |
Cristy | c773712 | 2018-03-09 20:01:16 -0500 | [diff] [blame] | 372 | SetPixelOpacity(image,GetPixelOpacity(canvas_image,p),q); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 373 | break; |
| 374 | } |
| 375 | case AlphaQuantum: |
| 376 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 377 | SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 378 | break; |
| 379 | } |
| 380 | default: |
| 381 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 382 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 383 | p+=GetPixelChannels(canvas_image); |
| 384 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 385 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 386 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 387 | break; |
| 388 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 389 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 390 | GetQuantumPixels(quantum_info),&count); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 391 | } |
| 392 | if (image->previous == (Image *) NULL) |
| 393 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 394 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 395 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 396 | if (status == MagickFalse) |
| 397 | break; |
| 398 | } |
| 399 | } |
| 400 | break; |
| 401 | } |
| 402 | case PlaneInterlace: |
| 403 | { |
| 404 | /* |
| 405 | Plane interlacing: RRRRRR...GGGGGG...BBBBBB... |
| 406 | */ |
| 407 | if (scene == 0) |
| 408 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 409 | length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum); |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 410 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 411 | GetQuantumPixels(quantum_info),&count); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 412 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 413 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 414 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 415 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 416 | *magick_restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 417 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 418 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 419 | *magick_restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 420 | |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 421 | register ssize_t |
| 422 | x; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 423 | |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 424 | if (count != (ssize_t) length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 425 | { |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 426 | status=MagickFalse; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 427 | ThrowFileException(exception,CorruptImageError, |
| 428 | "UnexpectedEndOfFile",image->filename); |
| 429 | break; |
| 430 | } |
| 431 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 432 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 433 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 434 | break; |
| 435 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 436 | quantum_info,RedQuantum,pixels,exception); |
| 437 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 438 | break; |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 439 | if (((y-image->extract_info.y) >= 0) && |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 440 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 441 | { |
| 442 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 443 | canvas_image->columns,1,exception); |
| 444 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 445 | image->columns,1,exception); |
cristy | ddacdd1 | 2012-05-07 23:08:14 +0000 | [diff] [blame] | 446 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 447 | break; |
| 448 | for (x=0; x < (ssize_t) image->columns; x++) |
| 449 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 450 | SetPixelRed(image,GetPixelRed(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 451 | p+=GetPixelChannels(canvas_image); |
| 452 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 453 | } |
| 454 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 455 | break; |
| 456 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 457 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 458 | GetQuantumPixels(quantum_info),&count); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 459 | } |
| 460 | if (image->previous == (Image *) NULL) |
| 461 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 462 | status=SetImageProgress(image,LoadImageTag,1,6); |
| 463 | if (status == MagickFalse) |
| 464 | break; |
| 465 | } |
| 466 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 467 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 468 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 469 | *magick_restrict p; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 470 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 471 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 472 | *magick_restrict q; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 473 | |
| 474 | register ssize_t |
| 475 | x; |
| 476 | |
| 477 | if (count != (ssize_t) length) |
| 478 | { |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 479 | status=MagickFalse; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 480 | ThrowFileException(exception,CorruptImageError, |
| 481 | "UnexpectedEndOfFile",image->filename); |
| 482 | break; |
| 483 | } |
| 484 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 485 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 486 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 487 | break; |
| 488 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 489 | quantum_info,GreenQuantum,pixels,exception); |
| 490 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 491 | break; |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 492 | if (((y-image->extract_info.y) >= 0) && |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 493 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 494 | { |
| 495 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 496 | canvas_image->columns,1,exception); |
| 497 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 498 | image->columns,1,exception); |
cristy | ddacdd1 | 2012-05-07 23:08:14 +0000 | [diff] [blame] | 499 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 500 | break; |
| 501 | for (x=0; x < (ssize_t) image->columns; x++) |
| 502 | { |
cristy | f27ee03 | 2011-09-29 17:51:41 +0000 | [diff] [blame] | 503 | SetPixelGreen(image,GetPixelGreen(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 504 | p+=GetPixelChannels(canvas_image); |
| 505 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 506 | } |
| 507 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 508 | break; |
| 509 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 510 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 511 | GetQuantumPixels(quantum_info),&count); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 512 | } |
| 513 | if (image->previous == (Image *) NULL) |
| 514 | { |
| 515 | status=SetImageProgress(image,LoadImageTag,2,6); |
| 516 | if (status == MagickFalse) |
| 517 | break; |
| 518 | } |
| 519 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 520 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 521 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 522 | *magick_restrict p; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 523 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 524 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 525 | *magick_restrict q; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 526 | |
| 527 | register ssize_t |
| 528 | x; |
| 529 | |
| 530 | if (count != (ssize_t) length) |
| 531 | { |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 532 | status=MagickFalse; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 533 | ThrowFileException(exception,CorruptImageError, |
| 534 | "UnexpectedEndOfFile",image->filename); |
| 535 | break; |
| 536 | } |
| 537 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 538 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 539 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 540 | break; |
| 541 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 542 | quantum_info,BlueQuantum,pixels,exception); |
| 543 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 544 | break; |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 545 | if (((y-image->extract_info.y) >= 0) && |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 546 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 547 | { |
| 548 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 549 | canvas_image->columns,1,exception); |
| 550 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 551 | image->columns,1,exception); |
cristy | ddacdd1 | 2012-05-07 23:08:14 +0000 | [diff] [blame] | 552 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 553 | break; |
| 554 | for (x=0; x < (ssize_t) image->columns; x++) |
| 555 | { |
cristy | f27ee03 | 2011-09-29 17:51:41 +0000 | [diff] [blame] | 556 | SetPixelBlue(image,GetPixelBlue(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 557 | p+=GetPixelChannels(canvas_image); |
| 558 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 559 | } |
| 560 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 561 | break; |
| 562 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 563 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 564 | GetQuantumPixels(quantum_info),&count); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 565 | } |
| 566 | if (image->previous == (Image *) NULL) |
| 567 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 568 | status=SetImageProgress(image,LoadImageTag,4,6); |
| 569 | if (status == MagickFalse) |
| 570 | break; |
| 571 | } |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 572 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 573 | { |
| 574 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 575 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 576 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 577 | *magick_restrict p; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 578 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 579 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 580 | *magick_restrict q; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 581 | |
| 582 | register ssize_t |
| 583 | x; |
| 584 | |
| 585 | if (count != (ssize_t) length) |
| 586 | { |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 587 | status=MagickFalse; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 588 | ThrowFileException(exception,CorruptImageError, |
| 589 | "UnexpectedEndOfFile",image->filename); |
| 590 | break; |
| 591 | } |
| 592 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 593 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 594 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 595 | break; |
| 596 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 597 | quantum_info,AlphaQuantum,pixels,exception); |
| 598 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 599 | break; |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 600 | if (((y-image->extract_info.y) >= 0) && |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 601 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 602 | { |
| 603 | p=GetVirtualPixels(canvas_image, |
| 604 | canvas_image->extract_info.x,0,canvas_image->columns,1, |
| 605 | exception); |
| 606 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 607 | image->columns,1,exception); |
cristy | ddacdd1 | 2012-05-07 23:08:14 +0000 | [diff] [blame] | 608 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 609 | break; |
| 610 | for (x=0; x < (ssize_t) image->columns; x++) |
| 611 | { |
cristy | f27ee03 | 2011-09-29 17:51:41 +0000 | [diff] [blame] | 612 | SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 613 | p+=GetPixelChannels(canvas_image); |
| 614 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 615 | } |
| 616 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 617 | break; |
| 618 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 619 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 620 | GetQuantumPixels(quantum_info),&count); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 621 | } |
| 622 | if (image->previous == (Image *) NULL) |
| 623 | { |
| 624 | status=SetImageProgress(image,LoadImageTag,5,6); |
| 625 | if (status == MagickFalse) |
| 626 | break; |
| 627 | } |
| 628 | } |
| 629 | if (image->previous == (Image *) NULL) |
| 630 | { |
| 631 | status=SetImageProgress(image,LoadImageTag,6,6); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 632 | if (status == MagickFalse) |
| 633 | break; |
| 634 | } |
| 635 | break; |
| 636 | } |
| 637 | case PartitionInterlace: |
| 638 | { |
| 639 | /* |
| 640 | Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB... |
| 641 | */ |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 642 | AppendImageFormat("R",image->filename); |
| 643 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 644 | if (status == MagickFalse) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 645 | break; |
Cristy | b2d2441 | 2018-03-09 19:41:19 -0500 | [diff] [blame] | 646 | if (DiscardBlobBytes(image,(MagickSizeType) image->offset) == MagickFalse) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 647 | { |
| 648 | status=MagickFalse; |
| 649 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 650 | image->filename); |
| 651 | break; |
| 652 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 653 | length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum); |
| 654 | for (i=0; i < (ssize_t) scene; i++) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 655 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 656 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 657 | { |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 658 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 659 | GetQuantumPixels(quantum_info),&count); |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 660 | if (count != (ssize_t) length) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 661 | break; |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 662 | } |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 663 | if (count != (ssize_t) length) |
| 664 | break; |
| 665 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 666 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 667 | GetQuantumPixels(quantum_info),&count); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 668 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 669 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 670 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 671 | *magick_restrict p; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 672 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 673 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 674 | *magick_restrict q; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 675 | |
| 676 | register ssize_t |
| 677 | x; |
| 678 | |
| 679 | if (count != (ssize_t) length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 680 | { |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 681 | status=MagickFalse; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 682 | ThrowFileException(exception,CorruptImageError, |
| 683 | "UnexpectedEndOfFile",image->filename); |
| 684 | break; |
| 685 | } |
| 686 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 687 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 688 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 689 | break; |
| 690 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 691 | quantum_info,RedQuantum,pixels,exception); |
| 692 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 693 | break; |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 694 | if (((y-image->extract_info.y) >= 0) && |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 695 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 696 | { |
| 697 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 698 | canvas_image->columns,1,exception); |
| 699 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 700 | image->columns,1,exception); |
cristy | ddacdd1 | 2012-05-07 23:08:14 +0000 | [diff] [blame] | 701 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 702 | break; |
| 703 | for (x=0; x < (ssize_t) image->columns; x++) |
| 704 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 705 | SetPixelRed(image,GetPixelRed(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 706 | p+=GetPixelChannels(canvas_image); |
| 707 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 708 | } |
| 709 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 710 | break; |
| 711 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 712 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 713 | GetQuantumPixels(quantum_info),&count); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 714 | } |
| 715 | if (image->previous == (Image *) NULL) |
| 716 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 717 | status=SetImageProgress(image,LoadImageTag,1,5); |
| 718 | if (status == MagickFalse) |
| 719 | break; |
| 720 | } |
| 721 | (void) CloseBlob(image); |
| 722 | AppendImageFormat("G",image->filename); |
| 723 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 724 | if (status == MagickFalse) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 725 | break; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 726 | length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum); |
| 727 | for (i=0; i < (ssize_t) scene; i++) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 728 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 729 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 730 | { |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 731 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 732 | GetQuantumPixels(quantum_info),&count); |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 733 | if (count != (ssize_t) length) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 734 | break; |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 735 | } |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 736 | if (count != (ssize_t) length) |
| 737 | break; |
| 738 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 739 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 740 | GetQuantumPixels(quantum_info),&count); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 741 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 742 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 743 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 744 | *magick_restrict p; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 745 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 746 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 747 | *magick_restrict q; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 748 | |
| 749 | register ssize_t |
| 750 | x; |
| 751 | |
| 752 | if (count != (ssize_t) length) |
| 753 | { |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 754 | status=MagickFalse; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 755 | ThrowFileException(exception,CorruptImageError, |
| 756 | "UnexpectedEndOfFile",image->filename); |
| 757 | break; |
| 758 | } |
| 759 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 760 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 761 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 762 | break; |
| 763 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 764 | quantum_info,GreenQuantum,pixels,exception); |
| 765 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 766 | break; |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 767 | if (((y-image->extract_info.y) >= 0) && |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 768 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 769 | { |
| 770 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 771 | canvas_image->columns,1,exception); |
| 772 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 773 | image->columns,1,exception); |
cristy | ddacdd1 | 2012-05-07 23:08:14 +0000 | [diff] [blame] | 774 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 775 | break; |
| 776 | for (x=0; x < (ssize_t) image->columns; x++) |
| 777 | { |
cristy | f27ee03 | 2011-09-29 17:51:41 +0000 | [diff] [blame] | 778 | SetPixelGreen(image,GetPixelGreen(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 779 | p+=GetPixelChannels(canvas_image); |
| 780 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 781 | } |
| 782 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 783 | break; |
| 784 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 785 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 786 | GetQuantumPixels(quantum_info),&count); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 787 | } |
| 788 | if (image->previous == (Image *) NULL) |
| 789 | { |
| 790 | status=SetImageProgress(image,LoadImageTag,2,5); |
| 791 | if (status == MagickFalse) |
| 792 | break; |
| 793 | } |
| 794 | (void) CloseBlob(image); |
| 795 | AppendImageFormat("B",image->filename); |
| 796 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 797 | if (status == MagickFalse) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 798 | break; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 799 | length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum); |
| 800 | for (i=0; i < (ssize_t) scene; i++) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 801 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 802 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 803 | { |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 804 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 805 | GetQuantumPixels(quantum_info),&count); |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 806 | if (count != (ssize_t) length) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 807 | break; |
| 808 | } |
| 809 | if (count != (ssize_t) length) |
| 810 | break; |
| 811 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 812 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 813 | GetQuantumPixels(quantum_info),&count); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 814 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 815 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 816 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 817 | *magick_restrict p; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 818 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 819 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 820 | *magick_restrict q; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 821 | |
| 822 | register ssize_t |
| 823 | x; |
| 824 | |
| 825 | if (count != (ssize_t) length) |
| 826 | { |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 827 | status=MagickFalse; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 828 | ThrowFileException(exception,CorruptImageError, |
| 829 | "UnexpectedEndOfFile",image->filename); |
| 830 | break; |
| 831 | } |
| 832 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 833 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 834 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 835 | break; |
| 836 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 837 | quantum_info,BlueQuantum,pixels,exception); |
| 838 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 839 | break; |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 840 | if (((y-image->extract_info.y) >= 0) && |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 841 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 842 | { |
| 843 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 844 | canvas_image->columns,1,exception); |
| 845 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 846 | image->columns,1,exception); |
cristy | ddacdd1 | 2012-05-07 23:08:14 +0000 | [diff] [blame] | 847 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 848 | break; |
| 849 | for (x=0; x < (ssize_t) image->columns; x++) |
| 850 | { |
cristy | f27ee03 | 2011-09-29 17:51:41 +0000 | [diff] [blame] | 851 | SetPixelBlue(image,GetPixelBlue(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 852 | p+=GetPixelChannels(canvas_image); |
| 853 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 854 | } |
| 855 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 856 | break; |
| 857 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 858 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 859 | GetQuantumPixels(quantum_info),&count); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 860 | } |
| 861 | if (image->previous == (Image *) NULL) |
| 862 | { |
| 863 | status=SetImageProgress(image,LoadImageTag,3,5); |
| 864 | if (status == MagickFalse) |
| 865 | break; |
| 866 | } |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 867 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 868 | { |
| 869 | (void) CloseBlob(image); |
| 870 | AppendImageFormat("A",image->filename); |
| 871 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 872 | if (status == MagickFalse) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 873 | break; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 874 | length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum); |
| 875 | for (i=0; i < (ssize_t) scene; i++) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 876 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 877 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 878 | { |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 879 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 880 | GetQuantumPixels(quantum_info),&count); |
| 881 | if (count != (ssize_t) length) |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 882 | break; |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 883 | } |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 884 | if (count != (ssize_t) length) |
| 885 | break; |
| 886 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 887 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 888 | GetQuantumPixels(quantum_info),&count); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 889 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 890 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 891 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 892 | *magick_restrict p; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 893 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 894 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 895 | *magick_restrict q; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 896 | |
| 897 | register ssize_t |
| 898 | x; |
| 899 | |
| 900 | if (count != (ssize_t) length) |
| 901 | { |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 902 | status=MagickFalse; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 903 | ThrowFileException(exception,CorruptImageError, |
| 904 | "UnexpectedEndOfFile",image->filename); |
| 905 | break; |
| 906 | } |
| 907 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1, |
| 908 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 909 | if (q == (Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 910 | break; |
| 911 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 912 | quantum_info,BlueQuantum,pixels,exception); |
| 913 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 914 | break; |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 915 | if (((y-image->extract_info.y) >= 0) && |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 916 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 917 | { |
| 918 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x, |
| 919 | 0,canvas_image->columns,1,exception); |
| 920 | q=GetAuthenticPixels(image,0,y-image->extract_info.y, |
| 921 | image->columns,1,exception); |
cristy | c6aebff | 2012-05-07 23:24:35 +0000 | [diff] [blame] | 922 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 923 | break; |
| 924 | for (x=0; x < (ssize_t) image->columns; x++) |
| 925 | { |
cristy | f27ee03 | 2011-09-29 17:51:41 +0000 | [diff] [blame] | 926 | SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 927 | p+=GetPixelChannels(canvas_image); |
| 928 | q+=GetPixelChannels(image); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 929 | } |
| 930 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 931 | break; |
| 932 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 933 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 934 | GetQuantumPixels(quantum_info),&count); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 935 | } |
| 936 | if (image->previous == (Image *) NULL) |
| 937 | { |
| 938 | status=SetImageProgress(image,LoadImageTag,4,5); |
| 939 | if (status == MagickFalse) |
| 940 | break; |
| 941 | } |
| 942 | } |
| 943 | (void) CloseBlob(image); |
| 944 | if (image->previous == (Image *) NULL) |
| 945 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 946 | status=SetImageProgress(image,LoadImageTag,5,5); |
| 947 | if (status == MagickFalse) |
| 948 | break; |
| 949 | } |
| 950 | break; |
| 951 | } |
| 952 | } |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 953 | if (status == MagickFalse) |
| 954 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 955 | SetQuantumImageType(image,quantum_type); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 956 | /* |
| 957 | Proceed to next image. |
| 958 | */ |
| 959 | if (image_info->number_scenes != 0) |
| 960 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 961 | break; |
| 962 | if (count == (ssize_t) length) |
| 963 | { |
| 964 | /* |
| 965 | Allocate next image structure. |
| 966 | */ |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 967 | AcquireNextImage(image_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 968 | if (GetNextImageInList(image) == (Image *) NULL) |
| 969 | { |
Cristy | 5ff0db9 | 2018-06-20 18:04:36 -0400 | [diff] [blame] | 970 | status=MagickFalse; |
| 971 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 972 | } |
| 973 | image=SyncNextImageInList(image); |
| 974 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 975 | GetBlobSize(image)); |
| 976 | if (status == MagickFalse) |
| 977 | break; |
| 978 | } |
| 979 | scene++; |
| 980 | } while (count == (ssize_t) length); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 981 | quantum_info=DestroyQuantumInfo(quantum_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 982 | canvas_image=DestroyImage(canvas_image); |
| 983 | (void) CloseBlob(image); |
Dirk Lemstra | dede840 | 2018-03-24 17:51:58 +0100 | [diff] [blame] | 984 | if (status == MagickFalse) |
Cristy | 3b48d20 | 2018-07-01 17:11:51 -0400 | [diff] [blame] | 985 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 986 | return(GetFirstImageInList(image)); |
| 987 | } |
| 988 | |
| 989 | /* |
| 990 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 991 | % % |
| 992 | % % |
| 993 | % % |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 994 | % R e a d R G B 5 6 5 I m a g e % |
| 995 | % % |
| 996 | % % |
| 997 | % % |
| 998 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 999 | % |
| 1000 | % ReadGRAYImage() reads an image of raw RGB 5-6-5 samples and returns it. It |
| 1001 | % allocates the memory necessary for the new Image structure and returns a |
| 1002 | % pointer to the new image. |
| 1003 | % |
| 1004 | % The format of the ReadGRAYImage method is: |
| 1005 | % |
| 1006 | % Image *ReadGRAYImage(const ImageInfo *image_info, |
| 1007 | % ExceptionInfo *exception) |
| 1008 | % |
| 1009 | % A description of each parameter follows: |
| 1010 | % |
| 1011 | % o image_info: the image info. |
| 1012 | % |
| 1013 | % o exception: return any errors or warnings in this structure. |
| 1014 | % |
| 1015 | */ |
| 1016 | static Image *ReadRGB565Image(const ImageInfo *image_info, |
| 1017 | ExceptionInfo *exception) |
| 1018 | { |
| 1019 | const unsigned char |
| 1020 | *pixels; |
| 1021 | |
| 1022 | Image |
| 1023 | *canvas_image, |
| 1024 | *image; |
| 1025 | |
| 1026 | MagickBooleanType |
| 1027 | status; |
| 1028 | |
| 1029 | MagickOffsetType |
| 1030 | scene; |
| 1031 | |
| 1032 | QuantumInfo |
| 1033 | *quantum_info; |
| 1034 | |
| 1035 | QuantumType |
| 1036 | quantum_type; |
| 1037 | |
| 1038 | size_t |
| 1039 | length; |
| 1040 | |
| 1041 | ssize_t |
| 1042 | count, |
| 1043 | y; |
| 1044 | |
| 1045 | /* |
| 1046 | Open image file. |
| 1047 | */ |
| 1048 | assert(image_info != (const ImageInfo *) NULL); |
| 1049 | assert(image_info->signature == MagickCoreSignature); |
| 1050 | if (image_info->debug != MagickFalse) |
| 1051 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 1052 | image_info->filename); |
| 1053 | assert(exception != (ExceptionInfo *) NULL); |
| 1054 | assert(exception->signature == MagickCoreSignature); |
| 1055 | image=AcquireImage(image_info,exception); |
| 1056 | if ((image->columns == 0) || (image->rows == 0)) |
| 1057 | ThrowReaderException(OptionError,"MustSpecifyImageSize"); |
| 1058 | image->depth=16; |
| 1059 | if (image_info->interlace != PartitionInterlace) |
| 1060 | { |
| 1061 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 1062 | if (status == MagickFalse) |
| 1063 | { |
| 1064 | image=DestroyImageList(image); |
| 1065 | return((Image *) NULL); |
| 1066 | } |
| 1067 | if (DiscardBlobBytes(image,(MagickSizeType) image->offset) == MagickFalse) |
| 1068 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 1069 | image->filename); |
| 1070 | } |
| 1071 | /* |
| 1072 | Create virtual canvas to support cropping (i.e. image.rgb[100x100+10+20]). |
| 1073 | */ |
| 1074 | canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse, |
| 1075 | exception); |
| 1076 | if(canvas_image == (Image *) NULL) |
| 1077 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 1078 | (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod, |
| 1079 | exception); |
| 1080 | quantum_info=AcquireQuantumInfo(image_info,canvas_image); |
| 1081 | if (quantum_info == (QuantumInfo *) NULL) |
| 1082 | { |
| 1083 | canvas_image=DestroyImage(canvas_image); |
| 1084 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 1085 | } |
| 1086 | quantum_type=GrayQuantum; |
| 1087 | pixels=(const unsigned char *) NULL; |
| 1088 | if (image_info->number_scenes != 0) |
| 1089 | while (image->scene < image_info->scene) |
| 1090 | { |
| 1091 | /* |
| 1092 | Skip to next image. |
| 1093 | */ |
| 1094 | image->scene++; |
| 1095 | length=GetQuantumExtent(canvas_image,quantum_info,quantum_type); |
| 1096 | for (y=0; y < (ssize_t) image->rows; y++) |
| 1097 | { |
| 1098 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 1099 | GetQuantumPixels(quantum_info),&count); |
| 1100 | if (count != (ssize_t) length) |
| 1101 | break; |
| 1102 | } |
| 1103 | } |
| 1104 | count=0; |
| 1105 | length=0; |
| 1106 | scene=0; |
| 1107 | status=MagickTrue; |
| 1108 | do |
| 1109 | { |
| 1110 | /* |
| 1111 | Read pixels to virtual canvas image then push to image. |
| 1112 | */ |
| 1113 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 1114 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 1115 | break; |
| 1116 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 1117 | if (status == MagickFalse) |
| 1118 | break; |
| 1119 | /* |
| 1120 | No interlacing: GGG... |
| 1121 | */ |
| 1122 | if (scene == 0) |
| 1123 | { |
| 1124 | length=GetQuantumExtent(canvas_image,quantum_info,quantum_type); |
| 1125 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 1126 | GetQuantumPixels(quantum_info),&count); |
| 1127 | } |
| 1128 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
| 1129 | { |
| 1130 | register const Quantum |
| 1131 | *magick_restrict p; |
| 1132 | |
| 1133 | register Quantum |
| 1134 | *magick_restrict q; |
| 1135 | |
| 1136 | register ssize_t |
| 1137 | x; |
| 1138 | |
| 1139 | if (count != (ssize_t) length) |
| 1140 | { |
| 1141 | status=MagickFalse; |
| 1142 | ThrowFileException(exception,CorruptImageError, |
| 1143 | "UnexpectedEndOfFile",image->filename); |
| 1144 | break; |
| 1145 | } |
| 1146 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,exception); |
| 1147 | if (q == (Quantum *) NULL) |
| 1148 | break; |
| 1149 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL, |
| 1150 | quantum_info,quantum_type,pixels,exception); |
| 1151 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 1152 | break; |
| 1153 | if (((y-image->extract_info.y) >= 0) && |
| 1154 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
| 1155 | { |
| 1156 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
| 1157 | canvas_image->columns,1,exception); |
| 1158 | q=QueueAuthenticPixels(image,0,y-image->extract_info.y, |
| 1159 | image->columns,1,exception); |
| 1160 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
| 1161 | break; |
| 1162 | for (x=0; x < (ssize_t) image->columns; x++) |
| 1163 | { |
| 1164 | unsigned short |
| 1165 | pixel; |
| 1166 | |
| 1167 | pixel=(unsigned short) ScaleQuantumToShort(GetPixelGray( |
| 1168 | canvas_image,p)); |
| 1169 | SetPixelRed(image,(Quantum) (((pixel >> 11) & 0x1f) << 11),q); |
| 1170 | SetPixelGreen(image,(Quantum) (((pixel >> 5) & 0x3f) << 10),q); |
| 1171 | SetPixelBlue(image,(Quantum) ((pixel & 0x1f) << 11),q); |
| 1172 | p+=GetPixelChannels(canvas_image); |
| 1173 | q+=GetPixelChannels(image); |
| 1174 | } |
| 1175 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 1176 | break; |
| 1177 | } |
| 1178 | if (image->previous == (Image *) NULL) |
| 1179 | { |
| 1180 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 1181 | image->rows); |
| 1182 | if (status == MagickFalse) |
| 1183 | break; |
| 1184 | } |
| 1185 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 1186 | GetQuantumPixels(quantum_info),&count); |
| 1187 | } |
| 1188 | if (status == MagickFalse) |
| 1189 | break; |
| 1190 | SetQuantumImageType(image,quantum_type); |
| 1191 | /* |
| 1192 | Proceed to next image. |
| 1193 | */ |
| 1194 | if (image_info->number_scenes != 0) |
| 1195 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 1196 | break; |
| 1197 | if (count == (ssize_t) length) |
| 1198 | { |
| 1199 | /* |
| 1200 | Allocate next image structure. |
| 1201 | */ |
| 1202 | AcquireNextImage(image_info,image,exception); |
| 1203 | if (GetNextImageInList(image) == (Image *) NULL) |
| 1204 | { |
| 1205 | status=MagickFalse; |
| 1206 | break; |
| 1207 | } |
| 1208 | image=SyncNextImageInList(image); |
| 1209 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 1210 | GetBlobSize(image)); |
| 1211 | if (status == MagickFalse) |
| 1212 | break; |
| 1213 | } |
| 1214 | scene++; |
| 1215 | } while (count == (ssize_t) length); |
| 1216 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 1217 | canvas_image=DestroyImage(canvas_image); |
| 1218 | (void) CloseBlob(image); |
| 1219 | if (status == MagickFalse) |
| 1220 | return(DestroyImageList(image)); |
| 1221 | return(GetFirstImageInList(image)); |
| 1222 | } |
| 1223 | |
| 1224 | /* |
| 1225 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1226 | % % |
| 1227 | % % |
| 1228 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1229 | % R e g i s t e r R G B I m a g e % |
| 1230 | % % |
| 1231 | % % |
| 1232 | % % |
| 1233 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1234 | % |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1235 | % RegisterRGBImage() adds attributes for the RGB image format to |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1236 | % the list of supported formats. The attributes include the image format |
| 1237 | % tag, a method to read and/or write the format, whether the format |
| 1238 | % supports the saving of more than one frame to the same file or blob, |
| 1239 | % whether the format supports native in-memory I/O, and a brief |
| 1240 | % description of the format. |
| 1241 | % |
| 1242 | % The format of the RegisterRGBImage method is: |
| 1243 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1244 | % size_t RegisterRGBImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1245 | % |
| 1246 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1247 | ModuleExport size_t RegisterRGBImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1248 | { |
| 1249 | MagickInfo |
| 1250 | *entry; |
| 1251 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 1252 | entry=AcquireMagickInfo("RGB","RGB", |
| 1253 | "Raw red, green, and blue samples"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1254 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 1255 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 1256 | entry->flags|=CoderRawSupportFlag; |
| 1257 | entry->flags|=CoderEndianSupportFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1258 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 1259 | entry=AcquireMagickInfo("RGB","RGBA", |
| 1260 | "Raw red, green, blue, and alpha samples"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1261 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 1262 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 1263 | entry->flags|=CoderRawSupportFlag; |
| 1264 | entry->flags|=CoderEndianSupportFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1265 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 1266 | entry=AcquireMagickInfo("RGB","RGBO", |
| 1267 | "Raw red, green, blue, and opacity samples"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1268 | entry->decoder=(DecodeImageHandler *) ReadRGBImage; |
| 1269 | entry->encoder=(EncodeImageHandler *) WriteRGBImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 1270 | entry->flags|=CoderRawSupportFlag; |
| 1271 | entry->flags|=CoderEndianSupportFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1272 | (void) RegisterMagickInfo(entry); |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 1273 | entry=AcquireMagickInfo("RGB","RGB565", |
Dirk Lemstra | 98bffc2 | 2019-06-09 07:23:35 +0200 | [diff] [blame^] | 1274 | "Raw red, green, blue samples in 565 format"); |
Cristy | 747a734 | 2019-06-03 21:01:22 -0400 | [diff] [blame] | 1275 | entry->decoder=(DecodeImageHandler *) ReadRGB565Image; |
| 1276 | entry->flags|=CoderRawSupportFlag; |
| 1277 | entry->flags|=CoderEndianSupportFlag; |
| 1278 | (void) RegisterMagickInfo(entry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1279 | return(MagickImageCoderSignature); |
| 1280 | } |
| 1281 | |
| 1282 | /* |
| 1283 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1284 | % % |
| 1285 | % % |
| 1286 | % % |
| 1287 | % U n r e g i s t e r R G B I m a g e % |
| 1288 | % % |
| 1289 | % % |
| 1290 | % % |
| 1291 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1292 | % |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1293 | % UnregisterRGBImage() removes format registrations made by the RGB module |
| 1294 | % from the list of supported formats. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1295 | % |
| 1296 | % The format of the UnregisterRGBImage method is: |
| 1297 | % |
| 1298 | % UnregisterRGBImage(void) |
| 1299 | % |
| 1300 | */ |
| 1301 | ModuleExport void UnregisterRGBImage(void) |
| 1302 | { |
| 1303 | (void) UnregisterMagickInfo("RGBO"); |
| 1304 | (void) UnregisterMagickInfo("RGBA"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1305 | (void) UnregisterMagickInfo("RGB"); |
| 1306 | } |
| 1307 | |
| 1308 | /* |
| 1309 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1310 | % % |
| 1311 | % % |
| 1312 | % % |
| 1313 | % W r i t e R G B I m a g e % |
| 1314 | % % |
| 1315 | % % |
| 1316 | % % |
| 1317 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1318 | % |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1319 | % WriteRGBImage() writes an image to a file in the RGB, RGBA, or RGBO |
| 1320 | % rasterfile format. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1321 | % |
| 1322 | % The format of the WriteRGBImage method is: |
| 1323 | % |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1324 | % MagickBooleanType WriteRGBImage(const ImageInfo *image_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1325 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1326 | % |
| 1327 | % A description of each parameter follows. |
| 1328 | % |
| 1329 | % o image_info: the image info. |
| 1330 | % |
| 1331 | % o image: The image. |
| 1332 | % |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1333 | % o exception: return any errors or warnings in this structure. |
| 1334 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1335 | */ |
cristy | c6aebff | 2012-05-07 23:24:35 +0000 | [diff] [blame] | 1336 | static MagickBooleanType WriteRGBImage(const ImageInfo *image_info, |
| 1337 | Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1338 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1339 | MagickBooleanType |
| 1340 | status; |
| 1341 | |
| 1342 | MagickOffsetType |
| 1343 | scene; |
| 1344 | |
| 1345 | QuantumInfo |
| 1346 | *quantum_info; |
| 1347 | |
| 1348 | QuantumType |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1349 | quantum_type; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1350 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 1351 | size_t |
Cristy | c45b2bb | 2018-04-07 12:32:12 -0400 | [diff] [blame] | 1352 | imageListLength, |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 1353 | length; |
| 1354 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1355 | ssize_t |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1356 | count, |
| 1357 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1358 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1359 | unsigned char |
| 1360 | *pixels; |
| 1361 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1362 | /* |
| 1363 | Allocate memory for pixels. |
| 1364 | */ |
| 1365 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1366 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1367 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1368 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1369 | if (image->debug != MagickFalse) |
| 1370 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1371 | if (image_info->interlace != PartitionInterlace) |
| 1372 | { |
| 1373 | /* |
| 1374 | Open output image file. |
| 1375 | */ |
cristy | edf03fa | 2011-08-30 12:44:39 +0000 | [diff] [blame] | 1376 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1377 | if (status == MagickFalse) |
| 1378 | return(status); |
| 1379 | } |
| 1380 | quantum_type=RGBQuantum; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1381 | if (LocaleCompare(image_info->magick,"RGBA") == 0) |
cristy | c6aebff | 2012-05-07 23:24:35 +0000 | [diff] [blame] | 1382 | quantum_type=RGBAQuantum; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1383 | if (LocaleCompare(image_info->magick,"RGBO") == 0) |
cristy | c6aebff | 2012-05-07 23:24:35 +0000 | [diff] [blame] | 1384 | quantum_type=RGBOQuantum; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1385 | scene=0; |
Cristy | c45b2bb | 2018-04-07 12:32:12 -0400 | [diff] [blame] | 1386 | imageListLength=GetImageListLength(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1387 | do |
| 1388 | { |
| 1389 | /* |
| 1390 | Convert MIFF to RGB raster pixels. |
| 1391 | */ |
cristy | af8d391 | 2014-02-21 14:50:33 +0000 | [diff] [blame] | 1392 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1393 | if ((LocaleCompare(image_info->magick,"RGBA") == 0) && |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 1394 | (image->alpha_trait == UndefinedPixelTrait)) |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1395 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception); |
cristy | 5f766ef | 2014-12-14 21:12:47 +0000 | [diff] [blame] | 1396 | quantum_info=AcquireQuantumInfo(image_info,image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1397 | if (quantum_info == (QuantumInfo *) NULL) |
| 1398 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 1399 | pixels=(unsigned char *) GetQuantumPixels(quantum_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1400 | switch (image_info->interlace) |
| 1401 | { |
| 1402 | case NoInterlace: |
| 1403 | default: |
| 1404 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1405 | /* |
| 1406 | No interlacing: RGBRGBRGBRGBRGBRGB... |
| 1407 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1408 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1409 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1410 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 1411 | *magick_restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1412 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1413 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1414 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1415 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1416 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1417 | quantum_type,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1418 | count=WriteBlob(image,length,pixels); |
| 1419 | if (count != (ssize_t) length) |
| 1420 | break; |
| 1421 | if (image->previous == (Image *) NULL) |
| 1422 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1423 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 1424 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1425 | if (status == MagickFalse) |
| 1426 | break; |
| 1427 | } |
| 1428 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1429 | break; |
| 1430 | } |
| 1431 | case LineInterlace: |
| 1432 | { |
| 1433 | /* |
| 1434 | Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB... |
| 1435 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1436 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1437 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1438 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 1439 | *magick_restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1440 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1441 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1442 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1443 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1444 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1445 | RedQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1446 | count=WriteBlob(image,length,pixels); |
| 1447 | if (count != (ssize_t) length) |
| 1448 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1449 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1450 | GreenQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1451 | count=WriteBlob(image,length,pixels); |
| 1452 | if (count != (ssize_t) length) |
| 1453 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1454 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1455 | BlueQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1456 | count=WriteBlob(image,length,pixels); |
| 1457 | if (count != (ssize_t) length) |
| 1458 | break; |
| 1459 | if (quantum_type == RGBAQuantum) |
| 1460 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1461 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1462 | AlphaQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1463 | count=WriteBlob(image,length,pixels); |
| 1464 | if (count != (ssize_t) length) |
| 1465 | break; |
| 1466 | } |
| 1467 | if (quantum_type == RGBOQuantum) |
| 1468 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1469 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1470 | OpacityQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1471 | count=WriteBlob(image,length,pixels); |
| 1472 | if (count != (ssize_t) length) |
| 1473 | break; |
| 1474 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1475 | if (image->previous == (Image *) NULL) |
| 1476 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1477 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 1478 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1479 | if (status == MagickFalse) |
| 1480 | break; |
| 1481 | } |
| 1482 | } |
| 1483 | break; |
| 1484 | } |
| 1485 | case PlaneInterlace: |
| 1486 | { |
| 1487 | /* |
| 1488 | Plane interlacing: RRRRRR...GGGGGG...BBBBBB... |
| 1489 | */ |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1490 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1491 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1492 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 1493 | *magick_restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1494 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1495 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1496 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1497 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1498 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1499 | RedQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1500 | count=WriteBlob(image,length,pixels); |
| 1501 | if (count != (ssize_t) length) |
| 1502 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1503 | } |
| 1504 | if (image->previous == (Image *) NULL) |
| 1505 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1506 | status=SetImageProgress(image,SaveImageTag,1,6); |
| 1507 | if (status == MagickFalse) |
| 1508 | break; |
| 1509 | } |
| 1510 | for (y=0; y < (ssize_t) image->rows; y++) |
| 1511 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1512 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 1513 | *magick_restrict p; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1514 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1515 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1516 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1517 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1518 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1519 | GreenQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1520 | count=WriteBlob(image,length,pixels); |
| 1521 | if (count != (ssize_t) length) |
| 1522 | break; |
| 1523 | } |
| 1524 | if (image->previous == (Image *) NULL) |
| 1525 | { |
| 1526 | status=SetImageProgress(image,SaveImageTag,2,6); |
| 1527 | if (status == MagickFalse) |
| 1528 | break; |
| 1529 | } |
| 1530 | for (y=0; y < (ssize_t) image->rows; y++) |
| 1531 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1532 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 1533 | *magick_restrict p; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1534 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1535 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1536 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1537 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1538 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1539 | BlueQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1540 | count=WriteBlob(image,length,pixels); |
| 1541 | if (count != (ssize_t) length) |
| 1542 | break; |
| 1543 | } |
| 1544 | if (image->previous == (Image *) NULL) |
| 1545 | { |
| 1546 | status=SetImageProgress(image,SaveImageTag,3,6); |
| 1547 | if (status == MagickFalse) |
| 1548 | break; |
| 1549 | } |
| 1550 | if (quantum_type == RGBAQuantum) |
| 1551 | { |
| 1552 | for (y=0; y < (ssize_t) image->rows; y++) |
| 1553 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1554 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 1555 | *magick_restrict p; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1556 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1557 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1558 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1559 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1560 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1561 | AlphaQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1562 | count=WriteBlob(image,length,pixels); |
| 1563 | if (count != (ssize_t) length) |
| 1564 | break; |
| 1565 | } |
| 1566 | if (image->previous == (Image *) NULL) |
| 1567 | { |
| 1568 | status=SetImageProgress(image,SaveImageTag,5,6); |
| 1569 | if (status == MagickFalse) |
| 1570 | break; |
| 1571 | } |
| 1572 | } |
| 1573 | if (image_info->interlace == PartitionInterlace) |
| 1574 | (void) CopyMagickString(image->filename,image_info->filename, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1575 | MagickPathExtent); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1576 | if (image->previous == (Image *) NULL) |
| 1577 | { |
| 1578 | status=SetImageProgress(image,SaveImageTag,6,6); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1579 | if (status == MagickFalse) |
| 1580 | break; |
| 1581 | } |
| 1582 | break; |
| 1583 | } |
| 1584 | case PartitionInterlace: |
| 1585 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1586 | /* |
| 1587 | Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB... |
| 1588 | */ |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1589 | AppendImageFormat("R",image->filename); |
| 1590 | status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode : |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1591 | AppendBinaryBlobMode,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1592 | if (status == MagickFalse) |
| 1593 | return(status); |
| 1594 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1595 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1596 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 1597 | *magick_restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1598 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1599 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1600 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1601 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1602 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1603 | RedQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1604 | count=WriteBlob(image,length,pixels); |
| 1605 | if (count != (ssize_t) length) |
| 1606 | break; |
| 1607 | } |
| 1608 | if (image->previous == (Image *) NULL) |
| 1609 | { |
| 1610 | status=SetImageProgress(image,SaveImageTag,1,6); |
| 1611 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1612 | break; |
| 1613 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1614 | (void) CloseBlob(image); |
| 1615 | AppendImageFormat("G",image->filename); |
| 1616 | status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode : |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1617 | AppendBinaryBlobMode,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1618 | if (status == MagickFalse) |
| 1619 | return(status); |
| 1620 | for (y=0; y < (ssize_t) image->rows; y++) |
| 1621 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1622 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 1623 | *magick_restrict p; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1624 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1625 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1626 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1627 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1628 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1629 | GreenQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1630 | count=WriteBlob(image,length,pixels); |
| 1631 | if (count != (ssize_t) length) |
| 1632 | break; |
| 1633 | } |
| 1634 | if (image->previous == (Image *) NULL) |
| 1635 | { |
| 1636 | status=SetImageProgress(image,SaveImageTag,2,6); |
| 1637 | if (status == MagickFalse) |
| 1638 | break; |
| 1639 | } |
| 1640 | (void) CloseBlob(image); |
| 1641 | AppendImageFormat("B",image->filename); |
| 1642 | status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode : |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1643 | AppendBinaryBlobMode,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1644 | if (status == MagickFalse) |
| 1645 | return(status); |
| 1646 | for (y=0; y < (ssize_t) image->rows; y++) |
| 1647 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1648 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 1649 | *magick_restrict p; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1650 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1651 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1652 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1653 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1654 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1655 | BlueQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1656 | count=WriteBlob(image,length,pixels); |
| 1657 | if (count != (ssize_t) length) |
| 1658 | break; |
| 1659 | } |
| 1660 | if (image->previous == (Image *) NULL) |
| 1661 | { |
| 1662 | status=SetImageProgress(image,SaveImageTag,3,6); |
| 1663 | if (status == MagickFalse) |
| 1664 | break; |
| 1665 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1666 | if (quantum_type == RGBAQuantum) |
| 1667 | { |
| 1668 | (void) CloseBlob(image); |
| 1669 | AppendImageFormat("A",image->filename); |
| 1670 | status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode : |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1671 | AppendBinaryBlobMode,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1672 | if (status == MagickFalse) |
| 1673 | return(status); |
| 1674 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1675 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1676 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 1677 | *magick_restrict p; |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1678 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1679 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1680 | if (p == (const Quantum *) NULL) |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1681 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1682 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1683 | AlphaQuantum,pixels,exception); |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1684 | count=WriteBlob(image,length,pixels); |
| 1685 | if (count != (ssize_t) length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1686 | break; |
| 1687 | } |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1688 | if (image->previous == (Image *) NULL) |
| 1689 | { |
| 1690 | status=SetImageProgress(image,SaveImageTag,5,6); |
| 1691 | if (status == MagickFalse) |
| 1692 | break; |
| 1693 | } |
| 1694 | } |
| 1695 | (void) CloseBlob(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1696 | (void) CopyMagickString(image->filename,image_info->filename, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1697 | MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1698 | if (image->previous == (Image *) NULL) |
| 1699 | { |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 1700 | status=SetImageProgress(image,SaveImageTag,6,6); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1701 | if (status == MagickFalse) |
| 1702 | break; |
| 1703 | } |
| 1704 | break; |
| 1705 | } |
| 1706 | } |
| 1707 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 1708 | if (GetNextImageInList(image) == (Image *) NULL) |
| 1709 | break; |
| 1710 | image=SyncNextImageInList(image); |
Cristy | c45b2bb | 2018-04-07 12:32:12 -0400 | [diff] [blame] | 1711 | status=SetImageProgress(image,SaveImagesTag,scene++,imageListLength); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1712 | if (status == MagickFalse) |
| 1713 | break; |
| 1714 | } while (image_info->adjoin != MagickFalse); |
| 1715 | (void) CloseBlob(image); |
| 1716 | return(MagickTrue); |
| 1717 | } |