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 "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"
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 % IsSCT() returns MagickTrue if the image format type, identified by the
74 % magick string, is SCT.
76 % The format of the IsSCT method is:
78 % MagickBooleanType IsSCT(const unsigned char *magick,const size_t length)
80 % A description of each parameter follows:
82 % o magick: compare image format pattern against these bytes.
84 % o length: Specifies the length of the magick string.
87 static MagickBooleanType IsSCT(const unsigned char *magick,const size_t length)
91 if (LocaleNCompare((const char *) magick,"CT",2) == 0)
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 % R e a d S C T I m a g e %
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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
111 % The format of the ReadSCTImage method is:
113 % Image *ReadSCTImage(const ImageInfo *image_info,ExceptionInfo *exception)
115 % A description of each parameter follows:
117 % o image_info: the image info.
119 % o exception: return any errors or warnings in this structure.
122 static Image *ReadSCTImage(const ImageInfo *image_info,ExceptionInfo *exception)
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);
169 image=AcquireImage(image_info);
170 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
171 if (status == MagickFalse)
173 image=DestroyImageList(image);
174 return((Image *) NULL);
179 count=ReadBlob(image,80,buffer);
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);
198 units=1UL*ReadBlobByte(image);
200 image->units=PixelsPerCentimeterResolution;
201 separations=1UL*ReadBlobByte(image);
202 separations_mask=ReadBlobMSBShort(image);
203 count=ReadBlob(image,14,buffer);
205 height=InterpretLocaleValue((char *) buffer,(char **) NULL);
206 count=ReadBlob(image,14,buffer);
207 width=InterpretLocaleValue((char *) buffer,(char **) NULL);
208 count=ReadBlob(image,12,buffer);
210 image->rows=StringToUnsignedLong((char *) buffer);
211 count=ReadBlob(image,12,buffer);
212 image->columns=StringToUnsignedLong((char *) buffer);
213 count=ReadBlob(image,200,buffer);
214 count=ReadBlob(image,768,buffer);
215 if (separations_mask == 0x0f)
216 image->colorspace=CMYKColorspace;
217 image->x_resolution=1.0*image->columns/width;
218 image->y_resolution=1.0*image->rows/height;
219 if (image_info->ping != MagickFalse)
221 (void) CloseBlob(image);
222 return(GetFirstImageInList(image));
225 Convert SCT raster image to pixel packets.
227 for (y=0; y < (ssize_t) image->rows; y++)
229 for (i=0; i < (ssize_t) separations; i++)
231 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
232 if (q == (Quantum *) NULL)
234 for (x=0; x < (ssize_t) image->columns; x++)
236 pixel=(Quantum) ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
237 if (image->colorspace == CMYKColorspace)
238 pixel=(Quantum) (QuantumRange-pixel);
243 SetPixelRed(image,pixel,q);
244 SetPixelGreen(image,pixel,q);
245 SetPixelBlue(image,pixel,q);
250 SetPixelGreen(image,pixel,q);
255 SetPixelBlue(image,pixel,q);
260 if (image->colorspace == CMYKColorspace)
261 SetPixelBlack(image,pixel,q);
265 q+=GetPixelChannels(image);
267 if (SyncAuthenticPixels(image,exception) == MagickFalse)
269 if ((image->columns % 2) != 0)
270 (void) ReadBlobByte(image); /* pad */
272 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
274 if (status == MagickFalse)
277 if (EOFBlob(image) != MagickFalse)
278 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
280 (void) CloseBlob(image);
281 return(GetFirstImageInList(image));
285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289 % R e g i s t e r S C T I m a g e %
293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 % RegisterSCTImage() adds attributes for the SCT image format to
296 % the list of supported formats. The attributes include the image format
297 % tag, a method to read and/or write the format, whether the format
298 % supports the saving of more than one frame to the same file or blob,
299 % whether the format supports native in-memory I/O, and a brief
300 % description of the format.
302 % The format of the RegisterSCTImage method is:
304 % size_t RegisterSCTImage(void)
307 ModuleExport size_t RegisterSCTImage(void)
312 entry=SetMagickInfo("SCT");
313 entry->decoder=(DecodeImageHandler *) ReadSCTImage;
314 entry->magick=(IsImageFormatHandler *) IsSCT;
315 entry->adjoin=MagickFalse;
316 entry->description=ConstantString("Scitex HandShake");
317 entry->module=ConstantString("SCT");
318 (void) RegisterMagickInfo(entry);
319 return(MagickImageCoderSignature);
323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
327 % U n r e g i s t e r S C T I m a g e %
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
333 % UnregisterSCTImage() removes format registrations made by the
334 % SCT module from the list of supported formats.
336 % The format of the UnregisterSCTImage method is:
338 % UnregisterSCTImage(void)
341 ModuleExport void UnregisterSCTImage(void)
343 (void) UnregisterMagickInfo("SCT");