Skip to content
Commits on Source (7)
......@@ -30,6 +30,7 @@
#include "weston-test-client-helper.h"
#include "weston-test-fixture-compositor.h"
#include "image-iter.h"
#include "color_util.h"
struct setup_args {
......@@ -110,22 +111,14 @@ unpremult_float(struct color_float *cf)
static void
fill_alpha_pattern(struct buffer *buf)
{
void *pixels;
int stride_bytes;
int w, h;
struct image_header ih = image_header_from(buf->image);
int y;
assert(pixman_image_get_format(buf->image) == PIXMAN_a8r8g8b8);
assert(ih.pixman_format == PIXMAN_a8r8g8b8);
assert(ih.width == BLOCK_WIDTH * ALPHA_STEPS);
pixels = pixman_image_get_data(buf->image);
stride_bytes = pixman_image_get_stride(buf->image);
w = pixman_image_get_width(buf->image);
h = pixman_image_get_height(buf->image);
assert(w == BLOCK_WIDTH * ALPHA_STEPS);
for (y = 0; y < h; y++) {
uint32_t *row = pixels + y * stride_bytes;
for (y = 0; y < ih.height; y++) {
uint32_t *row = image_header_get_row_u32(&ih, y);
uint32_t step;
for (step = 0; step < (uint32_t)ALPHA_STEPS; step++) {
......@@ -140,7 +133,6 @@ fill_alpha_pattern(struct buffer *buf)
}
}
static bool
compare_float(float ref, float dst, int x, const char *chan, float *max_diff)
{
......@@ -269,16 +261,12 @@ pixels_monotonic(const uint32_t *row, int x)
static void *
get_middle_row(struct buffer *buf)
{
const int y = (BLOCK_WIDTH - 1) / 2; /* middle row */
void *pixels;
int stride_bytes;
struct image_header ih = image_header_from(buf->image);
assert(pixman_image_get_width(buf->image) >= BLOCK_WIDTH * ALPHA_STEPS);
assert(pixman_image_get_height(buf->image) >= BLOCK_WIDTH);
assert(ih.width >= BLOCK_WIDTH * ALPHA_STEPS);
assert(ih.height >= BLOCK_WIDTH);
pixels = pixman_image_get_data(buf->image);
stride_bytes = pixman_image_get_stride(buf->image);
return pixels + y * stride_bytes;
return image_header_get_row_u32(&ih, (BLOCK_WIDTH - 1) / 2);
}
static bool
......
......@@ -34,6 +34,7 @@
#include "weston-test-client-helper.h"
#include "weston-test-fixture-compositor.h"
#include "color_util.h"
#include "image-iter.h"
#include "lcms_util.h"
struct lcms_pipeline {
......@@ -166,26 +167,6 @@ static const struct setup_args my_setup_args[] = {
{ { "sRGB->adobeRGB" }, 1, &pipeline_adobeRGB, 1, 17, PTYPE_CLUT, 0.0065 },
};
struct image_header {
int width;
int height;
int stride;
int depth;
pixman_format_code_t pix_format;
uint32_t *data;
};
static void
get_image_prop(struct buffer *buf, struct image_header *header)
{
header->width = pixman_image_get_width(buf->image);
header->height = pixman_image_get_height(buf->image);
header->stride = pixman_image_get_stride(buf->image);
header->depth = pixman_image_get_depth(buf->image);
header->pix_format = pixman_image_get_format (buf->image);
header->data = pixman_image_get_data(buf->image);
}
static void
test_roundtrip(uint8_t r, uint8_t g, uint8_t b, cmsPipeline *pip,
struct rgb_diff_stat *stat)
......@@ -486,7 +467,7 @@ fixture_setup(struct weston_test_harness *harness, const struct setup_args *arg)
DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args, meta);
static void
gen_ramp_rgb(const struct image_header *header, int bitwidth, int width_bar)
gen_ramp_rgb(pixman_image_t *image, int bitwidth, int width_bar)
{
static const int hue[][COLOR_CHAN_NUM] = {
{ 1, 1, 1 }, /* White */
......@@ -499,6 +480,7 @@ gen_ramp_rgb(const struct image_header *header, int bitwidth, int width_bar)
};
const int num_hues = ARRAY_LENGTH(hue);
struct image_header ih = image_header_from(image);
float val_max;
int x, y;
int hue_index;
......@@ -511,14 +493,15 @@ gen_ramp_rgb(const struct image_header *header, int bitwidth, int width_bar)
val_max = (1 << bitwidth) - 1;
for (y = 0; y < header->height; y++) {
hue_index = (y * num_hues) / (header->height - 1);
for (y = 0; y < ih.height; y++) {
hue_index = (y * num_hues) / (ih.height - 1);
hue_index = MIN(hue_index, num_hues - 1);
for (x = 0; x < header->width; x++) {
pixel = image_header_get_row_u32(&ih, y);
for (x = 0; x < ih.width; x++, pixel++) {
struct color_float rgb = { .rgb = { 0, 0, 0 } };
value = (float)x / (float)(header->width - 1);
value = (float)x / (float)(ih.width - 1);
if (width_bar > 1)
value = floor(value * n_steps) / n_steps;
......@@ -534,7 +517,6 @@ gen_ramp_rgb(const struct image_header *header, int bitwidth, int width_bar)
g = round(rgb.g * val_max);
b = round(rgb.b * val_max);
pixel = header->data + (y * header->stride / 4) + x;
*pixel = (255U << 24) | (r << 16) | (g << 8) | b;
}
}
......@@ -585,8 +567,8 @@ compare_float(float ref, float dst, int x, const char *chan,
}
static bool
process_pipeline_comparison(const struct image_header *src,
const struct image_header *shot,
process_pipeline_comparison(const struct buffer *src_buf,
const struct buffer *shot_buf,
const struct setup_args * arg)
{
const char *const chan_name[COLOR_CHAN_NUM] = { "r", "g", "b" };
......@@ -595,18 +577,23 @@ process_pipeline_comparison(const struct image_header *src,
float max_allow_diff = arg->tolerance / max_pixel_value;
float max_err = 0.0f;
bool ok = true;
uint32_t *row_ptr, *row_ptr_shot;
struct image_header ih_src = image_header_from(src_buf->image);
struct image_header ih_shot = image_header_from(shot_buf->image);
int y, x;
int chan;
struct color_float pix_src;
struct color_float pix_src_pipeline;
struct color_float pix_shot;
for (y = 0; y < src->height; y++) {
row_ptr = (uint32_t*)((uint8_t*)src->data + (src->stride * y));
row_ptr_shot = (uint32_t*)((uint8_t*)shot->data + (shot->stride * y));
/* no point to compare different images */
assert(ih_src.width == ih_shot.width);
assert(ih_src.height == ih_shot.height);
for (y = 0; y < ih_src.height; y++) {
uint32_t *row_ptr = image_header_get_row_u32(&ih_src, y);
uint32_t *row_ptr_shot = image_header_get_row_u32(&ih_shot, y);
for (x = 0; x < src->width; x++) {
for (x = 0; x < ih_src.width; x++) {
pix_src = a8r8g8b8_to_float(row_ptr[x]);
pix_shot = a8r8g8b8_to_float(row_ptr_shot[x]);
/* do pipeline processing */
......@@ -639,26 +626,6 @@ process_pipeline_comparison(const struct image_header *src,
return ok;
}
static bool
check_process_pattern_ex(struct buffer *src, struct buffer *shot,
const struct setup_args * arg)
{
struct image_header header_src;
struct image_header header_shot;
bool ok;
get_image_prop(src, &header_src);
get_image_prop(shot, &header_shot);
/* no point to compare different images */
assert(header_src.width == header_shot.width);
assert(header_src.height == header_shot.height);
ok = process_pipeline_comparison(&header_src, &header_shot, arg);
return ok;
}
/*
* Test that opaque client pixels produce the expected output when converted
* from the implicit sRGB input to ICC profile described output.
......@@ -680,7 +647,6 @@ TEST(opaque_pixel_conversion)
struct buffer *buf;
struct buffer *shot;
struct wl_surface *surface;
struct image_header image;
bool match;
client = create_client_and_test_surface(0, 0, width, height);
......@@ -688,8 +654,7 @@ TEST(opaque_pixel_conversion)
surface = client->surface->wl_surface;
buf = create_shm_buffer_a8r8g8b8(client, width, height);
get_image_prop(buf, &image);
gen_ramp_rgb(&image, bitwidth, width_bar);
gen_ramp_rgb(buf->image, bitwidth, width_bar);
wl_surface_attach(surface, buf->proxy, 0, 0);
wl_surface_damage(surface, 0, 0, width, height);
......@@ -700,7 +665,7 @@ TEST(opaque_pixel_conversion)
match = verify_image(shot, "shaper_matrix", arg->ref_image_index,
NULL, seq_no);
assert(check_process_pattern_ex(buf, shot, arg));
assert(process_pipeline_comparison(buf, shot, arg));
assert(match);
buffer_destroy(shot);
buffer_destroy(buf);
......
/*
* Copyright 2021 Advanced Micro Devices, Inc.
* Copyright 2022 Collabora, Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#pragma once
#include <stdint.h>
#include <pixman.h>
#include <assert.h>
/** A collection of basic information extracted from a pixman_image_t */
struct image_header {
int width;
int height;
pixman_format_code_t pixman_format;
int stride_bytes;
unsigned char *data;
};
/** Populate image_header from pixman_image_t */
static inline struct image_header
image_header_from(pixman_image_t *image)
{
struct image_header h;
h.width = pixman_image_get_width(image);
h.height = pixman_image_get_height(image);
h.pixman_format = pixman_image_get_format(image);
h.stride_bytes = pixman_image_get_stride(image);
h.data = (void *)pixman_image_get_data(image);
return h;
}
/** Get pointer to the beginning of the row
*
* \param header Header describing the Pixman image.
* \param y Index of the desired row, starting from zero.
* \return Pointer to the first pixel of the row.
*
* Asserts that y is within image height, and that pixel format uses 32 bits
* per pixel.
*/
static inline uint32_t *
image_header_get_row_u32(const struct image_header *header, int y)
{
assert(y >= 0);
assert(y < header->height);
assert(PIXMAN_FORMAT_BPP(header->pixman_format) == 32);
return (uint32_t *)(header->data + y * header->stride_bytes);
}
......@@ -30,6 +30,7 @@
#include "weston-test-client-helper.h"
#include "weston-test-fixture-compositor.h"
#include "image-iter.h"
#include "test-config.h"
static enum test_result_code
......@@ -55,30 +56,20 @@ DECLARE_FIXTURE_SETUP(fixture_setup);
static void
draw_stuff(pixman_image_t *image)
{
int w, h;
int stride; /* bytes */
struct image_header ih = image_header_from(image);
int x, y;
uint32_t r, g, b;
uint32_t *pixels;
uint32_t *pixel;
pixman_format_code_t fmt;
fmt = pixman_image_get_format(image);
w = pixman_image_get_width(image);
h = pixman_image_get_height(image);
stride = pixman_image_get_stride(image);
pixels = pixman_image_get_data(image);
for (y = 0; y < ih.height; y++) {
uint32_t *pixel = image_header_get_row_u32(&ih, y);
assert(PIXMAN_FORMAT_BPP(fmt) == 32);
for (x = 0; x < w; x++)
for (y = 0; y < h; y++) {
for (x = 0; x < ih.width; x++, pixel++) {
b = x;
g = x + y;
r = y;
pixel = pixels + (y * stride / 4) + x;
*pixel = (255U << 24) | (r << 16) | (g << 8) | b;
}
}
}
TEST(internal_screenshot)
......
......@@ -41,6 +41,7 @@
#include "shared/xalloc.h"
#include <libweston/zalloc.h>
#include "weston-test-client-helper.h"
#include "image-iter.h"
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) > (b)) ? (b) : (a))
......@@ -1200,8 +1201,8 @@ range_get(const struct range *r)
/**
* Compute the ROI for image comparisons
*
* \param img_a An image.
* \param img_b Another image.
* \param ih_a A header for an image.
* \param ih_b A header for another image.
* \param clip_rect Explicit ROI, or NULL for using the whole
* image area.
*
......@@ -1215,21 +1216,12 @@ range_get(const struct range *r)
* The ROI is given as pixman_box32_t, where x2,y2 are non-inclusive.
*/
static pixman_box32_t
image_check_get_roi(pixman_image_t *img_a, pixman_image_t *img_b,
const struct rectangle *clip_rect)
image_check_get_roi(const struct image_header *ih_a,
const struct image_header *ih_b,
const struct rectangle *clip_rect)
{
int width_a;
int width_b;
int height_a;
int height_b;
pixman_box32_t box;
width_a = pixman_image_get_width(img_a);
height_a = pixman_image_get_height(img_a);
width_b = pixman_image_get_width(img_b);
height_b = pixman_image_get_height(img_b);
if (clip_rect) {
box.x1 = clip_rect->x;
box.y1 = clip_rect->y;
......@@ -1238,45 +1230,22 @@ image_check_get_roi(pixman_image_t *img_a, pixman_image_t *img_b,
} else {
box.x1 = 0;
box.y1 = 0;
box.x2 = max(width_a, width_b);
box.y2 = max(height_a, height_b);
box.x2 = max(ih_a->width, ih_b->width);
box.y2 = max(ih_a->height, ih_b->height);
}
assert(box.x1 >= 0);
assert(box.y1 >= 0);
assert(box.x2 > box.x1);
assert(box.y2 > box.y1);
assert(box.x2 <= width_a);
assert(box.x2 <= width_b);
assert(box.y2 <= height_a);
assert(box.y2 <= height_b);
assert(box.x2 <= ih_a->width);
assert(box.x2 <= ih_b->width);
assert(box.y2 <= ih_a->height);
assert(box.y2 <= ih_b->height);
return box;
}
struct image_iterator {
char *data;
int stride; /* bytes */
};
static void
image_iter_init(struct image_iterator *it, pixman_image_t *image)
{
pixman_format_code_t fmt;
it->stride = pixman_image_get_stride(image);
it->data = (void *)pixman_image_get_data(image);
fmt = pixman_image_get_format(image);
assert(PIXMAN_FORMAT_BPP(fmt) == 32);
}
static uint32_t *
image_iter_get_row(struct image_iterator *it, int y)
{
return (uint32_t *)(it->data + y * it->stride);
}
struct pixel_diff_stat {
struct pixel_diff_stat_channel {
int min_diff;
......@@ -1347,21 +1316,18 @@ check_images_match(pixman_image_t *img_a, pixman_image_t *img_b,
{
struct range fuzz = range_get(prec);
struct pixel_diff_stat diffstat = {};
struct image_iterator it_a;
struct image_iterator it_b;
struct image_header ih_a = image_header_from(img_a);
struct image_header ih_b = image_header_from(img_b);
pixman_box32_t box;
int x, y;
uint32_t *pix_a;
uint32_t *pix_b;
box = image_check_get_roi(img_a, img_b, clip_rect);
image_iter_init(&it_a, img_a);
image_iter_init(&it_b, img_b);
box = image_check_get_roi(&ih_a, &ih_b, clip_rect);
for (y = box.y1; y < box.y2; y++) {
pix_a = image_iter_get_row(&it_a, y) + box.x1;
pix_b = image_iter_get_row(&it_b, y) + box.x1;
pix_a = image_header_get_row_u32(&ih_a, y) + box.x1;
pix_b = image_header_get_row_u32(&ih_b, y) + box.x1;
for (x = box.x1; x < box.x2; x++) {
if (!fuzzy_match_pixels(*pix_a, *pix_b,
......@@ -1431,11 +1397,9 @@ visualize_image_difference(pixman_image_t *img_a, pixman_image_t *img_b,
struct pixel_diff_stat diffstat = {};
pixman_image_t *diffimg;
pixman_image_t *shade;
struct image_iterator it_a;
struct image_iterator it_b;
struct image_iterator it_d;
int width;
int height;
struct image_header ih_a = image_header_from(img_a);
struct image_header ih_b = image_header_from(img_b);
struct image_header ih_d;
pixman_box32_t box;
int x, y;
uint32_t *pix_a;
......@@ -1443,32 +1407,28 @@ visualize_image_difference(pixman_image_t *img_a, pixman_image_t *img_b,
uint32_t *pix_d;
pixman_color_t shade_color = { 0, 0, 0, 32768 };
width = pixman_image_get_width(img_a);
height = pixman_image_get_height(img_a);
box = image_check_get_roi(img_a, img_b, clip_rect);
box = image_check_get_roi(&ih_a, &ih_b, clip_rect);
diffimg = pixman_image_create_bits_no_clear(PIXMAN_x8r8g8b8,
width, height, NULL, 0);
ih_a.width, ih_a.height,
NULL, 0);
ih_d = image_header_from(diffimg);
/* Fill diffimg with a black-shaded copy of img_a, and then fill
* the clip_rect area with original img_a.
*/
shade = pixman_image_create_solid_fill(&shade_color);
pixman_image_composite32(PIXMAN_OP_SRC, img_a, shade, diffimg,
0, 0, 0, 0, 0, 0, width, height);
0, 0, 0, 0, 0, 0, ih_a.width, ih_a.height);
pixman_image_unref(shade);
pixman_image_composite32(PIXMAN_OP_SRC, img_a, NULL, diffimg,
box.x1, box.y1, 0, 0, box.x1, box.y1,
box.x2 - box.x1, box.y2 - box.y1);
image_iter_init(&it_a, img_a);
image_iter_init(&it_b, img_b);
image_iter_init(&it_d, diffimg);
for (y = box.y1; y < box.y2; y++) {
pix_a = image_iter_get_row(&it_a, y) + box.x1;
pix_b = image_iter_get_row(&it_b, y) + box.x1;
pix_d = image_iter_get_row(&it_d, y) + box.x1;
pix_a = image_header_get_row_u32(&ih_a, y) + box.x1;
pix_b = image_header_get_row_u32(&ih_b, y) + box.x1;
pix_d = image_header_get_row_u32(&ih_d, y) + box.x1;
for (x = box.x1; x < box.x2; x++) {
if (fuzzy_match_pixels(*pix_a, *pix_b,
......@@ -1504,16 +1464,12 @@ write_image_as_png(pixman_image_t *image, const char *fname)
{
cairo_surface_t *cairo_surface;
cairo_status_t status;
cairo_format_t fmt;
fmt = format_pixman2cairo(pixman_image_get_format(image));
struct image_header ih = image_header_from(image);
cairo_format_t fmt = format_pixman2cairo(ih.pixman_format);
cairo_surface = cairo_image_surface_create_for_data(
(void *)pixman_image_get_data(image),
fmt,
pixman_image_get_width(image),
pixman_image_get_height(image),
pixman_image_get_stride(image));
cairo_surface = cairo_image_surface_create_for_data(ih.data, fmt,
ih.width, ih.height,
ih.stride_bytes);
status = cairo_surface_write_to_png(cairo_surface, fname);
if (status != CAIRO_STATUS_SUCCESS) {
......@@ -1532,21 +1488,17 @@ static pixman_image_t *
image_convert_to_a8r8g8b8(pixman_image_t *image)
{
pixman_image_t *ret;
int width;
int height;
struct image_header ih = image_header_from(image);
if (pixman_image_get_format(image) == PIXMAN_a8r8g8b8)
if (ih.pixman_format == PIXMAN_a8r8g8b8)
return pixman_image_ref(image);
width = pixman_image_get_width(image);
height = pixman_image_get_height(image);
ret = pixman_image_create_bits_no_clear(PIXMAN_a8r8g8b8, width, height,
NULL, 0);
ret = pixman_image_create_bits_no_clear(PIXMAN_a8r8g8b8,
ih.width, ih.height, NULL, 0);
assert(ret);
pixman_image_composite32(PIXMAN_OP_SRC, image, NULL, ret,
0, 0, 0, 0, 0, 0, width, height);
0, 0, 0, 0, 0, 0, ih.width, ih.height);
return ret;
}
......
......@@ -33,6 +33,7 @@
#include "weston-test-client-helper.h"
#include "weston-test-fixture-compositor.h"
#include "image-iter.h"
#include "shared/os-compatibility.h"
#include "shared/weston-drm-fourcc.h"
#include "shared/xalloc.h"
......@@ -158,13 +159,10 @@ y_u_v_create_buffer(struct client *client,
uint32_t drm_format,
pixman_image_t *rgb_image)
{
struct image_header rgb = image_header_from(rgb_image);
struct yuv_buffer *buf;
size_t bytes;
int width;
int height;
int x, y;
void *rgb_pixels;
int rgb_stride_bytes;
uint32_t *rgb_row;
uint8_t *y_base;
uint8_t *u_base;
......@@ -178,26 +176,23 @@ y_u_v_create_buffer(struct client *client,
assert(drm_format == DRM_FORMAT_YUV420 ||
drm_format == DRM_FORMAT_YUV444);
width = pixman_image_get_width(rgb_image);
height = pixman_image_get_height(rgb_image);
rgb_pixels = pixman_image_get_data(rgb_image);
rgb_stride_bytes = pixman_image_get_stride(rgb_image);
/* Full size Y plus quarter U and V */
bytes = width * height + (width / sub) * (height / sub) * 2;
buf = yuv_buffer_create(client, bytes, width, height, width, drm_format);
bytes = rgb.width * rgb.height +
(rgb.width / sub) * (rgb.height / sub) * 2;
buf = yuv_buffer_create(client, bytes, rgb.width, rgb.height,
rgb.width, drm_format);
y_base = buf->data;
u_base = y_base + width * height;
v_base = u_base + (width / sub) * (height / sub);
u_base = y_base + rgb.width * rgb.height;
v_base = u_base + (rgb.width / sub) * (rgb.height / sub);
for (y = 0; y < height; y++) {
rgb_row = rgb_pixels + (y / 2 * 2) * rgb_stride_bytes;
y_row = y_base + y * width;
u_row = u_base + (y / sub) * (width / sub);
v_row = v_base + (y / sub) * (width / sub);
for (y = 0; y < rgb.height; y++) {
rgb_row = image_header_get_row_u32(&rgb, y / 2 * 2);
y_row = y_base + y * rgb.width;
u_row = u_base + (y / sub) * (rgb.width / sub);
v_row = v_base + (y / sub) * (rgb.width / sub);
for (x = 0; x < width; x++) {
for (x = 0; x < rgb.width; x++) {
/*
* Sub-sample the source image instead, so that U and V
* sub-sampling does not require proper
......@@ -235,13 +230,10 @@ nv12_create_buffer(struct client *client,
uint32_t drm_format,
pixman_image_t *rgb_image)
{
struct image_header rgb = image_header_from(rgb_image);
struct yuv_buffer *buf;
size_t bytes;
int width;
int height;
int x, y;
void *rgb_pixels;
int rgb_stride_bytes;
uint32_t *rgb_row;
uint8_t *y_base;
uint16_t *uv_base;
......@@ -253,24 +245,21 @@ nv12_create_buffer(struct client *client,
assert(drm_format == DRM_FORMAT_NV12);
width = pixman_image_get_width(rgb_image);
height = pixman_image_get_height(rgb_image);
rgb_pixels = pixman_image_get_data(rgb_image);
rgb_stride_bytes = pixman_image_get_stride(rgb_image);
/* Full size Y, quarter UV */
bytes = width * height + (width / 2) * (height / 2) * sizeof(uint16_t);
buf = yuv_buffer_create(client, bytes, width, height, width, drm_format);
bytes = rgb.width * rgb.height +
(rgb.width / 2) * (rgb.height / 2) * sizeof(uint16_t);
buf = yuv_buffer_create(client, bytes, rgb.width, rgb.height,
rgb.width, drm_format);
y_base = buf->data;
uv_base = (uint16_t *)(y_base + width * height);
uv_base = (uint16_t *)(y_base + rgb.width * rgb.height);
for (y = 0; y < height; y++) {
rgb_row = rgb_pixels + (y / 2 * 2) * rgb_stride_bytes;
y_row = y_base + y * width;
uv_row = uv_base + (y / 2) * (width / 2);
for (y = 0; y < rgb.height; y++) {
rgb_row = image_header_get_row_u32(&rgb, y / 2 * 2);
y_row = y_base + y * rgb.width;
uv_row = uv_base + (y / 2) * (rgb.width / 2);
for (x = 0; x < width; x++) {
for (x = 0; x < rgb.width; x++) {
/*
* Sub-sample the source image instead, so that U and V
* sub-sampling does not require proper
......@@ -307,13 +296,10 @@ yuyv_create_buffer(struct client *client,
uint32_t drm_format,
pixman_image_t *rgb_image)
{
struct image_header rgb = image_header_from(rgb_image);
struct yuv_buffer *buf;
size_t bytes;
int width;
int height;
int x, y;
void *rgb_pixels;
int rgb_stride_bytes;
uint32_t *rgb_row;
uint32_t *yuv_base;
uint32_t *yuv_row;
......@@ -323,22 +309,18 @@ yuyv_create_buffer(struct client *client,
assert(drm_format == DRM_FORMAT_YUYV);
width = pixman_image_get_width(rgb_image);
height = pixman_image_get_height(rgb_image);
rgb_pixels = pixman_image_get_data(rgb_image);
rgb_stride_bytes = pixman_image_get_stride(rgb_image);
/* Full size Y, horizontally subsampled UV, 2 pixels in 32 bits */
bytes = width / 2 * height * sizeof(uint32_t);
buf = yuv_buffer_create(client, bytes, width, height, width / 2 * sizeof(uint32_t), drm_format);
bytes = rgb.width / 2 * rgb.height * sizeof(uint32_t);
buf = yuv_buffer_create(client, bytes, rgb.width, rgb.height,
rgb.width / 2 * sizeof(uint32_t), drm_format);
yuv_base = buf->data;
for (y = 0; y < height; y++) {
rgb_row = rgb_pixels + (y / 2 * 2) * rgb_stride_bytes;
yuv_row = yuv_base + y * (width / 2);
for (y = 0; y < rgb.height; y++) {
rgb_row = image_header_get_row_u32(&rgb, y / 2 * 2);
yuv_row = yuv_base + y * (rgb.width / 2);
for (x = 0; x < width; x += 2) {
for (x = 0; x < rgb.width; x += 2) {
/*
* Sub-sample the source image instead, so that U and V
* sub-sampling does not require proper
......@@ -367,13 +349,10 @@ xyuv8888_create_buffer(struct client *client,
uint32_t drm_format,
pixman_image_t *rgb_image)
{
struct image_header rgb = image_header_from(rgb_image);
struct yuv_buffer *buf;
size_t bytes;
int width;
int height;
int x, y;
void *rgb_pixels;
int rgb_stride_bytes;
uint32_t *rgb_row;
uint32_t *yuv_base;
uint32_t *yuv_row;
......@@ -383,22 +362,18 @@ xyuv8888_create_buffer(struct client *client,
assert(drm_format == DRM_FORMAT_XYUV8888);
width = pixman_image_get_width(rgb_image);
height = pixman_image_get_height(rgb_image);
rgb_pixels = pixman_image_get_data(rgb_image);
rgb_stride_bytes = pixman_image_get_stride(rgb_image);
/* Full size, 32 bits per pixel */
bytes = width * height * sizeof(uint32_t);
buf = yuv_buffer_create(client, bytes, width, height, width * sizeof(uint32_t), drm_format);
bytes = rgb.width * rgb.height * sizeof(uint32_t);
buf = yuv_buffer_create(client, bytes, rgb.width, rgb.height,
rgb.width * sizeof(uint32_t), drm_format);
yuv_base = buf->data;
for (y = 0; y < height; y++) {
rgb_row = rgb_pixels + (y / 2 * 2) * rgb_stride_bytes;
yuv_row = yuv_base + y * width;
for (y = 0; y < rgb.height; y++) {
rgb_row = image_header_get_row_u32(&rgb, y / 2 * 2);
yuv_row = yuv_base + y * rgb.width;
for (x = 0; x < width; x++) {
for (x = 0; x < rgb.width; x++) {
/*
* 2x2 sub-sample the source image to get the same
* result as the other YUV variants, so we can use the
......