FreeBASIC  0.91.0
gfx_blitter.c
Go to the documentation of this file.
1 /* blitter functions for different color depths */
2 
3 #include "fb_gfx.h"
4 
5 #ifdef HOST_X86
6 /* MMX functions declarations */
7 extern void fb_hBlit8to15RGBMMX(unsigned char *dest, int pitch);
8 extern void fb_hBlit8to15BGRMMX(unsigned char *dest, int pitch);
9 extern void fb_hBlit8to16RGBMMX(unsigned char *dest, int pitch);
10 extern void fb_hBlit8to16BGRMMX(unsigned char *dest, int pitch);
11 extern void fb_hBlit8to24RGBMMX(unsigned char *dest, int pitch);
12 extern void fb_hBlit8to24BGRMMX(unsigned char *dest, int pitch);
13 extern void fb_hBlit8to32RGBMMX(unsigned char *dest, int pitch);
14 extern void fb_hBlit8to32BGRMMX(unsigned char *dest, int pitch);
15 extern void fb_hBlit16to15RGBMMX(unsigned char *dest, int pitch);
16 extern void fb_hBlit16to15BGRMMX(unsigned char *dest, int pitch);
17 extern void fb_hBlit16to16RGBMMX(unsigned char *dest, int pitch);
18 extern void fb_hBlit16to24MMX(unsigned char *dest, int pitch);
19 extern void fb_hBlit16to32MMX(unsigned char *dest, int pitch);
20 extern void fb_hBlit32to15RGBMMX(unsigned char *dest, int pitch);
21 extern void fb_hBlit32to15BGRMMX(unsigned char *dest, int pitch);
22 extern void fb_hBlit32to16RGBMMX(unsigned char *dest, int pitch);
23 extern void fb_hBlit32to16BGRMMX(unsigned char *dest, int pitch);
24 extern void fb_hBlit32to24RGBMMX(unsigned char *dest, int pitch);
25 extern void fb_hBlit32to24BGRMMX(unsigned char *dest, int pitch);
26 extern void fb_hBlit32to32RGBMMX(unsigned char *dest, int pitch);
27 #endif
28 
29 void fb_hBlit_code_start(void) { }
30 
31 /*:::::*/
32 static void fb_hBlitCopy(unsigned char *dest, int pitch)
33 {
34  unsigned char *src = __fb_gfx->framebuffer;
35  char *dirty = __fb_gfx->dirty;
36  int y, z = 0;
37 
38  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
39  if (*dirty)
40  fb_hMemCpy(dest, src, __fb_gfx->pitch);
41  z++;
42  if (z >= __fb_gfx->scanline_size) {
43  z = 0;
44  dirty++;
45  src += __fb_gfx->pitch;
46  }
47  dest += pitch;
48  }
49 }
50 
51 
52 /*:::::*/
53 static void fb_hBlit8to15RGB(unsigned char *dest, int pitch)
54 {
55  unsigned int *pal = __fb_gfx->device_palette;
56  unsigned char *s, *src = __fb_gfx->framebuffer;
57  unsigned int c1, c2, *d;
58  char *dirty = __fb_gfx->dirty;
59  int x, y, z = 0;
60 
61  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
62  if (*dirty) {
63  s = src;
64  d = (unsigned int *)dest;
65  for (x = __fb_gfx->w >> 1; x; x--) {
66  c1 = pal[*s];
67  c2 = pal[*(s + 1)];
68  *d = ((c1 >> 3) & 0x001F) | ((c1 >> 6) & 0x03E0) | ((c1 >> 6) & 0x7C00) |
69  (((c2 >> 3) & 0x001F) | ((c2 >> 6) & 0x03E0) | ((c2 >> 6) & 0x7C00) << 16);
70  s += 2;
71  d++;
72  }
73  if (__fb_gfx->w & 0x1) {
74  c1 = pal[*s];
75  *(unsigned short *)d = ((c1 >> 3) & 0x001F) | ((c1 >> 6) & 0x03E0) | ((c1 >> 6) & 0x7C00);
76  }
77  }
78  z++;
79  if (z >= __fb_gfx->scanline_size) {
80  z = 0;
81  dirty++;
82  src += __fb_gfx->pitch;
83  }
84  dest += pitch;
85  }
86 }
87 
88 
89 /*:::::*/
90 static void fb_hBlit8to15BGR(unsigned char *dest, int pitch)
91 {
92  unsigned int *pal = __fb_gfx->device_palette;
93  unsigned char *s, *src = __fb_gfx->framebuffer;
94  unsigned int c1, c2, *d;
95  char *dirty = __fb_gfx->dirty;
96  int x, y, z = 0;
97 
98  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
99  if (*dirty) {
100  s = src;
101  d = (unsigned int *)dest;
102  for (x = __fb_gfx->w >> 1; x; x--) {
103  c1 = pal[*s];
104  c2 = pal[*(s + 1)];
105  *d = ((c1 << 7) & 0x7C00) | ((c1 >> 6) & 0x03E0) | ((c1 >> 19) & 0x001F) |
106  ((((c2 << 7) & 0x7C00) | ((c2 >> 6) & 0x03E0) | ((c2 >> 19) & 0x001F)) << 16);
107  s += 2;
108  d++;
109  }
110  if (__fb_gfx->w & 0x1) {
111  c1 = pal[*s];
112  *(unsigned short *)d = ((c1 << 7) & 0x7C00) | ((c1 >> 6) & 0x03E0) | ((c1 >> 19) & 0x001F);
113  }
114  }
115  z++;
116  if (z >= __fb_gfx->scanline_size) {
117  z = 0;
118  dirty++;
119  src += __fb_gfx->pitch;
120  }
121  dest += pitch;
122  }
123 }
124 
125 
126 /*:::::*/
127 static void fb_hBlit8to16RGB(unsigned char *dest, int pitch)
128 {
129  unsigned int *pal = __fb_gfx->device_palette;
130  unsigned char *s, *src = __fb_gfx->framebuffer;
131  unsigned int c1, c2, *d;
132  char *dirty = __fb_gfx->dirty;
133  int x, y, z = 0;
134 
135  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
136  if (*dirty) {
137  s = src;
138  d = (unsigned int *)dest;
139  for (x = __fb_gfx->w >> 1; x; x--) {
140  c1 = pal[*s];
141  c2 = pal[*(s + 1)];
142  *d = ((c1 >> 3) & 0x001F) | ((c1 >> 5) & 0x07E0) | ((c1 >> 5) & 0xF800) |
143  (((c2 >> 3) & 0x001F) | ((c2 >> 5) & 0x07E0) | ((c2 >> 5) & 0xF800) << 16);
144  s += 2;
145  d++;
146  }
147  if (__fb_gfx->w & 0x1) {
148  c1 = pal[*s];
149  *(unsigned short *)d = ((c1 >> 3) & 0x001F) | ((c1 >> 5) & 0x07E0) | ((c1 >> 5) & 0xF800);
150  }
151  }
152  z++;
153  if (z >= __fb_gfx->scanline_size) {
154  z = 0;
155  dirty++;
156  src += __fb_gfx->pitch;
157  }
158  dest += pitch;
159  }
160 }
161 
162 
163 /*:::::*/
164 static void fb_hBlit8to16BGR(unsigned char *dest, int pitch)
165 {
166  unsigned int *pal = __fb_gfx->device_palette;
167  unsigned char *s, *src = __fb_gfx->framebuffer;
168  unsigned int c1, c2, *d;
169  char *dirty = __fb_gfx->dirty;
170  int x, y, z = 0;
171 
172  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
173  if (*dirty) {
174  s = src;
175  d = (unsigned int *)dest;
176  for (x = __fb_gfx->w >> 1; x; x--) {
177  c1 = pal[*s];
178  c2 = pal[*(s + 1)];
179  *d = ((c1 << 8) & 0xF800) | ((c1 >> 5) & 0x07E0) | ((c1 >> 19) & 0x001F) |
180  ((((c2 << 8) & 0xF800) | ((c2 >> 5) & 0x07E0) | ((c2 >> 19) & 0x001F)) << 16);
181  s += 2;
182  d++;
183  }
184  if (__fb_gfx->w & 0x1) {
185  c1 = pal[*s];
186  *(unsigned short *)d = ((c1 << 8) & 0xF800) | ((c1 >> 5) & 0x07E0) | ((c1 >> 19) & 0x001F);
187  }
188  }
189  z++;
190  if (z >= __fb_gfx->scanline_size) {
191  z = 0;
192  dirty++;
193  src += __fb_gfx->pitch;
194  }
195  dest += pitch;
196  }
197 }
198 
199 
200 /*:::::*/
201 static void fb_hBlit8to24RGB(unsigned char *dest, int pitch)
202 {
203  unsigned int *pal = __fb_gfx->device_palette;
204  unsigned char *s, *src = __fb_gfx->framebuffer;
205  unsigned int c;
206  unsigned char *d;
207  char *dirty = __fb_gfx->dirty;
208  int x, y, z = 0;
209 
210  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
211  if (*dirty) {
212  s = src;
213  d = (unsigned char *)dest;
214  for (x = __fb_gfx->w; x; x--) {
215  c = pal[*s];
216  d[0] = (c >> 16) & 0xFF;
217  d[1] = (c >> 8) & 0xFF;
218  d[2] = c & 0xFF;
219  s++;
220  d += 3;
221  }
222  }
223  z++;
224  if (z >= __fb_gfx->scanline_size) {
225  z = 0;
226  dirty++;
227  src += __fb_gfx->pitch;
228  }
229  dest += pitch;
230  }
231 }
232 
233 
234 /*:::::*/
235 static void fb_hBlit8to24BGR(unsigned char *dest, int pitch)
236 {
237  unsigned int *pal = __fb_gfx->device_palette;
238  unsigned char *s, *src = __fb_gfx->framebuffer;
239  unsigned int c;
240  unsigned char *d;
241  char *dirty = __fb_gfx->dirty;
242  int x, y, z = 0;
243 
244  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
245  if (*dirty) {
246  s = src;
247  d = (unsigned char *)dest;
248  for (x = __fb_gfx->w; x; x--) {
249  c = pal[*s];
250  d[0] = c & 0xFF;
251  d[1] = (c >> 8) & 0xFF;
252  d[2] = (c >> 16) & 0xFF;
253  s++;
254  d += 3;
255  }
256  }
257  z++;
258  if (z >= __fb_gfx->scanline_size) {
259  z = 0;
260  dirty++;
261  src += __fb_gfx->pitch;
262  }
263  dest += pitch;
264  }
265 }
266 
267 
268 /*:::::*/
269 static void fb_hBlit8to32RGB(unsigned char *dest, int pitch)
270 {
271  unsigned int *pal = __fb_gfx->device_palette;
272  unsigned int *d;
273  unsigned char *s, *src = __fb_gfx->framebuffer;
274  char *dirty = __fb_gfx->dirty;
275  int x, y, z = 0;
276 
277  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
278  if (*dirty) {
279  s = src;
280  d = (unsigned int *)dest;
281  for (x = __fb_gfx->w; x; x--) {
282  *d = pal[*s];
283  s++;
284  d++;
285  }
286  }
287  z++;
288  if (z >= __fb_gfx->scanline_size) {
289  z = 0;
290  dirty++;
291  src += __fb_gfx->pitch;
292  }
293  dest += pitch;
294  }
295 }
296 
297 
298 /*:::::*/
299 static void fb_hBlit8to32BGR(unsigned char *dest, int pitch)
300 {
301  unsigned int *pal = __fb_gfx->device_palette;
302  unsigned int *d;
303  unsigned char *s, *src = __fb_gfx->framebuffer;
304  unsigned int c;
305  char *dirty = __fb_gfx->dirty;
306  int x, y, z = 0;
307 
308  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
309  if (*dirty) {
310  s = src;
311  d = (unsigned int *)dest;
312  for (x = __fb_gfx->w; x; x--) {
313  c = pal[*s];
314  *d = ((c << 16) & 0xFF0000) | (c & 0xFF00) | (c >> 16);
315  s++;
316  d++;
317  }
318  }
319  z++;
320  if (z >= __fb_gfx->scanline_size) {
321  z = 0;
322  dirty++;
323  src += __fb_gfx->pitch;
324  }
325  dest += pitch;
326  }
327 }
328 
329 
330 /*:::::*/
331 static void fb_hBlit16to15RGB(unsigned char *dest, int pitch)
332 {
333  unsigned int *d;
334  unsigned short *s;
335  unsigned char *src = __fb_gfx->framebuffer;
336  unsigned int c1, c2;
337  char *dirty = __fb_gfx->dirty;
338  int x, y, z = 0;
339 
340  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
341  if (*dirty) {
342  s = (unsigned short *)src;
343  d = (unsigned int *)dest;
344  for (x = __fb_gfx->w >> 1; x; x--) {
345  c1 = *s;
346  c2 = *(s + 1);
347  *d = ((c1 << 10) & 0x7C00) | ((c1 >> 1) & 0x03E0) | (c1 >> 11) |
348  ((((c2 << 10) & 0x7C00) | ((c2 >> 1) & 0x03E0) | (c2 >> 11)) << 16);
349  s += 2;
350  d++;
351  }
352  if (__fb_gfx->w & 0x1) {
353  c1 = *s;
354  *(unsigned short *)d = ((c1 << 10) & 0x7C00) | ((c1 >> 1) & 0x03E0) | (c1 >> 11);
355  }
356  }
357  z++;
358  if (z >= __fb_gfx->scanline_size) {
359  z = 0;
360  dirty++;
361  src += __fb_gfx->pitch;
362  }
363  dest += pitch;
364  }
365 }
366 
367 
368 /*:::::*/
369 static void fb_hBlit16to15BGR(unsigned char *dest, int pitch)
370 {
371  unsigned int *d;
372  unsigned short *s;
373  unsigned char *src = __fb_gfx->framebuffer;
374  unsigned int c1, c2;
375  char *dirty = __fb_gfx->dirty;
376  int x, y, z = 0;
377 
378  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
379  if (*dirty) {
380  s = (unsigned short *)src;
381  d = (unsigned int *)dest;
382  for (x = __fb_gfx->w >> 1; x; x--) {
383  c1 = *s;
384  c2 = *(s + 1);
385  *d = (c1 & 0x001F) | ((c1 >> 1) & 0x7FE0) |
386  (((c2 & 0x001F) | ((c2 >> 1) & 0x7FE0)) << 16);
387  s += 2;
388  d++;
389  }
390  if (__fb_gfx->w & 0x1) {
391  c1 = *s;
392  *(unsigned short *)d = (c1 & 0x001F) | ((c1 >> 1) & 0x7FE0);
393  }
394  }
395  z++;
396  if (z >= __fb_gfx->scanline_size) {
397  z = 0;
398  dirty++;
399  src += __fb_gfx->pitch;
400  }
401  dest += pitch;
402  }
403 }
404 
405 
406 /*:::::*/
407 static void fb_hBlit16to16RGB(unsigned char *dest, int pitch)
408 {
409  unsigned int *d;
410  unsigned short *s;
411  unsigned char *src = __fb_gfx->framebuffer;
412  unsigned int c1, c2;
413  char *dirty = __fb_gfx->dirty;
414  int x, y, z = 0;
415 
416  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
417  if (*dirty) {
418  s = (unsigned short *)src;
419  d = (unsigned int *)dest;
420  for (x = __fb_gfx->w >> 1; x; x--) {
421  c1 = *s;
422  c2 = *(s + 1);
423  *d = ((c1 << 11) & 0xF800) | (c1 & 0x07E0) | (c1 >> 11) |
424  ((((c2 << 11) & 0xF800) | (c2 & 0x07E0) | (c2 >> 11)) << 16);
425  s += 2;
426  d++;
427  }
428  if (__fb_gfx->w & 0x1) {
429  c1 = *s;
430  *(unsigned short *)d = ((c1 << 11) & 0xF800) | (c1 & 0x07E0) | (c1 >> 11);
431  }
432  }
433  z++;
434  if (z >= __fb_gfx->scanline_size) {
435  z = 0;
436  dirty++;
437  src += __fb_gfx->pitch;
438  }
439  dest += pitch;
440  }
441 }
442 
443 
444 /*:::::*/
445 static void fb_hBlit16to24(unsigned char *dest, int pitch)
446 {
447  unsigned char *src = __fb_gfx->framebuffer;
448  unsigned int *s, *d, c1, c2, c3, temp;
449  unsigned short *ss;
450  unsigned char *dc;
451  char *dirty = __fb_gfx->dirty;
452  int x, y, z = 0;
453 
454  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
455  if (*dirty) {
456  s = (unsigned int *)src;
457  d = (unsigned int *)dest;
458  for (x = __fb_gfx->w >> 2; x; x--) {
459  c1 = __fb_color_conv_16to32[*s & 0xFF] | __fb_color_conv_16to32[256 + ((*s >> 8) & 0xFF)];
460  temp = __fb_color_conv_16to32[(*s >> 16) & 0xFF] | __fb_color_conv_16to32[256 + ((*s >> 24) & 0xFF)];
461  *d++ = c1 | (temp << 24);
462  c2 = temp >> 8;
463  s++;
464  temp = __fb_color_conv_16to32[*s & 0xFF] | __fb_color_conv_16to32[256 + ((*s >> 8) & 0xFF)];
465  *d++ = c2 | (temp << 16);
466  c3 = temp >> 16;
467  *d++ = c3 | ((__fb_color_conv_16to32[(*s >> 16) & 0xFF] | __fb_color_conv_16to32[256 + ((*s >> 24) & 0xFF)]) << 8);
468  s++;
469  }
470  dc = (unsigned char *)d;
471  if (__fb_gfx->w & 0x2) {
472  c1 = __fb_color_conv_16to32[*s & 0xFF] | __fb_color_conv_16to32[256 + ((*s >> 8) & 0xFF)];
473  c2 = __fb_color_conv_16to32[(*s >> 16) & 0xFF] | __fb_color_conv_16to32[256 + ((*s >> 24) & 0xFF)];
474  dc[0] = (c1 >> 16) & 0xFF;
475  dc[1] = (c1 >> 8) & 0xFF;
476  dc[2] = c1 & 0xFF;
477  dc[3] = (c2 >> 16) & 0xFF;
478  dc[4] = (c2 >> 8) & 0xFF;
479  dc[5] = c2 & 0xFF;
480  dc += 6;
481  s++;
482  }
483  if (__fb_gfx->w & 0x1) {
484  ss = (unsigned short *)s;
485  c1 = __fb_color_conv_16to32[*ss & 0xFF] | __fb_color_conv_16to32[256 + ((*ss >> 8) & 0xFF)];
486  dc[0] = (c1 >> 16) & 0xFF;
487  dc[1] = (c1 >> 8) & 0xFF;
488  dc[2] = c1 & 0xFF;
489  }
490  }
491  z++;
492  if (z >= __fb_gfx->scanline_size) {
493  z = 0;
494  dirty++;
495  src += __fb_gfx->pitch;
496  }
497  dest += pitch;
498  }
499 }
500 
501 
502 /*:::::*/
503 static void fb_hBlit16to32(unsigned char *dest, int pitch)
504 {
505  unsigned int *d, *s;
506  unsigned char *src = __fb_gfx->framebuffer;
507  unsigned int c;
508  char *dirty = __fb_gfx->dirty;
509  int x, y, z = 0;
510 
511  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
512  if (*dirty) {
513  s = (unsigned int *)src;
514  d = (unsigned int *)dest;
515  for (x = __fb_gfx->w >> 1; x; x--) {
516  c = *s++;
517  *d++ = __fb_color_conv_16to32[c & 0xFF] | __fb_color_conv_16to32[256 + ((c >> 8) & 0xFF)];
518  *d++ = __fb_color_conv_16to32[(c >> 16) & 0xFF] | __fb_color_conv_16to32[256 + ((c >> 24) & 0xFF)];
519  }
520  if (__fb_gfx->w & 0x1) {
521  c = *(unsigned short *)s;
522  *d = __fb_color_conv_16to32[c & 0xFF] | __fb_color_conv_16to32[256 + ((c >> 8) & 0xFF)];
523  }
524  }
525  z++;
526  if (z >= __fb_gfx->scanline_size) {
527  z = 0;
528  dirty++;
529  src += __fb_gfx->pitch;
530  }
531  dest += pitch;
532  }
533 }
534 
535 
536 /*:::::*/
537 static void fb_hBlit32to15RGB(unsigned char *dest, int pitch)
538 {
539  unsigned int *d, *s;
540  unsigned char *src = __fb_gfx->framebuffer;
541  unsigned int c1, c2;
542  char *dirty = __fb_gfx->dirty;
543  int x, y, z = 0;
544 
545  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
546  if (*dirty) {
547  s = (unsigned int *)src;
548  d = (unsigned int *)dest;
549  for (x = __fb_gfx->w >> 1; x; x--) {
550  c1 = *s;
551  c2 = *(s + 1);
552  *d = (c1 >> 19) | ((c1 >> 6) & 0x03E0) | ((c1 << 7) & 0x7C00) |
553  (((c2 >> 19) | ((c2 >> 6) & 0x03E0) | ((c2 << 7) & 0x7C00)) << 16);
554  s += 2;
555  d++;
556  }
557  if (__fb_gfx->w & 0x1) {
558  c1 = *s;
559  *(unsigned short *)d = (c1 >> 19) | ((c1 >> 6) & 0x03E0) | ((c1 << 7) & 0x7C00);
560  }
561  }
562  z++;
563  if (z >= __fb_gfx->scanline_size) {
564  z = 0;
565  dirty++;
566  src += __fb_gfx->pitch;
567  }
568  dest += pitch;
569  }
570 }
571 
572 
573 /*:::::*/
574 static void fb_hBlit32to15BGR(unsigned char *dest, int pitch)
575 {
576  unsigned int *d, *s;
577  unsigned char *src = __fb_gfx->framebuffer;
578  unsigned int c1, c2;
579  char *dirty = __fb_gfx->dirty;
580  int x, y, z = 0;
581 
582  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
583  if (*dirty) {
584  s = (unsigned int *)src;
585  d = (unsigned int *)dest;
586  for (x = __fb_gfx->w >> 1; x; x--) {
587  c1 = *s;
588  c2 = *(s + 1);
589  *d = ((c1 >> 3) & 0x001F) | ((c1 >> 6) & 0x03E0) | ((c1 >> 9) & 0x7C00) |
590  ((((c2 >> 3) & 0x001F) | ((c2 >> 6) & 0x03E0) | ((c2 >> 9) & 0x7C00)) << 16);
591  s += 2;
592  d++;
593  }
594  if (__fb_gfx->w & 0x1) {
595  c1 = *s;
596  *(unsigned short *)d = ((c1 >> 3) & 0x001F) | ((c1 >> 6) & 0x03E0) | ((c1 >> 9) & 0x7C00);
597  }
598  }
599  z++;
600  if (z >= __fb_gfx->scanline_size) {
601  z = 0;
602  dirty++;
603  src += __fb_gfx->pitch;
604  }
605  dest += pitch;
606  }
607 }
608 
609 
610 /*:::::*/
611 static void fb_hBlit32to16RGB(unsigned char *dest, int pitch)
612 {
613  unsigned int *d, *s;
614  unsigned char *src = __fb_gfx->framebuffer;
615  unsigned int c1, c2;
616  char *dirty = __fb_gfx->dirty;
617  int x, y, z = 0;
618 
619  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
620  if (*dirty) {
621  s = (unsigned int *)src;
622  d = (unsigned int *)dest;
623  for (x = __fb_gfx->w >> 1; x; x--) {
624  c1 = *s;
625  c2 = *(s + 1);
626  *d = (c1 >> 19) | ((c1 >> 5) & 0x07E0) | ((c1 << 8) & 0xF800) |
627  (((c2 >> 19) | ((c2 >> 5) & 0x07E0) | ((c2 << 8) & 0xF800)) << 16);
628  s += 2;
629  d++;
630  }
631  if (__fb_gfx->w & 0x1) {
632  c1 = *s;
633  *(unsigned short *)d = (c1 >> 19) | ((c1 >> 5) & 0x07E0) | ((c1 << 8) & 0xF800);
634  }
635  }
636  z++;
637  if (z >= __fb_gfx->scanline_size) {
638  z = 0;
639  dirty++;
640  src += __fb_gfx->pitch;
641  }
642  dest += pitch;
643  }
644 }
645 
646 
647 /*:::::*/
648 static void fb_hBlit32to16BGR(unsigned char *dest, int pitch)
649 {
650  unsigned int *d, *s;
651  unsigned char *src = __fb_gfx->framebuffer;
652  unsigned int c1, c2;
653  char *dirty = __fb_gfx->dirty;
654  int x, y, z = 0;
655 
656  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
657  if (*dirty) {
658  s = (unsigned int *)src;
659  d = (unsigned int *)dest;
660  for (x = __fb_gfx->w >> 1; x; x--) {
661  c1 = *s;
662  c2 = *(s + 1);
663  *d = ((c1 >> 3) & 0x001F) | ((c1 >> 5) & 0x07E0) | ((c1 >> 8) & 0xF800) |
664  ((((c2 >> 3) & 0x001F) | ((c2 >> 5) & 0x07E0) | ((c2 >> 8) & 0xF800)) << 16);
665  s += 2;
666  d++;
667  }
668  if (__fb_gfx->w & 0x1) {
669  c1 = *s;
670  *(unsigned short *)d = ((c1 >> 3) & 0x001F) | ((c1 >> 5) & 0x07E0) | ((c1 >> 8) & 0xF800);
671  }
672  }
673  z++;
674  if (z >= __fb_gfx->scanline_size) {
675  z = 0;
676  dirty++;
677  src += __fb_gfx->pitch;
678  }
679  dest += pitch;
680  }
681 }
682 
683 
684 /*:::::*/
685 static void fb_hBlit32to24RGB(unsigned char *dest, int pitch)
686 {
687  unsigned int *s;
688  unsigned char *src = __fb_gfx->framebuffer;
689  unsigned int c;
690  unsigned char *d;
691  char *dirty = __fb_gfx->dirty;
692  int x, y, z = 0;
693 
694  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
695  if (*dirty) {
696  s = (unsigned int *)src;
697  d = (unsigned char *)dest;
698  for (x = __fb_gfx->w; x; x--) {
699  c = *s;
700  d[0] = (c >> 16) & 0xFF;
701  d[1] = (c >> 8) & 0xFF;
702  d[2] = c & 0xFF;
703  s++;
704  d += 3;
705  }
706  }
707  z++;
708  if (z >= __fb_gfx->scanline_size) {
709  z = 0;
710  dirty++;
711  src += __fb_gfx->pitch;
712  }
713  dest += pitch;
714  }
715 }
716 
717 
718 /*:::::*/
719 static void fb_hBlit32to24BGR(unsigned char *dest, int pitch)
720 {
721  unsigned int *s;
722  unsigned char *src = __fb_gfx->framebuffer;
723  unsigned int c;
724  unsigned char *d;
725  char *dirty = __fb_gfx->dirty;
726  int x, y, z = 0;
727 
728  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
729  if (*dirty) {
730  s = (unsigned int *)src;
731  d = (unsigned char *)dest;
732  for (x = __fb_gfx->w; x; x--) {
733  c = *s;
734  d[0] = c & 0xFF;
735  d[1] = (c >> 8) & 0xFF;
736  d[2] = (c >> 16) & 0xFF;
737  s++;
738  d += 3;
739  }
740  }
741  z++;
742  if (z >= __fb_gfx->scanline_size) {
743  z = 0;
744  dirty++;
745  src += __fb_gfx->pitch;
746  }
747  dest += pitch;
748  }
749 }
750 
751 
752 /*:::::*/
753 static void fb_hBlit32to32RGB(unsigned char *dest, int pitch)
754 {
755  unsigned int *d, *s;
756  unsigned char *src = __fb_gfx->framebuffer;
757  unsigned int c;
758  char *dirty = __fb_gfx->dirty;
759  int x, y, z = 0;
760 
761  for (y = __fb_gfx->h * __fb_gfx->scanline_size; y; y--) {
762  if (*dirty) {
763  s = (unsigned int *)src;
764  d = (unsigned int *)dest;
765  for (x = __fb_gfx->w; x; x--) {
766  c = (*s++) & 0xFFFFFF;
767  *d++ = (c >> 16) | (c & 0xFF00) | (c << 16);
768  }
769  }
770  z++;
771  if (z >= __fb_gfx->scanline_size) {
772  z = 0;
773  dirty++;
774  src += __fb_gfx->pitch;
775  }
776  dest += pitch;
777  }
778 }
779 
780 
781 /*:::::*/
782 BLITTER *fb_hGetBlitter(int device_depth, int is_rgb)
783 {
784  BLITTER *all_blitters[] = {
785  /* RGB (C) */
789  /* BGR (C) */
793 #ifdef HOST_X86
794  /* RGB (MMX) */
795  fb_hBlit8to15RGBMMX, fb_hBlit8to16RGBMMX, fb_hBlit8to24RGBMMX, fb_hBlit8to32RGBMMX,
796  fb_hBlit16to15RGBMMX, fb_hBlit16to16RGBMMX, fb_hBlit16to24MMX, fb_hBlit16to32MMX,
797  fb_hBlit32to15RGBMMX, fb_hBlit32to16RGBMMX, fb_hBlit32to24RGBMMX, fb_hBlit32to32RGBMMX,
798  /* BGR (MMX) */
799  fb_hBlit8to15BGRMMX, fb_hBlit8to16BGRMMX, fb_hBlit8to24BGRMMX, fb_hBlit8to32BGRMMX,
800  fb_hBlit16to15BGRMMX, fb_hBlitCopy, fb_hBlit16to24MMX, fb_hBlit16to32MMX,
801  fb_hBlit32to15BGRMMX, fb_hBlit32to16BGRMMX, fb_hBlit32to24BGRMMX, fb_hBlitCopy,
802 #endif
803  }, **blitter = &all_blitters[0];
804  int i;
805 
806  for (i = 0; i < 256; i++) {
807  if (is_rgb) {
808  __fb_color_conv_16to32[i] = ((i & 0x1F) << 19) | ((i & 0xE0) << 5);
809  __fb_color_conv_16to32[256+i] = ((i & 0x07) << 13) | (i & 0xF8);
810  }
811  else {
812  __fb_color_conv_16to32[i] = ((i & 0x1F) << 3) | ((i & 0xE0) << 5);
813  __fb_color_conv_16to32[256+i] = ((i & 0x07) << 13) | ((i & 0xF8) << 16);
814  }
815  }
816 
817 #ifdef HOST_X86
818  if ((__fb_gfx->flags & HAS_MMX) && (__fb_gfx->scanline_size == 1) && !(__fb_gfx->w & 0x3))
819  blitter = &blitter[24];
820 #endif
821 
822  if (!is_rgb)
823  blitter = &blitter[12];
824 
825  switch (__fb_gfx->depth) {
826  case 1:
827  case 2:
828  case 4:
829  case 8:
830  switch (device_depth) {
831  case 8: return fb_hBlitCopy;
832  case 15: return blitter[0];
833  case 16: return blitter[1];
834  case 24: return blitter[2];
835  case 32: return blitter[3];
836  }
837  break;
838 
839  case 15:
840  case 16:
841  switch (device_depth) {
842  case 15: return blitter[4];
843  case 16: return blitter[5];
844  case 24: return blitter[6];
845  case 32: return blitter[7];
846  }
847  break;
848 
849  case 24:
850  case 32:
851  switch (device_depth) {
852  case 15: return blitter[8];
853  case 16: return blitter[9];
854  case 24: return blitter[10];
855  case 32: return blitter[11];
856  }
857  break;
858  }
859  return NULL;
860 }
861 
862 void fb_hBlit_code_end(void) { }