2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Support PFS: 1st Publisher Clip Art Format %
20 % Copyright 1999-2012 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 "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"
49 #include "MagickCore/colorspace-private.h"
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"
67 static MagickBooleanType
68 WriteARTImage(const ImageInfo *,Image *,ExceptionInfo *);
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 % R e a d A R T I m a g e %
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.
85 % The format of the ReadARTImage method is:
87 % Image *ReadARTImage(const ImageInfo *image_info,
88 % ExceptionInfo *exception)
90 % A description of each parameter follows:
92 % o image_info: the image info.
94 % o exception: return any errors or warnings in this structure.
97 static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception)
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);
128 image=AcquireImage(image_info,exception);
129 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
130 if (status == MagickFalse)
132 image=DestroyImageList(image);
133 return((Image *) NULL);
135 image->colorspace=GRAYColorspace;
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_info->ping != MagickFalse)
144 (void) CloseBlob(image);
145 return(GetFirstImageInList(image));
148 Convert bi-level image to pixel packets.
150 quantum_info=AcquireQuantumInfo(image_info,image);
151 if (quantum_info == (QuantumInfo *) NULL)
152 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
153 pixels=GetQuantumPixels(quantum_info);
154 length=GetQuantumExtent(image,quantum_info,GrayQuantum);
155 for (y=0; y < (ssize_t) image->rows; y++)
160 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
161 if (q == (Quantum *) NULL)
163 count=ReadBlob(image,length,pixels);
164 if (count != (ssize_t) length)
165 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
166 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
167 GrayQuantum,pixels,exception);
168 count=ReadBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
169 if (SyncAuthenticPixels(image,exception) == MagickFalse)
171 if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
174 SetQuantumImageType(image,GrayQuantum);
175 quantum_info=DestroyQuantumInfo(quantum_info);
176 if (EOFBlob(image) != MagickFalse)
177 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
179 (void) CloseBlob(image);
180 return(GetFirstImageInList(image));
184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 % R e g i s t e r A R T I m a g e %
192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.
201 % The format of the RegisterARTImage method is:
203 % size_t RegisterARTImage(void)
206 ModuleExport size_t RegisterARTImage(void)
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);
223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227 % U n r e g i s t e r A R T I m a g e %
231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 % UnregisterARTImage() removes format registrations made by the
234 % ART module from the list of supported formats.
236 % The format of the UnregisterARTImage method is:
238 % UnregisterARTImage(void)
241 ModuleExport void UnregisterARTImage(void)
243 (void) UnregisterMagickInfo("ART");
247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 % W r i t e A R T I m a g e %
255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 % WriteARTImage() writes an image of raw bits in LSB order to a file.
259 % The format of the WriteARTImage method is:
261 % MagickBooleanType WriteARTImage(const ImageInfo *image_info,
262 % Image *image,ExceptionInfo *exception)
264 % A description of each parameter follows.
266 % o image_info: the image info.
268 % o image: The image.
270 % o exception: return any errors or warnings in this structure.
273 static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image,
274 ExceptionInfo *exception)
282 register const Quantum
296 Open output image file.
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);
304 assert(exception != (ExceptionInfo *) NULL);
305 assert(exception->signature == MagickSignature);
306 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
307 if (status == MagickFalse)
309 if ((image->columns > 65535UL) || (image->rows > 65535UL))
310 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
311 if (IssRGBColorspace(image->colorspace) == MagickFalse)
312 (void) TransformImageColorspace(image,sRGBColorspace,exception);
313 (void) SetImageType(image,BilevelType,exception);
314 image->endian=MSBEndian;
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);
320 quantum_info=AcquireQuantumInfo(image_info,image);
321 pixels=GetQuantumPixels(quantum_info);
322 for (y=0; y < (ssize_t) image->rows; y++)
324 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
325 if (p == (const Quantum *) NULL)
327 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
328 GrayQuantum,pixels,exception);
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);
333 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
335 if (status == MagickFalse)
338 quantum_info=DestroyQuantumInfo(quantum_info);
339 (void) CloseBlob(image);