Commit Graph

226 Commits

Author SHA1 Message Date
Michael Natterer b9265e7cde Issue #2685 - Crash when distributing layers horizontally
Fix xcf-load.c to correct out-of-range item offsets (simply set them
to 0), so XCF files that are broken this way can still be recovered.

This doesn't fix the original bug, just recovering the crash images.
2019-01-03 15:02:55 +01:00
Elle Stone 298cc57042 Issue #2345 - Add xyY to color sample readouts
Add xyY color space to the color spaces for sampling colors.

Also add code to xcf-load.c that makes sure the sample point loading
code handles unknown future GimpColorPickMode values (fall back to
PIXEL pick mode).
2018-10-23 17:37:28 +02:00
Michael Natterer e09e563a70 Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.

libgimp:

- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
  as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
  NON_LINEAR and PERCPTUAL for each encoding, matching the babl
  encoding variants RGB, R'G'B' and R~G~B~.

- gimp_color_transform_can_gegl_copy() now returns TRUE if both
  profiles can return a babl space, increasing the amount of fast babl
  color conversions significantly.

- TODO: no solution yet for getting libgimp drawable proxy buffers in
  the right format with space.

plug-ins:

- follow the GimpPrecision change.

- TODO: everything else unchanged and partly broken or sub-optimal,
  like setting a new image's color profile too late.

app:

- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
  replacement for all "linear" booleans.

- change gimp-babl functions to take babl spaces and GimpTRCType
  parameters and support all sorts of new perceptual ~ formats.

- a lot of places changed in the early days of goat invasion didn't
  take advantage of gimp-babl utility functions and constructed
  formats manually. They all needed revisiting and many now use much
  simpler code calling gimp-babl API.

- change gimp_babl_format_get_color_profile() to really extract a
  newly allocated color profile from the format, and add
  gimp_babl_get_builtin_color_profile() which does the same as
  gimp_babl_format_get_color_profile() did before. Visited all callers
  to decide whether they are looking for the format's actual profile,
  or for one of the builtin profiles, simplifying code that only needs
  builtin profiles.

- drawables have a new get_space_api(), get_linear() is now get_trc().

- images now have a "layer space" and an API to get it,
  gimp_image_get_layer_format() returns formats in that space.

- an image's layer space is created from the image's color profile,
  change gimpimage-color-profile to deal with that correctly

- change many babl_format() calls to babl_format_with_space() and take
  the space from passed formats or drawables

- add function gimp_layer_fix_format_space() which replaces the
  layer's buffer with one that has the image's layer format, but
  doesn't change pixel values

- use gimp_layer_fix_format_space() to make sure layers loaded from
  XCF and created by plug-ins have the right space when added to the
  image, because it's impossible to always assign the right space upon
  layer creation

- "assign color profile" and "discard color profile" now require use
  of gimp_layer_fix_format_space() too because the profile is now
  embedded in all formats via the space.  Add
  gimp_image_assign_color_profile() which does all that and call it
  instead of a simple gimp_image_set_color_profile(), also from the
  PDB set-color-profile functions, which are essentially "assign" and
  "discard" calls.

- generally, make sure a new image's color profile is set before
  adding layers to it, gimp_image_set_color_profile() is more than
  before considered know-what-you-are-doing API.

- take special precaution in all places that call
  gimp_drawable_convert_type(), we now must pass a new_profile from
  all callers that convert layers within the same image (such as
  image_convert_type, image_convert_precision), because the layer's
  new space can't be determined from the image's layer format during
  the call.

- change all "linear" properties to "trc", in all config objects like
  for levels and curves, in the histogram, in the widgets. This results
  in some GUI that now has three choices instead of two.
  TODO: we might want to reduce that back to two later.

- keep "linear" boolean properties around as compat if needed for file
  pasring, but always convert the parsed parsed boolean to
  GimpTRCType.

- TODO: the image's "enable color management" switch is currently
  broken, will fix that in another commit.
