2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read Scitex HandShake 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 "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);
185 count=ReadBlob(image,2,(unsigned char *) magick);
186 if ((LocaleNCompare((char *) magick,"CT",2) != 0) &&
187 (LocaleNCompare((char *) magick,"LW",2) != 0) &&
188 (LocaleNCompare((char *) magick,"BM",2) != 0) &&
189 (LocaleNCompare((char *) magick,"PG",2) != 0) &&
190 (LocaleNCompare((char *) magick,"TX",2) != 0))
191 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
192 if ((LocaleNCompare((char *) magick,"LW",2) == 0) ||
193 (LocaleNCompare((char *) magick,"BM",2) == 0) ||
194 (LocaleNCompare((char *) magick,"PG",2) == 0) ||
195 (LocaleNCompare((char *) magick,"TX",2) == 0))
196 ThrowReaderException(CoderError,"OnlyContinuousTonePictureSupported");
197 count=ReadBlob(image,174,buffer);
198 count=ReadBlob(image,768,buffer);
202 units=1UL*ReadBlobByte(image);
204 image->units=PixelsPerCentimeterResolution;
205 separations=1UL*ReadBlobByte(image);
206 separations_mask=ReadBlobMSBShort(image);
207 count=ReadBlob(image,14,buffer);
209 height=StringToDouble((char *) buffer);
210 count=ReadBlob(image,14,buffer);
211 width=StringToDouble((char *) buffer);
212 count=ReadBlob(image,12,buffer);
214 image->rows=StringToUnsignedLong((char *) buffer);
215 count=ReadBlob(image,12,buffer);
216 image->columns=StringToUnsignedLong((char *) buffer);
217 count=ReadBlob(image,200,buffer);
218 count=ReadBlob(image,768,buffer);
219 if (separations_mask == 0x0f)
220 image->colorspace=CMYKColorspace;
221 image->x_resolution=1.0*image->columns/width;
222 image->y_resolution=1.0*image->rows/height;
223 if (image_info->ping != MagickFalse)
225 (void) CloseBlob(image);
226 return(GetFirstImageInList(image));
229 Convert SCT raster image to pixel packets.
231 for (y=0; y < (ssize_t) image->rows; y++)
233 for (i=0; i < (ssize_t) separations; i++)
235 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
236 if (q == (PixelPacket *) NULL)
238 indexes=GetAuthenticIndexQueue(image);
239 for (x=0; x < (ssize_t) image->columns; x++)
241 pixel=(Quantum) ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
242 if (image->colorspace == CMYKColorspace)
243 pixel=(Quantum) (QuantumRange-pixel);
260 q->blue=pixel; break;
265 if (image->colorspace == CMYKColorspace)
266 indexes[x]=(IndexPacket) pixel;
272 if (SyncAuthenticPixels(image,exception) == MagickFalse)
274 if ((image->columns % 2) != 0)
275 (void) ReadBlobByte(image); /* pad */
277 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
279 if (status == MagickFalse)
282 if (EOFBlob(image) != MagickFalse)
283 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
285 (void) CloseBlob(image);
286 return(GetFirstImageInList(image));
290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294 % R e g i s t e r S C T I m a g e %
298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 % RegisterSCTImage() adds attributes for the SCT image format to
301 % the list of supported formats. The attributes include the image format
302 % tag, a method to read and/or write the format, whether the format
303 % supports the saving of more than one frame to the same file or blob,
304 % whether the format supports native in-memory I/O, and a brief
305 % description of the format.
307 % The format of the RegisterSCTImage method is:
309 % size_t RegisterSCTImage(void)
312 ModuleExport size_t RegisterSCTImage(void)
317 entry=SetMagickInfo("SCT");
318 entry->decoder=(DecodeImageHandler *) ReadSCTImage;
319 entry->magick=(IsImageFormatHandler *) IsSCT;
320 entry->adjoin=MagickFalse;
321 entry->description=ConstantString("Scitex HandShake");
322 entry->module=ConstantString("SCT");
323 (void) RegisterMagickInfo(entry);
324 return(MagickImageCoderSignature);
328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 % U n r e g i s t e r S C T I m a g e %
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 % UnregisterSCTImage() removes format registrations made by the
339 % SCT module from the list of supported formats.
341 % The format of the UnregisterSCTImage method is:
343 % UnregisterSCTImage(void)
346 ModuleExport void UnregisterSCTImage(void)
348 (void) UnregisterMagickInfo("SCT");