blob: 2e615cfa7057481827027a0d4f1d7fff653d9e98 [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
129 long
130 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
145 register long
146 i,
147 x;
148
149 register PixelPacket
150 *q;
151
152 ssize_t
153 count;
154
155 unsigned char
156 buffer[768];
157
158 unsigned long
159 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';
cristyf2f27272009-12-17 14:48:46 +0000213 image->rows=1UL*StringToLong((char *) buffer);
cristy3ed852e2009-09-05 21:47:34 +0000214 count=ReadBlob(image,12,buffer);
cristyf2f27272009-12-17 14:48:46 +0000215 image->columns=1UL*StringToLong((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 */
230 for (y=0; y < (long) image->rows; y++)
231 {
232 for (i=0; i < (long) separations; i++)
233 {
234 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
235 if (q == (PixelPacket *) NULL)
236 break;
237 indexes=GetAuthenticIndexQueue(image);
238 for (x=0; x < (long) image->columns; x++)
239 {
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 }
276 status=SetImageProgress(image,LoadImageTag,y,image->rows);
277 if (status == MagickFalse)
278 break;
279 }
280 if (EOFBlob(image) != MagickFalse)
281 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
282 image->filename);
283 (void) CloseBlob(image);
284 return(GetFirstImageInList(image));
285}
286
287/*
288%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289% %
290% %
291% %
292% R e g i s t e r S C T I m a g e %
293% %
294% %
295% %
296%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297%
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.
304%
305% The format of the RegisterSCTImage method is:
306%
307% unsigned long RegisterSCTImage(void)
308%
309*/
310ModuleExport unsigned long RegisterSCTImage(void)
311{
312 MagickInfo
313 *entry;
314
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);
323}
324
325/*
326%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
327% %
328% %
329% %
330% U n r e g i s t e r S C T I m a g e %
331% %
332% %
333% %
334%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335%
336% UnregisterSCTImage() removes format registrations made by the
337% SCT module from the list of supported formats.
338%
339% The format of the UnregisterSCTImage method is:
340%
341% UnregisterSCTImage(void)
342%
343*/
344ModuleExport void UnregisterSCTImage(void)
345{
346 (void) UnregisterMagickInfo("SCT");
347}