Initial checkin of Pika from heckimp

This commit is contained in:
2023-09-25 15:35:21 -07:00
commit 891e999216
6761 changed files with 5240685 additions and 0 deletions

18
app/xcf/meson.build Normal file
View File

@ -0,0 +1,18 @@
libappxcf_sources = [
'xcf-load.c',
'xcf-read.c',
'xcf-save.c',
'xcf-seek.c',
'xcf-utils.c',
'xcf-write.c',
'xcf.c',
]
libappxcf = static_library('appxcf',
libappxcf_sources,
include_directories: [ rootInclude, rootAppInclude, ],
c_args: '-DG_LOG_DOMAIN="Pika-XCF"',
dependencies: [
cairo, gegl, gdk_pixbuf, zlib
],
)

4020
app/xcf/xcf-load.c Normal file

File diff suppressed because it is too large Load Diff

31
app/xcf/xcf-load.h Normal file
View File

@ -0,0 +1,31 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __XCF_LOAD_H__
#define __XCF_LOAD_H__
PikaImage * xcf_load_image (Pika *pika,
XcfInfo *info,
GError **error);
#endif /* __XCF_LOAD_H__ */

140
app/xcf/xcf-private.h Normal file
View File

@ -0,0 +1,140 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __XCF_PRIVATE_H__
#define __XCF_PRIVATE_H__
#define XCF_TILE_WIDTH 64
#define XCF_TILE_HEIGHT 64
#define XCF_TILE_MAX_DATA_LENGTH_FACTOR 1.5
#define XCF_TILE_SAVE_BATCH_SIZE 128
typedef enum
{
PROP_END = 0,
PROP_COLORMAP = 1,
PROP_ACTIVE_LAYER = 2,
PROP_ACTIVE_CHANNEL = 3,
PROP_SELECTION = 4,
PROP_FLOATING_SELECTION = 5,
PROP_OPACITY = 6,
PROP_MODE = 7,
PROP_VISIBLE = 8,
PROP_LINKED = 9,
PROP_LOCK_ALPHA = 10,
PROP_APPLY_MASK = 11,
PROP_EDIT_MASK = 12,
PROP_SHOW_MASK = 13,
PROP_SHOW_MASKED = 14,
PROP_OFFSETS = 15,
PROP_COLOR = 16,
PROP_COMPRESSION = 17,
PROP_GUIDES = 18,
PROP_RESOLUTION = 19,
PROP_TATTOO = 20,
PROP_PARASITES = 21,
PROP_UNIT = 22,
PROP_PATHS = 23,
PROP_USER_UNIT = 24,
PROP_VECTORS = 25,
PROP_TEXT_LAYER_FLAGS = 26,
PROP_OLD_SAMPLE_POINTS = 27,
PROP_LOCK_CONTENT = 28,
PROP_GROUP_ITEM = 29,
PROP_ITEM_PATH = 30,
PROP_GROUP_ITEM_FLAGS = 31,
PROP_LOCK_POSITION = 32,
PROP_FLOAT_OPACITY = 33,
PROP_COLOR_TAG = 34,
PROP_COMPOSITE_MODE = 35,
PROP_COMPOSITE_SPACE = 36,
PROP_BLEND_SPACE = 37,
PROP_FLOAT_COLOR = 38,
PROP_SAMPLE_POINTS = 39,
PROP_ITEM_SET = 40,
PROP_ITEM_SET_ITEM = 41,
PROP_LOCK_VISIBILITY = 42,
PROP_SELECTED_PATH = 43,
} PropType;
typedef enum
{
COMPRESS_NONE = 0,
COMPRESS_RLE = 1,
COMPRESS_ZLIB = 2, /* unused */
COMPRESS_FRACTAL = 3 /* unused */
} XcfCompressionType;
typedef enum
{
XCF_ORIENTATION_HORIZONTAL = 1,
XCF_ORIENTATION_VERTICAL = 2
} XcfOrientationType;
typedef enum
{
XCF_STROKETYPE_STROKE = 0,
XCF_STROKETYPE_BEZIER_STROKE = 1
} XcfStrokeType;
typedef enum
{
XCF_GROUP_ITEM_EXPANDED = 1
} XcfGroupItemFlagsType;
typedef struct _XcfInfo XcfInfo;
struct _XcfInfo
{
Pika *pika;
PikaProgress *progress;
GInputStream *input;
GOutputStream *output;
GSeekable *seekable;
goffset cp;
gint bytes_per_offset;
GFile *file;
PikaTattoo tattoo_state;
GList *selected_layers;
GList *selected_channels;
GList *selected_vectors;
/* Old deprecated "linked" concept which we keep in the XcfInfo
* probably forever to transform these tags into named stored item
* sets instead.
*/
GList *linked_layers;
GList *linked_channels;
GList *linked_paths;
GList *layer_sets;
GList *channel_sets;
PikaDrawable *floating_sel_drawable;
PikaLayer *floating_sel;
goffset floating_sel_offset;
XcfCompressionType compression;
gint file_version;
};
#endif /* __XCF_PRIVATE_H__ */