2018-07-21 16:42:57 +02:00
Michael Natterer ac5f44eb74 app: opaque in gimp_layer_new() is 1.0 not 255
The value is later CLAMP()ed correctly, but fix the call in xcf-load.c
anyway.
2018-07-16 14:47:10 +02:00
Michael Natterer 47a008be97 Issue #1805 - Sample Points keep resetting themselves to "Pixel"
Rename XCF property PROP_SAMPLE_POINT to PROP_OLD_SAMPLE_POINT and add
new PROP_SAMPLE_POINT.

The new property saves the sample point's pick mode plus some padding
for whatever else we might want to add. Always save the old property
too so nothing changes for older GIMP versions, and avoid loading the
old property if the new one was loaded before.
2018-07-16 01:42:19 +02:00
Michael Natterer 5f700549e7 Change the license URL from http://www.gnu.org/licenses/ to https:// 2018-07-11 23:29:46 +02:00
Ell a0a62656d2 Issue #1792 - Xcf file crashing gimp-console-2.10 ...
... (valgrind reports Invalid read)

Add gimp_babl_is_valid(), which takes a GimpImageBaseType and a
GimpPrecision, and determines whether the image-type/precision
combination is valid.  Use this function to validate that loaded
XCFs use a valid type/precision combination, before trying to
create the image.  Otherwise, we get a CRITICAL, and eventually a
segfault, when the combination is invalid.

Use the same function to validate the arguments of
gimp_image_new().
2018-07-06 13:06:46 -04:00
Ell d4ff57c793 app: avoid CRITICAL when loading XCF with empty gimp-image-metadata parasite 2018-07-05 22:47:45 -04:00
Michael Natterer ecb99ab445 app: add the new distance, rotation and slider axes to GimpCoords
and add code to get them from events and devices.
2018-05-20 21:06:35 +02:00
luz.paz 4a77ff2d3d Bug 795557 - Misc. typo fixes in source, comments and doxygen (pt3)
Found via `codespell` and grep.
2018-04-25 23:49:06 +02:00
Michael Natterer 43549b7a38 app: remove some references to TileManager from xcf-load.c comments
and minor whitepace cleanup.
2018-04-06 12:56:31 +02:00
Jehan 65717041ed app: save image symmetries in the XCF file.
Symmetries are saved in a parasite, which is backward compatible.
2018-04-01 15:08:48 +02:00
Ell fcde7bdf47 app: small cleanup in xcf_load_channel_props()
Remove the impromptu boundary invalidation when converting a
channel to a selection mask in xcf_load_channel_props(), as this
happens implicitly when stealing the channel's buffer, since
commit 38d4aa8121.
2018-02-13 13:47:37 -05:00
Ell 38d4aa8121 Bug 793428 - Errors when loading an XCF with a saved selection mask
Since commit d0ae244fe8, which
connects GimpChannel instances to their buffer's "changed" signal,
the XCF loading code that steals a channel's buffer when converting
it to a selection mask (which happens when loading an XCF with a
saved selection mask) is unsafe, since fails to perform the
necessary cleanup and setup of the buffer in the old and new
channel objects, respectively.

Perform the buffer transfer using the new
gimp_drawable_steal_buffer(), which does the same thing in a safe
manner.
2018-02-13 13:29:15 -05:00
Michael Natterer d613842eba Bug 788768 - GIMP crashes loading a valid truncated xcf
If the XCF is truncated in the middle of selection mask data,
don't unref the currently loading channel because we can't
unref the image's selection.
2017-11-19 18:28:36 +01:00
Ell 0ae7acd594 app: in xcf-load, avoid writing buffer data for empty tiles
When loading tile data, avoid copying the data into the GEGL
buffer when the tile is empty (i.e., all its bytes are 0), so that
GEGL doesn't allocate memory for it unnecessarily.
2017-10-04 06:51:34 -04:00
Michael Natterer 8f3cee4241 app: also fix the calls to xcf_read,write-component() 2017-10-01 17:43:10 +02:00
Michael Natterer 4503dad78c app: also, it's not the number of pixels but the number of components, sigh 2017-10-01 17:39:54 +02:00
Michael Natterer 2e0035c9df app: XCF endian swapping was still not correct
The number of pixels is "tile_size / bpp", not "tile_size / n_components".
2017-10-01 17:27:04 +02:00
Michael Natterer a735ba0daa app: add code to read/write XCF tile data as big-endian
It was always supposed to be like that, but simply forgotten.
Fortunately, big-endian machines are almost extinct...

