Commit Graph

429 Commits

Author SHA1 Message Date
Jehan 46121685b8 app: get rid of rgb_to_pixel() GimpPickable method and related functions.
We don't try anymore to convert early from a pickable color to another
format/space. Now we are able to get a GeglColor and move it around,
doing only last-second (when needed) conversions.
2024-02-11 23:28:03 +01:00
Jehan 319150a3b1 app: get rid of gimp_pickable_pixel_to_rgb() and gimp_image_color_profile_pixel_to_rgb().
These are not used anywhere anymore.
2024-02-11 23:28:02 +01:00
Alx Sa 769e36d7cf core: color pick in image's RGB space
Replaces GimpPickableInterface's pixel_to_srgb () functions with
pixel_to_rgb(). Now GimpRGB's values should be in the correct
image color space from the beginning of the process.
2023-04-23 22:03:29 +00:00
Ell faf6acfb67 app: add "chunked" parameter to gimp_tile_handler_validate_validate()
... which allows validating the area in chunks, instead of in a
single step.
2020-03-14 13:54:57 +02:00
Ell 02943e22f6 app: fix gimp_projection_get_pixel_at() for general bounding boxes 2019-09-04 20:51:43 +03:00
Ell bcf2b937d9 app: notify GimpProjection::buffer when freeing the projection's buffer
... instead of only when subsequently reallocating it, so that
listeners can respond to the buffer being freed.
2019-09-04 19:16:41 +03:00
Ell 49bbf13911 app: in GimpProjection, avoid invalidating preview on flush while rendering
In GimpProjection, avoid erroneously invalidating the projectable's
preview when flushing the projection and there's nothing to be
flushed, if the chunk renderer is still running, and hence the
projection is not fully rendered yet.
2019-09-04 19:16:40 +03:00
Ell 1577174739 app: update projection-buffer extent when projectable size changes
In GimpProjection, when the projectable's size changes, while its
offset remains the same, simply update the projection buffer's
extent, instead of allocating a new buffer and copying the contents
over.
2019-08-13 17:44:11 +03:00
Niels De Graef 1dda60154c Use "Returns:" to annotate return values
To be able to annotate return values through GObject-introspection, you
need to make sure it is tagged with `Returns:` and not something else.
2019-08-03 07:53:47 +00:00
Ell 8ff43942d6 app: add support for projectables with an arbitrary bounding box
In GimpProjectable, replace gimp_projectable_get_size(), which only
returned a width and a height, with
gimp_projectable_get_bounding_box(), which returns a full
rectangle.  This allows projectables to have an arbitrary bounding
box, not limited to a (0, 0) top-left corner.

Adapt GimpProjection, creating a buffer with corresponding extent
to the projectable's bounding box.

Adapt GimpImage and GimpGroupLayer.
2019-08-02 00:40:01 +03:00
Ell 9d80ccc3e6 app: preserve projection priority rect across structure/bounds changes
In GimpProjection, store the priority rect in image coordinates,
and only convert it to projectable coordinates when initializing
the chunk-iterator's priority rect.  This allows us to preserve the
priority rect across projectable structure/bounds changes.
2019-03-26 04:58:51 -04:00
Ell 106df3b794 Issue #3142 - Filters on-canvas preview doesn't work ...
... immediately after an image precision change

When flushing a projection, make sure it has a buffer, instead of
bailing if it doesn't.  We rely on the image projection's "update"
signal to update the display after certain operations that free the
buffer, which would previously fail to happen, and cause subsequent
flushes to be ignored until the buffer is explicitly accessed.

This fixes commit b07f810273.
2019-03-24 03:20:39 -04:00
Ell 9833da3431 app: clear priority rect when finishing projection rendering
In gimp_projection_finish_draw(), clear the chunk iterator's
priority rect before finishing rendering, since it's not needed at
this point, and this is slightly more efficient.
2019-01-13 08:23:01 -05:00
Ell 42845c9462 app: in gimp_projection_chunk_render_start(), properly invalidate preview
In gimp_projection_chunk_render_start(), when the current
projection rendering is complete, but not finalized yet, and no new
rendering is started (since the current update region is empty),
make sure to invalidate the projectable's preview, since it
normally happens when rendering is finalized, which doesn't happen
in this case.
2019-01-12 08:33:16 -05:00
Ell 0e5de95760 app: in gimp_projection_chunk_render_start(), don't leak empty region
In gimp_projection_chunk_render_start(), don't leak the current
update region when it's empty, but not NULL, and properly shut down
the idle source.
2019-01-12 08:20:10 -05:00
Ell 246e782858 app: use GimpChunkIterator in GimpProjection
Replace the custom chunking logic of GimpProjection with
GimpChunkIterator, added in the previous commit.
2019-01-12 04:50:57 -05:00
Ell ef9b1f6694 app: in GimpLineArt, use "invalidate-preview" signal of input viewable
In GimpLineArt, use the "invalidate-preview" signal of the input
viewable, instead of its "painted" or "rendered" signals, for
asynchronously computing the line art.  Subsequently, remove the
aforementioned signals from GimpDrawable and GimpProjection,
respectively.  This simplifies the code, and reduces the number of
signals.
2018-12-27 17:14:28 -05:00
Ell c9c2397b0d app: in GimpProjection, fix reinit. of current row when chunk height changes
In GimpProjection's chunk renderer, when the chunk height changes
in the middle of a row, we need to merge the remainder of the
current render area back into the renderer's update region, and
refetch the remainder of the row as the new render area, so that we
don't miss any unrendered area, or re-render already-rendered area,
due to the change in chunk height.  However, we should previously
fail to verify that the fetched area is, in fact, the remainder of
the current row, which could cause us to render the wrong area,
missing parts of the update region.

Fix this, by breaking up some of the chunk-renderer fucntions into
smaller sub-functions, and using those in order to explicitly set
the new render area to the remainder of the current row when the
chunk height changes.  This also avoids erroneously merging the
unflushed update region of the projection into the renderer's
update region.
2018-12-06 08:50:59 -05:00
Ell dac9bfe334 app: add "direct" parameter to gimp_projection_flush_now()
Add a boolean "direct" parameter to gimp_projection_flush_now(),
which specifies if the projection buffer should only be invalidated
(FALSE), or rendered directly (TRUE).

Pass TRUE when flushing the projection during painting, so that the
affected regions are rendered in a single step, instead of tile-by-
tile.  We previously only invalidated the projection buffer, but
since we synchronously flush the display right after that, the
invalidated regions would still get rendered, albeit less
efficiently.

Likewise, pass TRUE when benchmarking the projection through the
debug action, and avoid flushing the display, to more accurately
measure the render time.
2018-12-02 10:14:58 -05:00
Ell d6f0ca5531 app: use gimp_tile_handler_validate_validate() in GimpProjection
Use gimp_tile_handler_validate_validate(), added in the last
commit, in GimpProjection, in order to render the projection,
instead of separately invalidating the buffer, undoing the
invalidation, and then rendering the graph.  This is more
efficient, and more idiomatic.
2018-11-28 13:26:38 -05:00
Ell 5a623fc54b app: add GimpTileHandlerValidate::{begin,end}_validate() vfuncs
Add begin_validate() and end_validate() virtual functions, and
corresponding free functions, to GimpTileHandlerValidate.  These
functions are called before/after validation happens, and should
perform any necessary steps to prepare for validation.  The default
implementation suspends validation on tile access, so that the
assigned buffer may be accessed without causing validation.

Implement the new functions in GimpTileHandlerProjectable, by
calling gimp_projectable_begin_render() and
gimp_projectable_end_render(), respectively, instead of calling
these functions in the ::validate() implementation (which, in turn,
allows us to use the default ::validate() implementation.)

In GimpProjection, use the new functions in place of
gimp_projectable_{begin,end}_render().
2018-11-28 13:25:33 -05:00
Ell 8a47b68194 app: avoid starting the chunk renderer while finishing drawing a projection
In gimp_projection_finish_draw(), make sure we don't accidentally
re-start the chunk renderer idle source while running the remaining
iterations, in case the chunk height changes, and we need to reinit
the renderer state.
2018-11-28 13:25:32 -05:00
Ell b07f810273 app: avoid flushing bufferless projections
Don't needlessly flush projections whose buffer hasn't been
allocated yet.  This can happen when opening an image, in which
case the image is flushed before its projection has a buffer.
2018-11-28 13:25:32 -05:00
Jehan 047265333c app: better handle drawable and image update for line art computation.
The "update" signal on drawable or projection can actually be emitted
many times for a single painting event. Just add new signals ("painted"
on GimpDrawable and "rendered" on GimpProjection) which are emitted once
for a single update (from user point of view), at the end, after actual
rendering is done (i.e. after the various "update" signals).

Also better support the sample merge vs current drawable paths for
bucket fill.
2018-11-19 14:18:18 +01:00
Ell 3b0040c043 app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()

g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58.  Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.