278
app/xcf/xcf-read.c Normal file
View File

@ -0,0 +1,278 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gio/gio.h>
#include "libpikabase/pikabase.h"
#include "core/core-types.h"
#include "xcf-private.h"
#include "xcf-read.h"
#include "pika-intl.h"
#define MAX_XCF_STRING_LEN (16L * 1024 * 1024)
guint
xcf_read_int8 (XcfInfo *info,
guint8 *data,
gint count)
{
gsize bytes_read = 0;
/* we allow for 'data == NULL && count == 0', which g_input_stream_read_all()
* rejects.
*/
if (count > 0)
{
g_input_stream_read_all (info->input, data, count,
&bytes_read, NULL, NULL);
info->cp += bytes_read;
}
return bytes_read;
}
guint
xcf_read_int16 (XcfInfo *info,
guint16 *data,
gint count)
{
guint total = 0;
if (count > 0)
{
total += xcf_read_int8 (info, (guint8 *) data, count * 2);
while (count--)
{
*data = g_ntohs (*data);
data++;
}
}
return total;
}
guint
xcf_read_int32 (XcfInfo *info,
guint32 *data,
gint count)
{
guint total = 0;
if (count > 0)
{
total += xcf_read_int8 (info, (guint8 *) data, count * 4);
while (count--)
{
*data = g_ntohl (*data);
data++;
}
}
return total;
}
guint
xcf_read_int64 (XcfInfo *info,
guint64 *data,
gint count)
{
guint total = 0;
if (count > 0)
{
total += xcf_read_int8 (info, (guint8 *) data, count * 8);
while (count--)
{
*data = GINT64_FROM_BE (*data);
data++;
}
}
return total;
}
guint
xcf_read_offset (XcfInfo *info,
goffset *data,
gint count)
{
guint total = 0;
if (count > 0)
{
if (info->bytes_per_offset == 4)
{
gint32 *int_offsets = g_alloca (count * sizeof (gint32));
total += xcf_read_int8 (info, (guint8 *) int_offsets, count * 4);
while (count--)
{
*data = g_ntohl (*int_offsets);
int_offsets++;
data++;
}
}
else
{
total += xcf_read_int8 (info, (guint8 *) data, count * 8);
while (count--)
{
*data = GINT64_FROM_BE (*data);
data++;
}
}
}
return total;
}
guint
xcf_read_float (XcfInfo *info,
gfloat *data,
gint count)
{
return xcf_read_int32 (info, (guint32 *) ((void *) data), count);
}
guint
xcf_read_string (XcfInfo *info,
gchar **data,
gint count)
{
guint total = 0;
gint i;
for (i = 0; i < count; i++)
{
guint32 tmp;
total += xcf_read_int32 (info, &tmp, 1);
if (tmp > MAX_XCF_STRING_LEN)
{
g_warning ("Maximum string length (%ld bytes) exceeded. "
"Possibly corrupt XCF file.", MAX_XCF_STRING_LEN);
data[i] = NULL;
}
else if (tmp > 0)
{
gchar *str;
str = g_new (gchar, tmp);
total += xcf_read_int8 (info, (guint8*) str, tmp);
if (str[tmp - 1] != '\0')
str[tmp - 1] = '\0';
data[i] = pika_any_to_utf8 (str, -1,
_("Invalid UTF-8 string in XCF file"));
g_free (str);
}
else
{
data[i] = NULL;
}
}
return total;
}
guint
xcf_read_component (XcfInfo *info,
gint bpc,
guint8 *data,
gint count)
{
switch (bpc)
{
case 1:
return xcf_read_int8 (info, data, count);
case 2:
return xcf_read_int16 (info, (guint16 *) data, count);
case 4:
return xcf_read_int32 (info, (guint32 *) data, count);
case 8:
return xcf_read_int64 (info, (guint64 *) data, count);
default:
break;
}
return 0;
}
void
xcf_read_from_be (gint bpc,
guint8 *data,
gint count)
{
gint i;
switch (bpc)
{
case 1:
break;
case 2:
{
guint16 *d = (guint16 *) data;
for (i = 0; i < count; i++)
d[i] = g_ntohs (d[i]);
}
break;
case 4:
{
guint32 *d = (guint32 *) data;
for (i = 0; i < count; i++)
d[i] = g_ntohl (d[i]);
}
break;
case 8:
{
guint64 *d = (guint64 *) data;
for (i = 0; i < count; i++)
d[i] = GINT64_FROM_BE (d[i]);
}
break;
}
}

