blob: b39538cdc845419ec5ee7b0bcf5b479756f8d4ce [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 %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1992 %
18% %
19% %
Cristy7ce65e72015-12-12 18:03:16 -050020% Copyright 1999-2016 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{
cristyb3f97ae2015-05-18 12:29:32 +0000100 const unsigned char
cristybd797f12015-01-24 20:42:32 +0000101 *pixels;
102
cristy3ed852e2009-09-05 21:47:34 +0000103 Image
104 *image;
105
cristy3ed852e2009-09-05 21:47:34 +0000106 QuantumInfo
107 *quantum_info;
108
cristy3ed852e2009-09-05 21:47:34 +0000109 MagickBooleanType
110 status;
111
cristy3ed852e2009-09-05 21:47:34 +0000112 size_t
113 length;
114
cristybdadf312011-04-23 23:16:21 +0000115 ssize_t
116 count,
117 y;
118
cristy3ed852e2009-09-05 21:47:34 +0000119 /*
120 Open image file.
121 */
122 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000123 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000124 if (image_info->debug != MagickFalse)
125 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
126 image_info->filename);
127 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000128 assert(exception->signature == MagickCoreSignature);
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 }
cristyacabb842014-12-14 23:36:33 +0000149 status=SetImageExtent(image,image->columns,image->rows,exception);
150 if (status == MagickFalse)
151 return(DestroyImageList(image));
cristy3ed852e2009-09-05 21:47:34 +0000152 /*
153 Convert bi-level image to pixel packets.
154 */
cristyb2c3f402012-05-13 18:05:12 +0000155 SetImageColorspace(image,GRAYColorspace,exception);
cristy5f766ef2014-12-14 21:12:47 +0000156 quantum_info=AcquireQuantumInfo(image_info,image);
cristy3ed852e2009-09-05 21:47:34 +0000157 if (quantum_info == (QuantumInfo *) NULL)
158 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
cristy100b8d92012-01-08 00:32:49 +0000159 length=GetQuantumExtent(image,quantum_info,GrayQuantum);
cristybb503372010-05-27 20:51:26 +0000160 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000161 {
cristy4c08aed2011-07-01 19:47:50 +0000162 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100163 *magick_restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000164
165 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000166 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000167 break;
cristyb3f97ae2015-05-18 12:29:32 +0000168 pixels=(const unsigned char *) ReadBlobStream(image,length,
169 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000170 if (count != (ssize_t) length)
171 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
172 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy100b8d92012-01-08 00:32:49 +0000173 GrayQuantum,pixels,exception);
cristyb3f97ae2015-05-18 12:29:32 +0000174 pixels=(const unsigned char *) ReadBlobStream(image,(size_t) (-(ssize_t)
175 length) & 0x01,GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000176 if (SyncAuthenticPixels(image,exception) == MagickFalse)
177 break;
178 if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
179 break;
180 }
cristy100b8d92012-01-08 00:32:49 +0000181 SetQuantumImageType(image,GrayQuantum);
cristy3ed852e2009-09-05 21:47:34 +0000182 quantum_info=DestroyQuantumInfo(quantum_info);
183 if (EOFBlob(image) != MagickFalse)
184 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
185 image->filename);
186 (void) CloseBlob(image);
187 return(GetFirstImageInList(image));
188}
189
190/*
191%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192% %
193% %
194% %
195% R e g i s t e r A R T I m a g e %
196% %
197% %
198% %
199%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200%
201% RegisterARTImage() adds attributes for the ART image format to
202% the list of supported formats. The attributes include the image format
203% tag, a method to read and/or write the format, whether the format
204% supports the saving of more than one frame to the same file or blob,
205% whether the format supports native in-memory I/O, and a brief
206% description of the format.
207%
208% The format of the RegisterARTImage method is:
209%
cristybb503372010-05-27 20:51:26 +0000210% size_t RegisterARTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000211%
212*/
cristybb503372010-05-27 20:51:26 +0000213ModuleExport size_t RegisterARTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000214{
215 MagickInfo
216 *entry;
217
dirk06b627a2015-04-06 18:59:17 +0000218 entry=AcquireMagickInfo("ART","ART","PFS: 1st Publisher Clip Art");
cristy3ed852e2009-09-05 21:47:34 +0000219 entry->decoder=(DecodeImageHandler *) ReadARTImage;
220 entry->encoder=(EncodeImageHandler *) WriteARTImage;
dirk08e9a112015-02-22 01:51:41 +0000221 entry->flags|=CoderRawSupportFlag;
222 entry->flags^=CoderAdjoinFlag;
cristy3ed852e2009-09-05 21:47:34 +0000223 (void) RegisterMagickInfo(entry);
224 return(MagickImageCoderSignature);
225}
226
227/*
228%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229% %
230% %
231% %
232% U n r e g i s t e r A R T I m a g e %
233% %
234% %
235% %
236%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237%
238% UnregisterARTImage() removes format registrations made by the
239% ART module from the list of supported formats.
240%
241% The format of the UnregisterARTImage method is:
242%
243% UnregisterARTImage(void)
244%
245*/
246ModuleExport void UnregisterARTImage(void)
247{
248 (void) UnregisterMagickInfo("ART");
249}
250
251/*
252%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253% %
254% %
255% %
256% W r i t e A R T I m a g e %
257% %
258% %
259% %
260%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261%
262% WriteARTImage() writes an image of raw bits in LSB order to a file.
263%
264% The format of the WriteARTImage method is:
265%
cristy1e178e72011-08-28 19:44:34 +0000266% MagickBooleanType WriteARTImage(const ImageInfo *image_info,
267% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000268%
269% A description of each parameter follows.
270%
271% o image_info: the image info.
272%
273% o image: The image.
274%
cristy1e178e72011-08-28 19:44:34 +0000275% o exception: return any errors or warnings in this structure.
276%
cristy3ed852e2009-09-05 21:47:34 +0000277*/
cristy1e178e72011-08-28 19:44:34 +0000278static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image,
279 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000280{
cristy3ed852e2009-09-05 21:47:34 +0000281 MagickBooleanType
282 status;
283
284 QuantumInfo
285 *quantum_info;
286
cristy4c08aed2011-07-01 19:47:50 +0000287 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +0000288 *p;
289
cristy3ed852e2009-09-05 21:47:34 +0000290 size_t
cristy94b11832011-09-08 19:46:03 +0000291 length;
292
293 ssize_t
294 count,
cristy4e82e512011-04-24 01:33:42 +0000295 y;
cristy3ed852e2009-09-05 21:47:34 +0000296
297 unsigned char
298 *pixels;
299
300 /*
301 Open output image file.
302 */
303 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000304 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000305 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000306 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000307 if (image->debug != MagickFalse)
308 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy3a37efd2011-08-28 20:31:03 +0000309 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000310 assert(exception->signature == MagickCoreSignature);
cristy1e178e72011-08-28 19:44:34 +0000311 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +0000312 if (status == MagickFalse)
313 return(status);
314 if ((image->columns > 65535UL) || (image->rows > 65535UL))
315 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
cristyaf8d3912014-02-21 14:50:33 +0000316 (void) TransformImageColorspace(image,sRGBColorspace,exception);
cristy100b8d92012-01-08 00:32:49 +0000317 (void) SetImageType(image,BilevelType,exception);
cristy3ed852e2009-09-05 21:47:34 +0000318 image->endian=MSBEndian;
319 image->depth=1;
320 (void) WriteBlobLSBShort(image,0);
321 (void) WriteBlobLSBShort(image,(unsigned short) image->columns);
322 (void) WriteBlobLSBShort(image,0);
323 (void) WriteBlobLSBShort(image,(unsigned short) image->rows);
cristy5f766ef2014-12-14 21:12:47 +0000324 quantum_info=AcquireQuantumInfo(image_info,image);
cristyb3f97ae2015-05-18 12:29:32 +0000325 pixels=(unsigned char *) GetQuantumPixels(quantum_info);
cristybb503372010-05-27 20:51:26 +0000326 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000327 {
cristy1e178e72011-08-28 19:44:34 +0000328 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000329 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000330 break;
cristy100b8d92012-01-08 00:32:49 +0000331 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +0000332 GrayQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000333 count=WriteBlob(image,length,pixels);
334 if (count != (ssize_t) length)
335 ThrowWriterException(CorruptImageError,"UnableToWriteImageData");
336 count=WriteBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
cristybdadf312011-04-23 23:16:21 +0000337 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
338 image->rows);
339 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000340 break;
341 }
342 quantum_info=DestroyQuantumInfo(quantum_info);
cristy3ed852e2009-09-05 21:47:34 +0000343 (void) CloseBlob(image);
cristy100b8d92012-01-08 00:32:49 +0000344 return(status);
cristy3ed852e2009-09-05 21:47:34 +0000345}