cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % AAA RRRR TTTTT % |
| 7 | % A A R R T % |
| 8 | % AAAAA RRRR T % |
| 9 | % A A R R T % |
| 10 | % A A R R T % |
| 11 | % % |
| 12 | % % |
| 13 | % Support PFS: 1st Publisher Clip Art 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" |
cristy | 8941c70 | 2012-06-21 01:30:15 +0000 | [diff] [blame] | 43 | #include "MagickCore/attribute.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/blob-private.h" |
| 46 | #include "MagickCore/cache.h" |
| 47 | #include "MagickCore/color-private.h" |
| 48 | #include "MagickCore/colormap.h" |
| 49 | #include "MagickCore/colorspace.h" |
cristy | 510d06a | 2011-07-06 23:43:54 +0000 | [diff] [blame] | 50 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 51 | #include "MagickCore/exception.h" |
| 52 | #include "MagickCore/exception-private.h" |
| 53 | #include "MagickCore/image.h" |
| 54 | #include "MagickCore/image-private.h" |
| 55 | #include "MagickCore/list.h" |
| 56 | #include "MagickCore/magick.h" |
| 57 | #include "MagickCore/memory_.h" |
| 58 | #include "MagickCore/monitor.h" |
| 59 | #include "MagickCore/monitor-private.h" |
| 60 | #include "MagickCore/quantum-private.h" |
| 61 | #include "MagickCore/static.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 | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 69 | WriteARTImage(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 A R T I m a g e % |
| 77 | % % |
| 78 | % % |
| 79 | % % |
| 80 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 81 | % |
| 82 | % ReadARTImage() reads an image of raw bits in LSB order and returns it. |
| 83 | % It allocates the memory necessary for the new Image structure and returns |
| 84 | % a pointer to the new image. |
| 85 | % |
| 86 | % The format of the ReadARTImage method is: |
| 87 | % |
| 88 | % Image *ReadARTImage(const ImageInfo *image_info, |
| 89 | % ExceptionInfo *exception) |
| 90 | % |
| 91 | % A description of each parameter follows: |
| 92 | % |
| 93 | % o image_info: the image info. |
| 94 | % |
| 95 | % o exception: return any errors or warnings in this structure. |
| 96 | % |
| 97 | */ |
| 98 | static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 99 | { |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame^] | 100 | const void |
| 101 | *pixels; |
| 102 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 | Image |
| 104 | *image; |
| 105 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 | QuantumInfo |
| 107 | *quantum_info; |
| 108 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 109 | MagickBooleanType |
| 110 | status; |
| 111 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 | size_t |
| 113 | length; |
| 114 | |
cristy | bdadf31 | 2011-04-23 23:16:21 +0000 | [diff] [blame] | 115 | ssize_t |
| 116 | count, |
| 117 | y; |
| 118 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 119 | /* |
| 120 | Open image file. |
| 121 | */ |
| 122 | assert(image_info != (const ImageInfo *) NULL); |
| 123 | assert(image_info->signature == MagickSignature); |
| 124 | if (image_info->debug != MagickFalse) |
| 125 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 126 | image_info->filename); |
| 127 | assert(exception != (ExceptionInfo *) NULL); |
| 128 | assert(exception->signature == MagickSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 129 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 130 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 131 | if (status == MagickFalse) |
| 132 | { |
| 133 | image=DestroyImageList(image); |
| 134 | return((Image *) NULL); |
| 135 | } |
| 136 | image->depth=1; |
| 137 | image->endian=MSBEndian; |
| 138 | (void) ReadBlobLSBShort(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 139 | image->columns=(size_t) ReadBlobLSBShort(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 140 | (void) ReadBlobLSBShort(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 141 | image->rows=(size_t) ReadBlobLSBShort(image); |
cristy | dacfa01 | 2012-07-11 22:04:06 +0000 | [diff] [blame] | 142 | if ((image->columns == 0) || (image->rows == 0)) |
| 143 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 144 | if (image_info->ping != MagickFalse) |
| 145 | { |
| 146 | (void) CloseBlob(image); |
| 147 | return(GetFirstImageInList(image)); |
| 148 | } |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 149 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 150 | if (status == MagickFalse) |
| 151 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 152 | /* |
| 153 | Convert bi-level image to pixel packets. |
| 154 | */ |
cristy | b2c3f40 | 2012-05-13 18:05:12 +0000 | [diff] [blame] | 155 | SetImageColorspace(image,GRAYColorspace,exception); |
cristy | 5f766ef | 2014-12-14 21:12:47 +0000 | [diff] [blame] | 156 | quantum_info=AcquireQuantumInfo(image_info,image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 157 | if (quantum_info == (QuantumInfo *) NULL) |
| 158 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | 100b8d9 | 2012-01-08 00:32:49 +0000 | [diff] [blame] | 159 | length=GetQuantumExtent(image,quantum_info,GrayQuantum); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 160 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 161 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 162 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 163 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 164 | |
| 165 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 166 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 167 | break; |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame^] | 168 | pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info), |
| 169 | &count); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 170 | if (count != (ssize_t) length) |
| 171 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 172 | (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 100b8d9 | 2012-01-08 00:32:49 +0000 | [diff] [blame] | 173 | GrayQuantum,pixels,exception); |
cristy | bd797f1 | 2015-01-24 20:42:32 +0000 | [diff] [blame^] | 174 | pixels=ReadBlobStream(image,(size_t) (-(ssize_t) length) & 0x01, |
| 175 | GetQuantumPixels(quantum_info),&count); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 176 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 177 | break; |
| 178 | if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse) |
| 179 | break; |
| 180 | } |
cristy | 100b8d9 | 2012-01-08 00:32:49 +0000 | [diff] [blame] | 181 | SetQuantumImageType(image,GrayQuantum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 183 | if (EOFBlob(image) != MagickFalse) |
| 184 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 185 | image->filename); |
| 186 | (void) CloseBlob(image); |
| 187 | return(GetFirstImageInList(image)); |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 192 | % % |
| 193 | % % |
| 194 | % % |
| 195 | % R e g i s t e r A R T I m a g e % |
| 196 | % % |
| 197 | % % |
| 198 | % % |
| 199 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 200 | % |
| 201 | % RegisterARTImage() adds attributes for the ART image format to |
| 202 | % the list of supported formats. The attributes include the image format |
| 203 | % tag, a method to read and/or write the format, whether the format |
| 204 | % supports the saving of more than one frame to the same file or blob, |
| 205 | % whether the format supports native in-memory I/O, and a brief |
| 206 | % description of the format. |
| 207 | % |
| 208 | % The format of the RegisterARTImage method is: |
| 209 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 210 | % size_t RegisterARTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 211 | % |
| 212 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 213 | ModuleExport size_t RegisterARTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 214 | { |
| 215 | MagickInfo |
| 216 | *entry; |
| 217 | |
| 218 | entry=SetMagickInfo("ART"); |
| 219 | entry->decoder=(DecodeImageHandler *) ReadARTImage; |
| 220 | entry->encoder=(EncodeImageHandler *) WriteARTImage; |
| 221 | entry->raw=MagickTrue; |
| 222 | entry->adjoin=MagickFalse; |
| 223 | entry->description=ConstantString("PFS: 1st Publisher Clip Art"); |
| 224 | entry->module=ConstantString("ART"); |
| 225 | (void) RegisterMagickInfo(entry); |
| 226 | return(MagickImageCoderSignature); |
| 227 | } |
| 228 | |
| 229 | /* |
| 230 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 231 | % % |
| 232 | % % |
| 233 | % % |
| 234 | % U n r e g i s t e r A R T I m a g e % |
| 235 | % % |
| 236 | % % |
| 237 | % % |
| 238 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 239 | % |
| 240 | % UnregisterARTImage() removes format registrations made by the |
| 241 | % ART module from the list of supported formats. |
| 242 | % |
| 243 | % The format of the UnregisterARTImage method is: |
| 244 | % |
| 245 | % UnregisterARTImage(void) |
| 246 | % |
| 247 | */ |
| 248 | ModuleExport void UnregisterARTImage(void) |
| 249 | { |
| 250 | (void) UnregisterMagickInfo("ART"); |
| 251 | } |
| 252 | |
| 253 | /* |
| 254 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 255 | % % |
| 256 | % % |
| 257 | % % |
| 258 | % W r i t e A R T I m a g e % |
| 259 | % % |
| 260 | % % |
| 261 | % % |
| 262 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 263 | % |
| 264 | % WriteARTImage() writes an image of raw bits in LSB order to a file. |
| 265 | % |
| 266 | % The format of the WriteARTImage method is: |
| 267 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 268 | % MagickBooleanType WriteARTImage(const ImageInfo *image_info, |
| 269 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 270 | % |
| 271 | % A description of each parameter follows. |
| 272 | % |
| 273 | % o image_info: the image info. |
| 274 | % |
| 275 | % o image: The image. |
| 276 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 277 | % o exception: return any errors or warnings in this structure. |
| 278 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 279 | */ |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 280 | static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image, |
| 281 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 282 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 283 | MagickBooleanType |
| 284 | status; |
| 285 | |
| 286 | QuantumInfo |
| 287 | *quantum_info; |
| 288 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 289 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 290 | *p; |
| 291 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 292 | size_t |
cristy | 94b1183 | 2011-09-08 19:46:03 +0000 | [diff] [blame] | 293 | length; |
| 294 | |
| 295 | ssize_t |
| 296 | count, |
cristy | 4e82e51 | 2011-04-24 01:33:42 +0000 | [diff] [blame] | 297 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 298 | |
| 299 | unsigned char |
| 300 | *pixels; |
| 301 | |
| 302 | /* |
| 303 | Open output image file. |
| 304 | */ |
| 305 | assert(image_info != (const ImageInfo *) NULL); |
| 306 | assert(image_info->signature == MagickSignature); |
| 307 | assert(image != (Image *) NULL); |
| 308 | assert(image->signature == MagickSignature); |
| 309 | if (image->debug != MagickFalse) |
| 310 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 311 | assert(exception != (ExceptionInfo *) NULL); |
| 312 | assert(exception->signature == MagickSignature); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 313 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 314 | if (status == MagickFalse) |
| 315 | return(status); |
| 316 | if ((image->columns > 65535UL) || (image->rows > 65535UL)) |
| 317 | ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit"); |
cristy | af8d391 | 2014-02-21 14:50:33 +0000 | [diff] [blame] | 318 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
cristy | 100b8d9 | 2012-01-08 00:32:49 +0000 | [diff] [blame] | 319 | (void) SetImageType(image,BilevelType,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 320 | image->endian=MSBEndian; |
| 321 | image->depth=1; |
| 322 | (void) WriteBlobLSBShort(image,0); |
| 323 | (void) WriteBlobLSBShort(image,(unsigned short) image->columns); |
| 324 | (void) WriteBlobLSBShort(image,0); |
| 325 | (void) WriteBlobLSBShort(image,(unsigned short) image->rows); |
cristy | 5f766ef | 2014-12-14 21:12:47 +0000 | [diff] [blame] | 326 | quantum_info=AcquireQuantumInfo(image_info,image); |
cristy | 100b8d9 | 2012-01-08 00:32:49 +0000 | [diff] [blame] | 327 | pixels=GetQuantumPixels(quantum_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 328 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 329 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 330 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 331 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 332 | break; |
cristy | 100b8d9 | 2012-01-08 00:32:49 +0000 | [diff] [blame] | 333 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 334 | GrayQuantum,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 335 | count=WriteBlob(image,length,pixels); |
| 336 | if (count != (ssize_t) length) |
| 337 | ThrowWriterException(CorruptImageError,"UnableToWriteImageData"); |
| 338 | count=WriteBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels); |
cristy | bdadf31 | 2011-04-23 23:16:21 +0000 | [diff] [blame] | 339 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 340 | image->rows); |
| 341 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 342 | break; |
| 343 | } |
| 344 | quantum_info=DestroyQuantumInfo(quantum_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 345 | (void) CloseBlob(image); |
cristy | 100b8d9 | 2012-01-08 00:32:49 +0000 | [diff] [blame] | 346 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 347 | } |