| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 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 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | static 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 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | static 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 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | ModuleExport 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 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | ModuleExport void UnregisterPWPImage(void) |
|---|
| 319 | { |
|---|
| 320 | (void) UnregisterMagickInfo("PWP"); |
|---|
| 321 | } |
|---|