blob: ec259ada4a81ae53b2b8df6ec1dd6d45edee4879 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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 %
16% John Cristy %
17% July 1992 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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/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"
cristyf2f27272009-12-17 14:48:46 +000053#include "magick/module.h"
cristy3ed852e2009-09-05 21:47:34 +000054#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"
cristyf2f27272009-12-17 14:48:46 +000059#include "magick/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000060
61/*
62%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63% %
64% %
65% %
66% I s S C T %
67% %
68% %
69% %
70%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71%
72% IsSCT() returns MagickTrue if the image format type, identified by the
73% magick string, is SCT.
74%
75% The format of the IsSCT method is:
76%
77% MagickBooleanType IsSCT(const unsigned char *magick,const size_t length)
78%
79% A description of each parameter follows:
80%
81% o magick: compare image format pattern against these bytes.
82%
83% o length: Specifies the length of the magick string.
84%
85*/
86static MagickBooleanType IsSCT(const unsigned char *magick,const size_t length)
87{
88 if (length < 2)
89 return(MagickFalse);
90 if (LocaleNCompare((const char *) magick,"CT",2) == 0)
91 return(MagickTrue);
92 return(MagickFalse);
93}
94
95/*
96%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97% %
98% %
99% %
100% R e a d S C T I m a g e %
101% %
102% %
103% %
104%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105%
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
108% the new image.
109%
110% The format of the ReadSCTImage method is:
111%
112% Image *ReadSCTImage(const ImageInfo *image_info,ExceptionInfo *exception)
113%
114% A description of each parameter follows:
115%
116% o image_info: the image info.
117%
118% o exception: return any errors or warnings in this structure.
119%
120*/
121static Image *ReadSCTImage(const ImageInfo *image_info,ExceptionInfo *exception)
122{
123 char
124 magick[2];
125
126 Image
127 *image;
128
cristybb503372010-05-27 20:51:26 +0000129 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000130 y;
131
132 MagickBooleanType
133 status;
134
135 MagickRealType
136 height,
137 width;
138
139 Quantum
140 pixel;
141
142 register IndexPacket
143 *indexes;
144
cristybb503372010-05-27 20:51:26 +0000145 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000146 i,
147 x;
148
149 register PixelPacket
150 *q;
151
152 ssize_t
153 count;
154
155 unsigned char
156 buffer[768];
157
cristybb503372010-05-27 20:51:26 +0000158 size_t
cristy3ed852e2009-09-05 21:47:34 +0000159 separations,
160 separations_mask,
161 units;
162
163 /*
164 Open image file.
165 */
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)
176 {
177 image=DestroyImageList(image);
178 return((Image *) NULL);
179 }
180 /*
181 Read control block.
182 */
183 count=ReadBlob(image,80,buffer);
cristyda16f162011-02-19 23:52:17 +0000184 (void) count;
cristy3ed852e2009-09-05 21:47:34 +0000185 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);
199 /*
200 Read paramter block.
201 */
202 units=1UL*ReadBlobByte(image);
203 if (units == 0)
204 image->units=PixelsPerCentimeterResolution;
205 separations=1UL*ReadBlobByte(image);
206 separations_mask=ReadBlobMSBShort(image);
207 count=ReadBlob(image,14,buffer);
208 buffer[14]='\0';
cristyf2f27272009-12-17 14:48:46 +0000209 height=StringToDouble((char *) buffer);
cristy3ed852e2009-09-05 21:47:34 +0000210 count=ReadBlob(image,14,buffer);
cristyf2f27272009-12-17 14:48:46 +0000211 width=StringToDouble((char *) buffer);
cristy3ed852e2009-09-05 21:47:34 +0000212 count=ReadBlob(image,12,buffer);
213 buffer[12]='\0';
cristy5131f3e2009-12-18 03:09:10 +0000214 image->rows=StringToUnsignedLong((char *) buffer);
cristy3ed852e2009-09-05 21:47:34 +0000215 count=ReadBlob(image,12,buffer);
cristy5131f3e2009-12-18 03:09:10 +0000216 image->columns=StringToUnsignedLong((char *) buffer);
cristy3ed852e2009-09-05 21:47:34 +0000217 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)
224 {
225 (void) CloseBlob(image);
226 return(GetFirstImageInList(image));
227 }
228 /*
229 Convert SCT raster image to pixel packets.
230 */
cristybb503372010-05-27 20:51:26 +0000231 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000232 {
cristybb503372010-05-27 20:51:26 +0000233 for (i=0; i < (ssize_t) separations; i++)
cristy3ed852e2009-09-05 21:47:34 +0000234 {
235 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
236 if (q == (PixelPacket *) NULL)
237 break;
238 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +0000239 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000240 {
241 pixel=(Quantum) ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
242 if (image->colorspace == CMYKColorspace)
243 pixel=(Quantum) (QuantumRange-pixel);
244 switch (i)
245 {
246 case 0:
247 {
248 q->red=pixel;
249 q->green=pixel;
250 q->blue=pixel;
251 break;
252 }
253 case 1:
254 {
255 q->green=pixel;
256 break;
257 }
258 case 2:
259 {
260 q->blue=pixel; break;
261 break;
262 }
263 case 3:
264 {
265 if (image->colorspace == CMYKColorspace)
266 indexes[x]=(IndexPacket) pixel;
267 break;
268 }
269 }
270 q++;
271 }
272 if (SyncAuthenticPixels(image,exception) == MagickFalse)
273 break;
274 if ((image->columns % 2) != 0)
275 (void) ReadBlobByte(image); /* pad */
276 }
cristycee97112010-05-28 00:44:52 +0000277 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
278 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000279 if (status == MagickFalse)
280 break;
281 }
282 if (EOFBlob(image) != MagickFalse)
283 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
284 image->filename);
285 (void) CloseBlob(image);
286 return(GetFirstImageInList(image));
287}
288
289/*
290%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
291% %
292% %
293% %
294% R e g i s t e r S C T I m a g e %
295% %
296% %
297% %
298%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299%
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.
306%
307% The format of the RegisterSCTImage method is:
308%
cristybb503372010-05-27 20:51:26 +0000309% size_t RegisterSCTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000310%
311*/
cristybb503372010-05-27 20:51:26 +0000312ModuleExport size_t RegisterSCTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000313{
314 MagickInfo
315 *entry;
316
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);
325}
326
327/*
328%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329% %
330% %
331% %
332% U n r e g i s t e r S C T I m a g e %
333% %
334% %
335% %
336%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337%
338% UnregisterSCTImage() removes format registrations made by the
339% SCT module from the list of supported formats.
340%
341% The format of the UnregisterSCTImage method is:
342%
343% UnregisterSCTImage(void)
344%
345*/
346ModuleExport void UnregisterSCTImage(void)
347{
348 (void) UnregisterMagickInfo("SCT");
349}