Added some missing definitions.
[wine/multimedia.git] / dlls / ddraw / convert.c
blob386e1c5bd928bba705230d919e29276320bab3b2
1 #include "ddraw_private.h"
2 #include "debugtools.h"
4 DEFAULT_DEBUG_CHANNEL(ddraw);
6 /* *************************************
7 16 / 15 bpp to palettized 8 bpp
8 ************************************* */
9 static void pixel_convert_16_to_8(void *src, void *dst, DWORD width, DWORD height, LONG pitch, IDirectDrawPaletteImpl* palette) {
10 unsigned char *c_src = (unsigned char *) src;
11 unsigned short *c_dst = (unsigned short *) dst;
12 int y;
14 if (palette != NULL) {
15 const unsigned int * pal = (unsigned int *) palette->screen_palents;
17 for (y = height; y--; ) {
18 #if defined(__i386__) && defined(__GNUC__)
19 /* gcc generates slightly inefficient code for the the copy/lookup,
20 * it generates one excess memory access (to pal) per pixel. Since
21 * we know that pal is not modified by the memory write we can
22 * put it into a register and reduce the number of memory accesses
23 * from 4 to 3 pp. There are two xor eax,eax to avoid pipeline
24 * stalls. (This is not guaranteed to be the fastest method.)
26 __asm__ __volatile__(
27 "xor %%eax,%%eax\n"
28 "1:\n"
29 " lodsb\n"
30 " movw (%%edx,%%eax,4),%%ax\n"
31 " stosw\n"
32 " xor %%eax,%%eax\n"
33 " loop 1b\n"
34 : "=S" (c_src), "=D" (c_dst)
35 : "S" (c_src), "D" (c_dst) , "c" (width), "d" (pal)
36 : "eax", "cc", "memory"
38 c_src+=(pitch-width);
39 #else
40 unsigned char * srclineend = c_src+width;
41 while (c_src < srclineend)
42 *c_dst++ = pal[*c_src++];
43 c_src+=(pitch-width);
44 #endif
46 } else {
47 FIXME("No palette set...\n");
48 memset(dst, 0, width * height * 2);
51 static void palette_convert_16_to_8(
52 LPPALETTEENTRY palent, void *screen_palette, DWORD start, DWORD count
53 ) {
54 int i;
55 unsigned int *pal = (unsigned int *) screen_palette;
57 for (i = 0; i < count; i++)
58 pal[start + i] = (((((unsigned short) palent[i].peRed) & 0xF8) << 8) |
59 ((((unsigned short) palent[i].peBlue) & 0xF8) >> 3) |
60 ((((unsigned short) palent[i].peGreen) & 0xFC) << 3));
63 static void palette_convert_15_to_8(
64 LPPALETTEENTRY palent, void *screen_palette, DWORD start, DWORD count
65 ) {
66 int i;
67 unsigned int *pal = (unsigned int *) screen_palette;
69 for (i = 0; i < count; i++)
70 pal[start + i] = (((((unsigned short) palent[i].peRed) & 0xF8) << 7) |
71 ((((unsigned short) palent[i].peBlue) & 0xF8) >> 3) |
72 ((((unsigned short) palent[i].peGreen) & 0xF8) << 2));
75 /* *************************************
76 24 to palettized 8 bpp
77 ************************************* */
78 static void pixel_convert_24_to_8(
79 void *src, void *dst, DWORD width, DWORD height, LONG pitch,
80 IDirectDrawPaletteImpl* palette
81 ) {
82 unsigned char *c_src = (unsigned char *) src;
83 unsigned char *c_dst = (unsigned char *) dst;
84 int y;
86 if (palette != NULL) {
87 const unsigned int *pal = (unsigned int *) palette->screen_palents;
89 for (y = height; y--; ) {
90 unsigned char * srclineend = c_src+width;
91 while (c_src < srclineend ) {
92 register long pixel = pal[*c_src++];
93 *c_dst++ = pixel;
94 *c_dst++ = pixel>>8;
95 *c_dst++ = pixel>>16;
97 c_src+=(pitch-width);
99 } else {
100 FIXME("No palette set...\n");
101 memset(dst, 0, width * height * 3);
105 /* *************************************
106 32 bpp to palettized 8 bpp
107 ************************************* */
108 static void pixel_convert_32_to_8(
109 void *src, void *dst, DWORD width, DWORD height, LONG pitch,
110 IDirectDrawPaletteImpl* palette
112 unsigned char *c_src = (unsigned char *) src;
113 unsigned int *c_dst = (unsigned int *) dst;
114 int y;
116 if (palette != NULL) {
117 const unsigned int *pal = (unsigned int *) palette->screen_palents;
119 for (y = height; y--; ) {
120 #if defined(__i386__) && defined(__GNUC__)
121 /* See comment in pixel_convert_16_to_8 */
122 __asm__ __volatile__(
123 "xor %%eax,%%eax\n"
124 "1:\n"
125 " lodsb\n"
126 " movl (%%edx,%%eax,4),%%eax\n"
127 " stosl\n"
128 " xor %%eax,%%eax\n"
129 " loop 1b\n"
130 : "=S" (c_src), "=D" (c_dst)
131 : "S" (c_src), "D" (c_dst) , "c" (width), "d" (pal)
132 : "eax", "cc", "memory"
134 c_src+=(pitch-width);
135 #else
136 unsigned char * srclineend = c_src+width;
137 while (c_src < srclineend )
138 *c_dst++ = pal[*c_src++];
139 c_src+=(pitch-width);
140 #endif
142 } else {
143 FIXME("No palette set...\n");
144 memset(dst, 0, width * height * 4);
148 static void palette_convert_24_to_8(
149 LPPALETTEENTRY palent, void *screen_palette, DWORD start, DWORD count
151 int i;
152 unsigned int *pal = (unsigned int *) screen_palette;
154 for (i = 0; i < count; i++)
155 pal[start + i] = ((((unsigned int) palent[i].peRed) << 16) |
156 (((unsigned int) palent[i].peGreen) << 8) |
157 ((unsigned int) palent[i].peBlue));
160 /* *************************************
161 16 bpp to 15 bpp
162 ************************************* */
163 static void pixel_convert_15_to_16(
164 void *src, void *dst, DWORD width, DWORD height, LONG pitch,
165 IDirectDrawPaletteImpl* palette
167 unsigned short *c_src = (unsigned short *) src;
168 unsigned short *c_dst = (unsigned short *) dst;
169 int y;
171 for (y = height; y--; ) {
172 unsigned short * srclineend = c_src+width;
173 while (c_src < srclineend ) {
174 unsigned short val = *c_src++;
175 *c_dst++=((val&0xFFC0)>>1)|(val&0x001f);
177 c_src+=((pitch/2)-width);
181 /* *************************************
182 32 bpp to 16 bpp
183 ************************************* */
184 static void pixel_convert_32_to_16(
185 void *src, void *dst, DWORD width, DWORD height, LONG pitch,
186 IDirectDrawPaletteImpl* palette
188 unsigned short *c_src = (unsigned short *) src;
189 unsigned int *c_dst = (unsigned int *) dst;
190 int y;
192 for (y = height; y--; ) {
193 unsigned short * srclineend = c_src+width;
194 while (c_src < srclineend ) {
195 *c_dst++ = (((*c_src & 0xF800) << 8) |
196 ((*c_src & 0x07E0) << 5) |
197 ((*c_src & 0x001F) << 3));
198 c_src++;
200 c_src+=((pitch/2)-width);
204 /* *************************************
205 32 bpp to 24 bpp
206 ************************************* */
207 static void pixel_convert_32_to_24(
208 void *src, void *dst, DWORD width, DWORD height, LONG pitch,
209 IDirectDrawPaletteImpl* palette
211 unsigned char *c_src = (unsigned char *) src;
212 unsigned int *c_dst = (unsigned int *) dst;
213 int y;
215 for (y = height; y--; ) {
216 unsigned char * srclineend = c_src+width*3;
217 while (c_src < srclineend ) {
218 /* FIXME: wrong for big endian */
219 memcpy(c_dst,c_src,3);
220 c_src+=3;
221 c_dst++;
223 c_src+=pitch-width*3;
227 Convert ModeEmulations[7] = {
228 { { 32, 24, 0x00FF0000, 0x0000FF00, 0x000000FF }, { 24, 24, 0xFF0000, 0x0000FF00, 0x00FF }, { pixel_convert_32_to_24, NULL } },
229 { { 32, 24, 0x00FF0000, 0x0000FF00, 0x000000FF }, { 8, 8, 0x00, 0x00, 0x00 }, { pixel_convert_32_to_8, palette_convert_24_to_8 } },
230 { { 32, 24, 0x00FF0000, 0x0000FF00, 0x000000FF }, { 16, 16, 0xF800, 0x07E0, 0x001F }, { pixel_convert_32_to_16, NULL } },
231 { { 24, 24, 0xFF0000, 0x00FF00, 0x0000FF }, { 8, 8, 0x00, 0x00, 0x00 }, { pixel_convert_24_to_8, palette_convert_24_to_8 } },
232 { { 16, 15, 0x7C00, 0x03E0, 0x001F }, { 16,16, 0xf800, 0x07e0, 0x001f }, { pixel_convert_15_to_16, NULL } },
233 { { 16, 16, 0xF800, 0x07E0, 0x001F }, { 8, 8, 0x00, 0x00, 0x00 }, { pixel_convert_16_to_8, palette_convert_16_to_8 } },
234 { { 16, 15, 0x7C00, 0x03E0, 0x001F }, { 8, 8, 0x00, 0x00, 0x00 }, { pixel_convert_16_to_8, palette_convert_15_to_8 } },