summaryrefslogtreecommitdiffstats
path: root/common/draw.h
blob: e277b2d9c431ad27f217daaf4ed366b5264c1607 (plain)
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/*
   Copyright (C) 2009 Red Hat, Inc.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are
   met:

       * Redistributions of source code must retain the above copyright
         notice, this list of conditions and the following disclaimer.
       * Redistributions in binary form must reproduce the above copyright
         notice, this list of conditions and the following disclaimer in
         the documentation and/or other materials provided with the
         distribution.
       * Neither the name of the copyright holder nor the names of its
         contributors may be used to endorse or promote products derived
         from this software without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
   IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
   PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _H_DRAW
#define _H_DRAW

#ifndef _WIN32
#include <stdint.h>
#endif

#ifdef __GNUC__
#define ATTR_PACKED __attribute__ ((__packed__))
typedef uint64_t UINT64;
typedef uint32_t UINT32;
typedef uint16_t UINT16;
typedef uint8_t UINT8;

typedef int16_t INT16;
typedef int32_t INT32;
#else
#include <basetsd.h>
#pragma pack(push)
#pragma pack(1)
#define ATTR_PACKED
#pragma warning(disable:4200)
#endif

#ifdef _WIN32_WCE
#include <stdint.h>
typedef uint64_t UINT64;
typedef uint32_t UINT32;
typedef uint16_t UINT16;
typedef uint8_t UINT8;

typedef int16_t INT16;
typedef int32_t INT32;
#endif

#define GET_ADDRESS(addr) ((void *)(unsigned long)(addr))
#define SET_ADDRESS(addr, val) ((addr) = (unsigned long)(val))

typedef INT32 FIXED28_4;
typedef UINT64 ADDRESS;

enum {
    PATH_BEGIN = (1 << 0),
    PATH_END = (1 << 1),
    PATH_CLOSE = (1 << 3),
    PATH_BEZIER = (1 << 4),
};

enum {
    LINE_ATTR_STARTGAP = (1 << 2),
    LINE_ATTR_STYLED = (1 << 3),
};

typedef struct ATTR_PACKED PointFix {
    FIXED28_4 x;
    FIXED28_4 y;
} PointFix;

typedef struct ATTR_PACKED Point {
    INT32 x;
    INT32 y;
} Point;

typedef struct ATTR_PACKED Point16 {
    INT16 x;
    INT16 y;
} Point16;

typedef struct ATTR_PACKED Rect {
    INT32 top;
    INT32 left;
    INT32 bottom;
    INT32 right;
} Rect;

typedef struct ATTR_PACKED PathSeg {
    UINT32 flags;
    UINT32 count;
    UINT8 data[0];
} PathSeg;

enum ClipType {
    CLIP_TYPE_NONE,
    CLIP_TYPE_RECTS,
    CLIP_TYPE_PATH,
};

typedef struct ATTR_PACKED Clip {
    UINT32 type;
    ADDRESS data;
} Clip;

enum ROPDescriptor {
    ROPD_INVERS_SRC = (1 << 0),
    ROPD_INVERS_BRUSH = (1 << 1),
    ROPD_INVERS_DEST = (1 << 2),
    ROPD_OP_PUT = (1 << 3),
    ROPD_OP_OR = (1 << 4),
    ROPD_OP_AND = (1 << 5),
    ROPD_OP_XOR = (1 << 6),
    ROPD_OP_BLACKNESS = (1 << 7),
    ROPD_OP_WHITENESS = (1 << 8),
    ROPD_OP_INVERS = (1 << 9),
    ROPD_INVERS_RES = (1 << 10),
};

typedef struct ATTR_PACKED Pattern {
    ADDRESS pat;
    Point pos;
} Pattern;

enum {
    BRUSH_TYPE_NONE,
    BRUSH_TYPE_SOLID,
    BRUSH_TYPE_PATTERN,
};

typedef struct ATTR_PACKED Brush {
    UINT32 type;
    union {
        UINT32 color;
        Pattern pattern;
    } u;
} Brush;

enum {
    MASK_INVERS = (1 << 0),
};

typedef struct ATTR_PACKED QMask {
    UINT8 flags;
    Point pos;
    ADDRESS bitmap;
} QMask;

typedef struct ATTR_PACKED Fill {
    Brush brush;
    UINT16 rop_decriptor;
    QMask mask;
} Fill;

typedef struct ATTR_PACKED Palette {
    UINT64 unique;
    UINT16 num_ents;
    UINT32 ents[0];
} Palette;

enum {
    IMAGE_TYPE_BITMAP,
    IMAGE_TYPE_QUIC,
    IMAGE_TYPE_RESERVED,
    IMAGE_TYPE_LZ_PLT = 100,
    IMAGE_TYPE_LZ_RGB,
    IMAGE_TYPE_GLZ_RGB,
    IMAGE_TYPE_FROM_CACHE,
};

enum {
    IMAGE_CACHE_ME = (1 << 0),
};

typedef struct ATTR_PACKED ImageDescriptor {
    UINT64 id;
    UINT8 type;
    UINT8 flags;
    UINT32 width;
    UINT32 height;
} ImageDescriptor;

enum {
    BITMAP_FMT_INVALID,
    BITMAP_FMT_1BIT_LE,
    BITMAP_FMT_1BIT_BE,
    BITMAP_FMT_4BIT_LE,
    BITMAP_FMT_4BIT_BE,
    BITMAP_FMT_8BIT,
    BITMAP_FMT_16BIT,
    BITMAP_FMT_24BIT,
    BITMAP_FMT_32BIT,
    BITMAP_FMT_RGBA,
};

enum {
    BITMAP_PAL_CACHE_ME = (1 << 0),
    BITMAP_PAL_FROM_CACHE = (1 << 1),
    BITMAP_TOP_DOWN = (1 << 2),
};

typedef struct ATTR_PACKED Bitmap {
    UINT8 format;
    UINT8 flags;
    UINT32 x;
    UINT32 y;
    UINT32 stride;
    ADDRESS palette;
    ADDRESS data; //data[0] ?
} Bitmap;

typedef struct ATTR_PACKED BitmapImage {
    ImageDescriptor descriptor;
    Bitmap bitmap;
} BitmapImage;

typedef struct ATTR_PACKED QUICData {
    UINT32 data_size;
    UINT8 data[0];
} QUICData, LZ_RGBData;

typedef struct ATTR_PACKED QUICImage {
    ImageDescriptor descriptor;
    QUICData quic;
} QUICImage;

typedef struct ATTR_PACKED LZ_RGBImage {
    ImageDescriptor descriptor;
    LZ_RGBData lz_rgb;
} LZ_RGBImage;

typedef struct ATTR_PACKED LZ_PLTData {
    UINT8 flags;
    UINT32 data_size;
    ADDRESS palette;
    UINT8 data[0];
} LZ_PLTData;

typedef struct ATTR_PACKED LZ_PLTImage {
    ImageDescriptor descriptor;
    LZ_PLTData lz_plt;
} LZ_PLTImage;

enum {
    IMAGE_SCALE_INTERPOLATE,
    IMAGE_SCALE_NEAREST,
};

typedef struct ATTR_PACKED Opaque {
    ADDRESS src_bitmap;
    Rect src_area;
    Brush brush;
    UINT16 rop_decriptor;
    UINT8 scale_mode;
    QMask mask;
} Opaque;

typedef struct ATTR_PACKED Copy {
    ADDRESS src_bitmap;
    Rect src_area;
    UINT16 rop_decriptor;
    UINT8 scale_mode;
    QMask mask;
} Copy, Blend;

typedef struct ATTR_PACKED Transparent {
    ADDRESS src_bitmap;
    Rect src_area;
    UINT32 src_color;
    UINT32 true_color;
} Transparent;

typedef struct ATTR_PACKED AlphaBlnd {
    UINT8 alpha;
    ADDRESS src_bitmap;
    Rect src_area;
} AlphaBlnd;

typedef struct ATTR_PACKED Rop3 {
    ADDRESS src_bitmap;
    Rect src_area;
    Brush brush;
    UINT8 rop3;
    UINT8 scale_mode;
    QMask mask;
} Rop3;

typedef struct ATTR_PACKED Blackness {
    QMask mask;
} Blackness, Invers, Whiteness;

enum {
    LINE_STYLED = (1 << 3),
    LINE_START_WITH_GAP = (1 << 2),
};

enum {
    LINE_CAP_ROUND,
    LINE_CAP_SQUARE,
    LINE_CAP_BUTT,
};

enum {
    LINE_JOIN_ROUND,
    LINE_JOIN_BEVEL,
    LINE_JOIN_MITER,
};

typedef struct ATTR_PACKED LineAttr {
    UINT8 flags;
    UINT8 join_style;
    UINT8 end_style;
    UINT8 style_nseg;
    FIXED28_4 width;
    FIXED28_4 miter_limit;
    ADDRESS style; //data[0] ?
} LineAttr;

typedef struct ATTR_PACKED Stroke {
    ADDRESS path;
    LineAttr attr;
    Brush brush;
    UINT16 fore_mode;
    UINT16 back_mode;
} Stroke;

typedef struct ATTR_PACKED RasterGlyph {
    Point render_pos;
    Point glyph_origin;
    UINT16 width;
    UINT16 height;
    UINT8 data[0];
} RasterGlyph;

typedef struct ATTR_PACKED VectotGlyph {
    Point render_pos;
    UINT32 data_size;
    UINT8 data[0]; //PathSeg[]
} VectotGlyph;

enum {
    STRING_RASTER_A1 = 1 << 0,
    STRING_RASTER_A4 = 1 << 1,
    STRING_RASTER_A8 = 1 << 2,
    STRING_RASTER_TOP_DOWN = 1 << 3,
};

typedef struct ATTR_PACKED String {
    UINT16 length;
    UINT16 flags;
    UINT8 data[0];
} String;

typedef struct ATTR_PACKED Text {
    ADDRESS str;
    Rect back_area;
    Brush fore_brush;
    Brush back_brush;
    UINT16 fore_mode;
    UINT16 back_mode;
} Text;

enum {
    CURSOR_TYPE_ALPHA,
    CURSOR_TYPE_MONO,
    CURSOR_TYPE_COLOR4,
    CURSOR_TYPE_COLOR8,
    CURSOR_TYPE_COLOR16,
    CURSOR_TYPE_COLOR24,
    CURSOR_TYPE_COLOR32,
};

typedef struct ATTR_PACKED CursorHeader {
    UINT64 unique;
    UINT16 type;
    UINT16 width;
    UINT16 height;
    UINT16 hot_spot_x;
    UINT16 hot_spot_y;
} CursorHeader;


#ifndef __GNUC__
#pragma pack(pop)
#endif

#undef ATTR_PACKED

#endif