2
% Copyright (C) 2003 GraphicsMagick Group
3
% Copyright (C) 2002 ImageMagick Studio
4
% Copyright 1991-1999 E. I. du Pont de Nemours and Company
6
% This program is covered by multiple licenses, which are described in
7
% Copyright.txt. You should have received a copy of Copyright.txt with this
8
% package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.
10
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16
% W W W BBBB M M M PPPP %
21
% Read/Write Wireless Bitmap (level 0) Image Format. %
30
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37
#include "magick/studio.h"
38
#include "magick/blob.h"
39
#include "magick/cache.h"
40
#include "magick/magick.h"
41
#include "magick/monitor.h"
42
#include "magick/utility.h"
48
WriteWBMPImage(const ImageInfo *,Image *);
51
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55
% R e a d W B M P I m a g e %
59
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61
% Method ReadWBMPImage reads a WBMP (level 0) image file and returns it. It
62
% allocates the memory necessary for the new Image structure and returns a
63
% pointer to the new image.
65
% ReadWBMPImage was contributed by Milan Votava <votava@mageo.cz>.
67
% The format of the ReadWBMPImage method is:
69
% Image *ReadWBMPImage(const ImageInfo *image_info,
70
% ExceptionInfo *exception)
72
% A description of each parameter follows:
74
% o image: Method ReadWBMPImage returns a pointer to the image after
75
% reading. A null image is returned if there is a memory shortage or
76
% if the image cannot be read.
78
% o image_info: Specifies a pointer to a ImageInfo structure.
80
% o exception: return any errors or warnings in this structure.
85
static unsigned int WBMPReadInteger(Image *image,unsigned long *value)
93
byte=ReadBlobByte(image);
97
*value|=(unsigned int) (byte & 0x7f);
98
} while (byte & 0x80);
102
static Image *ReadWBMPImage(const ImageInfo *image_info,
103
ExceptionInfo *exception)
138
assert(image_info != (const ImageInfo *) NULL);
139
assert(image_info->signature == MagickSignature);
140
assert(exception != (ExceptionInfo *) NULL);
141
assert(exception->signature == MagickSignature);
142
image=AllocateImage(image_info);
143
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
145
ThrowReaderException(FileOpenError,UnableToOpenFile,image);
146
if (!ReadBlob(image,2,(char *) &header))
147
ThrowReaderException(CorruptImageError,ImproperImageHeader,image);
149
ThrowReaderException(CoderError,OnlyLevelZerofilesSupported,image);
151
Initialize image structure.
153
if (WBMPReadInteger(image,&image->columns) == False)
154
ThrowReaderException(CorruptImageError,CorruptImage,image);
155
if (WBMPReadInteger(image,&image->rows) == False)
156
ThrowReaderException(CorruptImageError,CorruptImage,image);
157
if ((image->columns == 0) || (image->rows == 0))
158
ThrowReaderException(CorruptImageError,ImproperImageHeader,image);
159
for (i=0; i < image->offset; i++)
160
(void) ReadBlobByte(image);
161
if (!AllocateImageColormap(image,2))
162
ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image);
163
if (image_info->ping)
169
Convert bi-level image to pixel packets.
171
for (y=0; y < (long) image->rows; y++)
173
q=SetImagePixels(image,0,y,image->columns,1);
174
if (q == (PixelPacket *) NULL)
176
indexes=GetIndexes(image);
179
for (x=0; x < (long) image->columns; x++)
183
byte=ReadBlobByte(image);
185
ThrowReaderException(CorruptImageError,CorruptImage,image);
187
indexes[x]=(byte & (0x01 << (7-bit))) ? 1 : 0;
192
if (!SyncImagePixels(image))
194
if (QuantumTick(y,image->rows))
195
if (!MagickMonitor(LoadImageText,y,image->rows,exception))
200
ThrowException(exception,CorruptImageError,UnexpectedEndOfFile,
207
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211
% R e g i s t e r W B M P I m a g e %
215
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217
% Method RegisterWBMPImage adds attributes for the WBMP image format to
218
% the list of supported formats. The attributes include the image format
219
% tag, a method to read and/or write the format, whether the format
220
% supports the saving of more than one frame to the same file or blob,
221
% whether the format supports native in-memory I/O, and a brief
222
% description of the format.
224
% The format of the RegisterWBMPImage method is:
226
% RegisterWBMPImage(void)
229
ModuleExport void RegisterWBMPImage(void)
234
entry=SetMagickInfo("WBMP");
235
entry->decoder=(DecoderHandler) ReadWBMPImage;
236
entry->encoder=(EncoderHandler) WriteWBMPImage;
238
entry->description=AcquireString("Wireless Bitmap (level 0) image");
239
entry->module=AcquireString("WBMP");
240
(void) RegisterMagickInfo(entry);
244
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248
% U n r e g i s t e r W B M P I m a g e %
252
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254
% Method UnregisterWBMPImage removes format registrations made by the
255
% WBMP module from the list of supported formats.
257
% The format of the UnregisterWBMPImage method is:
259
% UnregisterWBMPImage(void)
262
ModuleExport void UnregisterWBMPImage(void)
264
(void) UnregisterMagickInfo("WBMP");
268
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272
% W r i t e W B M P I m a g e %
276
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278
% Method WriteWBMPImage writes an image to a file in the Wireless Bitmap
279
% (level 0) image format.
281
% WriteWBMPImage was contributed by Milan Votava <votava@mageo.cz>.
283
% The format of the WriteWBMPImage method is:
285
% unsigned int WriteWBMPImage(const ImageInfo *image_info,Image *image)
287
% A description of each parameter follows.
289
% o status: Method WriteWBMPImage return True if the image is written.
290
% False is returned is there is a memory shortage or if the image file
293
% o image_info: Specifies a pointer to a ImageInfo structure.
295
% o image: A pointer to an Image structure.
300
static void WBMPWriteInteger(Image *image,const unsigned long value)
317
for(i=4; i >= 0; i--)
319
octet=(unsigned char) ((value >> bits) & 0x7f);
325
buffer[4-i]=octet | (i && (flag || octet))*(0x01 << 7);
328
(void) WriteBlob(image,n,(char *) buffer+5-n);
331
static unsigned int WriteWBMPImage(const ImageInfo *image_info,Image *image)
336
register const PixelPacket
354
Open output image file.
356
assert(image_info != (const ImageInfo *) NULL);
357
assert(image_info->signature == MagickSignature);
358
assert(image != (Image *) NULL);
359
assert(image->signature == MagickSignature);
360
status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
362
ThrowWriterException(FileOpenError,UnableToOpenFile,image);
363
TransformColorspace(image,RGBColorspace);
365
Convert image to a bi-level image.
367
SetImageType(image,BilevelType);
368
polarity=PixelIntensityToQuantum(&image->colormap[0]) < (MaxRGB/2);
369
if (image->colors == 2)
370
polarity=PixelIntensityToQuantum(&image->colormap[0]) <
371
PixelIntensityToQuantum(&image->colormap[1]);
372
(void) WriteBlobMSBShort(image,0);
373
WBMPWriteInteger(image,image->columns);
374
WBMPWriteInteger(image,image->rows);
375
for (y=0; y < (long) image->rows; y++)
377
p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
378
if (p == (const PixelPacket *) NULL)
380
indexes=GetIndexes(image);
383
for (x=0; x < (long) image->columns; x++)
385
if (indexes[x] == polarity)
386
byte|=0x1 << (7-bit);
390
(void) WriteBlobByte(image,byte);
396
(void) WriteBlobByte(image,byte);
397
if (QuantumTick(y,image->rows))
398
if (!MagickMonitor(SaveImageText,y,image->rows,&image->exception))