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