2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Support PFS: 1st Publisher Clip Art Format %
20 % Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % https://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/attribute.h"
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"
50 #include "MagickCore/colorspace-private.h"
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"
68 static MagickBooleanType
69 WriteARTImage(const ImageInfo *,Image *,ExceptionInfo *);
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 % R e a d A R T I m a g e %
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.
86 % The format of the ReadARTImage method is:
88 % Image *ReadARTImage(const ImageInfo *image_info,
89 % ExceptionInfo *exception)
91 % A description of each parameter follows:
93 % o image_info: the image info.
95 % o exception: return any errors or warnings in this structure.
98 static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception)
122 assert(image_info != (const ImageInfo *) NULL);
123 assert(image_info->signature == MagickCoreSignature);
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 == MagickCoreSignature);
129 image=AcquireImage(image_info,exception);
130 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
131 if (status == MagickFalse)
133 image=DestroyImageList(image);
134 return((Image *) NULL);
137 image->endian=MSBEndian;
138 (void) ReadBlobLSBShort(image);
139 image->columns=(size_t) ReadBlobLSBShort(image);
140 (void) ReadBlobLSBShort(image);
141 image->rows=(size_t) ReadBlobLSBShort(image);
142 if ((image->columns == 0) || (image->rows == 0))
143 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
144 if (image_info->ping != MagickFalse)
146 (void) CloseBlob(image);
147 return(GetFirstImageInList(image));
149 status=SetImageExtent(image,image->columns,image->rows,exception);
150 if (status == MagickFalse)
151 return(DestroyImageList(image));
153 Convert bi-level image to pixel packets.
155 SetImageColorspace(image,GRAYColorspace,exception);
156 quantum_info=AcquireQuantumInfo(image_info,image);
157 if (quantum_info == (QuantumInfo *) NULL)
158 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
159 length=GetQuantumExtent(image,quantum_info,GrayQuantum);
160 for (y=0; y < (ssize_t) image->rows; y++)
165 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
166 if (q == (Quantum *) NULL)
168 pixels=(const unsigned char *) ReadBlobStream(image,length,
169 GetQuantumPixels(quantum_info),&count);
170 if (count != (ssize_t) length)
172 quantum_info=DestroyQuantumInfo(quantum_info);
173 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
175 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
176 GrayQuantum,pixels,exception);
177 pixels=(const unsigned char *) ReadBlobStream(image,(size_t) (-(ssize_t)
178 length) & 0x01,GetQuantumPixels(quantum_info),&count);
179 if (SyncAuthenticPixels(image,exception) == MagickFalse)
181 if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
184 SetQuantumImageType(image,GrayQuantum);
185 quantum_info=DestroyQuantumInfo(quantum_info);
186 if (EOFBlob(image) != MagickFalse)
187 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
189 (void) CloseBlob(image);
190 return(GetFirstImageInList(image));
194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 % R e g i s t e r A R T I m a g e %
202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204 % RegisterARTImage() adds attributes for the ART image format to
205 % the list of supported formats. The attributes include the image format
206 % tag, a method to read and/or write the format, whether the format
207 % supports the saving of more than one frame to the same file or blob,
208 % whether the format supports native in-memory I/O, and a brief
209 % description of the format.
211 % The format of the RegisterARTImage method is:
213 % size_t RegisterARTImage(void)
216 ModuleExport size_t RegisterARTImage(void)
221 entry=AcquireMagickInfo("ART","ART","PFS: 1st Publisher Clip Art");
222 entry->decoder=(DecodeImageHandler *) ReadARTImage;
223 entry->encoder=(EncodeImageHandler *) WriteARTImage;
224 entry->flags|=CoderRawSupportFlag;
225 entry->flags^=CoderAdjoinFlag;
226 (void) RegisterMagickInfo(entry);
227 return(MagickImageCoderSignature);
231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235 % U n r e g i s t e r A R T I m a g e %
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241 % UnregisterARTImage() removes format registrations made by the
242 % ART module from the list of supported formats.
244 % The format of the UnregisterARTImage method is:
246 % UnregisterARTImage(void)
249 ModuleExport void UnregisterARTImage(void)
251 (void) UnregisterMagickInfo("ART");
255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 % W r i t e A R T I m a g e %
263 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265 % WriteARTImage() writes an image of raw bits in LSB order to a file.
267 % The format of the WriteARTImage method is:
269 % MagickBooleanType WriteARTImage(const ImageInfo *image_info,
270 % Image *image,ExceptionInfo *exception)
272 % A description of each parameter follows.
274 % o image_info: the image info.
276 % o image: The image.
278 % o exception: return any errors or warnings in this structure.
281 static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image,
282 ExceptionInfo *exception)
290 register const Quantum
304 Open output image file.
306 assert(image_info != (const ImageInfo *) NULL);
307 assert(image_info->signature == MagickCoreSignature);
308 assert(image != (Image *) NULL);
309 assert(image->signature == MagickCoreSignature);
310 if (image->debug != MagickFalse)
311 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
312 assert(exception != (ExceptionInfo *) NULL);
313 assert(exception->signature == MagickCoreSignature);
314 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
315 if (status == MagickFalse)
317 if ((image->columns > 65535UL) || (image->rows > 65535UL))
318 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
319 (void) TransformImageColorspace(image,sRGBColorspace,exception);
320 (void) SetImageType(image,BilevelType,exception);
321 image->endian=MSBEndian;
323 (void) WriteBlobLSBShort(image,0);
324 (void) WriteBlobLSBShort(image,(unsigned short) image->columns);
325 (void) WriteBlobLSBShort(image,0);
326 (void) WriteBlobLSBShort(image,(unsigned short) image->rows);
327 quantum_info=AcquireQuantumInfo(image_info,image);
328 if (quantum_info == (QuantumInfo *) NULL)
329 ThrowWriterException(ImageError,"MemoryAllocationFailed");
330 pixels=(unsigned char *) GetQuantumPixels(quantum_info);
331 for (y=0; y < (ssize_t) image->rows; y++)
333 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
334 if (p == (const Quantum *) NULL)
336 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
337 GrayQuantum,pixels,exception);
338 count=WriteBlob(image,length,pixels);
339 if (count != (ssize_t) length)
340 ThrowWriterException(CorruptImageError,"UnableToWriteImageData");
341 count=WriteBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
342 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
344 if (status == MagickFalse)
347 quantum_info=DestroyQuantumInfo(quantum_info);
348 (void) CloseBlob(image);