[gthumb] replaced the "bilinear" filter with a real box filter
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] replaced the "bilinear" filter with a real box filter
- Date: Sun, 25 Jan 2015 12:07:23 +0000 (UTC)
commit 896fdfa00e534270314a775015d18c9769dd5802
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Jan 18 18:40:43 2015 +0100
replaced the "bilinear" filter with a real box filter
this will reduce blur in the tool preview
.../file_tools/gth-file-tool-adjust-colors.c | 2 +-
.../file_tools/gth-file-tool-adjust-contrast.c | 2 +-
extensions/file_tools/gth-file-tool-curves.c | 2 +-
extensions/file_tools/gth-file-tool-effects.c | 2 +-
extensions/file_tools/gth-file-tool-grayscale.c | 2 +-
extensions/file_tools/gth-file-tool-resize.c | 2 +-
extensions/file_tools/gth-image-line-tool.c | 2 +-
extensions/file_tools/gth-image-rotator.c | 2 +-
extensions/file_tools/gth-preview-tool.c | 2 +-
gthumb/cairo-scale.c | 325 +-------------------
gthumb/cairo-scale.h | 6 +-
gthumb/gth-image-overview.c | 6 +-
12 files changed, 24 insertions(+), 331 deletions(-)
---
diff --git a/extensions/file_tools/gth-file-tool-adjust-colors.c
b/extensions/file_tools/gth-file-tool-adjust-colors.c
index 3ec7b15..d825bb0 100644
--- a/extensions/file_tools/gth-file-tool-adjust-colors.c
+++ b/extensions/file_tools/gth-file-tool-adjust-colors.c
@@ -415,7 +415,7 @@ gth_file_tool_adjust_colors_get_options (GthFileTool *base)
viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
gtk_widget_get_allocation (GTK_WIDGET (viewer), &allocation);
if (scale_keeping_ratio (&width, &height, PREVIEW_SIZE * allocation.width, PREVIEW_SIZE *
allocation.height, FALSE))
- self->priv->preview = _cairo_image_surface_scale_bilinear (source, width, height);
+ self->priv->preview = _cairo_image_surface_scale_fast (source, width, height);
else
self->priv->preview = cairo_surface_reference (source);
diff --git a/extensions/file_tools/gth-file-tool-adjust-contrast.c
b/extensions/file_tools/gth-file-tool-adjust-contrast.c
index 95ab6b4..bb30c36 100644
--- a/extensions/file_tools/gth-file-tool-adjust-contrast.c
+++ b/extensions/file_tools/gth-file-tool-adjust-contrast.c
@@ -512,7 +512,7 @@ gth_file_tool_adjust_contrast_get_options (GthFileTool *base)
height = cairo_image_surface_get_height (source);
gtk_widget_get_allocation (GTK_WIDGET (viewer), &allocation);
if (scale_keeping_ratio (&width, &height, PREVIEW_SIZE * allocation.width, PREVIEW_SIZE *
allocation.height, FALSE))
- self->priv->preview = _cairo_image_surface_scale_bilinear (source, width, height);
+ self->priv->preview = _cairo_image_surface_scale_fast (source, width, height);
else
self->priv->preview = cairo_surface_reference (source);
diff --git a/extensions/file_tools/gth-file-tool-curves.c b/extensions/file_tools/gth-file-tool-curves.c
index c2aefbb..e224e2c 100644
--- a/extensions/file_tools/gth-file-tool-curves.c
+++ b/extensions/file_tools/gth-file-tool-curves.c
@@ -591,7 +591,7 @@ gth_file_tool_curves_get_options (GthFileTool *base)
viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
gtk_widget_get_allocation (GTK_WIDGET (viewer), &allocation);
if (scale_keeping_ratio (&width, &height, PREVIEW_SIZE * allocation.width, PREVIEW_SIZE *
allocation.height, FALSE))
- self->priv->preview = _cairo_image_surface_scale_bilinear (source, width, height);
+ self->priv->preview = _cairo_image_surface_scale_fast (source, width, height);
else
self->priv->preview = cairo_surface_reference (source);
diff --git a/extensions/file_tools/gth-file-tool-effects.c b/extensions/file_tools/gth-file-tool-effects.c
index 4cc7288..a0d5ff2 100644
--- a/extensions/file_tools/gth-file-tool-effects.c
+++ b/extensions/file_tools/gth-file-tool-effects.c
@@ -228,7 +228,7 @@ gth_file_tool_effects_get_options (GthFileTool *base)
height = cairo_image_surface_get_height (source);
gtk_widget_get_allocation (GTK_WIDGET (viewer), &allocation);
if (scale_keeping_ratio (&width, &height, PREVIEW_SIZE * allocation.width, PREVIEW_SIZE *
allocation.height, FALSE))
- self->priv->preview = _cairo_image_surface_scale_bilinear (source, width, height);
+ self->priv->preview = _cairo_image_surface_scale_fast (source, width, height);
else
self->priv->preview = cairo_surface_reference (source);
diff --git a/extensions/file_tools/gth-file-tool-grayscale.c b/extensions/file_tools/gth-file-tool-grayscale.c
index 7083636..0680350 100644
--- a/extensions/file_tools/gth-file-tool-grayscale.c
+++ b/extensions/file_tools/gth-file-tool-grayscale.c
@@ -351,7 +351,7 @@ gth_file_tool_grayscale_get_options (GthFileTool *base)
height = cairo_image_surface_get_height (source);
gtk_widget_get_allocation (GTK_WIDGET (viewer), &allocation);
if (scale_keeping_ratio (&width, &height, PREVIEW_SIZE * allocation.width, PREVIEW_SIZE *
allocation.height, FALSE))
- self->priv->preview = _cairo_image_surface_scale_bilinear (source, width, height);
+ self->priv->preview = _cairo_image_surface_scale_fast (source, width, height);
else
self->priv->preview = cairo_surface_reference (source);
diff --git a/extensions/file_tools/gth-file-tool-resize.c b/extensions/file_tools/gth-file-tool-resize.c
index 36a7d74..5136840 100644
--- a/extensions/file_tools/gth-file-tool-resize.c
+++ b/extensions/file_tools/gth-file-tool-resize.c
@@ -536,7 +536,7 @@ gth_file_tool_resize_get_options (GthFileTool *base)
preview_width = self->priv->original_width;
preview_height = self->priv->original_height;
if (scale_keeping_ratio (&preview_width, &preview_height, allocation.width, allocation.height, FALSE))
- self->priv->preview = _cairo_image_surface_scale_bilinear (source, preview_width,
preview_height);
+ self->priv->preview = _cairo_image_surface_scale_fast (source, preview_width, preview_height);
else
self->priv->preview = cairo_surface_reference (source);
diff --git a/extensions/file_tools/gth-image-line-tool.c b/extensions/file_tools/gth-image-line-tool.c
index 115c999..f33118e 100644
--- a/extensions/file_tools/gth-image-line-tool.c
+++ b/extensions/file_tools/gth-image-line-tool.c
@@ -147,7 +147,7 @@ update_image_surface (GthImageLineTool *self)
gtk_widget_get_allocation (GTK_WIDGET (self->priv->viewer), &allocation);
max_size = MAX (allocation.width, allocation.height) / G_SQRT2 + 2;
if (scale_keeping_ratio (&width, &height, max_size, max_size, FALSE))
- preview_image = _cairo_image_surface_scale_bilinear (image, width, height);
+ preview_image = _cairo_image_surface_scale_fast (image, width, height);
else
preview_image = cairo_surface_reference (image);
diff --git a/extensions/file_tools/gth-image-rotator.c b/extensions/file_tools/gth-image-rotator.c
index b596d3e..df0ec7d 100644
--- a/extensions/file_tools/gth-image-rotator.c
+++ b/extensions/file_tools/gth-image-rotator.c
@@ -241,7 +241,7 @@ update_image_surface (GthImageRotator *self)
gtk_widget_get_allocation (GTK_WIDGET (self->priv->viewer), &allocation);
max_size = MAX (allocation.width, allocation.height) / G_SQRT2 + 2;
if (scale_keeping_ratio (&width, &height, max_size, max_size, FALSE))
- preview_image = _cairo_image_surface_scale_bilinear (image, width, height);
+ preview_image = _cairo_image_surface_scale_fast (image, width, height);
else
preview_image = cairo_surface_reference (image);
diff --git a/extensions/file_tools/gth-preview-tool.c b/extensions/file_tools/gth-preview-tool.c
index 77e6eed..cefa1c2 100644
--- a/extensions/file_tools/gth-preview-tool.c
+++ b/extensions/file_tools/gth-preview-tool.c
@@ -119,7 +119,7 @@ update_preview_image (GthPreviewTool *self)
gtk_widget_get_allocation (GTK_WIDGET (self->priv->viewer), &allocation);
max_size = MAX (allocation.width, allocation.height) / G_SQRT2 + 2;
if (scale_keeping_ratio (&width, &height, max_size, max_size, FALSE))
- self->priv->preview_image = _cairo_image_surface_scale_bilinear (image, width, height);
+ self->priv->preview_image = _cairo_image_surface_scale_fast (image, width, height);
else
self->priv->preview_image = cairo_surface_reference (image);
diff --git a/gthumb/cairo-scale.c b/gthumb/cairo-scale.c
index 2591de4..e663864 100644
--- a/gthumb/cairo-scale.c
+++ b/gthumb/cairo-scale.c
@@ -146,6 +146,15 @@ _cairo_image_surface_scale_nearest (cairo_surface_t *image,
}
+cairo_surface_t *
+_cairo_image_surface_scale_fast (cairo_surface_t *image,
+ int new_width,
+ int new_height)
+{
+ return _cairo_image_surface_scale (image, new_width, new_height, SCALE_FILTER_BOX, NULL);
+}
+
+
/* -- _cairo_image_surface_scale_filter --
*
* Based on code from ImageMagick/magick/resize.c
@@ -603,322 +612,6 @@ _cairo_image_surface_scale_squared (cairo_surface_t *image,
}
-/* -- _cairo_image_surface_scale_bilinear -- */
-
-
-#if 0
-
-
-#define BILINEAR_INTERPOLATE(v, v00, v01, v10, v11, fx, fy) \
- tmp = (1.0 - (fy)) * \
- ((1.0 - (fx)) * (v00) + (fx) * (v01)) \
- + \
- (fy) * \
- ((1.0 - (fx)) * (v10) + (fx) * (v11)); \
- v = CLAMP (tmp, 0, 255);
-
-
-cairo_surface_t *
-_cairo_image_surface_scale_bilinear_2x2 (cairo_surface_t *image,
- int new_width,
- int new_height)
-{
- cairo_surface_t *scaled;
- int src_width;
- int src_height;
- guchar *p_src;
- guchar *p_dest;
- int src_rowstride;
- int dest_rowstride;
- ScaleReal step_x, step_y;
- guchar *p_dest_row;
- guchar *p_src_row;
- guchar *p_src_col;
- guchar *p_dest_col;
- ScaleReal x_src, y_src;
- int x, y;
- guchar r00, r01, r10, r11;
- guchar g00, g01, g10, g11;
- guchar b00, b01, b10, b11;
- guchar a00, a01, a10, a11;
- guchar r, g, b, a;
- guint32 pixel;
- ScaleReal tmp;
- ScaleReal x_fract, y_fract;
- int col, row;
-
- scaled = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- new_width,
- new_height);
-
- src_width = cairo_image_surface_get_width (image);
- src_height = cairo_image_surface_get_height (image);
- p_src = _cairo_image_surface_flush_and_get_data (image);
- p_dest = _cairo_image_surface_flush_and_get_data (scaled);
- src_rowstride = cairo_image_surface_get_stride (image);
- dest_rowstride = cairo_image_surface_get_stride (scaled);
-
- cairo_surface_flush (scaled);
-
- step_x = (ScaleReal) src_width / new_width;
- step_y = (ScaleReal) src_height / new_height;
- p_dest_row = p_dest;
- p_src_row = p_src;
- y_src = 0;
-
- for (y = 0; y < new_height; y++) {
- row = floor (y_src);
- y_fract = y_src - row;
- p_src_row = p_src + (row * src_rowstride);
-
- p_dest_col = p_dest_row;
- p_src_col = p_src_row;
- x_src = 0;
- for (x = 0; x < new_width; x++) {
- col = floor (x_src);
- x_fract = x_src - col;
- p_src_col = p_src_row + (col * 4);
-
- /* x00 */
-
- CAIRO_COPY_RGBA (p_src_col, r00, g00, b00, a00);
-
- /* x01 */
-
- if (col + 1 < src_width - 1) {
- p_src_col += 4;
- CAIRO_COPY_RGBA (p_src_col, r01, g01, b01, a01);
- }
- else {
- r01 = r00;
- g01 = g00;
- b01 = b00;
- a01 = a00;
- }
-
- /* x10 */
-
- if (row + 1 < src_height - 1) {
- p_src_col = p_src_row + src_rowstride + (col * 4);
- CAIRO_COPY_RGBA (p_src_col, r10, g10, b10, a10);
- }
- else {
- r10 = r00;
- g10 = g00;
- b10 = b00;
- a10 = a00;
- }
-
- /* x11 */
-
- if ((row + 1 < src_height - 1) && (col + 1 < src_width - 1)) {
- p_src_col += 4;
- CAIRO_COPY_RGBA (p_src_col, r11, g11, b11, a11);
- }
- else {
- r11 = r00;
- g11 = g00;
- b11 = b00;
- a11 = a00;
- }
-
- BILINEAR_INTERPOLATE (r, r00, r01, r10, r11, x_fract, y_fract);
- BILINEAR_INTERPOLATE (g, g00, g01, g10, g11, x_fract, y_fract);
- BILINEAR_INTERPOLATE (b, b00, b01, b10, b11, x_fract, y_fract);
- BILINEAR_INTERPOLATE (a, a00, a01, a10, a11, x_fract, y_fract);
- pixel = CAIRO_RGBA_TO_UINT32 (r, g, b, a);
- memcpy (p_dest_col, &pixel, 4);
-
- p_dest_col += 4;
- x_src += step_x;
- }
-
- p_dest_row += dest_rowstride;
- y_src += step_y;
- }
-
- cairo_surface_mark_dirty (scaled);
-
- return scaled;
-}
-
-
-static void
-_cairo_surface_reduce_row (guchar *dest_data,
- guchar *src_row0,
- guchar *src_row1,
- guchar *src_row2,
- int src_width)
-{
- int x, b;
- ScaleReal sum;
- int col0, col1, col2;
- guchar c[4];
- guint32 pixel;
-
- /* Pre calculated gausian matrix
- * Standard deviation = 0.71
-
- 12 32 12
- 32 86 32
- 12 32 12
-
- Matrix sum is = 262
- Normalize by dividing with 273
-
- */
-
- for (x = 0; x < src_width - (src_width % 2); x += 2) {
- for (b = 0; b < 4; b++) {
-
- col0 = MAX (x - 1, 0) * 4 + b;
- col1 = x * 4 + b;
- col2 = MIN (x + 1, src_width - 1) * 4 + b;
-
- sum = 0.0;
-
- sum += src_row0[col0] * 12;
- sum += src_row0[col1] * 32;
- sum += src_row0[col2] * 12;
-
- sum += src_row1[col0] * 32;
- sum += src_row1[col1] * 86;
- sum += src_row1[col2] * 32;
-
- sum += src_row2[col0] * 12;
- sum += src_row2[col1] * 32;
- sum += src_row2[col2] * 12;
-
- sum /= 262.0;
-
- c[b] = CLAMP (sum, 0, 255);
- }
-
- pixel = CAIRO_RGBA_TO_UINT32 (c[CAIRO_RED], c[CAIRO_GREEN], c[CAIRO_BLUE], c[CAIRO_ALPHA]);
- memcpy (dest_data, &pixel, 4);
-
- dest_data += 4;
- }
-}
-
-
-static cairo_surface_t *
-_cairo_surface_reduce_by_half (cairo_surface_t *src)
-{
- int src_width, src_height;
- cairo_surface_t *dest;
- int src_rowstride, dest_rowstride;
- guchar *row0, *row1, *row2;
- guchar *src_data, *dest_data;
- int y;
-
- src_width = cairo_image_surface_get_width (src);
- src_height = cairo_image_surface_get_height (src);
- dest = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- src_width / 2,
- src_height / 2);
-
- dest_rowstride = cairo_image_surface_get_stride (dest);
- dest_data = _cairo_image_surface_flush_and_get_data (dest);
-
- src_rowstride = cairo_image_surface_get_stride (src);
- src_data = _cairo_image_surface_flush_and_get_data (src);
-
- for (y = 0; y < src_height - (src_height % 2); y += 2) {
- row0 = src_data + (MAX (y - 1, 0) * src_rowstride);
- row1 = src_data + (y * src_rowstride);
- row2 = src_data + (MIN (y + 1, src_height - 1) * src_rowstride);
-
- _cairo_surface_reduce_row (dest_data,
- row0,
- row1,
- row2,
- src_width);
-
- dest_data += dest_rowstride;
- }
-
- cairo_surface_mark_dirty (dest);
-
- return dest;
-}
-
-
-#endif
-
-
-static cairo_surface_t *
-_cairo_image_surface_scale_bilinear_2x2 (cairo_surface_t *image,
- int new_width,
- int new_height)
-{
- cairo_surface_t *output;
- cairo_t *cr;
-
- output = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- new_width,
- new_height);
- cr = cairo_create (output);
- cairo_scale (cr,
- (double) new_width / cairo_image_surface_get_width (image),
- (double) new_height / cairo_image_surface_get_height (image));
- cairo_set_source_surface (cr, image, 0.0, 0.0);
- cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR);
- cairo_rectangle (cr, 0.0, 0.0, cairo_image_surface_get_width (image), cairo_image_surface_get_height
(image));
- cairo_fill (cr);
- cairo_surface_flush (output);
-
- cairo_destroy (cr);
-
- return output;
-}
-
-
-cairo_surface_t *
-_cairo_image_surface_scale_bilinear (cairo_surface_t *image,
- int new_width,
- int new_height)
-{
- double scale, last_scale, s;
- int iterations = 0;
- cairo_surface_t *tmp;
- cairo_surface_t *tmp2;
- double w, h;
-
- if ((new_width == 0) || (new_height == 0))
- return NULL;
-
- scale = (double) new_width / cairo_image_surface_get_width (image);
- last_scale = 1.0;
- s = scale;
- while (s < 1.0 / _CAIRO_MAX_SCALE_FACTOR) {
- s *= _CAIRO_MAX_SCALE_FACTOR;
- last_scale /= _CAIRO_MAX_SCALE_FACTOR;
- iterations++;
- }
- last_scale = last_scale / scale;
-
- tmp = cairo_surface_reference (image);
- w = cairo_image_surface_get_width (tmp);
- h = cairo_image_surface_get_height (tmp);
-
- while (iterations-- > 0) {
- w /= _CAIRO_MAX_SCALE_FACTOR;
- h /= _CAIRO_MAX_SCALE_FACTOR;
- tmp2 = _cairo_image_surface_scale_bilinear_2x2 (tmp, round (w), round (h));
- cairo_surface_destroy (tmp);
- tmp = tmp2;
- }
-
- w /= last_scale;
- h /= last_scale;
- tmp2 = _cairo_image_surface_scale_bilinear_2x2 (tmp, round (w), round (h));
- cairo_surface_destroy (tmp);
-
- return tmp2;
-}
-
-
/* -- _cairo_image_surface_scale_async -- */
diff --git a/gthumb/cairo-scale.h b/gthumb/cairo-scale.h
index a0f58ff..44662d2 100644
--- a/gthumb/cairo-scale.h
+++ b/gthumb/cairo-scale.h
@@ -50,6 +50,9 @@ typedef enum /*< skip >*/ {
cairo_surface_t * _cairo_image_surface_scale_nearest (cairo_surface_t *image,
int new_width,
int new_height);
+cairo_surface_t * _cairo_image_surface_scale_fast (cairo_surface_t *image,
+ int new_width,
+ int new_height);
cairo_surface_t * _cairo_image_surface_scale (cairo_surface_t *image,
int width,
int height,
@@ -59,9 +62,6 @@ cairo_surface_t * _cairo_image_surface_scale_squared (cairo_surface_t *imag
int size,
scale_filter_t quality,
GthAsyncTask *task);
-cairo_surface_t * _cairo_image_surface_scale_bilinear (cairo_surface_t *image,
- int new_width,
- int new_height);
void _cairo_image_surface_scale_async (cairo_surface_t *image,
int new_width,
int new_height,
diff --git a/gthumb/gth-image-overview.c b/gthumb/gth-image-overview.c
index 8e7cb5a..18a15d8 100644
--- a/gthumb/gth-image-overview.c
+++ b/gthumb/gth-image-overview.c
@@ -188,9 +188,9 @@ _gth_image_overview_update_preview (GthImageOverview *self)
}
_gth_image_overview_update_zoom_info (self);
- self->priv->preview = _cairo_image_surface_scale_bilinear (image,
- self->priv->preview_area.width,
- self->priv->preview_area.height);
+ self->priv->preview = _cairo_image_surface_scale_fast (image,
+ self->priv->preview_area.width,
+ self->priv->preview_area.height);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]