1
0
Fork 0

Adding upstream version 3.0.4.

Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
This commit is contained in:
Daniel Baumann 2025-06-23 00:14:50 +02:00
parent 1c8b56a4f5
commit 554424e00a
Signed by: daniel.baumann
GPG key ID: BCC918A2ABD66424
6822 changed files with 5440542 additions and 0 deletions

View file

@ -0,0 +1,80 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpbase-private.c
* Copyright (C) 2003 Sven Neumann <sven@gimp.org>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gio/gio.h>
#include "gimpbasetypes.h"
#include "gimpbase-private.h"
#include "gimpcompatenums.h"
GHashTable *_gimp_units = NULL;
GimpUnitVtable _gimp_unit_vtable = { NULL, };
void
gimp_base_init (GimpUnitVtable *vtable)
{
static gboolean gimp_base_initialized = FALSE;
g_return_if_fail (vtable != NULL);
if (gimp_base_initialized)
g_error ("gimp_base_init() must only be called once!");
_gimp_unit_vtable = *vtable;
gimp_base_compat_enums_init ();
gimp_base_initialized = TRUE;
}
void
gimp_base_exit (void)
{
g_clear_pointer (&_gimp_units, g_hash_table_unref);
}
void
gimp_base_compat_enums_init (void)
{
#if 0
static gboolean gimp_base_compat_initialized = FALSE;
GQuark quark;
if (gimp_base_compat_initialized)
return;
quark = g_quark_from_static_string ("gimp-compat-enum");
/* This is how a compat enum is registered, leave one here for
* documentation purposes, remove it as soon as we get a real
* compat enum again
*/
g_type_set_qdata (GIMP_TYPE_ADD_MASK_TYPE, quark,
(gpointer) GIMP_TYPE_ADD_MASK_TYPE_COMPAT);
gimp_base_compat_initialized = TRUE;
#endif
}

View file

@ -0,0 +1,78 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpbase-private.h
* Copyright (C) 2003 Sven Neumann <sven@gimp.org>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_BASE_PRIVATE_H__
#define __GIMP_BASE_PRIVATE_H__
#include <libgimpbase/gimpcpuaccel-private.h>
#include <libgimpbase/gimpenv-private.h>
#ifndef G_OS_WIN32
#include <libgimpbase/gimpsignal.h>
#endif
typedef struct _GimpUnitVtable GimpUnitVtable;
struct _GimpUnitVtable
{
/* These methods MUST only be set on libgimp, not in core app. */
gboolean (* get_deletion_flag) (GimpUnit *unit);
gboolean (* set_deletion_flag) (GimpUnit *unit,
gboolean deletion_flag);
gchar * (* get_data) (gint unit_id,
gdouble *factor,
gint *digits,
gchar **symbol,
gchar **abbreviation);
/* These methods MUST only be set on app, not in libgimp. */
GimpUnit * (* get_user_unit) (gint unit_id);
/* Reserved methods. */
void (* _reserved_0) (void);
void (* _reserved_1) (void);
void (* _reserved_2) (void);
void (* _reserved_3) (void);
void (* _reserved_4) (void);
void (* _reserved_5) (void);
void (* _reserved_6) (void);
void (* _reserved_7) (void);
void (* _reserved_8) (void);
void (* _reserved_9) (void);
};
extern GimpUnitVtable _gimp_unit_vtable;
extern GHashTable *_gimp_units;
G_BEGIN_DECLS
void gimp_base_init (GimpUnitVtable *vtable);
void gimp_base_exit (void);
void gimp_base_compat_enums_init (void);
G_END_DECLS
#endif /* __GIMP_BASE_PRIVATE_H__ */

300
libgimpbase/gimpbase.def Normal file
View file

@ -0,0 +1,300 @@
EXPORTS
gimp_add_mask_type_get_type
gimp_any_to_utf8
gimp_array_copy
gimp_array_free
gimp_array_get_type
gimp_array_new
gimp_base_compat_enums_init
gimp_base_exit
gimp_base_init
gimp_bind_text_domain
gimp_brush_generated_shape_get_type
gimp_cache_directory
gimp_canonicalize_identifier
gimp_cap_style_get_type
gimp_channel_ops_get_type
gimp_channel_type_get_type
gimp_check_size_get_type
gimp_check_type_get_type
gimp_checks_get_colors
gimp_choice_add
gimp_choice_get_documentation
gimp_choice_get_help
gimp_choice_get_id
gimp_choice_get_label
gimp_choice_get_type
gimp_choice_is_valid
gimp_choice_list_nicks
gimp_choice_new
gimp_choice_new_with_values
gimp_choice_set_sensitive
gimp_clone_type_get_type
gimp_color_array_copy
gimp_color_array_free
gimp_color_array_get_length
gimp_color_array_get_type
gimp_color_tag_get_type
gimp_component_type_get_type
gimp_convert_palette_type_get_type
gimp_convolve_type_get_type
gimp_core_object_array_get_length
gimp_core_object_array_get_type
gimp_cpu_accel_get_support
gimp_cpu_accel_set_use
gimp_data_directory
gimp_data_directory_file
gimp_desaturate_mode_get_type
gimp_directory
gimp_directory_file
gimp_dodge_burn_type_get_type
gimp_double_array_get_type
gimp_double_array_get_values
gimp_double_array_set_values
gimp_enum_get_desc
gimp_enum_get_value
gimp_enum_get_value_descriptions
gimp_enum_set_value_descriptions
gimp_enum_value_get_abbrev
gimp_enum_value_get_desc
gimp_enum_value_get_help
gimp_env_init
gimp_escape_uline
gimp_export_capabilities_get_type
gimp_export_options_get_type
gimp_file_chooser_action_get_type
gimp_file_get_utf8_name
gimp_file_has_extension
gimp_file_show_in_file_manager
gimp_filename_to_utf8
gimp_fill_type_get_type
gimp_flags_get_first_desc
gimp_flags_get_first_value
gimp_flags_get_value_descriptions
gimp_flags_set_value_descriptions
gimp_flags_value_get_abbrev
gimp_flags_value_get_desc
gimp_flags_value_get_help
gimp_foreground_extract_mode_get_type
gimp_gradient_blend_color_space_get_type
gimp_gradient_segment_color_get_type
gimp_gradient_segment_type_get_type
gimp_gradient_type_get_type
gimp_grid_style_get_type
gimp_hue_range_get_type
gimp_icon_type_get_type
gimp_image_base_type_get_type
gimp_image_type_get_type
gimp_ink_blob_type_get_type
gimp_installation_directory
gimp_installation_directory_file
gimp_int32_array_get_type
gimp_int32_array_get_values
gimp_int32_array_set_values
gimp_interpolation_type_get_type
gimp_is_canonical_identifier
gimp_join_style_get_type
gimp_locale_directory
gimp_locale_directory_file
gimp_major_version
gimp_mask_apply_mode_get_type
gimp_memsize_deserialize
gimp_memsize_get_type
gimp_memsize_serialize
gimp_merge_type_get_type
gimp_message_handler_type_get_type
gimp_metadata_add_xmp_history
gimp_metadata_deserialize
gimp_metadata_duplicate
gimp_metadata_get_colorspace
gimp_metadata_get_guid
gimp_metadata_get_resolution
gimp_metadata_get_type
gimp_metadata_is_tag_supported
gimp_metadata_load_from_file
gimp_metadata_new
gimp_metadata_save_to_file
gimp_metadata_serialize
gimp_metadata_set_bits_per_sample
gimp_metadata_set_colorspace
gimp_metadata_set_creation_date
gimp_metadata_set_from_exif
gimp_metadata_set_from_iptc
gimp_metadata_set_from_xmp
gimp_metadata_set_pixel_size
gimp_metadata_set_resolution
gimp_micro_version
gimp_minor_version
gimp_offset_type_get_type
gimp_orientation_type_get_type
gimp_paint_application_mode_get_type
gimp_param_array_get_type
gimp_param_choice_get_type
gimp_param_core_object_array_get_type
gimp_param_double_array_get_type
gimp_param_export_options_get_type
gimp_param_file_get_type
gimp_param_int32_array_get_type
gimp_param_memsize_get_type
gimp_param_object_get_type
gimp_param_parasite_get_type
gimp_param_spec_array
gimp_param_spec_choice
gimp_param_spec_choice_get_choice
gimp_param_spec_choice_get_default
gimp_param_spec_core_object_array
gimp_param_spec_core_object_array_get_object_type
gimp_param_spec_double_array
gimp_param_spec_export_options
gimp_param_spec_file
gimp_param_spec_file_get_action
gimp_param_spec_file_none_allowed
gimp_param_spec_file_set_action
gimp_param_spec_int32_array
gimp_param_spec_memsize
gimp_param_spec_object_duplicate
gimp_param_spec_object_get_default
gimp_param_spec_object_has_default
gimp_param_spec_object_set_default
gimp_param_spec_parasite
gimp_param_spec_unit
gimp_param_spec_unit_percent_allowed
gimp_param_spec_unit_pixel_allowed
gimp_param_spec_value_array
gimp_param_spec_value_array_get_element_spec
gimp_param_unit_get_type
gimp_param_value_array_get_type
gimp_parasite_compare
gimp_parasite_copy
gimp_parasite_free
gimp_parasite_get_data
gimp_parasite_get_flags
gimp_parasite_get_name
gimp_parasite_get_type
gimp_parasite_has_flag
gimp_parasite_is_persistent
gimp_parasite_is_type
gimp_parasite_is_undoable
gimp_parasite_new
gimp_path_free
gimp_path_get_user_writable_dir
gimp_path_parse
gimp_path_stroke_type_get_type
gimp_path_to_str
gimp_pdb_error_handler_get_type
gimp_pdb_proc_type_get_type
gimp_pdb_status_type_get_type
gimp_pixels_to_units
gimp_pixpipe_params_build
gimp_pixpipe_params_free
gimp_pixpipe_params_init
gimp_pixpipe_params_parse
gimp_plug_in_directory
gimp_plug_in_directory_file
gimp_precision_get_type
gimp_procedure_sensitivity_mask_get_type
gimp_progress_command_get_type
gimp_range_estimate_settings
gimp_rectangle_intersect
gimp_rectangle_union
gimp_repeat_mode_get_type
gimp_rotation_type_get_type
gimp_run_mode_get_type
gimp_select_criterion_get_type
gimp_signal_private
gimp_size_type_get_type
gimp_stack_trace_available
gimp_stack_trace_mode_get_type
gimp_stack_trace_print
gimp_stack_trace_query
gimp_strip_uline
gimp_stroke_method_get_type
gimp_sysconf_directory
gimp_sysconf_directory_file
gimp_temp_directory
gimp_text_direction_get_type
gimp_text_hint_style_get_type
gimp_text_justification_get_type
gimp_transfer_mode_get_type
gimp_transform_direction_get_type
gimp_transform_resize_get_type
gimp_type_get_translation_context
gimp_type_get_translation_domain
gimp_type_set_translation_context
gimp_type_set_translation_domain
gimp_unit_format_string
gimp_unit_get_abbreviation
gimp_unit_get_by_id
gimp_unit_get_deletion_flag
gimp_unit_get_digits
gimp_unit_get_factor
gimp_unit_get_id
gimp_unit_get_name
gimp_unit_get_scaled_digits
gimp_unit_get_symbol
gimp_unit_get_type
gimp_unit_inch
gimp_unit_is_built_in
gimp_unit_is_metric
gimp_unit_mm
gimp_unit_percent
gimp_unit_pica
gimp_unit_pixel
gimp_unit_point
gimp_unit_set_deletion_flag
gimp_units_to_pixels
gimp_units_to_points
gimp_utf8_strtrim
gimp_value_array_append
gimp_value_array_copy
gimp_value_array_get_color_array
gimp_value_array_get_core_object_array
gimp_value_array_get_type
gimp_value_array_index
gimp_value_array_insert
gimp_value_array_length
gimp_value_array_new
gimp_value_array_new_from_types
gimp_value_array_new_from_types_valist
gimp_value_array_new_from_values
gimp_value_array_prepend
gimp_value_array_ref
gimp_value_array_remove
gimp_value_array_truncate
gimp_value_array_unref
gimp_value_dup_double_array
gimp_value_dup_int32_array
gimp_value_get_double_array
gimp_value_get_int32_array
gimp_value_set_double_array
gimp_value_set_int32_array
gimp_value_set_static_double_array
gimp_value_set_static_int32_array
gimp_value_take_double_array
gimp_value_take_int32_array
gimp_wire_clear_error
gimp_wire_destroy
gimp_wire_error
gimp_wire_flush
gimp_wire_read
gimp_wire_read_msg
gimp_wire_register
gimp_wire_set_flusher
gimp_wire_set_reader
gimp_wire_set_writer
gimp_wire_write
gimp_wire_write_msg
gp_config_write
gp_extension_ack_write
gp_has_init_write
gp_init
gp_proc_install_write
gp_proc_return_write
gp_proc_run_write
gp_proc_uninstall_write
gp_quit_write
gp_temp_proc_return_write
gp_temp_proc_run_write
gp_tile_ack_write
gp_tile_data_write
gp_tile_req_write

46
libgimpbase/gimpbase.h Normal file
View file

@ -0,0 +1,46 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_BASE_H__
#define __GIMP_BASE_H__
#define __GIMP_BASE_H_INSIDE__
#include <gegl.h>
#include <libgimpbase/gimpbasetypes.h>
#include <libgimpbase/gimpchecks.h>
#include <libgimpbase/gimpchoice.h>
#include <libgimpbase/gimpcpuaccel.h>
#include <libgimpbase/gimpenv.h>
#include <libgimpbase/gimpexportoptions.h>
#include <libgimpbase/gimplimits.h>
#include <libgimpbase/gimpmemsize.h>
#include <libgimpbase/gimpmetadata.h>
#include <libgimpbase/gimpparamspecs.h>
#include <libgimpbase/gimpparasite.h>
#include <libgimpbase/gimprectangle.h>
#include <libgimpbase/gimpunit.h>
#include <libgimpbase/gimputils.h>
#include <libgimpbase/gimpversion.h>
#include <libgimpbase/gimpvaluearray.h>
#undef __GIMP_BASE_H_INSIDE__
#endif /* __GIMP_BASE_H__ */

2001
libgimpbase/gimpbaseenums.c Normal file

File diff suppressed because it is too large Load diff

1370
libgimpbase/gimpbaseenums.h Normal file

File diff suppressed because it is too large Load diff

244
libgimpbase/gimpbasetypes.c Normal file
View file

@ -0,0 +1,244 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimpbasetypes.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <glib-object.h>
#include "gimpbasetypes.h"
/**
* SECTION: gimpbasetypes
* @title: gimpbasetypes
* @short_description: Translation between gettext translation domain
* identifier and GType.
*
* Translation between gettext translation domain identifier and
* GType.
**/
static GQuark gimp_translation_domain_quark (void) G_GNUC_CONST;
static GQuark gimp_translation_context_quark (void) G_GNUC_CONST;
static GQuark gimp_value_descriptions_quark (void) G_GNUC_CONST;
/**
* gimp_type_set_translation_domain:
* @type: a #GType
* @domain: a constant string that identifies a translation domain or %NULL
*
* This function attaches a constant string as a gettext translation
* domain identifier to a #GType. The only purpose of this function is
* to use it when registering a #G_TYPE_ENUM with translatable value
* names.
*
* Since: 2.2
**/
void
gimp_type_set_translation_domain (GType type,
const gchar *domain)
{
g_type_set_qdata (type,
gimp_translation_domain_quark (), (gpointer) domain);
}
/**
* gimp_type_get_translation_domain:
* @type: a #GType
*
* Retrieves the gettext translation domain identifier that has been
* previously set using gimp_type_set_translation_domain(). You should
* not need to use this function directly, use gimp_enum_get_value()
* or gimp_enum_value_get_desc() instead.
*
* Returns: the translation domain associated with @type
* or %NULL if no domain was set
*
* Since: 2.2
**/
const gchar *
gimp_type_get_translation_domain (GType type)
{
return (const gchar *) g_type_get_qdata (type,
gimp_translation_domain_quark ());
}
/**
* gimp_type_set_translation_context:
* @type: a #GType
* @context: a constant string that identifies a translation context or %NULL
*
* This function attaches a constant string as a translation context
* to a #GType. The only purpose of this function is to use it when
* registering a #G_TYPE_ENUM with translatable value names.
*
* Since: 2.8
**/
void
gimp_type_set_translation_context (GType type,
const gchar *context)
{
g_type_set_qdata (type,
gimp_translation_context_quark (), (gpointer) context);
}
/**
* gimp_type_get_translation_context:
* @type: a #GType
*
* Retrieves the translation context that has been previously set
* using gimp_type_set_translation_context(). You should not need to
* use this function directly, use gimp_enum_get_value() or
* gimp_enum_value_get_desc() instead.
*
* Returns: the translation context associated with @type
* or %NULL if no context was set
*
* Since: 2.8
**/
const gchar *
gimp_type_get_translation_context (GType type)
{
return (const gchar *) g_type_get_qdata (type,
gimp_translation_context_quark ());
}
/**
* gimp_enum_set_value_descriptions:
* @enum_type: a #GType
* @descriptions: a %NULL terminated constant static array of #GimpEnumDesc
*
* Sets the array of human readable and translatable descriptions
* and help texts for enum values.
*
* Since: 2.2
**/
void
gimp_enum_set_value_descriptions (GType enum_type,
const GimpEnumDesc *descriptions)
{
g_return_if_fail (g_type_is_a (enum_type, G_TYPE_ENUM));
g_return_if_fail (descriptions != NULL);
g_type_set_qdata (enum_type,
gimp_value_descriptions_quark (),
(gpointer) descriptions);
}
/**
* gimp_enum_get_value_descriptions:
* @enum_type: a #GType
*
* Retrieves the array of human readable and translatable descriptions
* and help texts for enum values.
*
* Returns: a %NULL terminated constant array of #GimpEnumDesc
*
* Since: 2.2
**/
const GimpEnumDesc *
gimp_enum_get_value_descriptions (GType enum_type)
{
g_return_val_if_fail (g_type_is_a (enum_type, G_TYPE_ENUM), NULL);
return (const GimpEnumDesc *)
g_type_get_qdata (enum_type, gimp_value_descriptions_quark ());
}
/**
* gimp_flags_set_value_descriptions:
* @flags_type: a #GType
* @descriptions: a %NULL terminated constant static array of #GimpFlagsDesc
*
* Sets the array of human readable and translatable descriptions
* and help texts for flags values.
*
* Since: 2.2
**/
void
gimp_flags_set_value_descriptions (GType flags_type,
const GimpFlagsDesc *descriptions)
{
g_return_if_fail (g_type_is_a (flags_type, G_TYPE_FLAGS));
g_return_if_fail (descriptions != NULL);
g_type_set_qdata (flags_type,
gimp_value_descriptions_quark (),
(gpointer) descriptions);
}
/**
* gimp_flags_get_value_descriptions:
* @flags_type: a #GType
*
* Retrieves the array of human readable and translatable descriptions
* and help texts for flags values.
*
* Returns: a %NULL terminated constant array of #GimpFlagsDesc
*
* Since: 2.2
**/
const GimpFlagsDesc *
gimp_flags_get_value_descriptions (GType flags_type)
{
g_return_val_if_fail (g_type_is_a (flags_type, G_TYPE_FLAGS), NULL);
return (const GimpFlagsDesc *)
g_type_get_qdata (flags_type, gimp_value_descriptions_quark ());
}
/* private functions */
static GQuark
gimp_translation_domain_quark (void)
{
static GQuark quark = 0;
if (! quark)
quark = g_quark_from_static_string ("gimp-translation-domain-quark");
return quark;
}
static GQuark
gimp_translation_context_quark (void)
{
static GQuark quark = 0;
if (! quark)
quark = g_quark_from_static_string ("gimp-translation-context-quark");
return quark;
}
static GQuark
gimp_value_descriptions_quark (void)
{
static GQuark quark = 0;
if (! quark)
quark = g_quark_from_static_string ("gimp-value-descriptions-quark");
return quark;
}

110
libgimpbase/gimpbasetypes.h Normal file
View file

@ -0,0 +1,110 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_BASE_TYPES_H__
#define __GIMP_BASE_TYPES_H__
#include <libgimpcolor/gimpcolortypes.h>
#include <libgimpmath/gimpmathtypes.h>
#include <libgimpbase/gimpbaseenums.h>
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
/* XXX FIXME move these to a separate file */
#ifdef GIMP_DISABLE_DEPRECATION_WARNINGS
#define GIMP_DEPRECATED
#define GIMP_DEPRECATED_FOR(f)
#define GIMP_UNAVAILABLE(maj,min)
#else
#define GIMP_DEPRECATED G_DEPRECATED
#define GIMP_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f)
#define GIMP_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min)
#endif
typedef struct _GimpChoice GimpChoice;
typedef struct _GimpParasite GimpParasite;
typedef struct _GimpEnumDesc GimpEnumDesc;
typedef struct _GimpExportOptions GimpExportOptions;
typedef struct _GimpFlagsDesc GimpFlagsDesc;
typedef struct _GimpUnit GimpUnit;
typedef struct _GimpValueArray GimpValueArray;
typedef struct _GimpMetadata GimpMetadata;
/**
* GimpEnumDesc:
* @value: An enum value.
* @value_desc: The value's description.
* @value_help: The value's help text.
*
* This structure is used to register translatable descriptions and
* help texts for enum values. See gimp_enum_set_value_descriptions().
**/
struct _GimpEnumDesc
{
gint value;
const gchar *value_desc;
const gchar *value_help;
};
/**
* GimpFlagsDesc:
* @value: A flag value.
* @value_desc: The value's description.
* @value_help: The value's help text.
*
* This structure is used to register translatable descriptions and
* help texts for flag values. See gimp_flags_set_value_descriptions().
**/
struct _GimpFlagsDesc
{
guint value;
const gchar *value_desc;
const gchar *value_help;
};
void gimp_type_set_translation_domain (GType type,
const gchar *domain);
const gchar * gimp_type_get_translation_domain (GType type);
void gimp_type_set_translation_context (GType type,
const gchar *context);
const gchar * gimp_type_get_translation_context (GType type);
void gimp_enum_set_value_descriptions (GType enum_type,
const GimpEnumDesc *descriptions);
const GimpEnumDesc * gimp_enum_get_value_descriptions (GType enum_type);
void gimp_flags_set_value_descriptions (GType flags_type,
const GimpFlagsDesc *descriptions);
const GimpFlagsDesc * gimp_flags_get_value_descriptions (GType flags_type);
G_END_DECLS
#endif /* __GIMP_BASE_TYPES_H__ */

127
libgimpbase/gimpchecks.c Normal file
View file

@ -0,0 +1,127 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimpchecks.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <glib-object.h>
#include "gimpbasetypes.h"
#include "gimpchecks.h"
/**
* SECTION: gimpchecks
* @title: gimpchecks
* @short_description: Constants and functions related to rendering
* checkerboards.
*
* Constants and functions related to rendering checkerboards.
**/
/**
* gimp_checks_get_colors:
* @type: the checkerboard type
* @color1: (inout): current custom color and return location for the first color.
* @color2: (inout): current custom color and return location for the second color.
*
* Retrieves the colors to use when drawing a checkerboard for a certain
* #GimpCheckType and custom colors.
* If @type is %GIMP_CHECK_TYPE_CUSTOM_CHECKS, then @color1 and @color2
* will remain untouched, which means you must initialize them to the
* values expected for custom checks.
*
* To obtain the user-set colors in Preferences, just call:
* |[<!-- language="C" -->
* GeglColor *color1 = gimp_check_custom_color1 ();
* GeglColor *color2 = gimp_check_custom_color2 ();
* gimp_checks_get_colors (gimp_check_type (), &color1, &color2);
* ]|
*
* Since: 3.0
**/
void
gimp_checks_get_colors (GimpCheckType type,
GeglColor **color1,
GeglColor **color2)
{
g_return_if_fail ((color1 != NULL && GEGL_IS_COLOR (*color1)) || (color2 != NULL && GEGL_IS_COLOR (*color2)));
if (color1)
{
*color1 = gegl_color_duplicate (*color1);
switch (type)
{
case GIMP_CHECK_TYPE_LIGHT_CHECKS:
gegl_color_set_pixel (*color1, babl_format ("R'G'B'A double"), GIMP_CHECKS_LIGHT_COLOR_LIGHT);
break;
case GIMP_CHECK_TYPE_DARK_CHECKS:
gegl_color_set_pixel (*color1, babl_format ("R'G'B'A double"), GIMP_CHECKS_DARK_COLOR_LIGHT);
break;
case GIMP_CHECK_TYPE_WHITE_ONLY:
gegl_color_set_pixel (*color1, babl_format ("R'G'B'A double"), GIMP_CHECKS_WHITE_COLOR);
break;
case GIMP_CHECK_TYPE_GRAY_ONLY:
gegl_color_set_pixel (*color1, babl_format ("R'G'B'A double"), GIMP_CHECKS_GRAY_COLOR);
break;
case GIMP_CHECK_TYPE_BLACK_ONLY:
gegl_color_set_pixel (*color1, babl_format ("R'G'B'A double"), GIMP_CHECKS_BLACK_COLOR);
break;
case GIMP_CHECK_TYPE_CUSTOM_CHECKS:
/* Keep the current value. */
break;
default:
gegl_color_set_pixel (*color1, babl_format ("R'G'B'A double"), GIMP_CHECKS_GRAY_COLOR_LIGHT);
break;
}
}
if (color2)
{
*color2 = gegl_color_duplicate (*color2);
switch (type)
{
case GIMP_CHECK_TYPE_LIGHT_CHECKS:
gegl_color_set_pixel (*color2, babl_format ("R'G'B'A double"), GIMP_CHECKS_LIGHT_COLOR_DARK);
break;
case GIMP_CHECK_TYPE_DARK_CHECKS:
gegl_color_set_pixel (*color2, babl_format ("R'G'B'A double"), GIMP_CHECKS_DARK_COLOR_DARK);
break;
case GIMP_CHECK_TYPE_WHITE_ONLY:
gegl_color_set_pixel (*color2, babl_format ("R'G'B'A double"), GIMP_CHECKS_WHITE_COLOR);
break;
case GIMP_CHECK_TYPE_GRAY_ONLY:
gegl_color_set_pixel (*color2, babl_format ("R'G'B'A double"), GIMP_CHECKS_GRAY_COLOR);
break;
case GIMP_CHECK_TYPE_BLACK_ONLY:
gegl_color_set_pixel (*color2, babl_format ("R'G'B'A double"), GIMP_CHECKS_BLACK_COLOR);
break;
case GIMP_CHECK_TYPE_CUSTOM_CHECKS:
/* Keep the current value. */
break;
default:
gegl_color_set_pixel (*color2, babl_format ("R'G'B'A double"), GIMP_CHECKS_GRAY_COLOR_DARK);
break;
}
}
}

