2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Support PFS: 1st Publisher Clip Art Format %
20 % Copyright 1999-2011 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 % http://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 "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/cache.h"
46 #include "magick/color-private.h"
47 #include "magick/colormap.h"
48 #include "magick/colorspace.h"
49 #include "magick/exception.h"
50 #include "magick/exception-private.h"
51 #include "magick/image.h"
52 #include "magick/image-private.h"
53 #include "magick/list.h"
54 #include "magick/magick.h"
55 #include "magick/memory_.h"
56 #include "magick/monitor.h"
57 #include "magick/monitor-private.h"
58 #include "magick/quantum-private.h"
59 #include "magick/static.h"
60 #include "magick/string_.h"
61 #include "magick/module.h"
66 static MagickBooleanType
67 WriteARTImage(const ImageInfo *,Image *);
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 % R e a d A R T I m a g e %
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 % ReadARTImage() reads an image of raw bits in LSB order and returns it.
81 % It allocates the memory necessary for the new Image structure and returns
82 % a pointer to the new image.
84 % The format of the ReadARTImage method is:
86 % Image *ReadARTImage(const ImageInfo *image_info,
87 % ExceptionInfo *exception)
89 % A description of each parameter follows:
91 % o image_info: the image info.
93 % o exception: return any errors or warnings in this structure.
96 static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception)
123 assert(image_info != (const ImageInfo *) NULL);
124 assert(image_info->signature == MagickSignature);
125 if (image_info->debug != MagickFalse)
126 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
127 image_info->filename);
128 assert(exception != (ExceptionInfo *) NULL);
129 assert(exception->signature == MagickSignature);
130 image=AcquireImage(image_info);
131 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
132 if (status == MagickFalse)
134 image=DestroyImageList(image);
135 return((Image *) NULL);
138 image->endian=MSBEndian;
139 (void) ReadBlobLSBShort(image);
140 image->columns=(size_t) ReadBlobLSBShort(image);
141 (void) ReadBlobLSBShort(image);
142 image->rows=(size_t) ReadBlobLSBShort(image);
144 Initialize image colormap.
146 if (AcquireImageColormap(image,2) == MagickFalse)
147 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
148 if (image_info->ping != MagickFalse)
150 (void) CloseBlob(image);
151 return(GetFirstImageInList(image));
154 Convert bi-level image to pixel packets.
156 quantum_type=IndexQuantum;
157 quantum_info=AcquireQuantumInfo(image_info,image);
158 if (quantum_info == (QuantumInfo *) NULL)
159 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
160 pixels=GetQuantumPixels(quantum_info);
161 length=GetQuantumExtent(image,quantum_info,quantum_type);
162 for (y=0; y < (ssize_t) image->rows; y++)
167 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
168 if (q == (PixelPacket *) NULL)
170 count=ReadBlob(image,length,pixels);
171 if (count != (ssize_t) length)
172 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
173 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
174 quantum_type,pixels,exception);
175 count=ReadBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
176 if (SyncAuthenticPixels(image,exception) == MagickFalse)
178 if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
181 SetQuantumImageType(image,quantum_type);
182 quantum_info=DestroyQuantumInfo(quantum_info);
183 if (EOFBlob(image) != MagickFalse)
184 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
186 (void) CloseBlob(image);
187 return(GetFirstImageInList(image));
191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 % R e g i s t e r A R T I m a g e %
199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.
208 % The format of the RegisterARTImage method is:
210 % size_t RegisterARTImage(void)
213 ModuleExport size_t RegisterARTImage(void)
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);
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 % U n r e g i s t e r A R T I m a g e %
238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 % UnregisterARTImage() removes format registrations made by the
241 % ART module from the list of supported formats.
243 % The format of the UnregisterARTImage method is:
245 % UnregisterARTImage(void)
248 ModuleExport void UnregisterARTImage(void)
250 (void) UnregisterMagickInfo("ART");
254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258 % W r i t e A R T I m a g e %
262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 % WriteARTImage() writes an image of raw bits in LSB order to a file.
266 % The format of the WriteARTImage method is:
268 % MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image)
270 % A description of each parameter follows.
272 % o image_info: the image info.
274 % o image: The image.
277 static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image)
285 register const PixelPacket
299 Open output image file.
301 assert(image_info != (const ImageInfo *) NULL);
302 assert(image_info->signature == MagickSignature);
303 assert(image != (Image *) NULL);
304 assert(image->signature == MagickSignature);
305 if (image->debug != MagickFalse)
306 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
307 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
308 if (status == MagickFalse)
310 if ((image->columns > 65535UL) || (image->rows > 65535UL))
311 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
312 image->endian=MSBEndian;
314 (void) WriteBlobLSBShort(image,0);
315 (void) WriteBlobLSBShort(image,(unsigned short) image->columns);
316 (void) WriteBlobLSBShort(image,0);
317 (void) WriteBlobLSBShort(image,(unsigned short) image->rows);
318 if (image->colorspace != RGBColorspace)
319 (void) TransformImageColorspace(image,RGBColorspace);
320 length=(image->columns+7)/8;
321 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
322 if (pixels == (unsigned char *) NULL)
323 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
325 Convert image to a bi-level image.
327 (void) SetImageType(image,BilevelType);
328 quantum_info=AcquireQuantumInfo(image_info,image);
329 for (y=0; y < (ssize_t) image->rows; y++)
331 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
332 if (p == (const PixelPacket *) NULL)
334 (void) ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
335 GrayQuantum,pixels,&image->exception);
336 count=WriteBlob(image,length,pixels);
337 if (count != (ssize_t) length)
338 ThrowWriterException(CorruptImageError,"UnableToWriteImageData");
339 count=WriteBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
340 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
342 if (status == MagickFalse)
345 quantum_info=DestroyQuantumInfo(quantum_info);
346 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
347 (void) CloseBlob(image);