grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / hidds / graphics / colorconv / rgbconv_macros.h
blob47a435670c0aa2e0bbb0f75e635a76b261354aab
1 /* Pixel formats in AROS have their ID based on the pixel
2 component layout in memory. So vHidd_StdPixFmt_ARGB32
3 means 0xAA 0xRR 0xGG 0xBB in memory. When doing pixel
4 accesses (ULONG in this case) to memory on big endian
5 machines the pixel (ULONG) must in this case be ARGB32,
6 while on little endian machines it must be BGRA32.
8 For pixel conversion routines it might make more sense
9 to have pixel format IDs which are based on the pixel
10 access, so that for an ARGB32 format the pixel (ULONG)
11 can be in ARGB32 format both on little and big endian
12 machines.
14 Therefore the FMT_ stuff below. "OE" means other
15 endianess, ie. byte swapped. */
17 #if AROS_BIG_ENDIAN
18 #define FMT_RGB24 vHidd_StdPixFmt_RGB24
19 #define FMT_BGR24 vHidd_StdPixFmt_BGR24
20 #define FMT_RGB16 vHidd_StdPixFmt_RGB16
21 #define FMT_RGB16OE vHidd_StdPixFmt_RGB16_LE
22 #define FMT_BGR16 vHidd_StdPixFmt_BGR16
23 #define FMT_BGR16OE vHidd_StdPixFmt_BGR16_LE
24 #define FMT_RGB15 vHidd_StdPixFmt_RGB15
25 #define FMT_RGB15OE vHidd_StdPixFmt_RGB15_LE
26 #define FMT_BGR15 vHidd_StdPixFmt_BGR15
27 #define FMT_BGR15OE vHidd_StdPixFmt_BGR15_LE
28 #define FMT_ARGB32 vHidd_StdPixFmt_ARGB32
29 #define FMT_BGRA32 vHidd_StdPixFmt_BGRA32
30 #define FMT_RGBA32 vHidd_StdPixFmt_RGBA32
31 #define FMT_ABGR32 vHidd_StdPixFmt_ABGR32
32 #define FMT_XRGB32 vHidd_StdPixFmt_0RGB32
33 #define FMT_BGRX32 vHidd_StdPixFmt_BGR032
34 #define FMT_RGBX32 vHidd_StdPixFmt_RGB032
35 #define FMT_XBGR32 vHidd_StdPixFmt_0BGR32
36 #else
37 #define FMT_RGB24 vHidd_StdPixFmt_BGR24
38 #define FMT_BGR24 vHidd_StdPixFmt_RGB24
39 #define FMT_RGB16 vHidd_StdPixFmt_RGB16_LE
40 #define FMT_RGB16OE vHidd_StdPixFmt_RGB16
41 #define FMT_BGR16 vHidd_StdPixFmt_BGR16_LE
42 #define FMT_BGR16OE vHidd_StdPixFmt_BGR16
43 #define FMT_RGB15 vHidd_StdPixFmt_RGB15_LE
44 #define FMT_RGB15OE vHidd_StdPixFmt_RGB15
45 #define FMT_BGR15 vHidd_StdPixFmt_BGR15_LE
46 #define FMT_BGR15OE vHidd_StdPixFmt_BGR15
47 #define FMT_ARGB32 vHidd_StdPixFmt_BGRA32
48 #define FMT_BGRA32 vHidd_StdPixFmt_ARGB32
49 #define FMT_RGBA32 vHidd_StdPixFmt_ABGR32
50 #define FMT_ABGR32 vHidd_StdPixFmt_RGBA32
51 #define FMT_XRGB32 vHidd_StdPixFmt_BGR032
52 #define FMT_BGRX32 vHidd_StdPixFmt_0RGB32
53 #define FMT_RGBX32 vHidd_StdPixFmt_0BGR32
54 #define FMT_XBGR32 vHidd_StdPixFmt_RGB032
55 #endif
57 /* Component masks and shifts. Shifts are to left (!) not right, so
58 that most significant component bit becomes bit #31 */
60 #define RGB24_RMASK 0x00FF0000
61 #define RGB24_GMASK 0x0000FF00
62 #define RGB24_BMASK 0x000000FF
63 #define RGB24_RSHIFT 8
64 #define RGB24_GSHIFT 16
65 #define RGB24_BSHIFT 24
66 #define RGB24_BITS 24
68 #define BGR24_RMASK 0x000000FF
69 #define BGR24_GMASK 0x0000FF00
70 #define BGR24_BMASK 0x00FF0000
71 #define BGR24_RSHIFT 24
72 #define BGR24_GSHIFT 16
73 #define BGR24_BSHIFT 8
74 #define BGR24_BITS 24
76 #define RGB16_RMASK 0xF800
77 #define RGB16_GMASK 0x07E0
78 #define RGB16_BMASK 0x001F
79 #define RGB16_RSHIFT 16
80 #define RGB16_GSHIFT 21
81 #define RGB16_BSHIFT 27
82 #define RGB16_BITS 16
84 #define BGR16_RMASK 0x001F
85 #define BGR16_GMASK 0x07E0
86 #define BGR16_BMASK 0xF800
87 #define BGR16_RSHIFT 27
88 #define BGR16_GSHIFT 21
89 #define BGR16_BSHIFT 16
90 #define BGR16_BITS 16
92 #define RGB15_RMASK 0x7C00
93 #define RGB15_GMASK 0x03E0
94 #define RGB15_BMASK 0x001F
95 #define RGB15_RSHIFT 17
96 #define RGB15_GSHIFT 22
97 #define RGB15_BSHIFT 27
98 #define RGB15_BITS 15
100 #define BGR15_RMASK 0x001F
101 #define BGR15_GMASK 0x03E0
102 #define BGR15_BMASK 0x7C00
103 #define BGR15_RSHIFT 27
104 #define BGR15_GSHIFT 22
105 #define BGR15_BSHIFT 17
106 #define BGR15_BITS 15
108 #define ARGB32_RMASK 0x00FF0000
109 #define ARGB32_GMASK 0x0000FF00
110 #define ARGB32_BMASK 0x000000FF
111 #define ARGB32_AMASK 0xFF000000
112 #define ARGB32_RSHIFT 8
113 #define ARGB32_GSHIFT 16
114 #define ARGB32_BSHIFT 24
115 #define ARGB32_ASHIFT 0
116 #define ARGB32_BITS 32
118 #define BGRA32_RMASK 0x0000FF00
119 #define BGRA32_GMASK 0x00FF0000
120 #define BGRA32_BMASK 0xFF000000
121 #define BGRA32_AMASK 0x000000FF
122 #define BGRA32_RSHIFT 16
123 #define BGRA32_GSHIFT 8
124 #define BGRA32_BSHIFT 0
125 #define BGRA32_ASHIFT 24
126 #define BGRA32_BITS 32
128 #define RGBA32_RMASK 0xFF000000
129 #define RGBA32_GMASK 0x00FF0000
130 #define RGBA32_BMASK 0x0000FF00
131 #define RGBA32_AMASK 0x000000FF
132 #define RGBA32_RSHIFT 0
133 #define RGBA32_GSHIFT 8
134 #define RGBA32_BSHIFT 16
135 #define RGBA32_ASHIFT 24
136 #define RGBA32_BITS 32
138 #define ABGR32_RMASK 0x000000FF
139 #define ABGR32_GMASK 0x0000FF00
140 #define ABGR32_BMASK 0x00FF0000
141 #define ABGR32_AMASK 0xFF000000
142 #define ABGR32_RSHIFT 24
143 #define ABGR32_GSHIFT 16
144 #define ABGR32_BSHIFT 8
145 #define ABGR32_ASHIFT 0
146 #define ABGR32_BITS 32
148 #define DOSHIFT(val,shift) (((shift) < 0) ? ((val) << (-(shift))) : ((val) >> (shift)))
150 /* Shift from a pixel format with many bits per component to one with fewer bits per component */
152 #define DOWNSHIFT16(val,src,dst) ((DOSHIFT(val, (dst ## _ ## RSHIFT - src ## _ ## RSHIFT)) & dst ## _ ## RMASK) | \
153 (DOSHIFT(val, (dst ## _ ## GSHIFT - src ## _ ## GSHIFT)) & dst ## _ ## GMASK) | \
154 (DOSHIFT(val, (dst ## _ ## BSHIFT - src ## _ ## BSHIFT)) & dst ## _ ## BMASK) )
156 /* Shift from a pixel format with few bits per component to one with more bits per component */
158 #define UPSHIFT16(val,src,dst) (DOSHIFT((val) & src ## _ ## RMASK, (dst ## _ ## RSHIFT - src ## _ ## RSHIFT)) | \
159 DOSHIFT((val) & src ## _ ## GMASK, (dst ## _ ## GSHIFT - src ## _ ## GSHIFT)) | \
160 DOSHIFT((val) & src ## _ ## BMASK, (dst ## _ ## BSHIFT - src ## _ ## BSHIFT)) )
162 /* Shuffle around components (if src and dst pixfmt use same number of bits per component) */
164 #define SHUFFLE(val,src,dst) DOWNSHIFT16(val,src,dst)
166 #define SHUFFLE32(val,src,dst) ((DOSHIFT(val, (dst ## _ ## RSHIFT - src ## _ ## RSHIFT)) & dst ## _ ## RMASK) | \
167 (DOSHIFT(val, (dst ## _ ## GSHIFT - src ## _ ## GSHIFT)) & dst ## _ ## GMASK) | \
168 (DOSHIFT(val, (dst ## _ ## BSHIFT - src ## _ ## BSHIFT)) & dst ## _ ## BMASK) | \
169 (DOSHIFT(val, (dst ## _ ## ASHIFT - src ## _ ## ASHIFT)) & dst ## _ ## AMASK) )
171 #define SHUFFLE24(val,src,dst) ((DOSHIFT(val, (dst ## _ ## RSHIFT - src ## _ ## RSHIFT)) & dst ## _ ## RMASK) | \
172 (DOSHIFT(val, (dst ## _ ## GSHIFT - src ## _ ## GSHIFT)) & dst ## _ ## GMASK) | \
173 (DOSHIFT(val, (dst ## _ ## BSHIFT - src ## _ ## BSHIFT)) & dst ## _ ## BMASK) )
175 #define COMP8(val,which) ( ((val) & (0xFF << ((3 - which) * 8)) ) >> ((3 - which) * 8) )
177 #if AROS_BIG_ENDIAN
178 #define PUT24(dst,a,b,c) dst[x*3] = (a); dst[x*3+1] = (b); dst[x*3+2] = (c);
179 #define GET24 (src[x * 3] << 16) + (src[x * 3 + 1] << 8) + (src[x * 3 + 2]);
180 #define GET24_INV (src[x * 3]) + (src[x * 3 + 1] << 8) + (src[x * 3 + 2] << 16);
181 #else
182 #define PUT24(dst,a,b,c) dst[x*3] = (c); dst[x*3+1] = (b); dst[x*3+2] = (a);
183 #define GET24 (src[x * 3]) + (src[x * 3 + 1] << 8) + (src[x * 3 + 2] << 16);
184 #define GET24_INV (src[x * 3] << 16) + (src[x * 3 + 1] << 8) + (src[x * 3 + 2]);
185 #endif
187 #define INV16(x) AROS_SWAP_BYTES_WORD(x)
189 #define ARCHCONVERTFUNCP(arch, a, b) \
190 static ULONG convert_ ## a ## _ ## b ## _ ## arch \
191 (APTR srcPixels, ULONG srcMod, HIDDT_StdPixFmt srcPixFmt, \
192 APTR dstPixels, ULONG dstMod, HIDDT_StdPixFmt dstPixFmt, \
193 UWORD width, UWORD height);
195 #define ARCHCONVERTFUNCH(arch, a, b) \
196 static ULONG convert_ ## a ## _ ## b ## _ ## arch \
197 (APTR srcPixels, ULONG srcMod, HIDDT_StdPixFmt srcPixFmt, \
198 APTR dstPixels, ULONG dstMod, HIDDT_StdPixFmt dstPixFmt, \
199 UWORD width, UWORD height) \
202 #define CONVERTFUNC(a,b) ARCHCONVERTFUNCH(generic, a, b)
205 #define CONVERTFUNC_INIT
207 #define CONVERTFUNC_EXIT }