2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Slow Scan TeleVision Image Format %
20 % Copyright 1999-2011 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 "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/colorspace.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/image.h"
50 #include "MagickCore/image-private.h"
51 #include "MagickCore/list.h"
52 #include "MagickCore/magick.h"
53 #include "MagickCore/memory_.h"
54 #include "MagickCore/monitor.h"
55 #include "MagickCore/monitor-private.h"
56 #include "MagickCore/pixel-accessor.h"
57 #include "MagickCore/quantum-private.h"
58 #include "MagickCore/static.h"
59 #include "MagickCore/string_.h"
60 #include "MagickCore/module.h"
65 static MagickBooleanType
66 WriteHRZImage(const ImageInfo *,Image *);
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 % R e a d H R Z I m a g e %
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 % ReadHRZImage() reads a Slow Scan TeleVision image file and returns it. It
80 % allocates the memory necessary for the new Image structure and returns a
81 % pointer to the new image.
83 % The format of the ReadHRZImage method is:
85 % Image *ReadHRZImage(const ImageInfo *image_info,ExceptionInfo *exception)
87 % A description of each parameter follows:
89 % o image_info: the image info.
91 % o exception: return any errors or warnings in this structure.
94 static Image *ReadHRZImage(const ImageInfo *image_info,ExceptionInfo *exception)
108 register unsigned char
124 assert(image_info != (const ImageInfo *) NULL);
125 assert(image_info->signature == MagickSignature);
126 if (image_info->debug != MagickFalse)
127 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
128 image_info->filename);
129 assert(exception != (ExceptionInfo *) NULL);
130 assert(exception->signature == MagickSignature);
131 image=AcquireImage(image_info);
132 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
133 if (status == MagickFalse)
135 image=DestroyImageList(image);
136 return((Image *) NULL);
139 Convert HRZ raster image to pixel packets.
144 pixels=(unsigned char *) AcquireQuantumMemory(image->columns,3*
146 if (pixels == (unsigned char *) NULL)
147 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
148 length=(size_t) (3*image->columns);
149 for (y=0; y < (ssize_t) image->rows; y++)
151 count=ReadBlob(image,length,pixels);
152 if ((size_t) count != length)
153 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
155 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
156 if (q == (const Quantum *) NULL)
158 for (x=0; x < (ssize_t) image->columns; x++)
160 SetPixelRed(image,4*ScaleCharToQuantum(*p++),q);
161 SetPixelGreen(image,4*ScaleCharToQuantum(*p++),q);
162 SetPixelBlue(image,4*ScaleCharToQuantum(*p++),q);
163 SetPixelAlpha(image,OpaqueAlpha,q);
164 q+=GetPixelChannels(image);
166 if (SyncAuthenticPixels(image,exception) == MagickFalse)
168 if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
171 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
172 if (EOFBlob(image) != MagickFalse)
173 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
175 (void) CloseBlob(image);
176 return(GetFirstImageInList(image));
180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 % R e g i s t e r H R Z I m a g e %
188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 % RegisterHRZImage() adds attributes for the HRZ X image format to the list
191 % of supported formats. The attributes include the image format tag, a
192 % method to read and/or write the format, whether the format supports the
193 % saving of more than one frame to the same file or blob, whether the format
194 % supports native in-memory I/O, and a brief description of the format.
196 % The format of the RegisterHRZImage method is:
198 % size_t RegisterHRZImage(void)
201 ModuleExport size_t RegisterHRZImage(void)
206 entry=SetMagickInfo("HRZ");
207 entry->decoder=(DecodeImageHandler *) ReadHRZImage;
208 entry->encoder=(EncodeImageHandler *) WriteHRZImage;
209 entry->adjoin=MagickFalse;
210 entry->description=ConstantString("Slow Scan TeleVision");
211 entry->module=ConstantString("HRZ");
212 (void) RegisterMagickInfo(entry);
213 return(MagickImageCoderSignature);
217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 % U n r e g i s t e r H R Z I m a g e %
225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227 % UnregisterHRZImage() removes format registrations made by the
228 % HRZ module from the list of supported formats.
230 % The format of the UnregisterHRZImage method is:
232 % UnregisterHRZImage(void)
235 ModuleExport void UnregisterHRZImage(void)
237 (void) UnregisterMagickInfo("HRZ");
241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245 % W r i t e H R Z I m a g e %
249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 % WriteHRZImage() writes an image to a file in HRZ X image format.
253 % The format of the WriteHRZImage method is:
255 % MagickBooleanType WriteHRZImage(const ImageInfo *image_info,Image *image)
257 % A description of each parameter follows.
259 % o image_info: the image info.
261 % o image: The image.
264 static MagickBooleanType WriteHRZImage(const ImageInfo *image_info,Image *image)
272 register const Quantum
279 register unsigned char
289 Open output image file.
291 assert(image_info != (const ImageInfo *) NULL);
292 assert(image_info->signature == MagickSignature);
293 assert(image != (Image *) NULL);
294 assert(image->signature == MagickSignature);
295 if (image->debug != MagickFalse)
296 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
297 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
298 if (status == MagickFalse)
300 hrz_image=ResizeImage(image,256,240,image->filter,image->blur,
302 if (hrz_image == (Image *) NULL)
304 if (IsRGBColorspace(hrz_image->colorspace) == MagickFalse)
305 (void) TransformImageColorspace(hrz_image,RGBColorspace);
307 Allocate memory for pixels.
309 pixels=(unsigned char *) AcquireQuantumMemory((size_t) hrz_image->columns,
311 if (pixels == (unsigned char *) NULL)
313 hrz_image=DestroyImage(hrz_image);
314 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
317 Convert MIFF to HRZ raster pixels.
319 for (y=0; y < (ssize_t) hrz_image->rows; y++)
321 p=GetVirtualPixels(hrz_image,0,y,hrz_image->columns,1,&image->exception);
322 if (p == (const Quantum *) NULL)
325 for (x=0; x < (ssize_t) hrz_image->columns; x++)
327 *q++=ScaleQuantumToChar(GetPixelRed(hrz_image,p))/4;
328 *q++=ScaleQuantumToChar(GetPixelGreen(hrz_image,p))/4;
329 *q++=ScaleQuantumToChar(GetPixelBlue(hrz_image,p))/4;
330 p+=GetPixelChannels(hrz_image);
332 count=WriteBlob(image,(size_t) (q-pixels),pixels);
333 if (count != (ssize_t) (q-pixels))
335 status=SetImageProgress(image,SaveImageTag,y,hrz_image->rows);
336 if (status == MagickFalse)
339 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
340 hrz_image=DestroyImage(hrz_image);
341 (void) CloseBlob(image);