Skip to content
Snippets Groups Projects
Commit 04e878c2 authored by Søren Sandmann Pedersen's avatar Søren Sandmann Pedersen
Browse files

Make show_image() cope with more formats

This makes show_image() deal with more formats than just a8r8g8b8, in
particular, a8r8g8b8_sRGB can now be handled.

Images that are passed to show_image with a format of a8r8g8b8_sRGB
are displayed without modification under the assumption that the
monitor is approximately sRGB.

Images with a format of a8r8g8b8 are also displayed without
modification since many other users of show_image() have been
generating essentially sRGB data with this format. Other formats are
also assumed to be gamma compressed; these are converted to a8r8g8b8
before being displayed.

With these changes, srgb-test.c doesn't need to do its own conversion
anymore.
parent 8db9ec98
No related branches found
No related tags found
No related merge requests found
......@@ -149,7 +149,7 @@ main (int argc, char **argv)
0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
pixman_image_composite (operators[i].op, parrot, NULL, dest_img,
0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
pixbuf = pixbuf_from_argb32 (pixman_image_get_data (dest_img), TRUE,
pixbuf = pixbuf_from_argb32 (pixman_image_get_data (dest_img),
WIDTH, HEIGHT, WIDTH * 4);
image = gtk_image_new_from_pixbuf (pixbuf);
gtk_box_pack_start (GTK_BOX (vbox), image, FALSE, FALSE, 0);
......
......@@ -5,7 +5,6 @@
GdkPixbuf *
pixbuf_from_argb32 (uint32_t *bits,
gboolean has_alpha,
int width,
int height,
int stride)
......@@ -47,12 +46,12 @@ show_image (pixman_image_t *image)
{
GtkWidget *window;
GdkPixbuf *pixbuf;
int width, height, stride;
int width, height;
int argc;
char **argv;
char *arg0 = g_strdup ("pixman-test-program");
gboolean has_alpha;
pixman_format_code_t format;
pixman_image_t *copy;
argc = 1;
argv = (char **)&arg0;
......@@ -62,21 +61,43 @@ show_image (pixman_image_t *image)
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
width = pixman_image_get_width (image);
height = pixman_image_get_height (image);
stride = pixman_image_get_stride (image);
gtk_window_set_default_size (GTK_WINDOW (window), width, height);
format = pixman_image_get_format (image);
if (format == PIXMAN_a8r8g8b8)
has_alpha = TRUE;
else if (format == PIXMAN_x8r8g8b8)
has_alpha = FALSE;
else
g_error ("Can't deal with this format: %x\n", format);
pixbuf = pixbuf_from_argb32 (pixman_image_get_data (image), has_alpha,
width, height, stride);
/* Three cases:
*
* - image is a8r8g8b8_sRGB: we will display without modification
* under the assumption that the monitor is sRGB
*
* - image is a8r8g8b8: we will display without modification
* under the assumption that whoever created the image
* probably did it wrong by using sRGB inputs
*
* - other: we will convert to a8r8g8b8 under the assumption that
* whoever created the image probably did it wrong.
*/
switch (format)
{
case PIXMAN_a8r8g8b8_sRGB:
case PIXMAN_a8r8g8b8:
copy = pixman_image_ref (image);
break;
default:
copy = pixman_image_create_bits (PIXMAN_a8r8g8b8,
width, height, NULL, -1);
pixman_image_composite32 (PIXMAN_OP_SRC,
image, NULL, copy,
0, 0, 0, 0, 0, 0,
width, height);
break;
}
pixbuf = pixbuf_from_argb32 (pixman_image_get_data (copy),
width, height,
pixman_image_get_stride (copy));
g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), pixbuf);
g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
......
......@@ -7,7 +7,6 @@
void show_image (pixman_image_t *image);
GdkPixbuf *pixbuf_from_argb32 (uint32_t *bits,
gboolean has_alpha,
int width,
int height,
int stride);
......@@ -79,15 +79,6 @@ main (int argc, char **argv)
pixman_image_unref (src1_img);
free (src1);
pixman_image_unref (dest_img);
/* Now that the picture has been correctly constructed,
* we hand it over to our support library as argb which it
* knows how to handle (it doesn't understand _sRGB format). */
dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
WIDTH, HEIGHT,
dest,
WIDTH * 4);
show_image (dest_img);
pixman_image_unref (dest_img);
free (dest);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment