[igt-dev] [PATCH i-g-t v2 4/8] lib/igt_frame: Add function to dump frames in RGB and raw

Pekka Paalanen ppaalanen at gmail.com
Fri Apr 29 12:46:45 UTC 2022


On Mon, 28 Mar 2022 16:55:05 +0200
Maxime Ripard <maxime at cerno.tech> wrote:

> The igt_write_frame_to_png() already allows to dump the content of a
> cairo surface into a PNG image. However, it can be useful to have the
> raw content of the buffer as well, so let's create a function that will
> dump both a PNG image and its raw buffer.
> 
> Signed-off-by: Maxime Ripard <maxime at cerno.tech>

Hi,

when exactly is the raw dump useful? Do you need it for checking alpha?
Or for YUV formats? Or for multi-planar formats? Or for greater than 8
bpc or floating point formats?

How do you make use of the raw dump?

PNG can store alpha channel as well, and if that's not convenient
alongsize RGB, you could save another image where alpha has been
converted to gray scale.

PNG can also go up to 16 bpc I think?

PAM file format (netpbm type P7) might also be an option, looks like it
can do up to RGBA 16 bpc, and is trivial to generate.
http://netpbm.sourceforge.net/doc/pam.html

It's not much different from a raw dump, but contains enough metadata
for tools to understand the image.


Thanks,
pq

> ---
>  lib/igt_frame.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++
>  lib/igt_frame.h |  4 +++
>  2 files changed, 86 insertions(+)
> 
> diff --git a/lib/igt_frame.c b/lib/igt_frame.c
> index ba29ac028e1b..f53ba3a381ef 100644
> --- a/lib/igt_frame.c
> +++ b/lib/igt_frame.c
> @@ -112,6 +112,40 @@ static void igt_write_frame_to_png(cairo_surface_t *surface, int summary_fd,
>  	free(path);
>  }
>  
> +static void igt_write_frame_to_raw(cairo_surface_t *surface, int summary_fd,
> +				   const char *qualifier, const char *suffix)
> +{
> +	int height, stride, size;
> +	char *path;
> +	void *ptr;
> +	int out_fd = -1;
> +
> +	path = igt_get_frame_path(qualifier, suffix, "raw");
> +	igt_assert(path);
> +
> +	igt_debug("Dumping %s frame to %s...\n", qualifier, path);
> +
> +	out_fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
> +	igt_assert(out_fd >= 0);
> +
> +	ptr = cairo_image_surface_get_data(surface);
> +	igt_assert(ptr);
> +
> +	stride = cairo_image_surface_get_stride(surface);
> +	igt_assert(stride > 0);
> +
> +	height = cairo_image_surface_get_height(surface);
> +	igt_assert(height > 0);
> +
> +	size = stride * height;
> +	write(out_fd, ptr, size);
> +
> +	close(out_fd);
> +
> +	igt_log_frame_path(summary_fd, path);
> +	free(path);
> +}
> +
>  /**
>   * igt_write_compared_frames_to_png:
>   * @reference: The reference cairo surface
> @@ -158,6 +192,54 @@ void igt_write_compared_frames_to_png(cairo_surface_t *reference,
>  	close(fd);
>  }
>  
> +/**
> + * igt_write_compared_frames:
> + * @reference: The reference cairo surface
> + * @capture: The captured cairo surface
> + * @reference_suffix: The suffix to give to the reference png file
> + * @capture_suffix: The suffix to give to the capture png file
> + *
> + * Dump previously compared frames to png and raw files.
> + */
> +void igt_write_compared_frames(cairo_surface_t *reference,
> +			       cairo_surface_t *capture,
> +			       const char *reference_suffix,
> +			       const char *capture_suffix)
> +{
> +	char *id;
> +	const char *test_name;
> +	const char *subtest_name;
> +	char path[PATH_MAX];
> +	int fd = -1;
> +
> +	if (!igt_frame_dump_is_enabled())
> +		return;
> +
> +	id = getenv("IGT_FRAME_DUMP_ID");
> +
> +	test_name = igt_test_name();
> +	subtest_name = igt_subtest_name();
> +
> +	if (id)
> +		snprintf(path, PATH_MAX, "%s/frame-%s-%s-%s.txt",
> +			 igt_frame_dump_path, test_name, subtest_name, id);
> +	else
> +		snprintf(path, PATH_MAX, "%s/frame-%s-%s.txt",
> +			 igt_frame_dump_path, test_name, subtest_name);
> +
> +	fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
> +	igt_assert(fd >= 0);
> +
> +	igt_debug("Writing dump report to %s...\n", path);
> +
> +	igt_write_frame_to_raw(reference, fd, "reference", reference_suffix);
> +	igt_write_frame_to_png(reference, fd, "reference", reference_suffix);
> +	igt_write_frame_to_raw(capture, fd, "capture", capture_suffix);
> +	igt_write_frame_to_png(capture, fd, "capture", capture_suffix);
> +
> +	close(fd);
> +}
> +
>  /**
>   * igt_check_analog_frame_match:
>   * @reference: The reference cairo surface
> diff --git a/lib/igt_frame.h b/lib/igt_frame.h
> index f44f57d7ce73..51cbc2bd68b4 100644
> --- a/lib/igt_frame.h
> +++ b/lib/igt_frame.h
> @@ -36,6 +36,10 @@ void igt_write_compared_frames_to_png(cairo_surface_t *reference,
>  				      cairo_surface_t *capture,
>  				      const char *reference_suffix,
>  				      const char *capture_suffix);
> +void igt_write_compared_frames(cairo_surface_t *reference,
> +			       cairo_surface_t *capture,
> +			       const char *reference_suffix,
> +			       const char *capture_suffix);
>  bool igt_check_analog_frame_match(cairo_surface_t *reference,
>  				  cairo_surface_t *capture);
>  bool igt_check_checkerboard_frame_match(cairo_surface_t *reference,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/igt-dev/attachments/20220429/1c807cb6/attachment.sig>


More information about the igt-dev mailing list