mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2025-06-12 02:16:17 +00:00
lib: Add a helper to paint a PNG using cairo
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
This commit is contained in:
parent
30e0710ca3
commit
bde7060e3c
@ -1475,6 +1475,34 @@ void kmstest_paint_test_pattern(cairo_t *cr, int width, int height)
|
|||||||
assert(!cairo_status(cr));
|
assert(!cairo_status(cr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void kmstest_paint_image(cairo_t *cr, const char *filename,
|
||||||
|
int dst_x, int dst_y, int dst_width, int dst_height)
|
||||||
|
{
|
||||||
|
cairo_surface_t *image;
|
||||||
|
int img_width, img_height;
|
||||||
|
double scale_x, scale_y;
|
||||||
|
|
||||||
|
image = cairo_image_surface_create_from_png(filename);
|
||||||
|
assert(cairo_surface_status(image) == CAIRO_STATUS_SUCCESS);
|
||||||
|
|
||||||
|
img_width = cairo_image_surface_get_width(image);
|
||||||
|
img_height = cairo_image_surface_get_height(image);
|
||||||
|
|
||||||
|
scale_x = (double)dst_width / img_width;
|
||||||
|
scale_y = (double)dst_height / img_height;
|
||||||
|
|
||||||
|
cairo_save(cr);
|
||||||
|
|
||||||
|
cairo_translate(cr, dst_x, dst_y);
|
||||||
|
cairo_scale(cr, scale_x, scale_y);
|
||||||
|
cairo_set_source_surface(cr, image, 0, 0);
|
||||||
|
cairo_paint(cr);
|
||||||
|
|
||||||
|
cairo_surface_destroy(image);
|
||||||
|
|
||||||
|
cairo_restore(cr);
|
||||||
|
}
|
||||||
|
|
||||||
#define DF(did, cid, _bpp, _depth) \
|
#define DF(did, cid, _bpp, _depth) \
|
||||||
{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp, _depth }
|
{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp, _depth }
|
||||||
static struct format_desc_struct {
|
static struct format_desc_struct {
|
||||||
|
@ -355,6 +355,8 @@ cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb);
|
|||||||
void kmstest_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
|
void kmstest_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
|
||||||
int r, int g, int b);
|
int r, int g, int b);
|
||||||
void kmstest_paint_test_pattern(cairo_t *cr, int width, int height);
|
void kmstest_paint_test_pattern(cairo_t *cr, int width, int height);
|
||||||
|
void kmstest_paint_image(cairo_t *cr, const char *filename,
|
||||||
|
int dst_x, int dst_y, int dst_width, int dst_height);
|
||||||
void kmstest_dump_mode(drmModeModeInfo *mode);
|
void kmstest_dump_mode(drmModeModeInfo *mode);
|
||||||
int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
|
int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
|
||||||
const char *kmstest_format_str(uint32_t drm_format);
|
const char *kmstest_format_str(uint32_t drm_format);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user