blob: 677f2fa16d7020186573dd497c21ac9634534c15 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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*/
cristy4c08aed2011-07-01 19:47:50 +000042#include "MagickCore/studio.h"
cristy8941c702012-06-21 01:30:15 +000043#include "MagickCore/attribute.h"
cristy4c08aed2011-07-01 19:47:50 +000044#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"
cristy510d06a2011-07-06 23:43:54 +000050#include "MagickCore/colorspace-private.h"
cristy4c08aed2011-07-01 19:47:50 +000051#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"
cristy3ed852e2009-09-05 21:47:34 +000064
65/*
66 Forward declarations.
67*/
68static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +000069 WriteARTImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +000070
71/*
72%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73% %
74% %
75% %
76% R e a d A R T I m a g e %
77% %
78% %
79% %
80%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81%
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.
85%
86% The format of the ReadARTImage method is:
87%
88% Image *ReadARTImage(const ImageInfo *image_info,
89% ExceptionInfo *exception)
90%
91% A description of each parameter follows:
92%
93% o image_info: the image info.
94%
95% o exception: return any errors or warnings in this structure.
96%
97*/
98static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception)
99{
100 Image
101 *image;
102
cristy3ed852e2009-09-05 21:47:34 +0000103 QuantumInfo
104 *quantum_info;
105
cristy3ed852e2009-09-05 21:47:34 +0000106 MagickBooleanType
107 status;
108
cristy3ed852e2009-09-05 21:47:34 +0000109 size_t
110 length;
111
cristybdadf312011-04-23 23:16:21 +0000112 ssize_t
113 count,
114 y;
115
cristy3ed852e2009-09-05 21:47:34 +0000116 unsigned char
117 *pixels;
118
119 /*
120 Open image file.
121 */
122 assert(image_info != (const ImageInfo *) NULL);
123 assert(image_info->signature == MagickSignature);
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 == MagickSignature);
cristy9950d572011-10-01 18:22:35 +0000129 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000130 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
131 if (status == MagickFalse)
132 {
133 image=DestroyImageList(image);
134 return((Image *) NULL);
135 }
136 image->depth=1;
137 image->endian=MSBEndian;
138 (void) ReadBlobLSBShort(image);
cristybb503372010-05-27 20:51:26 +0000139 image->columns=(size_t) ReadBlobLSBShort(image);
cristy3ed852e2009-09-05 21:47:34 +0000140 (void) ReadBlobLSBShort(image);
cristybb503372010-05-27 20:51:26 +0000141 image->rows=(size_t) ReadBlobLSBShort(image);
cristy3ed852e2009-09-05 21:47:34 +0000142 if (image_info->ping != MagickFalse)
143 {
144 (void) CloseBlob(image);
145 return(GetFirstImageInList(image));
146 }
147 /*
148 Convert bi-level image to pixel packets.
149 */
cristyb2c3f402012-05-13 18:05:12 +0000150 SetImageColorspace(image,GRAYColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000151 quantum_info=AcquireQuantumInfo(image_info,image);
152 if (quantum_info == (QuantumInfo *) NULL)
153 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
154 pixels=GetQuantumPixels(quantum_info);
cristy100b8d92012-01-08 00:32:49 +0000155 length=GetQuantumExtent(image,quantum_info,GrayQuantum);
cristybb503372010-05-27 20:51:26 +0000156 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000157 {
cristy4c08aed2011-07-01 19:47:50 +0000158 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000159 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000160
161 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000162 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000163 break;
164 count=ReadBlob(image,length,pixels);
165 if (count != (ssize_t) length)
166 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
167 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy100b8d92012-01-08 00:32:49 +0000168 GrayQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000169 count=ReadBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
170 if (SyncAuthenticPixels(image,exception) == MagickFalse)
171 break;
172 if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
173 break;
174 }
cristy100b8d92012-01-08 00:32:49 +0000175 SetQuantumImageType(image,GrayQuantum);
cristy3ed852e2009-09-05 21:47:34 +0000176 quantum_info=DestroyQuantumInfo(quantum_info);
177 if (EOFBlob(image) != MagickFalse)
178 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
179 image->filename);
180 (void) CloseBlob(image);
181 return(GetFirstImageInList(image));
182}
183
184/*
185%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186% %
187% %
188% %
189% R e g i s t e r A R T I m a g e %
190% %
191% %
192% %
193%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194%
195% RegisterARTImage() adds attributes for the ART image format to
196% the list of supported formats. The attributes include the image format
197% tag, a method to read and/or write the format, whether the format
198% supports the saving of more than one frame to the same file or blob,
199% whether the format supports native in-memory I/O, and a brief
200% description of the format.
201%
202% The format of the RegisterARTImage method is:
203%
cristybb503372010-05-27 20:51:26 +0000204% size_t RegisterARTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000205%
206*/
cristybb503372010-05-27 20:51:26 +0000207ModuleExport size_t RegisterARTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000208{
209 MagickInfo
210 *entry;
211
212 entry=SetMagickInfo("ART");
213 entry->decoder=(DecodeImageHandler *) ReadARTImage;
214 entry->encoder=(EncodeImageHandler *) WriteARTImage;
215 entry->raw=MagickTrue;
216 entry->adjoin=MagickFalse;
217 entry->description=ConstantString("PFS: 1st Publisher Clip Art");
218 entry->module=ConstantString("ART");
219 (void) RegisterMagickInfo(entry);
220 return(MagickImageCoderSignature);
221}
222
223/*
224%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225% %
226% %
227% %
228% U n r e g i s t e r A R T I m a g e %
229% %
230% %
231% %
232%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233%
234% UnregisterARTImage() removes format registrations made by the
235% ART module from the list of supported formats.
236%
237% The format of the UnregisterARTImage method is:
238%
239% UnregisterARTImage(void)
240%
241*/
242ModuleExport void UnregisterARTImage(void)
243{
244 (void) UnregisterMagickInfo("ART");
245}
246
247/*
248%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249% %
250% %
251% %
252% W r i t e A R T I m a g e %
253% %
254% %
255% %
256%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257%
258% WriteARTImage() writes an image of raw bits in LSB order to a file.
259%
260% The format of the WriteARTImage method is:
261%
cristy1e178e72011-08-28 19:44:34 +0000262% MagickBooleanType WriteARTImage(const ImageInfo *image_info,
263% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000264%
265% A description of each parameter follows.
266%
267% o image_info: the image info.
268%
269% o image: The image.
270%
cristy1e178e72011-08-28 19:44:34 +0000271% o exception: return any errors or warnings in this structure.
272%
cristy3ed852e2009-09-05 21:47:34 +0000273*/
cristy1e178e72011-08-28 19:44:34 +0000274static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image,
275 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000276{
cristy3ed852e2009-09-05 21:47:34 +0000277 MagickBooleanType
278 status;
279
280 QuantumInfo
281 *quantum_info;
282
cristy4c08aed2011-07-01 19:47:50 +0000283 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +0000284 *p;
285
cristy3ed852e2009-09-05 21:47:34 +0000286 size_t
cristy94b11832011-09-08 19:46:03 +0000287 length;
288
289 ssize_t
290 count,
cristy4e82e512011-04-24 01:33:42 +0000291 y;
cristy3ed852e2009-09-05 21:47:34 +0000292
293 unsigned char
294 *pixels;
295
296 /*
297 Open output image file.
298 */
299 assert(image_info != (const ImageInfo *) NULL);
300 assert(image_info->signature == MagickSignature);
301 assert(image != (Image *) NULL);
302 assert(image->signature == MagickSignature);
303 if (image->debug != MagickFalse)
304 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy3a37efd2011-08-28 20:31:03 +0000305 assert(exception != (ExceptionInfo *) NULL);
306 assert(exception->signature == MagickSignature);
cristy1e178e72011-08-28 19:44:34 +0000307 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +0000308 if (status == MagickFalse)
309 return(status);
310 if ((image->columns > 65535UL) || (image->rows > 65535UL))
311 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
cristyab371872012-06-26 00:28:37 +0000312 if ((IssRGBColorspace(image->colorspace) == MagickFalse) &&
cristy4eecced2012-06-26 01:45:04 +0000313 (IsRGBColorspace(image->colorspace) == MagickFalse))
cristy8d951092012-02-08 18:54:56 +0000314 (void) TransformImageColorspace(image,sRGBColorspace,exception);
cristy100b8d92012-01-08 00:32:49 +0000315 (void) SetImageType(image,BilevelType,exception);
cristy3ed852e2009-09-05 21:47:34 +0000316 image->endian=MSBEndian;
317 image->depth=1;
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);
cristy3ed852e2009-09-05 21:47:34 +0000322 quantum_info=AcquireQuantumInfo(image_info,image);
cristy100b8d92012-01-08 00:32:49 +0000323 pixels=GetQuantumPixels(quantum_info);
cristybb503372010-05-27 20:51:26 +0000324 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000325 {
cristy1e178e72011-08-28 19:44:34 +0000326 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000327 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000328 break;
cristy100b8d92012-01-08 00:32:49 +0000329 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +0000330 GrayQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000331 count=WriteBlob(image,length,pixels);
332 if (count != (ssize_t) length)
333 ThrowWriterException(CorruptImageError,"UnableToWriteImageData");
334 count=WriteBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
cristybdadf312011-04-23 23:16:21 +0000335 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
336 image->rows);
337 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000338 break;
339 }
340 quantum_info=DestroyQuantumInfo(quantum_info);
cristy3ed852e2009-09-05 21:47:34 +0000341 (void) CloseBlob(image);
cristy100b8d92012-01-08 00:32:49 +0000342 return(status);
cristy3ed852e2009-09-05 21:47:34 +0000343}