Øyvind Kolås [Tue, 19 Jun 2018 17:29:48 +0000 (19:29 +0200)]
babl: rename functions that used to refer to specific gamma
The definitions of components and formats for linear and nonlinear formats in
model-rgb and model-gray are now using the TRC of a BablSpace, thus in the
format syntax ' now means nonlinear, not sRGB / 2.2 gamma - even though it ends
up meaning that for formats create without specifying the space.
Ell [Thu, 14 Jun 2018 05:54:52 +0000 (01:54 -0400)]
babl-fish: fix concurrent babl_fish()/process() calls with palette formats
In babl_fish(), don't call _babl_fish_rig_dispatch() on existing
path fishes during each lookup. We already call this function on
all path fishes upon creation (in particular, after commit b34a9672c8c9a42923a8f0b2650af30b1efe635c), so this isn't necessary.
This fixes an issue where the _babl_fish_rig_dispatch() call in
babl_fish() would temporarily modify the value of babl->fish.data,
causing a concurrent babl_process[_rows]() call in another thread
to pass the wrong 'data' value down to the conversion function. In
particular, this could cause palette conversions to segfault.
This API is internal only for now so we can change it, changing to use a
hard-coded pre-quantized chromaticities set for the internal sRGB space.
This preserve the gray axis matrix equalization performed for other spaces used
with babl, ideally we can improve the gray-axis equalization to match and
return to using it also for sRGB.
Ell [Wed, 30 May 2018 09:45:17 +0000 (05:45 -0400)]
babl-memory: allow babl_malloc(0) to succeed
Allow a babl_malloc() call with size == 0 to succeed, returning a
dummy allocation, instead of asserting on this condition. The new
babl-palette code tries to allocate an empty buffer for the radii
array when creating a single-color palette, which would previously
lead to a crash.
Ell [Fri, 18 May 2018 12:04:52 +0000 (08:04 -0400)]
babl-palette: speed up closest-color search
When constructing a palette format, calculate the distance between
each pair of colors in the palette, and for each color, construct a
list of all other colors and their distances from it, sorted by
distance. When searching for the closest palette color to a given
input pixel, based on the assumption that nearby pixels have
similar color, use the color list of the previous pixel's best
match, and use the triangle inequality to stop the search early.
Øyvind Kolås [Fri, 18 May 2018 09:02:04 +0000 (11:02 +0200)]
babl: use hashtable approach in double reference
Strictly speaking we should be doing the reference using
conversions to R'G'B'A double and using the distance metric
there; possibly getting a slight difference in result at
comparison ties.
In use GEGL ends up using both the really fast 8bit code paths
and the quite fast floating point code paths that use 8bit
hashtables for the lookup of conversion.
For working at acceptable performance with large indexed images, it is
recommended to run with BABL_TOLERANCE=0.0385 or highger set in the environment
when launching GIMP, this permits using a hashtable based optimization that
still isn't accurate enough according to babl-expectations.
Øyvind Kolås [Thu, 17 May 2018 10:53:42 +0000 (12:53 +0200)]
meson.build: synchronise with autotools version
WARNING: distributions should still not use meson to build packages - since
the meson build end up containing all instructions available on build host.
Debarshi Ray [Sat, 28 Apr 2018 23:15:46 +0000 (01:15 +0200)]
CIE: Add an SSE2 version of "RGBA float" to "CIE Lab alpha float"
On an Intel i7 Haswell, it now takes 0.13s to convert a 15 megapixel
buffer from "RGBA float" to "CIE Lab alpha float" instead of the
earlier 0.27s.
SSEx doesn't have integer multiplication or division operations, and
using bit shifts to implement integer divisions by powers of 2 seems to
introduce errors. Therefore, it was problematic to use the cube root
approximation from Hacker's Delight, which uses quite a few integer
divisions to make the initial guess. Instead, Halley's method of
approximating the cube root seems more SSEx friendly because the
initial guess requires only one integer division, which we can manage
by jumping through a relatively small number of hoops.
The scalar version of Halley's method seems to have originated from
http://metamerist.com/cbrt/cbrt.htm but that's not accessible anymore.
At present there's a copy in CubeRoot.cpp in the Skia sources that's
licensed under a BSD-style license. There's some discussion on the
implementation at http://www.voidcn.com/article/p-gpwztojr-wt.html.
Note that Darktable also has an SSE2 version of the same algorithm,
but uses only a single iteration of Halley's method, which is too
coarse.
Here's some more discussion on the cube root approximation algorithms:
https://bugzilla.gnome.org/show_bug.cgi?id=791837
This will permit slightly faster than the generic fast paths for some possibly
desired intermediate conversions. This also adds alpha stripping - which fills
in the last babl fast path currently reported missing on every launch of GIMP.
GIMP makes use of "Y' u8" to "R'G'B' u8" and we had no paths covering it,
making it go through floating point. This commit adds code paths for expanding
single grayscale u8 to R'G'B and R'G'B'A as well as R'aG'aB'aA u8.
extensions: add rgba8_rgb8 conversion that copies 24/32bit chunks
Slightly speeding up RGB u8 (without alpha) painting in GIMP, the rgba to rgb
and reverse conversions are used together with the very fast SIMD conversions
that operate on chunks of 4 components.
Øyvind Kolås [Tue, 30 Jan 2018 15:35:28 +0000 (16:35 +0100)]
babl: fix icc matrix profile fast paths
For core members, babl relies on shared data layout between fish and
conversion to be able to do dispatch, and have source/target match -
though only for simple fishes.
The ICC fast path conversions also used the user data - but directly
instead of throug the argument, changing this makes the matrix and
luts work again - and let the conversions be used.
Øyvind Kolås [Sat, 20 Jan 2018 17:41:12 +0000 (18:41 +0100)]
babl: initialize the bpp of fishes loaded from cache
The cache loading code manually constructs path fishes, which did not
get their bpp initialized, this resulted in conversions of long runs to
fail, not crash - but stop processing after MAX_BUFFER_SIZE pixels.
Øyvind Kolås [Wed, 17 Jan 2018 02:57:23 +0000 (03:57 +0100)]
babl: add a test iteration multiplier
On my system many of the conversions got measured to costs of 3 4 and 5, these
makes a big room for measurement errors, to increase reliability the tests are
now run 4 times - making it a ranking of contenders with fewer collisions.
This will slightly increase incurred delayed on search for conversions.
Øyvind Kolås [Wed, 17 Jan 2018 02:46:59 +0000 (03:46 +0100)]
babl: make pixel-count instrumentation opt-in
Checking if an integer is 0/1 is lower overhead than incrementing a long stored
kt a memory location. As a side effect, the entries in
~/.cache/babl/babl-fishes will not be sorted by most used to least used unless
the BABL_INSTRUMENT environment variable is set to a value.
Øyvind Kolås [Sun, 14 Jan 2018 21:49:40 +0000 (22:49 +0100)]
babl: refactor code to get rid of more branches in babl_process
In the best case scenario now, babl_process increments instrumentation
counters and directly calls the relevant registered fast path function,
with no additional call stack frames in-between.
Ell [Sat, 13 Jan 2018 09:02:24 +0000 (04:02 -0500)]
sse2-float: use same TRC for "leftover" samples
The SSE2 versions of the gamma <-> linear TRC functions can produce
slightly different results than the scalar ones. Consequently,
last commit didn't resolve all discrepancies between the main and
leftover samples (and didn't address the gamma -> linear
direction).
Use the same SSE2 TRC functions for converting the leftover
samples, rather than the scalar functions, to fix that.
Ell [Thu, 11 Jan 2018 14:22:46 +0000 (09:22 -0500)]
sse2-float: use babl_linear_to_gamma_2_2f() (instead of double)
Use the single-precision babl_linear_to_gamma_2_2f() function,
instead of the double-precision version, when converting "leftover"
samples, so that the result is consistent with the vectorized
samples.
Øyvind Kolås [Wed, 3 Jan 2018 16:12:41 +0000 (17:12 +0100)]
palette: expect palettes/formats to be gamma corrected in 8bit
A correctness correction related to bug #763581 the formats wanted
by GIMP and expected are gamma corrected not linear, I expect this
fix either does not much for GIMP or fixes an unknown 8bit linear
vs gamma quantization problem that has been lurking in INDEXED mode.