57
app/xcf/xcf-read.h Normal file
View File

@ -0,0 +1,57 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __XCF_READ_H__
#define __XCF_READ_H__
guint xcf_read_int8 (XcfInfo *info,
guint8 *data,
gint count);
guint xcf_read_int16 (XcfInfo *info,
guint16 *data,
gint count);
guint xcf_read_int32 (XcfInfo *info,
guint32 *data,
gint count);
guint xcf_read_int64 (XcfInfo *info,
guint64 *data,
gint count);
guint xcf_read_offset (XcfInfo *info,
goffset *data,
gint count);
guint xcf_read_float (XcfInfo *info,
gfloat *data,
gint count);
guint xcf_read_string (XcfInfo *info,
gchar **data,
gint count);
guint xcf_read_component (XcfInfo *info,
gint bpc,
guint8 *data,
gint count);
void xcf_read_from_be (gint bpc,
guint8 *data,
gint count);
#endif /* __XCF_READ_H__ */

2892
app/xcf/xcf-save.c Normal file

File diff suppressed because it is too large Load Diff

31
app/xcf/xcf-save.h Normal file
View File

@ -0,0 +1,31 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __XCF_SAVE_H__
#define __XCF_SAVE_H__
gboolean xcf_save_image (XcfInfo *info,
PikaImage *image,
GError **error);
#endif /* __XCF_SAVE_H__ */

57
app/xcf/xcf-seek.c Normal file
View File

@ -0,0 +1,57 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gio/gio.h>
#include "core/core-types.h"
#include "xcf-private.h"
#include "xcf-seek.h"
#include "pika-intl.h"
gboolean
xcf_seek_pos (XcfInfo *info,
goffset pos,
GError **error)
{
if (info->cp != pos)
{
GError *my_error = NULL;
info->cp = pos;
if (! g_seekable_seek (info->seekable, info->cp, G_SEEK_SET,
NULL, &my_error))
{
g_propagate_prefixed_error (error, my_error,
_("Could not seek in XCF file: "));
return FALSE;
}
pika_assert (info->cp == g_seekable_tell (info->seekable));
}
return TRUE;
}

31
app/xcf/xcf-seek.h Normal file
View File

@ -0,0 +1,31 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __XCF_SEEK_H__
#define __XCF_SEEK_H__
gboolean xcf_seek_pos (XcfInfo *info,
goffset pos,
GError **error);
#endif /* __XCF_SEEK_H__ */

57
app/xcf/xcf-utils.c Normal file
View File

@ -0,0 +1,57 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <cairo.h>
#include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "xcf-utils.h"
gboolean
xcf_data_is_zero (const void *data,
gint size)
{
const guint8 *data8;
const guint64 *data64;
for (data8 = data; size > 0 && (guintptr) data8 % 8 != 0; data8++, size--)
{
if (*data8)
return FALSE;
}
for (data64 = (gpointer) data8; size >= 8; data64++, size -= 8)
{
if (*data64)
return FALSE;
}
for (data8 = (gpointer) data64; size > 0; data8++, size--)
{
if (*data8)
return FALSE;
}
return TRUE;
}

