jimage.h
8.2 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/***************************************************************************
* Copyright (C) 2005 by Jeff Ferr *
* root@sat *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef J_IMAGE_H
#define J_IMAGE_H
#include "jgraphics.h"
#include "jfile.h"
#include "jinputstream.h"
#include <stdint.h>
#include <string.h>
namespace jgui{
enum jsurface_pixelformat_t {
JSP_UNKNOWN, // 0x00000000 unknown or unspecified format
JSP_ARGB1555, // SURFACE_PIXELFORMAT(0, 15, 1, 1, 0, 2, 0, 0, 0, 0, 0) 16 bit ARGB (2 byte, alpha 1@15, red 5@10, green 5@5, blue 5@0)
JSP_RGB16, // SURFACE_PIXELFORMAT(1, 16, 0, 0, 0, 2, 0, 0, 0, 0, 0) 16 bit RGB (2 byte, red 5@11, green 6@5, blue 5@0)
JSP_RGB24, // SURFACE_PIXELFORMAT(2, 24, 0, 0, 0, 3, 0, 0, 0, 0, 0) 24 bit RGB (3 byte, red 8@16, green 8@8, blue 8@0)
JSP_RGB32, // SURFACE_PIXELFORMAT(3, 24, 0, 0, 0, 4, 0, 0, 0, 0, 0) 24 bit RGB (4 byte, nothing@24, red 8@16, green 8@8, blue 8@0)
JSP_ARGB, // SURFACE_PIXELFORMAT(4, 24, 8, 1, 0, 4, 0, 0, 0, 0, 0) 32 bit ARGB (4 byte, alpha 8@24, red 8@16, green 8@8, blue 8@0)
JSP_A8, // SURFACE_PIXELFORMAT(5, 0, 8, 1, 0, 1, 0, 0, 0, 0, 0) 8 bit alpha (1 byte, alpha 8@0), e.g. anti-aliased glyphs
JSP_YUY2, // SURFACE_PIXELFORMAT(6, 16, 0, 0, 0, 2, 0, 0, 0, 0, 0) 16 bit YUV (4 byte/ 2 pixel, macropixel contains CbYCrY [31:0])
JSP_RGB332, // SURFACE_PIXELFORMAT(7, 8, 0, 0, 0, 1, 0, 0, 0, 0, 0) 8 bit RGB (1 byte, red 3@5, green 3@2, blue 2@0)
JSP_UYVY, // SURFACE_PIXELFORMAT(8, 16, 0, 0, 0, 2, 0, 0, 0, 0, 0) 16 bit YUV (4 byte/ 2 pixel, macropixel contains YCbYCr [31:0])
JSP_I420, // SURFACE_PIXELFORMAT(9, 12, 0, 0, 0, 1, 0, 2, 0, 0, 0) 12 bit YUV (8 bit Y plane followed by 8 bit quarter size U/V planes)
JSP_YV12, // SURFACE_PIXELFORMAT(10, 12, 0, 0, 0, 1, 0, 2, 0, 0, 0) 12 bit YUV (8 bit Y plane followed by 8 bit quarter size V/U planes)
JSP_LUT8, // SURFACE_PIXELFORMAT(11, 8, 0, 1, 0, 1, 0, 0, 0, 1, 0) 8 bit LUT (8 bit color and alpha lookup from palette)
JSP_ALUT44, // SURFACE_PIXELFORMAT(12, 4, 4, 1, 0, 1, 0, 0, 0, 1, 0) 8 bit ALUT (1 byte, alpha 4@4, color lookup 4@0)
JSP_AiRGB, // SURFACE_PIXELFORMAT(13, 24, 8, 1, 0, 4, 0, 0, 0, 0, 1) 32 bit ARGB (4 byte, inv. alpha 8@24, red 8@16, green 8@8, blue 8@0)
JSP_A1, // SURFACE_PIXELFORMAT(14, 0, 1, 1, 1, 0, 7, 0, 0, 0, 0) 1 bit alpha (1 byte/ 8 pixel, most significant bit used first)
JSP_NV12, // SURFACE_PIXELFORMAT(15, 12, 0, 0, 0, 1, 0, 2, 0, 0, 0) 12 bit YUV (8 bit Y plane followed by one 16 bit quarter size Cb|Cr [7:0|7:0] plane)
JSP_NV16, // SURFACE_PIXELFORMAT(16, 24, 0, 0, 0, 1, 0, 0, 1, 0, 0) 16 bit YUV (8 bit Y plane followed by one 16 bit half width Cb|Cr [7:0|7:0] plane)
JSP_ARGB2554, // SURFACE_PIXELFORMAT(17, 14, 2, 1, 0, 2, 0, 0, 0, 0, 0) 16 bit ARGB (2 byte, alpha 2@14, red 5@9, green 5@4, blue 4@0)
JSP_ARGB4444, // SURFACE_PIXELFORMAT(18, 12, 4, 1, 0, 2, 0, 0, 0, 0, 0) 16 bit ARGB (2 byte, alpha 4@12, red 4@8, green 4@4, blue 4@0)
JSP_RGBA4444, // SURFACE_PIXELFORMAT(19, 12, 4, 1, 0, 2, 0, 0, 0, 0, 0) 16 bit RGBA (2 byte, red 4@12, green 4@8, blue 4@4, alpha 4@0)
JSP_NV21, // SURFACE_PIXELFORMAT(20, 12, 0, 0, 0, 1, 0, 2, 0, 0, 0) 12 bit YUV (8 bit Y plane followed by one 16 bit quarter size Cr|Cb [7:0|7:0] plane)
JSP_AYUV, // SURFACE_PIXELFORMAT(21, 24, 8, 1, 0, 4, 0, 0, 0, 0, 0) 32 bit AYUV (4 byte, alpha 8@24, Y 8@16, Cb 8@8, Cr 8@0)
JSP_A4, // SURFACE_PIXELFORMAT(22, 0, 4, 1, 4, 0, 1, 0, 0, 0, 0) 4 bit alpha (1 byte/ 2 pixel, more significant nibble used first)
JSP_ARGB1666, // SURFACE_PIXELFORMAT(23, 18, 1, 1, 0, 3, 0, 0, 0, 0, 0) 1 bit alpha (3 byte/ alpha 1@18, red 6@12, green 6@6, blue 6@0)
JSP_ARGB6666, // SURFACE_PIXELFORMAT(24, 18, 6, 1, 0, 3, 0, 0, 0, 0, 0) 6 bit alpha (3 byte/ alpha 6@18, red 6@12, green 6@6, blue 6@0)
JSP_RGB18, // SURFACE_PIXELFORMAT(25, 18, 0, 0, 0, 3, 0, 0, 0, 0, 0) 6 bit RGB (3 byte/ red 6@12, green 6@6, blue 6@0)
JSP_LUT2, // SURFACE_PIXELFORMAT(26, 2, 0, 1, 2, 0, 3, 0, 0, 1, 0) 2 bit LUT (1 byte/ 4 pixel, 2 bit color and alpha lookup from palette)
JSP_RGB444, // SURFACE_PIXELFORMAT(27, 12, 0, 0, 0, 2, 0, 0, 0, 0, 0) 16 bit RGB (2 byte, nothing @12, red 4@8, green 4@4, blue 4@0)
JSP_RGB555, // SURFACE_PIXELFORMAT(28, 15, 0, 0, 0, 2, 0, 0, 0, 0, 0) 16 bit RGB (2 byte, nothing @15, red 5@10, green 5@5, blue 5@0)
JSP_BGR555, // SURFACE_PIXELFORMAT(29, 15, 0, 0, 0, 2, 0, 0, 0, 0, 0) 16 bit BGR (2 byte, nothing @15, blue 5@10, green 5@5, red 5@0)
JSP_RGBA5551, // SURFACE_PIXELFORMAT(30, 15, 1, 1, 0, 2, 0, 0, 0, 0, 0) 16 bit RGBA (2 byte, red 5@11, green 5@6, blue 5@1, alpha 1@0)
JSP_AVYU, // SURFACE_PIXELFORMAT(31, 24, 8, 1, 0, 4, 0, 0, 0, 0, 0) 32 bit AVYU 4:4:4 (4 byte, alpha 8@24, Cr 8@16, Y 8@8, Cb 8@0)
JSP_VYU, // SURFACE_PIXELFORMAT(32, 24, 0, 0, 0, 3, 0, 0, 0, 0, 0)
};
class Graphics;
/**
* \brief
*
* \author Jeff Ferr
*/
class Image : public virtual jcommon::Object{
private:
uint8_t *_buffer;
protected:
Graphics *_graphics;
struct jsize_t _size;
struct jsize_t _screen;
struct jsize_t _scale;
jsurface_pixelformat_t _pixelformat;
private:
/**
* \brief
*
*/
Image(int width, int height, jsurface_pixelformat_t pixelformat = JSP_ARGB, int scale_width = DEFAULT_SCALE_WIDTH, int scale_height = DEFAULT_SCALE_HEIGHT);
protected:
/**
* \brief
*
*/
Image(int width, int height, int scale_width = DEFAULT_SCALE_WIDTH, int scale_height = DEFAULT_SCALE_HEIGHT);
public:
/**
* \brief
*
*/
virtual ~Image();
/**
* \brief
*
*/
static bool GetImageSize(std::string img, int *width, int *height);
/**
* \brief
*
*/
static Image * CreateImage(int width, int height, jsurface_pixelformat_t pixelformat = JSP_ARGB, int scale_width = DEFAULT_SCALE_WIDTH, int scale_height = DEFAULT_SCALE_HEIGHT);
/**
* \brief
*
*/
static Image * CreateImage(uint32_t *data, int width, int height);
/**
* \brief
*
*/
static Image * CreateImage(uint8_t *data, int size);
/**
* \brief
*
*/
static Image * CreateImage(std::string image);
/**
* \brief
*
*/
static Image * CreateImage(jio::File *file);
/**
* \brief
*
*/
static Image * CreateImage(jio::InputStream *stream);
/**
* \brief
*
*/
static Image * CreateImage(Image *image);
/**
* \brief
*
*/
virtual jsize_t GetWorkingScreenSize();
/**
* \brief
*
*/
virtual Graphics * GetGraphics();
/**
* \brief
*
*/
virtual Image * Scaled(int width, int height);
/**
* \brief
*
*/
virtual Image * SubImage(int x, int y, int width, int height);
/**
* \brief
*
*/
virtual void GetRGB(uint32_t **rgb, int xp, int yp, int wp, int hp);
/**
* \brief
*
*/
virtual jsurface_pixelformat_t GetPixelFormat();
/**
* \brief
*
*/
virtual int GetWidth();
/**
* \brief
*
*/
virtual int GetHeight();
/**
* \brief
*
*/
virtual void Release();
/**
* \brief
*
*/
virtual void Restore();
};
}
#endif