cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % RRRR AAA W W % |
| 7 | % R R A A W W % |
| 8 | % RRRR AAAAA W W W % |
| 9 | % R R A A WW WW % |
| 10 | % R R A A W W % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write RAW Image Format % |
| 14 | % % |
| 15 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
Cristy | f6ff9ea | 2016-12-05 09:53:35 -0500 | [diff] [blame] | 20 | % Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
Cristy | f19d414 | 2017-04-24 11:34:30 -0400 | [diff] [blame] | 26 | % https://www.imagemagick.org/script/license.php % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/blob-private.h" |
| 45 | #include "MagickCore/cache.h" |
| 46 | #include "MagickCore/colorspace.h" |
| 47 | #include "MagickCore/constitute.h" |
| 48 | #include "MagickCore/exception.h" |
| 49 | #include "MagickCore/exception-private.h" |
| 50 | #include "MagickCore/image.h" |
| 51 | #include "MagickCore/image-private.h" |
| 52 | #include "MagickCore/list.h" |
| 53 | #include "MagickCore/magick.h" |
| 54 | #include "MagickCore/memory_.h" |
| 55 | #include "MagickCore/monitor.h" |
| 56 | #include "MagickCore/monitor-private.h" |
| 57 | #include "MagickCore/pixel-accessor.h" |
| 58 | #include "MagickCore/quantum-private.h" |
| 59 | #include "MagickCore/quantum-private.h" |
| 60 | #include "MagickCore/static.h" |
| 61 | #include "MagickCore/statistic.h" |
| 62 | #include "MagickCore/string_.h" |
| 63 | #include "MagickCore/module.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | Forward declarations. |
| 67 | */ |
| 68 | static MagickBooleanType |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 69 | WriteRAWImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 73 | % % |
| 74 | % % |
| 75 | % % |
| 76 | % R e a d R A W I m a g e % |
| 77 | % % |
| 78 | % % |
| 79 | % % |
| 80 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 81 | % |
| 82 | % ReadRAWImage() reads an image of raw samples and returns it. It allocates |
| 83 | % the memory necessary for the new Image structure and returns a pointer to |
| 84 | % the new image. |
| 85 | % |
| 86 | % The format of the ReadRAWImage method is: |
| 87 | % |
| 88 | % Image *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 89 | % |
| 90 | % A description of each parameter follows: |
| 91 | % |
| 92 | % o image_info: the image info. |
| 93 | % |
| 94 | % o exception: return any errors or warnings in this structure. |
| 95 | % |
| 96 | */ |
cristy | 0f8bcf3 | 2012-01-11 01:27:20 +0000 | [diff] [blame] | 97 | static Image *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 98 | { |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 99 | const unsigned char |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame] | 100 | *pixels; |
| 101 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 102 | Image |
| 103 | *canvas_image, |
| 104 | *image; |
| 105 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 | MagickBooleanType |
| 107 | status; |
| 108 | |
cristy | 9af8a2a | 2009-10-02 13:29:27 +0000 | [diff] [blame] | 109 | MagickOffsetType |
| 110 | scene; |
| 111 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 | QuantumInfo |
| 113 | *quantum_info; |
| 114 | |
| 115 | QuantumType |
| 116 | quantum_type; |
| 117 | |
cristy | b20901d | 2010-09-16 23:13:55 +0000 | [diff] [blame] | 118 | size_t |
| 119 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 120 | |
| 121 | ssize_t |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 122 | count, |
| 123 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 124 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 125 | /* |
| 126 | Open image file. |
| 127 | */ |
| 128 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 129 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 130 | if (image_info->debug != MagickFalse) |
| 131 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 132 | image_info->filename); |
| 133 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 134 | assert(exception->signature == MagickCoreSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 135 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 136 | if ((image->columns == 0) || (image->rows == 0)) |
| 137 | ThrowReaderException(OptionError,"MustSpecifyImageSize"); |
Cristy | f420dab | 2017-09-13 10:49:56 -0400 | [diff] [blame] | 138 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 139 | if (status == MagickFalse) |
| 140 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 141 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 142 | if (status == MagickFalse) |
| 143 | { |
| 144 | image=DestroyImageList(image); |
| 145 | return((Image *) NULL); |
| 146 | } |
Cristy | f420dab | 2017-09-13 10:49:56 -0400 | [diff] [blame] | 147 | if (DiscardBlobBytes(image,(MagickSizeType) image->offset) == MagickFalse) |
cristy | d429702 | 2010-09-16 22:59:09 +0000 | [diff] [blame] | 148 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 149 | image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 150 | /* |
| 151 | Create virtual canvas to support cropping (i.e. image.gray[100x100+10+20]). |
| 152 | */ |
| 153 | canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse, |
| 154 | exception); |
root | 1a7e6d1 | 2017-09-29 05:08:02 +0000 | [diff] [blame^] | 155 | if (canvas_image == (Image *) NULL) |
| 156 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | 387430f | 2012-02-07 13:09:46 +0000 | [diff] [blame] | 157 | (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod, |
| 158 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 159 | quantum_type=GrayQuantum; |
cristy | 5f766ef | 2014-12-14 21:12:47 +0000 | [diff] [blame] | 160 | quantum_info=AcquireQuantumInfo(image_info,canvas_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 161 | if (quantum_info == (QuantumInfo *) NULL) |
| 162 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 163 | pixels=(const unsigned char *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 164 | if (image_info->number_scenes != 0) |
| 165 | while (image->scene < image_info->scene) |
| 166 | { |
| 167 | /* |
| 168 | Skip to next image. |
| 169 | */ |
| 170 | image->scene++; |
| 171 | length=GetQuantumExtent(canvas_image,quantum_info,quantum_type); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 172 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 173 | { |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 174 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 175 | GetQuantumPixels(quantum_info),&count); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 176 | if (count != (ssize_t) length) |
| 177 | break; |
| 178 | } |
| 179 | } |
cristy | 9af8a2a | 2009-10-02 13:29:27 +0000 | [diff] [blame] | 180 | scene=0; |
| 181 | count=0; |
| 182 | length=0; |
Cristy | 7a610d4 | 2017-09-14 07:18:36 -0400 | [diff] [blame] | 183 | status=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 184 | do |
| 185 | { |
| 186 | /* |
| 187 | Read pixels to virtual canvas image then push to image. |
| 188 | */ |
| 189 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 190 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 191 | break; |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 192 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 193 | if (status == MagickFalse) |
Cristy | f420dab | 2017-09-13 10:49:56 -0400 | [diff] [blame] | 194 | break; |
cristy | 9af8a2a | 2009-10-02 13:29:27 +0000 | [diff] [blame] | 195 | if (scene == 0) |
| 196 | { |
| 197 | length=GetQuantumExtent(canvas_image,quantum_info,quantum_type); |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 198 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 199 | GetQuantumPixels(quantum_info),&count); |
cristy | 9af8a2a | 2009-10-02 13:29:27 +0000 | [diff] [blame] | 200 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 201 | for (y=0; y < (ssize_t) image->extract_info.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 202 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 203 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 204 | *magick_restrict p; |
cristy | 9af8a2a | 2009-10-02 13:29:27 +0000 | [diff] [blame] | 205 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 206 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 207 | *magick_restrict q; |
cristy | 9af8a2a | 2009-10-02 13:29:27 +0000 | [diff] [blame] | 208 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 209 | register ssize_t |
| 210 | x; |
| 211 | |
cristy | 9af8a2a | 2009-10-02 13:29:27 +0000 | [diff] [blame] | 212 | if (count != (ssize_t) length) |
| 213 | { |
Cristy | 7a610d4 | 2017-09-14 07:18:36 -0400 | [diff] [blame] | 214 | status=MagickFalse; |
cristy | 128e20d | 2012-01-11 01:24:58 +0000 | [diff] [blame] | 215 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 216 | image->filename); |
cristy | 9af8a2a | 2009-10-02 13:29:27 +0000 | [diff] [blame] | 217 | break; |
| 218 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 219 | q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 220 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 221 | break; |
| 222 | length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,quantum_info, |
| 223 | quantum_type,pixels,exception); |
| 224 | if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse) |
| 225 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 226 | if (((y-image->extract_info.y) >= 0) && |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 227 | ((y-image->extract_info.y) < (ssize_t) image->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 228 | { |
| 229 | p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0, |
cristy | 9af8a2a | 2009-10-02 13:29:27 +0000 | [diff] [blame] | 230 | image->columns,1,exception); |
| 231 | q=QueueAuthenticPixels(image,0,y-image->extract_info.y,image->columns, |
| 232 | 1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 233 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 234 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 235 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 236 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 237 | SetPixelRed(image,GetPixelRed(canvas_image,p),q); |
| 238 | SetPixelGreen(image,GetPixelGreen(canvas_image,p),q); |
| 239 | SetPixelBlue(image,GetPixelBlue(canvas_image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 240 | p+=GetPixelChannels(canvas_image); |
| 241 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 242 | } |
| 243 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 244 | break; |
| 245 | } |
| 246 | if (image->previous == (Image *) NULL) |
| 247 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 248 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 249 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 250 | if (status == MagickFalse) |
| 251 | break; |
| 252 | } |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 253 | pixels=(const unsigned char *) ReadBlobStream(image,length, |
| 254 | GetQuantumPixels(quantum_info),&count); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 255 | } |
| 256 | SetQuantumImageType(image,quantum_type); |
| 257 | /* |
| 258 | Proceed to next image. |
| 259 | */ |
| 260 | if (image_info->number_scenes != 0) |
| 261 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 262 | break; |
| 263 | if (count == (ssize_t) length) |
| 264 | { |
| 265 | /* |
| 266 | Allocate next image structure. |
| 267 | */ |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 268 | AcquireNextImage(image_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 269 | if (GetNextImageInList(image) == (Image *) NULL) |
| 270 | { |
| 271 | image=DestroyImageList(image); |
| 272 | return((Image *) NULL); |
| 273 | } |
| 274 | image=SyncNextImageInList(image); |
| 275 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 276 | GetBlobSize(image)); |
| 277 | if (status == MagickFalse) |
| 278 | break; |
| 279 | } |
cristy | 9af8a2a | 2009-10-02 13:29:27 +0000 | [diff] [blame] | 280 | scene++; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 281 | } while (count == (ssize_t) length); |
| 282 | quantum_info=DestroyQuantumInfo(quantum_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 283 | canvas_image=DestroyImage(canvas_image); |
| 284 | (void) CloseBlob(image); |
Cristy | 7a610d4 | 2017-09-14 07:18:36 -0400 | [diff] [blame] | 285 | if (status == MagickFalse) |
| 286 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 287 | return(GetFirstImageInList(image)); |
| 288 | } |
| 289 | |
| 290 | /* |
| 291 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 292 | % % |
| 293 | % % |
| 294 | % % |
| 295 | % R e g i s t e r R A W I m a g e % |
| 296 | % % |
| 297 | % % |
| 298 | % % |
| 299 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 300 | % |
| 301 | % RegisterRAWImage() adds attributes for the RAW image format to the list of |
| 302 | % supported formats. The attributes include the image format tag, a method to |
| 303 | % read and/or write the format, whether the format supports the saving of |
| 304 | % more than one frame to the same file or blob, whether the format supports |
| 305 | % native in-memory I/O, and a brief description of the format. |
| 306 | % |
| 307 | % The format of the RegisterRAWImage method is: |
| 308 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 309 | % size_t RegisterRAWImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 310 | % |
| 311 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 312 | ModuleExport size_t RegisterRAWImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 313 | { |
| 314 | MagickInfo |
| 315 | *entry; |
| 316 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 317 | entry=AcquireMagickInfo("RAW","R","Raw red samples"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 318 | entry->decoder=(DecodeImageHandler *) ReadRAWImage; |
| 319 | entry->encoder=(EncodeImageHandler *) WriteRAWImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 320 | entry->flags|=CoderRawSupportFlag; |
| 321 | entry->flags|=CoderEndianSupportFlag; |
cristy | 32ccaaa | 2015-06-14 19:13:46 +0000 | [diff] [blame] | 322 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 323 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 324 | entry=AcquireMagickInfo("RAW","C","Raw cyan samples"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 325 | entry->decoder=(DecodeImageHandler *) ReadRAWImage; |
| 326 | entry->encoder=(EncodeImageHandler *) WriteRAWImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 327 | entry->flags|=CoderRawSupportFlag; |
| 328 | entry->flags|=CoderEndianSupportFlag; |
cristy | 32ccaaa | 2015-06-14 19:13:46 +0000 | [diff] [blame] | 329 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 330 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 331 | entry=AcquireMagickInfo("RAW","G","Raw green samples"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 332 | entry->decoder=(DecodeImageHandler *) ReadRAWImage; |
| 333 | entry->encoder=(EncodeImageHandler *) WriteRAWImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 334 | entry->flags|=CoderRawSupportFlag; |
| 335 | entry->flags|=CoderEndianSupportFlag; |
cristy | 32ccaaa | 2015-06-14 19:13:46 +0000 | [diff] [blame] | 336 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 337 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 338 | entry=AcquireMagickInfo("RAW","M","Raw magenta samples"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 339 | entry->decoder=(DecodeImageHandler *) ReadRAWImage; |
| 340 | entry->encoder=(EncodeImageHandler *) WriteRAWImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 341 | entry->flags|=CoderRawSupportFlag; |
| 342 | entry->flags|=CoderEndianSupportFlag; |
cristy | 32ccaaa | 2015-06-14 19:13:46 +0000 | [diff] [blame] | 343 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 344 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 345 | entry=AcquireMagickInfo("RAW","B","Raw blue samples"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 346 | entry->decoder=(DecodeImageHandler *) ReadRAWImage; |
| 347 | entry->encoder=(EncodeImageHandler *) WriteRAWImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 348 | entry->flags|=CoderRawSupportFlag; |
| 349 | entry->flags|=CoderEndianSupportFlag; |
cristy | 32ccaaa | 2015-06-14 19:13:46 +0000 | [diff] [blame] | 350 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 351 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 352 | entry=AcquireMagickInfo("RAW","Y","Raw yellow samples"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 353 | entry->decoder=(DecodeImageHandler *) ReadRAWImage; |
| 354 | entry->encoder=(EncodeImageHandler *) WriteRAWImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 355 | entry->flags|=CoderRawSupportFlag; |
| 356 | entry->flags|=CoderEndianSupportFlag; |
cristy | 32ccaaa | 2015-06-14 19:13:46 +0000 | [diff] [blame] | 357 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 358 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 359 | entry=AcquireMagickInfo("RAW","A","Raw alpha samples"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 360 | entry->decoder=(DecodeImageHandler *) ReadRAWImage; |
| 361 | entry->encoder=(EncodeImageHandler *) WriteRAWImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 362 | entry->flags|=CoderRawSupportFlag; |
| 363 | entry->flags|=CoderEndianSupportFlag; |
cristy | 32ccaaa | 2015-06-14 19:13:46 +0000 | [diff] [blame] | 364 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 365 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 366 | entry=AcquireMagickInfo("RAW","O","Raw opacity samples"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 367 | entry->decoder=(DecodeImageHandler *) ReadRAWImage; |
| 368 | entry->encoder=(EncodeImageHandler *) WriteRAWImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 369 | entry->flags|=CoderRawSupportFlag; |
| 370 | entry->flags|=CoderEndianSupportFlag; |
cristy | 32ccaaa | 2015-06-14 19:13:46 +0000 | [diff] [blame] | 371 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 372 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 373 | entry=AcquireMagickInfo("RAW","K","Raw black samples"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 374 | entry->decoder=(DecodeImageHandler *) ReadRAWImage; |
| 375 | entry->encoder=(EncodeImageHandler *) WriteRAWImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 376 | entry->flags|=CoderRawSupportFlag; |
| 377 | entry->flags|=CoderEndianSupportFlag; |
cristy | 32ccaaa | 2015-06-14 19:13:46 +0000 | [diff] [blame] | 378 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 379 | (void) RegisterMagickInfo(entry); |
| 380 | return(MagickImageCoderSignature); |
| 381 | } |
| 382 | |
| 383 | /* |
| 384 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 385 | % % |
| 386 | % % |
| 387 | % % |
| 388 | % U n r e g i s t e r R A W I m a g e % |
| 389 | % % |
| 390 | % % |
| 391 | % % |
| 392 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 393 | % |
| 394 | % UnregisterRAWImage() removes format registrations made by the RAW module |
| 395 | % from the list of supported formats. |
| 396 | % |
| 397 | % The format of the UnregisterRAWImage method is: |
| 398 | % |
| 399 | % UnregisterRAWImage(void) |
| 400 | % |
| 401 | */ |
| 402 | ModuleExport void UnregisterRAWImage(void) |
| 403 | { |
| 404 | (void) UnregisterMagickInfo("R"); |
| 405 | (void) UnregisterMagickInfo("C"); |
| 406 | (void) UnregisterMagickInfo("G"); |
| 407 | (void) UnregisterMagickInfo("M"); |
| 408 | (void) UnregisterMagickInfo("B"); |
| 409 | (void) UnregisterMagickInfo("Y"); |
| 410 | (void) UnregisterMagickInfo("A"); |
| 411 | (void) UnregisterMagickInfo("O"); |
| 412 | (void) UnregisterMagickInfo("K"); |
| 413 | } |
| 414 | |
| 415 | /* |
| 416 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 417 | % % |
| 418 | % % |
| 419 | % % |
| 420 | % W r i t e R A W I m a g e % |
| 421 | % % |
| 422 | % % |
| 423 | % % |
| 424 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 425 | % |
| 426 | % WriteRAWImage() writes an image to a file as raw intensity values. |
| 427 | % |
| 428 | % The format of the WriteRAWImage method is: |
| 429 | % |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 430 | % MagickBooleanType WriteRAWImage(const ImageInfo *image_info, |
| 431 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 432 | % |
| 433 | % A description of each parameter follows. |
| 434 | % |
| 435 | % o image_info: the image info. |
| 436 | % |
| 437 | % o image: The image. |
| 438 | % |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 439 | % o exception: return any errors or warnings in this structure. |
| 440 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 441 | */ |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 442 | static MagickBooleanType WriteRAWImage(const ImageInfo *image_info,Image *image, |
| 443 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 444 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 445 | MagickOffsetType |
| 446 | scene; |
| 447 | |
| 448 | QuantumInfo |
| 449 | *quantum_info; |
| 450 | |
| 451 | QuantumType |
| 452 | quantum_type; |
| 453 | |
| 454 | MagickBooleanType |
| 455 | status; |
| 456 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 457 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 458 | *p; |
| 459 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 460 | size_t |
| 461 | length; |
| 462 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 463 | ssize_t |
| 464 | count, |
| 465 | y; |
| 466 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 467 | unsigned char |
| 468 | *pixels; |
| 469 | |
| 470 | /* |
| 471 | Open output image file. |
| 472 | */ |
| 473 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 474 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 475 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 476 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 477 | if (image->debug != MagickFalse) |
| 478 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 479 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 480 | assert(exception->signature == MagickCoreSignature); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 481 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 482 | if (status == MagickFalse) |
| 483 | return(status); |
| 484 | switch (*image->magick) |
| 485 | { |
| 486 | case 'A': |
| 487 | case 'a': |
| 488 | { |
| 489 | quantum_type=AlphaQuantum; |
| 490 | break; |
| 491 | } |
| 492 | case 'B': |
| 493 | case 'b': |
| 494 | { |
| 495 | quantum_type=BlueQuantum; |
| 496 | break; |
| 497 | } |
| 498 | case 'C': |
| 499 | case 'c': |
| 500 | { |
| 501 | quantum_type=CyanQuantum; |
| 502 | if (image->colorspace == CMYKColorspace) |
| 503 | break; |
| 504 | ThrowWriterException(ImageError,"ColorSeparatedImageRequired"); |
| 505 | } |
| 506 | case 'g': |
| 507 | case 'G': |
| 508 | { |
| 509 | quantum_type=GreenQuantum; |
| 510 | break; |
| 511 | } |
| 512 | case 'I': |
| 513 | case 'i': |
| 514 | { |
| 515 | quantum_type=IndexQuantum; |
| 516 | break; |
| 517 | } |
| 518 | case 'K': |
| 519 | case 'k': |
| 520 | { |
| 521 | quantum_type=BlackQuantum; |
| 522 | if (image->colorspace == CMYKColorspace) |
| 523 | break; |
| 524 | ThrowWriterException(ImageError,"ColorSeparatedImageRequired"); |
| 525 | } |
| 526 | case 'M': |
| 527 | case 'm': |
| 528 | { |
| 529 | quantum_type=MagentaQuantum; |
| 530 | if (image->colorspace == CMYKColorspace) |
| 531 | break; |
| 532 | ThrowWriterException(ImageError,"ColorSeparatedImageRequired"); |
| 533 | } |
| 534 | case 'o': |
| 535 | case 'O': |
| 536 | { |
| 537 | quantum_type=OpacityQuantum; |
| 538 | break; |
| 539 | } |
| 540 | case 'R': |
| 541 | case 'r': |
| 542 | { |
| 543 | quantum_type=RedQuantum; |
| 544 | break; |
| 545 | } |
| 546 | case 'Y': |
| 547 | case 'y': |
| 548 | { |
| 549 | quantum_type=YellowQuantum; |
| 550 | if (image->colorspace == CMYKColorspace) |
| 551 | break; |
| 552 | ThrowWriterException(ImageError,"ColorSeparatedImageRequired"); |
| 553 | } |
| 554 | default: |
| 555 | { |
| 556 | quantum_type=GrayQuantum; |
| 557 | break; |
| 558 | } |
| 559 | } |
| 560 | scene=0; |
| 561 | do |
| 562 | { |
| 563 | /* |
| 564 | Convert image to RAW raster pixels. |
| 565 | */ |
cristy | 5f766ef | 2014-12-14 21:12:47 +0000 | [diff] [blame] | 566 | quantum_info=AcquireQuantumInfo(image_info,image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 567 | if (quantum_info == (QuantumInfo *) NULL) |
| 568 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | b3f97ae | 2015-05-18 12:29:32 +0000 | [diff] [blame] | 569 | pixels=(unsigned char *) GetQuantumPixels(quantum_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 570 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 571 | { |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 572 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 573 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 574 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 575 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 576 | quantum_type,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 577 | count=WriteBlob(image,length,pixels); |
| 578 | if (count != (ssize_t) length) |
| 579 | break; |
| 580 | if (image->previous == (Image *) NULL) |
| 581 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 582 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
cristy | 566c5a8 | 2010-06-06 15:37:51 +0000 | [diff] [blame] | 583 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 584 | if (status == MagickFalse) |
| 585 | break; |
| 586 | } |
| 587 | } |
| 588 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 589 | if (GetNextImageInList(image) == (Image *) NULL) |
| 590 | break; |
| 591 | image=SyncNextImageInList(image); |
| 592 | status=SetImageProgress(image,SaveImagesTag,scene++, |
| 593 | GetImageListLength(image)); |
| 594 | if (status == MagickFalse) |
| 595 | break; |
| 596 | } while (image_info->adjoin != MagickFalse); |
| 597 | (void) CloseBlob(image); |
| 598 | return(MagickTrue); |
| 599 | } |