FreeBASIC  0.91.0
gfx_put_alpha.c
Go to the documentation of this file.
1 /* ALPHA drawing method for PUT statement */
2 
3 #include "fb_gfx.h"
4 
5 
6 extern void fb_hPutPSetC(unsigned char *src, unsigned char *dest, int w, int h, int src_pitch, int dest_pitch, int alpha, BLENDER *blender, void *param);
7 
8 #ifdef HOST_X86
9 
10 #include "x86/fb_gfx_mmx.h"
11 
12 extern void fb_hPutPSetMMX(unsigned char *src, unsigned char *dest, int w, int h, int src_pitch, int dest_pitch, int alpha, BLENDER *blender, void *param);
13 extern void fb_hPutAlpha4MMX(unsigned char *src, unsigned char *dest, int w, int h, int src_pitch, int dest_pitch, int alpha, BLENDER *blender, void *param);
14 
15 #endif
16 
17 
18 /*:::::*/
19 static void fb_hPutAlpha4C(unsigned char *src, unsigned char *dest, int w, int h, int src_pitch, int dest_pitch, int alpha, BLENDER *blender, void *param)
20 {
21  unsigned int *s = (unsigned int *)src;
22  unsigned int *d, sc, dc, a, drb, dga, srb, sga;
23  int x;
24 
25  src_pitch = (src_pitch >> 2) - w;
26  for (; h; h--) {
27  d = (unsigned int *)dest;
28  for (x = w; x; x--) {
29  sc = *s++;
30  dc = *d;
31  a = (sc >> 24);
32  srb = sc & MASK_RB_32;
33  sga = sc & MASK_GA_32;
34  drb = dc & MASK_RB_32;
35  dga = dc & MASK_GA_32;
36  srb = ((srb - drb) * a) >> 8;
37  sga = ((sga - dga) >> 8) * a;
38  *d++ = ((drb + srb) & MASK_RB_32) | ((dga + sga) & MASK_GA_32);
39  }
40  s += src_pitch;
41  dest += dest_pitch;
42  }
43 }
44 
45 
46 /*:::::*/
47 void fb_hPutAlpha(unsigned char *src, unsigned char *dest, int w, int h, int src_pitch, int dest_pitch, int alpha, BLENDER *blender, void *param)
48 {
49  static PUTTER *all_putters[] = {
51 #ifdef HOST_X86
52  fb_hPutPSetMMX, fb_hPutPSetMMX, NULL, fb_hPutAlpha4MMX,
53 #endif
54  };
55  PUTTER *putter;
57 
58  if (!context->putter[PUT_MODE_ALPHA]) {
59 #ifdef HOST_X86
60  if (__fb_gfx->flags & HAS_MMX)
61  context->putter[PUT_MODE_ALPHA] = &all_putters[4];
62  else
63 #endif
64  context->putter[PUT_MODE_ALPHA] = &all_putters[0];
65  }
66  putter = context->putter[PUT_MODE_ALPHA][context->target_bpp - 1];
67 
68  putter(src, dest, w, h, src_pitch, dest_pitch, alpha, blender, param);
69 }