-
Notifications
You must be signed in to change notification settings - Fork 80
/
rgba_pixman.c
155 lines (128 loc) · 4.28 KB
/
rgba_pixman.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Copyright (c) 2016 Andreas Baierl <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <string.h>
#include <cedrus/cedrus.h>
#include <sys/ioctl.h>
#include "vdpau_private.h"
#include "rgba_pixman.h"
#include "pixman.h"
static pixman_color_t uint32_to_pcolor(uint32_t color)
{
pixman_color_t pcolor;
/* Fetch 8bit values */
uint16_t alpha = color >> 24;
uint16_t red = color >> 16 & 0xff;
uint16_t green = color >> 8 & 0xff;
uint16_t blue = color & 0xff;
/* Premultiply with alpha value. Pixman only deals with premultiplied alpha. */
red = red * alpha / 255;
green = green * alpha / 255;
blue = blue * alpha / 255;
/* Convert 8bit -> 16bit for pixman */
pcolor.alpha = ((alpha & 0xFF) << 8) | (alpha & 0xFF);
pcolor.red = ((red & 0xFF) << 8) | (red & 0xFF);
pcolor.green = ((green & 0xFF) << 8) | (green & 0xFF);
pcolor.blue = ((blue & 0xFF) << 8) | (blue & 0xFF);
return pcolor;
}
VdpStatus vdp_pixman_ref(rgba_surface_t *rgba)
{
rgba->pimage = pixman_image_create_bits(PIXMAN_a8r8g8b8,
rgba->width, rgba->height,
cedrus_mem_get_pointer(rgba->data),
(rgba->width * 4));
return VDP_STATUS_OK;
}
VdpStatus vdp_pixman_unref(rgba_surface_t *rgba)
{
pixman_image_unref(rgba->pimage);
return VDP_STATUS_OK;
}
VdpStatus vdp_pixman_blit(rgba_surface_t *rgba_dst, const VdpRect *dst_rect,
rgba_surface_t *rgba_src, const VdpRect *src_rect)
{
pixman_image_t *dst;
pixman_image_t *src;
pixman_transform_t transform;
double fscale_x, fscale_y;
int pixman_operator;
dst = rgba_dst->pimage;
src = rgba_src->pimage;
if ((dst_rect->x1 - dst_rect->x0) == 0 ||
(src_rect->x1 - src_rect->x0) == 0 ||
(dst_rect->y1 - dst_rect->y0) == 0 ||
(src_rect->y1 - src_rect->y0) == 0 )
goto zero_size_blit;
/* Transform src_rct to dest_rct size */
fscale_x = (double)(dst_rect->x1 - dst_rect->x0) / (double)(src_rect->x1 - src_rect->x0);
fscale_y = (double)(dst_rect->y1 - dst_rect->y0) / (double)(src_rect->y1 - src_rect->y0);
pixman_transform_init_identity(&transform);
pixman_transform_scale(&transform, NULL,
pixman_double_to_fixed(fscale_x),
pixman_double_to_fixed(fscale_y));
pixman_image_set_transform(src, &transform);
/* Composite to the dest_img */
pixman_operator = (rgba_dst->flags & RGBA_FLAG_NEEDS_CLEAR) ? PIXMAN_OP_SRC : PIXMAN_OP_OVER;
pixman_image_composite32(
pixman_operator, src, NULL, dst,
(src_rect->x0 * fscale_x), (src_rect->y0 * fscale_y),
0, 0,
dst_rect->x0, dst_rect->y0,
(dst_rect->x1 - dst_rect->x0), (dst_rect->y1 - dst_rect->y0));
return VDP_STATUS_OK;
zero_size_blit:
VDPAU_DBG("Zero size blit requested!");
return VDP_STATUS_ERROR;
}
VdpStatus vdp_pixman_fill(rgba_surface_t *rgba_dst, const VdpRect *dst_rect,
uint32_t color)
{
/* Define default values if dst_rect == NULL) */
VdpRect rect = {
.x0 = 0,
.y0 = 0,
.x1 = rgba_dst->width,
.y1 = rgba_dst->height
};
if (dst_rect)
{
rect.x0 = dst_rect->x0;
rect.y0 = dst_rect->y0;
rect.x1 = dst_rect->x1;
rect.y1 = dst_rect->y1;
}
/* Check for zerosized rect */
if ((rect.x1 - rect.x0) == 0 ||
(rect.y1 - rect.y0) == 0)
goto zero_size_fill;
pixman_color_t pcolor = uint32_to_pcolor(color);
pixman_image_t *src = pixman_image_create_solid_fill(&pcolor);
pixman_image_t *dst = rgba_dst->pimage;
/* Composite to the dest_img */
pixman_image_composite32(
PIXMAN_OP_SRC, src, NULL, dst,
0, 0, 0, 0,
rect.x0, rect.y0,
(rect.x1 - rect.x0), (rect.y1 - rect.y0));
pixman_image_unref(src);
return VDP_STATUS_OK;
zero_size_fill:
VDPAU_DBG("Zero size fill requested!");
return VDP_STATUS_ERROR;
}