The new code is triggered with XCF version >= 12, but we will start
using that only after code review.
2017-09-16 19:03:20 +02:00
Michael Natterer 0cfe550639 app, pdb: change a lot of GIMP_LAYER_MODE_NORMAL_LEGACY to just NORMAL
this commit changes just those which make no difference to
functionality: property and object member defaults that get overridden
anyway, return values of g_return_val_if_fail(), some other stuff.
2017-08-19 20:33:47 +02:00
Ell 6b84293078 app: limit allowable tile data size in XCFs
When loading tiles from an XCF, reject tiles whose on-disk size is
greater than 1.5 times the size of an uncompressed tile -- a limit
that is already present for the last tile in the buffer.  This
should allow for the possibility of negative compression, while
restricting placing a realistic limit.

Currently, no limit is placed on the on-disk tile data size.  When
loading RLE- and zlib-compressed tiles, a buffer large enough to
hold the entire on-disk tile data, up to 2GB, is allocated on the
stack, and the data is read into it.  If the file is smaller than
the reported tile data size, the area of the buffer past the end
of the file is not touched.  This allows a malicious XCF to write
up to 2GB of arbitrary data, at an arbitrary offset, up to 2GB,
below the stack.

Note that a similar issue had existed for earlier versions of GIMP
(see commit d7a9e6079d), however,
since prior to 2.9 the tile data buffer was allocated on the heap,
the potential risk is far smaller.
2017-07-28 16:51:08 -04:00
Ell e7d781ff0e app: future-proof XCF layer blend/composite props
The layer blend space, composite space, and composite mode
properties have a special AUTO value, which may map to different
concrete values based on the layer mode.  Make sure we can change
this mapping in the future, without affecting existing XCFs (saved
after this commit), by encoding these properties as follows:

