root / ImageMagick / trunk / coders / sct.c

Revision 12035, 12.5 kB (checked in by cristy, 6 weeks ago)
Line 
1/*
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%                                                                             %
20%  Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization      %
21%  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/exception.h"
46#include "magick/exception-private.h"
47#include "magick/image.h"
48#include "magick/image-private.h"
49#include "magick/list.h"
50#include "magick/magick.h"
51#include "magick/memory_.h"
52#include "magick/monitor.h"
53#include "magick/monitor-private.h"
54#include "magick/quantum-private.h"
55#include "magick/static.h"
56#include "magick/string_.h"
57#include "magick/module.h"
58
59/*
60%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61%                                                                             %
62%                                                                             %
63%                                                                             %
64%   I s S C T                                                                 %
65%                                                                             %
66%                                                                             %
67%                                                                             %
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69%
70%  IsSCT() returns MagickTrue if the image format type, identified by the
71%  magick string, is SCT.
72%
73%  The format of the IsSCT method is:
74%
75%      MagickBooleanType IsSCT(const unsigned char *magick,const size_t length)
76%
77%  A description of each parameter follows:
78%
79%    o magick: This string is generally the first few bytes of an image file
80%      or blob.
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((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  if (SetImageExtent(image,0,0) == MagickFalse)
227    {
228      InheritException(exception,&image->exception);
229      return(DestroyImageList(image));
230    }
231  /*
232    Convert SCT raster image to pixel packets.
233  */
234  for (y=0; y < (long) image->rows; y++)
235  {
236    for (i=0; i < (long) separations; i++)
237    {
238      q=GetImagePixels(image,0,y,image->columns,1);
239      if (q == (PixelPacket *) NULL)
240        break;
241      indexes=GetIndexes(image);
242      for (x=0; x < (long) image->columns; x++)
243      {
244        pixel=(Quantum) ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
245        if (image->colorspace == CMYKColorspace)
246          pixel=(Quantum) (QuantumRange-pixel);
247        switch (i)
248        {
249          case 0:
250          {
251            q->red=pixel;
252            q->green=pixel;
253            q->blue=pixel;
254            break;
255          }
256          case 1:
257          {
258            q->green=pixel;
259            break;
260          }
261          case 2:
262          {
263            q->blue=pixel; break;
264            break;
265          }
266          case 3:
267          {
268            if (image->colorspace == CMYKColorspace)
269              indexes[x]=(IndexPacket) pixel;
270            break;
271          }
272        }
273        q++;
274      }
275      if (SyncImagePixels(image) == MagickFalse)
276        break;
277      if ((image->columns % 2) != 0)
278        (void) ReadBlobByte(image);  /* pad */
279    }
280    status=SetImageProgress(image,LoadImageTag,y,image->rows);
281    if (status == MagickFalse)
282      break;
283  }
284  if (EOFBlob(image) != MagickFalse)
285    ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
286      image->filename);
287  (void) CloseBlob(image);
288  return(GetFirstImageInList(image));
289}
290
291/*
292%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293%                                                                             %
294%                                                                             %
295%                                                                             %
296%   R e g i s t e r S C T I m a g e                                           %
297%                                                                             %
298%                                                                             %
299%                                                                             %
300%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301%
302%  RegisterSCTImage() adds attributes for the SCT image format to
303%  the list of supported formats.  The attributes include the image format
304%  tag, a method to read and/or write the format, whether the format
305%  supports the saving of more than one frame to the same file or blob,
306%  whether the format supports native in-memory I/O, and a brief
307%  description of the format.
308%
309%  The format of the RegisterSCTImage method is:
310%
311%      unsigned long RegisterSCTImage(void)
312%
313*/
314ModuleExport unsigned long RegisterSCTImage(void)
315{
316  MagickInfo
317    *entry;
318
319  entry=SetMagickInfo("SCT");
320  entry->decoder=(DecodeImageHandler *) ReadSCTImage;
321  entry->magick=(IsImageFormatHandler *) IsSCT;
322  entry->adjoin=MagickFalse;
323  entry->description=ConstantString("Scitex HandShake");
324  entry->module=ConstantString("SCT");
325  (void) RegisterMagickInfo(entry);
326  return(MagickImageCoderSignature);
327}
328
329/*
330%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331%                                                                             %
332%                                                                             %
333%                                                                             %
334%   U n r e g i s t e r S C T I m a g e                                       %
335%                                                                             %
336%                                                                             %
337%                                                                             %
338%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339%
340%  UnregisterSCTImage() removes format registrations made by the
341%  SCT module from the list of supported formats.
342%
343%  The format of the UnregisterSCTImage method is:
344%
345%      UnregisterSCTImage(void)
346%
347*/
348ModuleExport void UnregisterSCTImage(void)
349{
350  (void) UnregisterMagickInfo("SCT");
351}
Note: See TracBrowser for help on using the browser.