PageRenderTime 23ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/coders/pwp.c

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