1 /*
2  * in_png.cpp -- read PNG (Portable Network Graphics, PNG is Not GIF) files with pngtopnm
3  * by pts@fazekas.hu at Sun Apr 14 14:50:30 CEST 2002
4  */
5 
6 #ifdef __GNUC__
7 #ifndef __clang__
8 #pragma implementation
9 #endif
10 #endif
11 
12 #include "image.hpp"
13 
14 #if USE_IN_PNG
15 
16 #include "error.hpp"
17 #include "gensio.hpp"
18 #include "helpere.hpp"
19 #include <string.h> /* memchr() */
20 #include <stdio.h> /* printf() */
21 
in_png_reader(Image::Loader::UFD * ufd,SimBuffer::Flat const &)22 static Image::Sampled *in_png_reader(Image::Loader::UFD* ufd, SimBuffer::Flat const&) {
23   // Error::sev(Error::EERROR) << "Cannot load PNG images yet." << (Error*)0;
24   char const* cmd=
25 #if 0
26   #if OS_COTY==COTY_WIN9X || OS_COTY==COTY_WINNT
27     "pngtopnm %S >%D\npngtopnm -alpha %S >>%D";
28   #else
29     #if OS_COTY==COTY_UNIX
30       "(pngtopnm <%S && pngtopnm -alpha <%S) >%D";
31     #else
32       "pngtopnm %S >%D\npngtopnm -alpha %S >>%D";
33     #endif
34   #endif
35 #else /* Wed Feb  5 19:03:58 CET 2003 */
36   #if OS_COTY==COTY_WIN9X || OS_COTY==COTY_WINNT
37     "png22pnm -rgba %S >%D";
38   #else
39     #if OS_COTY==COTY_UNIX
40       #if 1
41         "(png22pnm -rgba %S || (pngtopnm <%S && pngtopnm -alpha <%S)) >%D";
42       #else
43         /* Dat: not using this to suppress `sh: png22pnm: command not found', because
44          * it would hide precious error messages printed by png22pnm.
45          */
46          "((png22pnm -rgba %S 2>/dev/null)|| (pngtopnm <%S && pngtopnm -alpha <%S)) >%D";
47       #endif
48     #else
49       "png22pnm -rgba %S >%D";
50     #endif
51   #endif
52 #endif
53   HelperE helper(cmd); /* Run external process pngtopnm */
54   Encoder::writeFrom(*(Filter::PipeE*)&helper, *(Filter::UngetFILED*)ufd);
55   ((Filter::PipeE*)&helper)->vi_write(0,0); /* Signal EOF */
56   return helper.getImg();
57 }
58 
in_png_checker(char buf[Image::Loader::MAGIC_LEN],char[Image::Loader::MAGIC_LEN],SimBuffer::Flat const &,Image::Loader::UFD *)59 static Image::Loader::reader_t in_png_checker(char buf[Image::Loader::MAGIC_LEN], char [Image::Loader::MAGIC_LEN], SimBuffer::Flat const&, Image::Loader::UFD*) {
60   return 0==memcmp(buf,"\211PNG\r\n\032\n",8) ? in_png_reader : 0;
61 }
62 
63 #else
64 #define in_png_checker (Image::Loader::checker_t)NULLP
65 #endif /* USE_IN_PNG */
66 
67 Image::Loader in_png_loader = { "PNG", in_png_checker, 0 };
68