]>
Dogcows Code - chaz/openbox/blob - render/image.c
1 #include "../kernel/geom.h"
7 void image_draw(pixel32
*target
, RrTextureRGBA
*rgba
, Rect
*area
)
9 pixel32
*draw
= rgba
->data
;
10 gint c
, i
, e
, t
, sfw
, sfh
;
14 g_assert(rgba
->data
!= NULL
);
16 if ((rgba
->width
!= sfw
|| rgba
->height
!= sfh
) &&
17 (rgba
->width
!= rgba
->cwidth
|| rgba
->height
!= rgba
->cheight
)) {
18 double dx
= rgba
->width
/ (double)sfw
;
19 double dy
= rgba
->height
/ (double)sfh
;
24 /* scale it and cache it */
25 if (rgba
->cache
!= NULL
)
27 rgba
->cache
= g_new(pixel32
, sfw
* sfh
);
30 for (i
= 0, c
= 0, e
= sfw
*sfh
; i
< e
; ++i
) {
31 rgba
->cache
[i
] = rgba
->data
[(int)px
+ iy
];
36 iy
= (int)py
* rgba
->width
;
41 /* do we use the cache we may have just created, or the original? */
42 if (rgba
->width
!= sfw
|| rgba
->height
!= sfh
)
45 /* apply the alpha channel */
46 for (i
= 0, c
= 0, t
= area
->x
, e
= sfw
*sfh
; i
< e
; ++i
, ++t
) {
47 guchar alpha
, r
, g
, b
, bgr
, bgg
, bgb
;
49 alpha
= draw
[i
] >> default_alpha_offset
;
50 r
= draw
[i
] >> default_red_offset
;
51 g
= draw
[i
] >> default_green_offset
;
52 b
= draw
[i
] >> default_blue_offset
;
56 t
+= area
->width
- sfw
;
59 /* background color */
60 bgr
= target
[t
] >> default_red_offset
;
61 bgg
= target
[t
] >> default_green_offset
;
62 bgb
= target
[t
] >> default_blue_offset
;
64 r
= bgr
+ (((r
- bgr
) * alpha
) >> 8);
65 g
= bgg
+ (((g
- bgg
) * alpha
) >> 8);
66 b
= bgb
+ (((b
- bgb
) * alpha
) >> 8);
68 target
[t
] = (r
<< default_red_offset
)
69 | (g
<< default_green_offset
)
70 | (b
<< default_blue_offset
);
This page took 0.034375 seconds and 4 git commands to generate.