/[H9]/trunk/tntnet/dynamic/gd-cpp/gdpp.cpp
ViewVC logotype

Contents of /trunk/tntnet/dynamic/gd-cpp/gdpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 68 - (show annotations) (download)
Tue Nov 27 14:28:59 2007 UTC (16 years, 5 months ago) by torben
File size: 2403 byte(s)
Basic structure for web-interface

1 #include "gdpp.h"
2 #ifdef __cplusplus
3
4 namespace GD
5 {
6 bool Image::CreateFrom(FILE * in)
7 {
8 bool rtn;
9 int c = fgetc(in);
10 ungetc(c, in);
11 switch (c)
12 {
13 /* PNG
14 The first eight bytes of a PNG file always contain the following (decimal) values:
15 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A
16 == .PNG\r\n.\n
17 */
18 case 0x89: // PNG
19 rtn = CreateFromPng(in);
20 break;
21 /* GIF
22 0x47 0x49 0x46
23 */
24 case 0x47: // GIF
25 rtn = CreateFromGif(in);
26 break;
27 /* JPEG
28 A JFIF-standard file will start with the four bytes (hex) FF D8 FF E0,
29 followed by two variable bytes (often hex 00 10), followed by 'JFIF'.
30 */
31 case 0xFF: // JPEG
32 rtn = CreateFromJpeg(in);
33 break;
34 /* WBMP
35 WBMP Type 0: B/W, Uncompressed bitmap is the only gd supported type
36 */
37 case 0x00: // WBMP
38 rtn = CreateFromWBMP(in);
39 break;
40 /* GD2
41 0x67 0x64 0x32 0x00
42 == GD2\0
43 Starts with gd2
44 */
45 case 0x67: // GD2
46 rtn = CreateFromGd2(in);
47 break;
48 /* GD
49 0xFF 0xFE
50 or
51 0xFF 0xFF
52 Conflicts with Jpeg
53 */
54 /* XBM
55 #define test_width 16
56 #define test_height 7
57 */
58 case 0x23: // XBM
59 rtn = CreateFromXbm(in);
60 break;
61 default:
62 rtn = false;
63 break;
64 }
65 return rtn;
66 }
67
68 bool Image::CreateFrom(std::istream & in)
69 {
70 bool rtn;
71 switch (in.peek())
72 {
73 /* PNG
74 The first eight bytes of a PNG file always contain the following (decimal) values:
75 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A
76 == .PNG\r\n.\n
77 */
78 case 0x89: // PNG
79 rtn = CreateFromPng(in);
80 break;
81 /* GIF
82 0x47 0x49 0x46
83 */
84 case 0x47: // GIF
85 rtn = CreateFromGif(in);
86 break;
87 /* JPEG
88 A JFIF-standard file will start with the four bytes (hex) FF D8 FF E0,
89 followed by two variable bytes (often hex 00 10), followed by 'JFIF'.
90 */
91 case 0xFF: // JPEG
92 rtn = CreateFromJpeg(in);
93 break;
94 /* WBMP
95 WBMP Type 0: B/W, Uncompressed bitmap is the only gd supported type
96 */
97 case 0x00: // WBMP
98 rtn = CreateFromWBMP(in);
99 break;
100 /* GD2
101 0x67 0x64 0x32 0x00
102 == GD2\0
103 Starts with gd2
104 */
105 case 0x67: // GD2
106 rtn = CreateFromGd2(in);
107 break;
108 /* GD
109 0xFF 0xFE
110 or
111 0xFF 0xFF
112 Conflicts with Jpeg
113 */
114 default:
115 rtn = false;
116 break;
117 }
118 return rtn;
119 }
120 } // namespace GD
121 std::istream & operator>> (std::istream & in, GD::Image & img)
122 {
123 img.CreateFrom(in);
124 return in;
125 }
126
127 #endif /* __cplusplus */

  ViewVC Help
Powered by ViewVC 1.1.20