30
app/xcf/xcf-utils.h Normal file
View File

@ -0,0 +1,30 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __XCF_UTILS_H__
#define __XCF_UTILS_H__
gboolean xcf_data_is_zero (const void *data,
gint size);
#endif /* __XCF_UTILS_H__ */

343
app/xcf/xcf-write.c Normal file
View File

@ -0,0 +1,343 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <gio/gio.h>
#include "core/core-types.h"
#include "xcf-private.h"
#include "xcf-write.h"
#include "pika-intl.h"
guint
xcf_write_int8 (XcfInfo *info,
const guint8 *data,
gint count,
GError **error)
{
GError *my_error = NULL;
gsize bytes_written = 0;
/* we allow for 'data == NULL && count == 0', which
* g_output_stream_write_all() rejects.
*/
if (count > 0)
{
if (! g_output_stream_write_all (info->output, data, count,
&bytes_written, NULL, &my_error))
{
g_propagate_prefixed_error (error, my_error,
_("Error writing XCF: "));
}
info->cp += bytes_written;
}
return bytes_written;
}
guint
xcf_write_int16 (XcfInfo *info,
const guint16 *data,
gint count,
GError **error)
{
GError *tmp_error = NULL;
gint i;
if (count > 0)
{
for (i = 0; i < count; i++)
{
guint16 tmp = g_htons (data[i]);
xcf_write_int8 (info, (const guint8 *) &tmp, 2, &tmp_error);
if (tmp_error)
{
g_propagate_error (error, tmp_error);
return i * 2;
}
}
}
return count * 2;
}
guint
xcf_write_int32 (XcfInfo *info,
const guint32 *data,
gint count,
GError **error)
{
GError *tmp_error = NULL;
gint i;
if (count > 0)
{
for (i = 0; i < count; i++)
{
guint32 tmp = g_htonl (data[i]);
xcf_write_int8 (info, (const guint8 *) &tmp, 4, &tmp_error);
if (tmp_error)
{
g_propagate_error (error, tmp_error);
return i * 4;
}
}
}
return count * 4;
}
guint
xcf_write_int64 (XcfInfo *info,
const guint64 *data,
gint count,
GError **error)
{
GError *tmp_error = NULL;
gint i;
if (count > 0)
{
for (i = 0; i < count; i++)
{
guint64 tmp = GINT64_TO_BE (data[i]);
xcf_write_int8 (info, (const guint8 *) &tmp, 8, &tmp_error);
if (tmp_error)
{
g_propagate_error (error, tmp_error);
return i * 8;
}
}
}
return count * 8;
}
guint
xcf_write_offset (XcfInfo *info,
const goffset *data,
gint count,
GError **error)
{
if (count > 0)
{
gint i;
for (i = 0; i < count; i++)
{
GError *tmp_error = NULL;
if (info->bytes_per_offset == 4)
{
guint32 tmp = g_htonl (data[i]);
xcf_write_int8 (info, (const guint8 *) &tmp, 4, &tmp_error);
}
else
{
gint64 tmp = GINT64_TO_BE (data[i]);
xcf_write_int8 (info, (const guint8 *) &tmp, 8, &tmp_error);
}
if (tmp_error)
{
g_propagate_error (error, tmp_error);
return i * info->bytes_per_offset;
}
}
}
return count * info->bytes_per_offset;
}
guint
xcf_write_zero_offset (XcfInfo *info,
gint count,
GError **error)
{
if (count > 0)
{
guint8 *tmp;
guint bytes_written = 0;
tmp = g_try_malloc (count * info->bytes_per_offset);
if (! tmp)
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Error writing XCF: failed to allocate %d bytes of memory."),
count * info->bytes_per_offset);
}
else
{
memset (tmp, 0, count * info->bytes_per_offset);
bytes_written = xcf_write_int8 (info, (const guint8 *) tmp,
count * info->bytes_per_offset, error);
g_free (tmp);
}
return bytes_written;
}
return 0;
}
guint
xcf_write_float (XcfInfo *info,
const gfloat *data,
gint count,
GError **error)
{
return xcf_write_int32 (info,
(const guint32 *)((gconstpointer) data), count,
error);
}
guint
xcf_write_string (XcfInfo *info,
gchar **data,
gint count,
GError **error)
{
GError *tmp_error = NULL;
guint total = 0;
gint i;
for (i = 0; i < count; i++)
{
guint32 tmp;
if (data[i])
tmp = strlen (data[i]) + 1;
else
tmp = 0;
xcf_write_int32 (info, &tmp, 1, &tmp_error);
if (tmp_error)
{
g_propagate_error (error, tmp_error);
return total;
}
if (tmp > 0)
xcf_write_int8 (info, (const guint8 *) data[i], tmp, &tmp_error);
if (tmp_error)
{
g_propagate_error (error, tmp_error);
return total;
}
total += 4 + tmp;
}
return total;
}
guint
xcf_write_component (XcfInfo *info,
gint bpc,
const guint8 *data,
gint count,
GError **error)
{
switch (bpc)
{
case 1:
return xcf_write_int8 (info, data, count, error);
case 2:
return xcf_write_int16 (info, (const guint16 *) data, count, error);
case 4:
return xcf_write_int32 (info, (const guint32 *) data, count, error);
case 8:
return xcf_write_int64 (info, (const guint64 *) data, count, error);
default:
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Error writing XCF: unsupported BPC when writing pixel: %d"),
bpc);
}
return 0;
}
void
xcf_write_to_be (gint bpc,
guint8 *data,
gint count)
{
gint i;
switch (bpc)
{
case 1:
break;
case 2:
{
guint16 *d = (guint16 *) data;
for (i = 0; i < count; i++)
d[i] = g_htons (d[i]);
}
break;
case 4:
{
guint32 *d = (guint32 *) data;
for (i = 0; i < count; i++)
d[i] = g_htonl (d[i]);
}
break;
case 8:
{
guint64 *d = (guint64 *) data;
for (i = 0; i < count; i++)
d[i] = GINT64_TO_BE (d[i]);
}
break;
}
}