145
libgimpbase/gimpchecks.h Normal file
View file

@ -0,0 +1,145 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
#ifndef __GIMP_CHECKS_H__
#define __GIMP_CHECKS_H__
G_BEGIN_DECLS
/**
* GIMP_CHECK_SIZE:
*
* The default checkerboard size in pixels. This is configurable in
* the core but GIMP plug-ins can't access the user preference and
* should use this constant instead.
**/
#define GIMP_CHECK_SIZE 8
/**
* GIMP_CHECK_SIZE_SM:
*
* The default small checkerboard size in pixels.
**/
#define GIMP_CHECK_SIZE_SM 4
/**
* GIMP_CHECK_DARK:
*
* The dark gray value for the default checkerboard pattern.
**/
#define GIMP_CHECK_DARK 0.4
/**
* GIMP_CHECK_LIGHT:
*
* The dark light value for the default checkerboard pattern.
**/
#define GIMP_CHECK_LIGHT 0.6
/**
* GIMP_CHECKS_LIGHT_COLOR_DARK:
*
* The dark color for the light checkerboard type.
**/
#define GIMP_CHECKS_LIGHT_COLOR_DARK ((gdouble[]) { 0.8, 0.8, 0.8, 1.0 })
/**
* GIMP_CHECKS_LIGHT_COLOR_LIGHT:
*
* The light color for the light checkerboard type.
**/
#define GIMP_CHECKS_LIGHT_COLOR_LIGHT ((gdouble[]) { 1.0, 1.0, 1.0, 1.0 })
/**
* GIMP_CHECKS_GRAY_COLOR_DARK:
*
* The dark color for the gray checkerboard type.
**/
#define GIMP_CHECKS_GRAY_COLOR_DARK ((gdouble[]) { 0.4, 0.4, 0.4, 1.0 })
/**
* GIMP_CHECKS_GRAY_COLOR_LIGHT:
*
* The light color for the gray checkerboard type.
**/
#define GIMP_CHECKS_GRAY_COLOR_LIGHT ((gdouble[]) { 0.6, 0.6, 0.6, 1.0 })
/**
* GIMP_CHECKS_DARK_COLOR_DARK:
*
* The dark color for the dark checkerboard type.
**/
#define GIMP_CHECKS_DARK_COLOR_DARK ((gdouble[]) { 0.0, 0.0, 0.0, 1.0 })
/**
* GIMP_CHECKS_DARK_COLOR_LIGHT:
*
* The light color for the dark checkerboard type.
**/
#define GIMP_CHECKS_DARK_COLOR_LIGHT ((gdouble[]) { 0.2, 0.2, 0.2, 1.0 })
/**
* GIMP_CHECKS_WHITE_COLOR:
*
* The light/dark color for the white checkerboard type.
**/
#define GIMP_CHECKS_WHITE_COLOR ((gdouble[]) { 1.0, 1.0, 1.0, 1.0 })
/**
* GIMP_CHECKS_GRAY_COLOR:
*
* The light/dark color for the gray checkerboard type.
**/
#define GIMP_CHECKS_GRAY_COLOR ((gdouble[]) { 0.5, 0.5, 0.5, 1.0 })
/**
* GIMP_CHECKS_BLACK_COLOR:
*
* The light/dark color for the black checkerboard type.
**/
#define GIMP_CHECKS_BLACK_COLOR ((gdouble[]) { 0.0, 0.0, 0.0, 1.0 })
/**
* GIMP_CHECKS_CUSTOM_COLOR1:
*
* The default color 1 for the custom checkerboard type.
**/
#define GIMP_CHECKS_CUSTOM_COLOR1 GIMP_CHECKS_GRAY_COLOR_LIGHT
/**
* GIMP_CHECKS_CUSTOM_COLOR2:
*
* The default color 2 for the custom checkerboard type.
**/
#define GIMP_CHECKS_CUSTOM_COLOR2 GIMP_CHECKS_GRAY_COLOR_DARK
void gimp_checks_get_colors (GimpCheckType type,
GeglColor **color1,
GeglColor **color2);
G_END_DECLS
#endif /* __GIMP_CHECKS_H__ */

617
libgimpbase/gimpchoice.c Normal file
View file

@ -0,0 +1,617 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-2000 Peter Mattis and Spencer Kimball
*
* gimpchoice.c
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gio/gio.h>
#include <glib-object.h>
#include "gimpbasetypes.h"
#include "gimpchoice.h"
#include "gimpparamspecs.h"
typedef struct _GimpChoiceDesc
{
gchar *label;
gchar *help;
gint id;
gboolean sensitive;
} GimpChoiceDesc;
enum
{
SENSITIVITY_CHANGED,
LAST_SIGNAL
};
struct _GimpChoice
{
GObject parent_instance;
GHashTable *choices;
GList *keys;
};
static void gimp_choice_finalize (GObject *object);
static void gimp_choice_desc_free (GimpChoiceDesc *desc);
G_DEFINE_TYPE (GimpChoice, gimp_choice, G_TYPE_OBJECT)
#define parent_class gimp_choice_parent_class
static guint gimp_choice_signals[LAST_SIGNAL] = { 0 };
static void
gimp_choice_class_init (GimpChoiceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
gimp_choice_signals[SENSITIVITY_CHANGED] =
g_signal_new ("sensitivity-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
0, /*G_STRUCT_OFFSET (GimpChoiceClass, sensitivity_changed),*/
NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_STRING);
object_class->finalize = gimp_choice_finalize;
}
static void
gimp_choice_init (GimpChoice *choice)
{
choice->choices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) gimp_choice_desc_free);
}
static void
gimp_choice_finalize (GObject *object)
{
GimpChoice *choice = GIMP_CHOICE (object);
g_hash_table_unref (choice->choices);
g_list_free_full (choice->keys, (GDestroyNotify) g_free);
}
/* Public API */
/**
* gimp_choice_new:
*
* Returns: (transfer full): a #GimpChoice.
*
* Since: 3.0
**/
GimpChoice *
gimp_choice_new (void)
{
GimpChoice *choice;
choice = g_object_new (GIMP_TYPE_CHOICE, NULL);
return choice;
}
/**
* gimp_choice_new_with_values:
* @nick: the first value.
* @id: integer ID for @nick.
* @label: the label of @nick.
* @help: longer help text for @nick.
* ...: more triplets of string to pre-fill the created %GimpChoice.
*
* Returns: (transfer full): a #GimpChoice.
*
* Since: 3.0
**/
GimpChoice *
gimp_choice_new_with_values (const gchar *nick,
gint id,
const gchar *label,
const gchar *help,
...)
{
GimpChoice *choice;
va_list va_args;
g_return_val_if_fail (nick != NULL, NULL);
g_return_val_if_fail (label != NULL, NULL);
choice = gimp_choice_new ();
va_start (va_args, help);
do
{
gimp_choice_add (choice, nick, id, label, help);
nick = va_arg (va_args, const gchar *);
if (nick == NULL)
break;
id = va_arg (va_args, gint);
label = va_arg (va_args, const gchar *);
if (label == NULL)
{
g_critical ("%s: nick '%s' cannot have a NULL label.", G_STRFUNC, nick);
break;
}
help = va_arg (va_args, const gchar *);
}
while (TRUE);
va_end (va_args);
return choice;
}
/**
* gimp_choice_add:
* @choice: the %GimpChoice.
* @nick: the nick of @choice.
* @id: optional integer ID for @nick.
* @label: the label of @choice.
* @help: optional longer help text for @nick.
*
* This procedure adds a new possible value to @choice list of values.
* The @id is an optional integer identifier. This can be useful for instance
* when you want to work with different enum values mapped to each @nick.
*
* Since: 3.0
**/
void
gimp_choice_add (GimpChoice *choice,
const gchar *nick,
gint id,
const gchar *label,
const gchar *help)
{
GimpChoiceDesc *desc;
GList *duplicate;
g_return_if_fail (label != NULL);
desc = g_new0 (GimpChoiceDesc, 1);
desc->id = id;
desc->label = g_strdup (label);
desc->help = help != NULL ? g_strdup (help) : NULL;
desc->sensitive = TRUE;
g_hash_table_insert (choice->choices, g_strdup (nick), desc);
duplicate = g_list_find_custom (choice->keys, nick, (GCompareFunc) g_strcmp0);
if (duplicate != NULL)
{
choice->keys = g_list_remove_link (choice->keys, duplicate);
gimp_choice_desc_free (duplicate->data);
g_list_free (duplicate);
}
choice->keys = g_list_append (choice->keys, g_strdup (nick));
}
/**
* gimp_choice_is_valid:
* @choice: a %GimpChoice.
* @nick: the nick to check.
*
* This procedure checks if the given @nick is valid and refers to
* an existing choice.
*
* Returns: Whether the choice is valid.
*
* Since: 3.0
**/
gboolean
gimp_choice_is_valid (GimpChoice *choice,
const gchar *nick)
{
GimpChoiceDesc *desc;
g_return_val_if_fail (GIMP_IS_CHOICE (choice), FALSE);
g_return_val_if_fail (nick != NULL, FALSE);
desc = g_hash_table_lookup (choice->choices, nick);
return (desc != NULL && desc->sensitive);
}
/**
* gimp_choice_list_nicks:
* @choice: a %GimpChoice.
*
* This procedure returns the list of nicks allowed for @choice.
*
* Returns: (element-type gchar*) (transfer none): The list of @choice's nicks.
*
* Since: 3.0
**/
GList *
gimp_choice_list_nicks (GimpChoice *choice)
{
/* I don't use g_hash_table_get_keys() on purpose, because I want to retain
* the adding-time order.
*/
return choice->keys;
}
/**
* gimp_choice_get_id:
* @choice: a %GimpChoice.
* @nick: the nick to lookup.
*
* Returns: the ID of @nick.
*
* Since: 3.0
**/
gint
gimp_choice_get_id (GimpChoice *choice,
const gchar *nick)
{
GimpChoiceDesc *desc;
desc = g_hash_table_lookup (choice->choices, nick);
if (desc)
return desc->id;
else
return 0;
}
/**
* gimp_choice_get_label:
* @choice: a %GimpChoice.
* @nick: the nick to lookup.
*
* Returns: (transfer none): the label of @nick.
*
* Since: 3.0
**/
const gchar *
gimp_choice_get_label (GimpChoice *choice,
const gchar *nick)
{
GimpChoiceDesc *desc;
desc = g_hash_table_lookup (choice->choices, nick);
if (desc)
return desc->label;
else
return NULL;
}
/**
* gimp_choice_get_help:
* @choice: a %GimpChoice.
* @nick: the nick to lookup.
*
* Returns the longer documentation for @nick.
*
* Returns: (transfer none): the help text of @nick.
*
* Since: 3.0
**/
const gchar *
gimp_choice_get_help (GimpChoice *choice,
const gchar *nick)
{
GimpChoiceDesc *desc;
desc = g_hash_table_lookup (choice->choices, nick);
if (desc)
return desc->help;
else
return NULL;
}
/**
* gimp_choice_get_documentation:
* @choice: the %GimpChoice.
* @nick: the possible value's nick you need documentation for.
* @label: (transfer none): the label of @nick.
* @help: (transfer none): the help text of @nick.
*
* Returns the documentation strings for @nick.
*
* Returns: %TRUE if @nick is found, %FALSE otherwise.
*
* Since: 3.0
**/
gboolean
gimp_choice_get_documentation (GimpChoice *choice,
const gchar *nick,
const gchar **label,
const gchar **help)
{
GimpChoiceDesc *desc;
desc = g_hash_table_lookup (choice->choices, nick);
if (desc)
{
*label = desc->label;
*help = desc->help;
return TRUE;
}
return FALSE;
}
/**
* gimp_choice_set_sensitive:
* @choice: the %GimpChoice.
* @nick: the nick to lookup.
*
* Change the sensitivity of a possible @nick. Technically a non-sensitive @nick
* means it cannot be chosen anymore (so [method@Gimp.Choice.is_valid] will
* return %FALSE; nevertheless [method@Gimp.Choice.list_nicks] and other
* functions to get information about a choice will still function).
*
* Since: 3.0
**/
void
gimp_choice_set_sensitive (GimpChoice *choice,
const gchar *nick,
gboolean sensitive)
{
GimpChoiceDesc *desc;
g_return_if_fail (GIMP_IS_CHOICE (choice));
g_return_if_fail (nick != NULL);
desc = g_hash_table_lookup (choice->choices, nick);
g_return_if_fail (desc != NULL);
if (desc->sensitive != sensitive)
{
desc->sensitive = sensitive;
g_signal_emit (choice, gimp_choice_signals[SENSITIVITY_CHANGED], 0, nick);
}
}
/* Private functions */
static void
gimp_choice_desc_free (GimpChoiceDesc *desc)
{
g_free (desc->label);
g_free (desc->help);
g_free (desc);
}
/*
* GIMP_TYPE_PARAM_CHOICE
*/
#define GIMP_PARAM_SPEC_CHOICE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_CHOICE, GimpParamSpecChoice))
typedef struct _GimpParamSpecChoice GimpParamSpecChoice;
struct _GimpParamSpecChoice
{
GParamSpecString parent_instance;
GimpChoice *choice;
};
static void gimp_param_choice_class_init (GParamSpecClass *klass);
static void gimp_param_choice_init (GParamSpec *pspec);
static void gimp_param_choice_finalize (GParamSpec *pspec);
static gboolean gimp_param_choice_validate (GParamSpec *pspec,
GValue *value);
static gboolean gimp_param_choice_value_is_valid (GParamSpec *pspec,
const GValue *value);
static gint gimp_param_choice_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2);
GType
gimp_param_choice_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_choice_class_init,
NULL, NULL,
sizeof (GimpParamSpecChoice),
0,
(GInstanceInitFunc) gimp_param_choice_init
};
type = g_type_register_static (G_TYPE_PARAM_STRING,
"GimpParamChoice", &info, 0);
}
return type;
}
static void
gimp_param_choice_class_init (GParamSpecClass *klass)
{
klass->value_type = G_TYPE_STRING;
klass->finalize = gimp_param_choice_finalize;
klass->value_validate = gimp_param_choice_validate;
klass->value_is_valid = gimp_param_choice_value_is_valid;
klass->values_cmp = gimp_param_choice_values_cmp;
}
static void
gimp_param_choice_init (GParamSpec *pspec)
{
GimpParamSpecChoice *choice = GIMP_PARAM_SPEC_CHOICE (pspec);
choice->choice = NULL;
}
static void
gimp_param_choice_finalize (GParamSpec *pspec)
{
GimpParamSpecChoice *spec_choice = GIMP_PARAM_SPEC_CHOICE (pspec);
GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (GIMP_TYPE_PARAM_CHOICE));
g_object_unref (spec_choice->choice);
parent_class->finalize (pspec);
}
static gboolean
gimp_param_choice_validate (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecChoice *spec_choice = GIMP_PARAM_SPEC_CHOICE (pspec);
GParamSpecString *spec_string = G_PARAM_SPEC_STRING (pspec);
GimpChoice *choice = spec_choice->choice;
const gchar *strval = g_value_get_string (value);
if (! gimp_choice_is_valid (choice, strval))
{
if (gimp_choice_is_valid (choice, spec_string->default_value))
{
g_value_set_string (value, spec_string->default_value);
}
else
{
/* This might happen if the default value is set insensitive. Then we
* should just set any valid random nick.
*/
GList *nicks;
nicks = gimp_choice_list_nicks (choice);
for (GList *iter = nicks; iter; iter = iter->next)
if (gimp_choice_is_valid (choice, (gchar *) iter->data))
{
g_value_set_string (value, (gchar *) iter->data);
break;
}
}
return TRUE;
}
return FALSE;
}
static gboolean
gimp_param_choice_value_is_valid (GParamSpec *pspec,
const GValue *value)
{
GimpParamSpecChoice *cspec = GIMP_PARAM_SPEC_CHOICE (pspec);
const gchar *strval = g_value_get_string (value);
GimpChoice *choice = cspec->choice;
return gimp_choice_is_valid (choice, strval);
}
static gint
gimp_param_choice_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2)
{
const gchar *choice1 = g_value_get_string (value1);
const gchar *choice2 = g_value_get_string (value2);
return g_strcmp0 (choice1, choice2);
}
/**
* gimp_param_spec_choice:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @choice: (transfer full): the %GimpChoice describing allowed choices.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecChoice specifying a
* #G_TYPE_STRING property.
* This %GimpParamSpecChoice takes ownership of the reference on @choice.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer floating): The newly created #GimpParamSpecChoice.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_choice (const gchar *name,
const gchar *nick,
const gchar *blurb,
GimpChoice *choice,
const gchar *default_value,
GParamFlags flags)
{
GimpParamSpecChoice *choice_spec;
GParamSpecString *string_spec;
g_return_val_if_fail (GIMP_IS_CHOICE (choice), NULL);
g_return_val_if_fail (gimp_choice_is_valid (choice, default_value), NULL);
choice_spec = g_param_spec_internal (GIMP_TYPE_PARAM_CHOICE,
name, nick, blurb, flags);
g_return_val_if_fail (choice_spec, NULL);
string_spec = G_PARAM_SPEC_STRING (choice_spec);
choice_spec->choice = choice;
string_spec->default_value = g_strdup (default_value);
return G_PARAM_SPEC (choice_spec);
}
/**
* gimp_param_spec_choice_get_choice:
* @pspec: a #GParamSpec to hold a #GimpParamSpecChoice value.
*
* Returns: (transfer none): the choice object defining the valid values.
*
* Since: 3.0
**/
GimpChoice *
gimp_param_spec_choice_get_choice (GParamSpec *pspec)
{
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_CHOICE (pspec), NULL);
return GIMP_PARAM_SPEC_CHOICE (pspec)->choice;
}
/**
* gimp_param_spec_choice_get_default:
* @pspec: a #GParamSpec to hold a #GimpParamSpecChoice value.
*
* Returns: the default value.
*
* Since: 3.0
**/
const gchar *
gimp_param_spec_choice_get_default (GParamSpec *pspec)
{
const GValue *value;
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_CHOICE (pspec), NULL);
value = g_param_spec_get_default_value (pspec);
return g_value_get_string (value);
}

94
libgimpbase/gimpchoice.h Normal file
View file

@ -0,0 +1,94 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-2000 Peter Mattis and Spencer Kimball
*
* gimpchoice.h
* Copyright (C) 2023 Jehan
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
#ifndef __GIMP_CHOICE_H__
#define __GIMP_CHOICE_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
#define GIMP_TYPE_CHOICE (gimp_choice_get_type ())
G_DECLARE_FINAL_TYPE (GimpChoice, gimp_choice, GIMP, CHOICE, GObject)
GimpChoice * gimp_choice_new (void);
GimpChoice * gimp_choice_new_with_values (const gchar *nick,
gint id,
const gchar *label,
const gchar *help,
...) G_GNUC_NULL_TERMINATED;
void gimp_choice_add (GimpChoice *choice,
const gchar *nick,
gint id,
const gchar *label,
const gchar *help);
gboolean gimp_choice_is_valid (GimpChoice *choice,
const gchar *nick);
GList * gimp_choice_list_nicks (GimpChoice *choice);
gint gimp_choice_get_id (GimpChoice *choice,
const gchar *nick);
const gchar * gimp_choice_get_label (GimpChoice *choice,
const gchar *nick);
const gchar * gimp_choice_get_help (GimpChoice *choice,
const gchar *nick);
gboolean gimp_choice_get_documentation (GimpChoice *choice,
const gchar *nick,
const gchar **label,
const gchar **help);
void gimp_choice_set_sensitive (GimpChoice *choice,
const gchar *nick,
gboolean sensitive);
/*
* GIMP_TYPE_PARAM_CHOICE
*/
#define GIMP_TYPE_PARAM_CHOICE (gimp_param_choice_get_type ())
#define GIMP_IS_PARAM_SPEC_CHOICE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_CHOICE))
GType gimp_param_choice_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_choice (const gchar *name,
const gchar *nick,
const gchar *blurb,
GimpChoice *choice,
const gchar *default_value,
GParamFlags flags);
GimpChoice * gimp_param_spec_choice_get_choice (GParamSpec *pspec);
const gchar * gimp_param_spec_choice_get_default (GParamSpec *pspec);
G_END_DECLS
#endif /* __GIMP_CHOICE_H__ */

View file

@ -0,0 +1,12 @@
/* Generated data (by gimp-mkenums) */
#include "stamp-gimpcompatenums.h"
#include "config.h"
#include <glib-object.h>
#include "gimpbasetypes.h"
#include "gimpcompatenums.h"
#include "libgimp/libgimp-intl.h"
/* Generated data ends here */

View file

@ -0,0 +1,54 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_COMPAT_ENUMS_H__
#define __GIMP_COMPAT_ENUMS_H__
G_BEGIN_DECLS
/* These enums exist only for compatibility, their nicks are needed
* for config file parsing; they are registered in gimp_base_init().
*/
#if 0
/* Leave one enum here for documentation purposes, remove it as
* soon as we need a real compat enum again, also don't have
* that "skip" on the compat enum...
*/
#define GIMP_TYPE_ADD_MASK_TYPE_COMPAT (gimp_add_mask_type_compat_get_type ())
GType gimp_add_mask_type_compat_get_type (void) G_GNUC_CONST;
typedef enum /*< skip >*/
{
GIMP_ADD_WHITE_MASK = GIMP_ADD_MASK_WHITE,
GIMP_ADD_BLACK_MASK = GIMP_ADD_MASK_BLACK,
GIMP_ADD_ALPHA_MASK = GIMP_ADD_MASK_ALPHA,
GIMP_ADD_ALPHA_TRANSFER_MASK = GIMP_ADD_MASK_ALPHA_TRANSFER,
GIMP_ADD_SELECTION_MASK = GIMP_ADD_MASK_SELECTION,
GIMP_ADD_COPY_MASK = GIMP_ADD_MASK_COPY,
GIMP_ADD_CHANNEL_MASK = GIMP_ADD_MASK_CHANNEL
} GimpAddMaskTypeCompat;
#endif
G_END_DECLS
#endif /* __GIMP_COMPAT_ENUMS_H__ */

View file

@ -0,0 +1,32 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcpuaccel-private.h
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_CPU_ACCEL_PRIVATE_H__
#define __GIMP_CPU_ACCEL_PRIVATE_H__
G_BEGIN_DECLS
void gimp_cpu_accel_set_use (gboolean use);
G_END_DECLS
#endif /* __GIMP_CPU_ACCEL_PRIVATE_H__ */

532
libgimpbase/gimpcpuaccel.c Normal file
View file

