cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % SSSSS CCCC TTTTT % |
| 7 | % SS C T % |
| 8 | % SSS C T % |
| 9 | % SS C T % |
| 10 | % SSSSS CCCC T % |
| 11 | % % |
| 12 | % % |
| 13 | % Read Scitex HandShake Image Format % |
| 14 | % % |
| 15 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | b56bb24 | 2014-11-25 17:12:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2015 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 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/blob-private.h" |
| 45 | #include "MagickCore/cache.h" |
| 46 | #include "MagickCore/exception.h" |
| 47 | #include "MagickCore/exception-private.h" |
| 48 | #include "MagickCore/image.h" |
| 49 | #include "MagickCore/image-private.h" |
| 50 | #include "MagickCore/list.h" |
| 51 | #include "MagickCore/magick.h" |
| 52 | #include "MagickCore/memory_.h" |
| 53 | #include "MagickCore/module.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/string-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 64 | % % |
| 65 | % % |
| 66 | % % |
| 67 | % I s S C T % |
| 68 | % % |
| 69 | % % |
| 70 | % % |
| 71 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 72 | % |
| 73 | % IsSCT() returns MagickTrue if the image format type, identified by the |
| 74 | % magick string, is SCT. |
| 75 | % |
| 76 | % The format of the IsSCT method is: |
| 77 | % |
| 78 | % MagickBooleanType IsSCT(const unsigned char *magick,const size_t length) |
| 79 | % |
| 80 | % A description of each parameter follows: |
| 81 | % |
| 82 | % o magick: compare image format pattern against these bytes. |
| 83 | % |
| 84 | % o length: Specifies the length of the magick string. |
| 85 | % |
| 86 | */ |
| 87 | static MagickBooleanType IsSCT(const unsigned char *magick,const size_t length) |
| 88 | { |
| 89 | if (length < 2) |
| 90 | return(MagickFalse); |
| 91 | if (LocaleNCompare((const char *) magick,"CT",2) == 0) |
| 92 | return(MagickTrue); |
| 93 | return(MagickFalse); |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 98 | % % |
| 99 | % % |
| 100 | % % |
| 101 | % R e a d S C T I m a g e % |
| 102 | % % |
| 103 | % % |
| 104 | % % |
| 105 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 106 | % |
| 107 | % ReadSCTImage() reads a Scitex image file and returns it. It allocates |
| 108 | % the memory necessary for the new Image structure and returns a pointer to |
| 109 | % the new image. |
| 110 | % |
| 111 | % The format of the ReadSCTImage method is: |
| 112 | % |
| 113 | % Image *ReadSCTImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 114 | % |
| 115 | % A description of each parameter follows: |
| 116 | % |
| 117 | % o image_info: the image info. |
| 118 | % |
| 119 | % o exception: return any errors or warnings in this structure. |
| 120 | % |
| 121 | */ |
| 122 | static Image *ReadSCTImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 123 | { |
| 124 | char |
| 125 | magick[2]; |
| 126 | |
| 127 | Image |
| 128 | *image; |
| 129 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 130 | MagickBooleanType |
| 131 | status; |
| 132 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 133 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 134 | height, |
| 135 | width; |
| 136 | |
| 137 | Quantum |
| 138 | pixel; |
| 139 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 140 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 141 | i, |
| 142 | x; |
| 143 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 144 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 145 | *q; |
| 146 | |
| 147 | ssize_t |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 148 | count, |
| 149 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 150 | |
| 151 | unsigned char |
| 152 | buffer[768]; |
| 153 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 154 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 155 | separations, |
| 156 | separations_mask, |
| 157 | units; |
| 158 | |
| 159 | /* |
| 160 | Open image file. |
| 161 | */ |
| 162 | assert(image_info != (const ImageInfo *) NULL); |
| 163 | assert(image_info->signature == MagickSignature); |
| 164 | if (image_info->debug != MagickFalse) |
| 165 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 166 | image_info->filename); |
| 167 | assert(exception != (ExceptionInfo *) NULL); |
| 168 | assert(exception->signature == MagickSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 169 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 170 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 171 | if (status == MagickFalse) |
| 172 | { |
| 173 | image=DestroyImageList(image); |
| 174 | return((Image *) NULL); |
| 175 | } |
| 176 | /* |
| 177 | Read control block. |
| 178 | */ |
| 179 | count=ReadBlob(image,80,buffer); |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 180 | (void) count; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 181 | count=ReadBlob(image,2,(unsigned char *) magick); |
| 182 | if ((LocaleNCompare((char *) magick,"CT",2) != 0) && |
| 183 | (LocaleNCompare((char *) magick,"LW",2) != 0) && |
| 184 | (LocaleNCompare((char *) magick,"BM",2) != 0) && |
| 185 | (LocaleNCompare((char *) magick,"PG",2) != 0) && |
| 186 | (LocaleNCompare((char *) magick,"TX",2) != 0)) |
| 187 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 188 | if ((LocaleNCompare((char *) magick,"LW",2) == 0) || |
| 189 | (LocaleNCompare((char *) magick,"BM",2) == 0) || |
| 190 | (LocaleNCompare((char *) magick,"PG",2) == 0) || |
| 191 | (LocaleNCompare((char *) magick,"TX",2) == 0)) |
| 192 | ThrowReaderException(CoderError,"OnlyContinuousTonePictureSupported"); |
| 193 | count=ReadBlob(image,174,buffer); |
| 194 | count=ReadBlob(image,768,buffer); |
| 195 | /* |
| 196 | Read paramter block. |
| 197 | */ |
| 198 | units=1UL*ReadBlobByte(image); |
| 199 | if (units == 0) |
| 200 | image->units=PixelsPerCentimeterResolution; |
| 201 | separations=1UL*ReadBlobByte(image); |
| 202 | separations_mask=ReadBlobMSBShort(image); |
| 203 | count=ReadBlob(image,14,buffer); |
| 204 | buffer[14]='\0'; |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 205 | height=StringToDouble((char *) buffer,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 206 | count=ReadBlob(image,14,buffer); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 207 | width=StringToDouble((char *) buffer,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 208 | count=ReadBlob(image,12,buffer); |
| 209 | buffer[12]='\0'; |
cristy | 5131f3e | 2009-12-18 03:09:10 +0000 | [diff] [blame] | 210 | image->rows=StringToUnsignedLong((char *) buffer); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 211 | count=ReadBlob(image,12,buffer); |
cristy | 5131f3e | 2009-12-18 03:09:10 +0000 | [diff] [blame] | 212 | image->columns=StringToUnsignedLong((char *) buffer); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 213 | count=ReadBlob(image,200,buffer); |
| 214 | count=ReadBlob(image,768,buffer); |
| 215 | if (separations_mask == 0x0f) |
cristy | e2c4f18 | 2012-05-12 14:11:53 +0000 | [diff] [blame] | 216 | SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 217 | image->resolution.x=1.0*image->columns/width; |
| 218 | image->resolution.y=1.0*image->rows/height; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 219 | if (image_info->ping != MagickFalse) |
| 220 | { |
| 221 | (void) CloseBlob(image); |
| 222 | return(GetFirstImageInList(image)); |
| 223 | } |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 224 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 225 | if (status == MagickFalse) |
| 226 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 227 | /* |
| 228 | Convert SCT raster image to pixel packets. |
| 229 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 230 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 231 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 232 | for (i=0; i < (ssize_t) separations; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 233 | { |
| 234 | q=GetAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 235 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 236 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 237 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 238 | { |
| 239 | pixel=(Quantum) ScaleCharToQuantum((unsigned char) ReadBlobByte(image)); |
| 240 | if (image->colorspace == CMYKColorspace) |
| 241 | pixel=(Quantum) (QuantumRange-pixel); |
| 242 | switch (i) |
| 243 | { |
| 244 | case 0: |
| 245 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 246 | SetPixelRed(image,pixel,q); |
| 247 | SetPixelGreen(image,pixel,q); |
| 248 | SetPixelBlue(image,pixel,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 249 | break; |
| 250 | } |
| 251 | case 1: |
| 252 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 253 | SetPixelGreen(image,pixel,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 254 | break; |
| 255 | } |
| 256 | case 2: |
| 257 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 258 | SetPixelBlue(image,pixel,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 259 | break; |
| 260 | } |
| 261 | case 3: |
| 262 | { |
| 263 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 264 | SetPixelBlack(image,pixel,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 265 | break; |
| 266 | } |
| 267 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 268 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 269 | } |
| 270 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 271 | break; |
| 272 | if ((image->columns % 2) != 0) |
| 273 | (void) ReadBlobByte(image); /* pad */ |
| 274 | } |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 275 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 276 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 277 | if (status == MagickFalse) |
| 278 | break; |
| 279 | } |
| 280 | if (EOFBlob(image) != MagickFalse) |
| 281 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 282 | image->filename); |
| 283 | (void) CloseBlob(image); |
| 284 | return(GetFirstImageInList(image)); |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 289 | % % |
| 290 | % % |
| 291 | % % |
| 292 | % R e g i s t e r S C T I m a g e % |
| 293 | % % |
| 294 | % % |
| 295 | % % |
| 296 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 297 | % |
| 298 | % RegisterSCTImage() adds attributes for the SCT image format to |
| 299 | % the list of supported formats. The attributes include the image format |
| 300 | % tag, a method to read and/or write the format, whether the format |
| 301 | % supports the saving of more than one frame to the same file or blob, |
| 302 | % whether the format supports native in-memory I/O, and a brief |
| 303 | % description of the format. |
| 304 | % |
| 305 | % The format of the RegisterSCTImage method is: |
| 306 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 307 | % size_t RegisterSCTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 308 | % |
| 309 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 310 | ModuleExport size_t RegisterSCTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 311 | { |
| 312 | MagickInfo |
| 313 | *entry; |
| 314 | |
| 315 | entry=SetMagickInfo("SCT"); |
| 316 | entry->decoder=(DecodeImageHandler *) ReadSCTImage; |
| 317 | entry->magick=(IsImageFormatHandler *) IsSCT; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame^] | 318 | entry->flags^=CoderAdjoinFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 319 | entry->description=ConstantString("Scitex HandShake"); |
| 320 | entry->module=ConstantString("SCT"); |
| 321 | (void) RegisterMagickInfo(entry); |
| 322 | return(MagickImageCoderSignature); |
| 323 | } |
| 324 | |
| 325 | /* |
| 326 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 327 | % % |
| 328 | % % |
| 329 | % % |
| 330 | % U n r e g i s t e r S C T I m a g e % |
| 331 | % % |
| 332 | % % |
| 333 | % % |
| 334 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 335 | % |
| 336 | % UnregisterSCTImage() removes format registrations made by the |
| 337 | % SCT module from the list of supported formats. |
| 338 | % |
| 339 | % The format of the UnregisterSCTImage method is: |
| 340 | % |
| 341 | % UnregisterSCTImage(void) |
| 342 | % |
| 343 | */ |
| 344 | ModuleExport void UnregisterSCTImage(void) |
| 345 | { |
| 346 | (void) UnregisterMagickInfo("SCT"); |
| 347 | } |