2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 % Read MacPaint Image Format %
21 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
22 % dedicated to making software imaging solutions freely available. %
24 % You may not use this file except in compliance with the License. You may %
25 % obtain a copy of the License at %
27 % http://www.imagemagick.org/script/license.php %
29 % Unless required by applicable law or agreed to in writing, software %
30 % distributed under the License is distributed on an "AS IS" BASIS, %
31 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
32 % See the License for the specific language governing permissions and %
33 % limitations under the License. %
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "magick/studio.h"
44 #include "magick/blob.h"
45 #include "magick/blob-private.h"
46 #include "magick/cache.h"
47 #include "magick/colormap.h"
48 #include "magick/colorspace.h"
49 #include "magick/exception.h"
50 #include "magick/exception-private.h"
51 #include "magick/image.h"
52 #include "magick/image-private.h"
53 #include "magick/list.h"
54 #include "magick/magick.h"
55 #include "magick/memory_.h"
56 #include "magick/monitor.h"
57 #include "magick/monitor-private.h"
58 #include "magick/quantum-private.h"
59 #include "magick/static.h"
60 #include "magick/string_.h"
61 #include "magick/module.h"
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 % R e a d M A C I m a g e %
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 % ReadMACImage() reads an MacPaint image file and returns it. It
75 % allocates the memory necessary for the new Image structure and returns a
76 % pointer to the new image.
78 % The format of the ReadMACImage method is:
80 % Image *ReadMACImage(const ImageInfo *image_info,ExceptionInfo *exception)
82 % A description of each parameter follows:
84 % o image_info: the image info.
86 % o exception: return any errors or warnings in this structure.
89 static Image *ReadMACImage(const ImageInfo *image_info,ExceptionInfo *exception)
106 register unsigned char
125 assert(image_info != (const ImageInfo *) NULL);
126 assert(image_info->signature == MagickSignature);
127 if (image_info->debug != MagickFalse)
128 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
129 image_info->filename);
130 assert(exception != (ExceptionInfo *) NULL);
131 assert(exception->signature == MagickSignature);
132 image=AcquireImage(image_info);
133 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
134 if (status == MagickFalse)
136 image=DestroyImageList(image);
137 return((Image *) NULL);
142 length=ReadBlobLSBShort(image);
143 if ((length & 0xff) != 0)
144 ThrowReaderException(CorruptImageError,"CorruptImage");
145 for (x=0; x < (ssize_t) 638; x++)
146 if (ReadBlobByte(image) == EOF)
147 ThrowReaderException(CorruptImageError,"CorruptImage");
151 if (AcquireImageColormap(image,2) == MagickFalse)
152 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
153 if (image_info->ping != MagickFalse)
155 (void) CloseBlob(image);
156 return(GetFirstImageInList(image));
159 Convert MAC raster image to pixel packets.
161 length=(image->columns+7)/8;
162 pixels=(unsigned char *) AcquireQuantumMemory(length+1,sizeof(*pixels));
163 if (pixels == (unsigned char *) NULL)
164 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
167 for (y=0; y < (ssize_t) image->rows; )
169 count=(unsigned char) ReadBlobByte(image);
170 if (EOFBlob(image) != MagickFalse)
172 if ((count <= 0) || (count >= 128))
174 byte=(unsigned char) (~ReadBlobByte(image));
181 if (offset >= (ssize_t) length)
183 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
184 if (q == (PixelPacket *) NULL)
186 indexes=GetAuthenticIndexQueue(image);
190 for (x=0; x < (ssize_t) image->columns; x++)
194 SetPixelIndex(indexes+x,((byte & 0x80) != 0 ?
201 if (SyncAuthenticPixels(image,exception) == MagickFalse)
213 byte=(unsigned char) (~ReadBlobByte(image));
217 if (offset >= (ssize_t) length)
219 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
220 if (q == (PixelPacket *) NULL)
222 indexes=GetAuthenticIndexQueue(image);
226 for (x=0; x < (ssize_t) image->columns; x++)
230 SetPixelIndex(indexes+x,((byte & 0x80) != 0 ?
237 if (SyncAuthenticPixels(image,exception) == MagickFalse)
245 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
246 (void) CloseBlob(image);
247 return(GetFirstImageInList(image));
251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
255 % R e g i s t e r M A C I m a g e %
259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261 % RegisterMACImage() adds attributes for the MAC X image format to the list
262 % of supported formats. The attributes include the image format tag, a
263 % method to read and/or write the format, whether the format supports the
264 % saving of more than one frame to the same file or blob, whether the format
265 % supports native in-memory I/O, and a brief description of the format.
267 % The format of the RegisterMACImage method is:
269 % size_t RegisterMACImage(void)
272 ModuleExport size_t RegisterMACImage(void)
277 entry=SetMagickInfo("MAC");
278 entry->decoder=(DecodeImageHandler *) ReadMACImage;
279 entry->description=ConstantString("MAC Paint");
280 entry->module=ConstantString("MAC");
281 (void) RegisterMagickInfo(entry);
282 return(MagickImageCoderSignature);
286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290 % U n r e g i s t e r M A C I m a g e %
294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 % UnregisterMACImage() removes format registrations made by the
297 % MAC module from the list of supported formats.
299 % The format of the UnregisterMACImage method is:
301 % UnregisterMACImage(void)
304 ModuleExport void UnregisterMACImage(void)
306 (void) UnregisterMagickInfo("MAC");