@ -0,0 +1,532 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
/*
* x86 bits Copyright (C) Manish Singh <yosh@gimp.org>
*/
/*
* PPC CPU acceleration detection was taken from DirectFB but seems to be
* originating from mpeg2dec with the following copyright:
*
* Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*/
#include "config.h"
#include <string.h>
#include <signal.h>
#include <setjmp.h>
#include <glib.h>
#include "gimpcpuaccel.h"
#include "gimpcpuaccel-private.h"
/**
* SECTION: gimpcpuaccel
* @title: gimpcpuaccel
* @short_description: Functions to query and configure CPU acceleration.
*
* Functions to query and configure CPU acceleration.
**/
static GimpCpuAccelFlags cpu_accel (void) G_GNUC_CONST;
static gboolean use_cpu_accel = TRUE;
/**
* gimp_cpu_accel_get_support:
*
* Query for CPU acceleration support.
*
* Returns: #GimpCpuAccelFlags as supported by the CPU.
*
* Since: 2.4
*/
GimpCpuAccelFlags
gimp_cpu_accel_get_support (void)
{
return use_cpu_accel ? cpu_accel () : GIMP_CPU_ACCEL_NONE;
}
/**
* gimp_cpu_accel_set_use:
* @use: whether to use CPU acceleration features or not
*
* This function is for internal use only.
*
* Since: 2.4
*/
void
gimp_cpu_accel_set_use (gboolean use)
{
use_cpu_accel = use ? TRUE : FALSE;
}
#if defined(ARCH_X86) && defined(USE_MMX) && defined(__GNUC__)
#define HAVE_ACCEL 1
typedef enum
{
ARCH_X86_VENDOR_NONE,
ARCH_X86_VENDOR_INTEL,
ARCH_X86_VENDOR_AMD,
ARCH_X86_VENDOR_CENTAUR,
ARCH_X86_VENDOR_CYRIX,
ARCH_X86_VENDOR_NSC,
ARCH_X86_VENDOR_TRANSMETA,
ARCH_X86_VENDOR_NEXGEN,
ARCH_X86_VENDOR_RISE,
ARCH_X86_VENDOR_UMC,
ARCH_X86_VENDOR_SIS,
ARCH_X86_VENDOR_HYGON,
ARCH_X86_VENDOR_UNKNOWN = 0xff
} X86Vendor;
enum
{
ARCH_X86_INTEL_FEATURE_MMX = 1 << 23,
ARCH_X86_INTEL_FEATURE_XMM = 1 << 25,
ARCH_X86_INTEL_FEATURE_XMM2 = 1 << 26,
ARCH_X86_AMD_FEATURE_MMXEXT = 1 << 22,
ARCH_X86_AMD_FEATURE_3DNOW = 1 << 31,
ARCH_X86_CENTAUR_FEATURE_MMX = 1 << 23,
ARCH_X86_CENTAUR_FEATURE_MMXEXT = 1 << 24,
ARCH_X86_CENTAUR_FEATURE_3DNOW = 1 << 31,
ARCH_X86_CYRIX_FEATURE_MMX = 1 << 23,
ARCH_X86_CYRIX_FEATURE_MMXEXT = 1 << 24
};
enum
{
ARCH_X86_INTEL_FEATURE_PNI = 1 << 0,
ARCH_X86_INTEL_FEATURE_SSSE3 = 1 << 9,
ARCH_X86_INTEL_FEATURE_SSE4_1 = 1 << 19,
ARCH_X86_INTEL_FEATURE_SSE4_2 = 1 << 20,
ARCH_X86_INTEL_FEATURE_AVX = 1 << 28
};
#if !defined(ARCH_X86_64) && (defined(PIC) || defined(__PIC__))
#define cpuid(op,eax,ebx,ecx,edx) \
__asm__ ("movl %%ebx, %%esi\n\t" \
"cpuid\n\t" \
"xchgl %%ebx,%%esi" \
: "=a" (eax), \
"=S" (ebx), \
"=c" (ecx), \
"=d" (edx) \
: "0" (op))
#else
#define cpuid(op,eax,ebx,ecx,edx) \
__asm__ ("cpuid" \
: "=a" (eax), \
"=b" (ebx), \
"=c" (ecx), \
"=d" (edx) \
: "0" (op))
#endif
static X86Vendor
arch_get_vendor (void)
{
guint32 eax, ebx, ecx, edx;
union{
gchar idaschar[16];
int idasint[4];
}id;
#ifndef ARCH_X86_64
/* Only need to check this on ia32 */
__asm__ ("pushfl\n\t"
"pushfl\n\t"
"popl %0\n\t"
"movl %0,%1\n\t"
"xorl $0x200000,%0\n\t"
"pushl %0\n\t"
"popfl\n\t"
"pushfl\n\t"
"popl %0\n\t"
"popfl"
: "=a" (eax),
"=c" (ecx)
:
: "cc");
if (eax == ecx)
return ARCH_X86_VENDOR_NONE;
#endif
cpuid (0, eax, ebx, ecx, edx);
if (eax == 0)
return ARCH_X86_VENDOR_NONE;
id.idasint[0] = ebx;
id.idasint[1] = edx;
id.idasint[2] = ecx;
id.idaschar[12] = '\0';
#ifdef ARCH_X86_64
if (strcmp (id.idaschar, "AuthenticAMD") == 0)
return ARCH_X86_VENDOR_AMD;
else if (strcmp (id.idaschar, "HygonGenuine") == 0)
return ARCH_X86_VENDOR_HYGON;
else if (strcmp (id.idaschar, "GenuineIntel") == 0)
return ARCH_X86_VENDOR_INTEL;
#else
if (strcmp (id.idaschar, "GenuineIntel") == 0)
return ARCH_X86_VENDOR_INTEL;
else if (strcmp (id.idaschar, "AuthenticAMD") == 0)
return ARCH_X86_VENDOR_AMD;
else if (strcmp (id.idaschar, "HygonGenuine") == 0)
return ARCH_X86_VENDOR_HYGON;
else if (strcmp (id.idaschar, "CentaurHauls") == 0)
return ARCH_X86_VENDOR_CENTAUR;
else if (strcmp (id.idaschar, "CyrixInstead") == 0)
return ARCH_X86_VENDOR_CYRIX;
else if (strcmp (id.idaschar, "Geode by NSC") == 0)
return ARCH_X86_VENDOR_NSC;
else if (strcmp (id.idaschar, "GenuineTMx86") == 0 ||
strcmp (id.idaschar, "TransmetaCPU") == 0)
return ARCH_X86_VENDOR_TRANSMETA;
else if (strcmp (id.idaschar, "NexGenDriven") == 0)
return ARCH_X86_VENDOR_NEXGEN;
else if (strcmp (id.idaschar, "RiseRiseRise") == 0)
return ARCH_X86_VENDOR_RISE;
else if (strcmp (id.idaschar, "UMC UMC UMC ") == 0)
return ARCH_X86_VENDOR_UMC;
else if (strcmp (id.idaschar, "SiS SiS SiS ") == 0)
return ARCH_X86_VENDOR_SIS;
#endif
return ARCH_X86_VENDOR_UNKNOWN;
}
static guint32
arch_accel_intel (void)
{
guint32 caps = 0;
#ifdef USE_MMX
{
guint32 eax, ebx, ecx, edx;
cpuid (1, eax, ebx, ecx, edx);
if ((edx & ARCH_X86_INTEL_FEATURE_MMX) == 0)
return 0;
caps = GIMP_CPU_ACCEL_X86_MMX;
#ifdef USE_SSE
if (edx & ARCH_X86_INTEL_FEATURE_XMM)
caps |= GIMP_CPU_ACCEL_X86_SSE | GIMP_CPU_ACCEL_X86_MMXEXT;
if (edx & ARCH_X86_INTEL_FEATURE_XMM2)
caps |= GIMP_CPU_ACCEL_X86_SSE2;
if (ecx & ARCH_X86_INTEL_FEATURE_PNI)
caps |= GIMP_CPU_ACCEL_X86_SSE3;
if (ecx & ARCH_X86_INTEL_FEATURE_SSSE3)
caps |= GIMP_CPU_ACCEL_X86_SSSE3;
if (ecx & ARCH_X86_INTEL_FEATURE_SSE4_1)
caps |= GIMP_CPU_ACCEL_X86_SSE4_1;
if (ecx & ARCH_X86_INTEL_FEATURE_SSE4_2)
caps |= GIMP_CPU_ACCEL_X86_SSE4_2;
if (ecx & ARCH_X86_INTEL_FEATURE_AVX)
caps |= GIMP_CPU_ACCEL_X86_AVX;
#endif /* USE_SSE */
}
#endif /* USE_MMX */
return caps;
}
static guint32
arch_accel_amd (void)
{
guint32 caps;
caps = arch_accel_intel ();
#ifdef USE_MMX
{
guint32 eax, ebx, ecx, edx;
cpuid (0x80000000, eax, ebx, ecx, edx);
if (eax < 0x80000001)
return caps;
#ifdef USE_SSE
cpuid (0x80000001, eax, ebx, ecx, edx);
if (edx & ARCH_X86_AMD_FEATURE_3DNOW)
caps |= GIMP_CPU_ACCEL_X86_3DNOW;
if (edx & ARCH_X86_AMD_FEATURE_MMXEXT)
caps |= GIMP_CPU_ACCEL_X86_MMXEXT;
#endif /* USE_SSE */
}
#endif /* USE_MMX */
return caps;
}
static guint32
arch_accel_centaur (void)
{
guint32 caps;
caps = arch_accel_intel ();
#ifdef USE_MMX
{
guint32 eax, ebx, ecx, edx;
cpuid (0x80000000, eax, ebx, ecx, edx);
if (eax < 0x80000001)
return caps;
cpuid (0x80000001, eax, ebx, ecx, edx);
if (edx & ARCH_X86_CENTAUR_FEATURE_MMX)
caps |= GIMP_CPU_ACCEL_X86_MMX;
#ifdef USE_SSE
if (edx & ARCH_X86_CENTAUR_FEATURE_3DNOW)
caps |= GIMP_CPU_ACCEL_X86_3DNOW;
if (edx & ARCH_X86_CENTAUR_FEATURE_MMXEXT)
caps |= GIMP_CPU_ACCEL_X86_MMXEXT;
#endif /* USE_SSE */
}
#endif /* USE_MMX */
return caps;
}
static guint32
arch_accel_cyrix (void)
{
guint32 caps;
caps = arch_accel_intel ();
#ifdef USE_MMX
{
guint32 eax, ebx, ecx, edx;
cpuid (0, eax, ebx, ecx, edx);
if (eax != 2)
return caps;
cpuid (0x80000001, eax, ebx, ecx, edx);
if (edx & ARCH_X86_CYRIX_FEATURE_MMX)
caps |= GIMP_CPU_ACCEL_X86_MMX;
#ifdef USE_SSE
if (edx & ARCH_X86_CYRIX_FEATURE_MMXEXT)
caps |= GIMP_CPU_ACCEL_X86_MMXEXT;
#endif /* USE_SSE */
}
#endif /* USE_MMX */
return caps;
}
#ifdef USE_SSE
static jmp_buf sigill_return;
static void
sigill_handler (gint n)
{
longjmp (sigill_return, 1);
}
static gboolean
arch_accel_sse_os_support (void)
{
if (setjmp (sigill_return))
{
return FALSE;
}
else
{
signal (SIGILL, sigill_handler);
__asm__ __volatile__ ("xorps %xmm0, %xmm0");
signal (SIGILL, SIG_DFL);
}
return TRUE;
}
#endif /* USE_SSE */
static guint32
arch_accel (void)
{
guint32 caps;
X86Vendor vendor;
vendor = arch_get_vendor ();
switch (vendor)
{
case ARCH_X86_VENDOR_NONE:
caps = 0;
break;
case ARCH_X86_VENDOR_AMD:
case ARCH_X86_VENDOR_HYGON:
caps = arch_accel_amd ();
break;
case ARCH_X86_VENDOR_CENTAUR:
caps = arch_accel_centaur ();
break;
case ARCH_X86_VENDOR_CYRIX:
case ARCH_X86_VENDOR_NSC:
caps = arch_accel_cyrix ();
break;
/* check for what Intel speced, even if UNKNOWN */
default:
caps = arch_accel_intel ();
break;
}
#ifdef USE_SSE
if ((caps & GIMP_CPU_ACCEL_X86_SSE) && !arch_accel_sse_os_support ())
caps &= ~(GIMP_CPU_ACCEL_X86_SSE | GIMP_CPU_ACCEL_X86_SSE2);
#endif
return caps;
}
#endif /* ARCH_X86 && USE_MMX && __GNUC__ */
#if defined(ARCH_PPC) && defined (USE_ALTIVEC)
#if defined(HAVE_ALTIVEC_SYSCTL)
#include <sys/sysctl.h>
#define HAVE_ACCEL 1
static guint32
arch_accel (void)
{
gint sels[2] = { CTL_HW, HW_VECTORUNIT };
gboolean has_vu = FALSE;
gsize length = sizeof(has_vu);
gint err;
err = sysctl (sels, 2, &has_vu, &length, NULL, 0);
if (err == 0 && has_vu)
return GIMP_CPU_ACCEL_PPC_ALTIVEC;
return 0;
}
#elif defined(__GNUC__)
#define HAVE_ACCEL 1
static sigjmp_buf jmpbuf;
static volatile sig_atomic_t canjump = 0;
static void
sigill_handler (gint sig)
{
if (!canjump)
{
signal (sig, SIG_DFL);
raise (sig);
}
canjump = 0;
siglongjmp (jmpbuf, 1);
}
static guint32
arch_accel (void)
{
signal (SIGILL, sigill_handler);
if (sigsetjmp (jmpbuf, 1))
{
signal (SIGILL, SIG_DFL);
return 0;
}
canjump = 1;
asm volatile ("mtspr 256, %0\n\t"
"vand %%v0, %%v0, %%v0"
:
: "r" (-1));
signal (SIGILL, SIG_DFL);
return GIMP_CPU_ACCEL_PPC_ALTIVEC;
}
#endif /* __GNUC__ */
#endif /* ARCH_PPC && USE_ALTIVEC */
static GimpCpuAccelFlags
cpu_accel (void)
{
#ifdef HAVE_ACCEL
static guint32 accel = ~0U;
if (accel != ~0U)
return accel;
accel = arch_accel ();
return (GimpCpuAccelFlags) accel;
#else /* !HAVE_ACCEL */
return GIMP_CPU_ACCEL_NONE;
#endif
}

View file

@ -0,0 +1,72 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
#ifndef __GIMP_CPU_ACCEL_H__
#define __GIMP_CPU_ACCEL_H__
G_BEGIN_DECLS
/**
* GimpCpuAccelFlags:
* @GIMP_CPU_ACCEL_NONE: None
* @GIMP_CPU_ACCEL_X86_MMX: MMX
* @GIMP_CPU_ACCEL_X86_3DNOW: 3dNow
* @GIMP_CPU_ACCEL_X86_MMXEXT: MMXEXT
* @GIMP_CPU_ACCEL_X86_SSE: SSE
* @GIMP_CPU_ACCEL_X86_SSE2: SSE2
* @GIMP_CPU_ACCEL_X86_SSE3: SSE3
* @GIMP_CPU_ACCEL_X86_SSSE3: SSSE3
* @GIMP_CPU_ACCEL_X86_SSE4_1: SSE4_1
* @GIMP_CPU_ACCEL_X86_SSE4_2: SSE4_2
* @GIMP_CPU_ACCEL_X86_AVX: AVX
* @GIMP_CPU_ACCEL_PPC_ALTIVEC: Altivec
*
* Types of detectable CPU accelerations
**/
typedef enum
{
GIMP_CPU_ACCEL_NONE = 0x0,
/* x86 accelerations */
GIMP_CPU_ACCEL_X86_MMX = 0x80000000,
GIMP_CPU_ACCEL_X86_3DNOW = 0x40000000,
GIMP_CPU_ACCEL_X86_MMXEXT = 0x20000000,
GIMP_CPU_ACCEL_X86_SSE = 0x10000000,
GIMP_CPU_ACCEL_X86_SSE2 = 0x08000000,
GIMP_CPU_ACCEL_X86_SSE3 = 0x02000000,
GIMP_CPU_ACCEL_X86_SSSE3 = 0x01000000,
GIMP_CPU_ACCEL_X86_SSE4_1 = 0x00800000,
GIMP_CPU_ACCEL_X86_SSE4_2 = 0x00400000,
GIMP_CPU_ACCEL_X86_AVX = 0x00200000,
/* powerpc accelerations */
GIMP_CPU_ACCEL_PPC_ALTIVEC = 0x04000000
} GimpCpuAccelFlags;
GimpCpuAccelFlags gimp_cpu_accel_get_support (void);
G_END_DECLS
#endif /* __GIMP_CPU_ACCEL_H__ */

View file

@ -0,0 +1,34 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpenv-private.h
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_ENV_PRIVATE_H__
#define __GIMP_ENV_PRIVATE_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
void gimp_env_init (gboolean plug_in);
G_END_DECLS
#endif /* __GIMP_ENV_PRIVATE_H__ */

1211
libgimpbase/gimpenv.c Normal file

File diff suppressed because it is too large Load diff

83
libgimpbase/gimpenv.h Normal file
View file

@ -0,0 +1,83 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpenv.h
* Copyright (C) 1999 Tor Lillqvist <tml@iki.fi>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
#ifndef __GIMP_ENV_H__
#define __GIMP_ENV_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
#ifdef G_OS_WIN32
# ifdef __GIMP_ENV_C__
# define GIMPVAR extern __declspec(dllexport)
# else /* !__GIMP_ENV_C__ */
# define GIMPVAR extern __declspec(dllimport)
# endif /* !__GIMP_ENV_C__ */
#else /* !G_OS_WIN32 */
# define GIMPVAR extern
#endif
GIMPVAR const guint gimp_major_version;
GIMPVAR const guint gimp_minor_version;
GIMPVAR const guint gimp_micro_version;
const gchar * gimp_directory (void) G_GNUC_CONST;
const gchar * gimp_installation_directory (void) G_GNUC_CONST;
const gchar * gimp_data_directory (void) G_GNUC_CONST;
const gchar * gimp_locale_directory (void) G_GNUC_CONST;
const gchar * gimp_sysconf_directory (void) G_GNUC_CONST;
const gchar * gimp_plug_in_directory (void) G_GNUC_CONST;
const gchar * gimp_cache_directory (void) G_GNUC_CONST;
const gchar * gimp_temp_directory (void) G_GNUC_CONST;
GFile * gimp_directory_file (const gchar *first_element,
...) G_GNUC_MALLOC;
GFile * gimp_installation_directory_file (const gchar *first_element,
...) G_GNUC_MALLOC;
GFile * gimp_data_directory_file (const gchar *first_element,
...) G_GNUC_MALLOC;
GFile * gimp_locale_directory_file (const gchar *first_element,
...) G_GNUC_MALLOC;
GFile * gimp_sysconf_directory_file (const gchar *first_element,
...) G_GNUC_MALLOC;
GFile * gimp_plug_in_directory_file (const gchar *first_element,
...) G_GNUC_MALLOC;
GList * gimp_path_parse (const gchar *path,
gint max_paths,
gboolean check,
GList **check_failed);
gchar * gimp_path_to_str (GList *path) G_GNUC_MALLOC;
void gimp_path_free (GList *path);
gchar * gimp_path_get_user_writable_dir (GList *path) G_GNUC_MALLOC;
G_END_DECLS
#endif /* __GIMP_ENV_H__ */

View file

@ -0,0 +1,230 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpexportoptions.h
* Copyright (C) 2024 Alx Sa.
*
* 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 <gegl.h>
#include "gimpbasetypes.h"
#include "gimpexportoptions.h"
/**
* SECTION: gimpexportoptions
* @title: gimpexportoptions
* @short_description: Generic Export Options
*
* A class holding generic export options.
* Note: right now, GIMP does not provide any generic export option to
* manipulate, and there is practically no reason for you to create this
* object yourself. In Export PDB procedure, or again in functions such
* as [func@Gimp.file_save], you may just pass %NULL.
*
* In the future, this object will enable to pass various generic
* options, such as ability to crop or resize images at export time.
**/
enum
{
PROP_0,
PROP_CAPABILITIES,
N_PROPS
};
struct _GimpExportOptions
{
GObject parent_instance;
GimpExportCapabilities capabilities;
};
static void gimp_export_options_finalize (GObject *object);
static void gimp_export_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_export_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE (GimpExportOptions, gimp_export_options, G_TYPE_OBJECT)
#define parent_class gimp_export_options_parent_class
static GParamSpec *props[N_PROPS] = { NULL, };
static void
gimp_export_options_class_init (GimpExportOptionsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gimp_export_options_finalize;
object_class->get_property = gimp_export_options_get_property;
object_class->set_property = gimp_export_options_set_property;
/**
* GimpExportOptions:capabilities:
*
* What [flags@ExportCapabilities] are supported.
*
* Since: 3.0.0
*/
props[PROP_CAPABILITIES] = g_param_spec_flags ("capabilities",
"Supported image capabilities",
NULL,
GIMP_TYPE_EXPORT_CAPABILITIES,
0,
G_PARAM_CONSTRUCT |
G_PARAM_READWRITE);
g_object_class_install_properties (object_class, N_PROPS, props);
}
static void
gimp_export_options_init (GimpExportOptions *options)
{
options->capabilities = 0;
}
static void
gimp_export_options_finalize (GObject *object)
{
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_export_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpExportOptions *options = GIMP_EXPORT_OPTIONS (object);
switch (property_id)
{
case PROP_CAPABILITIES:
options->capabilities = g_value_get_flags (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_export_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpExportOptions *options = GIMP_EXPORT_OPTIONS (object);
switch (property_id)
{
case PROP_CAPABILITIES:
g_value_set_flags (value, options->capabilities);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/*
* GIMP_TYPE_PARAM_EXPORT_OPTIONS
*/
static void gimp_param_export_options_class_init (GParamSpecClass *klass);
static void gimp_param_export_options_init (GParamSpec *pspec);
GType
gimp_param_export_options_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_export_options_class_init,
NULL, NULL,
sizeof (GParamSpecObject),
0,
(GInstanceInitFunc) gimp_param_export_options_init
};
type = g_type_register_static (G_TYPE_PARAM_OBJECT,
"GimpParamExportOptions", &info, 0);
}
return type;
}
static void
gimp_param_export_options_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_EXPORT_OPTIONS;
}
static void
gimp_param_export_options_init (GParamSpec *pspec)
{
}
/**
* gimp_param_spec_export_options:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecExportOptions specifying a
* #G_TYPE_INT property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer floating): The newly created #GimpParamSpecExportOptions.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_export_options (const gchar *name,
const gchar *nick,
const gchar *blurb,
GParamFlags flags)
{
GParamSpec *options_spec;
options_spec = g_param_spec_internal (GIMP_TYPE_PARAM_EXPORT_OPTIONS,
name, nick, blurb, flags);
g_return_val_if_fail (options_spec, NULL);
return options_spec;
}

View file

@ -0,0 +1,59 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpexportoptions.h
* Copyright (C) 2024 Alx Sa.
*
* 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/>.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
#ifndef __GIMP_EXPORT_OPTIONS_H__
#define __GIMP_EXPORT_OPTIONS_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
#define GIMP_TYPE_EXPORT_OPTIONS (gimp_export_options_get_type ())
#define GIMP_VALUE_HOLDS_EXPORT_OPTIONS(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_EXPORT_OPTIONS))
G_DECLARE_FINAL_TYPE (GimpExportOptions, gimp_export_options, GIMP, EXPORT_OPTIONS, GObject)
/*
* GIMP_TYPE_PARAM_EXPORT_OPTIONS
*/
#define GIMP_TYPE_PARAM_EXPORT_OPTIONS (gimp_param_export_options_get_type ())
#define GIMP_IS_PARAM_SPEC_EXPORT_OPTIONS(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_EXPORT_OPTIONS))
GType gimp_param_export_options_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_export_options (const gchar *name,
const gchar *nick,
const gchar *blurb,
GParamFlags flags);
G_END_DECLS
#endif /* __GIMP_EXPORT_OPTIONS_H__ */

97
libgimpbase/gimplimits.h Normal file
View file

@ -0,0 +1,97 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1999 Peter Mattis and Spencer Kimball
*
* gimplimits.h
* Copyright (C) 1999 Michael Natterer <mitschel@cs.tu-berlin.de>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
#ifndef __GIMP_LIMITS_H__
#define __GIMP_LIMITS_H__
G_BEGIN_DECLS
/**
* SECTION: gimplimits
* @title: gimplimits
* @short_description: Boundaries of some GIMP data types and some
* global constants.
*
* Boundaries of some GIMP data types and some global constants.
**/
/**
* GIMP_MIN_IMAGE_SIZE:
*
* The minimum width and height of a GIMP image in pixels.
**/
#define GIMP_MIN_IMAGE_SIZE 1
/**
* GIMP_MAX_IMAGE_SIZE:
*
* The maximum width and height of a GIMP image in pixels. This is a
* somewhat arbitrary value that can be used when an upper value for
* pixel sizes is needed; for example to give a spin button an upper
* limit.
**/
#define GIMP_MAX_IMAGE_SIZE 524288 /* 2^19 */
/**
* GIMP_MIN_RESOLUTION:
*
* The minimum resolution of a GIMP image in pixels per inch. This is
* a somewhat arbitrary value that can be used when a lower value for a
* resolution is needed. GIMP will not accept resolutions smaller than
* this value.
**/
#define GIMP_MIN_RESOLUTION 5e-3 /* shouldn't display as 0.000 */
/**
* GIMP_MAX_RESOLUTION:
*
* The maximum resolution of a GIMP image in pixels per inch. This is
* a somewhat arbitrary value that can be used to when an upper value
* for a resolution is needed. GIMP will not accept resolutions larger
* than this value.
**/
#define GIMP_MAX_RESOLUTION 1048576.0
/**
* GIMP_MAX_MEMSIZE:
*
* A large but arbitrary value that can be used when an upper limit
* for a memory size (in bytes) is needed. It is smaller than
* %G_MAXDOUBLE since the #GimpMemsizeEntry doesn't handle larger
* values.
**/
#define GIMP_MAX_MEMSIZE ((guint64) 1 << 42) /* 4 terabyte;
* needs a 64bit variable
* and must be < G_MAXDOUBLE
*/
G_END_DECLS
#endif /* __GIMP_LIMITS_H__ */

273
libgimpbase/gimpmemsize.c Normal file
View file

@ -0,0 +1,273 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <errno.h>
#include <glib-object.h>
#include "gimpbasetypes.h"
#include "gimpmemsize.h"
#include "libgimp/libgimp-intl.h"
/**
* SECTION: gimpmemsize
* @title: gimpmemsize
* @short_description: Functions to (de)serialize a given memory size.
*
* Functions to (de)serialize a given memory size.
**/
static void memsize_to_string (const GValue *src_value,
GValue *dest_value);
static void string_to_memsize (const GValue *src_value,
GValue *dest_value);
GType
gimp_memsize_get_type (void)
{
static GType memsize_type = 0;
if (! memsize_type)
{
const GTypeInfo type_info = { 0, };
memsize_type = g_type_register_static (G_TYPE_UINT64, "GimpMemsize",
&type_info, 0);
g_value_register_transform_func (memsize_type, G_TYPE_STRING,
memsize_to_string);
g_value_register_transform_func (G_TYPE_STRING, memsize_type,
string_to_memsize);
}
return memsize_type;
}
/**
* gimp_memsize_serialize:
* @memsize: memory size in bytes
*
* Creates a string representation of a given memory size. This string
* can be parsed by gimp_memsize_deserialize() and can thus be used in
* config files. It should not be displayed to the user. If you need a
* nice human-readable string please use g_format_size().
*
* Returns: A newly allocated string representation of @memsize.
*
* Since: 2.2
**/
gchar *
gimp_memsize_serialize (guint64 memsize)
{
if (memsize > (1 << 30) && memsize % (1 << 30) == 0)
return g_strdup_printf ("%" G_GUINT64_FORMAT "G", memsize >> 30);
else if (memsize > (1 << 20) && memsize % (1 << 20) == 0)
return g_strdup_printf ("%" G_GUINT64_FORMAT "M", memsize >> 20);
else if (memsize > (1 << 10) && memsize % (1 << 10) == 0)
return g_strdup_printf ("%" G_GUINT64_FORMAT "k", memsize >> 10);
else
return g_strdup_printf ("%" G_GUINT64_FORMAT, memsize);
}
/**
* gimp_memsize_deserialize:
* @string: a string as returned by gimp_memsize_serialize()
* @memsize: (out): return location for memory size in bytes
*
* Parses a string representation of a memory size as returned by
* gimp_memsize_serialize().
*
* Returns: %TRUE if the @string was successfully parsed and
* @memsize has been set, %FALSE otherwise.
*
* Since: 2.2
**/
gboolean
gimp_memsize_deserialize (const gchar *string,
guint64 *memsize)
{
gchar *end;
guint64 size;
g_return_val_if_fail (string != NULL, FALSE);
g_return_val_if_fail (memsize != NULL, FALSE);
size = g_ascii_strtoull (string, &end, 0);
if (size == G_MAXUINT64 && errno == ERANGE)
return FALSE;
if (end && *end)
{
guint shift;
switch (g_ascii_tolower (*end))
{
case 'b':
shift = 0;
break;
case 'k':
shift = 10;
break;
case 'm':
shift = 20;
break;
case 'g':
shift = 30;
break;
default:
return FALSE;
}
/* protect against overflow */
if (shift)
{
guint64 limit = G_MAXUINT64 >> shift;
if (size != (size & limit))
return FALSE;
size <<= shift;
}
}
*memsize = size;
return TRUE;
}
static void
memsize_to_string (const GValue *src_value,
GValue *dest_value)
{
g_value_take_string (dest_value,
gimp_memsize_serialize (g_value_get_uint64 (src_value)));
}
static void
string_to_memsize (const GValue *src_value,
GValue *dest_value)
{
const gchar *str;
guint64 memsize;
str = g_value_get_string (src_value);
if (str && gimp_memsize_deserialize (str, &memsize))
{
g_value_set_uint64 (dest_value, memsize);
}
else
{
g_warning ("Can't convert string to GimpMemsize.");
}
}
/*
* GIMP_TYPE_PARAM_MEMSIZE
*/
static void gimp_param_memsize_class_init (GParamSpecClass *class);
/**
* gimp_param_memsize_get_type:
*
* Reveals the object type
*
* Returns: the #GType for a memsize object
*
* Since: 2.4
**/
GType
gimp_param_memsize_get_type (void)
{
static GType spec_type = 0;
if (! spec_type)
{
const GTypeInfo type_info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_memsize_class_init,
NULL, NULL,
sizeof (GParamSpecUInt64),
0, NULL, NULL
};
spec_type = g_type_register_static (G_TYPE_PARAM_UINT64,
"GimpParamMemsize",
&type_info, 0);
}
return spec_type;
}
static void
gimp_param_memsize_class_init (GParamSpecClass *class)
{
class->value_type = GIMP_TYPE_MEMSIZE;
}
/**
* gimp_param_spec_memsize:
* @name: Canonical name of the param
* @nick: Nickname of the param
* @blurb: Brief description of param.
* @minimum: Smallest allowed value of the parameter.
* @maximum: Largest allowed value of the parameter.
* @default_value: Value to use if none is assigned.
* @flags: a combination of #GParamFlags
*
* Creates a param spec to hold a memory size value.
* See g_param_spec_internal() for more information.
*
* Returns: (transfer full): a newly allocated #GParamSpec instance
*
* Since: 2.4
**/
GParamSpec *
gimp_param_spec_memsize (const gchar *name,
const gchar *nick,
const gchar *blurb,
guint64 minimum,
guint64 maximum,
guint64 default_value,
GParamFlags flags)
{
GParamSpecUInt64 *pspec;
pspec = g_param_spec_internal (GIMP_TYPE_PARAM_MEMSIZE,
name, nick, blurb, flags);
pspec->minimum = minimum;
pspec->maximum = maximum;
pspec->default_value = default_value;
return G_PARAM_SPEC (pspec);
}

