2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-24 22:05:25 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
2003-11-06 15:27:05 +00:00
|
|
|
* Alias|Wavefront pix/matte image reading and writing code
|
1997-11-24 22:05:25 +00:00
|
|
|
* Copyright (C) 1997 Mike Taylor
|
|
|
|
* (email: mtaylor@aw.sgi.com, WWW: http://reality.sgi.com/mtaylor)
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-24 22:05:25 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-24 22:05:25 +00: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-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-24 22:05:25 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
/* This plug-in was written using the online documentation from
|
1997-11-24 22:05:25 +00:00
|
|
|
* Alias|Wavefront Inc's PowerAnimator product.
|
|
|
|
*
|
|
|
|
* Bug reports or suggestions should be e-mailed to mtaylor@aw.sgi.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Event history:
|
|
|
|
* V 1.0, MT, 02-Jul-97: initial version of plug-in
|
2003-11-06 15:27:05 +00:00
|
|
|
* V 1.1, MT, 04-Dec-97: added .als file extension
|
1997-11-24 22:05:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Features
|
2016-02-16 02:35:43 +01:00
|
|
|
* - loads and exports
|
2003-11-06 15:27:05 +00:00
|
|
|
* - 24-bit (.pix)
|
1997-11-24 22:05:25 +00:00
|
|
|
* - 8-bit (.matte, .alpha, or .mask) images
|
|
|
|
*
|
|
|
|
* NOTE: pix and matte files do not support alpha channels or indexed
|
2013-06-06 23:26:16 +02:00
|
|
|
* color, so neither does this plug-in
|
1997-11-24 22:05:25 +00:00
|
|
|
*/
|
2000-01-25 17:46:56 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-06-13 14:37:00 +00:00
|
|
|
#include <errno.h>
|
1999-05-29 01:28:24 +00:00
|
|
|
#include <string.h>
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2005-03-04 15:12:29 +00:00
|
|
|
#include <glib/gstdio.h>
|
2000-01-25 17:46:56 +00:00
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
2000-01-01 07:35:13 +00:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2000-05-01 17:01:18 +00:00
|
|
|
|
2005-08-15 11:07:27 +00:00
|
|
|
#define LOAD_PROC "file-pix-load"
|
|
|
|
#define SAVE_PROC "file-pix-save"
|
2008-08-11 10:06:13 +00:00
|
|
|
#define PLUG_IN_BINARY "file-pix"
|
2011-04-08 20:31:34 +02:00
|
|
|
#define PLUG_IN_ROLE "gimp-file-pix"
|
2005-08-15 11:07:27 +00:00
|
|
|
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
/* #define PIX_DEBUG */
|
|
|
|
|
|
|
|
#ifdef PIX_DEBUG
|
2007-02-19 10:37:33 +00:00
|
|
|
# define PIX_DEBUG_PRINT(a,b) g_printerr (a,b)
|
1997-11-24 22:05:25 +00:00
|
|
|
#else
|
2003-11-06 15:27:05 +00:00
|
|
|
# define PIX_DEBUG_PRINT(a,b)
|
1997-11-24 22:05:25 +00:00
|
|
|
#endif
|
|
|
|
|
2013-11-17 18:18:18 +01:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
typedef struct _Pix Pix;
|
|
|
|
typedef struct _PixClass PixClass;
|
|
|
|
|
|
|
|
struct _Pix
|
|
|
|
{
|
|
|
|
GimpPlugIn parent_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _PixClass
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2019-08-24 03:02:13 +02:00
|
|
|
GimpPlugInClass parent_class;
|
1997-11-24 22:05:25 +00:00
|
|
|
};
|
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
|
|
|
|
#define PIX_TYPE (pix_get_type ())
|
|
|
|
#define PIX (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PIX_TYPE, Pix))
|
|
|
|
|
|
|
|
GType pix_get_type (void) G_GNUC_CONST;
|
|
|
|
|
2023-08-06 02:56:44 +02:00
|
|
|
static GList * pix_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * pix_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static GimpValueArray * pix_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpMetadataLoadFlags *flags,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data);
|
|
|
|
static GimpValueArray * pix_save (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
|
|
|
gint n_drawables,
|
|
|
|
GimpDrawable **drawables,
|
|
|
|
GFile *file,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data);
|
|
|
|
|
|
|
|
static GimpImage * load_image (GFile *file,
|
|
|
|
GError **error);
|
2023-09-23 17:10:20 +00:00
|
|
|
static GimpImage * load_esm_image (GInputStream *input,
|
|
|
|
GError **error);
|
2023-08-06 02:56:44 +02:00
|
|
|
static gboolean save_image (GFile *file,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GError **error);
|
2019-08-24 03:02:13 +02:00
|
|
|
|
2023-08-06 02:56:44 +02:00
|
|
|
static gboolean get_short (GInputStream *input,
|
|
|
|
guint16 *value,
|
|
|
|
GError **error);
|
|
|
|
static gboolean put_short (GOutputStream *output,
|
|
|
|
guint16 value,
|
|
|
|
GError **error);
|
2019-08-24 03:02:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (Pix, pix, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (PIX_TYPE)
|
2022-05-26 00:59:36 +02:00
|
|
|
DEFINE_STD_SET_I18N
|
2019-08-24 03:02:13 +02:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2000-01-25 17:46:56 +00:00
|
|
|
static void
|
2019-08-24 03:02:13 +02:00
|
|
|
pix_class_init (PixClass *klass)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2019-08-24 03:02:13 +02:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
plug_in_class->query_procedures = pix_query_procedures;
|
|
|
|
plug_in_class->create_procedure = pix_create_procedure;
|
2022-05-26 00:59:36 +02:00
|
|
|
plug_in_class->set_i18n = STD_SET_I18N;
|
2019-08-24 03:02:13 +02:00
|
|
|
}
|
2002-06-24 20:49:10 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
static void
|
2019-08-24 03:02:13 +02:00
|
|
|
pix_init (Pix *pix)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2019-08-24 03:02:13 +02:00
|
|
|
}
|
1999-10-20 01:45:41 +00:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
static GList *
|
|
|
|
pix_query_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
GList *list = NULL;
|
2012-11-19 22:45:20 +01:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
list = g_list_append (list, g_strdup (LOAD_PROC));
|
|
|
|
list = g_list_append (list, g_strdup (SAVE_PROC));
|
2003-03-25 16:38:19 +00:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
return list;
|
|
|
|
}
|
2012-11-19 22:45:20 +01:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
static GimpProcedure *
|
|
|
|
pix_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
if (! strcmp (name, LOAD_PROC))
|
1999-10-20 01:45:41 +00:00
|
|
|
{
|
2023-08-06 03:21:27 +02:00
|
|
|
procedure = gimp_load_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
pix_load, NULL, NULL);
|
2019-08-24 03:02:13 +02:00
|
|
|
|
|
|
|
gimp_file_procedure_set_handles_remote (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
TRUE);
|
|
|
|
|
2022-07-04 22:50:53 +02:00
|
|
|
gimp_procedure_set_menu_label (procedure, _("Alias Pix image"));
|
2019-08-24 03:02:13 +02:00
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
"Loads files of the Alias|Wavefront "
|
2023-09-23 17:10:20 +00:00
|
|
|
"or Esm Software Pix file format",
|
2019-08-24 03:02:13 +02:00
|
|
|
"Loads files of the Alias|Wavefront "
|
2023-09-23 17:10:20 +00:00
|
|
|
"or Esm Software Pix file format",
|
2019-08-24 03:02:13 +02:00
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Michael Taylor",
|
|
|
|
"Michael Taylor",
|
|
|
|
"1997");
|
|
|
|
|
|
|
|
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"pix,matte,mask,alpha,als");
|
2023-09-23 17:10:20 +00:00
|
|
|
/* Magic Number for Esm Software PIX files */
|
|
|
|
gimp_file_procedure_set_magics (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"0,string,Esm Software PIX file");
|
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
}
|
2019-08-24 03:02:13 +02:00
|
|
|
else if (! strcmp (name, SAVE_PROC))
|
1999-10-20 01:45:41 +00:00
|
|
|
{
|
2023-07-22 23:49:47 +02:00
|
|
|
procedure = gimp_save_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
FALSE, pix_save, NULL, NULL);
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
gimp_procedure_set_image_types (procedure, "*");
|
2013-11-10 00:18:48 +01:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
gimp_file_procedure_set_handles_remote (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
TRUE);
|
2013-11-10 00:18:48 +01:00
|
|
|
|
2022-07-04 22:50:53 +02:00
|
|
|
gimp_procedure_set_menu_label (procedure, _("Alias Pix image"));
|
1999-10-20 01:45:41 +00:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
"Export file in the Alias|Wavefront "
|
|
|
|
"pix/matte file format",
|
|
|
|
"Export file in the Alias|Wavefront "
|
|
|
|
"pix/matte file format",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Michael Taylor",
|
|
|
|
"Michael Taylor",
|
|
|
|
"1997");
|
1999-10-20 01:45:41 +00:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"pix,matte,mask,alpha,als");
|
2000-01-25 17:46:56 +00:00
|
|
|
}
|
2019-08-24 03:02:13 +02:00
|
|
|
|
|
|
|
return procedure;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpValueArray *
|
2023-08-06 02:56:44 +02:00
|
|
|
pix_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpMetadataLoadFlags *flags,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data)
|
2019-08-24 03:02:13 +02:00
|
|
|
{
|
|
|
|
GimpValueArray *return_vals;
|
|
|
|
GimpImage *image;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
gegl_init (NULL, NULL);
|
|
|
|
|
|
|
|
image = load_image (file, &error);
|
|
|
|
|
|
|
|
if (! image)
|
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_EXECUTION_ERROR,
|
|
|
|
error);
|
|
|
|
|
|
|
|
return_vals = gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_SUCCESS,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
|
|
|
|
|
|
|
|
return return_vals;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpValueArray *
|
|
|
|
pix_save (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
2020-04-14 11:46:17 +02:00
|
|
|
gint n_drawables,
|
|
|
|
GimpDrawable **drawables,
|
2019-08-24 03:02:13 +02:00
|
|
|
GFile *file,
|
2023-07-21 18:08:00 +02:00
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpProcedureConfig *config,
|
2019-08-24 03:02:13 +02:00
|
|
|
gpointer run_data)
|
|
|
|
{
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
gegl_init (NULL, NULL);
|
|
|
|
|
|
|
|
switch (run_mode)
|
1999-10-20 01:45:41 +00:00
|
|
|
{
|
2019-08-24 03:02:13 +02:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2019-09-20 19:39:00 +02:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY);
|
2019-08-24 03:02:13 +02:00
|
|
|
|
2020-04-14 11:46:17 +02:00
|
|
|
export = gimp_export_image (&image, &n_drawables, &drawables, "PIX",
|
2019-08-24 03:02:13 +02:00
|
|
|
GIMP_EXPORT_CAN_HANDLE_RGB |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_GRAY |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_INDEXED);
|
|
|
|
|
|
|
|
if (export == GIMP_EXPORT_CANCEL)
|
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_CANCEL,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
1999-10-20 01:45:41 +00:00
|
|
|
}
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2020-04-14 11:46:17 +02:00
|
|
|
if (n_drawables != 1)
|
|
|
|
{
|
|
|
|
g_set_error (&error, G_FILE_ERROR, 0,
|
|
|
|
_("PIX format does not support multiple layers."));
|
|
|
|
|
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_CALLING_ERROR,
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! save_image (file, image, drawables[0], &error))
|
2008-08-18 19:35:55 +00:00
|
|
|
{
|
2019-08-24 03:02:13 +02:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
2008-08-18 19:35:55 +00:00
|
|
|
}
|
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
if (export == GIMP_EXPORT_EXPORT)
|
2020-04-14 11:46:17 +02:00
|
|
|
{
|
|
|
|
gimp_image_delete (image);
|
|
|
|
g_free (drawables);
|
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
return gimp_procedure_new_return_values (procedure, status, error);
|
|
|
|
}
|
2003-11-06 15:27:05 +00:00
|
|
|
|
|
|
|
/*
|
2002-06-24 20:49:10 +00:00
|
|
|
* Description:
|
|
|
|
* Reads a 16-bit integer from a file in such a way that the machine's
|
2002-06-25 08:46:35 +00:00
|
|
|
* byte order should not matter.
|
2002-06-24 20:49:10 +00:00
|
|
|
*/
|
|
|
|
|
2013-11-17 18:18:18 +01:00
|
|
|
static gboolean
|
|
|
|
get_short (GInputStream *input,
|
|
|
|
guint16 *value,
|
|
|
|
GError **error)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
1999-10-20 01:45:41 +00:00
|
|
|
guchar buf[2];
|
2013-11-17 18:18:18 +01:00
|
|
|
gsize bytes_read;
|
|
|
|
|
|
|
|
if (! g_input_stream_read_all (input, buf, 2,
|
|
|
|
&bytes_read, NULL, error) ||
|
|
|
|
bytes_read != 2)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2013-11-17 18:18:18 +01:00
|
|
|
if (value)
|
|
|
|
*value = (buf[0] << 8) + buf[1];
|
2002-06-25 08:46:35 +00:00
|
|
|
|
2013-11-17 18:18:18 +01:00
|
|
|
return TRUE;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2003-11-06 15:27:05 +00:00
|
|
|
|
|
|
|
/*
|
2002-06-24 20:49:10 +00:00
|
|
|
* Description:
|
2002-06-25 08:46:35 +00:00
|
|
|
* Writes a 16-bit integer to a file in such a way that the machine's
|
|
|
|
* byte order should not matter.
|
2002-06-24 20:49:10 +00:00
|
|
|
*/
|
|
|
|
|
2013-11-17 18:18:18 +01:00
|
|
|
static gboolean
|
|
|
|
put_short (GOutputStream *output,
|
|
|
|
guint16 value,
|
|
|
|
GError **error)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
1999-10-20 01:45:41 +00:00
|
|
|
guchar buf[2];
|
2013-11-17 18:18:18 +01:00
|
|
|
|
2002-06-25 08:46:35 +00:00
|
|
|
buf[0] = (value >> 8) & 0xFF;
|
|
|
|
buf[1] = value & 0xFF;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2014-09-07 20:30:14 +02:00
|
|
|
return g_output_stream_write_all (output, buf, 2, NULL, NULL, error);
|
2000-01-25 17:46:56 +00:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2002-06-24 20:49:10 +00:00
|
|
|
/*
|
|
|
|
* Description:
|
|
|
|
* load the given image into gimp
|
2003-11-06 15:27:05 +00:00
|
|
|
*
|
2002-06-24 20:49:10 +00:00
|
|
|
* Arguments:
|
|
|
|
* filename - name on the file to read
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Image id for the loaded image
|
2003-11-06 15:27:05 +00:00
|
|
|
*
|
2002-06-24 20:49:10 +00:00
|
|
|
*/
|
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
static GimpImage *
|
2013-11-17 18:18:18 +01:00
|
|
|
load_image (GFile *file,
|
|
|
|
GError **error)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2013-11-17 18:18:18 +01:00
|
|
|
GInputStream *input;
|
2012-11-19 22:45:20 +01:00
|
|
|
GeglBuffer *buffer;
|
2000-08-22 01:26:57 +00:00
|
|
|
GimpImageBaseType imgtype;
|
2012-11-19 22:45:20 +01:00
|
|
|
GimpImageType gdtype;
|
|
|
|
guchar *dest;
|
|
|
|
guchar *dest_base;
|
2023-09-23 17:10:20 +00:00
|
|
|
GimpImage *image = NULL;
|
2019-08-24 03:02:13 +02:00
|
|
|
GimpLayer *layer;
|
2012-11-19 22:45:20 +01:00
|
|
|
gushort width, height, depth;
|
|
|
|
gint i, j, tile_height, row;
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2019-09-11 21:48:34 +02:00
|
|
|
PIX_DEBUG_PRINT ("Opening file: %s\n", gimp_file_get_utf8_name (file));
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2014-07-23 16:39:00 +02:00
|
|
|
gimp_progress_init_printf (_("Opening '%s'"),
|
|
|
|
g_file_get_parse_name (file));
|
|
|
|
|
2013-11-17 18:18:18 +01:00
|
|
|
input = G_INPUT_STREAM (g_file_read (file, NULL, error));
|
|
|
|
if (! input)
|
2019-08-24 03:02:13 +02:00
|
|
|
return NULL;
|
2003-11-06 15:27:05 +00:00
|
|
|
|
1999-10-20 01:45:41 +00:00
|
|
|
/* Read header information */
|
2013-11-17 18:18:18 +01:00
|
|
|
if (! get_short (input, &width, error) ||
|
|
|
|
! get_short (input, &height, error) ||
|
|
|
|
! get_short (input, NULL, error) || /* Discard obsolete field */
|
|
|
|
! get_short (input, NULL, error) || /* Discard obsolete field */
|
|
|
|
! get_short (input, &depth, error))
|
|
|
|
{
|
|
|
|
g_object_unref (input);
|
2019-08-24 03:02:13 +02:00
|
|
|
return NULL;
|
2013-11-17 18:18:18 +01:00
|
|
|
}
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2013-11-17 18:18:18 +01:00
|
|
|
PIX_DEBUG_PRINT ("Width %hu\n", width);
|
2000-01-25 17:46:56 +00:00
|
|
|
PIX_DEBUG_PRINT ("Height %hu\n", height);
|
|
|
|
|
|
|
|
if (depth == 8)
|
1999-10-20 01:45:41 +00:00
|
|
|
{
|
|
|
|
/* Loading a matte file */
|
2000-08-22 01:26:57 +00:00
|
|
|
imgtype = GIMP_GRAY;
|
2012-11-19 22:45:20 +01:00
|
|
|
gdtype = GIMP_GRAY_IMAGE;
|
2000-01-25 17:46:56 +00:00
|
|
|
}
|
|
|
|
else if (depth == 24)
|
1999-10-20 01:45:41 +00:00
|
|
|
{
|
|
|
|
/* Loading an RGB file */
|
2000-08-22 01:26:57 +00:00
|
|
|
imgtype = GIMP_RGB;
|
2012-11-19 22:45:20 +01:00
|
|
|
gdtype = GIMP_RGB_IMAGE;
|
2000-01-25 17:46:56 +00:00
|
|
|
}
|
|
|
|
else
|
1999-10-20 01:45:41 +00:00
|
|
|
{
|
2023-09-23 17:10:20 +00:00
|
|
|
/* Check if this is Esm Software PIX file format */
|
|
|
|
gchar esm_header[22];
|
|
|
|
gsize bytes_read;
|
|
|
|
|
|
|
|
g_seekable_seek (G_SEEKABLE (input), 0, G_SEEK_SET, NULL, NULL);
|
|
|
|
if (g_input_stream_read_all (input, &esm_header, sizeof (esm_header),
|
|
|
|
&bytes_read, NULL, NULL))
|
|
|
|
{
|
|
|
|
esm_header[21] = '\0';
|
|
|
|
|
|
|
|
if (g_str_has_prefix (esm_header, "Esm Software PIX file"))
|
|
|
|
image = load_esm_image (input, error);
|
|
|
|
|
|
|
|
if (image)
|
|
|
|
{
|
|
|
|
g_object_unref (input);
|
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-20 01:45:41 +00:00
|
|
|
/* Header is invalid */
|
2013-11-17 18:18:18 +01:00
|
|
|
g_object_unref (input);
|
2019-08-24 03:02:13 +02:00
|
|
|
return NULL;
|
1999-10-20 01:45:41 +00:00
|
|
|
}
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
image = gimp_image_new (width, height, imgtype);
|
|
|
|
layer = gimp_layer_new (image, _("Background"),
|
|
|
|
width, height,
|
|
|
|
gdtype,
|
|
|
|
100,
|
|
|
|
gimp_image_get_default_new_layer_mode (image));
|
|
|
|
gimp_image_insert_layer (image, layer, NULL, 0);
|
2012-11-19 22:45:20 +01:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
tile_height = gimp_tile_height ();
|
2000-01-25 17:46:56 +00:00
|
|
|
|
|
|
|
if (depth == 24)
|
1999-10-20 01:45:41 +00:00
|
|
|
{
|
|
|
|
/* Read a 24-bit Pix image */
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
dest_base = dest = g_new (guchar, 3 * width * tile_height);
|
2000-01-25 17:46:56 +00:00
|
|
|
|
|
|
|
for (i = 0; i < height;)
|
2008-10-20 06:04:39 +00:00
|
|
|
{
|
|
|
|
for (dest = dest_base, row = 0;
|
|
|
|
row < tile_height && i < height;
|
|
|
|
i++, row++)
|
|
|
|
{
|
2013-11-17 18:18:18 +01:00
|
|
|
guchar record[4];
|
|
|
|
gsize bytes_read;
|
2008-10-20 06:04:39 +00:00
|
|
|
guchar count;
|
|
|
|
|
|
|
|
/* Read a row of the image */
|
|
|
|
j = 0;
|
|
|
|
while (j < width)
|
|
|
|
{
|
2013-11-17 18:18:18 +01:00
|
|
|
if (! g_input_stream_read_all (input, record, 4,
|
|
|
|
&bytes_read, NULL, error) ||
|
|
|
|
bytes_read != 4)
|
2008-10-20 06:04:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
for (count = 0; count < record[0]; ++count)
|
|
|
|
{
|
|
|
|
dest[0] = record[3];
|
|
|
|
dest[1] = record[2];
|
|
|
|
dest[2] = record[1];
|
|
|
|
dest += 3;
|
|
|
|
j++;
|
|
|
|
if (j >= width)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-19 22:45:20 +01:00
|
|
|
|
|
|
|
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, i - row, width, row), 0,
|
|
|
|
NULL, dest_base, GEGL_AUTO_ROWSTRIDE);
|
|
|
|
|
2008-10-20 06:04:39 +00:00
|
|
|
gimp_progress_update ((double) i / (double) height);
|
|
|
|
}
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2002-06-24 20:49:10 +00:00
|
|
|
g_free (dest_base);
|
2000-01-25 17:46:56 +00:00
|
|
|
}
|
|
|
|
else
|
1999-10-20 01:45:41 +00:00
|
|
|
{
|
|
|
|
/* Read an 8-bit Matte image */
|
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
dest_base = dest = g_new (guchar, width * tile_height);
|
|
|
|
|
|
|
|
for (i = 0; i < height;)
|
2008-10-20 06:04:39 +00:00
|
|
|
{
|
|
|
|
for (dest = dest_base, row = 0;
|
|
|
|
row < tile_height && i < height;
|
|
|
|
i++, row++)
|
|
|
|
{
|
2013-11-17 18:18:18 +01:00
|
|
|
guchar record[2];
|
|
|
|
gsize bytes_read;
|
2008-10-20 06:04:39 +00:00
|
|
|
guchar count;
|
|
|
|
|
|
|
|
/* Read a row of the image */
|
|
|
|
j = 0;
|
|
|
|
while (j < width)
|
|
|
|
{
|
2013-11-17 18:18:18 +01:00
|
|
|
if (! g_input_stream_read_all (input, record, 2,
|
|
|
|
&bytes_read, NULL, error) ||
|
|
|
|
bytes_read != 2)
|
2008-10-20 06:04:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
for (count = 0; count < record[0]; ++count)
|
|
|
|
{
|
|
|
|
dest[j] = record[1];
|
|
|
|
j++;
|
|
|
|
if (j >= width)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-19 22:45:20 +01:00
|
|
|
|
2008-10-20 06:04:39 +00:00
|
|
|
dest += width;
|
|
|
|
}
|
2012-11-19 22:45:20 +01:00
|
|
|
|
|
|
|
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, i - row, width, row), 0,
|
|
|
|
NULL, dest_base, GEGL_AUTO_ROWSTRIDE);
|
|
|
|
|
2008-10-20 06:04:39 +00:00
|
|
|
gimp_progress_update ((double) i / (double) height);
|
|
|
|
}
|
2012-11-19 22:45:20 +01:00
|
|
|
|
2000-01-25 17:46:56 +00:00
|
|
|
g_free (dest_base);
|
1999-10-20 01:45:41 +00:00
|
|
|
}
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2012-11-19 22:45:20 +01:00
|
|
|
g_object_unref (buffer);
|
2013-11-17 18:18:18 +01:00
|
|
|
g_object_unref (input);
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2012-11-19 22:45:20 +01:00
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
return image;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2023-09-23 17:10:20 +00:00
|
|
|
static GimpImage *
|
|
|
|
load_esm_image (GInputStream *input,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GimpImage *image = NULL;
|
|
|
|
GimpValueArray *return_vals = NULL;
|
|
|
|
GFile *temp_file = NULL;
|
|
|
|
FILE *fp;
|
|
|
|
goffset file_size;
|
|
|
|
|
|
|
|
g_seekable_seek (G_SEEKABLE (input), 0, G_SEEK_END, NULL, error);
|
|
|
|
file_size = g_seekable_tell (G_SEEKABLE (input));
|
|
|
|
g_seekable_seek (G_SEEKABLE (input), 21, G_SEEK_SET, NULL, error);
|
|
|
|
|
|
|
|
/* Esm Software PIX format is just a JPEG with an extra 21 byte header */
|
|
|
|
temp_file = gimp_temp_file ("jpeg");
|
|
|
|
fp = g_fopen (g_file_peek_path (temp_file), "wb");
|
|
|
|
|
|
|
|
if (! fp)
|
|
|
|
{
|
|
|
|
g_file_delete (temp_file, NULL, NULL);
|
|
|
|
g_object_unref (temp_file);
|
|
|
|
|
|
|
|
g_message (_("Error trying to open temporary JPEG file '%s' "
|
|
|
|
"for Esm Software pix loading: %s"),
|
|
|
|
gimp_file_get_utf8_name (temp_file),
|
|
|
|
g_strerror (errno));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
guchar buffer[file_size - 21];
|
|
|
|
|
|
|
|
if (! g_input_stream_read_all (input, buffer, sizeof (buffer),
|
|
|
|
NULL, NULL, error))
|
|
|
|
{
|
|
|
|
g_file_delete (temp_file, NULL, NULL);
|
|
|
|
g_object_unref (temp_file);
|
|
|
|
|
|
|
|
g_printerr (_("Invalid Esm Software PIX file"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fwrite (buffer, sizeof (guchar), file_size, fp);
|
|
|
|
fclose (fp);
|
|
|
|
|
|
|
|
return_vals =
|
|
|
|
gimp_pdb_run_procedure (gimp_get_pdb (),
|
|
|
|
"file-jpeg-load",
|
2023-10-17 15:49:32 +02:00
|
|
|
"run-mode", GIMP_RUN_NONINTERACTIVE,
|
|
|
|
"file", temp_file,
|
libgimp: PDB procedure arguments are not order-based anymore (API-wise).
As far as plug-in API is concerned, at least the calling API, order of arguments
when calling PDB procedures doesn't matter anymore.
Order still matters for creating procedures with standard arguments (for
instance, "run-mode" is first, then image, or file, drawables or whatnot,
depending on the subtype of procedure), but not for calling with libgimp.
Concretely in this commit:
- gimp_pdb_run_procedure_argv() was removed as it's intrinsically order-based.
- gimp_pdb_run_procedure() and gimp_pdb_run_procedure_valist() stay but their
semantic changes. Instead of an ordered list of (type, value) couple, it's now
an unordered list of (name, type, value) triplets. This way, you can also
ignore as many args as you want if you intend to keep them default. For
instance, say you have a procedure with 20 args and you only want to change
the last one and keep the 19 first with default values: while you used to have
to write down all 20 args annoyingly, now you can just list the only arg you
care about.
There are 2 important consequences here:
1. Calling PDB procedures becomes much more semantic, which means scripts with
PDB calls are simpler (smaller list of arguments) and easier to read (when
you had 5 int arguments in a row, you couldn't know what they refer to,
except by always checking the PDB source; now you'll have associated names,
such as "width", "height" and so on) hence maintain.
2. We will have the ability to add arguments and even order the new arguments in
middle of existing arguments without breaking compatibility. The only thing
which will matter will be that default values of new arguments will have to
behave like when the arg didn't exist. This way, existing scripts will not be
broken. This will avoid us having to always create variants of PDB procedure
(like original "file-bla-save", then variant "file-bla-save-2" and so on)
each time we add arguments.
Note: gimp_pdb_run_procedure_array() was not removed yet because it's currently
used by the PDB. To be followed.
2023-10-16 16:44:06 +02:00
|
|
|
NULL);
|
2023-09-23 17:10:20 +00:00
|
|
|
|
|
|
|
if (return_vals)
|
|
|
|
{
|
|
|
|
image = g_value_get_object (gimp_value_array_index (return_vals, 1));
|
|
|
|
|
|
|
|
gimp_value_array_unref (return_vals);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_file_delete (temp_file, NULL, NULL);
|
|
|
|
g_object_unref (temp_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
/*
|
1997-11-24 22:05:25 +00:00
|
|
|
* Description:
|
|
|
|
* save the given file out as an alias pix or matte file
|
2003-11-06 15:27:05 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
1997-11-24 22:05:25 +00:00
|
|
|
* filename - name of file to save to
|
2019-08-24 03:02:13 +02:00
|
|
|
* image - image to save
|
|
|
|
* drawable - current drawable
|
1997-11-24 22:05:25 +00:00
|
|
|
*/
|
2002-06-24 20:49:10 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
static gboolean
|
2019-08-24 03:02:13 +02:00
|
|
|
save_image (GFile *file,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GError **error)
|
2002-06-24 20:49:10 +00:00
|
|
|
{
|
2013-11-17 18:18:18 +01:00
|
|
|
GOutputStream *output;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
const Babl *format;
|
2018-11-27 12:27:20 +01:00
|
|
|
GCancellable *cancellable;
|
2013-11-17 18:18:18 +01:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint depth, i, j, row, tile_height, rectHeight;
|
|
|
|
gboolean savingColor = TRUE;
|
|
|
|
guchar *src;
|
|
|
|
guchar *src_base;
|
|
|
|
|
2016-02-16 02:35:43 +01:00
|
|
|
gimp_progress_init_printf (_("Exporting '%s'"),
|
2014-07-23 16:39:00 +02:00
|
|
|
g_file_get_parse_name (file));
|
|
|
|
|
2014-10-04 02:44:54 +02:00
|
|
|
output = G_OUTPUT_STREAM (g_file_replace (file,
|
|
|
|
NULL, FALSE, G_FILE_CREATE_NONE,
|
|
|
|
NULL, error));
|
2013-11-17 18:18:18 +01:00
|
|
|
if (! output)
|
|
|
|
return FALSE;
|
|
|
|
|
1999-10-20 01:45:41 +00:00
|
|
|
/* Get info about image */
|
2019-08-24 03:02:13 +02:00
|
|
|
buffer = gimp_drawable_get_buffer (drawable);
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2012-11-19 22:45:20 +01:00
|
|
|
width = gegl_buffer_get_width (buffer);
|
|
|
|
height = gegl_buffer_get_height (buffer);
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2019-08-24 03:02:13 +02:00
|
|
|
savingColor = ! gimp_drawable_is_gray (drawable);
|
2012-11-19 22:45:20 +01:00
|
|
|
|
|
|
|
if (savingColor)
|
|
|
|
format = babl_format ("R'G'B' u8");
|
|
|
|
else
|
|
|
|
format = babl_format ("Y' u8");
|
|
|
|
|
2014-04-11 15:08:49 +02:00
|
|
|
depth = babl_format_get_bytes_per_pixel (format);
|
2000-01-25 17:46:56 +00:00
|
|
|
|
1999-10-20 01:45:41 +00:00
|
|
|
/* Write the image header */
|
2012-11-19 22:45:20 +01:00
|
|
|
PIX_DEBUG_PRINT ("Width %hu\n", width);
|
|
|
|
PIX_DEBUG_PRINT ("Height %hu\n", height);
|
2013-11-17 18:18:18 +01:00
|
|
|
|
|
|
|
if (! put_short (output, width, error) ||
|
|
|
|
! put_short (output, height, error) ||
|
|
|
|
! put_short (output, 0, error) ||
|
|
|
|
! put_short (output, 0, error))
|
|
|
|
{
|
2018-11-27 12:27:20 +01:00
|
|
|
cancellable = g_cancellable_new ();
|
|
|
|
g_cancellable_cancel (cancellable);
|
|
|
|
g_output_stream_close (output, cancellable, NULL);
|
|
|
|
g_object_unref (cancellable);
|
|
|
|
|
2013-11-17 18:18:18 +01:00
|
|
|
g_object_unref (output);
|
|
|
|
g_object_unref (buffer);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-01-25 17:46:56 +00:00
|
|
|
|
|
|
|
tile_height = gimp_tile_height ();
|
2012-11-19 22:45:20 +01:00
|
|
|
src_base = g_new (guchar, tile_height * width * depth);
|
2000-01-25 17:46:56 +00:00
|
|
|
|
|
|
|
if (savingColor)
|
1999-10-20 01:45:41 +00:00
|
|
|
{
|
|
|
|
/* Writing a 24-bit Pix image */
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2013-11-17 18:18:18 +01:00
|
|
|
if (! put_short (output, 24, error))
|
|
|
|
goto fail;
|
2002-06-24 20:49:10 +00:00
|
|
|
|
2012-11-19 22:45:20 +01:00
|
|
|
for (i = 0; i < height;)
|
2008-10-20 06:04:39 +00:00
|
|
|
{
|
2014-04-11 15:25:22 +02:00
|
|
|
rectHeight = (tile_height < (height - i)) ?
|
|
|
|
tile_height : (height - i);
|
2012-11-19 22:45:20 +01:00
|
|
|
|
|
|
|
gegl_buffer_get (buffer, GEGL_RECTANGLE (0, i, width, rectHeight), 1.0,
|
|
|
|
format, src_base,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
2008-10-20 06:04:39 +00:00
|
|
|
|
|
|
|
for (src = src_base, row = 0;
|
2012-11-19 22:45:20 +01:00
|
|
|
row < tile_height && i < height;
|
2008-10-20 06:04:39 +00:00
|
|
|
i += 1, row += 1)
|
|
|
|
{
|
|
|
|
/* Write a row of the image */
|
2013-11-17 18:18:18 +01:00
|
|
|
|
|
|
|
guchar record[4];
|
|
|
|
|
2008-10-20 06:04:39 +00:00
|
|
|
record[0] = 1;
|
|
|
|
record[3] = src[0];
|
|
|
|
record[2] = src[1];
|
|
|
|
record[1] = src[2];
|
|
|
|
src += depth;
|
2012-11-19 22:45:20 +01:00
|
|
|
for (j = 1; j < width; ++j)
|
2008-10-20 06:04:39 +00:00
|
|
|
{
|
|
|
|
if ((record[3] != src[0]) ||
|
2013-11-17 18:18:18 +01:00
|
|
|
(record[2] != src[1]) ||
|
|
|
|
(record[1] != src[2]) ||
|
|
|
|
(record[0] == 255))
|
2008-10-20 06:04:39 +00:00
|
|
|
{
|
|
|
|
/* Write current RLE record and start a new one */
|
|
|
|
|
2013-11-17 18:18:18 +01:00
|
|
|
if (! g_output_stream_write_all (output, record, 4,
|
2014-09-07 20:30:14 +02:00
|
|
|
NULL, NULL, error))
|
2013-11-17 18:18:18 +01:00
|
|
|
{
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-10-20 06:04:39 +00:00
|
|
|
record[0] = 1;
|
|
|
|
record[3] = src[0];
|
|
|
|
record[2] = src[1];
|
|
|
|
record[1] = src[2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* increment run length in current record */
|
|
|
|
record[0]++;
|
|
|
|
}
|
|
|
|
src += depth;
|
|
|
|
}
|
2012-11-19 22:45:20 +01:00
|
|
|
|
2008-10-20 06:04:39 +00:00
|
|
|
/* Write last record in row */
|
2013-11-17 18:18:18 +01:00
|
|
|
|
|
|
|
if (! g_output_stream_write_all (output, record, 4,
|
2014-09-07 20:30:14 +02:00
|
|
|
NULL, NULL, error))
|
2013-11-17 18:18:18 +01:00
|
|
|
{
|
|
|
|
goto fail;
|
|
|
|
}
|
2008-10-20 06:04:39 +00:00
|
|
|
}
|
2012-11-19 22:45:20 +01:00
|
|
|
|
|
|
|
gimp_progress_update ((double) i / (double) height);
|
2008-10-20 06:04:39 +00:00
|
|
|
}
|
2000-01-25 17:46:56 +00:00
|
|
|
}
|
|
|
|
else
|
1999-10-20 01:45:41 +00:00
|
|
|
{
|
|
|
|
/* Writing a 8-bit Matte (Mask) image */
|
2000-01-25 17:46:56 +00:00
|
|
|
|
2013-11-17 18:18:18 +01:00
|
|
|
if (! put_short (output, 8, error))
|
|
|
|
goto fail;
|
2002-06-24 20:49:10 +00:00
|
|
|
|
2012-11-19 22:45:20 +01:00
|
|
|
for (i = 0; i < height;)
|
2008-10-20 06:04:39 +00:00
|
|
|
{
|
2014-04-11 15:25:22 +02:00
|
|
|
rectHeight = (tile_height < (height - i)) ?
|
|
|
|
tile_height : (height - i);
|
2012-11-19 22:45:20 +01:00
|
|
|
|
|
|
|
gegl_buffer_get (buffer, GEGL_RECTANGLE (0, i, width, rectHeight), 1.0,
|
|
|
|
format, src_base,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
2008-10-20 06:04:39 +00:00
|
|
|
|
|
|
|
for (src = src_base, row = 0;
|
2012-11-19 22:45:20 +01:00
|
|
|
row < tile_height && i < height;
|
2008-10-20 06:04:39 +00:00
|
|
|
i += 1, row += 1)
|
|
|
|
{
|
|
|
|
/* Write a row of the image */
|
2013-11-17 18:18:18 +01:00
|
|
|
|
|
|
|
guchar record[2];
|
|
|
|
|
2008-10-20 06:04:39 +00:00
|
|
|
record[0] = 1;
|
|
|
|
record[1] = src[0];
|
|
|
|
src += depth;
|
2012-11-19 22:45:20 +01:00
|
|
|
for (j = 1; j < width; ++j)
|
2008-10-20 06:04:39 +00:00
|
|
|
{
|
|
|
|
if ((record[1] != src[0]) || (record[0] == 255))
|
|
|
|
{
|
|
|
|
/* Write current RLE record and start a new one */
|
2013-11-17 18:18:18 +01:00
|
|
|
|
|
|
|
if (! g_output_stream_write_all (output, record, 2,
|
2014-09-07 20:30:14 +02:00
|
|
|
NULL, NULL, error))
|
2013-11-17 18:18:18 +01:00
|
|
|
{
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-10-20 06:04:39 +00:00
|
|
|
record[0] = 1;
|
|
|
|
record[1] = src[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* increment run length in current record */
|
|
|
|
record[0] ++;
|
|
|
|
}
|
|
|
|
src += depth;
|
|
|
|
}
|
2012-11-19 22:45:20 +01:00
|
|
|
|
2008-10-20 06:04:39 +00:00
|
|
|
/* Write last record in row */
|
2013-11-17 18:18:18 +01:00
|
|
|
|
|
|
|
if (! g_output_stream_write_all (output, record, 2,
|
2014-09-07 20:30:14 +02:00
|
|
|
NULL, NULL, error))
|
2013-11-17 18:18:18 +01:00
|
|
|
{
|
|
|
|
goto fail;
|
|
|
|
}
|
2008-10-20 06:04:39 +00:00
|
|
|
}
|
2012-11-19 22:45:20 +01:00
|
|
|
|
|
|
|
gimp_progress_update ((double) i / (double) height);
|
2008-10-20 06:04:39 +00:00
|
|
|
}
|
1999-10-20 01:45:41 +00:00
|
|
|
}
|
2000-01-25 17:46:56 +00:00
|
|
|
|
|
|
|
g_free (src_base);
|
2013-11-17 18:18:18 +01:00
|
|
|
g_object_unref (output);
|
2012-11-19 22:45:20 +01:00
|
|
|
g_object_unref (buffer);
|
|
|
|
|
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
2000-01-25 17:46:56 +00:00
|
|
|
return TRUE;
|
2013-11-17 18:18:18 +01:00
|
|
|
|
|
|
|
fail:
|
|
|
|
|
2018-11-27 12:27:20 +01:00
|
|
|
cancellable = g_cancellable_new ();
|
|
|
|
g_cancellable_cancel (cancellable);
|
|
|
|
g_output_stream_close (output, cancellable, NULL);
|
|
|
|
g_object_unref (cancellable);
|
|
|
|
|
2013-11-17 18:18:18 +01:00
|
|
|
g_free (src_base);
|
|
|
|
g_object_unref (output);
|
|
|
|
g_object_unref (buffer);
|
|
|
|
|
|
|
|
return FALSE;
|
1999-10-20 01:45:41 +00:00
|
|
|
}
|