2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read Scitex HandShake 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/exception.h"
47 #include "magick/exception-private.h"
48 #include "magick/image.h"
49 #include "magick/image-private.h"
50 #include "magick/list.h"
51 #include "magick/magick.h"
52 #include "magick/memory_.h"
53 #include "magick/module.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/string-private.h"
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 % IsSCT() returns MagickTrue if the image format type, identified by the
73 % magick string, is SCT.
75 % The format of the IsSCT method is:
77 % MagickBooleanType IsSCT(const unsigned char *magick,const size_t length)
79 % A description of each parameter follows:
81 % o magick: compare image format pattern against these bytes.
83 % o length: Specifies the length of the magick string.
86 static MagickBooleanType IsSCT(const unsigned char *magick,const size_t length)
90 if (LocaleNCompare((const char *) magick,"CT",2) == 0)
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 % R e a d S C T I m a g e %
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 % ReadSCTImage() reads a Scitex image file and returns it. It allocates
107 % the memory necessary for the new Image structure and returns a pointer to
110 % The format of the ReadSCTImage method is:
112 % Image *ReadSCTImage(const ImageInfo *image_info,ExceptionInfo *exception)
114 % A description of each parameter follows:
116 % o image_info: the image info.
118 % o exception: return any errors or warnings in this structure.
121 static Image *ReadSCTImage(const ImageInfo *image_info,ExceptionInfo *exception)
166 assert(image_info != (const ImageInfo *) NULL);
167 assert(image_info->signature == MagickSignature);
168 if (image_info->debug != MagickFalse)
169 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
170 image_info->filename);
171 assert(exception != (ExceptionInfo *) NULL);
172 assert(exception->signature == MagickSignature);
173 image=AcquireImage(image_info);
174 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
175 if (status == MagickFalse)
177 image=DestroyImageList(image);
178 return((Image *) NULL);
183 count=ReadBlob(image,80,buffer);
184 count=ReadBlob(image,2,(unsigned char *) magick);
185 if ((LocaleNCompare((char *) magick,"CT",2) != 0) &&
186 (LocaleNCompare((char *) magick,"LW",2) != 0) &&
187 (LocaleNCompare((char *) magick,"BM",2) != 0) &&
188 (LocaleNCompare((char *) magick,"PG",2) != 0) &&
189 (LocaleNCompare((char *) magick,"TX",2) != 0))
190 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
191 if ((LocaleNCompare((char *) magick,"LW",2) == 0) ||
192 (LocaleNCompare((char *) magick,"BM",2) == 0) ||
193 (LocaleNCompare((char *) magick,"PG",2) == 0) ||
194 (LocaleNCompare((char *) magick,"TX",2) == 0))
195 ThrowReaderException(CoderError,"OnlyContinuousTonePictureSupported");
196 count=ReadBlob(image,174,buffer);
197 count=ReadBlob(image,768,buffer);
201 units=1UL*ReadBlobByte(image);
203 image->units=PixelsPerCentimeterResolution;
204 separations=1UL*ReadBlobByte(image);
205 separations_mask=ReadBlobMSBShort(image);
206 count=ReadBlob(image,14,buffer);
208 height=StringToDouble((char *) buffer);
209 count=ReadBlob(image,14,buffer);
210 width=StringToDouble((char *) buffer);
211 count=ReadBlob(image,12,buffer);
213 image->rows=StringToUnsignedLong((char *) buffer);
214 count=ReadBlob(image,12,buffer);
215 image->columns=StringToUnsignedLong((char *) buffer);
216 count=ReadBlob(image,200,buffer);
217 count=ReadBlob(image,768,buffer);
218 if (separations_mask == 0x0f)
219 image->colorspace=CMYKColorspace;
220 image->x_resolution=1.0*image->columns/width;
221 image->y_resolution=1.0*image->rows/height;
222 if (image_info->ping != MagickFalse)
224 (void) CloseBlob(image);
225 return(GetFirstImageInList(image));
228 Convert SCT raster image to pixel packets.
230 for (y=0; y < (long) image->rows; y++)
232 for (i=0; i < (long) separations; i++)
234 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
235 if (q == (PixelPacket *) NULL)
237 indexes=GetAuthenticIndexQueue(image);
238 for (x=0; x < (long) image->columns; x++)
240 pixel=(Quantum) ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
241 if (image->colorspace == CMYKColorspace)
242 pixel=(Quantum) (QuantumRange-pixel);
259 q->blue=pixel; break;
264 if (image->colorspace == CMYKColorspace)
265 indexes[x]=(IndexPacket) pixel;
271 if (SyncAuthenticPixels(image,exception) == MagickFalse)
273 if ((image->columns % 2) != 0)
274 (void) ReadBlobByte(image); /* pad */
276 status=SetImageProgress(image,LoadImageTag,y,image->rows);
277 if (status == MagickFalse)
280 if (EOFBlob(image) != MagickFalse)
281 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
283 (void) CloseBlob(image);
284 return(GetFirstImageInList(image));
288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292 % R e g i s t e r S C T I m a g e %
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.
305 % The format of the RegisterSCTImage method is:
307 % unsigned long RegisterSCTImage(void)
310 ModuleExport unsigned long RegisterSCTImage(void)
315 entry=SetMagickInfo("SCT");
316 entry->decoder=(DecodeImageHandler *) ReadSCTImage;
317 entry->magick=(IsImageFormatHandler *) IsSCT;
318 entry->adjoin=MagickFalse;
319 entry->description=ConstantString("Scitex HandShake");
320 entry->module=ConstantString("SCT");
321 (void) RegisterMagickInfo(entry);
322 return(MagickImageCoderSignature);
326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
330 % U n r e g i s t e r S C T I m a g e %
334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336 % UnregisterSCTImage() removes format registrations made by the
337 % SCT module from the list of supported formats.
339 % The format of the UnregisterSCTImage method is:
341 % UnregisterSCTImage(void)
344 ModuleExport void UnregisterSCTImage(void)
346 (void) UnregisterMagickInfo("SCT");