gimp/app/core/gimpbrush-load.c

1152 lines
33 KiB
C
Raw Normal View History

/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpbrush-load.c
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
Jens Lautenbacher <jtl@gimp.org> 2000-12-18 Sven Neumann <sven@gimp.org> Jens Lautenbacher <jtl@gimp.org> * app/Makefile.am * app/gimpbrushlistP.h * app/gimpbrushpipeP.h * app/gimpobjectP.h: removed these three files * app/parasitelistP.h * app/channels_dialog.c * app/docindex.c * app/gimpdrawable.c * app/gimpdrawableP.h * app/gimpimage.c * app/gimpimageP.h * app/gimplist.[ch] * app/gimpobject.c * app/gimpobject.h * app/gimpsetP.h: changed according to header removal * app/airbrush.c * app/brush_select.[ch] * app/brushes_cmds.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushlist.[ch] * app/gimpbrushpipe.[ch] * app/gimpcontextpreview.c * app/paint_core.c * app/paintbrush.c * app/pencil.c * tools/pdbgen/pdb/brushes.pdb: Big Brushes Cleanup. The GimpBrush* object hierarchy and the file formats were broken by "design". This made it overly difficult to read and write pixmap brushes and brush pipes, leading to the situation that The GIMP was not able to read it's very own file formats. Since the GimpBrush format did support arbitrary color depths, the introduction of a file format for pixmap brushes was unnecessary. The GimpBrushPixmap object is dead. GimpBrush has an additional pixmap temp_buf and handles pixmap brushes transparently. The file format of pixmap brushes is not any longer a grayscale brush plus a pattern, but a simple brush with RGBA data. The old brushes can still be loaded, but the .gpb format is deprecated. GimpBrushPipe derives from GimpBrush. The fileformat is still a text header, followed by a number of brushes, but those brushes are stored in the new GimpBrush format (no pattern anymore). The pipe does not care about the depth of the contained GimpBrushes, so we get grayscale BrushPipes for free. Since the brush loader still loads the old format, old .gih files can also still be loaded. Since the brushes in the GimpBrushPipe do not any longer contain a pointer to the pipe object, we do only temporarily switch brushes in the paint_core routines. This is not very elegant, but the best we can do without a major redesign. * app/patterns.[ch]: changed the loader to work with a filedescriptor instead of a filehandle to make it work with the new brush loading code. * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/common/gih.c: new plug-in that saves GIH files in the new format (loader will follow soon) * plug-ins/common/gpb.c: removed since Pixmap Brushes are no longer supported as a special file format. * plug-ins/common/gbr.c: load and save brushes in the new brush format which allows RGBA brushes too. * plug-ins/common/pat.c: load and save grayscale patterns too
2000-12-18 23:14:08 +08:00
#include "libgimpbase/gimpbase.h"
#include "core-types.h"
Jens Lautenbacher <jtl@gimp.org> 2000-12-18 Sven Neumann <sven@gimp.org> Jens Lautenbacher <jtl@gimp.org> * app/Makefile.am * app/gimpbrushlistP.h * app/gimpbrushpipeP.h * app/gimpobjectP.h: removed these three files * app/parasitelistP.h * app/channels_dialog.c * app/docindex.c * app/gimpdrawable.c * app/gimpdrawableP.h * app/gimpimage.c * app/gimpimageP.h * app/gimplist.[ch] * app/gimpobject.c * app/gimpobject.h * app/gimpsetP.h: changed according to header removal * app/airbrush.c * app/brush_select.[ch] * app/brushes_cmds.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushlist.[ch] * app/gimpbrushpipe.[ch] * app/gimpcontextpreview.c * app/paint_core.c * app/paintbrush.c * app/pencil.c * tools/pdbgen/pdb/brushes.pdb: Big Brushes Cleanup. The GimpBrush* object hierarchy and the file formats were broken by "design". This made it overly difficult to read and write pixmap brushes and brush pipes, leading to the situation that The GIMP was not able to read it's very own file formats. Since the GimpBrush format did support arbitrary color depths, the introduction of a file format for pixmap brushes was unnecessary. The GimpBrushPixmap object is dead. GimpBrush has an additional pixmap temp_buf and handles pixmap brushes transparently. The file format of pixmap brushes is not any longer a grayscale brush plus a pattern, but a simple brush with RGBA data. The old brushes can still be loaded, but the .gpb format is deprecated. GimpBrushPipe derives from GimpBrush. The fileformat is still a text header, followed by a number of brushes, but those brushes are stored in the new GimpBrush format (no pattern anymore). The pipe does not care about the depth of the contained GimpBrushes, so we get grayscale BrushPipes for free. Since the brush loader still loads the old format, old .gih files can also still be loaded. Since the brushes in the GimpBrushPipe do not any longer contain a pointer to the pipe object, we do only temporarily switch brushes in the paint_core routines. This is not very elegant, but the best we can do without a major redesign. * app/patterns.[ch]: changed the loader to work with a filedescriptor instead of a filehandle to make it work with the new brush loading code. * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/common/gih.c: new plug-in that saves GIH files in the new format (loader will follow soon) * plug-ins/common/gpb.c: removed since Pixmap Brushes are no longer supported as a special file format. * plug-ins/common/gbr.c: load and save brushes in the new brush format which allows RGBA brushes too. * plug-ins/common/pat.c: load and save grayscale patterns too
2000-12-18 23:14:08 +08:00
#include "gimpbrush.h"
#include "gimpbrush-header.h"
#include "gimpbrush-load.h"
#include "gimpbrush-private.h"
#include "gimptempbuf.h"
Jens Lautenbacher <jtl@gimp.org> 2000-12-18 Sven Neumann <sven@gimp.org> Jens Lautenbacher <jtl@gimp.org> * app/Makefile.am * app/gimpbrushlistP.h * app/gimpbrushpipeP.h * app/gimpobjectP.h: removed these three files * app/parasitelistP.h * app/channels_dialog.c * app/docindex.c * app/gimpdrawable.c * app/gimpdrawableP.h * app/gimpimage.c * app/gimpimageP.h * app/gimplist.[ch] * app/gimpobject.c * app/gimpobject.h * app/gimpsetP.h: changed according to header removal * app/airbrush.c * app/brush_select.[ch] * app/brushes_cmds.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushlist.[ch] * app/gimpbrushpipe.[ch] * app/gimpcontextpreview.c * app/paint_core.c * app/paintbrush.c * app/pencil.c * tools/pdbgen/pdb/brushes.pdb: Big Brushes Cleanup. The GimpBrush* object hierarchy and the file formats were broken by "design". This made it overly difficult to read and write pixmap brushes and brush pipes, leading to the situation that The GIMP was not able to read it's very own file formats. Since the GimpBrush format did support arbitrary color depths, the introduction of a file format for pixmap brushes was unnecessary. The GimpBrushPixmap object is dead. GimpBrush has an additional pixmap temp_buf and handles pixmap brushes transparently. The file format of pixmap brushes is not any longer a grayscale brush plus a pattern, but a simple brush with RGBA data. The old brushes can still be loaded, but the .gpb format is deprecated. GimpBrushPipe derives from GimpBrush. The fileformat is still a text header, followed by a number of brushes, but those brushes are stored in the new GimpBrush format (no pattern anymore). The pipe does not care about the depth of the contained GimpBrushes, so we get grayscale BrushPipes for free. Since the brush loader still loads the old format, old .gih files can also still be loaded. Since the brushes in the GimpBrushPipe do not any longer contain a pointer to the pipe object, we do only temporarily switch brushes in the paint_core routines. This is not very elegant, but the best we can do without a major redesign. * app/patterns.[ch]: changed the loader to work with a filedescriptor instead of a filehandle to make it work with the new brush loading code. * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/common/gih.c: new plug-in that saves GIH files in the new format (loader will follow soon) * plug-ins/common/gpb.c: removed since Pixmap Brushes are no longer supported as a special file format. * plug-ins/common/gbr.c: load and save brushes in the new brush format which allows RGBA brushes too. * plug-ins/common/pat.c: load and save grayscale patterns too
2000-12-18 23:14:08 +08:00
#include "gimp-intl.h"
/* stuff from abr2gbr Copyright (C) 2001 Marco Lamberto <lm@sunnyspot.org> */
/* the above is GPL see http://the.sunnyspot.org/gimp/ */
removed GimpFillType. 2001-06-29 Michael Natterer <mitch@gimp.org> * app/appenums.h: removed GimpFillType. * app/gimprc.c: parse the session-info's new "aux-info" field. * app/global_edit.[ch]: removed the old "Paste Named" dialog and prefixed all functions with "gimp_". * app/core/core-types.h: added GimpFillType. * app/core/gimpbrush.[ch]: new signal "spacing_changed". * app/gui/Makefile.am * app/gui/tools-commands.[ch]: one more file cut out of commands.[ch]. * app/gui/commands.[ch]: removed the tools stuff here. * app/gui/brush-select.[ch] * app/gui/dialogs-constructors.c: use the new GimpBrushFactoryView (see below). * app/gui/dialogs-commands.[ch] * app/gui/menus.[ch]: - Made it 64bit safe again by passing the dialog factory's identifiers as GQuarks, not as guints created by GPOINTER_TO_UINT(). - Added a "gchar *quark_string" field to GimpItemFactoryEntry which gets transformed into a GQuark by menus_create_item(). - Added SEPARATOR() and BRANCH() macros which make the *_entries[] arrays more readable. - Added a menu item to show/hide GimpImageDock's image menu. - Removed file_last_opened_cmd_callback(). * app/gui/edit-commands.c: the global_edit functions are "gimp_" prefixed now. * app/gui/file-commands.[ch]: added file_last_opened_cmd_callback() here. * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpbrushfactoryview.[ch]: new widget: a GimpDataFactory subclass with a "spacing" scale. * app/widgets/gimpcontainereditor.[ch]: - Connect to the GimpContainerView's "select_item", "activate_item" and "context_item" signals here once instead of in each subclass and dispatch them via new virtual functions. - Added a convenience function which makes DND to the buttons much less painful for subclasses. * app/widgets/gimpbufferview.c * app/widgets/gimpdatafactoryview.[ch]: changed accordingly. * app/widgets/gimpdialogfactory.[ch]: - Added gimp_dialog_factory_dialog_raise() which can raise toplevel dialogs _and_ dockables (and creates them if they are not open yet). - Keep track of all created dialogs (not only toplevels). - Added an "aux_info" field to GimpSessionInfo which is a GList of gchar* and is saved in sessionrc. - Remember if GimpImageDock's image menu is visible by using an aux_info string. - The code did not become nicer with all those new constraints. I have to add comments before I forget how it works. * app/widgets/gimpdockbook.c: set the state of the "Show Image Menu" menu item before popping up the item factory. * app/widgets/gimpimagedock.[ch]: added gimp_image_dock_set_show_image_meu(). * plug-ins/gdyntext/gdyntext.c * plug-ins/perl/examples/fit-text * plug-ins/perl/examples/terral_text * plug-ins/perl/examples/tex-to-float: register all text rendering plug-ins under <Image>/Filters/Text * app/pdb/brush_select_cmds.c * app/pdb/drawable_cmds.c * app/pdb/edit_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/edit.pdb * tools/pdbgen/enums.pl * po/POTFILES.in: changed according to all the stuff above.
2001-06-30 03:25:03 +08:00
typedef struct _AbrHeader AbrHeader;
typedef struct _AbrBrushHeader AbrBrushHeader;
typedef struct _AbrSampledBrushHeader AbrSampledBrushHeader;
struct _AbrHeader
{
gint16 version;
gint16 count;
};
struct _AbrBrushHeader
{
gint16 type;
gint32 size;
};
struct _AbrSampledBrushHeader
{
gint32 misc;
gint16 spacing;
gchar antialiasing;
gint16 bounds[4];
gint32 bounds_long[4];
gint16 depth;
gboolean wide;
};
/* local function prototypes */
2014-07-04 08:18:52 +08:00
static GList * gimp_brush_load_abr_v12 (GDataInputStream *input,
AbrHeader *abr_hdr,
GFile *file,
GError **error);
static GList * gimp_brush_load_abr_v6 (GDataInputStream *input,
AbrHeader *abr_hdr,
GFile *file,
GError **error);
static GimpBrush * gimp_brush_load_abr_brush_v12 (GDataInputStream *input,
AbrHeader *abr_hdr,
gint index,
GFile *file,
GError **error);
static GimpBrush * gimp_brush_load_abr_brush_v6 (GDataInputStream *input,
AbrHeader *abr_hdr,
gint32 max_offset,
gint index,
GFile *file,
GError **error);
static gchar abr_read_char (GDataInputStream *input,
GError **error);
static gint16 abr_read_short (GDataInputStream *input,
GError **error);
static gint32 abr_read_long (GDataInputStream *input,
GError **error);
static gchar * abr_read_ucs2_text (GDataInputStream *input,
GError **error);
static gboolean abr_supported (AbrHeader *abr_hdr,
GError **error);
static gboolean abr_reach_8bim_section (GDataInputStream *input,
const gchar *name,
GError **error);
static gboolean abr_rle_decode (GDataInputStream *input,
gchar *buffer,
gsize buffer_size,
2014-07-04 08:18:52 +08:00
gint32 height,
GError **error);
removed GimpFillType. 2001-06-29 Michael Natterer <mitch@gimp.org> * app/appenums.h: removed GimpFillType. * app/gimprc.c: parse the session-info's new "aux-info" field. * app/global_edit.[ch]: removed the old "Paste Named" dialog and prefixed all functions with "gimp_". * app/core/core-types.h: added GimpFillType. * app/core/gimpbrush.[ch]: new signal "spacing_changed". * app/gui/Makefile.am * app/gui/tools-commands.[ch]: one more file cut out of commands.[ch]. * app/gui/commands.[ch]: removed the tools stuff here. * app/gui/brush-select.[ch] * app/gui/dialogs-constructors.c: use the new GimpBrushFactoryView (see below). * app/gui/dialogs-commands.[ch] * app/gui/menus.[ch]: - Made it 64bit safe again by passing the dialog factory's identifiers as GQuarks, not as guints created by GPOINTER_TO_UINT(). - Added a "gchar *quark_string" field to GimpItemFactoryEntry which gets transformed into a GQuark by menus_create_item(). - Added SEPARATOR() and BRANCH() macros which make the *_entries[] arrays more readable. - Added a menu item to show/hide GimpImageDock's image menu. - Removed file_last_opened_cmd_callback(). * app/gui/edit-commands.c: the global_edit functions are "gimp_" prefixed now. * app/gui/file-commands.[ch]: added file_last_opened_cmd_callback() here. * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpbrushfactoryview.[ch]: new widget: a GimpDataFactory subclass with a "spacing" scale. * app/widgets/gimpcontainereditor.[ch]: - Connect to the GimpContainerView's "select_item", "activate_item" and "context_item" signals here once instead of in each subclass and dispatch them via new virtual functions. - Added a convenience function which makes DND to the buttons much less painful for subclasses. * app/widgets/gimpbufferview.c * app/widgets/gimpdatafactoryview.[ch]: changed accordingly. * app/widgets/gimpdialogfactory.[ch]: - Added gimp_dialog_factory_dialog_raise() which can raise toplevel dialogs _and_ dockables (and creates them if they are not open yet). - Keep track of all created dialogs (not only toplevels). - Added an "aux_info" field to GimpSessionInfo which is a GList of gchar* and is saved in sessionrc. - Remember if GimpImageDock's image menu is visible by using an aux_info string. - The code did not become nicer with all those new constraints. I have to add comments before I forget how it works. * app/widgets/gimpdockbook.c: set the state of the "Show Image Menu" menu item before popping up the item factory. * app/widgets/gimpimagedock.[ch]: added gimp_image_dock_set_show_image_meu(). * plug-ins/gdyntext/gdyntext.c * plug-ins/perl/examples/fit-text * plug-ins/perl/examples/terral_text * plug-ins/perl/examples/tex-to-float: register all text rendering plug-ins under <Image>/Filters/Text * app/pdb/brush_select_cmds.c * app/pdb/drawable_cmds.c * app/pdb/edit_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/edit.pdb * tools/pdbgen/enums.pl * po/POTFILES.in: changed according to all the stuff above.
2001-06-30 03:25:03 +08:00
/* public functions */
GList *
gimp_brush_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GimpBrush *brush;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2014-07-03 03:11:49 +08:00
brush = gimp_brush_load_brush (context, file, input, error);
if (! brush)
return NULL;
return g_list_prepend (NULL, brush);
}
GimpBrush *
2014-07-03 03:11:49 +08:00
gimp_brush_load_brush (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GimpBrush *brush;
gsize bn_size;
BrushHeader header;
gchar *name = NULL;
guchar *pixmap;
guchar *mask;
2014-07-03 03:11:49 +08:00
gsize bytes_read;
gssize i, size;
gboolean success = TRUE;
g_return_val_if_fail (G_IS_FILE (file), NULL);
2014-07-03 03:11:49 +08:00
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2014-07-03 03:11:49 +08:00
/* read the header */
if (! g_input_stream_read_all (input, &header, sizeof (header),
&bytes_read, NULL, error) ||
2014-07-03 03:11:49 +08:00
bytes_read != sizeof (header))
{
return NULL;
}
/* rearrange the bytes in each unsigned int */
header.header_size = g_ntohl (header.header_size);
header.version = g_ntohl (header.version);
header.width = g_ntohl (header.width);
header.height = g_ntohl (header.height);
header.bytes = g_ntohl (header.bytes);
header.magic_number = g_ntohl (header.magic_number);
header.spacing = g_ntohl (header.spacing);
/* Check for correct file format */
if (header.width == 0)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: Width = 0."));
return NULL;
}
if (header.height == 0)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: Height = 0."));
return NULL;
}
if (header.bytes == 0)
added virtual function get_popup_size() which returns a boolean indicating 2003-02-27 Michael Natterer <mitch@gimp.org> * app/core/gimpviewable.[ch]: added virtual function get_popup_size() which returns a boolean indicating if a popup is needed and its size. * app/core/gimpbrush.c * app/core/gimpbrushpipe.c * app/core/gimpbuffer.c * app/core/gimpdrawable-preview.[ch] * app/core/gimpdrawable.c * app/core/gimpgradient.c * app/core/gimpimage.c * app/core/gimppalette.c * app/core/gimppattern.c * app/core/gimpundo.c: implement it. * app/widgets/gimppreview.[ch]: removed virtual functions needs_popup() and create_popup(). Removed the code which creates the popup and the popup members of the GimpPreview struct. * app/widgets/gimppreview-popup.[ch]: new files providing the utility function gimp_preview_popup_show() which can show popups from any widget, not just from a GimpPreview. Checks if a popup is needed using gimp_viewable_get_popup_size(). * app/widgets/gimpcellrendererviewable.c: show popups here too. * app/widgets/gimpbrushpreview.c * app/widgets/gimpbufferpreview.c * app/widgets/gimpdrawablepreview.c * app/widgets/gimpimagepreview.c: removed needs_popup() and create_popup() implementations. * app/widgets/gimpnavigationpreview.c: removed empty render() implementation. * app/widgets/gimpundoeditor.c: use a tree instead of a list view. * app/widgets/gimpgradientpreview.[ch] * app/widgets/gimppalettepreview.[ch] * app/widgets/gimppatternpreview.[ch]: removed because they only implemented the removed popup functions. * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpmenuitem.c * app/widgets/gimppreview-utils.c: changed accordingly
2003-02-27 21:59:41 +08:00
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: Bytes = 0."));
return NULL;
added virtual function get_popup_size() which returns a boolean indicating 2003-02-27 Michael Natterer <mitch@gimp.org> * app/core/gimpviewable.[ch]: added virtual function get_popup_size() which returns a boolean indicating if a popup is needed and its size. * app/core/gimpbrush.c * app/core/gimpbrushpipe.c * app/core/gimpbuffer.c * app/core/gimpdrawable-preview.[ch] * app/core/gimpdrawable.c * app/core/gimpgradient.c * app/core/gimpimage.c * app/core/gimppalette.c * app/core/gimppattern.c * app/core/gimpundo.c: implement it. * app/widgets/gimppreview.[ch]: removed virtual functions needs_popup() and create_popup(). Removed the code which creates the popup and the popup members of the GimpPreview struct. * app/widgets/gimppreview-popup.[ch]: new files providing the utility function gimp_preview_popup_show() which can show popups from any widget, not just from a GimpPreview. Checks if a popup is needed using gimp_viewable_get_popup_size(). * app/widgets/gimpcellrendererviewable.c: show popups here too. * app/widgets/gimpbrushpreview.c * app/widgets/gimpbufferpreview.c * app/widgets/gimpdrawablepreview.c * app/widgets/gimpimagepreview.c: removed needs_popup() and create_popup() implementations. * app/widgets/gimpnavigationpreview.c: removed empty render() implementation. * app/widgets/gimpundoeditor.c: use a tree instead of a list view. * app/widgets/gimpgradientpreview.[ch] * app/widgets/gimppalettepreview.[ch] * app/widgets/gimppatternpreview.[ch]: removed because they only implemented the removed popup functions. * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpmenuitem.c * app/widgets/gimppreview-utils.c: changed accordingly
2003-02-27 21:59:41 +08:00
}
switch (header.version)
{
case 1:
/* If this is a version 1 brush, set the fp back 8 bytes */
2014-07-03 03:11:49 +08:00
if (! g_seekable_seek (G_SEEKABLE (input), -8, G_SEEK_CUR,
NULL, error))
return NULL;
header.header_size += 8;
/* spacing is not defined in version 1 */
header.spacing = 25;
break;
case 3: /* cinepaint brush */
if (header.bytes == 18 /* FLOAT16_GRAY_GIMAGE */)
{
header.bytes = 2;
}
else
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: Unknown depth %d."),
header.bytes);
return NULL;
}
/* fallthrough */
case 2:
if (header.magic_number == GBRUSH_MAGIC)
break;
default:
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: Unknown version %d."),
header.version);
return NULL;
}
if (header.header_size < sizeof (BrushHeader))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Unsupported brush format"));
return NULL;
}
/* Read in the brush name */
if ((bn_size = (header.header_size - sizeof (header))))
{
gchar *utf8;
name = g_new (gchar, bn_size);
2014-07-03 03:11:49 +08:00
if (! g_input_stream_read_all (input, name, bn_size,
&bytes_read, NULL, error) ||
2014-07-03 03:11:49 +08:00
bytes_read != bn_size)
{
g_free (name);
return NULL;
}
utf8 = gimp_any_to_utf8 (name, bn_size - 1,
_("Invalid UTF-8 string in brush file '%s'."),
gimp_file_get_utf8_name (file));
g_free (name);
name = utf8;
}
if (!name)
name = g_strdup (_("Unnamed"));
brush = g_object_new (GIMP_TYPE_BRUSH,
"name", name,
"mime-type", "image/x-gimp-gbr",
NULL);
g_free (name);
brush->priv->mask = gimp_temp_buf_new (header.width, header.height,
babl_format ("Y u8"));
mask = gimp_temp_buf_get_data (brush->priv->mask);
size = header.width * header.height * header.bytes;
switch (header.bytes)
{
case 1:
2014-07-03 03:11:49 +08:00
success = (g_input_stream_read_all (input, mask, size,
&bytes_read, NULL, error) &&
2014-07-03 03:11:49 +08:00
bytes_read == size);
break;
case 2: /* cinepaint brush, 16 bit floats */
{
guchar buf[8 * 1024];
for (i = 0; success && i < size;)
{
2014-07-03 03:11:49 +08:00
gssize bytes = MIN (size - i, sizeof (buf));
2014-07-03 03:11:49 +08:00
success = (g_input_stream_read_all (input, buf, bytes,
&bytes_read, NULL, error) &&
2014-07-03 03:11:49 +08:00
bytes_read == bytes);
if (success)
{
guint16 *b = (guint16 *) buf;
i += bytes;
for (; bytes > 0; bytes -= 2, mask++, b++)
{
union
{
guint16 u[2];
gfloat f;
} short_float;
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
short_float.u[0] = 0;
short_float.u[1] = GUINT16_FROM_BE (*b);
#else
short_float.u[0] = GUINT16_FROM_BE (*b);
short_float.u[1] = 0;
#endif
*mask = (guchar) (short_float.f * 255.0 + 0.5);
}
}
}
}
break;
case 3:
/* The obsolete .gbp format had a 3-byte pattern following a
* 1-byte brush, when embedded in a brush pipe, the current code
* tries to load that pattern as a brush, and encounters the '3'
* in the header.
*/
g_object_unref (brush);
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file:\n"
"Unsupported brush depth %d\n"
"GIMP brushes must be GRAY or RGBA.\n"
"This might be an obsolete GIMP brush file, try "
"loading it as image and save it again."),
header.bytes);
return NULL;
break;
case 4:
{
guchar buf[8 * 1024];
brush->priv->pixmap = gimp_temp_buf_new (header.width, header.height,
babl_format ("R'G'B' u8"));
pixmap = gimp_temp_buf_get_data (brush->priv->pixmap);
for (i = 0; success && i < size;)
{
2014-07-03 03:11:49 +08:00
gssize bytes = MIN (size - i, sizeof (buf));
2014-07-03 03:11:49 +08:00
success = (g_input_stream_read_all (input, buf, bytes,
&bytes_read, NULL, error) &&
2014-07-03 03:11:49 +08:00
bytes_read == bytes);
if (success)
{
guchar *b = buf;
i += bytes;
for (; bytes > 0; bytes -= 4, pixmap += 3, mask++, b += 4)
{
pixmap[0] = b[0];
pixmap[1] = b[1];
pixmap[2] = b[2];
mask[0] = b[3];
}
}
}
}
break;
default:
g_object_unref (brush);
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file:\n"
"Unsupported brush depth %d\n"
"GIMP brushes must be GRAY or RGBA."),
header.bytes);
return NULL;
}
if (! success)
{
g_object_unref (brush);
return NULL;
}
brush->priv->spacing = header.spacing;
brush->priv->x_axis.x = header.width / 2.0;
brush->priv->x_axis.y = 0.0;
brush->priv->y_axis.x = 0.0;
brush->priv->y_axis.y = header.height / 2.0;
return brush;
}
GList *
gimp_brush_load_abr (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
added vitrual function GimpViewable::get_description() which returns the 2003-04-08 Michael Natterer <mitch@gimp.org> * app/core/gimpviewable.[ch]: added vitrual function GimpViewable::get_description() which returns the string that should be presented to the user plus an optional tooltip with more information. The default implementation just returns the object's name and no tooltip. * app/core/gimpbrush.c * app/core/gimpbuffer.c * app/core/gimpimage.c * app/core/gimppalette.c * app/core/gimppattern.c * app/core/gimptoolinfo.c: implement get_description(). * app/core/gimpimagefile.[ch]: ditto. Renamed gimp_imagefile_get_description() to gimp_imagefile_get_desc_string(). Well, um, gimme a better name... * app/gui/file-open-dialog.c: changed accordingly. * app/file/file-utils.[ch]: renamed readXVThumb() to file_utils_readXVThumb(). * tools/pdbgen/pdb/fileops.pdb: changed accordingly. * app/widgets/widgets-types.h: removed GimpItemGetNameFunc typedef. * app/widgets/gimpcontainerview-utils.[ch]: removed the the actual get_name_funcs. They now live in the core as GimpViewable::get_description() implementations. * app/widgets/gimpcontainermenu.[ch] * app/widgets/gimpcontainergridview.c * app/widgets/gimpcontainermenuimpl.c * app/widgets/gimpcontainertreeview.c * app/widgets/gimpcontainerview.[ch] * app/widgets/gimpmenuitem.[ch] * app/widgets/gimpviewabledialog.c: removed get_name_func stuff and use gimp_viewable_get_description(). * app/widgets/gimpcontainermenu.[ch]: added "preview_border_width" to gimp_container_menu_set_preview_size(). * app/widgets/gimpimagedock.c: changed accordingly. * app/pdb/fileops_cmds.c: regenerated.
2003-04-09 00:01:01 +08:00
{
2014-07-04 08:18:52 +08:00
GDataInputStream *data_input;
AbrHeader abr_hdr;
GList *brush_list = NULL;
GError *my_error = NULL;
added vitrual function GimpViewable::get_description() which returns the 2003-04-08 Michael Natterer <mitch@gimp.org> * app/core/gimpviewable.[ch]: added vitrual function GimpViewable::get_description() which returns the string that should be presented to the user plus an optional tooltip with more information. The default implementation just returns the object's name and no tooltip. * app/core/gimpbrush.c * app/core/gimpbuffer.c * app/core/gimpimage.c * app/core/gimppalette.c * app/core/gimppattern.c * app/core/gimptoolinfo.c: implement get_description(). * app/core/gimpimagefile.[ch]: ditto. Renamed gimp_imagefile_get_description() to gimp_imagefile_get_desc_string(). Well, um, gimme a better name... * app/gui/file-open-dialog.c: changed accordingly. * app/file/file-utils.[ch]: renamed readXVThumb() to file_utils_readXVThumb(). * tools/pdbgen/pdb/fileops.pdb: changed accordingly. * app/widgets/widgets-types.h: removed GimpItemGetNameFunc typedef. * app/widgets/gimpcontainerview-utils.[ch]: removed the the actual get_name_funcs. They now live in the core as GimpViewable::get_description() implementations. * app/widgets/gimpcontainermenu.[ch] * app/widgets/gimpcontainergridview.c * app/widgets/gimpcontainermenuimpl.c * app/widgets/gimpcontainertreeview.c * app/widgets/gimpcontainerview.[ch] * app/widgets/gimpmenuitem.[ch] * app/widgets/gimpviewabledialog.c: removed get_name_func stuff and use gimp_viewable_get_description(). * app/widgets/gimpcontainermenu.[ch]: added "preview_border_width" to gimp_container_menu_set_preview_size(). * app/widgets/gimpimagedock.c: changed accordingly. * app/pdb/fileops_cmds.c: regenerated.
2003-04-09 00:01:01 +08:00
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2014-07-04 08:18:52 +08:00
data_input = g_data_input_stream_new (input);
g_data_input_stream_set_byte_order (data_input,
G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN);
abr_hdr.version = abr_read_short (data_input, &my_error);
if (my_error)
goto done;
/* sub-version for ABR v6 */
abr_hdr.count = abr_read_short (data_input, &my_error);
if (my_error)
goto done;
gimprc.in user_install user_install.bat app/gimprc.[ch] removed the 2001-02-13 Michael Natterer <mitch@gimp.org> * gimprc.in * user_install * user_install.bat * app/gimprc.[ch] * app/preferences_dialog.c: removed the "brush_vbr_path" variable, because all data types will be editable and saveable soon. * app/Makefile.am * app/apptypes.h * app/gimpdatafactory.[ch]: new object which holds a data list and knows how to create, edit, duplicate etc. the items in it. Will completely replace the brushes.[ch], patterns.[ch], ... files soon. * po/POTFILES.in * app/gimpdatacontainerview.[ch]: removed. * app/gimpdatafactoryview.[ch]: added. A view on the GimpDataFactory with a GUI for creating, editing, deleting etc. items (mostly unimplemented). * app/context_manager.[ch]: replaced the global data lists by global data factories. * app/brush_select.c * app/brushes.[ch] * app/commands.c * app/convert.c * app/devices.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.c * app/gimpcontext.c * app/gimpdata.[ch] * app/gimpdatalist.[ch] * app/gimpdnd.c * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch] * app/gradient_editor.c * app/gradient_select.c * app/gradients.[ch] * app/indicator_area.c * app/palette.c * app/palette_import.c * app/palette_select.c * app/palettes.[ch] * app/pattern_select.c * app/patterns.[ch] * app/pdb/brush_select_cmds.c * app/pdb/brushes_cmds.c * app/pdb/convert_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/pattern_select_cmds.c * app/pdb/patterns_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly.
2001-02-14 03:53:07 +08:00
if (abr_supported (&abr_hdr, &my_error))
{
switch (abr_hdr.version)
{
case 1:
case 2:
2014-07-04 08:18:52 +08:00
brush_list = gimp_brush_load_abr_v12 (data_input, &abr_hdr,
file, &my_error);
break;
case 6:
2014-07-04 08:18:52 +08:00
brush_list = gimp_brush_load_abr_v6 (data_input, &abr_hdr,
file, &my_error);
break;
}
}
2014-07-04 08:18:52 +08:00
done:
g_object_unref (data_input);
if (! brush_list)
{
if (! my_error)
g_set_error (&my_error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Unable to decode abr format version %d."),
abr_hdr.version);
}
if (my_error)
g_propagate_error (error, my_error);
gimprc.in user_install user_install.bat app/gimprc.[ch] removed the 2001-02-13 Michael Natterer <mitch@gimp.org> * gimprc.in * user_install * user_install.bat * app/gimprc.[ch] * app/preferences_dialog.c: removed the "brush_vbr_path" variable, because all data types will be editable and saveable soon. * app/Makefile.am * app/apptypes.h * app/gimpdatafactory.[ch]: new object which holds a data list and knows how to create, edit, duplicate etc. the items in it. Will completely replace the brushes.[ch], patterns.[ch], ... files soon. * po/POTFILES.in * app/gimpdatacontainerview.[ch]: removed. * app/gimpdatafactoryview.[ch]: added. A view on the GimpDataFactory with a GUI for creating, editing, deleting etc. items (mostly unimplemented). * app/context_manager.[ch]: replaced the global data lists by global data factories. * app/brush_select.c * app/brushes.[ch] * app/commands.c * app/convert.c * app/devices.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.c * app/gimpcontext.c * app/gimpdata.[ch] * app/gimpdatalist.[ch] * app/gimpdnd.c * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch] * app/gradient_editor.c * app/gradient_select.c * app/gradients.[ch] * app/indicator_area.c * app/palette.c * app/palette_import.c * app/palette_select.c * app/palettes.[ch] * app/pattern_select.c * app/patterns.[ch] * app/pdb/brush_select_cmds.c * app/pdb/brushes_cmds.c * app/pdb/convert_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/pattern_select_cmds.c * app/pdb/patterns_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly.
2001-02-14 03:53:07 +08:00
return g_list_reverse (brush_list);
}
gimprc.in user_install user_install.bat app/gimprc.[ch] removed the 2001-02-13 Michael Natterer <mitch@gimp.org> * gimprc.in * user_install * user_install.bat * app/gimprc.[ch] * app/preferences_dialog.c: removed the "brush_vbr_path" variable, because all data types will be editable and saveable soon. * app/Makefile.am * app/apptypes.h * app/gimpdatafactory.[ch]: new object which holds a data list and knows how to create, edit, duplicate etc. the items in it. Will completely replace the brushes.[ch], patterns.[ch], ... files soon. * po/POTFILES.in * app/gimpdatacontainerview.[ch]: removed. * app/gimpdatafactoryview.[ch]: added. A view on the GimpDataFactory with a GUI for creating, editing, deleting etc. items (mostly unimplemented). * app/context_manager.[ch]: replaced the global data lists by global data factories. * app/brush_select.c * app/brushes.[ch] * app/commands.c * app/convert.c * app/devices.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.c * app/gimpcontext.c * app/gimpdata.[ch] * app/gimpdatalist.[ch] * app/gimpdnd.c * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch] * app/gradient_editor.c * app/gradient_select.c * app/gradients.[ch] * app/indicator_area.c * app/palette.c * app/palette_import.c * app/palette_select.c * app/palettes.[ch] * app/pattern_select.c * app/patterns.[ch] * app/pdb/brush_select_cmds.c * app/pdb/brushes_cmds.c * app/pdb/convert_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/pattern_select_cmds.c * app/pdb/patterns_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly.
2001-02-14 03:53:07 +08:00
/* private functions */
static GList *
2014-07-04 08:18:52 +08:00
gimp_brush_load_abr_v12 (GDataInputStream *input,
AbrHeader *abr_hdr,
GFile *file,
GError **error)
{
GList *brush_list = NULL;
gint i;
for (i = 0; i < abr_hdr->count; i++)
{
GimpBrush *brush;
GError *my_error = NULL;
2014-07-04 08:18:52 +08:00
brush = gimp_brush_load_abr_brush_v12 (input, abr_hdr, i,
file, &my_error);
/* a NULL brush without an error means an unsupported brush
* type was encountered, silently skip it and try the next one
*/
if (brush)
{
brush_list = g_list_prepend (brush_list, brush);
}
else if (my_error)
{
g_propagate_error (error, my_error);
break;
}
}
return brush_list;
}
static GList *
2014-07-04 08:18:52 +08:00
gimp_brush_load_abr_v6 (GDataInputStream *input,
AbrHeader *abr_hdr,
GFile *file,
GError **error)
{
2014-07-04 08:18:52 +08:00
GList *brush_list = NULL;
gint32 sample_section_size;
goffset sample_section_end;
gint i = 1;
if (! abr_reach_8bim_section (input, "samp", error))
return brush_list;
2014-07-04 08:18:52 +08:00
sample_section_size = abr_read_long (input, error);
if (error && *error)
return brush_list;
2014-07-04 08:18:52 +08:00
sample_section_end = (sample_section_size +
g_seekable_tell (G_SEEKABLE (input)));
2014-07-04 08:18:52 +08:00
while (g_seekable_tell (G_SEEKABLE (input)) < sample_section_end)
{
GimpBrush *brush;
GError *my_error = NULL;
2014-07-04 08:18:52 +08:00
brush = gimp_brush_load_abr_brush_v6 (input, abr_hdr, sample_section_end,
i, file, &my_error);
/* a NULL brush without an error means an unsupported brush
* type was encountered, silently skip it and try the next one
*/
if (brush)
{
brush_list = g_list_prepend (brush_list, brush);
}
else if (my_error)
{
g_propagate_error (error, my_error);
break;
}
i++;
}
return brush_list;
}
static GimpBrush *
2014-07-04 08:18:52 +08:00
gimp_brush_load_abr_brush_v12 (GDataInputStream *input,
AbrHeader *abr_hdr,
gint index,
GFile *file,
GError **error)
{
GimpBrush *brush = NULL;
AbrBrushHeader abr_brush_hdr;
2014-07-04 08:18:52 +08:00
abr_brush_hdr.type = abr_read_short (input, error);
if (error && *error)
return NULL;
abr_brush_hdr.size = abr_read_long (input, error);
if (error && *error)
return NULL;
if (abr_brush_hdr.size < 0)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: "
"Brush size value corrupt."));
return NULL;
}
/* g_print(" + BRUSH\n | << type: %i block size: %i bytes\n",
* abr_brush_hdr.type, abr_brush_hdr.size);
*/
switch (abr_brush_hdr.type)
{
case 1: /* computed brush */
/* FIXME: support it!
*
* We can probabaly feed the info into the generated brush code
* and get a usable brush back. It seems to support the same
* types -akl
*/
g_printerr ("WARNING: computed brush unsupported, skipping.\n");
2014-07-04 08:18:52 +08:00
g_seekable_seek (G_SEEKABLE (input), abr_brush_hdr.size,
G_SEEK_CUR, NULL, NULL);
break;
case 2: /* sampled brush */
{
AbrSampledBrushHeader abr_sampled_brush_hdr;
gint width, height;
gint bytes;
gint size;
guchar *mask;
gint i;
gchar *name;
gchar *sample_name = NULL;
gchar *tmp;
gshort compress;
2014-07-04 08:18:52 +08:00
abr_sampled_brush_hdr.misc = abr_read_long (input, error);
if (error && *error)
break;
abr_sampled_brush_hdr.spacing = abr_read_short (input, error);
if (error && *error)
break;
if (abr_hdr->version == 2)
2014-07-04 08:18:52 +08:00
{
sample_name = abr_read_ucs2_text (input, error);
if (error && *error)
break;
}
2014-07-04 08:18:52 +08:00
abr_sampled_brush_hdr.antialiasing = abr_read_char (input, error);
if (error && *error)
break;
for (i = 0; i < 4; i++)
2014-07-04 08:18:52 +08:00
{
abr_sampled_brush_hdr.bounds[i] = abr_read_short (input, error);
if (error && *error)
break;
}
for (i = 0; i < 4; i++)
2014-07-04 08:18:52 +08:00
{
abr_sampled_brush_hdr.bounds_long[i] = abr_read_long (input, error);
if (error && *error)
break;
}
2014-07-04 08:18:52 +08:00
abr_sampled_brush_hdr.depth = abr_read_short (input, error);
if (error && *error)
break;
height = (abr_sampled_brush_hdr.bounds_long[2] -
abr_sampled_brush_hdr.bounds_long[0]); /* bottom - top */
width = (abr_sampled_brush_hdr.bounds_long[3] -
abr_sampled_brush_hdr.bounds_long[1]); /* right - left */
bytes = abr_sampled_brush_hdr.depth >> 3;
/* g_print ("width %i height %i bytes %i\n", width, height, bytes); */
if (width < 1 || width > 10000 ||
height < 1 || height > 10000 ||
bytes < 1 || bytes > 1 ||
G_MAXSIZE / width / height / bytes < 1)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: "
"Brush dimensions out of range."));
break;
}
abr_sampled_brush_hdr.wide = height > 16384;
if (abr_sampled_brush_hdr.wide)
{
/* FIXME: support wide brushes */
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: "
"Wide brushes are not supported."));
2014-07-04 08:18:52 +08:00
break;
}
tmp = g_path_get_basename (gimp_file_get_utf8_name (file));
if (! sample_name)
{
/* build name from filename and index */
name = g_strdup_printf ("%s-%03d", tmp, index);
}
else
{
/* build name from filename and sample name */
name = g_strdup_printf ("%s-%s", tmp, sample_name);
g_free (sample_name);
}
g_free (tmp);
brush = g_object_new (GIMP_TYPE_BRUSH,
"name", name,
/* FIXME: MIME type!! */
"mime-type", "application/x-photoshop-abr",
NULL);
g_free (name);
brush->priv->spacing = abr_sampled_brush_hdr.spacing;
brush->priv->x_axis.x = width / 2.0;
brush->priv->x_axis.y = 0.0;
brush->priv->y_axis.x = 0.0;
brush->priv->y_axis.y = height / 2.0;
brush->priv->mask = gimp_temp_buf_new (width, height,
babl_format ("Y u8"));
mask = gimp_temp_buf_get_data (brush->priv->mask);
size = width * height * bytes;
2014-07-04 08:18:52 +08:00
compress = abr_read_char (input, error);
if (error && *error)
{
g_object_unref (brush);
brush = NULL;
break;
}
/* g_print(" | << size: %dx%d %d bit (%d bytes) %s\n",
* width, height, abr_sampled_brush_hdr.depth, size,
* comppres ? "compressed" : "raw");
*/
if (! compress)
2014-07-04 08:18:52 +08:00
{
gsize bytes_read;
if (! g_input_stream_read_all (G_INPUT_STREAM (input),
mask, size,
&bytes_read, NULL, error) ||
bytes_read != size)
{
g_object_unref (brush);
brush = NULL;
break;
}
}
else
2014-07-04 08:18:52 +08:00
{
if (! abr_rle_decode (input, (gchar *) mask, size, height, error))
2014-07-04 08:18:52 +08:00
{
g_object_unref (brush);
brush = NULL;
break;
}
}
}
break;
default:
g_printerr ("WARNING: unknown brush type, skipping.\n");
2014-07-04 08:18:52 +08:00
g_seekable_seek (G_SEEKABLE (input), abr_brush_hdr.size,
G_SEEK_CUR, NULL, NULL);
break;
}
return brush;
}
static GimpBrush *
2014-07-04 08:18:52 +08:00
gimp_brush_load_abr_brush_v6 (GDataInputStream *input,
AbrHeader *abr_hdr,
gint32 max_offset,
gint index,
GFile *file,
GError **error)
{
GimpBrush *brush = NULL;
guchar *mask;
gint32 brush_size;
gint32 brush_end;
2014-07-04 08:18:52 +08:00
goffset next_brush;
gint32 top, left, bottom, right;
gint16 depth;
gchar compress;
gint32 width, height;
gint32 size;
gchar *tmp;
gchar *name;
2014-07-04 08:18:52 +08:00
gboolean r;
brush_size = abr_read_long (input, error);
if (error && *error)
return NULL;
if (brush_size < 0)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: "
"Brush size value corrupt."));
return NULL;
}
brush_end = brush_size;
/* complement to 4 */
while (brush_end % 4 != 0)
brush_end++;
2014-07-04 08:18:52 +08:00
next_brush = (brush_end + g_seekable_tell (G_SEEKABLE (input)));
if (abr_hdr->count == 1)
2014-07-04 08:18:52 +08:00
{
/* discard key and short coordinates and unknown short */
r = g_seekable_seek (G_SEEKABLE (input), 47, G_SEEK_CUR,
NULL, error);
}
else
2014-07-04 08:18:52 +08:00
{
/* discard key and unknown bytes */
r = g_seekable_seek (G_SEEKABLE (input), 301, G_SEEK_CUR,
NULL, error);
}
2014-07-04 08:18:52 +08:00
if (! r)
{
2014-07-04 08:18:52 +08:00
g_prefix_error (error,
2015-12-01 19:25:15 +08:00
_("Fatal parse error in brush file: "
"File appears truncated: "));
return NULL;
}
2014-07-04 08:18:52 +08:00
top = abr_read_long (input, error); if (error && *error) return NULL;
left = abr_read_long (input, error); if (error && *error) return NULL;
bottom = abr_read_long (input, error); if (error && *error) return NULL;
right = abr_read_long (input, error); if (error && *error) return NULL;
depth = abr_read_short (input, error); if (error && *error) return NULL;
compress = abr_read_char (input, error); if (error && *error) return NULL;
depth = depth >> 3;
width = right - left;
height = bottom - top;
size = width * depth * height;
#if 0
g_printerr ("width %i height %i depth %i compress %i\n",
width, height, depth, compress);
#endif
if (width < 1 || width > 10000 ||
height < 1 || height > 10000 ||
depth < 1 || depth > 1 ||
G_MAXSIZE / width / height / depth < 1)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: "
"Brush dimensions out of range."));
return NULL;
}
if (compress < 0 || compress > 1)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: "
"Unknown compression method."));
return NULL;
}
tmp = g_path_get_basename (gimp_file_get_utf8_name (file));
name = g_strdup_printf ("%s-%03d", tmp, index);
g_free (tmp);
brush = g_object_new (GIMP_TYPE_BRUSH,
"name", name,
/* FIXME: MIME type!! */
"mime-type", "application/x-photoshop-abr",
NULL);
g_free (name);
brush->priv->spacing = 25; /* real value needs 8BIMdesc section parser */
brush->priv->x_axis.x = width / 2.0;
brush->priv->x_axis.y = 0.0;
brush->priv->y_axis.x = 0.0;
brush->priv->y_axis.y = height / 2.0;
brush->priv->mask = gimp_temp_buf_new (width, height,
babl_format ("Y u8"));
mask = gimp_temp_buf_get_data (brush->priv->mask);
/* data decoding */
if (! compress)
2014-07-04 08:18:52 +08:00
{
/* not compressed - read raw bytes as brush data */
gsize bytes_read;
if (! g_input_stream_read_all (G_INPUT_STREAM (input),
mask, size,
&bytes_read, NULL, error) ||
bytes_read != size)
{
g_object_unref (brush);
return NULL;
}
}
else
2014-07-04 08:18:52 +08:00
{
if (! abr_rle_decode (input, (gchar *) mask, size, height, error))
2014-07-04 08:18:52 +08:00
{
g_object_unref (brush);
return NULL;
}
}
if (g_seekable_tell (G_SEEKABLE (input)) <= next_brush)
g_seekable_seek (G_SEEKABLE (input), next_brush, G_SEEK_SET,
NULL, NULL);
Jens Lautenbacher <jtl@gimp.org> 2000-12-18 Sven Neumann <sven@gimp.org> Jens Lautenbacher <jtl@gimp.org> * app/Makefile.am * app/gimpbrushlistP.h * app/gimpbrushpipeP.h * app/gimpobjectP.h: removed these three files * app/parasitelistP.h * app/channels_dialog.c * app/docindex.c * app/gimpdrawable.c * app/gimpdrawableP.h * app/gimpimage.c * app/gimpimageP.h * app/gimplist.[ch] * app/gimpobject.c * app/gimpobject.h * app/gimpsetP.h: changed according to header removal * app/airbrush.c * app/brush_select.[ch] * app/brushes_cmds.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushlist.[ch] * app/gimpbrushpipe.[ch] * app/gimpcontextpreview.c * app/paint_core.c * app/paintbrush.c * app/pencil.c * tools/pdbgen/pdb/brushes.pdb: Big Brushes Cleanup. The GimpBrush* object hierarchy and the file formats were broken by "design". This made it overly difficult to read and write pixmap brushes and brush pipes, leading to the situation that The GIMP was not able to read it's very own file formats. Since the GimpBrush format did support arbitrary color depths, the introduction of a file format for pixmap brushes was unnecessary. The GimpBrushPixmap object is dead. GimpBrush has an additional pixmap temp_buf and handles pixmap brushes transparently. The file format of pixmap brushes is not any longer a grayscale brush plus a pattern, but a simple brush with RGBA data. The old brushes can still be loaded, but the .gpb format is deprecated. GimpBrushPipe derives from GimpBrush. The fileformat is still a text header, followed by a number of brushes, but those brushes are stored in the new GimpBrush format (no pattern anymore). The pipe does not care about the depth of the contained GimpBrushes, so we get grayscale BrushPipes for free. Since the brush loader still loads the old format, old .gih files can also still be loaded. Since the brushes in the GimpBrushPipe do not any longer contain a pointer to the pipe object, we do only temporarily switch brushes in the paint_core routines. This is not very elegant, but the best we can do without a major redesign. * app/patterns.[ch]: changed the loader to work with a filedescriptor instead of a filehandle to make it work with the new brush loading code. * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/common/gih.c: new plug-in that saves GIH files in the new format (loader will follow soon) * plug-ins/common/gpb.c: removed since Pixmap Brushes are no longer supported as a special file format. * plug-ins/common/gbr.c: load and save brushes in the new brush format which allows RGBA brushes too. * plug-ins/common/pat.c: load and save grayscale patterns too
2000-12-18 23:14:08 +08:00
return brush;
Jens Lautenbacher <jtl@gimp.org> 2000-12-18 Sven Neumann <sven@gimp.org> Jens Lautenbacher <jtl@gimp.org> * app/Makefile.am * app/gimpbrushlistP.h * app/gimpbrushpipeP.h * app/gimpobjectP.h: removed these three files * app/parasitelistP.h * app/channels_dialog.c * app/docindex.c * app/gimpdrawable.c * app/gimpdrawableP.h * app/gimpimage.c * app/gimpimageP.h * app/gimplist.[ch] * app/gimpobject.c * app/gimpobject.h * app/gimpsetP.h: changed according to header removal * app/airbrush.c * app/brush_select.[ch] * app/brushes_cmds.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushlist.[ch] * app/gimpbrushpipe.[ch] * app/gimpcontextpreview.c * app/paint_core.c * app/paintbrush.c * app/pencil.c * tools/pdbgen/pdb/brushes.pdb: Big Brushes Cleanup. The GimpBrush* object hierarchy and the file formats were broken by "design". This made it overly difficult to read and write pixmap brushes and brush pipes, leading to the situation that The GIMP was not able to read it's very own file formats. Since the GimpBrush format did support arbitrary color depths, the introduction of a file format for pixmap brushes was unnecessary. The GimpBrushPixmap object is dead. GimpBrush has an additional pixmap temp_buf and handles pixmap brushes transparently. The file format of pixmap brushes is not any longer a grayscale brush plus a pattern, but a simple brush with RGBA data. The old brushes can still be loaded, but the .gpb format is deprecated. GimpBrushPipe derives from GimpBrush. The fileformat is still a text header, followed by a number of brushes, but those brushes are stored in the new GimpBrush format (no pattern anymore). The pipe does not care about the depth of the contained GimpBrushes, so we get grayscale BrushPipes for free. Since the brush loader still loads the old format, old .gih files can also still be loaded. Since the brushes in the GimpBrushPipe do not any longer contain a pointer to the pipe object, we do only temporarily switch brushes in the paint_core routines. This is not very elegant, but the best we can do without a major redesign. * app/patterns.[ch]: changed the loader to work with a filedescriptor instead of a filehandle to make it work with the new brush loading code. * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/common/gih.c: new plug-in that saves GIH files in the new format (loader will follow soon) * plug-ins/common/gpb.c: removed since Pixmap Brushes are no longer supported as a special file format. * plug-ins/common/gbr.c: load and save brushes in the new brush format which allows RGBA brushes too. * plug-ins/common/pat.c: load and save grayscale patterns too
2000-12-18 23:14:08 +08:00
}
static gchar
2014-07-04 08:18:52 +08:00
abr_read_char (GDataInputStream *input,
GError **error)
First version of per-tool paint options. No PDB interface yet. The tool 1999-04-22 Michael Natterer <mitschel@cs.tu-berlin.de> First version of per-tool paint options. No PDB interface yet. The tool options dialog got rather big when in per-tool mode, so it will probably have to become a notebook. It's not yet 100% consistent. If switched off, everything should behave exactly like before. * app/Makefile.am * app/paint_options.h: new file * app/tool_options.c: PaintOptions gui. Maintain a list of all paint tools' ToolOptions to enable switching between global and per-tool paint options. * app/brush_select.[ch]: changed packing boxes, tables, ... The paint options in the brush selection can be hidden now. Moved create_paint_mode_menu() to paint_options.h and tool_options.c and renamed it to paint_mode_menu_new(). * app/gimage_mask.c * app/gimpbrush.[ch] * app/gimpbrushlist.[ch] * app/paint_core.c: moved gimp_brush_[set|get]_spacing() from gimpbrushlist.[ch] to gimpbrush.[ch]. Moved gimp_brush_[get|set]_[opacity|paint_mode]() to paint_options.h and tool_options.c and renamed them to paint_options_*_*(). They are "global paint options" now. * app/airbrush.c * app/blend.c * app/bucket_fill.c * app/clone.c * app/convolve.c * app/eraser.c * app/ink.c * app/paintbrush.c * app/pencil.c: all paint tools' options are derived from "PaintOptions" now. Opacity and paint mode are obtained through macros which take into account the current paint options mode. * app/buildmenu.h: #include <gtk/gtk.h> * app/color_picker.c * app/text_tool.c: changed spacings. * app/gimprc.[ch]: new gimprc option "global-paint-options" * app/preferences_dialog.c: Added a "Tool Options" page. Code cleanup. Some work on the convenience constructors test site. * app/tools.c: fixed "unused variable" warning.
1999-04-22 22:34:00 +08:00
{
2014-07-04 08:18:52 +08:00
return g_data_input_stream_read_byte (input, NULL, error);
First version of per-tool paint options. No PDB interface yet. The tool 1999-04-22 Michael Natterer <mitschel@cs.tu-berlin.de> First version of per-tool paint options. No PDB interface yet. The tool options dialog got rather big when in per-tool mode, so it will probably have to become a notebook. It's not yet 100% consistent. If switched off, everything should behave exactly like before. * app/Makefile.am * app/paint_options.h: new file * app/tool_options.c: PaintOptions gui. Maintain a list of all paint tools' ToolOptions to enable switching between global and per-tool paint options. * app/brush_select.[ch]: changed packing boxes, tables, ... The paint options in the brush selection can be hidden now. Moved create_paint_mode_menu() to paint_options.h and tool_options.c and renamed it to paint_mode_menu_new(). * app/gimage_mask.c * app/gimpbrush.[ch] * app/gimpbrushlist.[ch] * app/paint_core.c: moved gimp_brush_[set|get]_spacing() from gimpbrushlist.[ch] to gimpbrush.[ch]. Moved gimp_brush_[get|set]_[opacity|paint_mode]() to paint_options.h and tool_options.c and renamed them to paint_options_*_*(). They are "global paint options" now. * app/airbrush.c * app/blend.c * app/bucket_fill.c * app/clone.c * app/convolve.c * app/eraser.c * app/ink.c * app/paintbrush.c * app/pencil.c: all paint tools' options are derived from "PaintOptions" now. Opacity and paint mode are obtained through macros which take into account the current paint options mode. * app/buildmenu.h: #include <gtk/gtk.h> * app/color_picker.c * app/text_tool.c: changed spacings. * app/gimprc.[ch]: new gimprc option "global-paint-options" * app/preferences_dialog.c: Added a "Tool Options" page. Code cleanup. Some work on the convenience constructors test site. * app/tools.c: fixed "unused variable" warning.
1999-04-22 22:34:00 +08:00
}
static gint16
2014-07-04 08:18:52 +08:00
abr_read_short (GDataInputStream *input,
GError **error)
First version of per-tool paint options. No PDB interface yet. The tool 1999-04-22 Michael Natterer <mitschel@cs.tu-berlin.de> First version of per-tool paint options. No PDB interface yet. The tool options dialog got rather big when in per-tool mode, so it will probably have to become a notebook. It's not yet 100% consistent. If switched off, everything should behave exactly like before. * app/Makefile.am * app/paint_options.h: new file * app/tool_options.c: PaintOptions gui. Maintain a list of all paint tools' ToolOptions to enable switching between global and per-tool paint options. * app/brush_select.[ch]: changed packing boxes, tables, ... The paint options in the brush selection can be hidden now. Moved create_paint_mode_menu() to paint_options.h and tool_options.c and renamed it to paint_mode_menu_new(). * app/gimage_mask.c * app/gimpbrush.[ch] * app/gimpbrushlist.[ch] * app/paint_core.c: moved gimp_brush_[set|get]_spacing() from gimpbrushlist.[ch] to gimpbrush.[ch]. Moved gimp_brush_[get|set]_[opacity|paint_mode]() to paint_options.h and tool_options.c and renamed them to paint_options_*_*(). They are "global paint options" now. * app/airbrush.c * app/blend.c * app/bucket_fill.c * app/clone.c * app/convolve.c * app/eraser.c * app/ink.c * app/paintbrush.c * app/pencil.c: all paint tools' options are derived from "PaintOptions" now. Opacity and paint mode are obtained through macros which take into account the current paint options mode. * app/buildmenu.h: #include <gtk/gtk.h> * app/color_picker.c * app/text_tool.c: changed spacings. * app/gimprc.[ch]: new gimprc option "global-paint-options" * app/preferences_dialog.c: Added a "Tool Options" page. Code cleanup. Some work on the convenience constructors test site. * app/tools.c: fixed "unused variable" warning.
1999-04-22 22:34:00 +08:00
{
2014-07-04 08:18:52 +08:00
return g_data_input_stream_read_int16 (input, NULL, error);
removed GimpFillType. 2001-06-29 Michael Natterer <mitch@gimp.org> * app/appenums.h: removed GimpFillType. * app/gimprc.c: parse the session-info's new "aux-info" field. * app/global_edit.[ch]: removed the old "Paste Named" dialog and prefixed all functions with "gimp_". * app/core/core-types.h: added GimpFillType. * app/core/gimpbrush.[ch]: new signal "spacing_changed". * app/gui/Makefile.am * app/gui/tools-commands.[ch]: one more file cut out of commands.[ch]. * app/gui/commands.[ch]: removed the tools stuff here. * app/gui/brush-select.[ch] * app/gui/dialogs-constructors.c: use the new GimpBrushFactoryView (see below). * app/gui/dialogs-commands.[ch] * app/gui/menus.[ch]: - Made it 64bit safe again by passing the dialog factory's identifiers as GQuarks, not as guints created by GPOINTER_TO_UINT(). - Added a "gchar *quark_string" field to GimpItemFactoryEntry which gets transformed into a GQuark by menus_create_item(). - Added SEPARATOR() and BRANCH() macros which make the *_entries[] arrays more readable. - Added a menu item to show/hide GimpImageDock's image menu. - Removed file_last_opened_cmd_callback(). * app/gui/edit-commands.c: the global_edit functions are "gimp_" prefixed now. * app/gui/file-commands.[ch]: added file_last_opened_cmd_callback() here. * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpbrushfactoryview.[ch]: new widget: a GimpDataFactory subclass with a "spacing" scale. * app/widgets/gimpcontainereditor.[ch]: - Connect to the GimpContainerView's "select_item", "activate_item" and "context_item" signals here once instead of in each subclass and dispatch them via new virtual functions. - Added a convenience function which makes DND to the buttons much less painful for subclasses. * app/widgets/gimpbufferview.c * app/widgets/gimpdatafactoryview.[ch]: changed accordingly. * app/widgets/gimpdialogfactory.[ch]: - Added gimp_dialog_factory_dialog_raise() which can raise toplevel dialogs _and_ dockables (and creates them if they are not open yet). - Keep track of all created dialogs (not only toplevels). - Added an "aux_info" field to GimpSessionInfo which is a GList of gchar* and is saved in sessionrc. - Remember if GimpImageDock's image menu is visible by using an aux_info string. - The code did not become nicer with all those new constraints. I have to add comments before I forget how it works. * app/widgets/gimpdockbook.c: set the state of the "Show Image Menu" menu item before popping up the item factory. * app/widgets/gimpimagedock.[ch]: added gimp_image_dock_set_show_image_meu(). * plug-ins/gdyntext/gdyntext.c * plug-ins/perl/examples/fit-text * plug-ins/perl/examples/terral_text * plug-ins/perl/examples/tex-to-float: register all text rendering plug-ins under <Image>/Filters/Text * app/pdb/brush_select_cmds.c * app/pdb/drawable_cmds.c * app/pdb/edit_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/edit.pdb * tools/pdbgen/enums.pl * po/POTFILES.in: changed according to all the stuff above.
2001-06-30 03:25:03 +08:00
}
static gint32
2014-07-04 08:18:52 +08:00
abr_read_long (GDataInputStream *input,
GError **error)
removed GimpFillType. 2001-06-29 Michael Natterer <mitch@gimp.org> * app/appenums.h: removed GimpFillType. * app/gimprc.c: parse the session-info's new "aux-info" field. * app/global_edit.[ch]: removed the old "Paste Named" dialog and prefixed all functions with "gimp_". * app/core/core-types.h: added GimpFillType. * app/core/gimpbrush.[ch]: new signal "spacing_changed". * app/gui/Makefile.am * app/gui/tools-commands.[ch]: one more file cut out of commands.[ch]. * app/gui/commands.[ch]: removed the tools stuff here. * app/gui/brush-select.[ch] * app/gui/dialogs-constructors.c: use the new GimpBrushFactoryView (see below). * app/gui/dialogs-commands.[ch] * app/gui/menus.[ch]: - Made it 64bit safe again by passing the dialog factory's identifiers as GQuarks, not as guints created by GPOINTER_TO_UINT(). - Added a "gchar *quark_string" field to GimpItemFactoryEntry which gets transformed into a GQuark by menus_create_item(). - Added SEPARATOR() and BRANCH() macros which make the *_entries[] arrays more readable. - Added a menu item to show/hide GimpImageDock's image menu. - Removed file_last_opened_cmd_callback(). * app/gui/edit-commands.c: the global_edit functions are "gimp_" prefixed now. * app/gui/file-commands.[ch]: added file_last_opened_cmd_callback() here. * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpbrushfactoryview.[ch]: new widget: a GimpDataFactory subclass with a "spacing" scale. * app/widgets/gimpcontainereditor.[ch]: - Connect to the GimpContainerView's "select_item", "activate_item" and "context_item" signals here once instead of in each subclass and dispatch them via new virtual functions. - Added a convenience function which makes DND to the buttons much less painful for subclasses. * app/widgets/gimpbufferview.c * app/widgets/gimpdatafactoryview.[ch]: changed accordingly. * app/widgets/gimpdialogfactory.[ch]: - Added gimp_dialog_factory_dialog_raise() which can raise toplevel dialogs _and_ dockables (and creates them if they are not open yet). - Keep track of all created dialogs (not only toplevels). - Added an "aux_info" field to GimpSessionInfo which is a GList of gchar* and is saved in sessionrc. - Remember if GimpImageDock's image menu is visible by using an aux_info string. - The code did not become nicer with all those new constraints. I have to add comments before I forget how it works. * app/widgets/gimpdockbook.c: set the state of the "Show Image Menu" menu item before popping up the item factory. * app/widgets/gimpimagedock.[ch]: added gimp_image_dock_set_show_image_meu(). * plug-ins/gdyntext/gdyntext.c * plug-ins/perl/examples/fit-text * plug-ins/perl/examples/terral_text * plug-ins/perl/examples/tex-to-float: register all text rendering plug-ins under <Image>/Filters/Text * app/pdb/brush_select_cmds.c * app/pdb/drawable_cmds.c * app/pdb/edit_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/edit.pdb * tools/pdbgen/enums.pl * po/POTFILES.in: changed according to all the stuff above.
2001-06-30 03:25:03 +08:00
{
2014-07-04 08:18:52 +08:00
return g_data_input_stream_read_int32 (input, NULL, error);
First version of per-tool paint options. No PDB interface yet. The tool 1999-04-22 Michael Natterer <mitschel@cs.tu-berlin.de> First version of per-tool paint options. No PDB interface yet. The tool options dialog got rather big when in per-tool mode, so it will probably have to become a notebook. It's not yet 100% consistent. If switched off, everything should behave exactly like before. * app/Makefile.am * app/paint_options.h: new file * app/tool_options.c: PaintOptions gui. Maintain a list of all paint tools' ToolOptions to enable switching between global and per-tool paint options. * app/brush_select.[ch]: changed packing boxes, tables, ... The paint options in the brush selection can be hidden now. Moved create_paint_mode_menu() to paint_options.h and tool_options.c and renamed it to paint_mode_menu_new(). * app/gimage_mask.c * app/gimpbrush.[ch] * app/gimpbrushlist.[ch] * app/paint_core.c: moved gimp_brush_[set|get]_spacing() from gimpbrushlist.[ch] to gimpbrush.[ch]. Moved gimp_brush_[get|set]_[opacity|paint_mode]() to paint_options.h and tool_options.c and renamed them to paint_options_*_*(). They are "global paint options" now. * app/airbrush.c * app/blend.c * app/bucket_fill.c * app/clone.c * app/convolve.c * app/eraser.c * app/ink.c * app/paintbrush.c * app/pencil.c: all paint tools' options are derived from "PaintOptions" now. Opacity and paint mode are obtained through macros which take into account the current paint options mode. * app/buildmenu.h: #include <gtk/gtk.h> * app/color_picker.c * app/text_tool.c: changed spacings. * app/gimprc.[ch]: new gimprc option "global-paint-options" * app/preferences_dialog.c: Added a "Tool Options" page. Code cleanup. Some work on the convenience constructors test site. * app/tools.c: fixed "unused variable" warning.
1999-04-22 22:34:00 +08:00
}
static gchar *
2014-07-04 08:18:52 +08:00
abr_read_ucs2_text (GDataInputStream *input,
GError **error)
{
gchar *name_ucs2;
gchar *name_utf8;
gint len;
gint i;
/* two-bytes characters encoded (UCS-2)
* format:
* long : number of characters in string
* data : zero terminated UCS-2 string
*/
2014-07-04 08:18:52 +08:00
len = 2 * abr_read_long (input, error);
if (len <= 0)
return NULL;
name_ucs2 = g_new (gchar, len);
for (i = 0; i < len; i++)
2014-07-04 08:18:52 +08:00
{
name_ucs2[i] = abr_read_char (input, error);
if (error && *error)
{
g_free (name_ucs2);
return NULL;
}
}
name_utf8 = g_convert (name_ucs2, len,
"UTF-8", "UCS-2BE",
NULL, NULL, NULL);
g_free (name_ucs2);
return name_utf8;
}
static gboolean
abr_supported (AbrHeader *abr_hdr,
GError **error)
{
switch (abr_hdr->version)
{
case 1:
case 2:
return TRUE;
break;
case 6:
/* in this case, count contains format sub-version */
if (abr_hdr->count == 1 || abr_hdr->count == 2)
return TRUE;
2014-07-04 08:18:52 +08:00
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: "
"Unable to decode abr format version %d."),
2014-07-04 08:18:52 +08:00
/* horrid subversion display, but better than
* having yet another translatable string for
* this
*/
abr_hdr->version * 10 + abr_hdr->count);
break;
}
return FALSE;
}
static gboolean
2014-07-04 08:18:52 +08:00
abr_reach_8bim_section (GDataInputStream *input,
const gchar *name,
GError **error)
{
2014-07-04 08:18:52 +08:00
while (TRUE)
{
gchar tag[4];
gchar tagname[5];
guint32 section_size;
gsize bytes_read;
2014-07-04 08:18:52 +08:00
if (! g_input_stream_read_all (G_INPUT_STREAM (input),
tag, 4,
&bytes_read, NULL, error) ||
bytes_read != 4)
return FALSE;
if (strncmp (tag, "8BIM", 4))
return FALSE;
2014-07-04 08:18:52 +08:00
if (! g_input_stream_read_all (G_INPUT_STREAM (input),
tagname, 4,
&bytes_read, NULL, error) ||
bytes_read != 4)
return FALSE;
tagname[4] = '\0';
if (! strncmp (tagname, name, 4))
return TRUE;
2014-07-04 08:18:52 +08:00
section_size = abr_read_long (input, error);
if (error && *error)
return FALSE;
if (! g_seekable_seek (G_SEEKABLE (input), section_size, G_SEEK_CUR,
NULL, error))
return FALSE;
}
return FALSE;
}
2014-07-04 08:18:52 +08:00
static gboolean
abr_rle_decode (GDataInputStream *input,
gchar *buffer,
gsize buffer_size,
2014-07-04 08:18:52 +08:00
gint32 height,
GError **error)
{
gchar ch;
gint i, j, c;
gshort *cscanline_len;
gchar *data = buffer;
/* read compressed size foreach scanline */
cscanline_len = g_new0 (gshort, height);
for (i = 0; i < height; i++)
2014-07-04 08:18:52 +08:00
{
cscanline_len[i] = abr_read_short (input, error);
if (error && *error)
{
g_free (cscanline_len);
return FALSE;
}
}
/* unpack each scanline data */
for (i = 0; i < height; i++)
{
for (j = 0; j < cscanline_len[i];)
{
2014-07-04 08:18:52 +08:00
gint32 n = abr_read_char (input, error);
if (error && *error)
{
g_free (cscanline_len);
return FALSE;
}
j++;
if (n >= 128) /* force sign */
n -= 256;
if (n < 0)
{
/* copy the following char -n + 1 times */
if (n == -128) /* it's a nop */
continue;
n = -n + 1;
2014-07-04 08:18:52 +08:00
ch = abr_read_char (input, error);
if (error && *error)
{
g_free (cscanline_len);
return FALSE;
}
j++;
for (c = 0; c < n; c++, data++)
{
if (data >= buffer + buffer_size)
{
g_free (cscanline_len);
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: "
"RLE compressed brush data corrupt."));
return FALSE;
}
*data = ch;
}
}
else
{
/* read the following n + 1 chars (no compr) */
for (c = 0; c < n + 1; c++, j++, data++)
2014-07-04 08:18:52 +08:00
{
if (data >= buffer + buffer_size)
{
g_free (cscanline_len);
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file: "
"RLE compressed brush data corrupt."));
return FALSE;
}
2014-07-04 08:18:52 +08:00
*data = abr_read_char (input, error);
if (error && *error)
{
g_free (cscanline_len);
return FALSE;
}
}
}
}
}
g_free (cscanline_len);
2014-07-04 08:18:52 +08:00
return TRUE;
}