#include "gdpp.h" #ifdef __cplusplus namespace GD { bool Image::CreateFrom(FILE * in) { bool rtn; int c = fgetc(in); ungetc(c, in); switch (c) { /* PNG The first eight bytes of a PNG file always contain the following (decimal) values: 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A == .PNG\r\n.\n */ case 0x89: // PNG rtn = CreateFromPng(in); break; /* GIF 0x47 0x49 0x46 */ case 0x47: // GIF rtn = CreateFromGif(in); break; /* JPEG A JFIF-standard file will start with the four bytes (hex) FF D8 FF E0, followed by two variable bytes (often hex 00 10), followed by 'JFIF'. */ case 0xFF: // JPEG rtn = CreateFromJpeg(in); break; /* WBMP WBMP Type 0: B/W, Uncompressed bitmap is the only gd supported type */ case 0x00: // WBMP rtn = CreateFromWBMP(in); break; /* GD2 0x67 0x64 0x32 0x00 == GD2\0 Starts with gd2 */ case 0x67: // GD2 rtn = CreateFromGd2(in); break; /* GD 0xFF 0xFE or 0xFF 0xFF Conflicts with Jpeg */ /* XBM #define test_width 16 #define test_height 7 */ case 0x23: // XBM rtn = CreateFromXbm(in); break; default: rtn = false; break; } return rtn; } bool Image::CreateFrom(std::istream & in) { bool rtn; switch (in.peek()) { /* PNG The first eight bytes of a PNG file always contain the following (decimal) values: 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A == .PNG\r\n.\n */ case 0x89: // PNG rtn = CreateFromPng(in); break; /* GIF 0x47 0x49 0x46 */ case 0x47: // GIF rtn = CreateFromGif(in); break; /* JPEG A JFIF-standard file will start with the four bytes (hex) FF D8 FF E0, followed by two variable bytes (often hex 00 10), followed by 'JFIF'. */ case 0xFF: // JPEG rtn = CreateFromJpeg(in); break; /* WBMP WBMP Type 0: B/W, Uncompressed bitmap is the only gd supported type */ case 0x00: // WBMP rtn = CreateFromWBMP(in); break; /* GD2 0x67 0x64 0x32 0x00 == GD2\0 Starts with gd2 */ case 0x67: // GD2 rtn = CreateFromGd2(in); break; /* GD 0xFF 0xFE or 0xFF 0xFF Conflicts with Jpeg */ default: rtn = false; break; } return rtn; } } // namespace GD std::istream & operator>> (std::istream & in, GD::Image & img) { img.CreateFrom(in); return in; } #endif /* __cplusplus */