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