]>
Dogcows Code - chaz/openbox/blob - render/image.c
2 #include "../kernel/geom.h"
5 void image_draw(pixel32
*target
, TextureRGBA
*rgba
, Rect
*position
)
7 unsigned long *draw
= rgba
->data
;
9 unsigned int i
, e
, bgi
;
10 sfw
= position
->width
;
11 sfh
= position
->height
;
13 g_assert(rgba
->data
!= NULL
);
15 if ((rgba
->width
!= sfw
|| rgba
->height
!= sfh
) &&
16 (rgba
->width
!= rgba
->cwidth
|| rgba
->height
!= rgba
->cheight
)) {
17 double dx
= rgba
->width
/ (double)sfw
;
18 double dy
= rgba
->height
/ (double)sfh
;
23 /* scale it and cache it */
24 if (rgba
->cache
!= NULL
)
26 rgba
->cache
= g_new(unsigned long, sfw
* sfh
);
29 for (i
= 0, c
= 0, e
= sfw
*sfh
; i
< e
; ++i
) {
30 rgba
->cache
[i
] = rgba
->data
[(int)px
+ iy
];
35 iy
= (int)py
* rgba
->width
;
40 /* do we use the cache we may have just created, or the original? */
41 if (rgba
->width
!= sfw
|| rgba
->height
!= sfh
)
44 /* apply the alpha channel */
45 for (i
= 0, c
= 0, e
= sfw
*sfh
; i
< e
; ++i
, ++bgi
) {
46 unsigned char alpha
= draw
[i
] >> 24;
47 unsigned char r
= draw
[i
] >> 16;
48 unsigned char g
= draw
[i
] >> 8;
49 unsigned char b
= draw
[i
];
51 /* background color */
52 unsigned char bgr
= target
[i
] >> default_red_shift
;
53 unsigned char bgg
= target
[i
] >> default_green_shift
;
54 unsigned char bgb
= target
[i
] >> default_blue_shift
;
56 r
= bgr
+ (((r
- bgr
) * alpha
) >> 8);
57 g
= bgg
+ (((g
- bgg
) * alpha
) >> 8);
58 b
= bgb
+ (((b
- bgb
) * alpha
) >> 8);
60 target
[i
] = (r
<< default_red_shift
) | (g
<< default_green_shift
) |
61 (b
<< default_blue_shift
);
This page took 0.040429 seconds and 4 git commands to generate.