2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Support PFS: 1st Publisher Clip Art Format %
20 % Copyright 1999-2010 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)
125 assert(image_info != (const ImageInfo *) NULL);
126 assert(image_info->signature == MagickSignature);
127 if (image_info->debug != MagickFalse)
128 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
129 image_info->filename);
130 assert(exception != (ExceptionInfo *) NULL);
131 assert(exception->signature == MagickSignature);
132 image=AcquireImage(image_info);
133 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
134 if (status == MagickFalse)
136 image=DestroyImageList(image);
137 return((Image *) NULL);
140 image->endian=MSBEndian;
141 (void) ReadBlobLSBShort(image);
142 image->columns=(size_t) ReadBlobLSBShort(image);
143 (void) ReadBlobLSBShort(image);
144 image->rows=(size_t) ReadBlobLSBShort(image);
146 Initialize image colormap.
148 if (AcquireImageColormap(image,2) == MagickFalse)
149 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
150 if (image_info->ping != MagickFalse)
152 (void) CloseBlob(image);
153 return(GetFirstImageInList(image));
156 Convert bi-level image to pixel packets.
158 quantum_type=IndexQuantum;
159 quantum_info=AcquireQuantumInfo(image_info,image);
160 if (quantum_info == (QuantumInfo *) NULL)
161 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
162 pixels=GetQuantumPixels(quantum_info);
163 length=GetQuantumExtent(image,quantum_info,quantum_type);
164 for (y=0; y < (ssize_t) image->rows; y++)
169 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
170 if (q == (PixelPacket *) NULL)
172 count=ReadBlob(image,length,pixels);
173 if (count != (ssize_t) length)
174 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
175 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
176 quantum_type,pixels,exception);
177 count=ReadBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
178 if (SyncAuthenticPixels(image,exception) == MagickFalse)
180 if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
183 SetQuantumImageType(image,quantum_type);
184 quantum_info=DestroyQuantumInfo(quantum_info);
185 if (EOFBlob(image) != MagickFalse)
186 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
188 (void) CloseBlob(image);
189 return(GetFirstImageInList(image));
193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197 % R e g i s t e r A R T I m a g e %
201 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 % RegisterARTImage() adds attributes for the ART image format to
204 % the list of supported formats. The attributes include the image format
205 % tag, a method to read and/or write the format, whether the format
206 % supports the saving of more than one frame to the same file or blob,
207 % whether the format supports native in-memory I/O, and a brief
208 % description of the format.
210 % The format of the RegisterARTImage method is:
212 % size_t RegisterARTImage(void)
215 ModuleExport size_t RegisterARTImage(void)
220 entry=SetMagickInfo("ART");
221 entry->decoder=(DecodeImageHandler *) ReadARTImage;
222 entry->encoder=(EncodeImageHandler *) WriteARTImage;
223 entry->raw=MagickTrue;
224 entry->adjoin=MagickFalse;
225 entry->description=ConstantString("PFS: 1st Publisher Clip Art");
226 entry->module=ConstantString("ART");
227 (void) RegisterMagickInfo(entry);
228 return(MagickImageCoderSignature);
232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236 % U n r e g i s t e r A R T I m a g e %
240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242 % UnregisterARTImage() removes format registrations made by the
243 % ART module from the list of supported formats.
245 % The format of the UnregisterARTImage method is:
247 % UnregisterARTImage(void)
250 ModuleExport void UnregisterARTImage(void)
252 (void) UnregisterMagickInfo("ART");
256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
260 % W r i t e A R T I m a g e %
264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266 % WriteARTImage() writes an image of raw bits in LSB order to a file.
268 % The format of the WriteARTImage method is:
270 % MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image)
272 % A description of each parameter follows.
274 % o image_info: the image info.
276 % o image: The image.
279 static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image)
290 register const PixelPacket
303 Open output image file.
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);
311 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
312 if (status == MagickFalse)
314 if ((image->columns > 65535UL) || (image->rows > 65535UL))
315 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
316 image->endian=MSBEndian;
318 (void) WriteBlobLSBShort(image,0);
319 (void) WriteBlobLSBShort(image,(unsigned short) image->columns);
320 (void) WriteBlobLSBShort(image,0);
321 (void) WriteBlobLSBShort(image,(unsigned short) image->rows);
322 if (image->colorspace != RGBColorspace)
323 (void) TransformImageColorspace(image,RGBColorspace);
324 length=(image->columns+7)/8;
325 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
326 if (pixels == (unsigned char *) NULL)
327 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
329 Convert image to a bi-level image.
331 (void) SetImageType(image,BilevelType);
332 quantum_info=AcquireQuantumInfo(image_info,image);
333 for (y=0; y < (ssize_t) image->rows; y++)
335 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
336 if (p == (const PixelPacket *) NULL)
338 (void) ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
339 GrayQuantum,pixels,&image->exception);
340 count=WriteBlob(image,length,pixels);
341 if (count != (ssize_t) length)
342 ThrowWriterException(CorruptImageError,"UnableToWriteImageData");
343 count=WriteBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
344 if (SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,image->rows) == MagickFalse)
347 quantum_info=DestroyQuantumInfo(quantum_info);
348 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
349 (void) CloseBlob(image);