blob: 2b7f0f651b7b836c11dfd167f7cb0e23bf3b79c4 [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% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 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);
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);
198 /*
199 Read paramter block.
200 */
201 units=1UL*ReadBlobByte(image);
202 if (units == 0)
203 image->units=PixelsPerCentimeterResolution;
204 separations=1UL*ReadBlobByte(image);
205 separations_mask=ReadBlobMSBShort(image);
206 count=ReadBlob(image,14,buffer);
207 buffer[14]='\0';
cristyf2f27272009-12-17 14:48:46 +0000208 height=StringToDouble((char *) buffer);
cristy3ed852e2009-09-05 21:47:34 +0000209 count=ReadBlob(image,14,buffer);
cristyf2f27272009-12-17 14:48:46 +0000210 width=StringToDouble((char *) buffer);
cristy3ed852e2009-09-05 21:47:34 +0000211 count=ReadBlob(image,12,buffer);
212 buffer[12]='\0';
cristy5131f3e2009-12-18 03:09:10 +0000213 image->rows=StringToUnsignedLong((char *) buffer);
cristy3ed852e2009-09-05 21:47:34 +0000214 count=ReadBlob(image,12,buffer);
cristy5131f3e2009-12-18 03:09:10 +0000215 image->columns=StringToUnsignedLong((char *) buffer);
cristy3ed852e2009-09-05 21:47:34 +0000216 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)
223 {
224 (void) CloseBlob(image);
225 return(GetFirstImageInList(image));
226 }
227 /*
228 Convert SCT raster image to pixel packets.
229 */
cristybb503372010-05-27 20:51:26 +0000230 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000231 {
cristybb503372010-05-27 20:51:26 +0000232 for (i=0; i < (ssize_t) separations; i++)
cristy3ed852e2009-09-05 21:47:34 +0000233 {
234 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
235 if (q == (PixelPacket *) NULL)
236 break;
237 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +0000238 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000239 {
240 pixel=(Quantum) ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
241 if (image->colorspace == CMYKColorspace)
242 pixel=(Quantum) (QuantumRange-pixel);
243 switch (i)
244 {
245 case 0:
246 {
247 q->red=pixel;
248 q->green=pixel;
249 q->blue=pixel;
250 break;
251 }
252 case 1:
253 {
254 q->green=pixel;
255 break;
256 }
257 case 2:
258 {
259 q->blue=pixel; break;
260 break;
261 }
262 case 3:
263 {
264 if (image->colorspace == CMYKColorspace)
265 indexes[x]=(IndexPacket) pixel;
266 break;
267 }
268 }
269 q++;
270 }
271 if (SyncAuthenticPixels(image,exception) == MagickFalse)
272 break;
273 if ((image->columns % 2) != 0)
274 (void) ReadBlobByte(image); /* pad */
275 }
cristycee97112010-05-28 00:44:52 +0000276 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
277 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000278 if (status == MagickFalse)
279 break;
280 }
281 if (EOFBlob(image) != MagickFalse)
282 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
283 image->filename);
284 (void) CloseBlob(image);
285 return(GetFirstImageInList(image));
286}
287
288/*
289%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290% %
291% %
292% %
293% R e g i s t e r S C T I m a g e %
294% %
295% %
296% %
297%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298%
299% RegisterSCTImage() adds attributes for the SCT image format to
300% the list of supported formats. The attributes include the image format
301% tag, a method to read and/or write the format, whether the format
302% supports the saving of more than one frame to the same file or blob,
303% whether the format supports native in-memory I/O, and a brief
304% description of the format.
305%
306% The format of the RegisterSCTImage method is:
307%
cristybb503372010-05-27 20:51:26 +0000308% size_t RegisterSCTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000309%
310*/
cristybb503372010-05-27 20:51:26 +0000311ModuleExport size_t RegisterSCTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000312{
313 MagickInfo
314 *entry;
315
316 entry=SetMagickInfo("SCT");
317 entry->decoder=(DecodeImageHandler *) ReadSCTImage;
318 entry->magick=(IsImageFormatHandler *) IsSCT;
319 entry->adjoin=MagickFalse;
320 entry->description=ConstantString("Scitex HandShake");
321 entry->module=ConstantString("SCT");
322 (void) RegisterMagickInfo(entry);
323 return(MagickImageCoderSignature);
324}
325
326/*
327%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328% %
329% %
330% %
331% U n r e g i s t e r S C T I m a g e %
332% %
333% %
334% %
335%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336%
337% UnregisterSCTImage() removes format registrations made by the
338% SCT module from the list of supported formats.
339%
340% The format of the UnregisterSCTImage method is:
341%
342% UnregisterSCTImage(void)
343%
344*/
345ModuleExport void UnregisterSCTImage(void)
346{
347 (void) UnregisterMagickInfo("SCT");
348}