blob: c102f028893693a0af542d9038618c5ce0aee6fd [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% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 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"
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"
cristy510d06a2011-07-06 23:43:54 +000049#include "MagickCore/colorspace-private.h"
cristy4c08aed2011-07-01 19:47:50 +000050#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"
cristy3ed852e2009-09-05 21:47:34 +000063
64/*
65 Forward declarations.
66*/
67static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +000068 WriteARTImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +000069
70/*
71%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72% %
73% %
74% %
75% R e a d A R T I m a g e %
76% %
77% %
78% %
79%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80%
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.
84%
85% The format of the ReadARTImage method is:
86%
87% Image *ReadARTImage(const ImageInfo *image_info,
88% ExceptionInfo *exception)
89%
90% A description of each parameter follows:
91%
92% o image_info: the image info.
93%
94% o exception: return any errors or warnings in this structure.
95%
96*/
97static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception)
98{
99 Image
100 *image;
101
cristy3ed852e2009-09-05 21:47:34 +0000102 QuantumInfo
103 *quantum_info;
104
105 QuantumType
106 quantum_type;
107
108 MagickBooleanType
109 status;
110
cristy3ed852e2009-09-05 21:47:34 +0000111 size_t
112 length;
113
cristybdadf312011-04-23 23:16:21 +0000114 ssize_t
115 count,
116 y;
117
cristy3ed852e2009-09-05 21:47:34 +0000118 unsigned char
119 *pixels;
120
121 /*
122 Open image file.
123 */
124 assert(image_info != (const ImageInfo *) NULL);
125 assert(image_info->signature == MagickSignature);
126 if (image_info->debug != MagickFalse)
127 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
128 image_info->filename);
129 assert(exception != (ExceptionInfo *) NULL);
130 assert(exception->signature == MagickSignature);
cristy9950d572011-10-01 18:22:35 +0000131 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000132 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
133 if (status == MagickFalse)
134 {
135 image=DestroyImageList(image);
136 return((Image *) NULL);
137 }
138 image->depth=1;
139 image->endian=MSBEndian;
140 (void) ReadBlobLSBShort(image);
cristybb503372010-05-27 20:51:26 +0000141 image->columns=(size_t) ReadBlobLSBShort(image);
cristy3ed852e2009-09-05 21:47:34 +0000142 (void) ReadBlobLSBShort(image);
cristybb503372010-05-27 20:51:26 +0000143 image->rows=(size_t) ReadBlobLSBShort(image);
cristy3ed852e2009-09-05 21:47:34 +0000144 /*
145 Initialize image colormap.
146 */
cristy018f07f2011-09-04 21:15:19 +0000147 if (AcquireImageColormap(image,2,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000148 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
149 if (image_info->ping != MagickFalse)
150 {
151 (void) CloseBlob(image);
152 return(GetFirstImageInList(image));
153 }
154 /*
155 Convert bi-level image to pixel packets.
156 */
157 quantum_type=IndexQuantum;
158 quantum_info=AcquireQuantumInfo(image_info,image);
159 if (quantum_info == (QuantumInfo *) NULL)
160 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
161 pixels=GetQuantumPixels(quantum_info);
162 length=GetQuantumExtent(image,quantum_info,quantum_type);
cristybb503372010-05-27 20:51:26 +0000163 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000164 {
cristy4c08aed2011-07-01 19:47:50 +0000165 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000166 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000167
168 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000169 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000170 break;
171 count=ReadBlob(image,length,pixels);
172 if (count != (ssize_t) length)
173 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
174 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
175 quantum_type,pixels,exception);
176 count=ReadBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
177 if (SyncAuthenticPixels(image,exception) == MagickFalse)
178 break;
179 if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
180 break;
181 }
182 SetQuantumImageType(image,quantum_type);
183 quantum_info=DestroyQuantumInfo(quantum_info);
184 if (EOFBlob(image) != MagickFalse)
185 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
186 image->filename);
187 (void) CloseBlob(image);
188 return(GetFirstImageInList(image));
189}
190
191/*
192%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193% %
194% %
195% %
196% R e g i s t e r A R T I m a g e %
197% %
198% %
199% %
200%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201%
202% RegisterARTImage() adds attributes for the ART image format to
203% the list of supported formats. The attributes include the image format
204% tag, a method to read and/or write the format, whether the format
205% supports the saving of more than one frame to the same file or blob,
206% whether the format supports native in-memory I/O, and a brief
207% description of the format.
208%
209% The format of the RegisterARTImage method is:
210%
cristybb503372010-05-27 20:51:26 +0000211% size_t RegisterARTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000212%
213*/
cristybb503372010-05-27 20:51:26 +0000214ModuleExport size_t RegisterARTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000215{
216 MagickInfo
217 *entry;
218
219 entry=SetMagickInfo("ART");
220 entry->decoder=(DecodeImageHandler *) ReadARTImage;
221 entry->encoder=(EncodeImageHandler *) WriteARTImage;
222 entry->raw=MagickTrue;
223 entry->adjoin=MagickFalse;
224 entry->description=ConstantString("PFS: 1st Publisher Clip Art");
225 entry->module=ConstantString("ART");
226 (void) RegisterMagickInfo(entry);
227 return(MagickImageCoderSignature);
228}
229
230/*
231%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232% %
233% %
234% %
235% U n r e g i s t e r A R T I m a g e %
236% %
237% %
238% %
239%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240%
241% UnregisterARTImage() removes format registrations made by the
242% ART module from the list of supported formats.
243%
244% The format of the UnregisterARTImage method is:
245%
246% UnregisterARTImage(void)
247%
248*/
249ModuleExport void UnregisterARTImage(void)
250{
251 (void) UnregisterMagickInfo("ART");
252}
253
254/*
255%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256% %
257% %
258% %
259% W r i t e A R T I m a g e %
260% %
261% %
262% %
263%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264%
265% WriteARTImage() writes an image of raw bits in LSB order to a file.
266%
267% The format of the WriteARTImage method is:
268%
cristy1e178e72011-08-28 19:44:34 +0000269% MagickBooleanType WriteARTImage(const ImageInfo *image_info,
270% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000271%
272% A description of each parameter follows.
273%
274% o image_info: the image info.
275%
276% o image: The image.
277%
cristy1e178e72011-08-28 19:44:34 +0000278% o exception: return any errors or warnings in this structure.
279%
cristy3ed852e2009-09-05 21:47:34 +0000280*/
cristy1e178e72011-08-28 19:44:34 +0000281static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image,
282 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000283{
cristy3ed852e2009-09-05 21:47:34 +0000284 MagickBooleanType
285 status;
286
287 QuantumInfo
288 *quantum_info;
289
cristy4c08aed2011-07-01 19:47:50 +0000290 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +0000291 *p;
292
cristy3ed852e2009-09-05 21:47:34 +0000293 size_t
cristy94b11832011-09-08 19:46:03 +0000294 length;
295
296 ssize_t
297 count,
cristy4e82e512011-04-24 01:33:42 +0000298 y;
cristy3ed852e2009-09-05 21:47:34 +0000299
300 unsigned char
301 *pixels;
302
303 /*
304 Open output image file.
305 */
306 assert(image_info != (const ImageInfo *) NULL);
307 assert(image_info->signature == MagickSignature);
308 assert(image != (Image *) NULL);
309 assert(image->signature == MagickSignature);
310 if (image->debug != MagickFalse)
311 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy3a37efd2011-08-28 20:31:03 +0000312 assert(exception != (ExceptionInfo *) NULL);
313 assert(exception->signature == MagickSignature);
cristy1e178e72011-08-28 19:44:34 +0000314 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +0000315 if (status == MagickFalse)
316 return(status);
317 if ((image->columns > 65535UL) || (image->rows > 65535UL))
318 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
319 image->endian=MSBEndian;
320 image->depth=1;
321 (void) WriteBlobLSBShort(image,0);
322 (void) WriteBlobLSBShort(image,(unsigned short) image->columns);
323 (void) WriteBlobLSBShort(image,0);
324 (void) WriteBlobLSBShort(image,(unsigned short) image->rows);
cristy510d06a2011-07-06 23:43:54 +0000325 if (IsRGBColorspace(image->colorspace) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000326 (void) TransformImageColorspace(image,RGBColorspace);
327 length=(image->columns+7)/8;
328 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
329 if (pixels == (unsigned char *) NULL)
330 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
331 /*
332 Convert image to a bi-level image.
333 */
cristy018f07f2011-09-04 21:15:19 +0000334 (void) SetImageType(image,BilevelType,exception);
cristy3ed852e2009-09-05 21:47:34 +0000335 quantum_info=AcquireQuantumInfo(image_info,image);
cristybb503372010-05-27 20:51:26 +0000336 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000337 {
cristy1e178e72011-08-28 19:44:34 +0000338 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000339 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000340 break;
cristy4c08aed2011-07-01 19:47:50 +0000341 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +0000342 GrayQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000343 count=WriteBlob(image,length,pixels);
344 if (count != (ssize_t) length)
345 ThrowWriterException(CorruptImageError,"UnableToWriteImageData");
346 count=WriteBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
cristybdadf312011-04-23 23:16:21 +0000347 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
348 image->rows);
349 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000350 break;
351 }
352 quantum_info=DestroyQuantumInfo(quantum_info);
353 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
354 (void) CloseBlob(image);
355 return(MagickTrue);
356}