From 3182fa2bcae5dea54f7f3c82ead20ac006da0415 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Thu, 11 Jul 2013 21:01:22 +0200 Subject: Add naive up-scaling --- bin/gui/control.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++-- bin/gui/control.glade | 8 +++++++ 2 files changed, 67 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/gui/control.c b/bin/gui/control.c index c177f07..5fa82df 100644 --- a/bin/gui/control.c +++ b/bin/gui/control.c @@ -70,14 +70,14 @@ static UcaPluginManager *plugin_manager; static gsize mem_size = 2048; static void -convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) +down_scale (ThreadData *data, gpointer buffer) { gdouble min; gdouble max; gdouble factor; guint8 *output; - gint i = 0; gint stride; + gint i = 0; egg_histogram_get_visible_range (EGG_HISTOGRAM_VIEW (data->histogram_view), &min, &max); factor = 255.0 / (max - min); @@ -118,6 +118,63 @@ convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) } } +static void +up_scale (ThreadData *data, gpointer buffer) +{ + gdouble min; + gdouble max; + gdouble factor; + guint8 *output; + gint i = 0; + gint zoom; + + egg_histogram_get_visible_range (EGG_HISTOGRAM_VIEW (data->histogram_view), &min, &max); + factor = 255.0 / (max - min); + output = data->pixels; + zoom = (gint) data->zoom_factor; + + if (data->pixel_size == 1) { + guint8 *input = (guint8 *) buffer; + + for (gint y = 0; y < data->display_height; y++) { + for (gint x = 0; x < data->display_width; x++) { + gint offset = ((gint) (y / zoom) * data->width) + ((gint) (x / zoom)); + gdouble dval = (input[offset] - min) * factor; + guchar val = (guchar) CLAMP(dval, 0.0, 255.0); + + output[i++] = val; + output[i++] = val; + output[i++] = val; + } + } + } + else if (data->pixel_size == 2) { + guint16 *input = (guint16 *) buffer; + + for (gint y = 0; y < data->display_height; y++) { + for (gint x = 0; x < data->display_width; x++) { + gint offset = ((gint) (y / zoom) * data->width) + ((gint) (x / zoom)); + gdouble dval = (input[offset] - min) * factor; + guchar val = (guchar) CLAMP(dval, 0.0, 255.0); + + output[i++] = val; + output[i++] = val; + output[i++] = val; + } + } + } +} + + +static void +convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) +{ + if (data->zoom_factor <= 1) + down_scale (data, buffer); + else + up_scale (data, buffer); +} + static void update_pixbuf (ThreadData *data) { diff --git a/bin/gui/control.glade b/bin/gui/control.glade index eec9dde..3f64802 100644 --- a/bin/gui/control.glade +++ b/bin/gui/control.glade @@ -445,6 +445,14 @@ + + 400 % + 4 + + + 200 % + 2 + 100 % 1 -- cgit v1.2.3