cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % H H RRRR ZZZZZ % |
| 7 | % H H R R ZZ % |
| 8 | % HHHHH RRRR Z % |
| 9 | % H H R R ZZ % |
| 10 | % H H R R ZZZZZ % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write Slow Scan TeleVision Image Format % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 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. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
| 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" |
| 60 | |
| 61 | /* |
| 62 | Forward declarations. |
| 63 | */ |
| 64 | static MagickBooleanType |
| 65 | WriteHRZImage(const ImageInfo *,Image *); |
| 66 | |
| 67 | /* |
| 68 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 69 | % % |
| 70 | % % |
| 71 | % % |
| 72 | % R e a d H R Z I m a g e % |
| 73 | % % |
| 74 | % % |
| 75 | % % |
| 76 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 77 | % |
| 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. |
| 81 | % |
| 82 | % The format of the ReadHRZImage method is: |
| 83 | % |
| 84 | % Image *ReadHRZImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 85 | % |
| 86 | % A description of each parameter follows: |
| 87 | % |
| 88 | % o image_info: the image info. |
| 89 | % |
| 90 | % o exception: return any errors or warnings in this structure. |
| 91 | % |
| 92 | */ |
| 93 | static Image *ReadHRZImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 94 | { |
| 95 | Image |
| 96 | *image; |
| 97 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 98 | MagickBooleanType |
| 99 | status; |
| 100 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 101 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 102 | x; |
| 103 | |
| 104 | register PixelPacket |
| 105 | *q; |
| 106 | |
| 107 | register unsigned char |
| 108 | *p; |
| 109 | |
| 110 | ssize_t |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame] | 111 | count, |
| 112 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 113 | |
| 114 | size_t |
| 115 | length; |
| 116 | |
| 117 | unsigned char |
| 118 | *pixels; |
| 119 | |
| 120 | /* |
| 121 | Open image file. |
| 122 | */ |
| 123 | assert(image_info != (const ImageInfo *) NULL); |
| 124 | assert(image_info->signature == MagickSignature); |
| 125 | if (image_info->debug != MagickFalse) |
| 126 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 127 | image_info->filename); |
| 128 | assert(exception != (ExceptionInfo *) NULL); |
| 129 | assert(exception->signature == MagickSignature); |
| 130 | image=AcquireImage(image_info); |
| 131 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 132 | if (status == MagickFalse) |
| 133 | { |
| 134 | image=DestroyImageList(image); |
| 135 | return((Image *) NULL); |
| 136 | } |
| 137 | /* |
| 138 | Convert HRZ raster image to pixel packets. |
| 139 | */ |
| 140 | image->columns=256; |
| 141 | image->rows=240; |
| 142 | image->depth=8; |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame] | 143 | pixels=(unsigned char *) AcquireQuantumMemory(image->columns,3* |
| 144 | sizeof(*pixels)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 145 | if (pixels == (unsigned char *) NULL) |
| 146 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 147 | length=(size_t) (3*image->columns); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 148 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 149 | { |
| 150 | count=ReadBlob(image,length,pixels); |
| 151 | if ((size_t) count != length) |
| 152 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 153 | p=pixels; |
| 154 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
| 155 | if (q == (PixelPacket *) NULL) |
| 156 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 157 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 158 | { |
cristy | ef61831 | 2011-06-25 12:26:44 +0000 | [diff] [blame] | 159 | SetPixelRed(q,4*ScaleCharToQuantum(*p++)); |
| 160 | SetPixelGreen(q,4*ScaleCharToQuantum(*p++)); |
| 161 | SetPixelBlue(q,4*ScaleCharToQuantum(*p++)); |
| 162 | SetPixelOpacity(q,OpaqueOpacity); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 163 | q++; |
| 164 | } |
| 165 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 166 | break; |
| 167 | if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse) |
| 168 | break; |
| 169 | } |
| 170 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 171 | if (EOFBlob(image) != MagickFalse) |
| 172 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 173 | image->filename); |
| 174 | (void) CloseBlob(image); |
| 175 | return(GetFirstImageInList(image)); |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 180 | % % |
| 181 | % % |
| 182 | % % |
| 183 | % R e g i s t e r H R Z I m a g e % |
| 184 | % % |
| 185 | % % |
| 186 | % % |
| 187 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 188 | % |
| 189 | % RegisterHRZImage() adds attributes for the HRZ X image format to the list |
| 190 | % of supported formats. The attributes include the image format tag, a |
| 191 | % method to read and/or write the format, whether the format supports the |
| 192 | % saving of more than one frame to the same file or blob, whether the format |
| 193 | % supports native in-memory I/O, and a brief description of the format. |
| 194 | % |
| 195 | % The format of the RegisterHRZImage method is: |
| 196 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 197 | % size_t RegisterHRZImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 198 | % |
| 199 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 200 | ModuleExport size_t RegisterHRZImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 201 | { |
| 202 | MagickInfo |
| 203 | *entry; |
| 204 | |
| 205 | entry=SetMagickInfo("HRZ"); |
| 206 | entry->decoder=(DecodeImageHandler *) ReadHRZImage; |
| 207 | entry->encoder=(EncodeImageHandler *) WriteHRZImage; |
| 208 | entry->adjoin=MagickFalse; |
| 209 | entry->description=ConstantString("Slow Scan TeleVision"); |
| 210 | entry->module=ConstantString("HRZ"); |
| 211 | (void) RegisterMagickInfo(entry); |
| 212 | return(MagickImageCoderSignature); |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 217 | % % |
| 218 | % % |
| 219 | % % |
| 220 | % U n r e g i s t e r H R Z I m a g e % |
| 221 | % % |
| 222 | % % |
| 223 | % % |
| 224 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 225 | % |
| 226 | % UnregisterHRZImage() removes format registrations made by the |
| 227 | % HRZ module from the list of supported formats. |
| 228 | % |
| 229 | % The format of the UnregisterHRZImage method is: |
| 230 | % |
| 231 | % UnregisterHRZImage(void) |
| 232 | % |
| 233 | */ |
| 234 | ModuleExport void UnregisterHRZImage(void) |
| 235 | { |
| 236 | (void) UnregisterMagickInfo("HRZ"); |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 241 | % % |
| 242 | % % |
| 243 | % % |
| 244 | % W r i t e H R Z I m a g e % |
| 245 | % % |
| 246 | % % |
| 247 | % % |
| 248 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 249 | % |
| 250 | % WriteHRZImage() writes an image to a file in HRZ X image format. |
| 251 | % |
| 252 | % The format of the WriteHRZImage method is: |
| 253 | % |
| 254 | % MagickBooleanType WriteHRZImage(const ImageInfo *image_info,Image *image) |
| 255 | % |
| 256 | % A description of each parameter follows. |
| 257 | % |
| 258 | % o image_info: the image info. |
| 259 | % |
| 260 | % o image: The image. |
| 261 | % |
| 262 | */ |
| 263 | static MagickBooleanType WriteHRZImage(const ImageInfo *image_info,Image *image) |
| 264 | { |
| 265 | Image |
| 266 | *hrz_image; |
| 267 | |
| 268 | MagickBooleanType |
| 269 | status; |
| 270 | |
| 271 | register const PixelPacket |
| 272 | *p; |
| 273 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 274 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 275 | x, |
| 276 | y; |
| 277 | |
| 278 | register unsigned char |
| 279 | *q; |
| 280 | |
| 281 | ssize_t |
| 282 | count; |
| 283 | |
| 284 | unsigned char |
| 285 | *pixels; |
| 286 | |
| 287 | /* |
| 288 | Open output image file. |
| 289 | */ |
| 290 | assert(image_info != (const ImageInfo *) NULL); |
| 291 | assert(image_info->signature == MagickSignature); |
| 292 | assert(image != (Image *) NULL); |
| 293 | assert(image->signature == MagickSignature); |
| 294 | if (image->debug != MagickFalse) |
| 295 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 296 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); |
| 297 | if (status == MagickFalse) |
| 298 | return(status); |
| 299 | hrz_image=ResizeImage(image,256,240,image->filter,image->blur, |
| 300 | &image->exception); |
| 301 | if (hrz_image == (Image *) NULL) |
| 302 | return(MagickFalse); |
| 303 | if (hrz_image->colorspace != RGBColorspace) |
| 304 | (void) TransformImageColorspace(hrz_image,RGBColorspace); |
| 305 | /* |
| 306 | Allocate memory for pixels. |
| 307 | */ |
| 308 | pixels=(unsigned char *) AcquireQuantumMemory((size_t) hrz_image->columns, |
| 309 | 3*sizeof(*pixels)); |
| 310 | if (pixels == (unsigned char *) NULL) |
| 311 | { |
| 312 | hrz_image=DestroyImage(hrz_image); |
| 313 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 314 | } |
| 315 | /* |
| 316 | Convert MIFF to HRZ raster pixels. |
| 317 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 318 | for (y=0; y < (ssize_t) hrz_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 319 | { |
| 320 | p=GetVirtualPixels(hrz_image,0,y,hrz_image->columns,1,&image->exception); |
| 321 | if (p == (PixelPacket *) NULL) |
| 322 | break; |
| 323 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 324 | for (x=0; x < (ssize_t) hrz_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 325 | { |
cristy | ef61831 | 2011-06-25 12:26:44 +0000 | [diff] [blame] | 326 | *q++=ScaleQuantumToChar(GetPixelRed(p))/4; |
| 327 | *q++=ScaleQuantumToChar(GetPixelGreen(p))/4; |
| 328 | *q++=ScaleQuantumToChar(GetPixelBlue(p))/4; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 329 | p++; |
| 330 | } |
| 331 | count=WriteBlob(image,(size_t) (q-pixels),pixels); |
| 332 | if (count != (ssize_t) (q-pixels)) |
| 333 | break; |
| 334 | status=SetImageProgress(image,SaveImageTag,y,hrz_image->rows); |
| 335 | if (status == MagickFalse) |
| 336 | break; |
| 337 | } |
| 338 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 339 | hrz_image=DestroyImage(hrz_image); |
| 340 | (void) CloseBlob(image); |
| 341 | return(MagickTrue); |
| 342 | } |