[gegl] workshop/enlarge: add checker alpha removal utility function
- From: Øyvind "pippin" Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] workshop/enlarge: add checker alpha removal utility function
- Date: Fri, 28 Jun 2019 13:55:29 +0000 (UTC)
commit 0693b1c4fe1c5fa23308bc50aa99a094333f08ac
Author: Øyvind Kolås <pippin gimp org>
Date: Wed Jun 26 19:34:34 2019 +0200
workshop/enlarge: add checker alpha removal utility function
operations/workshop/enlarge.c | 58 ++++++++++++++++++++++++++++++++++++--
operations/workshop/pixel-duster.h | 20 ++++++-------
2 files changed, 65 insertions(+), 13 deletions(-)
---
diff --git a/operations/workshop/enlarge.c b/operations/workshop/enlarge.c
index ad240a67e..d6ba55544 100644
--- a/operations/workshop/enlarge.c
+++ b/operations/workshop/enlarge.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include "config.h"
#include <glib/gi18n-lib.h>
+#include <math.h>
#ifdef GEGL_PROPERTIES
@@ -79,12 +80,61 @@ static void scaled_copy (PixelDuster *duster,
{
float rgba[4];
GeglRectangle r = {x, y, 1, 1};
- gegl_sampler_get (duster->in_sampler_f, x / scale, y / scale, NULL,
+ gegl_sampler_get (duster->in_sampler_f, x / scale+0.5, y / scale+0.5, NULL,
&rgba[0], 0);
gegl_buffer_set (out, &r, 0, format, &rgba[0], 0);
}
}
+static void remove_checker (GeglBuffer *out,
+ int phase)
+{
+ GeglRectangle rect;
+ const Babl *format = babl_format ("RGBA float");
+ GeglBufferIterator *iterator;
+ rect = *gegl_buffer_get_extent (out);
+ iterator = gegl_buffer_iterator_new (out, &rect, 0, format, GEGL_BUFFER_READWRITE, GEGL_ABYSS_NONE, 1);
+ while (gegl_buffer_iterator_next (iterator))
+ {
+ int x = iterator->items[0].roi.x;
+ int y = iterator->items[0].roi.y;
+ gfloat *data = iterator->items[0].data;
+
+ int i;
+ for (i = 0; i < iterator->length; i++)
+ {
+
+ if (phase == 0)
+ {
+
+ if ( ((x%2==0) && (y%2==0)) ||
+ ((x%2==1) && (y%2==1)))
+ {
+ data[3]=0.0;
+ }
+ }
+ else
+ {
+ if ( ((x%2==1) && (y%2==1)) ||
+ ((x%2==0) && (y%2==0)))
+ {
+ data[3]=0.0;
+ }
+
+ }
+ data += 4;
+
+ x++;
+ if (x >= iterator->items[0].roi.x + iterator->items[0].roi.width)
+ {
+ x = iterator->items[0].roi.x;
+ y++;
+ }
+ }
+ }
+}
+
+
static void improve (PixelDuster *duster,
GeglBuffer *in,
GeglBuffer *out,
@@ -133,7 +183,7 @@ static void improve (PixelDuster *duster,
}
if (rgba[3] <= 0.01)
- fprintf (stderr, "eek %i,%i %f %f %f %f\n", probe->source_x[MAX_K/2], probe->source_y[MAX_K/2],
rgba[0], rgba[1], rgba[2], rgba[3]);
+ fprintf (stderr, "eek %f,%f %f %f %f %f\n", probe->source_x[MAX_K/2], probe->source_y[MAX_K/2],
rgba[0], rgba[1], rgba[2], rgba[3]);
gegl_buffer_set (duster->output, GEGL_RECTANGLE(probe->target_x, probe->target_y, 1, 1), 0,
format, &rgba[0], 0);
#else
@@ -193,8 +243,12 @@ process (GeglOperation *operation,
NULL);
scaled_copy (duster, input, output, o->scale);
seed_db (duster);
+
+ remove_checker (output, 0);
improve (duster, input, output, o->scale);
+ remove_checker (output, 1);
improve (duster, input, output, o->scale);
+ //improve (duster, input, output, o->scale);
pixel_duster_destroy (duster);
return TRUE;
diff --git a/operations/workshop/pixel-duster.h b/operations/workshop/pixel-duster.h
index a99ef0924..dd78d7dfe 100644
--- a/operations/workshop/pixel-duster.h
+++ b/operations/workshop/pixel-duster.h
@@ -75,10 +75,10 @@ typedef struct
} PixelDuster;
-#define MAX_K 2
+#define MAX_K 1
#define PIXDUST_REL_DIGEST 0
-#define NEIGHBORHOOD 23
-#define PIXDUST_ORDERED 0
+#define NEIGHBORHOOD 123
+#define PIXDUST_ORDERED 1
#define MAX_DIR 4
//#define ONLY_DIR 1
@@ -86,15 +86,15 @@ typedef struct
typedef struct Probe {
int target_x;
int target_y;
- /* the only real datamembers are above should be float*/
int age;
int k;
float score;
- int k_score[MAX_K];
+ float k_score[MAX_K];
/* should store sampled coordinates instead */
- int source_x[MAX_K];
- int source_y[MAX_K];
+ /* the only real datamembers are below and should be float*/
+ float source_x[MAX_K];
+ float source_y[MAX_K];
guchar *hay[MAX_K];
} Probe;
@@ -550,7 +550,6 @@ static int site_subset (guchar *site)
return a;
}
-
static void site_subset2 (guchar *site, gint *min, gint *max)
{
int v[3] = {(site[4 + 1]/4), (site[8 + 1]/4), (site[12 + 1]/4)};
@@ -700,8 +699,6 @@ static int probe_improve (PixelDuster *duster,
void *ptr[3] = {duster, probe, &needle[0]};
float old_score = probe->score;
static const Babl *format = NULL;
- int set_start[3];
- int set_end[3];
if (!format)
format = babl_format ("RGBA float");
@@ -866,8 +863,9 @@ static inline void pixel_duster_fill (PixelDuster *duster)
}
for (gint c = 0; c < 4; c++)
rgba[c] = sum_rgba[c] / probe->k;
+
if (rgba[3] <= 0.01)
- fprintf (stderr, "eek %i,%i %f %f %f %f\n", probe->source_x[MAX_K/2], probe->source_y[MAX_K/2],
rgba[0], rgba[1], rgba[2], rgba[3]);
+ fprintf (stderr, "eek %f,%f %f %f %f %f\n", probe->source_x[MAX_K/2], probe->source_y[MAX_K/2],
rgba[0], rgba[1], rgba[2], rgba[3]);
gegl_buffer_set (duster->output, GEGL_RECTANGLE(probe->target_x, probe->target_y, 1, 1), 0,
format, &rgba[0], 0);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]