68
app/xcf/xcf-write.h Normal file
View File

@ -0,0 +1,68 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __XCF_WRITE_H__
#define __XCF_WRITE_H__
guint xcf_write_int8 (XcfInfo *info,
const guint8 *data,
gint count,
GError **error);
guint xcf_write_int16 (XcfInfo *info,
const guint16 *data,
gint count,
GError **error);
guint xcf_write_int32 (XcfInfo *info,
const guint32 *data,
gint count,
GError **error);
guint xcf_write_int64 (XcfInfo *info,
const guint64 *data,
gint count,
GError **error);
guint xcf_write_offset (XcfInfo *info,
const goffset *data,
gint count,
GError **error);
guint xcf_write_zero_offset (XcfInfo *info,
gint count,
GError **error);
guint xcf_write_float (XcfInfo *info,
const gfloat *data,
gint count,
GError **error);
guint xcf_write_string (XcfInfo *info,
gchar **data,
gint count,
GError **error);
guint xcf_write_component (XcfInfo *info,
gint bpc,
const guint8 *data,
gint count,
GError **error);
void xcf_write_to_be (gint bpc,
guint8 *data,
gint count);
#endif /* __XCF_WRITE_H__ */

506
app/xcf/xcf.c Normal file
View File

@ -0,0 +1,506 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <glib/gstdio.h>
#include <gegl.h>
#include "libpikabase/pikabase.h"
#include "core/core-types.h"
#include "core/pika.h"
#include "core/pikaimage.h"
#include "core/pikadrawable.h"
#include "core/pikaparamspecs.h"
#include "core/pikaprogress.h"
#include "plug-in/pikapluginmanager.h"
#include "plug-in/pikapluginprocedure.h"
#include "xcf.h"
#include "xcf-private.h"
#include "xcf-load.h"
#include "xcf-read.h"
#include "xcf-save.h"
#include "pika-intl.h"
typedef PikaImage * PikaXcfLoaderFunc (Pika *pika,
XcfInfo *info,
GError **error);
static PikaValueArray * xcf_load_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error);
static PikaValueArray * xcf_save_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error);
static PikaXcfLoaderFunc * const xcf_loaders[] =
{
xcf_load_image, /* version 0 */
xcf_load_image, /* version 1 */
xcf_load_image, /* version 2 */
xcf_load_image, /* version 3 */
xcf_load_image, /* version 4 */
xcf_load_image, /* version 5 */
xcf_load_image, /* version 6 */
xcf_load_image, /* version 7 */
xcf_load_image, /* version 8 */
xcf_load_image, /* version 9 */
xcf_load_image, /* version 10 */
xcf_load_image, /* version 11 */
xcf_load_image, /* version 12 */
xcf_load_image, /* version 13 */
xcf_load_image, /* version 14 */
xcf_load_image, /* version 15 */
xcf_load_image, /* version 16 */
xcf_load_image, /* version 17 */
xcf_load_image, /* version 18 */
xcf_load_image, /* version 19 */
};
void
xcf_init (Pika *pika)
{
PikaPlugInProcedure *proc;
GFile *file;
PikaProcedure *procedure;
g_return_if_fail (PIKA_IS_PIKA (pika));
/* So this is sort of a hack, but its better than it was before. To
* do this right there would be a file load-save handler type and
* the whole interface would change but there isn't, and currently
* the plug-in structure contains all the load-save info, so it
* makes sense to use that for the XCF load/save handlers, even
* though they are internal. The only thing it requires is using a
* PlugInProcDef struct. -josh
*/
/* pika-xcf-save */
file = g_file_new_for_path ("pika-xcf-save");
procedure = pika_plug_in_procedure_new (PIKA_PDB_PROC_TYPE_PLUGIN, file);
g_object_unref (file);
procedure->proc_type = PIKA_PDB_PROC_TYPE_INTERNAL;
procedure->marshal_func = xcf_save_invoker;
proc = PIKA_PLUG_IN_PROCEDURE (procedure);
proc->menu_label = g_strdup (N_("PIKA XCF image"));
pika_plug_in_procedure_set_icon (proc, PIKA_ICON_TYPE_ICON_NAME,
(const guint8 *) "pika-mascot",
strlen ("pika-mascot") + 1,
NULL);
pika_plug_in_procedure_set_image_types (proc, "RGB*, GRAY*, INDEXED*");
pika_plug_in_procedure_set_file_proc (proc, "xcf", "", NULL);
pika_plug_in_procedure_set_mime_types (proc, "image/x-xcf");
pika_plug_in_procedure_set_handles_remote (proc);
pika_object_set_static_name (PIKA_OBJECT (procedure), "pika-xcf-save");
pika_procedure_set_static_help (procedure,
"Saves file in the .xcf file format",
"The XCF file format has been designed "
"specifically for loading and saving "
"tiled and layered images in PIKA. "
"This procedure will save the specified "
"image in the xcf file format.",
NULL);
pika_procedure_set_static_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996");
pika_procedure_add_argument (procedure,
pika_param_spec_enum ("dummy-param",
"Dummy Param",
"Dummy parameter",
PIKA_TYPE_RUN_MODE,
PIKA_RUN_INTERACTIVE,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
pika_param_spec_image ("image",
"Image",
"Input image",
FALSE,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_int ("n-drawables",
"Num drawables",
"Number of drawables",
0, G_MAXINT, 0,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
pika_param_spec_object_array ("drawables",
"Drawables",
"Selected drawables",
PIKA_TYPE_DRAWABLE,
PIKA_PARAM_READWRITE | PIKA_PARAM_NO_VALIDATE));
pika_procedure_add_argument (procedure,
g_param_spec_object ("file",
"File",
"The file "
"to save the image in",
G_TYPE_FILE,
PIKA_PARAM_READWRITE));
pika_plug_in_manager_add_procedure (pika->plug_in_manager, proc);
g_object_unref (procedure);
/* pika-xcf-load */
file = g_file_new_for_path ("pika-xcf-load");
procedure = pika_plug_in_procedure_new (PIKA_PDB_PROC_TYPE_PLUGIN, file);
g_object_unref (file);
procedure->proc_type = PIKA_PDB_PROC_TYPE_INTERNAL;
procedure->marshal_func = xcf_load_invoker;
proc = PIKA_PLUG_IN_PROCEDURE (procedure);
proc->menu_label = g_strdup (N_("PIKA XCF image"));
pika_plug_in_procedure_set_icon (proc, PIKA_ICON_TYPE_ICON_NAME,
(const guint8 *) "pika-mascot",
strlen ("pika-mascot") + 1,
NULL);
pika_plug_in_procedure_set_image_types (proc, NULL);
pika_plug_in_procedure_set_file_proc (proc, "xcf", "",
"0,string,pika\\040xcf\\040");
pika_plug_in_procedure_set_mime_types (proc, "image/x-xcf");
pika_plug_in_procedure_set_handles_remote (proc);
pika_object_set_static_name (PIKA_OBJECT (procedure), "pika-xcf-load");
pika_procedure_set_static_help (procedure,
"Loads file saved in the .xcf file format",
"The XCF file format has been designed "
"specifically for loading and saving "
"tiled and layered images in PIKA. "
"This procedure will load the specified "
"file.",
NULL);
pika_procedure_set_static_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996");
pika_procedure_add_argument (procedure,
pika_param_spec_enum ("dummy-param",
"Dummy Param",
"Dummy parameter",
PIKA_TYPE_RUN_MODE,
PIKA_RUN_INTERACTIVE,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_object ("file",
"File",
"The file to load",
G_TYPE_FILE,
PIKA_PARAM_READWRITE));
pika_procedure_add_return_value (procedure,
pika_param_spec_image ("image",
"Image",
"Output image",
FALSE,
PIKA_PARAM_READWRITE));
pika_plug_in_manager_add_procedure (pika->plug_in_manager, proc);
g_object_unref (procedure);
}
void
xcf_exit (Pika *pika)
{
g_return_if_fail (PIKA_IS_PIKA (pika));
}
PikaImage *
xcf_load_stream (Pika *pika,
GInputStream *input,
GFile *input_file,
PikaProgress *progress,
GError **error)
{
XcfInfo info = { 0, };
const gchar *filename;
PikaImage *image = NULL;
gchar id[14];
gboolean success;
g_return_val_if_fail (PIKA_IS_PIKA (pika), NULL);
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
g_return_val_if_fail (input_file == NULL || G_IS_FILE (input_file), NULL);
g_return_val_if_fail (progress == NULL || PIKA_IS_PROGRESS (progress), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (input_file)
filename = pika_file_get_utf8_name (input_file);
else
filename = _("Memory Stream");
info.pika = pika;
info.input = input;
info.seekable = G_SEEKABLE (input);
info.bytes_per_offset = 4;
info.progress = progress;
info.file = input_file;
info.compression = COMPRESS_NONE;
if (progress)
pika_progress_start (progress, FALSE, _("Opening '%s'"), filename);
success = TRUE;
xcf_read_int8 (&info, (guint8 *) id, 14);
if (! g_str_has_prefix (id, "gimp xcf "))
{
success = FALSE;
}
else if (strcmp (id + 9, "file") == 0)
{
info.file_version = 0;
}
else if (id[9] == 'v' &&
id[13] == '\0')
{
info.file_version = atoi (id + 10);
}
else
{
success = FALSE;
}
if (info.file_version >= 11)
info.bytes_per_offset = 8;
if (success)
{
if (info.file_version >= 0 &&
info.file_version < G_N_ELEMENTS (xcf_loaders))
{
image = (*(xcf_loaders[info.file_version])) (pika, &info, error);
if (! image)
success = FALSE;
g_input_stream_close (info.input, NULL, NULL);
}
else
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("XCF error: unsupported XCF file version %d "
"encountered"), info.file_version);
success = FALSE;
}
}
if (progress)
pika_progress_end (progress);
return image;
}
gboolean
xcf_save_stream (Pika *pika,
PikaImage *image,
GOutputStream *output,
GFile *output_file,
PikaProgress *progress,
GError **error)
{
XcfInfo info = { 0, };
const gchar *filename;
gboolean success = FALSE;
GError *my_error = NULL;
GCancellable *cancellable;
g_return_val_if_fail (PIKA_IS_PIKA (pika), FALSE);
g_return_val_if_fail (PIKA_IS_IMAGE (image), FALSE);
g_return_val_if_fail (G_IS_OUTPUT_STREAM (output), FALSE);
g_return_val_if_fail (output_file == NULL || G_IS_FILE (output_file), FALSE);
g_return_val_if_fail (progress == NULL || PIKA_IS_PROGRESS (progress), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (output_file)
filename = pika_file_get_utf8_name (output_file);
else
filename = _("Memory Stream");
info.pika = pika;
info.output = output;
info.seekable = G_SEEKABLE (output);
info.bytes_per_offset = 4;
info.progress = progress;
info.file = output_file;
if (pika_image_get_xcf_compression (image))
info.compression = COMPRESS_ZLIB;
else
info.compression = COMPRESS_RLE;
info.file_version = pika_image_get_xcf_version (image,
info.compression ==
COMPRESS_ZLIB,
NULL, NULL, NULL);
if (info.file_version >= 11)
info.bytes_per_offset = 8;
if (progress)
pika_progress_start (progress, FALSE, _("Saving '%s'"), filename);
success = xcf_save_image (&info, image, &my_error);
cancellable = g_cancellable_new ();
if (success)
{
if (progress)
pika_progress_set_text (progress, _("Closing '%s'"), filename);
}
else
{
/* When closing the stream, the image will be actually saved,
* unless we properly cancel it with a GCancellable.
* Not closing the stream is not an option either, as this will
* happen anyway when finalizing the output.
* So let's make sure now that we don't overwrite the XCF file
* when an error occurred.
*/
g_cancellable_cancel (cancellable);
}
success = g_output_stream_close (info.output, cancellable, &my_error);
g_object_unref (cancellable);
if (! success && my_error)
g_propagate_prefixed_error (error, my_error,
_("Error writing '%s': "), filename);
if (progress)
pika_progress_end (progress);
return success;
}
/* private functions */
static PikaValueArray *
xcf_load_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
PikaValueArray *return_vals;
PikaImage *image = NULL;
GFile *file;
GInputStream *input;
GError *my_error = NULL;
pika_set_busy (pika);
file = g_value_get_object (pika_value_array_index (args, 1));
input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
if (input)
{
image = xcf_load_stream (pika, input, file, progress, error);
g_object_unref (input);
}
else
{
g_propagate_prefixed_error (error, my_error,
_("Could not open '%s' for reading: "),
pika_file_get_utf8_name (file));
}
return_vals = pika_procedure_get_return_values (procedure, image != NULL,
error ? *error : NULL);
if (image)
g_value_set_object (pika_value_array_index (return_vals, 1), image);
pika_unset_busy (pika);
return return_vals;
}
static PikaValueArray *
xcf_save_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
PikaValueArray *return_vals;
PikaImage *image;
GFile *file;
GOutputStream *output;
gboolean success = FALSE;
GError *my_error = NULL;
pika_set_busy (pika);
image = g_value_get_object (pika_value_array_index (args, 1));
file = g_value_get_object (pika_value_array_index (args, 4));
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, &my_error));
if (output)
{
success = xcf_save_stream (pika, image, output, file, progress, error);
g_object_unref (output);
}
else
{
g_propagate_prefixed_error (error, my_error,
_("Error creating '%s': "),
pika_file_get_utf8_name (file));
}
return_vals = pika_procedure_get_return_values (procedure, success,
error ? *error : NULL);
pika_unset_busy (pika);
return return_vals;
}

42
app/xcf/xcf.h Normal file
View File

@ -0,0 +1,42 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __XCF_H__
#define __XCF_H__
void xcf_init (Pika *pika);
void xcf_exit (Pika *pika);
PikaImage * xcf_load_stream (Pika *pika,
GInputStream *input,
GFile *input_file,
PikaProgress *progress,
GError **error);
gboolean xcf_save_stream (Pika *pika,
PikaImage *image,
GOutputStream *output,
GFile *output_file,
PikaProgress *progress,
GError **error);
#endif /* __XCF_H__ */