2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2000-01-26 01:46:56 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2000-01-26 01:46:56 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2000-01-26 01:46:56 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2000-01-26 01:46:56 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1999-05-29 09:28:24 +08:00
|
|
|
#include <string.h>
|
2000-01-26 01:46:56 +08:00
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
2000-01-17 21:21:13 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-02 01:01:18 +08:00
|
|
|
|
2005-08-14 06:52:41 +08:00
|
|
|
#define SAVE_PROC "file-header-save"
|
2008-08-11 18:06:13 +08:00
|
|
|
#define PLUG_IN_BINARY "file-header"
|
2011-04-09 02:31:34 +08:00
|
|
|
#define PLUG_IN_ROLE "gimp-file-header"
|
2005-08-14 06:52:41 +08:00
|
|
|
|
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
typedef struct _Header Header;
|
|
|
|
typedef struct _HeaderClass HeaderClass;
|
2015-10-18 05:28:45 +08:00
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
struct _Header
|
|
|
|
{
|
|
|
|
GimpPlugIn parent_instance;
|
|
|
|
};
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
struct _HeaderClass
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-08-24 19:41:48 +08:00
|
|
|
GimpPlugInClass parent_class;
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
#define HEADER_TYPE (header_get_type ())
|
|
|
|
#define HEADER (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HEADER_TYPE, Header))
|
|
|
|
|
|
|
|
GType header_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
static GList * header_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * header_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static GimpValueArray * header_save (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
2020-04-14 17:46:17 +08:00
|
|
|
gint n_drawables,
|
|
|
|
GimpDrawable **drawables,
|
2019-08-24 19:41:48 +08:00
|
|
|
GFile *file,
|
2023-07-22 00:08:00 +08:00
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpProcedureConfig *config,
|
2019-08-24 19:41:48 +08:00
|
|
|
gpointer run_data);
|
|
|
|
|
|
|
|
static gboolean save_image (GFile *file,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GError **error);
|
|
|
|
|
|
|
|
static gboolean print (GOutputStream *output,
|
|
|
|
GError **error,
|
|
|
|
const gchar *format,
|
|
|
|
...) G_GNUC_PRINTF (3, 4);
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (Header, header, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (HEADER_TYPE)
|
2022-05-26 06:59:36 +08:00
|
|
|
DEFINE_STD_SET_I18N
|
2019-08-24 19:41:48 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2019-08-24 19:41:48 +08:00
|
|
|
header_class_init (HeaderClass *klass)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-08-24 19:41:48 +08:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
|
|
|
|
|
|
|
plug_in_class->query_procedures = header_query_procedures;
|
|
|
|
plug_in_class->create_procedure = header_create_procedure;
|
2022-05-26 06:59:36 +08:00
|
|
|
plug_in_class->set_i18n = STD_SET_I18N;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-24 19:41:48 +08:00
|
|
|
header_init (Header *header)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-08-24 19:41:48 +08:00
|
|
|
}
|
2012-11-19 07:34:36 +08:00
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
static GList *
|
|
|
|
header_query_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
return g_list_append (NULL, g_strdup (SAVE_PROC));
|
|
|
|
}
|
2003-03-26 00:38:19 +08:00
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
static GimpProcedure *
|
|
|
|
header_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
if (! strcmp (name, SAVE_PROC))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2023-07-23 05:49:47 +08:00
|
|
|
procedure = gimp_save_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
FALSE, header_save, NULL, NULL);
|
2019-08-24 19:41:48 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "INDEXED, RGB");
|
|
|
|
|
2022-07-05 04:50:53 +08:00
|
|
|
gimp_procedure_set_menu_label (procedure, _("C source code header"));
|
2019-08-24 19:41:48 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
"saves files as C unsigned character "
|
|
|
|
"array",
|
|
|
|
"FIXME: write help",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Spencer Kimball & Peter Mattis",
|
|
|
|
"Spencer Kimball & Peter Mattis",
|
|
|
|
"1997");
|
|
|
|
|
|
|
|
gimp_file_procedure_set_handles_remote (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
TRUE);
|
|
|
|
gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"image/x-chdr");
|
|
|
|
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"h");
|
|
|
|
}
|
2013-11-10 07:18:48 +08:00
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
return procedure;
|
|
|
|
}
|
2008-10-20 14:04:39 +08:00
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
static GimpValueArray *
|
|
|
|
header_save (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
2020-04-14 17:46:17 +08:00
|
|
|
gint n_drawables,
|
|
|
|
GimpDrawable **drawables,
|
2019-08-24 19:41:48 +08:00
|
|
|
GFile *file,
|
2023-07-22 00:08:00 +08:00
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpProcedureConfig *config,
|
2019-08-24 19:41:48 +08:00
|
|
|
gpointer run_data)
|
|
|
|
{
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
|
|
|
GError *error = NULL;
|
1999-10-10 03:06:14 +08:00
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
gegl_init (NULL, NULL);
|
1999-10-10 03:06:14 +08:00
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
switch (run_mode)
|
2000-01-26 01:46:56 +08:00
|
|
|
{
|
2019-08-24 19:41:48 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2019-09-21 01:39:00 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY);
|
2019-08-24 19:41:48 +08:00
|
|
|
|
2020-04-14 17:46:17 +08:00
|
|
|
export = gimp_export_image (&image, &n_drawables, &drawables, "Header",
|
2019-08-24 19:41:48 +08:00
|
|
|
GIMP_EXPORT_CAN_HANDLE_RGB |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_INDEXED);
|
|
|
|
|
|
|
|
if (export == GIMP_EXPORT_CANCEL)
|
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_CANCEL,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2000-01-26 01:46:56 +08:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:46:17 +08:00
|
|
|
if (n_drawables != 1)
|
|
|
|
{
|
|
|
|
g_set_error (&error, G_FILE_ERROR, 0,
|
|
|
|
_("Header plug-in does not support multiple layers."));
|
|
|
|
|
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_CALLING_ERROR,
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! save_image (file, image, drawables[0],
|
2019-08-24 19:41:48 +08:00
|
|
|
&error))
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
2019-08-24 19:41:48 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
2014-10-04 05:40:13 +08:00
|
|
|
}
|
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
if (export == GIMP_EXPORT_EXPORT)
|
2020-04-14 17:46:17 +08:00
|
|
|
{
|
|
|
|
gimp_image_delete (image);
|
|
|
|
g_free (drawables);
|
|
|
|
}
|
2019-08-24 19:41:48 +08:00
|
|
|
|
|
|
|
return gimp_procedure_new_return_values (procedure, status, error);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2014-10-04 05:40:13 +08:00
|
|
|
static gboolean
|
2019-08-24 19:41:48 +08:00
|
|
|
save_image (GFile *file,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GError **error)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2012-11-19 07:34:36 +08:00
|
|
|
GeglBuffer *buffer;
|
|
|
|
const Babl *format;
|
2003-07-02 20:03:08 +08:00
|
|
|
GimpImageType drawable_type;
|
2014-10-04 05:40:13 +08:00
|
|
|
GOutputStream *output;
|
2008-09-17 16:37:24 +08:00
|
|
|
gint x, y, b, c;
|
|
|
|
const gchar *backslash = "\\\\";
|
|
|
|
const gchar *quote = "\\\"";
|
|
|
|
const gchar *newline = "\"\n\t\"";
|
|
|
|
gchar buf[4];
|
|
|
|
guchar *d = NULL;
|
2011-01-26 15:05:34 +08:00
|
|
|
guchar *data = NULL;
|
2008-09-17 16:37:24 +08:00
|
|
|
guchar *cmap;
|
2018-11-27 19:27:20 +08:00
|
|
|
GCancellable *cancellable;
|
2008-09-17 16:37:24 +08:00
|
|
|
gint colors;
|
2012-11-19 07:34:36 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2014-10-04 05:40:13 +08:00
|
|
|
output = G_OUTPUT_STREAM (g_file_replace (file,
|
|
|
|
NULL, FALSE, G_FILE_CREATE_NONE,
|
|
|
|
NULL, error));
|
|
|
|
if (output)
|
|
|
|
{
|
|
|
|
GOutputStream *buffered;
|
|
|
|
|
|
|
|
buffered = g_buffered_output_stream_new (output);
|
|
|
|
g_object_unref (output);
|
|
|
|
|
|
|
|
output = buffered;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
buffer = gimp_drawable_get_buffer (drawable);
|
2012-11-19 07:34:36 +08:00
|
|
|
|
|
|
|
width = gegl_buffer_get_width (buffer);
|
|
|
|
height = gegl_buffer_get_height (buffer);
|
|
|
|
|
2019-08-24 19:41:48 +08:00
|
|
|
drawable_type = gimp_drawable_type (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error,
|
|
|
|
"/* GIMP header image file format (%s): %s */\n\n",
|
|
|
|
GIMP_RGB_IMAGE == drawable_type ? "RGB" : "INDEXED",
|
|
|
|
gimp_file_get_utf8_name (file)) ||
|
|
|
|
! print (output, error,
|
|
|
|
"static unsigned int width = %d;\n", width) ||
|
|
|
|
! print (output, error,
|
|
|
|
"static unsigned int height = %d;\n\n", height) ||
|
|
|
|
! print (output, error,
|
|
|
|
"/* Call this macro repeatedly. After each use, the pixel data can be extracted */\n\n"))
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
|
|
|
goto fail;
|
|
|
|
}
|
2008-09-17 16:37:24 +08:00
|
|
|
|
1999-06-29 01:54:19 +08:00
|
|
|
switch (drawable_type)
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RGB_IMAGE:
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error,
|
|
|
|
"#define HEADER_PIXEL(data,pixel) {\\\n"
|
|
|
|
"pixel[0] = (((data[0] - 33) << 2) | ((data[1] - 33) >> 4)); \\\n"
|
|
|
|
"pixel[1] = ((((data[1] - 33) & 0xF) << 4) | ((data[2] - 33) >> 2)); \\\n"
|
|
|
|
"pixel[2] = ((((data[2] - 33) & 0x3) << 6) | ((data[3] - 33))); \\\n"
|
|
|
|
"data += 4; \\\n}\n") ||
|
|
|
|
! print (output, error,
|
|
|
|
"static char *header_data =\n\t\""))
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
|
|
|
goto fail;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-11-19 07:34:36 +08:00
|
|
|
format = babl_format ("R'G'B' u8");
|
|
|
|
|
|
|
|
data = g_new (guchar, width * babl_format_get_bytes_per_pixel (format));
|
|
|
|
|
1999-06-29 01:54:19 +08:00
|
|
|
c = 0;
|
2012-11-19 07:34:36 +08:00
|
|
|
for (y = 0; y < height; y++)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
2012-11-19 07:34:36 +08:00
|
|
|
gegl_buffer_get (buffer, GEGL_RECTANGLE (0, y, width, 1), 1.0,
|
|
|
|
format, data,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
2008-09-17 16:37:24 +08:00
|
|
|
|
2012-11-19 07:34:36 +08:00
|
|
|
for (x = 0; x < width; x++)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
2012-11-19 07:34:36 +08:00
|
|
|
d = data + x * babl_format_get_bytes_per_pixel (format);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
buf[0] = ((d[0] >> 2) & 0x3F) + 33;
|
|
|
|
buf[1] = ((((d[0] & 0x3) << 4) | (d[1] >> 4)) & 0x3F) + 33;
|
|
|
|
buf[2] = ((((d[1] & 0xF) << 2) | (d[2] >> 6)) & 0x3F) + 33;
|
|
|
|
buf[3] = (d[2] & 0x3F) + 33;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
for (b = 0; b < 4; b++)
|
2008-09-17 16:37:24 +08:00
|
|
|
{
|
|
|
|
if (buf[b] == '"')
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error, "%s", quote))
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2008-09-17 16:37:24 +08:00
|
|
|
else if (buf[b] == '\\')
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error, "%s", backslash))
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2008-09-17 16:37:24 +08:00
|
|
|
else
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error, "%c", buf[b]))
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2008-09-17 16:37:24 +08:00
|
|
|
}
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
c++;
|
|
|
|
if (c >= 16)
|
|
|
|
{
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error, "%s", newline))
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
c = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-17 16:37:24 +08:00
|
|
|
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error, "\";\n"))
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
1999-06-29 01:54:19 +08:00
|
|
|
break;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_INDEXED_IMAGE:
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error,
|
|
|
|
"#define HEADER_PIXEL(data,pixel) {\\\n"
|
|
|
|
"pixel[0] = header_data_cmap[(unsigned char)data[0]][0]; \\\n"
|
|
|
|
"pixel[1] = header_data_cmap[(unsigned char)data[0]][1]; \\\n"
|
|
|
|
"pixel[2] = header_data_cmap[(unsigned char)data[0]][2]; \\\n"
|
|
|
|
"data ++; }\n\n"))
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
1999-06-29 01:54:19 +08:00
|
|
|
/* save colormap */
|
2023-05-24 05:37:46 +08:00
|
|
|
cmap = gimp_image_get_colormap (image, NULL, &colors);
|
1999-06-29 01:54:19 +08:00
|
|
|
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error,
|
2019-12-09 14:03:23 +08:00
|
|
|
"static unsigned char header_data_cmap[256][3] = {") ||
|
2014-10-04 08:30:37 +08:00
|
|
|
! print (output, error,
|
|
|
|
"\n\t{%3d,%3d,%3d}",
|
|
|
|
(gint) cmap[0], (gint) cmap[1], (gint) cmap[2]))
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
|
|
|
goto fail;
|
|
|
|
}
|
2008-09-17 16:37:24 +08:00
|
|
|
|
1999-06-29 01:54:19 +08:00
|
|
|
for (c = 1; c < colors; c++)
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error,
|
|
|
|
",\n\t{%3d,%3d,%3d}",
|
|
|
|
(gint) cmap[3 * c],
|
|
|
|
(gint) cmap[3 * c + 1],
|
|
|
|
(gint) cmap[3 * c + 2]))
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
2008-09-17 16:37:24 +08:00
|
|
|
|
1999-06-29 01:54:19 +08:00
|
|
|
/* fill the rest */
|
|
|
|
for ( ; c < 256; c++)
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error, ",\n\t{255,255,255}"))
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2008-09-17 16:37:24 +08:00
|
|
|
|
1999-06-29 01:54:19 +08:00
|
|
|
/* close bracket */
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error, "\n\t};\n"))
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
|
|
|
|
2008-09-17 16:37:24 +08:00
|
|
|
g_free (cmap);
|
1999-06-29 01:54:19 +08:00
|
|
|
|
|
|
|
/* save image */
|
2019-12-09 14:03:23 +08:00
|
|
|
if (! print (output, error, "static unsigned char header_data[] = {\n\t"))
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
1999-06-29 01:54:19 +08:00
|
|
|
|
2012-11-19 07:34:36 +08:00
|
|
|
data = g_new (guchar, width * 1);
|
1999-06-29 01:54:19 +08:00
|
|
|
|
|
|
|
c = 0;
|
2012-11-19 07:34:36 +08:00
|
|
|
for (y = 0; y < height; y++)
|
1999-06-29 01:54:19 +08:00
|
|
|
{
|
2012-11-19 07:34:36 +08:00
|
|
|
gegl_buffer_get (buffer, GEGL_RECTANGLE (0, y, width, 1), 1.0,
|
|
|
|
NULL, data,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
2008-09-17 16:37:24 +08:00
|
|
|
|
2012-11-19 07:34:36 +08:00
|
|
|
for (x = 0; x < width -1; x++)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
2012-11-19 07:34:36 +08:00
|
|
|
d = data + x * 1;
|
1999-06-29 01:54:19 +08:00
|
|
|
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error, "%d,", (gint) d[0]))
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
1999-06-29 01:54:19 +08:00
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
c++;
|
|
|
|
if (c >= 16)
|
|
|
|
{
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error, "\n\t"))
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
c = 0;
|
|
|
|
}
|
|
|
|
}
|
1999-06-29 01:54:19 +08:00
|
|
|
|
2012-11-19 07:34:36 +08:00
|
|
|
if (y != height - 1)
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error, "%d,\n\t", (gint) d[1]))
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
1999-06-29 01:54:19 +08:00
|
|
|
else
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error, "%d\n\t", (gint) d[1]))
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2008-09-17 16:37:24 +08:00
|
|
|
|
1999-06-29 01:54:19 +08:00
|
|
|
c = 0; /* reset line counter */
|
|
|
|
}
|
2014-10-04 05:40:13 +08:00
|
|
|
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error, "};\n"))
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
1999-06-29 01:54:19 +08:00
|
|
|
break;
|
2008-09-17 16:37:24 +08:00
|
|
|
|
1999-07-07 01:26:06 +08:00
|
|
|
default:
|
|
|
|
g_warning ("unhandled drawable type (%d)", drawable_type);
|
2014-10-04 05:40:13 +08:00
|
|
|
goto fail;
|
2008-09-17 16:37:24 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2014-10-04 05:40:13 +08:00
|
|
|
if (! g_output_stream_close (output, NULL, error))
|
|
|
|
goto fail;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (data);
|
2014-10-04 05:40:13 +08:00
|
|
|
g_object_unref (output);
|
2012-11-19 07:34:36 +08:00
|
|
|
g_object_unref (buffer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2014-10-04 05:40:13 +08:00
|
|
|
|
|
|
|
fail:
|
|
|
|
|
2018-11-27 19:27:20 +08:00
|
|
|
cancellable = g_cancellable_new ();
|
|
|
|
g_cancellable_cancel (cancellable);
|
|
|
|
g_output_stream_close (output, cancellable, NULL);
|
|
|
|
|
2014-10-04 05:40:13 +08:00
|
|
|
g_free (data);
|
|
|
|
g_object_unref (output);
|
|
|
|
g_object_unref (buffer);
|
2018-11-27 19:27:20 +08:00
|
|
|
g_object_unref (cancellable);
|
2014-10-04 05:40:13 +08:00
|
|
|
|
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2015-10-18 05:28:45 +08:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
print (GOutputStream *output,
|
|
|
|
GError **error,
|
|
|
|
const gchar *format,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
va_start (args, format);
|
|
|
|
success = g_output_stream_vprintf (output, NULL, NULL,
|
|
|
|
error, format, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|