When saving an XCF, if the property has a concrete (non-AUTO)
value, which is always positive, encode it as is.  If the property
is AUTO, which is always 0, encode it as the negative of the value
it actually maps to at the time of saving (note that in some cases
AUTO may map to AUTO, in which case it's encoded as 0).

When loading an XCF, if the encoded property (stored in the file)
is nonnegative, use it as is.  Otherwise, compare the negative of
the encoded property to the value AUTO maps to at the time of
loading.  If the values are equal, set the property to AUTO;
otherwise, use the concrete value (i.e., the negative of the value
stored in the XCF).

Note that XCFs saved prior to this commit still load fine, it's
simply that if we change the AUTO mapping in the future, all their
AUTO properties will keep being loaded as AUTO, even if the
resulting concrete values will have changed.
2017-05-21 08:44:19 -04:00
Michael Natterer 10360c9e13 app: add new XCF property PROP_FLOAT_COLOR
We were still saving channel colors in 8 bit, this additionally
saves/loads the color as float values. Still save the old PROP_COLOR
for compatibility.
2017-03-24 22:35:57 +01:00
Michael Natterer a0521a520f app: change the "XCF compat" stuff to "XCF compression"
Both in the GimpImage API and in the GUI. The toggle in the save
dialog now controls ZLIB compression directly. Changed the various
info labels accordingly. Ditch the XCF parasite that saved the XCF
compat mode.
2017-03-23 18:03:27 +01:00
Michael Natterer 01be120349 Bug 731390 - XCF files have a max size of 4G
Change the xcf_read_foo() functions to take the XcfInfo* instead of
a GInputStream*, and make them advance the info->cp offset by
themselves. Makes xcf-load.c a lot more readable.
2017-03-23 12:26:09 +01:00
Michael Natterer a0a5f714bb Bug 731390 - XCF files have a max size of 4G
Step one, without changing anything in the saved XCFs yet:

Abstract reading and writing of file offsets away into their own
xcf_read_offset() and xcf_write_offset() functions, which take
"goffset" instead of "guint32". Also change xcf_seek_pos() to take a
goffset argument.

Change all file offset variables in xcf-load.c, xcf-write.c and struct
XcfInfo to goffset, and add new member "bytes_per_offset" to XcfInfo,
which is currently always 4.
2017-03-23 11:44:41 +01:00
Michael Natterer 3cf423f0cd *: rename NORMAL to NORMAL_LEGACY and NORMAL_LINEAR to NORMAL
and make NORMAL_LEGACY immutable.
2017-02-26 16:26:34 +01:00
Michael Natterer 8634b5cbc3 app: make layer blend color space and compositing color space configurable
...they say it's going to get worse before it gets better...
2017-02-12 23:49:26 +01:00
Michael Natterer 2a96d598c3 app: add internal and PDB API and UI to control a layer's composite mode
Largely based on a patch by Ell, with the enum type renamed and
various small changes. Adds another axis of configurability to the
existing layer mode madness, and is WIP too.
2017-02-02 00:38:25 +01:00
Michael Natterer 152adbb1bd Rename GIMP_LAYER_MODE_FOO_BROKEN to GIMP_LAYER_MODE_FOO_LEGACY
"Broken" sounds like it needs fixing, but it's legacy compat stuff
that will have to stay for all eternity.
2017-01-09 01:27:20 +01:00
Michael Natterer 66060e3307 app, libgimp*, plug-ins: replace enum GimpLayerModeEffects by GimpLayerMode
with proper value names. Mark most values as _BROKEN because they use
weird alpha compositing that has to die. Move GimpLayerModeEffects to
libgimpbase, deprecate it, and set it as compat enum for GimpLayerMode.
Add the GimpLayerModeEffects values as compat constants to script-fu
and pygimp.
2017-01-08 23:00:19 +01:00
Hartmut Kuhse 66bc98d299 Revert "New GimpMetadata as subclass of GExiv2Metadata"
This reverts commit 3ab08c8bfd.
2017-01-03 19:36:22 +01:00
Hartmut Kuhse 3ab08c8bfd New GimpMetadata as subclass of GExiv2Metadata 2017-01-03 19:26:35 +01:00
Jehan 3fa016fb4b app: clean out tab indentations. 2016-12-21 04:05:32 +01:00
Michael Natterer 4f9095798d Bug 769738 - Add color tags/labels for layers/channels/paths
Forgot to add XCF saving and loading of color tags.
2016-11-14 23:02:43 +01:00
Michael Natterer 63bcc69827 app: factor out xcf_load_stream() and xcf_save_stream()
which can be used to load/save XCF from/to arbitrars streams. Use the
new functions from the load/save procedure invokers.

This commit also fixes a leaked open file ans input stream for each
loaded XCF.
2016-09-18 20:19:42 +02:00
Shmuel H 6d804bf9ae Bug 767873 - (CVE-2016-4994) Multiple Use-After-Free when parsing...
...XCF channel and layer properties

The properties PROP_ACTIVE_LAYER, PROP_FLOATING_SELECTION,
PROP_ACTIVE_CHANNEL saves the current object pointer the @info
structure. Others like PROP_SELECTION (for channel) and
PROP_GROUP_ITEM (for layer) will delete the current object and create
a new object, leaving the pointers in @info invalid (dangling).

Therefore, if a property from the first type will come before the
second, the result will be an UaF in the last lines of xcf_load_image
(when it actually using the pointers from @info).

I wasn't able to exploit this bug because that
g_object_instance->c_class gets cleared by the last g_object_unref and
GIMP_IS_{LAYER,CHANNEL} detects that and return FALSE.
2016-06-22 12:47:13 +02:00
Michael Natterer 2ef8719cbe app: rename more stuff from "floating sel" to "floating selection" 2016-05-20 16:46:26 +02:00
Michael Natterer e5a669bdfc libgimpbase: fix gimp_metadata_set_from_xmp() to really expect XMP
Don't skip the first 10 bytes. That code was there to skip the magic
"GIMP_XMP_1" of the old "gimp-metadata" parasite. Instead, properly
check for that magic in xcf_load_image() and pass only the actual XMP
to gimp_metadata_set_from_xmp(). Also remove the +10 hack in file-exr.
2016-04-22 22:49:06 +02:00
Michael Natterer 47ef3be145 Initialize GValues with G_VALUE_INIT instead of { 0, } 2016-03-26 15:59:26 +01:00
Michael Natterer a2ad257711 Bug 756678 - Layer opacities change upon saving and reopening an xcf file
Add new XCF property FLOAT_OPACITY and always save both the old 8-bit
and the new float opacity of layers and channels. Float opacity is
saved after the 8-bit one so when loading, it overwrites the limited
8-bit value with the proper precision. Do not increase the XCF version
number because old GIMP versions will simply skip the unknown
FLOAT_OPACITY and keep using the 8-bit value.
2015-10-16 21:59:11 +02:00
Michael Natterer 5d7710a8a5 app: fix comment in xcf_load_image() 2015-09-15 23:02:54 +02:00
Jehan c7a2574136 app: parasite renamed to gimp-xcf-compatibility-mode.
Commit 0ea7d85 was misunderstanding due to foo-lang (language spoken by
Mitch and others, but not me, it would seem!). :-P
2015-09-02 11:47:51 +02:00
Jehan 0ea7d85570 app: rename compat parasite s/gimp-compatibility-mode/gimp-xcf-foo/
Not sure why, ask Mitch! :-)
2015-09-01 19:47:48 +02:00
Jehan cb84d4bd7e app: save compatibility mode data in a parasite.
If one explicitely enabled the compat mode on an image, we should assume
this mode should be reused upon following saves, even after shutdown.
2015-09-01 19:27:56 +02:00
Michael Natterer 597a438f07 app: remove gimp_image_set_filename()
- gimp-image-set-filename PDB wrapper: implement the same there in
  a few lines
