2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Slow Scan TeleVision 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/cache.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 WriteHRZImage(const ImageInfo *,Image *);
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 % R e a d H R Z I m a g e %
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 % ReadHRZImage() reads a Slow Scan TeleVision image file 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 ReadHRZImage method is:
84 % Image *ReadHRZImage(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.
93 static Image *ReadHRZImage(const ImageInfo *image_info,ExceptionInfo *exception)
110 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);
140 Convert HRZ raster image to pixel packets.
145 pixels=(unsigned char *) AcquireQuantumMemory(image->columns,
147 if (pixels == (unsigned char *) NULL)
148 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
149 length=(size_t) (3*image->columns);
150 for (y=0; y < (long) image->rows; y++)
152 count=ReadBlob(image,length,pixels);
153 if ((size_t) count != length)
154 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
156 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
157 if (q == (PixelPacket *) NULL)
159 for (x=0; x < (long) image->columns; x++)
161 q->red=4*ScaleCharToQuantum(*p++);
162 q->green=4*ScaleCharToQuantum(*p++);
163 q->blue=4*ScaleCharToQuantum(*p++);
164 SetOpacityPixelComponent(q,OpaqueOpacity);
167 if (SyncAuthenticPixels(image,exception) == MagickFalse)
169 if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
172 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
173 if (EOFBlob(image) != MagickFalse)
174 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
176 (void) CloseBlob(image);
177 return(GetFirstImageInList(image));
181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 % R e g i s t e r H R Z I m a g e %
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 % RegisterHRZImage() adds attributes for the HRZ X image format to the list
192 % of supported formats. The attributes include the image format tag, a
193 % method to read and/or write the format, whether the format supports the
194 % saving of more than one frame to the same file or blob, whether the format
195 % supports native in-memory I/O, and a brief description of the format.
197 % The format of the RegisterHRZImage method is:
199 % unsigned long RegisterHRZImage(void)
202 ModuleExport unsigned long RegisterHRZImage(void)
207 entry=SetMagickInfo("HRZ");
208 entry->decoder=(DecodeImageHandler *) ReadHRZImage;
209 entry->encoder=(EncodeImageHandler *) WriteHRZImage;
210 entry->adjoin=MagickFalse;
211 entry->description=ConstantString("Slow Scan TeleVision");
212 entry->module=ConstantString("HRZ");
213 (void) RegisterMagickInfo(entry);
214 return(MagickImageCoderSignature);
218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 % U n r e g i s t e r H R Z I m a g e %
226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 % UnregisterHRZImage() removes format registrations made by the
229 % HRZ module from the list of supported formats.
231 % The format of the UnregisterHRZImage method is:
233 % UnregisterHRZImage(void)
236 ModuleExport void UnregisterHRZImage(void)
238 (void) UnregisterMagickInfo("HRZ");
242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 % W r i t e H R Z I m a g e %
250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252 % WriteHRZImage() writes an image to a file in HRZ X image format.
254 % The format of the WriteHRZImage method is:
256 % MagickBooleanType WriteHRZImage(const ImageInfo *image_info,Image *image)
258 % A description of each parameter follows.
260 % o image_info: the image info.
262 % o image: The image.
265 static MagickBooleanType WriteHRZImage(const ImageInfo *image_info,Image *image)
273 register const PixelPacket
280 register unsigned char
290 Open output image file.
292 assert(image_info != (const ImageInfo *) NULL);
293 assert(image_info->signature == MagickSignature);
294 assert(image != (Image *) NULL);
295 assert(image->signature == MagickSignature);
296 if (image->debug != MagickFalse)
297 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
298 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
299 if (status == MagickFalse)
301 hrz_image=ResizeImage(image,256,240,image->filter,image->blur,
303 if (hrz_image == (Image *) NULL)
305 if (hrz_image->colorspace != RGBColorspace)
306 (void) TransformImageColorspace(hrz_image,RGBColorspace);
308 Allocate memory for pixels.
310 pixels=(unsigned char *) AcquireQuantumMemory((size_t) hrz_image->columns,
312 if (pixels == (unsigned char *) NULL)
314 hrz_image=DestroyImage(hrz_image);
315 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
318 Convert MIFF to HRZ raster pixels.
320 for (y=0; y < (long) hrz_image->rows; y++)
322 p=GetVirtualPixels(hrz_image,0,y,hrz_image->columns,1,&image->exception);
323 if (p == (PixelPacket *) NULL)
326 for (x=0; x < (long) hrz_image->columns; x++)
328 *q++=ScaleQuantumToChar(GetRedPixelComponent(p))/4;
329 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p))/4;
330 *q++=ScaleQuantumToChar(GetBluePixelComponent(p))/4;
333 count=WriteBlob(image,(size_t) (q-pixels),pixels);
334 if (count != (ssize_t) (q-pixels))
336 status=SetImageProgress(image,SaveImageTag,y,hrz_image->rows);
337 if (status == MagickFalse)
340 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
341 hrz_image=DestroyImage(hrz_image);
342 (void) CloseBlob(image);