This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.

Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-18 14:39:56 -04:00
Ell a1706bbd29 app: use adaptive chunk size when rendering projections
In GimpProjection, use an adaptive chunk size when rendering the
projection asynchronously, rather than using a fixed chunk size.
The chunk size is determined according to the number of pixels
processed during the last frame, and the time it took to process
them, aiming for some target frame-rate (currently, 15 FPS).  In
other words, the chunks become bigger when processing is fast, and
smaller when processing is slow.  We're currently aiming for
generally-square chunks, whose sides are powers of 2, within a
predefined range.

Note that the chunk size represents a trade off between throughput
and responsiveness: bigger chunks result in better throughput,
since each individual chunk incurs an overhead, in particular when
rendering area filters or multithreaded ops, while smaller chunks
result in better responsiveness, since the time each chunk
individual takes to render is smaller, allowing us to more
accurately meet the target frame rate.  With this commit, we aim to
find a good compromise dynamically, rather than statically.

The use of adaptive chunk sizes can be disabled by defining the
environment variable GIMP_NO_ADAPTIVE_CHUNK_SIZE, in which case we
use a fixed chunk size, as before.
2018-08-20 11:13:53 -04:00
Ell 105ffc787d app: don't chunk update area when rendering projection synchronously
Add a boolean "chunk" parameter to
gimp_projection_chunk_render_iteration(), which determines whether
the work area should be sub-divided into chunks prior to rendering
(previously, the work area would always be sub-divided.)  Only
pass TRUE when rendering the projection asynchronously, in the
render callback, and pass FALSE when rendering the projection
synchronously, in gimp_projection_finish_draw(), which is called
when flushing the projection through the GimpPickable interface.

Rendering the projection using as big chunks as possible improves
performance, while worsening responsiveness.  Since responsiveness
doesn't matter when rendering synchronously, there's no reason to
render in chunks.
2018-08-20 11:13:05 -04:00
Ell 2d63bc6e0a app: fix projection update-area offset upon buffer allocation/reisizing
In GimpProjection, change gimp_projection_add_update_area() to take
coordinates in the projection's coordinate system, rather than the
image coordinate system, and move the offset adjustment to the
projectable invalidation handler.

Modify gimp_projection_projectable_structure_changed() to pass
projection-space coordinates to gimp_projection_add_update_area().

gimp_projection_get_buffer() and
gimp_projection_projectable_bounds_changed() already pass
projection-space coordinates to gimp_projection_add_update_area(),
which was wrong before, when the projection had a nontrivial
offset, but is correct now.
2018-08-10 03:21:08 -04:00
Ell c6b8a4213c app: short-circuit GimpProjection bounds-changed handler if disjoint
In gimp_projection_projectable_bounds_changed(), bail early by
calling gimp_projection_projectable_structure_changed() instead, if
the new bounds don't intersect the old bounds.
2018-08-03 22:04:10 -04:00
Ell bb5e3fd926 app: fix gimp_projection_projectable_bounds_changed()
In gimp_projection_projectable_bounds_changed(), which is called by
GimpProjection in response to a GimpProjectable::bounds-changed
signal, invalidate all regions of the new projection that weren't
copied from the old projection, so that they get rendered upon
flushing, instead of remaining empty.

Additionally, fix preview invalidation -- in particular, don't
directly invalidate the projectable's preview, even if preview
invalidation is already queued and chunk rendering was finished by
the boundary change, and instead always queue a preview
invalidation.
2018-08-03 22:04:10 -04:00
Ell fbeae36118 app: respond to GimpProjectable::bounds-changed in GimpProjection
In GimpProjection, respond to the projectable's "bounds-changed"
signal, by reallocating the buffer, and copying the corresponding
region of the old buffer (using
gimp_tile_handler_validate_buffer_copy(), added a few commits back,
so that the relevant portion of the validate handler's dirty region
is also copied).  Additionally, shift and clip all outstanding
update regions as necessary (actually, we avoid copying the buffer
when a shift is necessary, and simply reconstruct the projection;
see FIXME comment in the code.)
2018-08-03 13:50:13 -04:00
Ell 12530e21b2 app: add gimp_tile_handler_validate_unassign()
... which should be used to properly remove a
GimpTileHandlerValidate from a buffer, instead of using
gegl_buffer_remove_handler() directly.

