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