65
libgimpbase/gimpmemsize.h Normal file
View file

@ -0,0 +1,65 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
#ifndef __GIMP_MEMSIZE_H__
#define __GIMP_MEMSIZE_H__
G_BEGIN_DECLS
/**
* GIMP_TYPE_MEMSIZE:
*
* #GIMP_TYPE_MEMSIZE is a #GType derived from #G_TYPE_UINT64.
**/
#define GIMP_TYPE_MEMSIZE (gimp_memsize_get_type ())
#define GIMP_VALUE_HOLDS_MEMSIZE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_MEMSIZE))
GType gimp_memsize_get_type (void) G_GNUC_CONST;
gchar * gimp_memsize_serialize (guint64 memsize) G_GNUC_MALLOC;
gboolean gimp_memsize_deserialize (const gchar *string,
guint64 *memsize);
/*
* GIMP_TYPE_PARAM_MEMSIZE
*/
#define GIMP_TYPE_PARAM_MEMSIZE (gimp_param_memsize_get_type ())
#define GIMP_IS_PARAM_SPEC_MEMSIZE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_MEMSIZE))
GType gimp_param_memsize_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_memsize (const gchar *name,
const gchar *nick,
const gchar *blurb,
guint64 minimum,
guint64 maximum,
guint64 default_value,
GParamFlags flags);
G_END_DECLS
#endif /* __GIMP_MEMSIZE_H__ */

2141
libgimpbase/gimpmetadata.c Normal file

File diff suppressed because it is too large Load diff

158
libgimpbase/gimpmetadata.h Normal file
View file

@ -0,0 +1,158 @@
/* LIBGIMPBASE - The GIMP Basic Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpmetadata.h
* Copyright (C) 2013 Hartmut Kuhse <hartmutkuhse@src.gnome.org>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_METADATA_H__
#define __GIMP_METADATA_H__
G_BEGIN_DECLS
#include <gexiv2/gexiv2.h>
#define GIMP_TYPE_METADATA (gimp_metadata_get_type ())
G_DECLARE_FINAL_TYPE (GimpMetadata, gimp_metadata, GIMP, METADATA, GExiv2Metadata)
/**
* GimpMetadataLoadFlags:
* @GIMP_METADATA_LOAD_NONE: Do not load the metadata
* @GIMP_METADATA_LOAD_COMMENT: Load the comment
* @GIMP_METADATA_LOAD_RESOLUTION: Load the resolution
* @GIMP_METADATA_LOAD_ORIENTATION: Load the orientation (rotation)
* @GIMP_METADATA_LOAD_COLORSPACE: Load the colorspace
* @GIMP_METADATA_LOAD_ALL: Load all of the above
*
* What metadata to load when importing images.
**/
typedef enum
{
GIMP_METADATA_LOAD_NONE = 0,
GIMP_METADATA_LOAD_COMMENT = 1 << 0,
GIMP_METADATA_LOAD_RESOLUTION = 1 << 1,
GIMP_METADATA_LOAD_ORIENTATION = 1 << 2,
GIMP_METADATA_LOAD_COLORSPACE = 1 << 3,
GIMP_METADATA_LOAD_ALL = 0xffffffff
} GimpMetadataLoadFlags;
/**
* GimpMetadataSaveFlags:
* @GIMP_METADATA_SAVE_EXIF: Save EXIF
* @GIMP_METADATA_SAVE_XMP: Save XMP
* @GIMP_METADATA_SAVE_IPTC: Save IPTC
* @GIMP_METADATA_SAVE_THUMBNAIL: Save a thumbnail of the image
* @GIMP_METADATA_SAVE_COLOR_PROFILE: Save the image's color profile
* Since: 2.10.10
* @GIMP_METADATA_SAVE_COMMENT: Save the image's comment
* Since: 3.0
* @GIMP_METADATA_SAVE_ALL: Save all of the above
*
* What kinds of metadata to save when exporting images.
**/
typedef enum
{
GIMP_METADATA_SAVE_EXIF = 1 << 0,
GIMP_METADATA_SAVE_XMP = 1 << 1,
GIMP_METADATA_SAVE_IPTC = 1 << 2,
GIMP_METADATA_SAVE_THUMBNAIL = 1 << 3,
GIMP_METADATA_SAVE_COLOR_PROFILE = 1 << 4,
GIMP_METADATA_SAVE_COMMENT = 1 << 5,
GIMP_METADATA_SAVE_ALL = 0xffffffff
} GimpMetadataSaveFlags;
/**
* GimpMetadataColorspace:
* @GIMP_METADATA_COLORSPACE_UNSPECIFIED: Unspecified
* @GIMP_METADATA_COLORSPACE_UNCALIBRATED: Uncalibrated
* @GIMP_METADATA_COLORSPACE_SRGB: sRGB
* @GIMP_METADATA_COLORSPACE_ADOBERGB: Adobe RGB
*
* Well-defined colorspace information available from metadata
**/
typedef enum
{
GIMP_METADATA_COLORSPACE_UNSPECIFIED,
GIMP_METADATA_COLORSPACE_UNCALIBRATED,
GIMP_METADATA_COLORSPACE_SRGB,
GIMP_METADATA_COLORSPACE_ADOBERGB
} GimpMetadataColorspace;
GimpMetadata * gimp_metadata_new (void);
GimpMetadata * gimp_metadata_duplicate (GimpMetadata *metadata);
GimpMetadata * gimp_metadata_deserialize (const gchar *metadata_xml);
gchar * gimp_metadata_serialize (GimpMetadata *metadata);
gchar * gimp_metadata_get_guid (void);
void gimp_metadata_add_xmp_history (GimpMetadata *metadata,
gchar *state_status);
GimpMetadata * gimp_metadata_load_from_file (GFile *file,
GError **error);
gboolean gimp_metadata_save_to_file (GimpMetadata *metadata,
GFile *file,
GError **error);
gboolean gimp_metadata_set_from_exif (GimpMetadata *metadata,
const guchar *exif_data,
gint exif_data_length,
GError **error);
gboolean gimp_metadata_set_from_iptc (GimpMetadata *metadata,
const guchar *iptc_data,
gint iptc_data_length,
GError **error);
gboolean gimp_metadata_set_from_xmp (GimpMetadata *metadata,
const guchar *xmp_data,
gint xmp_data_length,
GError **error);
void gimp_metadata_set_pixel_size (GimpMetadata *metadata,
gint width,
gint height);
void gimp_metadata_set_bits_per_sample (GimpMetadata *metadata,
gint bits_per_sample);
gboolean gimp_metadata_get_resolution (GimpMetadata *metadata,
gdouble *xres,
gdouble *yres,
GimpUnit **unit);
void gimp_metadata_set_resolution (GimpMetadata *metadata,
gdouble xres,
gdouble yres,
GimpUnit *unit);
void gimp_metadata_set_creation_date (GimpMetadata *metadata,
GDateTime *datetime);
GimpMetadataColorspace
gimp_metadata_get_colorspace (GimpMetadata *metadata);
void gimp_metadata_set_colorspace (GimpMetadata *metadata,
GimpMetadataColorspace colorspace);
gboolean gimp_metadata_is_tag_supported (const gchar *tag,
const gchar *mime_type);
G_END_DECLS
#endif /* __GIMP_METADATA_H__ */

1510
libgimpbase/gimpparamspecs.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,416 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
*
* gimpparamspecs.h
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
#ifndef __GIMP_PARAM_SPECS_H__
#define __GIMP_PARAM_SPECS_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
/**
* GIMP_PARAM_NO_VALIDATE:
*
* Since 3.0
*/
#define GIMP_PARAM_NO_VALIDATE (1 << (0 + G_PARAM_USER_SHIFT))
/**
* GIMP_PARAM_DONT_SERIALIZE:
*
* This property will be ignored when serializing and deserializing.
* This is useful for GimpProcedure arguments for which you never want
* the last run values to be restored.
*
* Since 3.0
*/
#define GIMP_PARAM_DONT_SERIALIZE (1 << (1 + G_PARAM_USER_SHIFT))
/**
* GIMP_PARAM_FLAG_SHIFT:
*
* Minimum shift count to be used for libgimpconfig defined
* [flags@GObject.ParamFlags] (see libgimpconfig/gimpconfig-params.h).
*/
#define GIMP_PARAM_FLAG_SHIFT (2 + G_PARAM_USER_SHIFT)
/**
* GIMP_PARAM_STATIC_STRINGS:
*
* Since: 2.4
**/
#define GIMP_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | \
G_PARAM_STATIC_NICK | \
G_PARAM_STATIC_BLURB)
/**
* GIMP_PARAM_READABLE:
*
* Since: 2.4
**/
#define GIMP_PARAM_READABLE (G_PARAM_READABLE | \
GIMP_PARAM_STATIC_STRINGS)
/**
* GIMP_PARAM_WRITABLE:
*
* Since: 2.4
**/
#define GIMP_PARAM_WRITABLE (G_PARAM_WRITABLE | \
GIMP_PARAM_STATIC_STRINGS)
/**
* GIMP_PARAM_READWRITE:
*
* Since: 2.4
**/
#define GIMP_PARAM_READWRITE (G_PARAM_READWRITE | \
GIMP_PARAM_STATIC_STRINGS)
/*
* GIMP_TYPE_PARAM_OBJECT
*/
#define GIMP_TYPE_PARAM_OBJECT (gimp_param_object_get_type ())
#define GIMP_PARAM_SPEC_OBJECT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_OBJECT, GimpParamSpecObject))
#define GIMP_PARAM_SPEC_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PARAM_OBJECT, GimpParamSpecObjectClass))
#define GIMP_IS_PARAM_SPEC_OBJECT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_OBJECT))
#define GIMP_IS_PARAM_SPEC_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PARAM_OBJECT))
#define GIMP_PARAM_SPEC_OBJECT_GET_CLASS(pspec) (G_TYPE_INSTANCE_GET_CLASS ((pspec), G_TYPE_PARAM_OBJECT, GimpParamSpecObjectClass))
typedef struct _GimpParamSpecObject GimpParamSpecObject;
typedef struct _GimpParamSpecObjectClass GimpParamSpecObjectClass;
struct _GimpParamSpecObject
{
GParamSpecObject parent_instance;
/*< private >*/
GObject *_default_value;
gboolean _has_default;
};
struct _GimpParamSpecObjectClass
{
/* XXX: vapigen fails with the following error without the private
* comment:
* > error: The type name `GLib.ParamSpecClass' could not be found
* Not sure why it doesn't search for GObject.ParamSpecClass instead.
* Anyway putting it private is good enough and hides the parent_class
* to bindings.
*/
/*< private >*/
GParamSpecClass parent_class;
GParamSpec * (* duplicate) (GParamSpec *pspec);
GObject * (* get_default) (GParamSpec *pspec);
/* Padding for future expansion */
void (*_gimp_reserved0) (void);
void (*_gimp_reserved1) (void);
void (*_gimp_reserved2) (void);
void (*_gimp_reserved3) (void);
void (*_gimp_reserved4) (void);
void (*_gimp_reserved5) (void);
void (*_gimp_reserved6) (void);
void (*_gimp_reserved7) (void);
void (*_gimp_reserved8) (void);
void (*_gimp_reserved9) (void);
};
GType gimp_param_object_get_type (void) G_GNUC_CONST;
GObject * gimp_param_spec_object_get_default (GParamSpec *pspec);
void gimp_param_spec_object_set_default (GParamSpec *pspec,
GObject *default_value);
gboolean gimp_param_spec_object_has_default (GParamSpec *pspec);
GParamSpec * gimp_param_spec_object_duplicate (GParamSpec *pspec);
/*
* GIMP_TYPE_PARAM_FILE
*/
#define GIMP_VALUE_HOLDS_FILE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FILE))
#define GIMP_TYPE_PARAM_FILE (gimp_param_file_get_type ())
#define GIMP_IS_PARAM_SPEC_FILE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_FILE))
GType gimp_param_file_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_file (const gchar *name,
const gchar *nick,
const gchar *blurb,
GimpFileChooserAction action,
gboolean none_ok,
GFile *default_value,
GParamFlags flags);
GimpFileChooserAction gimp_param_spec_file_get_action (GParamSpec *pspec);
void gimp_param_spec_file_set_action (GParamSpec *pspec,
GimpFileChooserAction action);
gboolean gimp_param_spec_file_none_allowed (GParamSpec *pspec);
/*
* GIMP_TYPE_ARRAY
*/
/**
* GimpArray:
* @data: (array length=length): pointer to the array's data.
* @length: length of @data, in bytes.
* @static_data: whether @data points to statically allocated memory.
**/
typedef struct _GimpArray GimpArray;
struct _GimpArray
{
guint8 *data;
gsize length;
gboolean static_data;
};
GimpArray * gimp_array_new (const guint8 *data,
gsize length,
gboolean static_data);
GimpArray * gimp_array_copy (const GimpArray *array);
void gimp_array_free (GimpArray *array);
#define GIMP_TYPE_ARRAY (gimp_array_get_type ())
#define GIMP_VALUE_HOLDS_ARRAY(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_ARRAY))
GType gimp_array_get_type (void) G_GNUC_CONST;
/*
* GIMP_TYPE_PARAM_ARRAY
*/
#define GIMP_TYPE_PARAM_ARRAY (gimp_param_array_get_type ())
#define GIMP_IS_PARAM_SPEC_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_ARRAY))
GType gimp_param_array_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_array (const gchar *name,
const gchar *nick,
const gchar *blurb,
GParamFlags flags);
/*
* GIMP_TYPE_INT32_ARRAY
*/
#define GIMP_TYPE_INT32_ARRAY (gimp_int32_array_get_type ())
#define GIMP_VALUE_HOLDS_INT32_ARRAY(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_INT32_ARRAY))
GType gimp_int32_array_get_type (void) G_GNUC_CONST;
const gint32 * gimp_int32_array_get_values (GimpArray *array,
gsize *length);
void gimp_int32_array_set_values (GimpArray *array,
const gint32 *values,
gsize length,
gboolean static_data);
/*
* GIMP_TYPE_PARAM_INT32_ARRAY
*/
#define GIMP_TYPE_PARAM_INT32_ARRAY (gimp_param_int32_array_get_type ())
#define GIMP_IS_PARAM_SPEC_INT32_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_INT32_ARRAY))
GType gimp_param_int32_array_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_int32_array (const gchar *name,
const gchar *nick,
const gchar *blurb,
GParamFlags flags);
const gint32 * gimp_value_get_int32_array (const GValue *value,
gsize *length);
gint32 * gimp_value_dup_int32_array (const GValue *value,
gsize *length);
void gimp_value_set_int32_array (GValue *value,
const gint32 *data,
gsize length);
void gimp_value_set_static_int32_array (GValue *value,
const gint32 *data,
gsize length);
void gimp_value_take_int32_array (GValue *value,
gint32 *data,
gsize length);
/*
* GIMP_TYPE_DOUBLE_ARRAY
*/
#define GIMP_TYPE_DOUBLE_ARRAY (gimp_double_array_get_type ())
#define GIMP_VALUE_HOLDS_DOUBLE_ARRAY(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_DOUBLE_ARRAY))
GType gimp_double_array_get_type (void) G_GNUC_CONST;
const gdouble * gimp_double_array_get_values (GimpArray *array,
gsize *length);
void gimp_double_array_set_values (GimpArray *array,
const gdouble *values,
gsize length,
gboolean static_data);
/*
* GIMP_TYPE_PARAM_DOUBLE_ARRAY
*/
#define GIMP_TYPE_PARAM_DOUBLE_ARRAY (gimp_param_double_array_get_type ())
#define GIMP_IS_PARAM_SPEC_DOUBLE_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_DOUBLE_ARRAY))
GType gimp_param_double_array_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_double_array (const gchar *name,
const gchar *nick,
const gchar *blurb,
GParamFlags flags);
const gdouble * gimp_value_get_double_array (const GValue *value,
gsize *length);
gdouble * gimp_value_dup_double_array (const GValue *value,
gsize *length);
void gimp_value_set_double_array (GValue *value,
const gdouble *data,
gsize length);
void gimp_value_set_static_double_array (GValue *value,
const gdouble *data,
gsize length);
void gimp_value_take_double_array (GValue *value,
gdouble *data,
gsize length);
/*
* GIMP_TYPE_COLOR_ARRAY
*/
/**
* GimpColorArray:
*
* A boxed type which is nothing more than an alias to a %NULL-terminated array
* of [class@Gegl.Color].
*
* The code fragments in the following example show the use of a property of
* type %GIMP_TYPE_COLOR_ARRAY with g_object_class_install_property(),
* g_object_set() and g_object_get().
*
* ```C
* g_object_class_install_property (object_class,
* PROP_COLORS,
* g_param_spec_boxed ("colors",
* _("Colors"),
* _("List of colors"),
* GIMP_TYPE_COLOR_ARRAY,
* G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
*
* GeglColor *colors[] = { gegl_color_new ("red"), gegl_color_new ("blue"), NULL };
*
* g_object_set (obj, "colors", colors, NULL);
*
* GeglColors **colors;
*
* g_object_get (obj, "colors", &colors, NULL);
* gimp_color_array_free (colors);
* ```
*
* Since: 3.0
*/
typedef GeglColor** GimpColorArray;
#define GIMP_TYPE_COLOR_ARRAY (gimp_color_array_get_type ())
#define GIMP_VALUE_HOLDS_COLOR_ARRAY(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_COLOR_ARRAY))
GType gimp_color_array_get_type (void) G_GNUC_CONST;
GimpColorArray gimp_color_array_copy (GimpColorArray array);
void gimp_color_array_free (GimpColorArray array);
gint gimp_color_array_get_length (GimpColorArray array);
/*
* GIMP_TYPE_CORE_OBJECT_ARRAY
*/
/**
* GimpCoreObjectArray:
*
* A boxed type which is nothing more than an alias to a %NULL-terminated array
* of [class@GObject.Object]. No reference is being hold on contents
* because core objects are owned by `libgimp`.
*
* The reason of existence for this alias is to have common arrays of
* objects as a boxed type easy to use as plug-in's procedure argument.
*
* You should never have to interact with this type directly, though
* [func@Gimp.core_object_array_get_length] might be convenient.
*
* Since: 3.0
*/
typedef GObject** GimpCoreObjectArray;
#define GIMP_TYPE_CORE_OBJECT_ARRAY (gimp_core_object_array_get_type ())
#define GIMP_VALUE_HOLDS_CORE_OBJECT_ARRAY(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_CORE_OBJECT_ARRAY))
GType gimp_core_object_array_get_type (void) G_GNUC_CONST;
gsize gimp_core_object_array_get_length (GObject **array);
/*
* GIMP_TYPE_PARAM_CORE_OBJECT_ARRAY
*/
#define GIMP_TYPE_PARAM_CORE_OBJECT_ARRAY (gimp_param_core_object_array_get_type ())
#define GIMP_IS_PARAM_SPEC_CORE_OBJECT_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_CORE_OBJECT_ARRAY))
GType gimp_param_core_object_array_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_core_object_array (const gchar *name,
const gchar *nick,
const gchar *blurb,
GType object_type,
GParamFlags flags);
GType gimp_param_spec_core_object_array_get_object_type (GParamSpec *pspec);
G_END_DECLS
#endif /* __GIMP_PARAM_SPECS_H__ */

438
libgimpbase/gimpparasite.c Normal file
View file

@ -0,0 +1,438 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpparasite.c
* Copyright (C) 1998 Jay Cox <jaycox@gimp.org>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#include <glib-object.h>
#ifdef G_OS_WIN32
#include <process.h> /* For _getpid() */
#endif
#include "gimpbasetypes.h"
#include "gimpparasite.h"
/**
* SECTION: gimpparasite
* @title: GimpParasite
* @short_description: Arbitrary pieces of data which can be attached
* to various GIMP objects.
* @see_also: gimp_image_attach_parasite(), gimp_item_attach_parasite(),
* gimp_attach_parasite() and their related functions.
*
* Arbitrary pieces of data which can be attached to various GIMP objects.
**/
/*
* GIMP_TYPE_PARASITE
*/
G_DEFINE_BOXED_TYPE (GimpParasite, gimp_parasite, gimp_parasite_copy, gimp_parasite_free)
/*
* GIMP_TYPE_PARAM_PARASITE
*/
static void gimp_param_parasite_class_init (GParamSpecClass *class);
static void gimp_param_parasite_init (GParamSpec *pspec);
static gboolean gimp_param_parasite_validate (GParamSpec *pspec,
GValue *value);
static gint gimp_param_parasite_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2);
GType
gimp_param_parasite_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo type_info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_parasite_class_init,
NULL, NULL,
sizeof (GParamSpecBoxed),
0,
(GInstanceInitFunc) gimp_param_parasite_init
};
type = g_type_register_static (G_TYPE_PARAM_BOXED,
"GimpParamParasite",
&type_info, 0);
}
return type;
}
static void
gimp_param_parasite_class_init (GParamSpecClass *class)
{
class->value_type = GIMP_TYPE_PARASITE;
class->value_validate = gimp_param_parasite_validate;
class->values_cmp = gimp_param_parasite_values_cmp;
}
static void
gimp_param_parasite_init (GParamSpec *pspec)
{
}
static gboolean
gimp_param_parasite_validate (GParamSpec *pspec,
GValue *value)
{
GimpParasite *parasite = value->data[0].v_pointer;
if (! parasite)
{
return TRUE;
}
else if (parasite->name == NULL ||
*parasite->name == '\0' ||
! g_utf8_validate (parasite->name, -1, NULL) ||
(parasite->size == 0 && parasite->data != NULL) ||
(parasite->size > 0 && parasite->data == NULL))
{
g_value_set_boxed (value, NULL);
return TRUE;
}
return FALSE;
}
static gint
gimp_param_parasite_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2)
{
GimpParasite *parasite1 = value1->data[0].v_pointer;
GimpParasite *parasite2 = value2->data[0].v_pointer;
/* try to return at least *something*, it's useless anyway... */
if (! parasite1)
return parasite2 != NULL ? -1 : 0;
else if (! parasite2)
return parasite1 != NULL;
else
return gimp_parasite_compare (parasite1, parasite2);
}
/**
* gimp_param_spec_parasite:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecParasite specifying a
* [type@Parasite] property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecParasite.
*
* Since: 2.4
**/
GParamSpec *
gimp_param_spec_parasite (const gchar *name,
const gchar *nick,
const gchar *blurb,
GParamFlags flags)
{
GParamSpec *parasite_spec;
parasite_spec = g_param_spec_internal (GIMP_TYPE_PARAM_PARASITE,
name, nick, blurb, flags);
return parasite_spec;
}
#ifdef DEBUG
static void
gimp_parasite_print (GimpParasite *parasite)
{
if (parasite == NULL)
{
g_print ("pid %d: attempt to print a null parasite\n", getpid ());
return;
}
g_print ("pid %d: parasite: %p\n", getpid (), parasite);
if (parasite->name)
g_print ("\tname: %s\n", parasite->name);
else
g_print ("\tname: NULL\n");
g_print ("\tflags: %d\n", parasite->flags);
g_print ("\tsize: %d\n", parasite->size);
if (parasite->size > 0)
g_print ("\tdata: %p\n", parasite->data);
}
#endif
/**
* gimp_parasite_new:
* @name: the new #GimpParasite name.
* @flags: see libgimpbase/gimpparasite.h macros.
* @size: the size of @data, including a terminal %NULL byte if needed.
* @data: (nullable) (array length=size) (element-type char): the data to save in a parasite.
*
* Creates a new parasite and save @data which may be a proper text (in
* which case you may want to set @size as strlen(@data) + 1) or not.
*
* Returns: (transfer full): a new #GimpParasite.
*/
GimpParasite *
gimp_parasite_new (const gchar *name,
guint32 flags,
guint32 size,
gconstpointer data)
{
GimpParasite *parasite;
if (! (name && *name))
return NULL;
parasite = g_slice_new (GimpParasite);
parasite->name = g_strdup (name);
parasite->flags = (flags & 0xFF);
parasite->size = size;
if (size)
parasite->data = g_memdup2 (data, size);
else
parasite->data = NULL;
return parasite;
}
/**
* gimp_parasite_free:
* @parasite: a #GimpParasite
*
* Free @parasite's dynamically allocated memory.
*/
void
gimp_parasite_free (GimpParasite *parasite)
{
if (parasite == NULL)
return;
if (parasite->name)
g_free (parasite->name);
if (parasite->data)
g_free (parasite->data);
g_slice_free (GimpParasite, parasite);
}
/**
* gimp_parasite_is_type:
* @parasite: a #GimpParasite
* @name: a parasite name.
*
* Compare parasite's names.
*
* Returns: %TRUE if @parasite is named @name, %FALSE otherwise.
*/
gboolean
gimp_parasite_is_type (const GimpParasite *parasite,
const gchar *name)
{
if (!parasite || !parasite->name)
return FALSE;
return (strcmp (parasite->name, name) == 0);
}
/**
* gimp_parasite_copy:
* @parasite: a #GimpParasite
*
* Create a new parasite with all the same values.
*
* Returns: (transfer full): a newly allocated #GimpParasite with same contents.
*/
GimpParasite *
gimp_parasite_copy (const GimpParasite *parasite)
{
if (parasite == NULL)
return NULL;
return gimp_parasite_new (parasite->name, parasite->flags,
parasite->size, parasite->data);
}
/**
* gimp_parasite_compare:
* @a: a #GimpParasite
* @b: a #GimpParasite
*
* Compare parasite's contents.
*
* Returns: %TRUE if @a and @b have same contents, %FALSE otherwise.
*/
gboolean
gimp_parasite_compare (const GimpParasite *a,
const GimpParasite *b)
{
if (a && b &&
a->name && b->name &&
strcmp (a->name, b->name) == 0 &&
a->flags == b->flags &&
a->size == b->size)
{
if (a->data == NULL && b->data == NULL)
return TRUE;
else if (a->data && b->data && memcmp (a->data, b->data, a->size) == 0)
return TRUE;
}
return FALSE;
}
/**
* gimp_parasite_get_flags:
* @parasite: a #GimpParasite
*
* Returns: @parasite flags.
*/
gulong
gimp_parasite_get_flags (const GimpParasite *parasite)
{
if (parasite == NULL)
return 0;
return parasite->flags;
}
/**
* gimp_parasite_is_persistent:
* @parasite: a #GimpParasite
*
* Returns: %TRUE if @parasite is persistent, %FALSE otherwise.
*/
gboolean
gimp_parasite_is_persistent (const GimpParasite *parasite)
{
if (parasite == NULL)
return FALSE;
return (parasite->flags & GIMP_PARASITE_PERSISTENT);
}
/**
* gimp_parasite_is_undoable:
* @parasite: a #GimpParasite
*
* Returns: %TRUE if @parasite is undoable, %FALSE otherwise.
*/
gboolean
gimp_parasite_is_undoable (const GimpParasite *parasite)
{
if (parasite == NULL)
return FALSE;
return (parasite->flags & GIMP_PARASITE_UNDOABLE);
}
/**
* gimp_parasite_has_flag:
* @parasite: a #GimpParasite
* @flag: a parasite flag
*
* Returns: %TRUE if @parasite has @flag set, %FALSE otherwise.
*/
gboolean
gimp_parasite_has_flag (const GimpParasite *parasite,
gulong flag)
{
if (parasite == NULL)
return FALSE;
return (parasite->flags & flag);
}
/**
* gimp_parasite_get_name:
* @parasite: a #GimpParasite
*
* Returns: @parasite's name.
*/
const gchar *
gimp_parasite_get_name (const GimpParasite *parasite)
{
if (parasite)
return parasite->name;
return NULL;
}
/**
* gimp_parasite_get_data:
* @parasite: a #GimpParasite
* @num_bytes: (out) (nullable): size of the returned data.
*
* Gets the parasite's data. It may not necessarily be text, nor is it
* guaranteed to be %NULL-terminated. It is your responsibility to know
* how to deal with this data.
* Even when you expect a nul-terminated string, it is advised not to
* assume the returned data to be, as parasites can be edited by third
* party scripts. You may end up reading out-of-bounds data. So you
* should only ignore @num_bytes when you all you care about is checking
* if the parasite has contents.
*
* Returns: (array length=num_bytes) (element-type char): parasite's data.
*/
gconstpointer
gimp_parasite_get_data (const GimpParasite *parasite,
guint32 *num_bytes)
{
if (parasite)
{
if (num_bytes)
*num_bytes = parasite->size;
return parasite->data;
}
if (num_bytes)
*num_bytes = 0;
return NULL;
}