Use gimp_tile_handler_validate_unassign(), instead of
gegl_buffer_remove_handler(), in gimp_projection_free_buffer().
2018-08-03 13:50:13 -04: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 5f700549e7 Change the license URL from http://www.gnu.org/licenses/ to https:// 2018-07-11 23:29:46 +02:00
Ell 25490b0251 app: implement GimpPickable::get_pixel_average() in various classes
Implement GimpPickable::get_pixel_average(), added in the previous
commit, in GimpDrawable, GimpImage, and GimpProjection, using
gimp_gegl_average_color(), added in the commit before last.  This
is significantly faster than the default implementation.
2018-05-18 15:07:32 -04:00
Ell 49285463e6 app: align projection update area to coarse grid
When adding a rectangle to a projection's update area, align the
rectangle to a coarse grid, to reduce the complexity of the overall
area.  We currently align the rectangle to a 32x32 grid, which
seems to be a good tradeoff between the overhead of processing a
complex area, and the overhead of processing a large area.
2018-03-31 08:19:18 -04:00
Ell 61ae3089ad app: avoid begin_render()/end_render() when flushing projections
... since we don't actually render anything, only invalidate.
2017-12-02 10:38:34 -05:00
Ell 1a2c0e8198 app: add gimp_projection_{get,set}_priority()
... which control the priority of the projection's idle source.

The projection's priority is specified relatively to
GIMP_PRIORITY_PROJECTION_IDLE (i.e., a priority of 1 results in an
idle source with priority GIMP_PRIORITY_PROJECTION_IDLE + 1, etc.)
2017-12-02 10:38:34 -05:00
Ell 1c68617302 app: use {begin,end}_render() and GimpTileHandlerProjectable ...
... in GimpProjection and gimp_display_shell_render() (the latter
is not really necessary, but whatever.)
2017-08-08 15:39:27 -04:00
Michael Natterer 12f920d8bf app: change GimpTileHandlerValidate's API to use GeglRectangle
instead of x, y, width, height.
2017-08-05 15:43:41 +02:00
Michael Natterer 0cb3e75f79 app: use a lot of g_clear_object() and g_clear_pointer()
More than 2000 lines of code less in app/, instead of

if (instance->member)
  {
    g_object_unref/g_free/g_whatever (instance->member);
    instance->member = NULL;
  }

we now simply use

g_clear_object/pointer (&instance->member);
2017-07-15 18:42:44 +02:00
Michael Natterer 5b4d0219d8 app: add GimpPickable::srgb_to_pixel()
which isn't really for "picking", but it just fits too nicely into
GimpPickable to not put it there.

Also add utility function gimp_pickable_srgb_to_image_color() which
takes a "real" (sRGB) GimpRGB value, transforms it to the pickable's
colorspace and puts it into an "image color" GimpRGB.
2016-05-23 01:33:52 +02:00
Michael Natterer 26251695b0 Bug 748749 - picked colors don't match image colors...
...when a color profile is active

Add GimpPickable::pixel_to_srgb() which puts a picked raw image
pixel into a GimpRGB. Default to gimp_rgba_set_pixel() but implement
pixel_to_srgb() in GimpLayer, GimpProjection and GimpImage and
run the pixel through gimp_image_color_profile_pixel_to_srgb().
2016-05-22 23:28:31 +02:00
Øyvind Kolås 9cc634e838 app: add new required arguments to gegl_node_blit_buffers 2015-11-21 03:18:56 +01:00
Michael Natterer 76ff1c1584 Revert "app: add ::get_color_profile() to GimpPickable and GimpProjectable"
This reverts commit 5c8ffdf6c5.

It was a bad idea, we have the GimpColorManaged interface for that.
2015-09-03 00:21:09 +02:00
Michael Natterer 5c8ffdf6c5 app: add ::get_color_profile() to GimpPickable and GimpProjectable
which currently all end in a call to gimp_color_managed_get_color_profile()
except for channels and masks. This is currently unused infrastructure but
will be used for things like layer previews, and return NULL if called
on a mask or channel, or if color management is disabled, or whatever.
2015-09-01 22:27:31 +02:00
Michael Natterer 8c6e890835 app: rename GimpTileHandlerProjection to GimpTileHandlerValidate
Add virtual function validate() so subclasses can construct arbitrary
buffers on-the-fly. The default implementation blits from the
projection graph like before. Add boolean property "whole-tile" which
allows for switching between always validating entire tiles, and
validating the parts of the tile that are actually dirty.
2015-03-15 22:09:04 +01:00
Michael Natterer 980ba7f85a app: move memsize functions into their own files gimp-memsize.[ch] 2014-08-12 13:57:57 +02:00
Michael Natterer c88800e840 app: add gimp-priorities.h and keep the most important priorities there
also add comments with all predefined priorities as documentation.
2014-07-02 04:47:24 +02:00
Michael Natterer f2b265f751 app: more correct code in gimp_projection_chunk_render_iteration()
wasn't broken before, just too obscure.
2014-06-30 23:12:53 +02:00