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