113
libgimpbase/gimpparasite.h Normal file
View file

@ -0,0 +1,113 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpparasite.h
* Copyright (C) 1998 Jay Cox <jaycox@gimp.org>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
#ifndef __GIMP_PARASITE_H__
#define __GIMP_PARASITE_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
/*
* GIMP_TYPE_PARASITE
*/
#define GIMP_TYPE_PARASITE (gimp_parasite_get_type ())
#define GIMP_VALUE_HOLDS_PARASITE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_PARASITE))
GType gimp_parasite_get_type (void) G_GNUC_CONST;
/*
* GIMP_TYPE_PARAM_PARASITE
*/
#define GIMP_TYPE_PARAM_PARASITE (gimp_param_parasite_get_type ())
#define GIMP_IS_PARAM_SPEC_PARASITE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_PARASITE))
GType gimp_param_parasite_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_parasite (const gchar *name,
const gchar *nick,
const gchar *blurb,
GParamFlags flags);
#define GIMP_PARASITE_PERSISTENT 1
#define GIMP_PARASITE_UNDOABLE 2
#define GIMP_PARASITE_ATTACH_PARENT (0x80 << 8)
#define GIMP_PARASITE_PARENT_PERSISTENT (GIMP_PARASITE_PERSISTENT << 8)
#define GIMP_PARASITE_PARENT_UNDOABLE (GIMP_PARASITE_UNDOABLE << 8)
#define GIMP_PARASITE_ATTACH_GRANDPARENT (0x80 << 16)
#define GIMP_PARASITE_GRANDPARENT_PERSISTENT (GIMP_PARASITE_PERSISTENT << 16)
#define GIMP_PARASITE_GRANDPARENT_UNDOABLE (GIMP_PARASITE_UNDOABLE << 16)
/**
* GimpParasite:
* @name: the parasite name, USE A UNIQUE PREFIX
* @flags: the parasite flags, like save in XCF etc.
* @size: the parasite size in bytes
* @data: (array length=size): the parasite data, the owner os the parasite is responsible
* for tracking byte order and internal structure
**/
struct _GimpParasite
{
gchar *name;
guint32 flags;
guint32 size;
gpointer data;
};
GimpParasite * gimp_parasite_new (const gchar *name,
guint32 flags,
guint32 size,
gconstpointer data);
void gimp_parasite_free (GimpParasite *parasite);
GimpParasite * gimp_parasite_copy (const GimpParasite *parasite);
gboolean gimp_parasite_compare (const GimpParasite *a,
const GimpParasite *b);
gboolean gimp_parasite_is_type (const GimpParasite *parasite,
const gchar *name);
gboolean gimp_parasite_is_persistent (const GimpParasite *parasite);
gboolean gimp_parasite_is_undoable (const GimpParasite *parasite);
gboolean gimp_parasite_has_flag (const GimpParasite *parasite,
gulong flag);
gulong gimp_parasite_get_flags (const GimpParasite *parasite);
const gchar * gimp_parasite_get_name (const GimpParasite *parasite);
gconstpointer gimp_parasite_get_data (const GimpParasite *parasite,
guint32 *num_bytes);
G_END_DECLS
#endif /* __GIMP_PARASITE_H__ */

View file

@ -0,0 +1,204 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpparasiteio.c
* Copyright (C) 1999 Tor Lillqvist <tml@iki.fi>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
/*
* Functions for building and parsing string representations of
* various standard parasite types.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "gimpparasiteio.h"
/**
* SECTION: gimpparasiteio
* @title: gimpparasiteio
* @short_description: Utility functions to (de)serialize certain C
* structures to/from #GimpParasite's.
* @see_also: #GimpParasite
*
* Utility functions to (de)serialize certain C structures to/from*
* #GimpParasite's.
**/
void
gimp_pixpipe_params_init (GimpPixPipeParams *params)
{
gint i;
g_return_if_fail (params != NULL);
params->step = 100;
params->ncells = 1;
params->cellwidth = 1;
params->cellheight = 1;
params->dim = 1;
params->cols = 1;
params->rows = 1;
params->placement = g_strdup ("constant");
for (i = 0; i < GIMP_PIXPIPE_MAXDIM; i++)
params->selection[i] = g_strdup ("random");
params->rank[0] = 1;
for (i = 1; i < GIMP_PIXPIPE_MAXDIM; i++)
params->rank[i] = 0;
}
void
gimp_pixpipe_params_parse (const gchar *string,
GimpPixPipeParams *params)
{
gchar *copy;
gchar *p, *q, *r;
gint i;
g_return_if_fail (string != NULL);
g_return_if_fail (params != NULL);
copy = g_strdup (string);
q = copy;
while ((p = strtok (q, " \r\n")) != NULL)
{
q = NULL;
r = strchr (p, ':');
if (r)
*r = 0;
if (strcmp (p, "ncells") == 0)
{
if (r)
params->ncells = atoi (r + 1);
}
else if (strcmp (p, "step") == 0)
{
if (r)
params->step = atoi (r + 1);
}
else if (strcmp (p, "dim") == 0)
{
if (r)
{
params->dim = atoi (r + 1);
params->dim = CLAMP (params->dim, 1, GIMP_PIXPIPE_MAXDIM);
}
}
else if (strcmp (p, "cols") == 0)
{
if (r)
params->cols = atoi (r + 1);
}
else if (strcmp (p, "rows") == 0)
{
if (r)
params->rows = atoi (r + 1);
}
else if (strcmp (p, "cellwidth") == 0)
{
if (r)
params->cellwidth = atoi (r + 1);
}
else if (strcmp (p, "cellheight") == 0)
{
if (r)
params->cellheight = atoi (r + 1);
}
else if (strcmp (p, "placement") == 0)
{
if (r)
{
g_free (params->placement);
params->placement = g_strdup (r + 1);
}
}
else if (strncmp (p, "rank", strlen ("rank")) == 0 && r)
{
if (r)
{
i = atoi (p + strlen ("rank"));
if (i >= 0 && i < params->dim)
params->rank[i] = atoi (r + 1);
}
}
else if (strncmp (p, "sel", strlen ("sel")) == 0 && r)
{
if (r)
{
i = atoi (p + strlen ("sel"));
if (i >= 0 && i < params->dim)
{
g_free (params->selection[i]);
params->selection[i] = g_strdup (r + 1);
}
}
}
if (r)
*r = ':';
}
g_free (copy);
}
gchar *
gimp_pixpipe_params_build (GimpPixPipeParams *params)
{
GString *str;
gint i;
g_return_val_if_fail (params != NULL, NULL);
str = g_string_new (NULL);
g_string_printf (str, "ncells:%d cellwidth:%d cellheight:%d "
"step:%d dim:%d cols:%d rows:%d placement:%s",
params->ncells, params->cellwidth, params->cellheight,
params->step, params->dim,
params->cols, params->rows,
params->placement);
for (i = 0; i < params->dim; i++)
{
g_string_append_printf (str, " rank%d:%d", i, params->rank[i]);
g_string_append_printf (str, " sel%d:%s", i, params->selection[i]);
}
return g_string_free (str, FALSE);
}
void
gimp_pixpipe_params_free (GimpPixPipeParams *params)
{
gint i;
g_free (params->placement);
for (i = 0; i < GIMP_PIXPIPE_MAXDIM; i++)
g_free (params->selection[i]);
}

View file

@ -0,0 +1,87 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpparasiteio.h
* Copyright (C) 1999 Tor Lillqvist <tml@iki.fi>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_PARASITE_IO_H__
#define __GIMP_PARASITE_IO_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
/* Data structures for various standard parasites used by plug-ins and
* the GIMP core, and functions to build and parse their string
* representations.
*/
/*
* Pixmap brush pipes.
*/
#define GIMP_PIXPIPE_MAXDIM 4
typedef struct _GimpPixPipeParams GimpPixPipeParams;
/**
* GimpPixPipeParams:
* @step: Step
* @ncells: Number of cells
* @dim: Dimension
* @cols: Columns
* @rows: Rows
* @cellwidth: Cell width
* @cellheight: Cell height
* @placement: Placement
* @rank: Rank
* @selection: Selection
*
* PLease somebody help documenting this.
**/
struct _GimpPixPipeParams
{
gint step;
gint ncells;
gint dim;
gint cols;
gint rows;
gint cellwidth;
gint cellheight;
gchar *placement;
gint rank[GIMP_PIXPIPE_MAXDIM];
gchar *selection[GIMP_PIXPIPE_MAXDIM];
};
/* Initialize with dummy values */
void gimp_pixpipe_params_init (GimpPixPipeParams *params);
/* Parse a string into a GimpPixPipeParams */
void gimp_pixpipe_params_parse (const gchar *parameters,
GimpPixPipeParams *params);
/* Build a string representation of GimpPixPipeParams */
gchar * gimp_pixpipe_params_build (GimpPixPipeParams *params) G_GNUC_MALLOC;
/* Free the internal values. It does not free the struct itself. */
void gimp_pixpipe_params_free (GimpPixPipeParams *params);
G_END_DECLS
#endif /* __GIMP_PARASITE_IO_H__ */

2519
libgimpbase/gimpprotocol.c Normal file

File diff suppressed because it is too large Load diff

423
libgimpbase/gimpprotocol.h Normal file
View file

@ -0,0 +1,423 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_PROTOCOL_H__
#define __GIMP_PROTOCOL_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
/* Increment every time the protocol changes
*/
#define GIMP_PROTOCOL_VERSION 0x0115
enum
{
GP_QUIT,
GP_CONFIG,
GP_TILE_REQ,
GP_TILE_ACK,
GP_TILE_DATA,
GP_PROC_RUN,
GP_PROC_RETURN,
GP_TEMP_PROC_RUN,
GP_TEMP_PROC_RETURN,
GP_PROC_INSTALL,
GP_PROC_UNINSTALL,
GP_EXTENSION_ACK,
GP_HAS_INIT
};
typedef enum
{
GP_PARAM_DEF_TYPE_DEFAULT,
GP_PARAM_DEF_TYPE_INT,
GP_PARAM_DEF_TYPE_UNIT,
GP_PARAM_DEF_TYPE_ENUM,
GP_PARAM_DEF_TYPE_CHOICE,
GP_PARAM_DEF_TYPE_BOOLEAN,
GP_PARAM_DEF_TYPE_DOUBLE,
GP_PARAM_DEF_TYPE_STRING,
GP_PARAM_DEF_TYPE_GEGL_COLOR,
GP_PARAM_DEF_TYPE_ID,
GP_PARAM_DEF_TYPE_ID_ARRAY,
GP_PARAM_DEF_TYPE_EXPORT_OPTIONS,
GP_PARAM_DEF_TYPE_RESOURCE,
GP_PARAM_DEF_TYPE_FILE
} GPParamDefType;
typedef enum
{
GP_PARAM_TYPE_INT,
GP_PARAM_TYPE_DOUBLE,
GP_PARAM_TYPE_STRING,
GP_PARAM_TYPE_STRV,
GP_PARAM_TYPE_BYTES,
GP_PARAM_TYPE_FILE,
GP_PARAM_TYPE_BABL_FORMAT,
GP_PARAM_TYPE_GEGL_COLOR,
GP_PARAM_TYPE_COLOR_ARRAY,
GP_PARAM_TYPE_PARASITE,
GP_PARAM_TYPE_ARRAY,
GP_PARAM_TYPE_ID_ARRAY,
GP_PARAM_TYPE_EXPORT_OPTIONS,
GP_PARAM_TYPE_PARAM_DEF,
GP_PARAM_TYPE_VALUE_ARRAY,
} GPParamType;
typedef struct _GPConfig GPConfig;
typedef struct _GPTileReq GPTileReq;
typedef struct _GPTileAck GPTileAck;
typedef struct _GPTileData GPTileData;
typedef struct _GPParamDef GPParamDef;
typedef struct _GPParamDefInt GPParamDefInt;
typedef struct _GPParamDefUnit GPParamDefUnit;
typedef struct _GPParamDefEnum GPParamDefEnum;
typedef struct _GPParamDefBoolean GPParamDefBoolean;
typedef struct _GPParamDefDouble GPParamDefDouble;
typedef struct _GPParamDefString GPParamDefString;
typedef struct _GPParamDefChoice GPParamDefChoice;
typedef struct _GPParamStrv GPParamStrv;
typedef struct _GPParamDefGeglColor GPParamDefGeglColor;
typedef struct _GPParamDefID GPParamDefID;
typedef struct _GPParamDefIDArray GPParamDefIDArray;
typedef struct _GPParamDefResource GPParamDefResource;
typedef struct _GPParamDefFile GPParamDefFile;
typedef struct _GPParam GPParam;
typedef struct _GPParamArray GPParamArray;
typedef struct _GPParamIDArray GPParamIDArray;
typedef struct _GPParamFormat GPParamFormat;
typedef struct _GPParamColor GPParamColor;
typedef struct _GPParamColorArray GPParamColorArray;
typedef struct _GPParamExportOptions GPParamExportOptions;
typedef struct _GPParamValueArray GPParamValueArray;
typedef struct _GPProcRun GPProcRun;
typedef struct _GPProcReturn GPProcReturn;
typedef struct _GPProcInstall GPProcInstall;
typedef struct _GPProcUninstall GPProcUninstall;
struct _GPConfig
{
guint32 tile_width;
guint32 tile_height;
gint32 shm_id;
gint8 check_size;
gint8 check_type;
gint8 show_help_button;
gint8 use_cpu_accel;
gint8 use_opencl;
gint8 export_color_profile;
gint8 export_comment;
gint8 export_exif;
gint8 export_xmp;
gint8 export_iptc;
gint32 default_display_id;
gchar *app_name;
gchar *wm_class;
gchar *display_name;
gint32 monitor_number;
guint32 timestamp;
gchar *icon_theme_dir;
guint64 tile_cache_size;
gchar *swap_path;
gchar *swap_compression;
gint32 num_processors;
/* Since protocol version 0x0111:
* These values are used to represent 2 GeglColor objects but we avoid
* initializing GEGL in the wire protocol. This leads to extremely
* slow startup when initializing every plug-in. So we store them as
* bytes and encoding string and reconstruct the GeglColor in libgimp.
*/
GBytes *check_custom_color1;
GBytes *check_custom_icc1;
gchar *check_custom_encoding1;
GBytes *check_custom_color2;
GBytes *check_custom_icc2;
gchar *check_custom_encoding2;
};
struct _GPTileReq
{
gint32 drawable_id;
guint32 tile_num;
guint32 shadow;
};
struct _GPTileData
{
gint32 drawable_id;
guint32 tile_num;
guint32 shadow;
guint32 bpp;
guint32 width;
guint32 height;
guint32 use_shm;
guchar *data;
};
struct _GPParamDefInt
{
gint64 min_val;
gint64 max_val;
gint64 default_val;
};
struct _GPParamDefUnit
{
gint32 allow_pixels;
gint32 allow_percent;
gint32 default_val;
};
struct _GPParamDefEnum
{
gint32 default_val;
};
struct _GPParamDefBoolean
{
gint32 default_val;
};
struct _GPParamDefDouble
{
gdouble min_val;
gdouble max_val;
gdouble default_val;
};
struct _GPParamDefString
{
gchar *default_val;
};
struct _GPParamDefGeglColor
{
gint32 has_alpha;
GPParamColor *default_val;
};
struct _GPParamDefID
{
gint32 none_ok;
};
struct _GPParamDefIDArray
{
gchar *type_name;
};
struct _GPParamDefChoice
{
GimpChoice *choice;
gchar *default_val;
};
struct _GPParamDefResource
{
gint32 none_ok;
gint32 default_to_context;
gint32 default_resource_id;
};
struct _GPParamDefFile
{
/* action is a GimpFileChooserAction casted to gint32. */
gint32 action;
gint32 none_ok;
gchar *default_uri;
};
struct _GPParamDef
{
GPParamDefType param_def_type;
gchar *type_name;
gchar *value_type_name;
gchar *name;
gchar *nick;
gchar *blurb;
guint flags;
union
{
GPParamDefInt m_int;
GPParamDefUnit m_unit;
GPParamDefEnum m_enum;
GPParamDefBoolean m_boolean;
GPParamDefDouble m_double;
GPParamDefString m_string;
GPParamDefGeglColor m_gegl_color;
GPParamDefID m_id;
GPParamDefIDArray m_id_array;
GPParamDefChoice m_choice;
GPParamDefResource m_resource;
GPParamDefFile m_file;
} meta;
};
struct _GPParamArray
{
guint32 size;
guint8 *data;
};
struct _GPParamIDArray
{
gchar *type_name;
guint32 size;
gint32 *data;
};
struct _GPParamFormat
{
/* Transferring a BablFormat with the encoding and the ICC data. */
gchar *encoding;
guint32 profile_size;
guint8 *profile_data;
};
struct _GPParamColor
{
guint32 size;
guint8 data[40];
GPParamFormat format;
};
struct _GPParamColorArray
{
guint32 size;
GPParamColor *colors;
};
struct _GPParamExportOptions
{
/* XXX: this is an empty shell right now, because there are no export
* options yet. The capabilities property doesn't need to be passed
* through the wire because it is set by libgimp, not at run call.
*/
};
struct _GPParamValueArray
{
guint32 n_values;
GPParam *values;
};
struct _GPParam
{
GPParamType param_type;
gchar *type_name;
union
{
gint32 d_int;
gdouble d_double;
gchar *d_string;
gchar **d_strv;
GBytes *d_bytes;
GPParamFormat d_format;
GPParamColor d_gegl_color;
GPParamColorArray d_color_array;
GimpParasite d_parasite;
GPParamArray d_array;
GPParamIDArray d_id_array;
GPParamExportOptions d_export_options;
GPParamDef d_param_def;
GPParamValueArray d_value_array;
} data;
};
struct _GPProcRun
{
gchar *name;
guint32 n_params;
GPParam *params;
};
struct _GPProcReturn
{
gchar *name;
guint32 n_params;
GPParam *params;
};
struct _GPProcInstall
{
gchar *name;
guint32 type;
guint32 n_params;
guint32 n_return_vals;
GPParamDef *params;
GPParamDef *return_vals;
};
struct _GPProcUninstall
{
gchar *name;
};
void gp_init (void);
gboolean gp_quit_write (GIOChannel *channel,
gpointer user_data);
gboolean gp_config_write (GIOChannel *channel,
GPConfig *config,
gpointer user_data);
gboolean gp_tile_req_write (GIOChannel *channel,
GPTileReq *tile_req,
gpointer user_data);
gboolean gp_tile_ack_write (GIOChannel *channel,
gpointer user_data);
gboolean gp_tile_data_write (GIOChannel *channel,
GPTileData *tile_data,
gpointer user_data);
gboolean gp_proc_run_write (GIOChannel *channel,
GPProcRun *proc_run,
gpointer user_data);
gboolean gp_proc_return_write (GIOChannel *channel,
GPProcReturn *proc_return,
gpointer user_data);
gboolean gp_temp_proc_run_write (GIOChannel *channel,
GPProcRun *proc_run,
gpointer user_data);
gboolean gp_temp_proc_return_write (GIOChannel *channel,
GPProcReturn *proc_return,
gpointer user_data);
gboolean gp_proc_install_write (GIOChannel *channel,
GPProcInstall *proc_install,
gpointer user_data);
gboolean gp_proc_uninstall_write (GIOChannel *channel,
GPProcUninstall *proc_uninstall,
gpointer user_data);
gboolean gp_extension_ack_write (GIOChannel *channel,
gpointer user_data);
gboolean gp_has_init_write (GIOChannel *channel,
gpointer user_data);
G_END_DECLS
#endif /* __GIMP_PROTOCOL_H__ */

137
libgimpbase/gimprectangle.c Normal file
View file

@ -0,0 +1,137 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimprectangle.c
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <glib.h>
#include "gimprectangle.h"
/**
* SECTION: gimprectangle
* @title: gimprectangle
* @short_description: Utility functions dealing with rectangle extents.
*
* Utility functions dealing with rectangle extents.
**/
/**
* gimp_rectangle_intersect:
* @x1: origin of first rectangle
* @y1: origin of first rectangle
* @width1: width of first rectangle
* @height1: height of first rectangle
* @x2: origin of second rectangle
* @y2: origin of second rectangle
* @width2: width of second rectangle
* @height2: height of second rectangle
* @dest_x: (out) (optional): return location for origin of intersection,
* or %NULL
* @dest_y: (out) (optional): return location for origin of intersection,
* or %NULL
* @dest_width: (out) (optional): return location for width of intersection,
* or %NULL
* @dest_height: (out) (optional): return location for height of intersection,
* or %NULL
*
* Calculates the intersection of two rectangles.
*
* Returns: %TRUE if the intersection is non-empty, %FALSE otherwise
*
* Since: 2.4
**/
gboolean
gimp_rectangle_intersect (gint x1,
gint y1,
gint width1,
gint height1,
gint x2,
gint y2,
gint width2,
gint height2,
gint *dest_x,
gint *dest_y,
gint *dest_width,
gint *dest_height)
{
gint d_x, d_y;
gint d_w, d_h;
d_x = MAX (x1, x2);
d_y = MAX (y1, y2);
d_w = MIN (x1 + width1, x2 + width2) - d_x;
d_h = MIN (y1 + height1, y2 + height2) - d_y;
if (dest_x) *dest_x = d_x;
if (dest_y) *dest_y = d_y;
if (dest_width) *dest_width = d_w;
if (dest_height) *dest_height = d_h;
return (d_w > 0 && d_h > 0);
}
/**
* gimp_rectangle_union:
* @x1: origin of first rectangle
* @y1: origin of first rectangle
* @width1: width of first rectangle
* @height1: height of first rectangle
* @x2: origin of second rectangle
* @y2: origin of second rectangle
* @width2: width of second rectangle
* @height2: height of second rectangle
* @dest_x: (out) (optional): return location for origin of union, or %NULL
* @dest_y: (out) (optional): return location for origin of union, or %NULL
* @dest_width: (out) (optional): return location for width of union, or %NULL
* @dest_height: (out) (optional): return location for height of union, or %NULL
*
* Calculates the union of two rectangles.
*
* Since: 2.8
**/
void
gimp_rectangle_union (gint x1,
gint y1,
gint width1,
gint height1,
gint x2,
gint y2,
gint width2,
gint height2,
gint *dest_x,
gint *dest_y,
gint *dest_width,
gint *dest_height)
{
gint d_x, d_y;
gint d_w, d_h;
d_x = MIN (x1, x2);
d_y = MIN (y1, y2);
d_w = MAX (x1 + width1, x2 + width2) - d_x;
d_h = MAX (y1 + height1, y2 + height2) - d_y;
if (dest_x) *dest_x = d_x;
if (dest_y) *dest_y = d_y;
if (dest_width) *dest_width = d_w;
if (dest_height) *dest_height = d_h;
}

