blob: 46ed0610631b1bf9a8498c8273bb3fe7dda19685 [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"
53#include "magick/monitor.h"
54#include "magick/monitor-private.h"
55#include "magick/quantum-private.h"
56#include "magick/static.h"
57#include "magick/string_.h"
58#include "magick/module.h"
59
60/*
61%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62% %
63% %
64% %
65% I s S C T %
66% %
67% %
68% %
69%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70%
71% IsSCT() returns MagickTrue if the image format type, identified by the
72% magick string, is SCT.
73%
74% The format of the IsSCT method is:
75%
76% MagickBooleanType IsSCT(const unsigned char *magick,const size_t length)
77%
78% A description of each parameter follows:
79%
80% o magick: compare image format pattern against these bytes.
81%
82% o length: Specifies the length of the magick string.
83%
84*/
85static MagickBooleanType IsSCT(const unsigned char *magick,const size_t length)
86{
87 if (length < 2)
88 return(MagickFalse);
89 if (LocaleNCompare((const char *) magick,"CT",2) == 0)
90 return(MagickTrue);
91 return(MagickFalse);
92}
93
94/*
95%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96% %
97% %
98% %
99% R e a d S C T I m a g e %
100% %
101% %
102% %
103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104%
105% ReadSCTImage() reads a Scitex image file and returns it. It allocates
106% the memory necessary for the new Image structure and returns a pointer to
107% the new image.
108%
109% The format of the ReadSCTImage method is:
110%
111% Image *ReadSCTImage(const ImageInfo *image_info,ExceptionInfo *exception)
112%
113% A description of each parameter follows:
114%
115% o image_info: the image info.
116%
117% o exception: return any errors or warnings in this structure.
118%
119*/
120static Image *ReadSCTImage(const ImageInfo *image_info,ExceptionInfo *exception)
121{
122 char
123 magick[2];
124
125 Image
126 *image;
127
128 long
129 y;
130
131 MagickBooleanType
132 status;
133
134 MagickRealType
135 height,
136 width;
137
138 Quantum
139 pixel;
140
141 register IndexPacket
142 *indexes;
143
144 register long
145 i,
146 x;
147
148 register PixelPacket
149 *q;
150
151 ssize_t
152 count;
153
154 unsigned char
155 buffer[768];
156
157 unsigned long
158 separations,
159 separations_mask,
160 units;
161
162 /*
163 Open image file.
164 */
165 assert(image_info != (const ImageInfo *) NULL);
166 assert(image_info->signature == MagickSignature);
167 if (image_info->debug != MagickFalse)
168 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
169 image_info->filename);
170 assert(exception != (ExceptionInfo *) NULL);
171 assert(exception->signature == MagickSignature);
172 image=AcquireImage(image_info);
173 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
174 if (status == MagickFalse)
175 {
176 image=DestroyImageList(image);
177 return((Image *) NULL);
178 }
179 /*
180 Read control block.
181 */
182 count=ReadBlob(image,80,buffer);
183 count=ReadBlob(image,2,(unsigned char *) magick);
184 if ((LocaleNCompare((char *) magick,"CT",2) != 0) &&
185 (LocaleNCompare((char *) magick,"LW",2) != 0) &&
186 (LocaleNCompare((char *) magick,"BM",2) != 0) &&
187 (LocaleNCompare((char *) magick,"PG",2) != 0) &&
188 (LocaleNCompare((char *) magick,"TX",2) != 0))
189 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
190 if ((LocaleNCompare((char *) magick,"LW",2) == 0) ||
191 (LocaleNCompare((char *) magick,"BM",2) == 0) ||
192 (LocaleNCompare((char *) magick,"PG",2) == 0) ||
193 (LocaleNCompare((char *) magick,"TX",2) == 0))
194 ThrowReaderException(CoderError,"OnlyContinuousTonePictureSupported");
195 count=ReadBlob(image,174,buffer);
196 count=ReadBlob(image,768,buffer);
197 /*
198 Read paramter block.
199 */
200 units=1UL*ReadBlobByte(image);
201 if (units == 0)
202 image->units=PixelsPerCentimeterResolution;
203 separations=1UL*ReadBlobByte(image);
204 separations_mask=ReadBlobMSBShort(image);
205 count=ReadBlob(image,14,buffer);
206 buffer[14]='\0';
207 height=atof((char *) buffer);
208 count=ReadBlob(image,14,buffer);
209 width=atof((char *) buffer);
210 count=ReadBlob(image,12,buffer);
211 buffer[12]='\0';
212 image->rows=1UL*atol((char *) buffer);
213 count=ReadBlob(image,12,buffer);
214 image->columns=1UL*atol((char *) buffer);
215 count=ReadBlob(image,200,buffer);
216 count=ReadBlob(image,768,buffer);
217 if (separations_mask == 0x0f)
218 image->colorspace=CMYKColorspace;
219 image->x_resolution=1.0*image->columns/width;
220 image->y_resolution=1.0*image->rows/height;
221 if (image_info->ping != MagickFalse)
222 {
223 (void) CloseBlob(image);
224 return(GetFirstImageInList(image));
225 }
226 /*
227 Convert SCT raster image to pixel packets.
228 */
229 for (y=0; y < (long) image->rows; y++)
230 {
231 for (i=0; i < (long) separations; i++)
232 {
233 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
234 if (q == (PixelPacket *) NULL)
235 break;
236 indexes=GetAuthenticIndexQueue(image);
237 for (x=0; x < (long) image->columns; x++)
238 {
239 pixel=(Quantum) ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
240 if (image->colorspace == CMYKColorspace)
241 pixel=(Quantum) (QuantumRange-pixel);
242 switch (i)
243 {
244 case 0:
245 {
246 q->red=pixel;
247 q->green=pixel;
248 q->blue=pixel;
249 break;
250 }
251 case 1:
252 {
253 q->green=pixel;
254 break;
255 }
256 case 2:
257 {
258 q->blue=pixel; break;
259 break;
260 }
261 case 3:
262 {
263 if (image->colorspace == CMYKColorspace)
264 indexes[x]=(IndexPacket) pixel;
265 break;
266 }
267 }
268 q++;
269 }
270 if (SyncAuthenticPixels(image,exception) == MagickFalse)
271 break;
272 if ((image->columns % 2) != 0)
273 (void) ReadBlobByte(image); /* pad */
274 }
275 status=SetImageProgress(image,LoadImageTag,y,image->rows);
276 if (status == MagickFalse)
277 break;
278 }
279 if (EOFBlob(image) != MagickFalse)
280 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
281 image->filename);
282 (void) CloseBlob(image);
283 return(GetFirstImageInList(image));
284}
285
286/*
287%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
288% %
289% %
290% %
291% R e g i s t e r S C T I m a g e %
292% %
293% %
294% %
295%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296%
297% RegisterSCTImage() adds attributes for the SCT image format to
298% the list of supported formats. The attributes include the image format
299% tag, a method to read and/or write the format, whether the format
300% supports the saving of more than one frame to the same file or blob,
301% whether the format supports native in-memory I/O, and a brief
302% description of the format.
303%
304% The format of the RegisterSCTImage method is:
305%
306% unsigned long RegisterSCTImage(void)
307%
308*/
309ModuleExport unsigned long RegisterSCTImage(void)
310{
311 MagickInfo
312 *entry;
313
314 entry=SetMagickInfo("SCT");
315 entry->decoder=(DecodeImageHandler *) ReadSCTImage;
316 entry->magick=(IsImageFormatHandler *) IsSCT;
317 entry->adjoin=MagickFalse;
318 entry->description=ConstantString("Scitex HandShake");
319 entry->module=ConstantString("SCT");
320 (void) RegisterMagickInfo(entry);
321 return(MagickImageCoderSignature);
322}
323
324/*
325%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
326% %
327% %
328% %
329% U n r e g i s t e r S C T I m a g e %
330% %
331% %
332% %
333%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334%
335% UnregisterSCTImage() removes format registrations made by the
336% SCT module from the list of supported formats.
337%
338% The format of the UnregisterSCTImage method is:
339%
340% UnregisterSCTImage(void)
341%
342*/
343ModuleExport void UnregisterSCTImage(void)
344{
345 (void) UnregisterMagickInfo("SCT");
346}