blob: a6669c4e0c2f195c8f229972faf12412e4dede9a [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% %
cristy45ef08f2012-12-07 13:13:34 +000020% Copyright 1999-2013 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);
cristydacfa012012-07-11 22:04:06 +0000142 if ((image->columns == 0) || (image->rows == 0))
143 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
cristy3ed852e2009-09-05 21:47:34 +0000144 if (image_info->ping != MagickFalse)
145 {
146 (void) CloseBlob(image);
147 return(GetFirstImageInList(image));
148 }
149 /*
150 Convert bi-level image to pixel packets.
151 */
cristyb2c3f402012-05-13 18:05:12 +0000152 SetImageColorspace(image,GRAYColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000153 quantum_info=AcquireQuantumInfo(image_info,image);
154 if (quantum_info == (QuantumInfo *) NULL)
155 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
156 pixels=GetQuantumPixels(quantum_info);
cristy100b8d92012-01-08 00:32:49 +0000157 length=GetQuantumExtent(image,quantum_info,GrayQuantum);
cristybb503372010-05-27 20:51:26 +0000158 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000159 {
cristy4c08aed2011-07-01 19:47:50 +0000160 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000161 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000162
163 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000164 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000165 break;
166 count=ReadBlob(image,length,pixels);
167 if (count != (ssize_t) length)
168 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
169 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy100b8d92012-01-08 00:32:49 +0000170 GrayQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000171 count=ReadBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
172 if (SyncAuthenticPixels(image,exception) == MagickFalse)
173 break;
174 if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
175 break;
176 }
cristy100b8d92012-01-08 00:32:49 +0000177 SetQuantumImageType(image,GrayQuantum);
cristy3ed852e2009-09-05 21:47:34 +0000178 quantum_info=DestroyQuantumInfo(quantum_info);
179 if (EOFBlob(image) != MagickFalse)
180 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
181 image->filename);
182 (void) CloseBlob(image);
183 return(GetFirstImageInList(image));
184}
185
186/*
187%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188% %
189% %
190% %
191% R e g i s t e r A R T I m a g e %
192% %
193% %
194% %
195%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196%
197% RegisterARTImage() adds attributes for the ART image format to
198% the list of supported formats. The attributes include the image format
199% tag, a method to read and/or write the format, whether the format
200% supports the saving of more than one frame to the same file or blob,
201% whether the format supports native in-memory I/O, and a brief
202% description of the format.
203%
204% The format of the RegisterARTImage method is:
205%
cristybb503372010-05-27 20:51:26 +0000206% size_t RegisterARTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000207%
208*/
cristybb503372010-05-27 20:51:26 +0000209ModuleExport size_t RegisterARTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000210{
211 MagickInfo
212 *entry;
213
214 entry=SetMagickInfo("ART");
215 entry->decoder=(DecodeImageHandler *) ReadARTImage;
216 entry->encoder=(EncodeImageHandler *) WriteARTImage;
217 entry->raw=MagickTrue;
218 entry->adjoin=MagickFalse;
219 entry->description=ConstantString("PFS: 1st Publisher Clip Art");
220 entry->module=ConstantString("ART");
221 (void) RegisterMagickInfo(entry);
222 return(MagickImageCoderSignature);
223}
224
225/*
226%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227% %
228% %
229% %
230% U n r e g i s t e r A R T I m a g e %
231% %
232% %
233% %
234%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235%
236% UnregisterARTImage() removes format registrations made by the
237% ART module from the list of supported formats.
238%
239% The format of the UnregisterARTImage method is:
240%
241% UnregisterARTImage(void)
242%
243*/
244ModuleExport void UnregisterARTImage(void)
245{
246 (void) UnregisterMagickInfo("ART");
247}
248
249/*
250%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251% %
252% %
253% %
254% W r i t e A R T I m a g e %
255% %
256% %
257% %
258%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259%
260% WriteARTImage() writes an image of raw bits in LSB order to a file.
261%
262% The format of the WriteARTImage method is:
263%
cristy1e178e72011-08-28 19:44:34 +0000264% MagickBooleanType WriteARTImage(const ImageInfo *image_info,
265% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000266%
267% A description of each parameter follows.
268%
269% o image_info: the image info.
270%
271% o image: The image.
272%
cristy1e178e72011-08-28 19:44:34 +0000273% o exception: return any errors or warnings in this structure.
274%
cristy3ed852e2009-09-05 21:47:34 +0000275*/
cristy1e178e72011-08-28 19:44:34 +0000276static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image,
277 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000278{
cristy3ed852e2009-09-05 21:47:34 +0000279 MagickBooleanType
280 status;
281
282 QuantumInfo
283 *quantum_info;
284
cristy4c08aed2011-07-01 19:47:50 +0000285 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +0000286 *p;
287
cristy3ed852e2009-09-05 21:47:34 +0000288 size_t
cristy94b11832011-09-08 19:46:03 +0000289 length;
290
291 ssize_t
292 count,
cristy4e82e512011-04-24 01:33:42 +0000293 y;
cristy3ed852e2009-09-05 21:47:34 +0000294
295 unsigned char
296 *pixels;
297
298 /*
299 Open output image file.
300 */
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);
cristy3a37efd2011-08-28 20:31:03 +0000307 assert(exception != (ExceptionInfo *) NULL);
308 assert(exception->signature == MagickSignature);
cristy1e178e72011-08-28 19:44:34 +0000309 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +0000310 if (status == MagickFalse)
311 return(status);
312 if ((image->columns > 65535UL) || (image->rows > 65535UL))
313 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
cristy3d9f5ba2012-06-26 13:37:31 +0000314 if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
cristy8d951092012-02-08 18:54:56 +0000315 (void) TransformImageColorspace(image,sRGBColorspace,exception);
cristy100b8d92012-01-08 00:32:49 +0000316 (void) SetImageType(image,BilevelType,exception);
cristy3ed852e2009-09-05 21:47:34 +0000317 image->endian=MSBEndian;
318 image->depth=1;
319 (void) WriteBlobLSBShort(image,0);
320 (void) WriteBlobLSBShort(image,(unsigned short) image->columns);
321 (void) WriteBlobLSBShort(image,0);
322 (void) WriteBlobLSBShort(image,(unsigned short) image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000323 quantum_info=AcquireQuantumInfo(image_info,image);
cristy100b8d92012-01-08 00:32:49 +0000324 pixels=GetQuantumPixels(quantum_info);
cristybb503372010-05-27 20:51:26 +0000325 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000326 {
cristy1e178e72011-08-28 19:44:34 +0000327 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000328 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000329 break;
cristy100b8d92012-01-08 00:32:49 +0000330 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +0000331 GrayQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000332 count=WriteBlob(image,length,pixels);
333 if (count != (ssize_t) length)
334 ThrowWriterException(CorruptImageError,"UnableToWriteImageData");
335 count=WriteBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
cristybdadf312011-04-23 23:16:21 +0000336 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
337 image->rows);
338 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000339 break;
340 }
341 quantum_info=DestroyQuantumInfo(quantum_info);
cristy3ed852e2009-09-05 21:47:34 +0000342 (void) CloseBlob(image);
cristy100b8d92012-01-08 00:32:49 +0000343 return(status);
cristy3ed852e2009-09-05 21:47:34 +0000344}