View file

@ -0,0 +1,60 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
#ifndef __GIMP_RECTANGLE_H__
#define __GIMP_RECTANGLE_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
gboolean gimp_rectangle_intersect (gint x1,
gint y1,
gint width1,
gint height1,
gint x2,
gint y2,
gint width2,
gint height2,
gint *dest_x,
gint *dest_y,
gint *dest_width,
gint *dest_height);
void gimp_rectangle_union (gint x1,
gint y1,
gint width1,
gint height1,
gint x2,
gint y2,
gint width2,
gint height2,
gint *dest_x,
gint *dest_y,
gint *dest_width,
gint *dest_height);
G_END_DECLS
#endif /* __GIMP_RECTANGLE_H__ */

488
libgimpbase/gimpreloc.c Normal file
View file

@ -0,0 +1,488 @@
/*
* BinReloc - a library for creating relocatable executables
* Written by: Hongli Lai <h.lai@chello.nl>
* http://autopackage.org/
*
* This source code is public domain. You can relicense this code
* under whatever license you want.
*
* See http://autopackage.org/docs/binreloc/ for
* more information and how to use this.
*/
#include "config.h"
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#if defined(ENABLE_RELOCATABLE_RESOURCES) && ! defined(G_OS_WIN32)
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif /* ENABLE_RELOCATABLE_RESOURCES && ! G_OS_WIN32 */
#include <gio/gio.h>
#include <glib.h>
#include <glib/gstdio.h>
#include "gimpreloc.h"
/*
* Find the canonical filename of the executable. Returns the filename
* (which must be freed) or NULL on error. If the parameter 'error' is
* not NULL, the error code will be stored there, if an error occurred.
*/
static char *
_br_find_exe (GimpBinrelocInitError *error)
{
#if ! defined(ENABLE_RELOCATABLE_RESOURCES) || defined(G_OS_WIN32) || defined(__APPLE__)
if (error)
*error = GIMP_RELOC_INIT_ERROR_DISABLED;
return NULL;
#else
GDataInputStream *data_input;
GInputStream *input;
GFile *file;
GError *gerror = NULL;
gchar *path;
gchar *sym_path;
gchar *maps_line;
sym_path = g_strdup ("/proc/self/exe");
while (1)
{
struct stat stat_buf;
int i;
/* Do not use readlink() with a buffer of size PATH_MAX because
* some systems actually allow paths of bigger size. Thus this
* macro is kind of bogus. Some systems like Hurd will not even
* define it (see MR !424).
* g_file_read_link() on the other hand will return a size of
* appropriate size, with newline removed and NUL terminator
* added.
*/
path = g_file_read_link (sym_path, &gerror);
g_free (sym_path);
if (! path)
{
/* Read link fails but we can try reading /proc/self/maps as
* an alternate method.
*/
g_printerr ("%s: %s\n", G_STRFUNC, gerror->message);
g_clear_error (&gerror);
break;
}
/* Check whether the symlink's target is also a symlink.
* We want to get the final target. */
i = stat (path, &stat_buf);
if (i == -1)
{
/* Error. */
break;
}
/* stat() success. */
if (! S_ISLNK (stat_buf.st_mode))
{
/* path is not a symlink. Done. */
return path;
}
/* path is a symlink. Continue loop and resolve this. */
sym_path = path;
}
/* readlink() or stat() failed; this can happen when the program is
* running in Valgrind 2.2. Read from /proc/self/maps as fallback. */
file = g_file_new_for_path ("/proc/self/maps");
input = G_INPUT_STREAM (g_file_read (file, NULL, &gerror));
g_object_unref (file);
if (! input)
{
g_printerr ("%s: %s", G_STRFUNC, gerror->message);
g_clear_error (&gerror);
if (error)
*error = GIMP_RELOC_INIT_ERROR_OPEN_MAPS;
return NULL;
}
data_input = g_data_input_stream_new (input);
g_object_unref (input);
/* The first entry with r-xp permission should be the executable name. */
while ((maps_line = g_data_input_stream_read_line (data_input, NULL, NULL, &gerror)))
{
if (maps_line == NULL)
{
if (gerror)
{
g_printerr ("%s: %s\n", G_STRFUNC, gerror->message);
g_error_free (gerror);
}
g_object_unref (data_input);
if (error)
*error = GIMP_RELOC_INIT_ERROR_READ_MAPS;
return NULL;
}
/* Extract the filename; it is always an absolute path. */
path = strchr (maps_line, '/');
/* Sanity check. */
if (path && strstr (maps_line, " r-xp "))
{
/* We found the executable name. */
path = g_strdup (path);
break;
}
g_free (maps_line);
maps_line = NULL;
path = NULL;
}
if (path == NULL && error)
*error = GIMP_RELOC_INIT_ERROR_INVALID_MAPS;
g_object_unref (data_input);
g_free (maps_line);
return path;
#endif /* ! ENABLE_RELOCATABLE_RESOURCES || G_OS_WIN32 */
}
/*
* Find the canonical filename of the executable which owns symbol.
* Returns a filename which must be freed, or NULL on error.
*/
static char *
_br_find_exe_for_symbol (const void *symbol, GimpBinrelocInitError *error)
{
#if ! defined(ENABLE_RELOCATABLE_RESOURCES) || defined(G_OS_WIN32) || defined(__APPLE__)
if (error)
*error = GIMP_RELOC_INIT_ERROR_DISABLED;
return (char *) NULL;
#else
GDataInputStream *data_input;
GInputStream *input;
GFile *file;
GError *gerror = NULL;
gchar *maps_line;
char *found = NULL;
char *address_string;
size_t address_string_len;
if (symbol == NULL)
return (char *) NULL;
file = g_file_new_for_path ("/proc/self/maps");
input = G_INPUT_STREAM (g_file_read (file, NULL, &gerror));
g_object_unref (file);
if (! input)
{
g_printerr ("%s: %s", G_STRFUNC, gerror->message);
g_error_free (gerror);
if (error)
*error = GIMP_RELOC_INIT_ERROR_OPEN_MAPS;
return NULL;
}
data_input = g_data_input_stream_new (input);
g_object_unref (input);
address_string_len = 4;
address_string = g_try_new (char, address_string_len);
while ((maps_line = g_data_input_stream_read_line (data_input, NULL, NULL, &gerror)))
{
char *start_addr, *end_addr, *end_addr_end;
char *path;
void *start_addr_p, *end_addr_p;
size_t len;
if (maps_line == NULL)
{
if (gerror)
{
g_printerr ("%s: %s\n", G_STRFUNC, gerror->message);
g_error_free (gerror);
}
if (error)
*error = GIMP_RELOC_INIT_ERROR_READ_MAPS;
break;
}
/* Sanity check. */
/* XXX Early versions of this code would check that the mapped
* region was with r-xp permission. It might have been true at
* some point in time, but last I tested, the searched pointer was
* in a r--p region for libgimpbase. Thus _br_find_exe_for_symbol()
* would fail to find the executable's path.
* So now we don't test the region's permission anymore.
*/
if (strchr (maps_line, '/') == NULL)
{
g_free (maps_line);
continue;
}
/* Parse line. */
start_addr = maps_line;
end_addr = strchr (maps_line, '-');
path = strchr (maps_line, '/');
/* More sanity check. */
if (!(path > end_addr && end_addr != NULL && end_addr[0] == '-'))
{
g_free (maps_line);
continue;
}
end_addr[0] = '\0';
end_addr++;
end_addr_end = strchr (end_addr, ' ');
if (end_addr_end == NULL)
{
g_free (maps_line);
continue;
}
end_addr_end[0] = '\0';
len = strlen (path);
if (len == 0)
{
g_free (maps_line);
continue;
}
if (path[len - 1] == '\n')
path[len - 1] = '\0';
/* Get rid of "(deleted)" from the filename. */
len = strlen (path);
if (len > 10 && strcmp (path + len - 10, " (deleted)") == 0)
path[len - 10] = '\0';
/* I don't know whether this can happen but better safe than sorry. */
len = strlen (start_addr);
if (len != strlen (end_addr))
{
g_free (maps_line);
continue;
}
/* Transform the addresses into a string in the form of 0xdeadbeef,
* then transform that into a pointer. */
if (address_string_len < len + 3)
{
address_string_len = len + 3;
address_string = (char *) g_try_realloc (address_string, address_string_len);
}
memcpy (address_string, "0x", 2);
memcpy (address_string + 2, start_addr, len);
address_string[2 + len] = '\0';
sscanf (address_string, "%p", &start_addr_p);
memcpy (address_string, "0x", 2);
memcpy (address_string + 2, end_addr, len);
address_string[2 + len] = '\0';
sscanf (address_string, "%p", &end_addr_p);
if (symbol >= start_addr_p && symbol < end_addr_p)
{
found = g_strdup (path);
g_free (maps_line);
break;
}
g_free (maps_line);
}
g_free (address_string);
g_object_unref (data_input);
return found;
#endif /* ! ENABLE_RELOCATABLE_RESOURCES || G_OS_WIN32 */
}
static gchar *exe = NULL;
static void set_gerror (GError **error, GimpBinrelocInitError errcode);
/* Initialize the BinReloc library (for applications).
*
* This function must be called before using any other BinReloc functions.
* It attempts to locate the application's canonical filename.
*
* @note If you want to use BinReloc for a library, then you should call
* _gimp_reloc_init_lib() instead.
* @note Initialization failure is not fatal. BinReloc functions will just
* fallback to the supplied default path.
*
* @param error If BinReloc failed to initialize, then the error report will
* be stored in this variable. Set to NULL if you don't want an
* error report. See the #GimpBinrelocInitError for a list of error
* codes.
*
* @returns TRUE on success, FALSE if BinReloc failed to initialize.
*/
gboolean
_gimp_reloc_init (GError **error)
{
GimpBinrelocInitError errcode;
/* Shut up compiler warning about uninitialized variable. */
errcode = GIMP_RELOC_INIT_ERROR_NOMEM;
/* Locate the application's filename. */
exe = _br_find_exe (&errcode);
if (exe != NULL)
/* Success! */
return TRUE;
else
{
/* Failed :-( */
set_gerror (error, errcode);
return FALSE;
}
}
/* Initialize the BinReloc library (for libraries).
*
* This function must be called before using any other BinReloc functions.
* It attempts to locate the calling library's canonical filename.
*
* @note The BinReloc source code MUST be included in your library, or this
* function won't work correctly.
* @note Initialization failure is not fatal. BinReloc functions will just
* fallback to the supplied default path.
*
* @returns TRUE on success, FALSE if a filename cannot be found.
*/
gboolean
_gimp_reloc_init_lib (GError **error)
{
GimpBinrelocInitError errcode;
/* Shut up compiler warning about uninitialized variable. */
errcode = GIMP_RELOC_INIT_ERROR_NOMEM;
exe = _br_find_exe_for_symbol ((const void *) "", &errcode);
if (exe != NULL)
{
/* Success! */
return TRUE;
}
else
{
/* Failed :-( */
set_gerror (error, errcode);
return exe != NULL;
}
}
static void
set_gerror (GError **error, GimpBinrelocInitError errcode)
{
const gchar *error_message;
if (error == NULL)
return;
switch (errcode)
{
case GIMP_RELOC_INIT_ERROR_NOMEM:
error_message = "Cannot allocate memory.";
break;
case GIMP_RELOC_INIT_ERROR_OPEN_MAPS:
error_message = "Unable to open /proc/self/maps for reading.";
break;
case GIMP_RELOC_INIT_ERROR_READ_MAPS:
error_message = "Unable to read from /proc/self/maps.";
break;
case GIMP_RELOC_INIT_ERROR_INVALID_MAPS:
error_message = "The file format of /proc/self/maps is invalid.";
break;
case GIMP_RELOC_INIT_ERROR_DISABLED:
error_message = "Binary relocation support is disabled.";
break;
default:
error_message = "Unknown error.";
break;
};
g_set_error (error, g_quark_from_static_string ("GBinReloc"),
errcode, "%s", error_message);
}
/* Locate the prefix in which the current application is installed.
*
* The prefix is generated by the following pseudo-code evaluation:
* \code
* dirname(dirname(exename))
* \endcode
*
* @param default_prefix A default prefix which will used as fallback.
* @return A string containing the prefix, which must be freed when no
* longer necessary. If BinReloc is not initialized, or if the
* initialization function failed, then a copy of default_prefix
* will be returned. If default_prefix is NULL, then NULL will be
* returned.
*/
gchar *
_gimp_reloc_find_prefix (const gchar *default_prefix)
{
gchar *dir1, *dir2;
gchar *exe_dir;
if (exe == NULL)
{
/* BinReloc not initialized. */
if (default_prefix != NULL)
return g_strdup (default_prefix);
else
return NULL;
}
dir1 = g_path_get_dirname (exe);
dir2 = g_path_get_dirname (dir1);
exe_dir = g_path_get_basename (dir1);
if (g_strcmp0 (exe_dir, "bin") != 0 && ! g_str_has_prefix (exe_dir, "lib"))
{
g_free (exe_dir);
exe_dir = g_path_get_basename (dir2);
if (g_str_has_prefix (exe_dir, "lib"))
{
/* Supporting multiarch folders, such as lib/x86_64-linux-gnu/ */
gchar *dir3 = g_path_get_dirname (dir2);
g_free (dir2);
dir2 = dir3;
}
}
g_free (dir1);
g_free (exe_dir);
return dir2;
}

46
libgimpbase/gimpreloc.h Normal file
View file

@ -0,0 +1,46 @@
/*
* BinReloc - a library for creating relocatable executables
* Written by: Hongli Lai <h.lai@chello.nl>
* http://autopackage.org/
*
* This source code is public domain. You can relicense this code
* under whatever license you want.
*
* See http://autopackage.org/docs/binreloc/ for
* more information and how to use this.
*/
#ifndef __GIMP_RELOC_H__
#define __GIMP_RELOC_H__
G_BEGIN_DECLS
/* These error codes can be returned from _gimp_reloc_init() or
* _gimp_reloc_init_lib().
*/
typedef enum
{
/** Cannot allocate memory. */
GIMP_RELOC_INIT_ERROR_NOMEM,
/** Unable to open /proc/self/maps; see errno for details. */
GIMP_RELOC_INIT_ERROR_OPEN_MAPS,
/** Unable to read from /proc/self/maps; see errno for details. */
GIMP_RELOC_INIT_ERROR_READ_MAPS,
/** The file format of /proc/self/maps is invalid; kernel bug? */
GIMP_RELOC_INIT_ERROR_INVALID_MAPS,
/** BinReloc is disabled (the ENABLE_BINRELOC macro is not defined). */
GIMP_RELOC_INIT_ERROR_DISABLED
} GimpBinrelocInitError;
G_GNUC_INTERNAL gboolean _gimp_reloc_init (GError **error);
G_GNUC_INTERNAL gboolean _gimp_reloc_init_lib (GError **error);
G_GNUC_INTERNAL gchar * _gimp_reloc_find_prefix (const gchar *default_prefix);
G_END_DECLS
#endif /* _GIMPRELOC_H_ */

110
libgimpbase/gimpsignal.c Normal file
View file

@ -0,0 +1,110 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*
* $Revision$
*/
#include "config.h"
#define _GNU_SOURCE /* for the sigaction stuff */
#include <glib.h>
#include "gimpsignal.h"
/**
* SECTION: gimpsignal
* @title: gimpsignal
* @short_description: Portable signal handling.
* @see_also: signal(2), signal(5 or 7), sigaction(2).
*
* Portable signal handling.
**/
/* Courtesy of Austin Donnelly 06-04-2000 to address bug #2742 */
/**
* gimp_signal_private: (skip)
* @signum: Selects signal to be handled (see `man 7 signal`)
* @handler: Handler that maps to signum. Invoked by O/S.
* Handler gets signal that caused invocation. Corresponds
* to the @sa_handler field of the @sigaction struct.
* @flags: Preferences. OR'ed SA_&lt;xxx&gt;. See man sigaction. Corresponds
* to the @sa_flags field of the @sigaction struct.
*
* This function furnishes a workalike for signal(2) but
* which internally invokes sigaction(2) after certain
* sa_flags are set; these primarily to ensure restarting
* of interrupted system calls. See sigaction(2) It is a
* aid to transition and not new development: that effort
* should employ sigaction directly. [gosgood 18.04.2000]
*
* Cause @handler to be run when @signum is delivered. We
* use sigaction(2) rather than signal(2) so that we can control the
* signal handler's environment completely via @flags: some signal(2)
* implementations differ in their semantics, so we need to nail down
* exactly what we want. [austin 06.04.2000]
*
* Returns: A reference to the signal handling function which was
* active before the call to gimp_signal_private().
*/
GimpSignalHandlerFunc
gimp_signal_private (gint signum,
GimpSignalHandlerFunc handler,
gint flags)
{
#ifndef G_OS_WIN32
gint ret;
struct sigaction sa;
struct sigaction osa;
/* The sa_handler (mandated by POSIX.1) and sa_sigaction (a
* common extension) are often implemented by the OS as members
* of a union. This means you CAN NOT set both, you set one or
* the other. Caveat programmer!
*/
/* Passing gimp_signal_private a gimp_sighandler of NULL is not
* an error, and generally results in the action for that signal
* being set to SIG_DFL (default behavior). Many OSes define
* SIG_DFL as (void (*)()0, so setting sa_handler to NULL is
* the same thing as passing SIG_DFL to it.
*/
sa.sa_handler = handler;
/* Mask all signals while handler runs to avoid re-entrancy
* problems.
*/
sigfillset (&sa.sa_mask);
sa.sa_flags = flags;
ret = sigaction (signum, &sa, &osa);
if (ret < 0)
g_error ("unable to set handler for signal %d\n", signum);
return (GimpSignalHandlerFunc) osa.sa_handler;
#else
return NULL; /* Or g_error()? Should all calls to
* this function really be inside
* #ifdef G_OS_UNIX?
*/
#endif
}

48
libgimpbase/gimpsignal.h Normal file
View file

@ -0,0 +1,48 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-2000 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_SIGNAL_H__
#define __GIMP_SIGNAL_H__
#include <signal.h>
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
/**
* GimpSignalHandlerFunc:
* @signum: The number of the signal. Useful if different signals are
* handled by a single handler.
*
* A prototype for a reference to a signal handler functions. Note
* that each function which takes or returns a variable of this type
* also accepts or may return special values defined by your system's
* signal.h header file (like @SIG_DFL or @SIG_IGN).
**/
typedef void (* GimpSignalHandlerFunc) (gint signum);
GimpSignalHandlerFunc gimp_signal_private (gint signum,
GimpSignalHandlerFunc handler,
gint flags);
G_END_DECLS
#endif /* __GIMP_SIGNAL_H__ */

1140
libgimpbase/gimpunit.c Normal file

File diff suppressed because it is too large Load diff

108
libgimpbase/gimpunit.h Normal file
View file

@ -0,0 +1,108 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpunit.h
* Copyright (C) 1999-2003 Michael Natterer <mitch@gimp.org>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
#ifndef __GIMP_UNIT_H__
#define __GIMP_UNIT_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
/**
* GIMP_TYPE_UNIT:
*
* #GIMP_TYPE_UNIT is a class representing units used for measuring
* dimensions in GIMP.
**/
#define GIMP_TYPE_UNIT (gimp_unit_get_type ())
G_DECLARE_FINAL_TYPE (GimpUnit, gimp_unit, GIMP, UNIT, GObject)
gint32 gimp_unit_get_id (GimpUnit *unit);
const gchar * gimp_unit_get_name (GimpUnit *unit);
gdouble gimp_unit_get_factor (GimpUnit *unit);
gint gimp_unit_get_digits (GimpUnit *unit);
gint gimp_unit_get_scaled_digits (GimpUnit *unit,
gdouble resolution);
const gchar * gimp_unit_get_symbol (GimpUnit *unit);
const gchar * gimp_unit_get_abbreviation (GimpUnit *unit);
gboolean gimp_unit_get_deletion_flag (GimpUnit *unit);
void gimp_unit_set_deletion_flag (GimpUnit *unit,
gboolean deletion_flag);
GimpUnit * gimp_unit_get_by_id (gint unit_id);
GimpUnit * gimp_unit_pixel (void);
GimpUnit * gimp_unit_mm (void);
GimpUnit * gimp_unit_inch (void);
GimpUnit * gimp_unit_point (void);
GimpUnit * gimp_unit_pica (void);
GimpUnit * gimp_unit_percent (void);
gboolean gimp_unit_is_built_in (GimpUnit *unit);
gboolean gimp_unit_is_metric (GimpUnit *unit);
gchar * gimp_unit_format_string (const gchar *format,
GimpUnit *unit);
gdouble gimp_pixels_to_units (gdouble pixels,
GimpUnit *unit,
gdouble resolution);
gdouble gimp_units_to_pixels (gdouble value,
GimpUnit *unit,
gdouble resolution);
gdouble gimp_units_to_points (gdouble value,
GimpUnit *unit,
gdouble resolution);
/*
* GIMP_TYPE_PARAM_UNIT
*/
#define GIMP_VALUE_HOLDS_UNIT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_UNIT))
#define GIMP_TYPE_PARAM_UNIT (gimp_param_unit_get_type ())
#define GIMP_IS_PARAM_SPEC_UNIT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_UNIT))
GType gimp_param_unit_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_unit (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean allow_pixel,
gboolean allow_percent,
GimpUnit *default_value,
GParamFlags flags);
gboolean gimp_param_spec_unit_pixel_allowed (GParamSpec *pspec);
gboolean gimp_param_spec_unit_percent_allowed (GParamSpec *pspec);
G_END_DECLS
#endif /* __GIMP_UNIT_H__ */

1838
libgimpbase/gimputils.c Normal file

File diff suppressed because it is too large Load diff

96
libgimpbase/gimputils.h Normal file
View file

@ -0,0 +1,96 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
#ifndef __GIMP_UTILS_H__
#define __GIMP_UTILS_H__
G_BEGIN_DECLS
gchar * gimp_utf8_strtrim (const gchar *str,
gint max_chars) G_GNUC_MALLOC;
gchar * gimp_any_to_utf8 (const gchar *str,
gssize len,
const gchar *warning_format,
...) G_GNUC_PRINTF (3, 4) G_GNUC_MALLOC;
const gchar * gimp_filename_to_utf8 (const gchar *filename);
const gchar * gimp_file_get_utf8_name (GFile *file);
gboolean gimp_file_has_extension (GFile *file,
const gchar *extension);
gboolean gimp_file_show_in_file_manager (GFile *file,
GError **error);
gchar * gimp_strip_uline (const gchar *str) G_GNUC_MALLOC;
gchar * gimp_escape_uline (const gchar *str) G_GNUC_MALLOC;
gboolean gimp_is_canonical_identifier (const gchar *identifier);
gchar * gimp_canonicalize_identifier (const gchar *identifier) G_GNUC_MALLOC;
const GimpEnumDesc * gimp_enum_get_desc (GEnumClass *enum_class,
gint value);
gboolean gimp_enum_get_value (GType enum_type,
gint value,
const gchar **value_name,
const gchar **value_nick,
const gchar **value_desc,
const gchar **value_help);
const gchar * gimp_enum_value_get_desc (GEnumClass *enum_class,
const GEnumValue *enum_value);
const gchar * gimp_enum_value_get_help (GEnumClass *enum_class,
const GEnumValue *enum_value);
const gchar * gimp_enum_value_get_abbrev (GEnumClass *enum_class,
const GEnumValue *enum_value);
const GimpFlagsDesc * gimp_flags_get_first_desc (GFlagsClass *flags_class,
guint value);
gboolean gimp_flags_get_first_value (GType flags_type,
guint value,
const gchar **value_name,
const gchar **value_nick,
const gchar **value_desc,
const gchar **value_help);
const gchar * gimp_flags_value_get_desc (GFlagsClass *flags_class,
const GFlagsValue *flags_value);
const gchar * gimp_flags_value_get_help (GFlagsClass *flags_class,
const GFlagsValue *flags_value);
const gchar * gimp_flags_value_get_abbrev (GFlagsClass *flags_class,
const GFlagsValue *flags_value);
gboolean gimp_stack_trace_available (gboolean optimal);
gboolean gimp_stack_trace_print (const gchar *prog_name,
gpointer stream,
gchar **trace);
void gimp_stack_trace_query (const gchar *prog_name);
void gimp_range_estimate_settings (gdouble lower,
gdouble upper,
gdouble *step,
gdouble *page,
gint *digits);
void gimp_bind_text_domain (const gchar *domain_name,
const gchar *dir_name);
G_END_DECLS
#endif /* __GIMP_UTILS_H__ */

View file

