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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
89
90
91
92
93
94
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>KSquirrel: development</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name='Author' content='Baryshev Dmitry/Krasu'>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
In ksquirrel-libs I use the following wrappers for built-in types (valid for x86, 32-bit platform): int - <b>s32</b>,
unsigned int - <b>u32</b>, short - <b>s16</b>, unsigned short - <b>u16</b>, char - <b>s8</b>, unsinged char - <b>u8</b>.
All of them are defined in <b>fmt_types.h</b>.
<pre>
<b>Defines one metainfo record. For example:
{"JPEG 'COM' marker", "File written by Photoshop"}</b>
struct fmt_metaentry
{
<b>Group name, for example "SGI Image name"</b>
std::string group;
<b>Information. For example "This image was created with MegaTool 0.5.1"</b>
std::string data;
};
<b>Defines 32-bit pixel. Red, Green, Blue and Alpha channel.</b>
struct RGBA
{
RGBA() : r(0), g(0), b(0), a(0)
{}
RGBA(s32 r1, s32 g1, s32 b1, s32 a1) : r(r1), g(g1), b(b1), a(a1)
{}
u8 r;
u8 g;
u8 b;
u8 a;
}PACKED;
<b>Defines 24-bit color pixel. Red, Green, Blue.</b>
struct RGB
{
RGB() : r(0), g(0), b(0)
{}
RGB(s32 r1, s32 g1, s32 b1) : r(r1), g(g1), b(b1)
{}
u8 r;
u8 g;
u8 b;
}PACKED;
<b>Defines one image. It stores the main information about one image: width,
height, metainfo, ...</b>
struct fmt_image
{
fmt_image() : w(0), h(0), bpp(0), hasalpha(false), needflip(false),
delay(0), interlaced(false), passes(1)
{}
<b>width of the image</b>
s32 w;
<b>height</b>
s32 h;
<b>bits per pixel</b>
s32 bpp;
<b>has alpha channel ?</b>
bool hasalpha;
<b>flip ? (for example BMP needs)</b>
bool needflip;
<b>only for animated images (like GIF)</b>
s32 delay;
<b>Is it interlaced or normal ?</b>
bool interlaced;
<b>Item 'passes' stores a number of passes if the image is iterlaced, or 1 otherwise.</b>
s32 passes;
<b>color space (RGB, RGBA, CMYK, LAB ...)</b>
std::string colorspace;
<b>compression type (RLE, JPEG, Deflate ...)</b>
std::string compression;
};
<b>The main structure in ksquirrel-libs. It contains all information needed
to decode a file with one or more images.</b>
struct fmt_info
{
fmt_info() : animated(false)
{}
<b>Array of fmt_image structures. One structure defines one image.</b>
std::vector<fmt_image> image;
<b>Metainfo entries</b>
std::vector<fmt_metaentry> meta;
<b>Is it animated or static ?</b>
bool animated;
};
enum fmt_compression {
<b>No compression</b>
CompressionNo = 1,
<b>RLE compression</b>
CompressionRLE = 2,
<b>Internal cmpression. E.g. compression_level will be passed to internal routines,
for example in libjpeg, libpng.
Note: if the image can be compressed with RLE encoding and with only RLE
encoding, compression_scheme should be CompressionInternal</b>
CompressionInternal = 4 };
<b>Write options for image format</b>
struct fmt_writeoptionsabs
{
<b>Can be interlaced ?</b>
bool interlaced;
<b>if interlaced, this value should store preferred number of passes.</b>
s32 passes;
<b>if the image should be flipped before writing</b>
bool needflip;
<b> with which compression it can be encoded ?
for example: CompressionNo | CompressionRLE.
it means, that image can be encoded with RLE
method or can be saved without any compression.</b>
s32 compression_scheme;
<b> minimum compression level, maximum and default.
For example, JPEG library has minimum = 0,
maximum = 100 and default = 25.</b>
s32 compression_min, compression_max, compression_def;
}PACKED;
<b>this information will be passed to writing function</b>
struct fmt_writeoptions
{
<b>write interlaced image or normal ?</b>
bool interlaced;
<b>with which compression encode the image ?</b>
fmt_compression compression_scheme;
<b>compression level</b>
s32 compression_level;
<b>has alpha channel ? If no, A channel in RGBA image will be ignored</b>
bool alpha;
}PACKED;
<b>We can use comparison operators for RGBA and RGB pixels. For example:</b>
<strong>
#define SQ_NEED_OPERATOR_RGBA_RGB
RGBA rgba;
RGB rgb;
...
if(rgba == rgb)
printf("Pixels are equal!\n");
</strong>
#if defined SQ_NEED_OPERATOR_RGBA_RGBA
static s32 operator== (const RGBA &rgba1, const RGBA &rgba2)
{
return (rgba1.r == rgba2.r && rgba1.g == rgba2.g && rgba1.b == rgba2.b && rgba1.a == rgba2.a);
}
#endif
#if defined SQ_NEED_OPERATOR_RGB_RGBA
static s32 operator== (const RGB &rgb, const RGBA &rgba)
{
return (rgb.r == rgba.r && rgb.g == rgba.g && rgb.b == rgba.b);
}
#endif
#if defined SQ_NEED_OPERATOR_RGBA_RGB
static s32 operator== (const RGBA &rgba, const RGB &rgb)
{
return (rgba.r == rgb.r && rgba.g == rgb.g && rgba.b == rgb.b);
}
#endif
#endif
</pre>
</body>
</html>
|