2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read Seattle Film Works Image Format %
20 % Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % https://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/constitute.h"
46 #include "MagickCore/exception.h"
47 #include "MagickCore/exception-private.h"
48 #include "MagickCore/image.h"
49 #include "MagickCore/image-private.h"
50 #include "MagickCore/list.h"
51 #include "MagickCore/magick.h"
52 #include "MagickCore/memory_.h"
53 #include "MagickCore/monitor.h"
54 #include "MagickCore/monitor-private.h"
55 #include "MagickCore/resource_.h"
56 #include "MagickCore/quantum-private.h"
57 #include "MagickCore/static.h"
58 #include "MagickCore/string_.h"
59 #include "MagickCore/module.h"
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 % IsPWP() returns MagickTrue if the image format type, identified by the
73 % magick string, is PWP.
75 % The format of the IsPWP method is:
77 % MagickBooleanType IsPWP(const unsigned char *magick,const size_t length)
79 % A description of each parameter follows:
81 % o magick: compare image format pattern against these bytes.
83 % o length: Specifies the length of the magick string.
87 static MagickBooleanType IsPWP(const unsigned char *magick,const size_t length)
91 if (LocaleNCompare((char *) magick,"SFW95",5) == 0)
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 % R e a d P W P I m a g e %
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 % ReadPWPImage() reads a Seattle Film Works multi-image file and returns
108 % it. It allocates the memory necessary for the new Image structure and
109 % returns a pointer to the new image.
111 % The format of the ReadPWPImage method is:
113 % Image *ReadPWPImage(const ImageInfo *image_info,ExceptionInfo *exception)
115 % A description of each parameter follows:
117 % o image_info: the image info.
119 % o exception: return any errors or warnings in this structure.
122 static Image *ReadPWPImage(const ImageInfo *image_info,ExceptionInfo *exception)
156 magick[MagickPathExtent];
161 assert(image_info != (const ImageInfo *) NULL);
162 assert(image_info->signature == MagickCoreSignature);
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 == MagickCoreSignature);
168 pwp_image=AcquireImage(image_info,exception);
170 status=OpenBlob(image_info,pwp_image,ReadBinaryBlobMode,exception);
171 if (status == MagickFalse)
172 return((Image *) NULL);
173 ResetMagickMemory(magick,0,sizeof(magick));
174 count=ReadBlob(pwp_image,5,magick);
175 if ((count != 5) || (LocaleNCompare((char *) magick,"SFW95",5) != 0))
176 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
177 read_info=CloneImageInfo(image_info);
178 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
180 SetImageInfoBlob(read_info,(void *) NULL,0);
181 unique_file=AcquireUniqueFileResource(read_info->filename);
184 (void) memset(magick,0,sizeof(magick));
185 for (c=ReadBlobByte(pwp_image); c != EOF; c=ReadBlobByte(pwp_image))
187 for (i=0; i < 17; i++)
188 magick[i]=magick[i+1];
189 magick[17]=(unsigned char) c;
190 if (LocaleNCompare((char *) (magick+12),"SFW94A",6) == 0)
195 (void) RelinquishUniqueFileResource(read_info->filename);
196 ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
198 if (LocaleNCompare((char *) (magick+12),"SFW94A",6) != 0)
200 (void) RelinquishUniqueFileResource(read_info->filename);
201 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
204 Dump SFW image to a temporary file.
207 if (unique_file != -1)
208 file=fdopen(unique_file,"wb");
209 if ((unique_file == -1) || (file == (FILE *) NULL))
211 (void) RelinquishUniqueFileResource(read_info->filename);
212 ThrowFileException(exception,FileOpenError,"UnableToWriteFile",
214 image=DestroyImageList(image);
215 return((Image *) NULL);
217 length=fwrite("SFW94A",1,6,file);
219 filesize=65535UL*magick[2]+256L*magick[1]+magick[0];
220 for (i=0; i < (ssize_t) filesize; i++)
222 c=ReadBlobByte(pwp_image);
225 (void) fputc(c,file);
230 (void) RelinquishUniqueFileResource(read_info->filename);
231 ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
233 next_image=ReadImage(read_info,exception);
234 if (next_image == (Image *) NULL)
236 (void) FormatLocaleString(next_image->filename,MagickPathExtent,
237 "slide_%02ld.sfw",(long) next_image->scene);
238 if (image == (Image *) NULL)
243 Link image into image list.
245 for (p=image; p->next != (Image *) NULL; p=GetNextImageInList(p)) ;
246 next_image->previous=p;
247 next_image->scene=p->scene+1;
250 if (image_info->number_scenes != 0)
251 if (next_image->scene >= (image_info->scene+image_info->number_scenes-1))
253 status=SetImageProgress(image,LoadImagesTag,TellBlob(pwp_image),
254 GetBlobSize(pwp_image));
255 if (status == MagickFalse)
258 if (unique_file != -1)
259 (void) close(unique_file);
260 (void) RelinquishUniqueFileResource(read_info->filename);
261 read_info=DestroyImageInfo(read_info);
262 if (image != (Image *) NULL)
264 if (EOFBlob(image) != MagickFalse)
269 message=GetExceptionMessage(errno);
270 (void) ThrowMagickException(exception,GetMagickModule(),
271 CorruptImageError,"UnexpectedEndOfFile","`%s': %s",image->filename,
273 message=DestroyString(message);
275 (void) CloseBlob(image);
277 return(GetFirstImageInList(image));
281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 % R e g i s t e r P W P I m a g e %
289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
291 % RegisterPWPImage() adds attributes for the PWP image format to
292 % the list of supported formats. The attributes include the image format
293 % tag, a method to read and/or write the format, whether the format
294 % supports the saving of more than one frame to the same file or blob,
295 % whether the format supports native in-memory I/O, and a brief
296 % description of the format.
298 % The format of the RegisterPWPImage method is:
300 % size_t RegisterPWPImage(void)
303 ModuleExport size_t RegisterPWPImage(void)
308 entry=AcquireMagickInfo("PWP","PWP","Seattle Film Works");
309 entry->decoder=(DecodeImageHandler *) ReadPWPImage;
310 entry->magick=(IsImageFormatHandler *) IsPWP;
311 (void) RegisterMagickInfo(entry);
312 return(MagickImageCoderSignature);
316 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
320 % U n r e g i s t e r P W P I m a g e %
324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
326 % UnregisterPWPImage() removes format registrations made by the
327 % PWP module from the list of supported formats.
329 % The format of the UnregisterPWPImage method is:
331 % UnregisterPWPImage(void)
334 ModuleExport void UnregisterPWPImage(void)
336 (void) UnregisterMagickInfo("PWP");