@ -0,0 +1,887 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpvaluearray.c ported from GValueArray
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <gegl.h>
#include <gio/gio.h>
#include <glib-object.h>
#include <gobject/gvaluecollector.h>
#include "gimpbasetypes.h"
#include "gimpparamspecs.h"
#include "gimpvaluearray.h"
/**
* SECTION:gimpvaluearray
* @short_description: A container structure to maintain an array of
* generic values
* @see_also: #GValue, #GParamSpecValueArray, gimp_param_spec_value_array()
* @title: GimpValueArray
*
* The prime purpose of a #GimpValueArray is for it to be used as an
* object property that holds an array of values. A #GimpValueArray wraps
* an array of #GValue elements in order for it to be used as a boxed
* type through %GIMP_TYPE_VALUE_ARRAY.
*/
#define GROUP_N_VALUES (1) /* power of 2 !! */
/**
* GimpValueArray:
*
* A #GimpValueArray contains an array of #GValue elements.
*
* Since: 2.10
*/
struct _GimpValueArray
{
gint n_values;
GValue *values;
gint n_prealloced;
gint ref_count;
};
G_DEFINE_BOXED_TYPE (GimpValueArray, gimp_value_array,
gimp_value_array_ref, gimp_value_array_unref)
/**
* gimp_value_array_index:
* @value_array: #GimpValueArray to get a value from
* @index: index of the value of interest
*
* Return a pointer to the value at @index contained in @value_array.
*
* *Note*: in binding languages, some custom types fail to be correctly passed
* through. For these types, you should use specific functions.
* For instance, in the Python binding, a [type@ColorArray] `GValue`
* won't be usable with this function. You should use instead
* [method@ValueArray.get_color_array].
*
* Returns: (transfer none): pointer to a value at @index in @value_array
*
* Since: 2.10
*/
GValue *
gimp_value_array_index (const GimpValueArray *value_array,
gint index)
{
g_return_val_if_fail (value_array != NULL, NULL);
g_return_val_if_fail (index < value_array->n_values, NULL);
return value_array->values + index;
}
/**
* gimp_value_array_get_color_array:
* @value_array: #GimpValueArray to get a value from
* @index: index of the value of interest
*
* Return a pointer to the value at @index contained in @value_array. This value
* is supposed to be a [type@ColorArray].
*
* *Note*: most of the time, you should use the generic [method@Gimp.ValueArray.index]
* to retrieve a value, then the relevant `g_value_get_*()` function.
* This alternative function is mostly there for bindings because
* GObject-Introspection is [not able yet to process correctly known
* boxed array types](https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/492).
*
* There are no reasons to use this function in C code.
*
* Returns: (transfer none) (array zero-terminated=1): the [type@ColorArray] stored at @index in @value_array.
*
* Since: 3.0
*/
/* XXX See: https://gitlab.gnome.org/GNOME/gimp/-/issues/10885#note_2030308
* This explains why we created a specific function for GimpColorArray, instead
* of using the generic gimp_value_array_index().
*/
GeglColor **
gimp_value_array_get_color_array (const GimpValueArray *value_array,
gint index)
{
GValue *value;
GimpColorArray colors;
g_return_val_if_fail (value_array != NULL, NULL);
g_return_val_if_fail (index < value_array->n_values, NULL);
value = value_array->values + index;
g_return_val_if_fail (GIMP_VALUE_HOLDS_COLOR_ARRAY (value), NULL);
colors = g_value_get_boxed (value);
return colors;
}
/**
* gimp_value_array_get_core_object_array:
* @value_array: #GimpValueArray to get a value from
* @index: index of the value of interest
*
* Return a pointer to the value at @index contained in @value_array. This value
* is supposed to be a [type@CoreObjectArray].
*
* *Note*: most of the time, you should use the generic [method@Gimp.ValueArray.index]
* to retrieve a value, then the relevant `g_value_get_*()` function.
* This alternative function is mostly there for bindings because
* GObject-Introspection is [not able yet to process correctly known
* boxed array types](https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/492).
*
* There are no reasons to use this function in C code.
*
* Returns: (transfer none) (array zero-terminated=1): the [type@CoreObjectArray] stored at @index in @value_array.
*
* Since: 3.0
*/
GObject **
gimp_value_array_get_core_object_array (const GimpValueArray *value_array,
gint index)
{
GValue *value;
GObject **objects;
g_return_val_if_fail (value_array != NULL, NULL);
g_return_val_if_fail (index < value_array->n_values, NULL);
value = value_array->values + index;
g_return_val_if_fail (GIMP_VALUE_HOLDS_CORE_OBJECT_ARRAY (value), NULL);
objects = g_value_get_boxed (value);
return objects;
}
static inline void
value_array_grow (GimpValueArray *value_array,
gint n_values,
gboolean zero_init)
{
g_return_if_fail ((guint) n_values >= (guint) value_array->n_values);
value_array->n_values = n_values;
if (value_array->n_values > value_array->n_prealloced)
{
gint i = value_array->n_prealloced;
value_array->n_prealloced = (value_array->n_values + GROUP_N_VALUES - 1) & ~(GROUP_N_VALUES - 1);
value_array->values = g_renew (GValue, value_array->values, value_array->n_prealloced);
if (!zero_init)
i = value_array->n_values;
memset (value_array->values + i, 0,
(value_array->n_prealloced - i) * sizeof (value_array->values[0]));
}
}
static inline void
value_array_shrink (GimpValueArray *value_array)
{
if (value_array->n_prealloced >= value_array->n_values + GROUP_N_VALUES)
{
value_array->n_prealloced = (value_array->n_values + GROUP_N_VALUES - 1) & ~(GROUP_N_VALUES - 1);
value_array->values = g_renew (GValue, value_array->values, value_array->n_prealloced);
}
}
/**
* gimp_value_array_new:
* @n_prealloced: number of values to preallocate space for
*
* Allocate and initialize a new #GimpValueArray, optionally preserve space
* for @n_prealloced elements. New arrays always contain 0 elements,
* regardless of the value of @n_prealloced.
*
* Returns: a newly allocated #GimpValueArray with 0 values
*
* Since: 2.10
*/
GimpValueArray *
gimp_value_array_new (gint n_prealloced)
{
GimpValueArray *value_array = g_slice_new0 (GimpValueArray);
value_array_grow (value_array, n_prealloced, TRUE);
value_array->n_values = 0;
value_array->ref_count = 1;
return value_array;
}
/**
* gimp_value_array_new_from_types: (skip)
* @error_msg: return location for an error message.
* @first_type: first type in the array, or #G_TYPE_NONE.
* @...: the remaining types in the array, terminated by #G_TYPE_NONE
*
* Allocate and initialize a new #GimpValueArray, and fill it with
* values that are given as a list of (#GType, value) pairs,
* terminated by #G_TYPE_NONE.
*
* Returns: (nullable): a newly allocated #GimpValueArray, or %NULL if
* an error happened.
*
* Since: 3.0
*/
GimpValueArray *
gimp_value_array_new_from_types (gchar **error_msg,
GType first_type,
...)
{
GimpValueArray *value_array;
va_list va_args;
g_return_val_if_fail (error_msg == NULL || *error_msg == NULL, NULL);
va_start (va_args, first_type);
value_array = gimp_value_array_new_from_types_valist (error_msg,
first_type,
va_args);
va_end (va_args);
return value_array;
}
/**
* gimp_value_array_new_from_types_valist: (skip)
* @error_msg: return location for an error message.
* @first_type: first type in the array, or #G_TYPE_NONE.
* @va_args: a va_list of GTypes and values, terminated by #G_TYPE_NONE
*
* Allocate and initialize a new #GimpValueArray, and fill it with
* @va_args given in the order as passed to
* gimp_value_array_new_from_types().
*
* Returns: (nullable): a newly allocated #GimpValueArray, or %NULL if
* an error happened.
*
* Since: 3.0
*/
GimpValueArray *
gimp_value_array_new_from_types_valist (gchar **error_msg,
GType first_type,
va_list va_args)
{
GimpValueArray *value_array;
GType type;
g_return_val_if_fail (error_msg == NULL || *error_msg == NULL, NULL);
type = first_type;
value_array = gimp_value_array_new (type == G_TYPE_NONE ? 0 : 1);
while (type != G_TYPE_NONE)
{
GValue value = G_VALUE_INIT;
gchar *my_error = NULL;
g_value_init (&value, type);
G_VALUE_COLLECT (&value, va_args, G_VALUE_NOCOPY_CONTENTS, &my_error);
if (my_error)
{
if (error_msg)
{
*error_msg = my_error;
}
else
{
g_printerr ("%s: %s", G_STRFUNC, my_error);
g_free (my_error);
}
gimp_value_array_unref (value_array);
va_end (va_args);
return NULL;
}
gimp_value_array_append (value_array, &value);
g_value_unset (&value);
type = va_arg (va_args, GType);
}
va_end (va_args);
return value_array;
}
/**
* gimp_value_array_copy:
* @value_array: #GimpValueArray to copy
*
* Return an exact copy of a #GimpValueArray by duplicating all its values.
*
* Returns: a newly allocated #GimpValueArray.
*
* Since: 3.0
*/
GimpValueArray *
gimp_value_array_copy (const GimpValueArray *value_array)
{
g_return_val_if_fail (value_array != NULL, NULL);
return gimp_value_array_new_from_values (value_array->values,
value_array->n_values);
}
/**
* gimp_value_array_new_from_values:
* @values: (array length=n_values): The #GValue elements
* @n_values: the number of value elements
*
* Allocate and initialize a new #GimpValueArray, and fill it with
* the given #GValues. When no #GValues are given, returns empty #GimpValueArray.
*
* Returns: a newly allocated #GimpValueArray.
*
* Since: 3.0
*/
GimpValueArray *
gimp_value_array_new_from_values (const GValue *values,
gint n_values)
{
GimpValueArray *value_array;
gint i;
/* n_values is zero if and only if values is NULL. */
g_return_val_if_fail ((n_values == 0 && values == NULL) ||
(n_values > 0 && values != NULL),
NULL);
value_array = gimp_value_array_new (n_values);
for (i = 0; i < n_values; i++)
{
gimp_value_array_insert (value_array, i, &values[i]);
}
return value_array;
}
/**
* gimp_value_array_ref:
* @value_array: #GimpValueArray to ref
*
* Adds a reference to a #GimpValueArray.
*
* Returns: the same @value_array
*
* Since: 2.10
*/
GimpValueArray *
gimp_value_array_ref (GimpValueArray *value_array)
{
g_return_val_if_fail (value_array != NULL, NULL);
value_array->ref_count++;
return value_array;
}
/**
* gimp_value_array_unref:
* @value_array: #GimpValueArray to unref
*
* Unref a #GimpValueArray. If the reference count drops to zero, the
* array including its contents are freed.
*
* Since: 2.10
*/
void
gimp_value_array_unref (GimpValueArray *value_array)
{
g_return_if_fail (value_array != NULL);
value_array->ref_count--;
if (value_array->ref_count < 1)
{
gint i;
for (i = 0; i < value_array->n_values; i++)
{
GValue *value = value_array->values + i;
if (G_VALUE_TYPE (value) != 0) /* we allow unset values in the array */
g_value_unset (value);
}
g_free (value_array->values);
g_slice_free (GimpValueArray, value_array);
}
}
gint
gimp_value_array_length (const GimpValueArray *value_array)
{
g_return_val_if_fail (value_array != NULL, 0);
return value_array->n_values;
}
/**
* gimp_value_array_prepend:
* @value_array: #GimpValueArray to add an element to
* @value: (allow-none): #GValue to copy into #GimpValueArray, or %NULL
*
* Insert a copy of @value as first element of @value_array. If @value is
* %NULL, an uninitialized value is prepended.
*
* Returns: (transfer none): the #GimpValueArray passed in as @value_array
*
* Since: 2.10
*/
GimpValueArray *
gimp_value_array_prepend (GimpValueArray *value_array,
const GValue *value)
{
g_return_val_if_fail (value_array != NULL, NULL);
return gimp_value_array_insert (value_array, 0, value);
}
/**
* gimp_value_array_append:
* @value_array: #GimpValueArray to add an element to
* @value: (allow-none): #GValue to copy into #GimpValueArray, or %NULL
*
* Insert a copy of @value as last element of @value_array. If @value is
* %NULL, an uninitialized value is appended.
*
* Returns: (transfer none): the #GimpValueArray passed in as @value_array
*
* Since: 2.10
*/
GimpValueArray *
gimp_value_array_append (GimpValueArray *value_array,
const GValue *value)
{
g_return_val_if_fail (value_array != NULL, NULL);
return gimp_value_array_insert (value_array, value_array->n_values, value);
}
/**
* gimp_value_array_insert:
* @value_array: #GimpValueArray to add an element to
* @index: insertion position, must be &lt;= gimp_value_array_length()
* @value: (allow-none): #GValue to copy into #GimpValueArray, or %NULL
*
* Insert a copy of @value at specified position into @value_array. If @value
* is %NULL, an uninitialized value is inserted.
*
* Returns: (transfer none): the #GimpValueArray passed in as @value_array
*
* Since: 2.10
*/
GimpValueArray *
gimp_value_array_insert (GimpValueArray *value_array,
gint index,
const GValue *value)
{
gint i;
g_return_val_if_fail (value_array != NULL, NULL);
g_return_val_if_fail (index <= value_array->n_values, value_array);
i = value_array->n_values;
value_array_grow (value_array, value_array->n_values + 1, FALSE);
if (index + 1 < value_array->n_values)
memmove (value_array->values + index + 1, value_array->values + index,
(i - index) * sizeof (value_array->values[0]));
memset (value_array->values + index, 0, sizeof (value_array->values[0]));
if (value)
{
g_value_init (value_array->values + index, G_VALUE_TYPE (value));
g_value_copy (value, value_array->values + index);
}
return value_array;
}
/**
* gimp_value_array_remove:
* @value_array: #GimpValueArray to remove an element from
* @index: position of value to remove, which must be less than
* gimp_value_array_length()
*
* Remove the value at position @index from @value_array.
*
* Returns: (transfer none): the #GimpValueArray passed in as @value_array
*
* Since: 2.10
*/
GimpValueArray *
gimp_value_array_remove (GimpValueArray *value_array,
gint index)
{
g_return_val_if_fail (value_array != NULL, NULL);
g_return_val_if_fail (index < value_array->n_values, value_array);
if (G_VALUE_TYPE (value_array->values + index) != 0)
g_value_unset (value_array->values + index);
value_array->n_values--;
if (index < value_array->n_values)
memmove (value_array->values + index, value_array->values + index + 1,
(value_array->n_values - index) * sizeof (value_array->values[0]));
value_array_shrink (value_array);
if (value_array->n_prealloced > value_array->n_values)
memset (value_array->values + value_array->n_values, 0, sizeof (value_array->values[0]));
return value_array;
}
void
gimp_value_array_truncate (GimpValueArray *value_array,
gint n_values)
{
gint i;
g_return_if_fail (value_array != NULL);
g_return_if_fail (n_values > 0 && n_values <= value_array->n_values);
for (i = value_array->n_values; i > n_values; i--)
gimp_value_array_remove (value_array, i - 1);
}
/*
* GIMP_TYPE_PARAM_VALUE_ARRAY
*/
#define GIMP_PARAM_SPEC_VALUE_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_VALUE_ARRAY, GimpParamSpecValueArray))
typedef struct _GimpParamSpecValueArray GimpParamSpecValueArray;
/**
* GimpParamSpecValueArray:
* @parent_instance: private #GParamSpec portion
* @element_spec: the #GParamSpec of the array elements
* @fixed_n_elements: default length of the array
*
* A #GParamSpec derived structure that contains the meta data for
* value array properties.
**/
struct _GimpParamSpecValueArray
{
GParamSpec parent_instance;
GParamSpec *element_spec;
gint fixed_n_elements;
};
static void gimp_param_value_array_class_init (GParamSpecClass *klass);
static void gimp_param_value_array_init (GParamSpec *pspec);
static void gimp_param_value_array_finalize (GParamSpec *pspec);
static void gimp_param_value_array_set_default (GParamSpec *pspec,
GValue *value);
static gboolean gimp_param_value_array_validate (GParamSpec *pspec,
GValue *value);
static gint gimp_param_value_array_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2);
GType
gimp_param_value_array_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_value_array_class_init,
NULL, NULL,
sizeof (GimpParamSpecValueArray),
0,
(GInstanceInitFunc) gimp_param_value_array_init
};
type = g_type_register_static (G_TYPE_PARAM_BOXED,
"GimpParamValueArray", &info, 0);
}
return type;
}
static void
gimp_param_value_array_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_VALUE_ARRAY;
klass->finalize = gimp_param_value_array_finalize;
klass->value_set_default = gimp_param_value_array_set_default;
klass->value_validate = gimp_param_value_array_validate;
klass->values_cmp = gimp_param_value_array_values_cmp;
}
static void
gimp_param_value_array_init (GParamSpec *pspec)
{
GimpParamSpecValueArray *aspec = GIMP_PARAM_SPEC_VALUE_ARRAY (pspec);
aspec->element_spec = NULL;
aspec->fixed_n_elements = 0; /* disable */
}
static inline guint
gimp_value_array_ensure_size (GimpValueArray *value_array,
guint fixed_n_elements)
{
guint changed = 0;
if (fixed_n_elements)
{
while (gimp_value_array_length (value_array) < fixed_n_elements)
{
gimp_value_array_append (value_array, NULL);
changed++;
}
while (gimp_value_array_length (value_array) > fixed_n_elements)
{
gimp_value_array_remove (value_array,
gimp_value_array_length (value_array) - 1);
changed++;
}
}
return changed;
}
static void
gimp_param_value_array_finalize (GParamSpec *pspec)
{
GimpParamSpecValueArray *aspec = GIMP_PARAM_SPEC_VALUE_ARRAY (pspec);
GParamSpecClass *parent_class;
parent_class = g_type_class_peek (g_type_parent (GIMP_TYPE_PARAM_VALUE_ARRAY));
g_clear_pointer (&aspec->element_spec, g_param_spec_unref);
parent_class->finalize (pspec);
}
static void
gimp_param_value_array_set_default (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecValueArray *aspec = GIMP_PARAM_SPEC_VALUE_ARRAY (pspec);
if (! value->data[0].v_pointer && aspec->fixed_n_elements)
value->data[0].v_pointer = gimp_value_array_new (aspec->fixed_n_elements);
if (value->data[0].v_pointer)
{
/* g_value_reset (value); already done */
gimp_value_array_ensure_size (value->data[0].v_pointer,
aspec->fixed_n_elements);
}
}
static gboolean
gimp_param_value_array_validate (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecValueArray *aspec = GIMP_PARAM_SPEC_VALUE_ARRAY (pspec);
GimpValueArray *value_array = value->data[0].v_pointer;
guint changed = 0;
if (! value->data[0].v_pointer && aspec->fixed_n_elements)
value->data[0].v_pointer = gimp_value_array_new (aspec->fixed_n_elements);
if (value->data[0].v_pointer)
{
/* ensure array size validity */
changed += gimp_value_array_ensure_size (value_array,
aspec->fixed_n_elements);
/* ensure array values validity against a present element spec */
if (aspec->element_spec)
{
GParamSpec *element_spec = aspec->element_spec;
gint length = gimp_value_array_length (value_array);
gint i;
for (i = 0; i < length; i++)
{
GValue *element = gimp_value_array_index (value_array, i);
/* need to fixup value type, or ensure that the array
* value is initialized at all
*/
if (! g_value_type_compatible (G_VALUE_TYPE (element),
G_PARAM_SPEC_VALUE_TYPE (element_spec)))
{
if (G_VALUE_TYPE (element) != 0)
g_value_unset (element);
g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec));
g_param_value_set_default (element_spec, element);
changed++;
}
/* validate array value against element_spec */
changed += g_param_value_validate (element_spec, element);
}
}
}
return changed;
}
static gint
gimp_param_value_array_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2)
{
GimpParamSpecValueArray *aspec = GIMP_PARAM_SPEC_VALUE_ARRAY (pspec);
GimpValueArray *value_array1 = value1->data[0].v_pointer;
GimpValueArray *value_array2 = value2->data[0].v_pointer;
gint length1;
gint length2;
if (!value_array1 || !value_array2)
return value_array2 ? -1 : value_array1 != value_array2;
length1 = gimp_value_array_length (value_array1);
length2 = gimp_value_array_length (value_array2);
if (length1 != length2)
{
return length1 < length2 ? -1 : 1;
}
else if (! aspec->element_spec)
{
/* we need an element specification for comparisons, so there's
* not much to compare here, try to at least provide stable
* lesser/greater result
*/
return length1 < length2 ? -1 : length1 > length2;
}
else /* length1 == length2 */
{
gint i;
for (i = 0; i < length1; i++)
{
GValue *element1 = gimp_value_array_index (value_array1, i);
GValue *element2 = gimp_value_array_index (value_array2, i);
gint cmp;
/* need corresponding element types, provide stable result
* otherwise
*/
if (G_VALUE_TYPE (element1) != G_VALUE_TYPE (element2))
return G_VALUE_TYPE (element1) < G_VALUE_TYPE (element2) ? -1 : 1;
cmp = g_param_values_cmp (aspec->element_spec, element1, element2);
if (cmp)
return cmp;
}
return 0;
}
}
/**
* gimp_param_spec_value_array:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @element_spec: (nullable): #GParamSpec the contained array's elements
* have comply to, or %NULL.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecValueArray specifying a
* [type@GObject.ValueArray] property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecValueArray.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_value_array (const gchar *name,
const gchar *nick,
const gchar *blurb,
GParamSpec *element_spec,
GParamFlags flags)
{
GimpParamSpecValueArray *aspec;
if (element_spec)
g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec), NULL);
aspec = g_param_spec_internal (GIMP_TYPE_PARAM_VALUE_ARRAY,
name,
nick,
blurb,
flags);
if (element_spec)
{
aspec->element_spec = g_param_spec_ref (element_spec);
g_param_spec_sink (element_spec);
}
return G_PARAM_SPEC (aspec);
}
/**
* gimp_param_spec_value_array_get_element_spec:
* @pspec: a #GParamSpec to hold a #GimpParamSpecValueArray value.
*
* Returns: (transfer none): param spec for elements of the value array.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_value_array_get_element_spec (GParamSpec *pspec)
{
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_VALUE_ARRAY (pspec), NULL);
return GIMP_PARAM_SPEC_VALUE_ARRAY (pspec)->element_spec;
}

View file

@ -0,0 +1,103 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpvaluearray.h ported from GValueArray
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
#ifndef __GIMP_VALUE_ARRAY_H__
#define __GIMP_VALUE_ARRAY_H__
G_BEGIN_DECLS
/**
* GIMP_TYPE_VALUE_ARRAY:
*
* The type ID of the "GimpValueArray" type which is a boxed type,
* used to pass around pointers to GimpValueArrays.
*
* Since: 2.10
*/
#define GIMP_TYPE_VALUE_ARRAY (gimp_value_array_get_type ())
#define GIMP_VALUE_HOLDS_VALUE_ARRAY(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_VALUE_ARRAY))
GType gimp_value_array_get_type (void) G_GNUC_CONST;
GimpValueArray * gimp_value_array_new (gint n_prealloced);
GimpValueArray * gimp_value_array_new_from_types (gchar **error_msg,
GType first_type,
...);
GimpValueArray * gimp_value_array_new_from_types_valist (gchar **error_msg,
GType first_type,
va_list va_args);
GimpValueArray * gimp_value_array_new_from_values (const GValue *values,
gint n_values);
GimpValueArray * gimp_value_array_copy (const GimpValueArray *value_array);
GimpValueArray * gimp_value_array_ref (GimpValueArray *value_array);
void gimp_value_array_unref (GimpValueArray *value_array);
gint gimp_value_array_length (const GimpValueArray *value_array);
GValue * gimp_value_array_index (const GimpValueArray *value_array,
gint index);
GeglColor ** gimp_value_array_get_color_array (const GimpValueArray *value_array,
gint index);
GObject ** gimp_value_array_get_core_object_array (const GimpValueArray *value_array,
gint index);
GimpValueArray * gimp_value_array_prepend (GimpValueArray *value_array,
const GValue *value);
GimpValueArray * gimp_value_array_append (GimpValueArray *value_array,
const GValue *value);
GimpValueArray * gimp_value_array_insert (GimpValueArray *value_array,
gint index,
const GValue *value);
GimpValueArray * gimp_value_array_remove (GimpValueArray *value_array,
gint index);
void gimp_value_array_truncate (GimpValueArray *value_array,
gint n_values);
/*
* GIMP_TYPE_PARAM_VALUE_ARRAY
*/
#define GIMP_TYPE_PARAM_VALUE_ARRAY (gimp_param_value_array_get_type ())
#define GIMP_IS_PARAM_SPEC_VALUE_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_VALUE_ARRAY))
GType gimp_param_value_array_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_value_array (const gchar *name,
const gchar *nick,
const gchar *blurb,
GParamSpec *element_spec,
GParamFlags flags);
GParamSpec * gimp_param_spec_value_array_get_element_spec (GParamSpec *pspec);
G_END_DECLS
#endif /* __GIMP_VALUE_ARRAY_H__ */

View file

@ -0,0 +1,68 @@
#ifndef __GIMP_VERSION_H__
#define __GIMP_VERSION_H__
/* gimpversion.h.in -> gimpversion.h
* This file is configured by Meson. Please modify meson.build files.
*/
#if !defined (__GIMP_BASE_H_INSIDE__) && !defined (GIMP_BASE_COMPILATION)
#error "Only <libgimpbase/gimpbase.h> can be included directly."
#endif
G_BEGIN_DECLS
/**
* SECTION: gimpversion
* @title: gimpversion
* @short_description: Macros and constants useful for determining
* GIMP's version number and capabilities.
*
* Macros and constants useful for determining GIMP's version number and
* capabilities.
**/
/**
* GIMP_MAJOR_VERSION:
*
* The major GIMP version number.
**/
#define GIMP_MAJOR_VERSION (@GIMP_MAJOR_VERSION@)
/**
* GIMP_MINOR_VERSION:
*
* The minor GIMP version number.
**/
#define GIMP_MINOR_VERSION (@GIMP_MINOR_VERSION@)
/**
* GIMP_MICRO_VERSION:
*
* The micro GIMP version number.
**/
#define GIMP_MICRO_VERSION (@GIMP_MICRO_VERSION@)
/**
* GIMP_VERSION:
*
* The GIMP version as a string.
**/
#define GIMP_VERSION "@GIMP_VERSION@"
/**
* GIMP_API_VERSION:
*
* Since: 2.2
**/
#define GIMP_API_VERSION "@GIMP_API_VERSION@"
#define GIMP_CHECK_VERSION(major, minor, micro) \
(GIMP_MAJOR_VERSION > (major) || \
(GIMP_MAJOR_VERSION == (major) && GIMP_MINOR_VERSION > (minor)) || \
(GIMP_MAJOR_VERSION == (major) && GIMP_MINOR_VERSION == (minor) && \
GIMP_MICRO_VERSION >= (micro)))
G_END_DECLS
#endif /* __GIMP_VERSION_H__ */

View file

