diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2013-09-16 12:38:36 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <soren.sandmann@gmail.com> | 2018-03-27 19:17:18 -0400 |
commit | 07f59aebe52729fb60fa8982ee989e550de87b3e (patch) | |
tree | c506c07ab9fdd56bf86a8585f04319453d64dcfc | |
parent | a99e39cd46982fa0e95ad39ddac72dbf9a0c8aae (diff) |
Add a check box for gamma aware scaling
This is a hack because just changing the format doesn't work when the
image has an alpha channel
-rw-r--r-- | demos/scale.c | 25 | ||||
-rw-r--r-- | demos/scale.ui | 15 | ||||
-rw-r--r-- | pixman/pixman-image.c | 11 | ||||
-rw-r--r-- | pixman/pixman-private.h | 4 |
4 files changed, 52 insertions, 3 deletions
diff --git a/demos/scale.c b/demos/scale.c index c872139d..4ced07ed 100644 --- a/demos/scale.c +++ b/demos/scale.c @@ -203,11 +203,25 @@ to_scale (double v) return pow (1.15, v); } +static pixman_format_code_t +get_format (app_t *app) +{ + /* FIXME: Just changing the format isn't correct when + * the image has an alpha channel since in that case we + * need to do a gamma aware premultiplication. + */ + return gtk_toggle_button_get_active ( + GTK_TOGGLE_BUTTON ( + get_widget (app, "gamma_checkbutton")))? + PIXMAN_a8r8g8b8_sRGB : PIXMAN_a8r8g8b8; +} + static void rescale (GtkWidget *may_be_null, app_t *app) { pixman_f_transform_t ftransform; pixman_transform_t transform; + pixman_format_code_t format; double new_width, new_height; double fscale_x, fscale_y; double rotation; @@ -249,6 +263,8 @@ rescale (GtkWidget *may_be_null, app_t *app) pixman_transform_from_pixman_f_transform (&transform, &ftransform); pixman_image_set_transform (app->original, &transform); + pixman_image_set_format (app->original, get_format (app)); + params = pixman_filter_create_separable_convolution ( &n_params, sx * 65536.0 + 0.5, @@ -286,10 +302,11 @@ on_expose (GtkWidget *da, GdkEvent *event, gpointer data) pixman_image_t *tmp; cairo_t *cr; uint32_t *pixels; + pixman_format_code_t format; pixels = calloc (1, area->width * area->height * 4); tmp = pixman_image_create_bits ( - PIXMAN_a8r8g8b8_sRGB, area->width, area->height, pixels, area->width * 4); + get_format (app), area->width, area->height, pixels, area->width * 4); if (area->x < app->scaled_width && area->y < app->scaled_height) { @@ -414,6 +431,10 @@ app_new (pixman_image_t *original) gtk_builder_get_object (app->builder, "lock_checkbutton"), "toggled", G_CALLBACK (rescale), app); + g_signal_connect ( + gtk_builder_get_object (app->builder, "gamma_checkbutton"), + "toggled", G_CALLBACK (rescale), app); + rescale (NULL, app); return app; @@ -434,7 +455,7 @@ main (int argc, char **argv) return -1; } - if (!(image = pixman_image_from_file (argv[1], PIXMAN_a8r8g8b8_sRGB))) + if (!(image = pixman_image_from_file (argv[1], PIXMAN_a8r8g8b8))) { printf ("Could not load image \"%s\"\n", argv[1]); return -1; diff --git a/demos/scale.ui b/demos/scale.ui index d498d26e..ee8773ee 100644 --- a/demos/scale.ui +++ b/demos/scale.ui @@ -186,6 +186,19 @@ <property name="position">1</property> </packing> </child> + <child> + <object class="GtkCheckButton" + id="gamma_checkbutton"> + <property name="label" translatable="yes">Gamma Aware</property> + <property name="xalign">0.0</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="padding">6</property> + <property name="position">2</property> + </packing> + </child> <child> <object class="GtkTable" id="grid1"> <property name="visible">True</property> @@ -313,7 +326,7 @@ <packing> <property name="expand">False</property> <property name="padding">6</property> - <property name="position">1</property> + <property name="position">2</property> </packing> </child> </object> diff --git a/pixman/pixman-image.c b/pixman/pixman-image.c index 681864eb..3424f189 100644 --- a/pixman/pixman-image.c +++ b/pixman/pixman-image.c @@ -565,6 +565,17 @@ _pixman_image_validate (pixman_image_t *image) _pixman_image_validate ((pixman_image_t *)image->common.alpha_map); } +PIXMAN_EXPORT void +pixman_image_set_format (pixman_image_t *image, + pixman_format_code_t format) +{ + return_if_fail (image && image->type == BITS); + + image->bits.format = format; + + image_property_changed (image); +} + PIXMAN_EXPORT pixman_bool_t pixman_image_set_clip_region32 (pixman_image_t * image, pixman_region32_t *region) diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h index e246af04..4b64bb7b 100644 --- a/pixman/pixman-private.h +++ b/pixman/pixman-private.h @@ -320,6 +320,10 @@ void _pixman_image_reset_clip_region (pixman_image_t *image); void +_pixman_image_set_format (pixman_image_t *image, + pixman_format_code_t format); + +void _pixman_image_validate (pixman_image_t *image); #define PIXMAN_IMAGE_GET_LINE(image, x, y, type, out_stride, line, mul) \ |