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.
Debarshi Ray [Thu, 21 Dec 2017 09:14:53 +0000 (10:14 +0100)]
CIE: Use a faster cbrtf implementation
This is the approximate cube root of an IEEE float implementation from
Hacker's Delight. The elimination of all conditional branches probably
makes it a better candidate for future SIMD accelerated code paths.
On an Intel i7 Haswell, it now takes 0.27s to convert a 15 megapixel
buffer from "RGBA float" to "CIE Lab alpha float" instead of the
earlier 0.35s. A "Y float" to "CIE L float" conversion takes 0.085s
instead of 0.102s.
Original code: http://www.hackersdelight.org/hdcodetxt/acbrt.c.txt
Permissions: http://www.hackersdelight.org/permissions.htm
Øyvind Kolås [Sat, 9 Dec 2017 19:51:38 +0000 (20:51 +0100)]
CIE: add CIE XYZ and CIE XYZ alpha models
Even more useful now with custom RGB primaries - and being able to use babl for
conversions when needed is convenient. This is with reference paths - which
means fast paths for double precision float - single precision would have to be
added for it to be used and higher throughput in most common scenarios.
Jehan [Mon, 4 Dec 2017 02:33:47 +0000 (03:33 +0100)]
tests: not all UNIX-like OSes have a libpthread.
In particular Android systems don't need to link with -lpthread
(actually the link would fail with "ld: cannot find -lpthread").
Use the $(THREAD_LIB) variable which is set correctly during configure
since commit c02af82.
Debarshi Ray [Thu, 9 Nov 2017 06:48:26 +0000 (07:48 +0100)]
CIE: Add "CIE L float"
Some of these conversions will be leveraged by gegl:shadows-highlights
which needs to go from "Y float" or "YaA float" to "CIE L float".
The conversion from "RGBA float" was added to aid "YaA float" to
"CIE L float" fishes. They go via:
"YaA float" to "RaGaBaA float"
"RaGaBaA float" to "RGBA float"
"RGBA float" to "Y float"
"Y float" to "CIE L float"
A direct conversion from "YaA float" to "Y float" in simple C is
hindered by the need to check every pixel's alpha value to avoid
dividing by zero. The pipeline stalls make it lose out to the look-up
table and SIMD based RGB conversions to unassociated alpha.
However, we can trivially cut out the third step and still reduce some
memory traffic.