@ -0,0 +1,99 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpwin32-io.h
* Compatibility defines, you mostly need this as unistd.h replacement
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_WIN32_IO_H__
#define __GIMP_WIN32_IO_H__
#include <io.h>
#include <direct.h>
G_BEGIN_DECLS
#define mkdir(n,a) _mkdir(n)
#define chmod(n,f) _chmod(n,f)
#define access(f,p) _access(f,p)
#ifndef S_ISREG
#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
#endif
#ifndef S_ISDIR
#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
#endif
#ifndef S_IRUSR
#define S_IRUSR _S_IREAD
#endif
#ifndef S_IWUSR
#define S_IWUSR _S_IWRITE
#endif
#ifndef S_IXUSR
#define S_IXUSR _S_IEXEC
#endif
#ifndef S_IRGRP
#define S_IRGRP _S_IREAD
#endif
#ifndef S_IXGRP
#define S_IXGRP _S_IEXEC
#endif
#ifndef S_IROTH
#define S_IROTH _S_IREAD
#endif
#ifndef S_IXOTH
#define S_IXOTH _S_IEXEC
#endif
#ifndef _O_BINARY
#define _O_BINARY 0
#endif
#ifndef _O_TEMPORARY
#define _O_TEMPORARY 0
#endif
#ifndef F_OK
#define F_OK 0
#endif
#ifndef W_OK
#define W_OK 2
#endif
#ifndef R_OK
#define R_OK 4
#endif
#ifndef X_OK
#define X_OK 0 /* not really */
#endif
/*
2004-09-15 Tor Lillqvist <tml@iki.fi>
* glib/gwin32.h: Don't define ftruncate as a macro. Was never a
good idea, and it clashes with newest mingw headers, which have a
ftruncate implementation as an inline function. Thanks to Dominik R.
*/
/* needs coorection for msvc though ;( */
#ifdef _MSC_VER
#define ftruncate(f,s) g_win32_ftruncate(f,s)
#endif
G_END_DECLS
#endif /* __GIMP_WIN32_IO_H__ */

765
libgimpbase/gimpwire.c Normal file
View file

@ -0,0 +1,765 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include <libgimpcolor/gimpcolortypes.h>
#include "gimpwire.h"
typedef struct _GimpWireHandler GimpWireHandler;
struct _GimpWireHandler
{
guint32 type;
GimpWireReadFunc read_func;
GimpWireWriteFunc write_func;
GimpWireDestroyFunc destroy_func;
};
static GHashTable *wire_ht = NULL;
static GimpWireIOFunc wire_read_func = NULL;
static GimpWireIOFunc wire_write_func = NULL;
static GimpWireFlushFunc wire_flush_func = NULL;
static gboolean wire_error_val = FALSE;
static void gimp_wire_init (void);
void
gimp_wire_register (guint32 type,
GimpWireReadFunc read_func,
GimpWireWriteFunc write_func,
GimpWireDestroyFunc destroy_func)
{
GimpWireHandler *handler;
if (! wire_ht)
gimp_wire_init ();
handler = g_hash_table_lookup (wire_ht, &type);
if (! handler)
handler = g_slice_new0 (GimpWireHandler);
handler->type = type;
handler->read_func = read_func;
handler->write_func = write_func;
handler->destroy_func = destroy_func;
g_hash_table_insert (wire_ht, &handler->type, handler);
}
void
gimp_wire_set_reader (GimpWireIOFunc read_func)
{
wire_read_func = read_func;
}
void
gimp_wire_set_writer (GimpWireIOFunc write_func)
{
wire_write_func = write_func;
}
void
gimp_wire_set_flusher (GimpWireFlushFunc flush_func)
{
wire_flush_func = flush_func;
}
gboolean
gimp_wire_read (GIOChannel *channel,
guint8 *buf,
gsize count,
gpointer user_data)
{
if (wire_read_func)
{
if (!(* wire_read_func) (channel, buf, count, user_data))
{
/* Gives a confusing error message most of the time, disable:
g_warning ("%s: gimp_wire_read: error", g_get_prgname ());
*/
wire_error_val = TRUE;
return FALSE;
}
}
else
{
GIOStatus status;
GError *error = NULL;
gsize bytes;
while (count > 0)
{
do
{
bytes = 0;
status = g_io_channel_read_chars (channel,
(gchar *) buf, count,
&bytes,
&error);
}
while (G_UNLIKELY (status == G_IO_STATUS_AGAIN));
if (G_UNLIKELY (bytes == 0 && status == G_IO_STATUS_EOF))
{
g_warning ("%s: gimp_wire_read(): unexpected EOF",
g_get_prgname ());
wire_error_val = TRUE;
return FALSE;
}
else if (G_UNLIKELY (status != G_IO_STATUS_NORMAL))
{
if (error)
{
g_warning ("%s: gimp_wire_read(): error: %s",
g_get_prgname (), error->message);
g_error_free (error);
}
else
{
g_warning ("%s: gimp_wire_read(): error",
g_get_prgname ());
}
wire_error_val = TRUE;
return FALSE;
}
count -= bytes;
buf += bytes;
}
}
return TRUE;
}
gboolean
gimp_wire_write (GIOChannel *channel,
const guint8 *buf,
gsize count,
gpointer user_data)
{
if (wire_write_func)
{
if (!(* wire_write_func) (channel, (guint8 *) buf, count, user_data))
{
g_warning ("%s: gimp_wire_write: error", g_get_prgname ());
wire_error_val = TRUE;
return FALSE;
}
}
else
{
GIOStatus status;
GError *error = NULL;
gsize bytes;
while (count > 0)
{
do
{
bytes = 0;
status = g_io_channel_write_chars (channel,
(const gchar *) buf, count,
&bytes,
&error);
}
while (G_UNLIKELY (status == G_IO_STATUS_AGAIN));
if (G_UNLIKELY (status != G_IO_STATUS_NORMAL))
{
if (error)
{
g_warning ("%s: gimp_wire_write(): error: %s",
g_get_prgname (), error->message);
g_error_free (error);
}
else
{
g_warning ("%s: gimp_wire_write(): error",
g_get_prgname ());
}
wire_error_val = TRUE;
return FALSE;
}
count -= bytes;
buf += bytes;
}
}
return TRUE;
}
gboolean
gimp_wire_flush (GIOChannel *channel,
gpointer user_data)
{
if (wire_flush_func)
return (* wire_flush_func) (channel, user_data);
return FALSE;
}
gboolean
gimp_wire_error (void)
{
return wire_error_val;
}
void
gimp_wire_clear_error (void)
{
wire_error_val = FALSE;
}
gboolean
gimp_wire_read_msg (GIOChannel *channel,
GimpWireMessage *msg,
gpointer user_data)
{
GimpWireHandler *handler;
if (G_UNLIKELY (! wire_ht))
g_error ("gimp_wire_read_msg: the wire protocol has not been initialized");
if (wire_error_val)
return !wire_error_val;
if (! _gimp_wire_read_int32 (channel, &msg->type, 1, user_data))
return FALSE;
handler = g_hash_table_lookup (wire_ht, &msg->type);
if (G_UNLIKELY (! handler))
g_error ("gimp_wire_read_msg: could not find handler for message: %d",
msg->type);
(* handler->read_func) (channel, msg, user_data);
return !wire_error_val;
}
gboolean
gimp_wire_write_msg (GIOChannel *channel,
GimpWireMessage *msg,
gpointer user_data)
{
GimpWireHandler *handler;
if (G_UNLIKELY (! wire_ht))
g_error ("gimp_wire_write_msg: the wire protocol has not been initialized");
if (wire_error_val)
return !wire_error_val;
handler = g_hash_table_lookup (wire_ht, &msg->type);
if (G_UNLIKELY (! handler))
g_error ("gimp_wire_write_msg: could not find handler for message: %d",
msg->type);
if (! _gimp_wire_write_int32 (channel, &msg->type, 1, user_data))
return FALSE;
(* handler->write_func) (channel, msg, user_data);
return !wire_error_val;
}
void
gimp_wire_destroy (GimpWireMessage *msg)
{
GimpWireHandler *handler;
if (G_UNLIKELY (! wire_ht))
g_error ("gimp_wire_destroy: the wire protocol has not been initialized");
handler = g_hash_table_lookup (wire_ht, &msg->type);
if (G_UNLIKELY (! handler))
g_error ("gimp_wire_destroy: could not find handler for message: %d\n",
msg->type);
(* handler->destroy_func) (msg);
}
gboolean
_gimp_wire_read_int64 (GIOChannel *channel,
guint64 *data,
gint count,
gpointer user_data)
{
g_return_val_if_fail (count >= 0, FALSE);
if (count > 0)
{
if (! _gimp_wire_read_int8 (channel,
(guint8 *) data, count * 8, user_data))
return FALSE;
while (count--)
{
*data = GUINT64_FROM_BE (*data);
data++;
}
}
return TRUE;
}
gboolean
_gimp_wire_read_int32 (GIOChannel *channel,
guint32 *data,
gint count,
gpointer user_data)
{
g_return_val_if_fail (count >= 0, FALSE);
if (count > 0)
{
if (! _gimp_wire_read_int8 (channel,
(guint8 *) data, count * 4, user_data))
return FALSE;
while (count--)
{
*data = g_ntohl (*data);
data++;
}
}
return TRUE;
}
gboolean
_gimp_wire_read_int16 (GIOChannel *channel,
guint16 *data,
gint count,
gpointer user_data)
{
g_return_val_if_fail (count >= 0, FALSE);
if (count > 0)
{
if (! _gimp_wire_read_int8 (channel,
(guint8 *) data, count * 2, user_data))
return FALSE;
while (count--)
{
*data = g_ntohs (*data);
data++;
}
}
return TRUE;
}
gboolean
_gimp_wire_read_int8 (GIOChannel *channel,
guint8 *data,
gint count,
gpointer user_data)
{
g_return_val_if_fail (count >= 0, FALSE);
return gimp_wire_read (channel, data, count, user_data);
}
gboolean
_gimp_wire_read_double (GIOChannel *channel,
gdouble *data,
gint count,
gpointer user_data)
{
gdouble *t;
guint8 tmp[8];
gint i;
g_return_val_if_fail (count >= 0, FALSE);
t = (gdouble *) tmp;
for (i = 0; i < count; i++)
{
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
gint j;
#endif
if (! _gimp_wire_read_int8 (channel, tmp, 8, user_data))
return FALSE;
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
for (j = 0; j < 4; j++)
{
guint8 swap;
swap = tmp[j];
tmp[j] = tmp[7 - j];
tmp[7 - j] = swap;
}
#endif
data[i] = *t;
}
return TRUE;
}
gboolean
_gimp_wire_read_string (GIOChannel *channel,
gchar **data,
gint count,
gpointer user_data)
{
gint i;
g_return_val_if_fail (count >= 0, FALSE);
for (i = 0; i < count; i++)
{
guint32 tmp;
if (! _gimp_wire_read_int32 (channel, &tmp, 1, user_data))
return FALSE;
if (tmp > 0)
{
data[i] = g_try_new (gchar, tmp);
if (! data[i])
{
g_printerr ("%s: failed to allocate %u bytes\n", G_STRFUNC, tmp);
return FALSE;
}
if (! _gimp_wire_read_int8 (channel,
(guint8 *) data[i], tmp, user_data))
{
g_free (data[i]);
return FALSE;
}
/* make sure that the string is NULL-terminated */
data[i][tmp - 1] = '\0';
}
else
{
data[i] = NULL;
}
}
return TRUE;
}
gboolean
_gimp_wire_read_gegl_color (GIOChannel *channel,
GBytes **pixel_data,
GBytes **icc_data,
gchar **encoding,
gint count,
gpointer user_data)
{
gint i;
g_return_val_if_fail (count >= 0, FALSE);
for (i = 0; i < count; i++)
{
guint32 size;
guint8 pixel[40];
guint32 icc_length;
if (! _gimp_wire_read_int32 (channel,
&size, 1,
user_data) ||
size > 40 ||
! _gimp_wire_read_int8 (channel, pixel, size, user_data) ||
! _gimp_wire_read_string (channel, &(encoding[i]), 1, user_data) ||
! _gimp_wire_read_int32 (channel, &icc_length, 1, user_data))
{
g_clear_pointer (&(encoding[i]), g_free);
return FALSE;
}
pixel_data[i] = (size > 0 ? g_bytes_new (pixel, size) : NULL);
/* Read space (profile data). */
icc_data[i] = NULL;
if (icc_length > 0)
{
guint8 *icc;
icc = g_new0 (guint8, icc_length);
if (! _gimp_wire_read_int8 (channel, icc, icc_length, user_data))
{
g_clear_pointer (&(encoding[i]), g_free);
g_clear_pointer (&icc, g_free);
return FALSE;
}
icc_data[i] = g_bytes_new_take (icc, icc_length);
}
}
return TRUE;
}
gboolean
_gimp_wire_write_int64 (GIOChannel *channel,
const guint64 *data,
gint count,
gpointer user_data)
{
g_return_val_if_fail (count >= 0, FALSE);
if (count > 0)
{
gint i;
for (i = 0; i < count; i++)
{
guint64 tmp = GUINT64_TO_BE (data[i]);
if (! _gimp_wire_write_int8 (channel,
(const guint8 *) &tmp, 8, user_data))
return FALSE;
}
}
return TRUE;
}
gboolean
_gimp_wire_write_int32 (GIOChannel *channel,
const guint32 *data,
gint count,
gpointer user_data)
{
g_return_val_if_fail (count >= 0, FALSE);
if (count > 0)
{
gint i;
for (i = 0; i < count; i++)
{
guint32 tmp = g_htonl (data[i]);
if (! _gimp_wire_write_int8 (channel,
(const guint8 *) &tmp, 4, user_data))
return FALSE;
}
}
return TRUE;
}
gboolean
_gimp_wire_write_int16 (GIOChannel *channel,
const guint16 *data,
gint count,
gpointer user_data)
{
g_return_val_if_fail (count >= 0, FALSE);
if (count > 0)
{
gint i;
for (i = 0; i < count; i++)
{
guint16 tmp = g_htons (data[i]);
if (! _gimp_wire_write_int8 (channel,
(const guint8 *) &tmp, 2, user_data))
return FALSE;
}
}
return TRUE;
}
gboolean
_gimp_wire_write_int8 (GIOChannel *channel,
const guint8 *data,
gint count,
gpointer user_data)
{
g_return_val_if_fail (count >= 0, FALSE);
return gimp_wire_write (channel, data, count, user_data);
}
gboolean
_gimp_wire_write_double (GIOChannel *channel,
const gdouble *data,
gint count,
gpointer user_data)
{
gdouble *t;
guint8 tmp[8];
gint i;
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
gint j;
#endif
g_return_val_if_fail (count >= 0, FALSE);
t = (gdouble *) tmp;
for (i = 0; i < count; i++)
{
*t = data[i];
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
for (j = 0; j < 4; j++)
{
guint8 swap;
swap = tmp[j];
tmp[j] = tmp[7 - j];
tmp[7 - j] = swap;
}
#endif
if (! _gimp_wire_write_int8 (channel, tmp, 8, user_data))
return FALSE;
#if 0
{
gint k;
g_print ("Wire representation of %f:\t", data[i]);
for (k = 0; k < 8; k++)
g_print ("%02x ", tmp[k]);
g_print ("\n");
}
#endif
}
return TRUE;
}
gboolean
_gimp_wire_write_string (GIOChannel *channel,
gchar **data,
gint count,
gpointer user_data)
{
gint i;
g_return_val_if_fail (count >= 0, FALSE);
for (i = 0; i < count; i++)
{
guint32 tmp;
if (data[i])
tmp = strlen (data[i]) + 1;
else
tmp = 0;
if (! _gimp_wire_write_int32 (channel, &tmp, 1, user_data))
return FALSE;
if (tmp > 0)
if (! _gimp_wire_write_int8 (channel,
(const guint8 *) data[i], tmp, user_data))
return FALSE;
}
return TRUE;
}
gboolean
_gimp_wire_write_gegl_color (GIOChannel *channel,
GBytes **pixel_data,
GBytes **icc_data,
gchar **encoding,
gint count,
gpointer user_data)
{
gint i;
g_return_val_if_fail (count >= 0, FALSE);
for (i = 0; i < count; i++)
{
const guint8 *pixel = NULL;
gsize bpp = 0;
const guint8 *icc = NULL;
gsize icc_length = 0;
if (pixel_data[i])
pixel = g_bytes_get_data (pixel_data[i], &bpp);
if (icc_data[i])
icc = g_bytes_get_data (icc_data[i], &icc_length);
if (! _gimp_wire_write_int32 (channel, (const guint32 *) &bpp, 1, user_data))
return FALSE;
if (bpp > 0 && ! _gimp_wire_write_int8 (channel, pixel, bpp, user_data))
return FALSE;
if (! _gimp_wire_write_string (channel, &(encoding[i]), 1, user_data) ||
! _gimp_wire_write_int32 (channel, (const guint32 *) &icc_length, 1, user_data))
return FALSE;
if (icc_length > 0 && ! _gimp_wire_write_int8 (channel, icc, icc_length, user_data))
return FALSE;
}
return TRUE;
}
static guint
gimp_wire_hash (const guint32 *key)
{
return *key;
}
static gboolean
gimp_wire_compare (const guint32 *a,
const guint32 *b)
{
return (*a == *b);
}
static void
gimp_wire_init (void)
{
if (! wire_ht)
wire_ht = g_hash_table_new ((GHashFunc) gimp_wire_hash,
(GCompareFunc) gimp_wire_compare);
}

152
libgimpbase/gimpwire.h Normal file
View file

@ -0,0 +1,152 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_WIRE_H__
#define __GIMP_WIRE_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
typedef struct _GimpWireMessage GimpWireMessage;
typedef void (* GimpWireReadFunc) (GIOChannel *channel,
GimpWireMessage *msg,
gpointer user_data);
typedef void (* GimpWireWriteFunc) (GIOChannel *channel,
GimpWireMessage *msg,
gpointer user_data);
typedef void (* GimpWireDestroyFunc) (GimpWireMessage *msg);
typedef gboolean (* GimpWireIOFunc) (GIOChannel *channel,
const guint8 *buf,
gulong count,
gpointer user_data);
typedef gboolean (* GimpWireFlushFunc) (GIOChannel *channel,
gpointer user_data);
struct _GimpWireMessage
{
guint32 type;
gpointer data;
};
void gimp_wire_register (guint32 type,
GimpWireReadFunc read_func,
GimpWireWriteFunc write_func,
GimpWireDestroyFunc destroy_func);
void gimp_wire_set_reader (GimpWireIOFunc read_func);
void gimp_wire_set_writer (GimpWireIOFunc write_func);
void gimp_wire_set_flusher (GimpWireFlushFunc flush_func);
gboolean gimp_wire_read (GIOChannel *channel,
guint8 *buf,
gsize count,
gpointer user_data);
gboolean gimp_wire_write (GIOChannel *channel,
const guint8 *buf,
gsize count,
gpointer user_data);
gboolean gimp_wire_flush (GIOChannel *channel,
gpointer user_data);
gboolean gimp_wire_error (void);
void gimp_wire_clear_error (void);
gboolean gimp_wire_read_msg (GIOChannel *channel,
GimpWireMessage *msg,
gpointer user_data);
gboolean gimp_wire_write_msg (GIOChannel *channel,
GimpWireMessage *msg,
gpointer user_data);
void gimp_wire_destroy (GimpWireMessage *msg);
/* for internal use in libgimpbase */
G_GNUC_INTERNAL gboolean _gimp_wire_read_int64 (GIOChannel *channel,
guint64 *data,
gint count,
gpointer user_data);
G_GNUC_INTERNAL gboolean _gimp_wire_read_int32 (GIOChannel *channel,
guint32 *data,
gint count,
gpointer user_data);
G_GNUC_INTERNAL gboolean _gimp_wire_read_int16 (GIOChannel *channel,
guint16 *data,
gint count,
gpointer user_data);
G_GNUC_INTERNAL gboolean _gimp_wire_read_int8 (GIOChannel *channel,
guint8 *data,
gint count,
gpointer user_data);
G_GNUC_INTERNAL gboolean _gimp_wire_read_double (GIOChannel *channel,
gdouble *data,
gint count,
gpointer user_data);
G_GNUC_INTERNAL gboolean _gimp_wire_read_string (GIOChannel *channel,
gchar **data,
gint count,
gpointer user_data);
G_GNUC_INTERNAL gboolean
_gimp_wire_read_gegl_color (GIOChannel *channel,
GBytes **pixel_data,
GBytes **icc_data,
gchar **encoding,
gint count,
gpointer user_data);
G_GNUC_INTERNAL gboolean _gimp_wire_write_int64 (GIOChannel *channel,
const guint64 *data,
gint count,
gpointer user_data);
G_GNUC_INTERNAL gboolean _gimp_wire_write_int32 (GIOChannel *channel,
const guint32 *data,
gint count,
gpointer user_data);
G_GNUC_INTERNAL gboolean _gimp_wire_write_int16 (GIOChannel *channel,
const guint16 *data,
gint count,
gpointer user_data);
G_GNUC_INTERNAL gboolean _gimp_wire_write_int8 (GIOChannel *channel,
const guint8 *data,
gint count,
gpointer user_data);
G_GNUC_INTERNAL gboolean _gimp_wire_write_double (GIOChannel *channel,
const gdouble *data,
gint count,
gpointer user_data);
G_GNUC_INTERNAL gboolean _gimp_wire_write_string (GIOChannel *channel,
gchar **data,
gint count,
gpointer user_data);
G_GNUC_INTERNAL gboolean
_gimp_wire_write_gegl_color (GIOChannel *channel,
GBytes **pixel_data,
GBytes **icc_data,
gchar **encoding,
gint count,
gpointer user_data);
G_END_DECLS
#endif /* __GIMP_WIRE_H__ */

154
libgimpbase/meson.build Normal file
View file

@ -0,0 +1,154 @@
if platform_osx
add_project_arguments('-ObjC', language : 'c')
endif
gimpversion = configure_file(
input : 'gimpversion.h.in',
output: 'gimpversion.h',
configuration: versionconfig,
)
stamp_base_enums = custom_target('stamp-gimpbaseenums.h',
input : [
files(
'gimpbaseenums.h'
),
],
output: [ 'stamp-gimpbaseenums.h', ],
command: [
mkenums_wrap, perl,
meson.project_source_root(), meson.current_source_dir(),
meson.current_build_dir(),
'gimpbase',
'#include <glib-object.h>\n' +
'#include "gimpbasetypes.h"\n' +
'#include "libgimp/libgimp-intl.h"\n',
'',
libgimp_mkenums_dtails
],
build_by_default: true
)
stamp_compat_enums = custom_target('stamp-gimpcompatenums.h',
input : [
files(
'gimpcompatenums.h'
),
],
output: [ 'stamp-gimpcompatenums.h', ],
command: [
mkenums_wrap, perl,
meson.project_source_root(), meson.current_source_dir(), meson.current_build_dir(),
'gimpcompat',
'#include <glib-object.h>\n' +
'#include "gimpbasetypes.h"\n',
'#include "libgimp/libgimp-intl.h"',
],
build_by_default: true
)
libgimpbase_sources_introspectable = files(
'gimpbasetypes.c',
'gimpchecks.c',
'gimpchoice.c',
'gimpcpuaccel.c',
'gimpenv.c',
'gimpexportoptions.c',
'gimpmemsize.c',
'gimpmetadata.c',
'gimpparamspecs.c',
'gimpparasite.c',
'gimpparasiteio.c',
'gimprectangle.c',
'gimpunit.c',
'gimputils.c',
'gimpvaluearray.c',
)
libgimpbase_sources = [
libgimpbase_sources_introspectable,
'gimpbase-private.c',
'gimpprotocol.c',
'gimpreloc.c',
'gimpsignal.c',
'gimpwire.c',
'gimpbaseenums.c',
stamp_base_enums,
'gimpcompatenums.c',
stamp_compat_enums
]
libgimpbase_headers_introspectable = files(
'gimpbaseenums.h',
'gimpbasetypes.h',
'gimpchecks.h',
'gimpchoice.h',
'gimpcpuaccel.h',
'gimpenv.h',
'gimpexportoptions.h',
'gimplimits.h',
'gimpmemsize.h',
'gimpmetadata.h',
'gimpparamspecs.h',
'gimpparasite.h',
'gimpparasiteio.h',
'gimprectangle.h',
'gimpunit.h',
'gimputils.h',
'gimpvaluearray.h',
) + [
gimpversion,
]
libgimpbase_headers = [
libgimpbase_headers_introspectable,
'gimpbase.h',
gimpversion,
]
libgimpbase_introspectable = [
libgimpbase_sources_introspectable,
libgimpbase_headers_introspectable,
]
libgimpbase = library('gimpbase-' + gimp_api_version,
libgimpbase_sources,
include_directories: rootInclude,
dependencies: [
gegl, gexiv2, gio, math,
# optionally depend on libexecinfo on platforms where it is not
# internal to the libc.
opt_execinfo,
],
c_args: [
'-DG_LOG_DOMAIN="LibGimpBase"',
'-DGIMP_BASE_COMPILATION',
],
vs_module_defs: 'gimpbase.def',
install: true,
version: so_version,
)
install_headers(
libgimpbase_headers,
subdir: gimp_api_name / 'libgimpbase',
)
# Test program, not installed
executable('test-cpu-accel',
'test-cpu-accel.c',
include_directories: rootInclude,
dependencies: [
glib,
],
c_args: [
'-DG_LOG_DOMAIN="LibGimpBase"',
'-DGIMP_BASE_COMPILATION',
],
link_with: [
libgimpbase,
],
install: false,
)

View file

@ -0,0 +1,48 @@
/* A small test program for the CPU detection code */
#include "config.h"
#include <stdlib.h>
#include <glib.h>
#include "gimpcpuaccel.h"
static void
cpu_accel_print_results (void)
{
GimpCpuAccelFlags support;
g_printerr ("Testing CPU features...\n");
support = gimp_cpu_accel_get_support ();
#ifdef ARCH_X86
g_printerr (" mmx : %s\n",
(support & GIMP_CPU_ACCEL_X86_MMX) ? "yes" : "no");
g_printerr (" 3dnow : %s\n",
(support & GIMP_CPU_ACCEL_X86_3DNOW) ? "yes" : "no");
g_printerr (" mmxext : %s\n",
(support & GIMP_CPU_ACCEL_X86_MMXEXT) ? "yes" : "no");
g_printerr (" sse : %s\n",
(support & GIMP_CPU_ACCEL_X86_SSE) ? "yes" : "no");
g_printerr (" sse2 : %s\n",
(support & GIMP_CPU_ACCEL_X86_SSE2) ? "yes" : "no");
g_printerr (" sse3 : %s\n",
(support & GIMP_CPU_ACCEL_X86_SSE3) ? "yes" : "no");
#endif
#ifdef ARCH_PPC
g_printerr (" altivec : %s\n",
(support & GIMP_CPU_ACCEL_PPC_ALTIVEC) ? "yes" : "no");
#endif
g_printerr ("\n");
}
int
main (void)
{
cpu_accel_print_results ();
return EXIT_SUCCESS;
}