owfimage.h
8.66 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/* Copyright (c) 2009 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and/or associated documentation files (the
* "Materials"), to deal in the Materials without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Materials, and to
* permit persons to whom the Materials are furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
#ifndef __OWFIMAGE_H__
#define __OWFIMAGE_H__
#include "owftypes.h"
#ifdef __cplusplus
extern "C" {
#endif
#undef USE_FLOAT_PIXEL
/*
* This is and always should be the only place where USE_FLOAT_PIXEL is
* defined so if #define USE_FLOAT_PIXEL is absent in owfimage.h then it
* can be assumed it is not defined elsewhere.
* \remark <b>[MTK]</b> We don't use float pixel.
*/
//#define USE_FLOAT_PIXEL
/* --
* internal pixel format
*/
#ifdef USE_FLOAT_PIXEL
#define OWF_IMAGE_INTERNAL_PIXEL_IS_FLOAT
typedef OWFfloat OWFsubpixel; /* subpixel representation */
#define OWF_RED_MIN_VALUE 0.0f
#define OWF_RED_MAX_VALUE 1.0f
#define OWF_GREEN_MIN_VALUE 0.0f
#define OWF_GREEN_MAX_VALUE 1.0f
#define OWF_BLUE_MIN_VALUE 0.0f
#define OWF_BLUE_MAX_VALUE 1.0f
#define OWF_ALPHA_MIN_VALUE 0.0f
#define OWF_ALPHA_MAX_VALUE 1.0f
#define OWF_FULLY_OPAQUE OWF_ALPHA_MAX_VALUE
#define OWF_FULLY_TRANSPARENT OWF_ALPHA_MIN_VALUE
#define OWF_BYTE_MAX_VALUE 255.0f
#define OWF_BILINEAR_ROUNDING_VALUE 0.0f
#define OWF_BLEND_ROUNDING_VALUE 0.0f
#define OWF_PREMUL_ROUNDING_FACTOR 0.0f
#else
#undef OWF_IMAGE_INTERNAL_PIXEL_IS_FLOAT
typedef OWFuint8 OWFsubpixel; /* subpixel representation */
#define OWF_RED_MIN_VALUE 0
#define OWF_RED_MAX_VALUE 255
#define OWF_GREEN_MIN_VALUE 0
#define OWF_GREEN_MAX_VALUE 255
#define OWF_BLUE_MIN_VALUE 0
#define OWF_BLUE_MAX_VALUE 255
#define OWF_ALPHA_MIN_VALUE 0
#define OWF_ALPHA_MAX_VALUE 255
#define OWF_FULLY_OPAQUE OWF_ALPHA_MAX_VALUE
#define OWF_FULLY_TRANSPARENT OWF_ALPHA_MIN_VALUE
#define OWF_BYTE_MAX_VALUE 255
#define OWF_BILINEAR_ROUNDING_VALUE 0.5f
#define OWF_BLEND_ROUNDING_VALUE (OWF_ALPHA_MAX_VALUE/2)
#define OWF_PREMUL_ROUNDING_FACTOR (OWF_ALPHA_MAX_VALUE/2)
#endif
/*
* Byte order of different color formats
* these are used when converting from/to
* internal format
*/
#define ARGB8888_ALPHA_MASK 0xFF000000
#define ARGB8888_RED_MASK 0x00FF0000
#define ARGB8888_GREEN_MASK 0x0000FF00
#define ARGB8888_BLUE_MASK 0x000000FF
#define ARGB8888_ALPHA_SHIFT 24
#define ARGB8888_RED_SHIFT 16
#define ARGB8888_GREEN_SHIFT 8
#define ARGB8888_BLUE_SHIFT 0
#define RGB565_ALPHA_MASK 0xFFFF
#define RGB565_RED_MASK 0xF800
#define RGB565_GREEN_MASK 0x07E0
#define RGB565_BLUE_MASK 0x001F
/* These are used when converting from RGB565 to ARGB8888. */
#define RGB565_ALPHA_SHIFT 16
#define RGB565_RED_SHIFT 11
#define RGB565_GREEN_SHIFT 5
/* subpixels per pixel */
#define OWF_PIXEL_SIZE 4
/* subpixel in bytes */
#define OWF_SUBPIXEL_SIZE sizeof(OWFsubpixel)
#define OWF_BYTES_PER_PIXEL (OWF_PIXEL_SIZE * OWF_SUBPIXEL_SIZE)
#pragma pack(push, 1)
typedef union {
struct {
OWFsubpixel blue;
OWFsubpixel green;
OWFsubpixel red;
OWFsubpixel alpha;
} color;
OWFsubpixel subpixel[OWF_PIXEL_SIZE];
OWFuint8 pixelbytes[OWF_BYTES_PER_PIXEL];
} OWFpixel;
#pragma pack(pop)
/* -- */
/* filters used in OWF_Image_Stretch */
typedef enum {
OWF_FILTER_POINT_SAMPLING, /* nearest pixel */
OWF_FILTER_BILINEAR /* nearest 4 */
} OWF_FILTERING;
typedef struct {
OWFint width;
OWFint height;
OWFint stride; /**< number of bytes per line */
OWFint pixelSize; /**< pixel size in bytes */
OWF_IMAGE_FORMAT format;
OWFboolean foreign; /**< The data buffer is allocated outside. */
OWFint dataMax; /* data buffer max size */
//OWFboolean alphaEnable; /**< MTK: Enable global alpha for flatten */
OWFint alpha; /** MTK: desired target alpha for ARGB format fow w2mem*/
void* data;
} OWF_IMAGE;
/* This typedef denotes an owned OWF_IMAGE, as opposed to a temporary association.
* Owned instances must be destroyed when the containing object is destroyed.
*/
typedef OWF_IMAGE* OWF_IMAGE_INST;
typedef enum {
OWF_FLIP_NONE,
OWF_FLIP_VERTICALLY = 1,
OWF_FLIP_HORIZONTALLY = 2
} OWF_FLIP_DIRECTION;
typedef enum {
OWF_ROTATION_0 = 0,
OWF_ROTATION_90 = 90,
OWF_ROTATION_180 = 180,
OWF_ROTATION_270 = 270
} OWF_ROTATION;
typedef enum {
OWF_TRANSPARENCY_NONE,
OWF_TRANSPARENCY_GLOBAL_ALPHA = (1 << 0),
OWF_TRANSPARENCY_SOURCE_ALPHA = (1 << 1),
OWF_TRANSPARENCY_MASK = (1 << 2),
OWF_TRANSPARENCY_COLOR_KEY = (1 << 3)
} OWF_TRANSPARENCY;
typedef struct _OWF_BLEND_INFO {
struct {
OWF_IMAGE* image;
OWF_RECTANGLE* rectangle;
} destination;
struct {
OWF_IMAGE* image;
OWF_RECTANGLE* rectangle;
} source;
OWF_IMAGE* mask;
OWFsubpixel globalAlpha;
OWFboolean destinationFullyOpaque;
OWFpixel* tsColor;
} OWF_BLEND_INFO;
/*!---------------------------------------------------------------------------
* \brief Initialize image object
*
* \param
*
* \return
*----------------------------------------------------------------------------*/
OWF_API_CALL void
OWF_Image_FreeData(void** buffer);
/*!---------------------------------------------------------------------------
* \param image Image to resize
* \param width New width of the image
*
* \param image Image to resize
* \param premultiply Image data is premultiplied
* \param dstRect Destination rectangle
* \param src Source image
* \param src Source image
* \brief
*
* \param
*
* \return
*----------------------------------------------------------------------------*/
OWF_API_CALL OWFint
OWF_Image_GetFormatPixelSize(OWF_PIXEL_FORMAT format);
/*!---------------------------------------------------------------------------
* \brief
*
* \param
*
* \return
*----------------------------------------------------------------------------*/
OWF_API_CALL OWFint
OWF_Image_GetFormatPixelSize(OWF_PIXEL_FORMAT format);
/*!---------------------------------------------------------------------------
* \brief Return pointer to given pixel in image.
*
* \param image Image
* \param x X-coordinate of the pixel (0..width-1)
* \param y Y-coordinate of the pixel (0..height-1)
*
* The x & y coordinates will be clamped to [0..width-1, 0..height-1]
*
* \return Pointer to given pixel
*----------------------------------------------------------------------------*/
OWF_API_CALL OWFpixel*
OWF_Image_GetPixelPtr(OWF_IMAGE* image,
OWFint x,
OWFint y);
/*!---------------------------------------------------------------------------
* \brief Return stride (aligned row size in bytes) calculated from image
* width and pixelSize. If pixelSize is negative image width must be divisible
* by pixelSize.
*
* \param width Width of image
* \param pixelSize Size of single pixel in bytes. Negative size
* means value is a divisor (i.e. 1/pixelSize)
* \param padding Number of bits each row is padded to.
* \return Row size in bytes.
*----------------------------------------------------------------------------*/
OWF_PUBLIC OWFint
OWF_Image_GetStride(OWFint width,
const OWF_IMAGE_FORMAT* format,
OWFint minimumStride);
#ifdef __cplusplus
}
#endif
#endif /* __OWFIMAGE_H__ */