[gegl/wip/rishi/operation-shadhi] factor out mrg_blit from gegl ui
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/wip/rishi/operation-shadhi] factor out mrg_blit from gegl ui
- Date: Sat, 11 Nov 2017 14:56:32 +0000 (UTC)
commit ba05f609ad913f95f8ff7157901b30ff8b48c732
Author: Øyvind Kolås <pippin gimp org>
Date: Fri Nov 10 16:49:29 2017 +0100
factor out mrg_blit from gegl ui
bin/Makefile.am | 2 +-
bin/mrg-gegl.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
bin/ui.c | 95 +++------------------------------------
3 files changed, 142 insertions(+), 88 deletions(-)
---
diff --git a/bin/Makefile.am b/bin/Makefile.am
index d4dfd20..d385bdb 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -43,7 +43,7 @@ gegl_SOURCES = \
if HAVE_MRG
if HAVE_GEXIV2
if HAVE_SDL
-gegl_SOURCES += ui.c
+gegl_SOURCES += ui.c mrg-gegl.c
AM_CFLAGS += $(SDL_CFLAGS)
AM_LDFLAGS += $(SDL_LIBS)
endif
diff --git a/bin/mrg-gegl.c b/bin/mrg-gegl.c
new file mode 100644
index 0000000..7ced6ec
--- /dev/null
+++ b/bin/mrg-gegl.c
@@ -0,0 +1,133 @@
+/* This file is part of GEGL editor -- an mrg frontend for GEGL
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2015 Øyvind Kolås pippin gimp org
+ */
+
+/* The code in this file is an image viewer/editor written using microraptor
+ * gui and GEGL. It renders the UI directly from GEGLs data structures.
+ */
+
+#define _BSD_SOURCE
+#define _DEFAULT_SOURCE
+
+#include "config.h"
+
+#if HAVE_MRG
+
+#include <ctype.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <mrg.h>
+#include <gegl.h>
+#include <gexiv2/gexiv2.h>
+#include <gegl-paramspecs.h>
+#include <SDL.h>
+#include <gegl-audio-fragment.h>
+
+static unsigned char *copy_buf = NULL;
+static int copy_buf_len = 0;
+
+void mrg_gegl_blit (Mrg *mrg,
+ float x0, float y0,
+ float width, float height,
+ GeglNode *node,
+ float u, float v,
+ float scale,
+ float preview_multiplier);
+
+void mrg_gegl_blit (Mrg *mrg,
+ float x0, float y0,
+ float width, float height,
+ GeglNode *node,
+ float u, float v,
+ float scale,
+ float preview_multiplier)
+{
+ float fake_factor = preview_multiplier;
+ GeglRectangle bounds;
+
+ cairo_t *cr = mrg_cr (mrg);
+ cairo_surface_t *surface = NULL;
+
+ if (!node)
+ return;
+
+ bounds = gegl_node_get_bounding_box (node);
+
+ if (width == -1 && height == -1)
+ {
+ width = bounds.width;
+ height = bounds.height;
+ }
+
+ if (width == -1)
+ width = bounds.width * height / bounds.height;
+ if (height == -1)
+ height = bounds.height * width / bounds.width;
+
+ width /= fake_factor;
+ height /= fake_factor;
+ u /= fake_factor;
+ v /= fake_factor;
+
+ if (copy_buf_len < width * height * 4)
+ {
+ if (copy_buf)
+ free (copy_buf);
+ copy_buf_len = width * height * 4;
+ copy_buf = malloc (copy_buf_len);
+ }
+ {
+ static int foo = 0;
+ unsigned char *buf = copy_buf;
+ GeglRectangle roi = {u, v, width, height};
+ static const Babl *fmt = NULL;
+
+foo++;
+ if (!fmt) fmt = babl_format ("cairo-RGB24");
+ gegl_node_blit (node, scale / fake_factor, &roi, fmt, buf, width * 4,
+ GEGL_BLIT_DEFAULT);
+ surface = cairo_image_surface_create_for_data (buf, CAIRO_FORMAT_RGB24, width, height, width * 4);
+ }
+
+ cairo_save (cr);
+ cairo_surface_set_device_scale (surface, 1.0/fake_factor, 1.0/fake_factor);
+
+ width *= fake_factor;
+ height *= fake_factor;
+ u *= fake_factor;
+ v *= fake_factor;
+
+ cairo_rectangle (cr, x0, y0, width, height);
+
+ cairo_clip (cr);
+ cairo_translate (cr, x0 * fake_factor, y0 * fake_factor);
+ cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
+ cairo_set_source_surface (cr, surface, 0, 0);
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_paint (cr);
+ cairo_surface_destroy (surface);
+ cairo_restore (cr);
+}
+
+
+#endif
diff --git a/bin/ui.c b/bin/ui.c
index 4522033..de4339e 100644
--- a/bin/ui.c
+++ b/bin/ui.c
@@ -46,6 +46,14 @@
*/
// #define DEBUG_OP_LIST 1
+void mrg_gegl_blit (Mrg *mrg,
+ float x0, float y0,
+ float width, float height,
+ GeglNode *node,
+ float u, float v,
+ float scale,
+ float preview_multiplier);
+
static int audio_len = 0;
static int audio_pos = 0;
@@ -158,14 +166,6 @@ static int is_gegl_path (const char *path);
static void contrasty_stroke (cairo_t *cr);
-static void mrg_gegl_blit (Mrg *mrg,
- float x0, float y0,
- float width, float height,
- GeglNode *node,
- float u, float v,
- float scale,
- float preview_multiplier);
-
gchar *get_thumb_path (const char *path);
gchar *get_thumb_path (const char *path)
{
@@ -1198,85 +1198,6 @@ static void contrasty_stroke (cairo_t *cr)
cairo_stroke (cr);
}
-static unsigned char *copy_buf = NULL;
-static int copy_buf_len = 0;
-
-static void mrg_gegl_blit (Mrg *mrg,
- float x0, float y0,
- float width, float height,
- GeglNode *node,
- float u, float v,
- float scale,
- float preview_multiplier)
-{
- float fake_factor = preview_multiplier;
- GeglRectangle bounds;
-
- cairo_t *cr = mrg_cr (mrg);
- cairo_surface_t *surface = NULL;
-
- if (!node)
- return;
-
- bounds = gegl_node_get_bounding_box (node);
-
- if (width == -1 && height == -1)
- {
- width = bounds.width;
- height = bounds.height;
- }
-
- if (width == -1)
- width = bounds.width * height / bounds.height;
- if (height == -1)
- height = bounds.height * width / bounds.width;
-
- width /= fake_factor;
- height /= fake_factor;
- u /= fake_factor;
- v /= fake_factor;
-
- if (copy_buf_len < width * height * 4)
- {
- if (copy_buf)
- free (copy_buf);
- copy_buf_len = width * height * 4;
- copy_buf = malloc (copy_buf_len);
- }
- {
- static int foo = 0;
- unsigned char *buf = copy_buf;
- GeglRectangle roi = {u, v, width, height};
- static const Babl *fmt = NULL;
-
-foo++;
- if (!fmt) fmt = babl_format ("cairo-RGB24");
- gegl_node_blit (node, scale / fake_factor, &roi, fmt, buf, width * 4,
- GEGL_BLIT_DEFAULT);
- surface = cairo_image_surface_create_for_data (buf, CAIRO_FORMAT_RGB24, width, height, width * 4);
- }
-
- cairo_save (cr);
- cairo_surface_set_device_scale (surface, 1.0/fake_factor, 1.0/fake_factor);
-
- width *= fake_factor;
- height *= fake_factor;
- u *= fake_factor;
- v *= fake_factor;
-
- cairo_rectangle (cr, x0, y0, width, height);
-
- cairo_clip (cr);
- cairo_translate (cr, x0 * fake_factor, y0 * fake_factor);
- cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
- cairo_set_source_surface (cr, surface, 0, 0);
-
- cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
- cairo_paint (cr);
- cairo_surface_destroy (surface);
- cairo_restore (cr);
-}
-
static void load_path (State *o)
{
char *path;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]