Commit 88e4a462 authored by Michael Natterer's avatar Michael Natterer 😴

plug-ins: port file-csource to GEGL

parent 8c72ad9b
...@@ -1018,6 +1018,7 @@ file_csource_LDADD = \ ...@@ -1018,6 +1018,7 @@ file_csource_LDADD = \
$(libgimpcolor) \ $(libgimpcolor) \
$(libgimpbase) \ $(libgimpbase) \
$(GTK_LIBS) \ $(GTK_LIBS) \
$(GEGL_LIBS) \
$(RT_LIBS) \ $(RT_LIBS) \
$(INTLLIBS) \ $(INTLLIBS) \
$(file_csource_RC) $(file_csource_RC)
......
...@@ -51,7 +51,6 @@ typedef struct ...@@ -51,7 +51,6 @@ typedef struct
} Config; } Config;
/* --- prototypes --- */
static void query (void); static void query (void);
static void run (const gchar *name, static void run (const gchar *name,
gint nparams, gint nparams,
...@@ -65,7 +64,7 @@ static gboolean save_image (Config *config, ...@@ -65,7 +64,7 @@ static gboolean save_image (Config *config,
GError **error); GError **error);
static gboolean run_save_dialog (Config *config); static gboolean run_save_dialog (Config *config);
/* --- variables --- */
const GimpPlugInInfo PLUG_IN_INFO = const GimpPlugInInfo PLUG_IN_INFO =
{ {
NULL, /* init_proc */ NULL, /* init_proc */
...@@ -88,10 +87,10 @@ static Config config = ...@@ -88,10 +87,10 @@ static Config config =
100.0, /* opacity */ 100.0, /* opacity */
}; };
/* --- implement main (), provided by libgimp --- */
MAIN () MAIN ()
/* --- functions --- */
static void static void
query (void) query (void)
{ {
...@@ -133,13 +132,14 @@ run (const gchar *name, ...@@ -133,13 +132,14 @@ run (const gchar *name,
GimpExportReturn export = GIMP_EXPORT_CANCEL; GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL; GError *error = NULL;
INIT_I18N ();
gegl_init (NULL, NULL);
run_mode = param[0].data.d_int32; run_mode = param[0].data.d_int32;
*nreturn_vals = 1; *nreturn_vals = 1;
*return_vals = values; *return_vals = values;
INIT_I18N ();
values[0].type = GIMP_PDB_STATUS; values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
...@@ -173,8 +173,8 @@ run (const gchar *name, ...@@ -173,8 +173,8 @@ run (const gchar *name,
gimp_ui_init (PLUG_IN_BINARY, FALSE); gimp_ui_init (PLUG_IN_BINARY, FALSE);
export = gimp_export_image (&image_ID, &drawable_ID, NULL, export = gimp_export_image (&image_ID, &drawable_ID, NULL,
(GIMP_EXPORT_CAN_HANDLE_RGB | GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_ALPHA )); GIMP_EXPORT_CAN_HANDLE_ALPHA);
if (export == GIMP_EXPORT_CANCEL) if (export == GIMP_EXPORT_CANCEL)
{ {
...@@ -390,15 +390,19 @@ save_image (Config *config, ...@@ -390,15 +390,19 @@ save_image (Config *config,
gint32 drawable_ID, gint32 drawable_ID,
GError **error) GError **error)
{ {
GimpDrawable *drawable = gimp_drawable_get (drawable_ID); GeglBuffer *buffer;
GimpImageType drawable_type = gimp_drawable_type (drawable_ID); FILE *fp;
GimpPixelRgn pixel_rgn; GimpImageType drawable_type = gimp_drawable_type (drawable_ID);
gchar *s_uint_8, *s_uint, *s_char, *s_null; gchar *s_uint_8, *s_uint, *s_char, *s_null;
FILE *fp; guint c;
guint c; gchar *macro_name;
gchar *macro_name; guint8 *img_buffer, *img_buffer_end;
guint8 *img_buffer, *img_buffer_end; gchar *basename;
gchar *basename; guint8 *data, *p;
gint width;
gint height;
gint x, y, pad, n_bytes, bpp;
gint drawable_bpp;
fp = g_fopen (config->file_name, "w"); fp = g_fopen (config->file_name, "w");
if (! fp) if (! fp)
...@@ -410,84 +414,90 @@ save_image (Config *config, ...@@ -410,84 +414,90 @@ save_image (Config *config,
return FALSE; return FALSE;
} }
gimp_pixel_rgn_init (&pixel_rgn, drawable, buffer = gimp_drawable_get_buffer (drawable_ID);
0, 0, drawable->width, drawable->height, FALSE, FALSE);
if (1) width = gegl_buffer_get_width (buffer);
{ height = gegl_buffer_get_height (buffer);
guint8 *data, *p;
gint x, y, pad, n_bytes, bpp;
bpp = config->rgb565 ? 2 : (config->alpha ? 4 : 3); drawable_bpp = gimp_drawable_bpp (drawable_ID);
n_bytes = drawable->width * drawable->height * bpp;
pad = drawable->width * drawable->bpp; bpp = config->rgb565 ? 2 : (config->alpha ? 4 : 3);
if (config->use_rle) n_bytes = width * height * bpp;
pad = MAX (pad, 130 + n_bytes / 127); pad = width * bpp;
if (config->use_rle)
pad = MAX (pad, 130 + n_bytes / 127);
data = g_new (guint8, pad + n_bytes); data = g_new (guint8, pad + n_bytes);
p = data + pad; p = data + pad;
for (y = 0; y < height; y++)
{
gegl_buffer_get (buffer, GEGL_RECTANGLE (0, y, width, 1), 1.0,
NULL, data,
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
for (y = 0; y < drawable->height; y++) if (bpp == 2)
{ {
gimp_pixel_rgn_get_row (&pixel_rgn, data, 0, y, drawable->width); for (x = 0; x < width; x++)
{
if (bpp == 2) guint8 *d = data + x * drawable_bpp;
for (x = 0; x < drawable->width; x++) guint8 r, g, b;
{ gushort rgb16;
guint8 *d = data + x * drawable->bpp; gdouble alpha = drawable_type == GIMP_RGBA_IMAGE ? d[3] : 0xff;
guint8 r, g, b;
gushort rgb16; alpha *= config->opacity / 25500.0;
gdouble alpha = drawable_type == GIMP_RGBA_IMAGE ? d[3] : 0xff; r = (0.5 + alpha * (gdouble) d[0]);
g = (0.5 + alpha * (gdouble) d[1]);
alpha *= config->opacity / 25500.0; b = (0.5 + alpha * (gdouble) d[2]);
r = (0.5 + alpha * (gdouble) d[0]); r >>= 3;
g = (0.5 + alpha * (gdouble) d[1]); g >>= 2;
b = (0.5 + alpha * (gdouble) d[2]); b >>= 3;
r >>= 3; rgb16 = (r << 11) + (g << 5) + b;
g >>= 2; *(p++) = (guchar) rgb16;
b >>= 3; *(p++) = (guchar) (rgb16 >> 8);
rgb16 = (r << 11) + (g << 5) + b; }
*(p++) = (guchar) rgb16;
*(p++) = (guchar) (rgb16 >> 8);
}
else if (config->alpha)
for (x = 0; x < drawable->width; x++)
{
guint8 *d = data + x * drawable->bpp;
gdouble alpha = drawable_type == GIMP_RGBA_IMAGE ? d[3] : 0xff;
alpha *= config->opacity / 100.0;
*(p++) = d[0];
*(p++) = d[1];
*(p++) = d[2];
*(p++) = alpha + 0.5;
}
else
for (x = 0; x < drawable->width; x++)
{
guint8 *d = data + x * drawable->bpp;
gdouble alpha = drawable_type == GIMP_RGBA_IMAGE ? d[3] : 0xff;
alpha *= config->opacity / 25500.0;
*(p++) = 0.5 + alpha * (gdouble) d[0];
*(p++) = 0.5 + alpha * (gdouble) d[1];
*(p++) = 0.5 + alpha * (gdouble) d[2];
}
} }
else if (config->alpha)
img_buffer = data + pad;
if (config->use_rle)
{ {
img_buffer_end = rl_encode_rgbx (data, img_buffer, for (x = 0; x < width; x++)
img_buffer + n_bytes, bpp); {
img_buffer = data; guint8 *d = data + x * drawable_bpp;
gdouble alpha = drawable_type == GIMP_RGBA_IMAGE ? d[3] : 0xff;
alpha *= config->opacity / 100.0;
*(p++) = d[0];
*(p++) = d[1];
*(p++) = d[2];
*(p++) = alpha + 0.5;
}
} }
else else
{ {
img_buffer_end = img_buffer + n_bytes; for (x = 0; x < width; x++)
{
guint8 *d = data + x * drawable_bpp;
gdouble alpha = drawable_type == GIMP_RGBA_IMAGE ? d[3] : 0xff;
alpha *= config->opacity / 25500.0;
*(p++) = 0.5 + alpha * (gdouble) d[0];
*(p++) = 0.5 + alpha * (gdouble) d[1];
*(p++) = 0.5 + alpha * (gdouble) d[2];
}
} }
} }
img_buffer = data + pad;
if (config->use_rle)
{
img_buffer_end = rl_encode_rgbx (data, img_buffer,
img_buffer + n_bytes, bpp);
img_buffer = data;
}
else
{
img_buffer_end = img_buffer + n_bytes;
}
if (!config->use_macros && config->glib_types) if (!config->use_macros && config->glib_types)
{ {
s_uint_8 = "guint8 "; s_uint_8 = "guint8 ";
...@@ -551,21 +561,21 @@ save_image (Config *config, ...@@ -551,21 +561,21 @@ save_image (Config *config,
fprintf (fp, "%u + 1];\n", (guint) (img_buffer_end - img_buffer)); fprintf (fp, "%u + 1];\n", (guint) (img_buffer_end - img_buffer));
else else
fprintf (fp, "%u * %u * %u + 1];\n", fprintf (fp, "%u * %u * %u + 1];\n",
drawable->width, width,
drawable->height, height,
config->rgb565 ? 2 : (config->alpha ? 4 : 3)); config->rgb565 ? 2 : (config->alpha ? 4 : 3));
fprintf (fp, "} %s = {\n", config->prefixed_name); fprintf (fp, "} %s = {\n", config->prefixed_name);
fprintf (fp, " %u, %u, %u,\n", fprintf (fp, " %u, %u, %u,\n",
drawable->width, width,
drawable->height, height,
config->rgb565 ? 2 : (config->alpha ? 4 : 3)); config->rgb565 ? 2 : (config->alpha ? 4 : 3));
} }
else /* use macros */ else /* use macros */
{ {
fprintf (fp, "#define %s_WIDTH (%u)\n", fprintf (fp, "#define %s_WIDTH (%u)\n",
macro_name, drawable->width); macro_name, width);
fprintf (fp, "#define %s_HEIGHT (%u)\n", fprintf (fp, "#define %s_HEIGHT (%u)\n",
macro_name, drawable->height); macro_name, height);
fprintf (fp, "#define %s_BYTES_PER_PIXEL (%u) /* 3:RGB, 4:RGBA */\n", fprintf (fp, "#define %s_BYTES_PER_PIXEL (%u) /* 3:RGB, 4:RGBA */\n",
macro_name, config->alpha ? 4 : 3); macro_name, config->alpha ? 4 : 3);
} }
...@@ -630,8 +640,8 @@ save_image (Config *config, ...@@ -630,8 +640,8 @@ save_image (Config *config,
fprintf (fp, "%u] =\n", (guint) (img_buffer_end - img_buffer)); fprintf (fp, "%u] =\n", (guint) (img_buffer_end - img_buffer));
else else
fprintf (fp, "%u * %u * %u + 1] =\n", fprintf (fp, "%u * %u * %u + 1] =\n",
drawable->width, width,
drawable->height, height,
config->alpha ? 4 : 3); config->alpha ? 4 : 3);
fprintf (fp, "(\""); fprintf (fp, "(\"");
c = 2; c = 2;
...@@ -660,8 +670,7 @@ save_image (Config *config, ...@@ -660,8 +670,7 @@ save_image (Config *config,
fprintf (fp, "\");\n\n"); fprintf (fp, "\");\n\n");
fclose (fp); fclose (fp);
g_object_unref (buffer);
gimp_drawable_detach (drawable);
return TRUE; return TRUE;
} }
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
'engrave' => { ui => 1 }, 'engrave' => { ui => 1 },
'file-aa' => { ui => 1, gegl => 1, optional => 1, libs => 'AA_LIBS' }, 'file-aa' => { ui => 1, gegl => 1, optional => 1, libs => 'AA_LIBS' },
'file-cel' => { ui => 1 }, 'file-cel' => { ui => 1 },
'file-csource' => { ui => 1 }, 'file-csource' => { ui => 1, gegl => 1 },
'file-desktop-link' => {}, 'file-desktop-link' => {},
'file-dicom' => { ui => 1, cflags => '-fno-strict-aliasing' }, 'file-dicom' => { ui => 1, cflags => '-fno-strict-aliasing' },
'file-gbr' => { ui => 1, gegl => 1 }, 'file-gbr' => { ui => 1, gegl => 1 },
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment