root / ImageMagick / trunk / coders / pwp.c

Revision 11742, 12.0 kB (checked in by cristy, 3 weeks ago)
Line 
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3%                                                                             %
4%                                                                             %
5%                                                                             %
6%                            PPPP   W   W  PPPP                               %
7%                            P   P  W   W  P   P                              %
8%                            PPPP   W   W  PPPP                               %
9%                            P      W W W  P                                  %
10%                            P       W W   P                                  %
11%                                                                             %
12%                                                                             %
13%                    Read Seattle Film Works 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/constitute.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/resource_.h"
56#include "magick/quantum-private.h"
57#include "magick/static.h"
58#include "magick/string_.h"
59#include "magick/module.h"
60
61/*
62%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63%                                                                             %
64%                                                                             %
65%                                                                             %
66%   I s P W P                                                                 %
67%                                                                             %
68%                                                                             %
69%                                                                             %
70%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71%
72%  IsPWP() returns MagickTrue if the image format type, identified by the
73%  magick string, is PWP.
74%
75%  The format of the IsPWP method is:
76%
77%      MagickBooleanType IsPWP(const unsigned char *magick,const size_t length)
78%
79%  A description of each parameter follows:
80%
81%    o magick: This string is generally the first few bytes of an image file
82%      or blob.
83%
84%    o length: Specifies the length of the magick string.
85%
86%
87*/
88static MagickBooleanType IsPWP(const unsigned char *magick,const size_t length)
89{
90  if (length < 5)
91    return(MagickFalse);
92  if (LocaleNCompare((char *) magick,"SFW95",5) == 0)
93    return(MagickTrue);
94  return(MagickFalse);
95}
96
97/*
98%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99%                                                                             %
100%                                                                             %
101%                                                                             %
102%   R e a d P W P I m a g e                                                   %
103%                                                                             %
104%                                                                             %
105%                                                                             %
106%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107%
108%  ReadPWPImage() reads a Seattle Film Works multi-image file and returns
109%  it.  It allocates the memory necessary for the new Image structure and
110%  returns a pointer to the new image.
111%
112%  The format of the ReadPWPImage method is:
113%
114%      Image *ReadPWPImage(const ImageInfo *image_info,ExceptionInfo *exception)
115%
116%  A description of each parameter follows:
117%
118%    o image_info: the image info.
119%
120%    o exception: return any errors or warnings in this structure.
121%
122*/
123static Image *ReadPWPImage(const ImageInfo *image_info,ExceptionInfo *exception)
124{
125  FILE
126    *file;
127
128  Image
129    *image,
130    *next_image,
131    *pwp_image;
132
133  ImageInfo
134    *read_info;
135
136  int
137    c,
138    unique_file;
139
140  MagickBooleanType
141    status;
142
143  register Image
144    *p;
145
146  register long
147    i;
148
149  ssize_t
150    count;
151
152  unsigned char
153    magick[MaxTextExtent];
154
155  unsigned long
156    filesize;
157
158  /*
159    Open image file.
160  */
161  assert(image_info != (const ImageInfo *) NULL);
162  assert(image_info->signature == MagickSignature);
163  if (image_info->debug != MagickFalse)
164    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
165      image_info->filename);
166  assert(exception != (ExceptionInfo *) NULL);
167  assert(exception->signature == MagickSignature);
168  pwp_image=AcquireImage(image_info);
169  image=pwp_image;
170  status=OpenBlob(image_info,pwp_image,ReadBinaryBlobMode,exception);
171  if (status == MagickFalse)
172    return((Image *) NULL);
173  count=ReadBlob(pwp_image,5,magick);
174  if ((count == 0) || (LocaleNCompare((char *) magick,"SFW95",5) != 0))
175    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
176  read_info=CloneImageInfo(image_info);
177  (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
178    (void *) NULL);
179  SetImageInfoBlob(read_info,(void *) NULL,0);
180  unique_file=AcquireUniqueFileResource(read_info->filename);
181  for ( ; ; )
182  {
183    for (c=ReadBlobByte(pwp_image); c != EOF; c=ReadBlobByte(pwp_image))
184    {
185      for (i=0; i < 17; i++)
186        magick[i]=magick[i+1];
187      magick[17]=(unsigned char) c;
188      if (LocaleNCompare((char *) (magick+12),"SFW94A",6) == 0)
189        break;
190    }
191    if (c == EOF)
192      break;
193    if (LocaleNCompare((char *) (magick+12),"SFW94A",6) != 0)
194      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
195    /*
196      Dump SFW image to a temporary file.
197    */
198    file=(FILE *) NULL;
199    if (unique_file != -1)
200      file=fdopen(unique_file,"wb");
201    if ((unique_file == -1) || (file == (FILE *) NULL))
202      {
203        ThrowFileException(exception,FileOpenError,"UnableToWriteFile",
204          image->filename);
205        image=DestroyImageList(image);
206        return((Image *) NULL);
207      }
208    (void) fwrite("SFW94A",1,6,file);
209    filesize=65535UL*magick[2]+256L*magick[1]+magick[0];
210    for (i=0; i < (long) filesize; i++)
211    {
212      c=ReadBlobByte(pwp_image);
213      (void) fputc(c,file);
214    }
215    (void) fclose(file);
216    next_image=ReadImage(read_info,exception);
217    if (next_image == (Image *) NULL)
218      break;
219    (void) FormatMagickString(next_image->filename,MaxTextExtent,
220      "slide_%02ld.sfw",next_image->scene);
221    if (image == (Image *) NULL)
222      image=next_image;
223    else
224      {
225        /*
226          Link image into image list.
227        */
228        for (p=image; p->next != (Image *) NULL; p=GetNextImageInList(p)) ;
229        next_image->previous=p;
230        next_image->scene=p->scene+1;
231        p->next=next_image;
232      }
233    if (image_info->number_scenes != 0)
234      if (next_image->scene >= (image_info->scene+image_info->number_scenes-1))
235        break;
236    if (image->progress_monitor != (MagickProgressMonitor) NULL)
237      {
238        status=image->progress_monitor(LoadImagesTag,TellBlob(pwp_image),
239          GetBlobSize(image),image->client_data);
240        if (status == MagickFalse)
241          break;
242      }
243  }
244  (void) RelinquishUniqueFileResource(read_info->filename);
245  read_info=DestroyImageInfo(read_info);
246  (void) CloseBlob(pwp_image);
247  pwp_image=DestroyImage(pwp_image);
248  if (EOFBlob(image) != MagickFalse)
249    {
250      char
251        *message;
252
253      message=GetExceptionMessage(errno);
254      (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
255        "UnexpectedEndOfFile","`%s': %s",image->filename,message);
256      message=DestroyString(message);
257    }
258  (void) CloseBlob(image);
259  return(GetFirstImageInList(image));
260}
261
262/*
263%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264%                                                                             %
265%                                                                             %
266%                                                                             %
267%   R e g i s t e r P W P I m a g e                                           %
268%                                                                             %
269%                                                                             %
270%                                                                             %
271%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272%
273%  RegisterPWPImage() adds attributes for the PWP image format to
274%  the list of supported formats.  The attributes include the image format
275%  tag, a method to read and/or write the format, whether the format
276%  supports the saving of more than one frame to the same file or blob,
277%  whether the format supports native in-memory I/O, and a brief
278%  description of the format.
279%
280%  The format of the RegisterPWPImage method is:
281%
282%      unsigned long RegisterPWPImage(void)
283%
284*/
285ModuleExport unsigned long RegisterPWPImage(void)
286{
287  MagickInfo
288    *entry;
289
290  entry=SetMagickInfo("PWP");
291  entry->decoder=(DecodeImageHandler *) ReadPWPImage;
292  entry->magick=(IsImageFormatHandler *) IsPWP;
293  entry->description=ConstantString("Seattle Film Works");
294  entry->module=ConstantString("PWP");
295  (void) RegisterMagickInfo(entry);
296  return(MagickImageCoderSignature);
297}
298
299/*
300%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301%                                                                             %
302%                                                                             %
303%                                                                             %
304%   U n r e g i s t e r P W P I m a g e                                       %
305%                                                                             %
306%                                                                             %
307%                                                                             %
308%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309%
310%  UnregisterPWPImage() removes format registrations made by the
311%  PWP module from the list of supported formats.
312%
313%  The format of the UnregisterPWPImage method is:
314%
315%      UnregisterPWPImage(void)
316%
317*/
318ModuleExport void UnregisterPWPImage(void)
319{
320  (void) UnregisterMagickInfo("PWP");
321}
Note: See TracBrowser for help on using the browser.