summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2012-05-25 21:51:25 -0400
committerKristian Høgsberg <krh@bitplanet.net>2012-05-25 21:51:25 -0400
commit2255eb08164b99605dc4ae126d7545106f66f37b (patch)
tree50dcd88862c11c423ceba08ff929fea508772157
parentb2aa91c1645c6041056da6fe10a992132bff7b15 (diff)
downloadweston-2255eb08164b99605dc4ae126d7545106f66f37b.tar.gz
weston-2255eb08164b99605dc4ae126d7545106f66f37b.tar.bz2
weston-2255eb08164b99605dc4ae126d7545106f66f37b.zip
wcap: Support the other pixel format we may write
-rw-r--r--wcap/vpxenc.c31
-rw-r--r--wcap/wcap-decode.c1
-rw-r--r--wcap/wcap-decode.h1
3 files changed, 23 insertions, 10 deletions
diff --git a/wcap/vpxenc.c b/wcap/vpxenc.c
index 3559a326..7e0c5521 100644
--- a/wcap/vpxenc.c
+++ b/wcap/vpxenc.c
@@ -316,12 +316,22 @@ struct input_state
struct wcap_decoder *wcap;
};
-static inline int rgb_to_yuv(uint32_t p, int *u, int *v)
-{
- int r = (p >> 16) & 0xff;
- int g = (p >> 8) & 0xff;
- int b = (p >> 0) & 0xff;
- int y;
+static inline int rgb_to_yuv(uint32_t format, uint32_t p, int *u, int *v)
+{
+ int r, g, b, y;
+
+ switch (format) {
+ case WCAP_FORMAT_XRGB8888:
+ r = (p >> 16) & 0xff;
+ g = (p >> 8) & 0xff;
+ b = (p >> 0) & 0xff;
+ break;
+ case WCAP_FORMAT_XBGR8888:
+ r = (p >> 0) & 0xff;
+ g = (p >> 8) & 0xff;
+ b = (p >> 16) & 0xff;
+ break;
+ }
y = 0.299 * r + 0.587 * g + 0.114 * b;
if (y > 255)
@@ -348,6 +358,7 @@ static void convert_to_yv12(struct wcap_decoder *wcap, vpx_image_t *img)
unsigned char *y1, *y2, *u, *v;
uint32_t *p1, *p2, *end;
int i, u_accum, v_accum;
+ uint32_t format = wcap->format;
for (i = 0; i < wcap->height; i += 2) {
y1 = img->planes[0] + img->stride[0] * i;
@@ -361,10 +372,10 @@ static void convert_to_yv12(struct wcap_decoder *wcap, vpx_image_t *img)
while (p1 < end) {
u_accum = 0;
v_accum = 0;
- y1[0] = rgb_to_yuv(p1[0], &u_accum, &v_accum);
- y1[1] = rgb_to_yuv(p1[1], &u_accum, &v_accum);
- y2[0] = rgb_to_yuv(p2[0], &u_accum, &v_accum);
- y2[1] = rgb_to_yuv(p2[1], &u_accum, &v_accum);
+ y1[0] = rgb_to_yuv(format, p1[0], &u_accum, &v_accum);
+ y1[1] = rgb_to_yuv(format, p1[1], &u_accum, &v_accum);
+ y2[0] = rgb_to_yuv(format, p2[0], &u_accum, &v_accum);
+ y2[1] = rgb_to_yuv(format, p2[1], &u_accum, &v_accum);
u[0] = clamp_uv(u_accum);
v[0] = clamp_uv(v_accum);
diff --git a/wcap/wcap-decode.c b/wcap/wcap-decode.c
index f6798c62..d6adc332 100644
--- a/wcap/wcap-decode.c
+++ b/wcap/wcap-decode.c
@@ -120,6 +120,7 @@ wcap_decoder_create(const char *filename)
PROT_READ, MAP_PRIVATE, decoder->fd, 0);
header = decoder->map;
+ decoder->format = header->format;
decoder->width = header->width;
decoder->height = header->height;
decoder->p = header + 1;
diff --git a/wcap/wcap-decode.h b/wcap/wcap-decode.h
index 598e490c..8cf45d38 100644
--- a/wcap/wcap-decode.h
+++ b/wcap/wcap-decode.h
@@ -50,6 +50,7 @@ struct wcap_decoder {
size_t size;
void *map, *p, *end;
uint32_t *frame;
+ uint32_t format;
int width, height;
};