2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write On-The-Air Image Format %
20 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 #include "magick/studio.h"
42 #include "magick/blob.h"
43 #include "magick/blob-private.h"
44 #include "magick/cache.h"
45 #include "magick/color-private.h"
46 #include "magick/colorspace.h"
47 #include "magick/exception.h"
48 #include "magick/exception-private.h"
49 #include "magick/image.h"
50 #include "magick/image-private.h"
51 #include "magick/list.h"
52 #include "magick/magick.h"
53 #include "magick/memory_.h"
54 #include "magick/monitor.h"
55 #include "magick/monitor-private.h"
56 #include "magick/quantum-private.h"
57 #include "magick/static.h"
58 #include "magick/string_.h"
59 #include "magick/module.h"
64 static MagickBooleanType
65 WriteOTBImage(const ImageInfo *,Image *);
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 % R e a d O T B I m a g e %
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 % ReadOTBImage() reads a on-the-air (level 0) bitmap and returns it. It
79 % allocates the memory necessary for the new Image structure and returns a
80 % pointer to the new image.
82 % The format of the ReadOTBImage method is:
84 % Image *ReadOTBImage(const ImageInfo *image_info,ExceptionInfo *exception)
86 % A description of each parameter follows:
88 % o image_info: the image info.
90 % o exception: return any errors or warnings in this structure.
94 static Image *ReadOTBImage(const ImageInfo *image_info,ExceptionInfo *exception)
96 #define GetBit(a,i) (((a) >> (i)) & 1L)
127 assert(image_info != (const ImageInfo *) NULL);
128 assert(image_info->signature == MagickSignature);
129 if (image_info->debug != MagickFalse)
130 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
131 image_info->filename);
132 assert(exception != (ExceptionInfo *) NULL);
133 assert(exception->signature == MagickSignature);
134 image=AcquireImage(image_info);
135 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
136 if (status == MagickFalse)
138 image=DestroyImageList(image);
139 return((Image *) NULL);
142 Initialize image structure.
144 info=(unsigned char) ReadBlobByte(image);
145 if (GetBit(info,4) == 0)
147 image->columns=(unsigned long) ReadBlobByte(image);
148 image->rows=(unsigned long) ReadBlobByte(image);
152 image->columns=(unsigned long) ReadBlobMSBShort(image);
153 image->rows=(unsigned long) ReadBlobMSBShort(image);
155 if ((image->columns == 0) || (image->rows == 0))
156 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
157 depth=(unsigned char) ReadBlobByte(image);
159 ThrowReaderException(CoderError,"OnlyLevelZerofilesSupported");
160 if (AcquireImageColormap(image,2) == MagickFalse)
161 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
162 if (image_info->ping != MagickFalse)
164 (void) CloseBlob(image);
165 return(GetFirstImageInList(image));
168 Convert bi-level image to pixel packets.
170 for (y=0; y < (long) image->rows; y++)
172 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
173 if (q == (PixelPacket *) NULL)
175 indexes=GetAuthenticIndexQueue(image);
178 for (x=0; x < (long) image->columns; x++)
182 byte=ReadBlobByte(image);
184 ThrowReaderException(CorruptImageError,"CorruptImage");
186 indexes[x]=(IndexPacket) ((byte & (0x01 << (7-bit))) ? 0x00 : 0x01);
191 if (SyncAuthenticPixels(image,exception) == MagickFalse)
193 if (image->previous == (Image *) NULL)
195 status=SetImageProgress(image,LoadImageTag,y,image->rows);
196 if (status == MagickFalse)
200 (void) SyncImage(image);
201 if (EOFBlob(image) != MagickFalse)
202 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
204 (void) CloseBlob(image);
205 return(GetFirstImageInList(image));
209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 % R e g i s t e r O T B I m a g e %
217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219 % RegisterOTBImage() adds attributes for the OTB image format to
220 % the list of supported formats. The attributes include the image format
221 % tag, a method to read and/or write the format, whether the format
222 % supports the saving of more than one frame to the same file or blob,
223 % whether the format supports native in-memory I/O, and a brief
224 % description of the format.
226 % The format of the RegisterOTBImage method is:
228 % unsigned long RegisterOTBImage(void)
231 ModuleExport unsigned long RegisterOTBImage(void)
236 entry=SetMagickInfo("OTB");
237 entry->decoder=(DecodeImageHandler *) ReadOTBImage;
238 entry->encoder=(EncodeImageHandler *) WriteOTBImage;
239 entry->adjoin=MagickFalse;
240 entry->description=ConstantString("On-the-air bitmap");
241 entry->module=ConstantString("OTB");
242 (void) RegisterMagickInfo(entry);
243 return(MagickImageCoderSignature);
247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 % U n r e g i s t e r O T B I m a g e %
255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 % UnregisterOTBImage() removes format registrations made by the
258 % OTB module from the list of supported formats.
260 % The format of the UnregisterOTBImage method is:
262 % UnregisterOTBImage(void)
265 ModuleExport void UnregisterOTBImage(void)
267 (void) UnregisterMagickInfo("OTB");
271 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 % W r i t e O T B I m a g e %
279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
281 % WriteOTBImage() writes an image to a file in the On-the-air Bitmap
282 % (level 0) image format.
284 % The format of the WriteOTBImage method is:
286 % MagickBooleanType WriteOTBImage(const ImageInfo *image_info,Image *image)
288 % A description of each parameter follows.
290 % o image_info: the image info.
292 % o image: The image.
296 static MagickBooleanType WriteOTBImage(const ImageInfo *image_info,Image *image)
298 #define SetBit(a,i,set) \
299 a=(unsigned char) ((set) ? (a) | (1L << (i)) : (a) & ~(1L << (i)))
307 register const PixelPacket
319 Open output image file.
321 assert(image_info != (const ImageInfo *) NULL);
322 assert(image_info->signature == MagickSignature);
323 assert(image != (Image *) NULL);
324 assert(image->signature == MagickSignature);
325 if (image->debug != MagickFalse)
326 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
327 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
328 if (status == MagickFalse)
330 if (image->colorspace != RGBColorspace)
331 (void) TransformImageColorspace(image,RGBColorspace);
333 Convert image to a bi-level image.
335 (void) SetImageType(image,BilevelType);
337 if ((image->columns >= 256) || (image->rows >= 256))
339 (void) WriteBlobByte(image,info);
340 if ((image->columns >= 256) || (image->rows >= 256))
342 (void) WriteBlobMSBShort(image,(unsigned short) image->columns);
343 (void) WriteBlobMSBShort(image,(unsigned short) image->rows);
347 (void) WriteBlobByte(image,(unsigned char) image->columns);
348 (void) WriteBlobByte(image,(unsigned char) image->rows);
350 (void) WriteBlobByte(image,1); /* depth */
351 for (y=0; y < (long) image->rows; y++)
353 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
354 if (p == (const PixelPacket *) NULL)
358 for (x=0; x < (long) image->columns; x++)
360 if (PixelIntensity(p) < ((Quantum) QuantumRange/2.0))
361 byte|=0x1 << (7-bit);
365 (void) WriteBlobByte(image,byte);
372 (void) WriteBlobByte(image,byte);
373 if (image->previous == (Image *) NULL)
375 status=SetImageProgress(image,SaveImageTag,y,image->rows);
376 if (status == MagickFalse)
380 (void) CloseBlob(image);