/src/graphicsmagick/coders/pwp.c
Line | Count | Source |
1 | | /* |
2 | | % Copyright (C) 2003-2020 GraphicsMagick Group |
3 | | % Copyright (C) 2002 ImageMagick Studio |
4 | | % Copyright 1991-1999 E. I. du Pont de Nemours and Company |
5 | | % |
6 | | % This program is covered by multiple licenses, which are described in |
7 | | % Copyright.txt. You should have received a copy of Copyright.txt with this |
8 | | % package; otherwise see http://www.graphicsmagick.org/www/Copyright.html. |
9 | | % |
10 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
11 | | % % |
12 | | % % |
13 | | % % |
14 | | % PPPP W W PPPP % |
15 | | % P P W W P P % |
16 | | % PPPP W W PPPP % |
17 | | % P W W W P % |
18 | | % P W W P % |
19 | | % % |
20 | | % % |
21 | | % Read Seattle Film Works Image Format. % |
22 | | % % |
23 | | % % |
24 | | % Software Design % |
25 | | % John Cristy % |
26 | | % July 1992 % |
27 | | % % |
28 | | % % |
29 | | % % |
30 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
31 | | % |
32 | | % |
33 | | */ |
34 | | |
35 | | /* |
36 | | Include declarations. |
37 | | */ |
38 | | #include "magick/studio.h" |
39 | | #include "magick/blob.h" |
40 | | #include "magick/constitute.h" |
41 | | #include "magick/magick.h" |
42 | | #include "magick/monitor.h" |
43 | | #include "magick/tempfile.h" |
44 | | #include "magick/utility.h" |
45 | | |
46 | | /* |
47 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
48 | | % % |
49 | | % % |
50 | | % % |
51 | | % I s P W P % |
52 | | % % |
53 | | % % |
54 | | % % |
55 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
56 | | % |
57 | | % Method IsPWP returns True if the image format type, identified by the |
58 | | % magick string, is PWP. |
59 | | % |
60 | | % The format of the IsPWP method is: |
61 | | % |
62 | | % unsigned int IsPWP(const unsigned char *magick,const size_t length) |
63 | | % |
64 | | % A description of each parameter follows: |
65 | | % |
66 | | % o status: Method IsPWP returns True if the image format type is PWP. |
67 | | % |
68 | | % o magick: This string is generally the first few bytes of an image file |
69 | | % or blob. |
70 | | % |
71 | | % o length: Specifies the length of the magick string. |
72 | | % |
73 | | % |
74 | | */ |
75 | | static unsigned int IsPWP(const unsigned char *magick,const size_t length) |
76 | 0 | { |
77 | 0 | if (length < 5) |
78 | 0 | return(False); |
79 | 0 | if (LocaleNCompare((char *) magick,"SFW95",5) == 0) |
80 | 0 | return(True); |
81 | 0 | return(False); |
82 | 0 | } |
83 | | |
84 | | /* |
85 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
86 | | % % |
87 | | % % |
88 | | % % |
89 | | % R e a d P W P I m a g e % |
90 | | % % |
91 | | % % |
92 | | % % |
93 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
94 | | % |
95 | | % Method ReadPWPImage reads a Seattle Film Works multi-image file and returns |
96 | | % it. It allocates the memory necessary for the new Image structure and |
97 | | % returns a pointer to the new image. |
98 | | % |
99 | | % The format of the ReadPWPImage method is: |
100 | | % |
101 | | % Image *ReadPWPImage(const ImageInfo *image_info,ExceptionInfo *exception) |
102 | | % |
103 | | % A description of each parameter follows: |
104 | | % |
105 | | % o image: Method ReadPWPImage returns a pointer to the image after |
106 | | % reading. A null image is returned if there is a memory shortage or |
107 | | % if the image cannot be read. |
108 | | % |
109 | | % o image_info: Specifies a pointer to a ImageInfo structure. |
110 | | % |
111 | | % o exception: return any errors or warnings in this structure. |
112 | | % |
113 | | % |
114 | | */ |
115 | | static Image *ReadPWPImage(const ImageInfo *image_info,ExceptionInfo *exception) |
116 | 11.1k | { |
117 | 11.1k | FILE |
118 | 11.1k | *file; |
119 | | |
120 | 11.1k | Image |
121 | 11.1k | *image, |
122 | 11.1k | *next_image, |
123 | 11.1k | *pwp_image; |
124 | | |
125 | 11.1k | ImageInfo |
126 | 11.1k | *clone_info; |
127 | | |
128 | 11.1k | int |
129 | 11.1k | c; |
130 | | |
131 | 11.1k | MonitorHandler |
132 | 11.1k | handler; |
133 | | |
134 | 11.1k | register Image |
135 | 11.1k | *p; |
136 | | |
137 | 11.1k | register unsigned long |
138 | 11.1k | i; |
139 | | |
140 | 11.1k | size_t |
141 | 11.1k | count; |
142 | | |
143 | 11.1k | unsigned char |
144 | 11.1k | magick[MaxTextExtent]; |
145 | | |
146 | 11.1k | unsigned int |
147 | 11.1k | status; |
148 | | |
149 | 11.1k | unsigned long |
150 | 11.1k | filesize; |
151 | | |
152 | | /* |
153 | | Open image file. |
154 | | */ |
155 | 11.1k | assert(image_info != (const ImageInfo *) NULL); |
156 | 11.1k | assert(image_info->signature == MagickSignature); |
157 | 11.1k | assert(exception != (ExceptionInfo *) NULL); |
158 | 11.1k | assert(exception->signature == MagickSignature); |
159 | 11.1k | image=(Image *) NULL; |
160 | 11.1k | pwp_image=AllocateImage(image_info); |
161 | 11.1k | status=OpenBlob(image_info,pwp_image,ReadBinaryBlobMode,exception); |
162 | 11.1k | if (status == False) |
163 | 11.1k | ThrowReaderException(FileOpenError,UnableToOpenFile,pwp_image); |
164 | 11.1k | count=ReadBlob(pwp_image,5,(char *) magick); |
165 | 11.1k | if ((count != 5) || (LocaleNCompare((char *) magick,"SFW95",5) != 0)) |
166 | 11.1k | ThrowReaderException(CorruptImageError,ImproperImageHeader,pwp_image); |
167 | 11.1k | clone_info=CloneImageInfo(image_info); |
168 | 11.1k | clone_info->blob=(void *) NULL; |
169 | 11.1k | clone_info->length=0; |
170 | 11.1k | for ( ; ; ) |
171 | 11.1k | { |
172 | 11.1k | (void) memset(magick,0,sizeof(magick)); |
173 | 1.85M | for (c=ReadBlobByte(pwp_image); c != EOF; c=ReadBlobByte(pwp_image)) |
174 | 1.84M | { |
175 | 33.2M | for (i=0; i < 17; i++) |
176 | 31.4M | magick[i]=magick[i+1]; |
177 | 1.84M | magick[17]=(unsigned char) c; |
178 | 1.84M | if (LocaleNCompare((char *) (magick+12),"SFW94A",6) == 0) |
179 | 8.89k | break; |
180 | 1.84M | } |
181 | 11.1k | if (c == EOF) |
182 | 2.26k | { |
183 | 2.26k | ThrowException(exception,CorruptImageError,UnexpectedEndOfFile, |
184 | 2.26k | clone_info->filename); |
185 | 2.26k | break; |
186 | 2.26k | } |
187 | 8.89k | if (LocaleNCompare((char *) (magick+12),"SFW94A",6) != 0) |
188 | 0 | { |
189 | 0 | ThrowException(exception,CorruptImageError,ImproperImageHeader, |
190 | 0 | clone_info->filename); |
191 | 0 | break; |
192 | 0 | } |
193 | | /* |
194 | | Dump SFW image to a temporary file. |
195 | | */ |
196 | 8.89k | { |
197 | 8.89k | char tmpfile[MaxTextExtent]; |
198 | 8.89k | file=AcquireTemporaryFileStream(tmpfile,BinaryFileIOMode); |
199 | 8.89k | if (file == (FILE *) NULL) |
200 | 0 | { |
201 | 0 | ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile, |
202 | 0 | clone_info->filename); |
203 | 0 | break; |
204 | 0 | } |
205 | 8.89k | (void) strlcpy(clone_info->filename,"SFW:",sizeof(clone_info->filename)); |
206 | 8.89k | (void) strlcat(clone_info->filename,tmpfile,sizeof(clone_info->filename)); |
207 | 8.89k | } |
208 | 0 | (void) fwrite("SFW94A",1,6,file); |
209 | 8.89k | filesize=(65535L*magick[2]+256L*magick[1]+magick[0]) & 0xFFFFFFFF; |
210 | 21.8M | for (i=0; i < filesize; i++) |
211 | 21.8M | { |
212 | 21.8M | if ((c=ReadBlobByte(pwp_image)) == EOF) |
213 | 177 | break; |
214 | 21.8M | (void) fputc(c,file); |
215 | 21.8M | } |
216 | 8.89k | (void) fclose(file); |
217 | 8.89k | if (c == EOF) |
218 | 177 | { |
219 | 177 | ThrowException(exception,CorruptImageError,UnexpectedEndOfFile, |
220 | 177 | clone_info->filename); |
221 | 177 | break; |
222 | 177 | } |
223 | 8.71k | handler=SetMonitorHandler((MonitorHandler) NULL); |
224 | 8.71k | next_image=ReadImage(clone_info,exception); |
225 | 8.71k | (void) LiberateTemporaryFile(clone_info->filename); |
226 | 8.71k | (void) SetMonitorHandler(handler); |
227 | 8.71k | if (next_image == (Image *) NULL) |
228 | 7.58k | break; |
229 | 1.12k | StopTimer(&next_image->timer); |
230 | 1.12k | FormatString(next_image->filename,"slide_%02ld.sfw",next_image->scene); |
231 | 1.12k | if (image == (Image *) NULL) |
232 | 1.12k | image=next_image; |
233 | 0 | else |
234 | 0 | { |
235 | | /* |
236 | | Link image into image list. |
237 | | */ |
238 | 0 | for (p=image; p->next != (Image *) NULL; p=p->next); |
239 | 0 | next_image->previous=p; |
240 | 0 | next_image->scene=p->scene+1; |
241 | 0 | p->next=next_image; |
242 | 0 | } |
243 | 1.12k | if (image_info->subrange != 0) |
244 | 1.12k | if (next_image->scene >= (image_info->subimage+image_info->subrange-1)) |
245 | 1.12k | break; |
246 | 0 | if (!MagickMonitorFormatted(TellBlob(pwp_image),GetBlobSize(image), |
247 | 0 | &image->exception,LoadImagesText, |
248 | 0 | image->filename)) |
249 | 0 | break; |
250 | 0 | } |
251 | 11.1k | DestroyImageInfo(clone_info); |
252 | 11.1k | CloseBlob(pwp_image); |
253 | 11.1k | DestroyImage(pwp_image); |
254 | 11.1k | return(image); |
255 | 11.1k | } |
256 | | |
257 | | /* |
258 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
259 | | % % |
260 | | % % |
261 | | % % |
262 | | % R e g i s t e r P W P I m a g e % |
263 | | % % |
264 | | % % |
265 | | % % |
266 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
267 | | % |
268 | | % Method RegisterPWPImage adds attributes for the PWP image format to |
269 | | % the list of supported formats. The attributes include the image format |
270 | | % tag, a method to read and/or write the format, whether the format |
271 | | % supports the saving of more than one frame to the same file or blob, |
272 | | % whether the format supports native in-memory I/O, and a brief |
273 | | % description of the format. |
274 | | % |
275 | | % The format of the RegisterPWPImage method is: |
276 | | % |
277 | | % RegisterPWPImage(void) |
278 | | % |
279 | | */ |
280 | | ModuleExport void RegisterPWPImage(void) |
281 | 4 | { |
282 | 4 | MagickInfo |
283 | 4 | *entry; |
284 | | |
285 | 4 | entry=SetMagickInfo("PWP"); |
286 | 4 | entry->decoder=(DecoderHandler) ReadPWPImage; |
287 | 4 | entry->magick=(MagickHandler) IsPWP; |
288 | 4 | entry->description="Seattle Film Works"; |
289 | 4 | entry->module="PWP"; |
290 | 4 | entry->coder_class=UnstableCoderClass; |
291 | 4 | (void) RegisterMagickInfo(entry); |
292 | 4 | } |
293 | | |
294 | | /* |
295 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
296 | | % % |
297 | | % % |
298 | | % % |
299 | | % U n r e g i s t e r P W P I m a g e % |
300 | | % % |
301 | | % % |
302 | | % % |
303 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
304 | | % |
305 | | % Method UnregisterPWPImage removes format registrations made by the |
306 | | % PWP module from the list of supported formats. |
307 | | % |
308 | | % The format of the UnregisterPWPImage method is: |
309 | | % |
310 | | % UnregisterPWPImage(void) |
311 | | % |
312 | | */ |
313 | | ModuleExport void UnregisterPWPImage(void) |
314 | 0 | { |
315 | 0 | (void) UnregisterMagickInfo("PWP"); |
316 | 0 | } |