- xcf-load.c: use gimp_image_set_file() instead, and get rid of the
  last use of filename in xcf/ in favor of GFile
2015-07-13 22:43:22 +02:00
Michael Natterer db09d0f3d3 app: move functions to create layers to new files gimplayer-new.[ch] 2015-06-17 13:21:01 +02:00
Michael Natterer bc4cf9918f Bug 673501 - Issue with Overlay
GIMP's OVERLAY mode was identical to SOFTLIGHT. This commit fixes the
issue and introduces a NEW_OVERLAY mode and enum value.

- change gimp:overlay-mode to be a real (svg-ish) overlay mode
- when compositing, map OVERLAY to gimp:softlight-mode
- when compisiting, map NEW_OVERLAY to gimp:overlay-mode
- bump the XCF version when NEW_OVERLAY is used
- map OVERLAY to SOFTLIGHT when loading and saving XCF
- map OVERLAY to softlight in all PDB setters
- map OVERLAY to softlight when deserializing a GimpContext
- change all paint mode menus to show an entry for NEW_OVERLAY
  instead of OVERLAY
- change PSP, PSD and OpenRaster to use NEW_OVERLAY

These changes should (redundantly) make sure that no OVERLAY enum
value is used in the core any longer because it gets mapped to
SOFTLIGHT at all entry points, with the downside of introducing a
setter/getter asymmetry when OVERLAY was set in a PDB api.
2015-04-29 13:32:58 -04:00
Michael Natterer dd169a6a36 app: extend array in xcf_load_vector() for the new members of GimpCoords 2014-11-18 23:05:47 +01:00