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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://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
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Declare some local functions.
|
|
|
|
*/
|
2014-10-04 05:40:13 +08:00
|
|
|
static void query (void);
|
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
|
|
|
|
2014-10-04 08:30:37 +08:00
|
|
|
static gboolean print (GOutputStream *output,
|
2014-10-04 05:40:13 +08:00
|
|
|
GError **error,
|
|
|
|
const gchar *format,
|
|
|
|
...) G_GNUC_PRINTF (3, 0);
|
|
|
|
static gboolean save_image (GFile *file,
|
|
|
|
gint32 image_ID,
|
|
|
|
gint32 drawable_ID,
|
|
|
|
GError **error);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
const GimpPlugInInfo PLUG_IN_INFO =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-26 01:46:56 +08:00
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
MAIN ()
|
|
|
|
|
|
|
|
static void
|
2000-01-26 01:46:56 +08:00
|
|
|
query (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef save_args[] =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2009-01-20 04:11:36 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
2005-08-14 06:52:41 +08:00
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Drawable to save" },
|
|
|
|
{ GIMP_PDB_STRING, "filename", "The name of the file to save the image in" },
|
|
|
|
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to save the image in" }
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
2005-08-14 06:52:41 +08:00
|
|
|
gimp_install_procedure (SAVE_PROC,
|
2000-01-31 10:32:30 +08:00
|
|
|
"saves files as C unsigned character array",
|
1997-11-25 06:05:25 +08:00
|
|
|
"FIXME: write help",
|
|
|
|
"Spencer Kimball & Peter Mattis",
|
|
|
|
"Spencer Kimball & Peter Mattis",
|
|
|
|
"1997",
|
2004-05-14 08:42:38 +08:00
|
|
|
N_("C source code header"),
|
2008-10-20 14:04:39 +08:00
|
|
|
"INDEXED, RGB",
|
2000-08-22 09:26:57 +08:00
|
|
|
GIMP_PLUGIN,
|
2001-12-06 10:28:58 +08:00
|
|
|
G_N_ELEMENTS (save_args), 0,
|
1997-11-25 06:05:25 +08:00
|
|
|
save_args, NULL);
|
|
|
|
|
2005-08-14 06:52:41 +08:00
|
|
|
gimp_register_file_handler_mime (SAVE_PROC, "text/x-chdr");
|
2014-10-04 05:40:13 +08:00
|
|
|
gimp_register_file_handler_uri (SAVE_PROC);
|
2005-08-14 06:52:41 +08:00
|
|
|
gimp_register_save_handler (SAVE_PROC, "h", "");
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-07-02 20:03:08 +08:00
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2014-10-04 05:40:13 +08:00
|
|
|
static GimpParam values[2];
|
|
|
|
GimpRunMode run_mode;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
GError *error = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
INIT_I18N ();
|
2012-11-19 07:34:36 +08:00
|
|
|
gegl_init (NULL, NULL);
|
|
|
|
|
|
|
|
run_mode = param[0].data.d_int32;
|
2003-03-26 00:38:19 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
*nreturn_vals = 1;
|
2000-01-26 01:46:56 +08:00
|
|
|
*return_vals = values;
|
2000-08-22 09:26:57 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
|
|
|
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-08-14 06:52:41 +08:00
|
|
|
if (strcmp (name, SAVE_PROC) == 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2008-09-17 16:37:24 +08:00
|
|
|
gint32 image_ID;
|
|
|
|
gint32 drawable_ID;
|
|
|
|
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
|
|
|
|
1999-10-10 03:06:14 +08:00
|
|
|
image_ID = param[1].data.d_int32;
|
|
|
|
drawable_ID = param[2].data.d_int32;
|
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
/* eventually export the image */
|
1999-10-10 03:06:14 +08:00
|
|
|
switch (run_mode)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
|
|
|
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
2013-11-10 07:18:48 +08:00
|
|
|
|
|
|
|
export = gimp_export_image (&image_ID, &drawable_ID, "Header",
|
2012-11-19 07:34:36 +08:00
|
|
|
GIMP_EXPORT_CAN_HANDLE_RGB |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_INDEXED);
|
2013-11-10 07:18:48 +08:00
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
if (export == GIMP_EXPORT_CANCEL)
|
|
|
|
{
|
|
|
|
values[0].data.d_status = GIMP_PDB_CANCEL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1999-10-10 03:06:14 +08:00
|
|
|
|
2014-10-04 05:40:13 +08:00
|
|
|
if (! save_image (g_file_new_for_uri (param[3].data.d_string),
|
|
|
|
image_ID, drawable_ID, &error))
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
1999-10-10 03:06:14 +08:00
|
|
|
|
2000-08-24 22:17:34 +08:00
|
|
|
if (export == GIMP_EXPORT_EXPORT)
|
2008-10-20 14:04:39 +08:00
|
|
|
gimp_image_delete (image_ID);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-01-26 01:46:56 +08:00
|
|
|
else
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
2000-01-26 01:46:56 +08:00
|
|
|
}
|
|
|
|
|
2014-10-04 05:40:13 +08:00
|
|
|
if (status != GIMP_PDB_SUCCESS && error)
|
|
|
|
{
|
|
|
|
*nreturn_vals = 2;
|
|
|
|
values[1].type = GIMP_PDB_STRING;
|
|
|
|
values[1].data.d_string = error->message;
|
|
|
|
}
|
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
values[0].data.d_status = status;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2008-09-17 16:37:24 +08:00
|
|
|
static gboolean
|
2014-10-04 08:30:37 +08:00
|
|
|
print (GOutputStream *output,
|
|
|
|
GError **error,
|
|
|
|
const gchar *format,
|
|
|
|
...)
|
2014-10-04 05:40:13 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
save_image (GFile *file,
|
|
|
|
gint32 image_ID,
|
|
|
|
gint32 drawable_ID,
|
|
|
|
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;
|
|
|
|
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
|
|
|
|
2012-11-19 07:34:36 +08:00
|
|
|
buffer = gimp_drawable_get_buffer (drawable_ID);
|
|
|
|
|
|
|
|
width = gegl_buffer_get_width (buffer);
|
|
|
|
height = gegl_buffer_get_height (buffer);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
drawable_type = gimp_drawable_type (drawable_ID);
|
|
|
|
|
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 */
|
2004-11-02 20:00:25 +08:00
|
|
|
cmap = gimp_image_get_colormap (image_ID, &colors);
|
1999-06-29 01:54:19 +08:00
|
|
|
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error,
|
|
|
|
"static char header_data_cmap[256][3] = {") ||
|
|
|
|
! 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 */
|
2014-10-04 08:30:37 +08:00
|
|
|
if (! print (output, error, "static 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:
|
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
g_object_unref (output);
|
|
|
|
g_object_unref (buffer);
|
|
|
|
|
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|