1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 00:05:07 +00:00
Commit graph

161 commits

Author SHA1 Message Date
Nico Weber
9bd35fda56 ICC: Implement TRC inversion in from_pcs for parametric curves 2023-05-02 17:15:48 +01:00
Nico Weber
4169c94ebe ICC: Implement some of Profile::from_pcs()
This implements conversion from profile connection space to the
device-dependent color for matrix-based profiles.

It only does the inverse color transform but does not yet do the
inverse tone reproduction curve transform -- i.e. it doesn't
implement many cases (LUT transforms), and it does the one thing
it does implement incorrectly. But to vindicate the commit a bit,
it also does the incorrect thing very inefficiently.
2023-05-02 17:15:48 +01:00
Nico Weber
2319b2ffb5 ICC: Use snake_case instead of matching spec's camelCase in to_pcs() 2023-05-02 17:15:48 +01:00
Nico Weber
82bd7c33d1 ICC: Make a "not yet implemented" string more precise 2023-05-02 17:15:48 +01:00
Nico Weber
103f818afc ICC: Rename tag_for_rendering_intent()
To make clear it's for forward transforms, it's now called
forward_transform_tag_for_rendering_intent().

No behavior change.
2023-05-02 17:15:48 +01:00
Nico Weber
8ab6e0d3a5 ICC: Mark Profile::to_pcs() and to_lab() const 2023-04-30 05:57:20 +02:00
Nico Weber
adec1abf81 LibGfx: Move CIELAB to its own file 2023-04-30 05:57:20 +02:00
Nico Weber
f3dbfb85d9 ICC: Add Profile::to_lab()
This can be used to convert a profile-dependent color to the L*a*b*
color space.

(I'd like to use this to implement the DeltaE (CIE 2000) algorithm,
which is a metric for how similar two colors are perceived.
(And I'd like to use that to evaluate color conversion roundtrip
quality, once I've implemented full conversions.)
2023-04-30 00:46:11 +02:00
Nico Weber
ab98ad4e70 ICC: Add a missing " at the end of a comment 2023-04-29 06:49:36 +02:00
Nico Weber
227072a5af ICC: Rename XYZ and XYZNumber fields to uppercase
Given that XYZ and xyz are distinct things, let's use the correct
case for these member variables.

No behavior change.
2023-04-29 06:49:36 +02:00
Nico Weber
1e5ececf75 ICC: Add comment with a link to WellKnownProfiles.cpp 2023-04-29 06:49:36 +02:00
Nico Weber
af453b246a ICC: Add method to convert a color to the profile connection space
Only implemented for matrix profiles so far.

This API won't be fast enough to color manage images, but let's
get something working before getting something fast.
2023-04-29 06:49:36 +02:00
Nico Weber
e76d2238bb ICC: Make number_of_components_in_color_space() external
...and make its return type unsigned.
2023-04-29 06:49:36 +02:00
Nico Weber
037d213fdf ICC: Make struct XYZ store float instead of double
Should be good enough.
2023-04-29 06:49:36 +02:00
Nico Weber
93f5a6f217 LibGfx/ICC: Use mix() in CurveTagData::evaluate()
No behavior change.

(Well, technically mix() uses the other simple implementation of lerp
and the two have slightly different behavior if the arguments are of
very different magnitude and in various corner cases. But in practice,
for ICC profiles, it shouldn't matter. For a few profiles I tested, it
didn't have a measurable effect.)
2023-04-12 15:23:51 +02:00
Nico Weber
df6b47609a LibGfx/ICC: Add evaluate() member functions to both curve types 2023-04-11 18:23:07 +02:00
Nico Weber
5df35d030f LibGfx/ICC: Extract sRGB_curve() function
This returns just the tone reproduction curve of the sRGB profile.
2023-04-11 18:23:07 +02:00
Ben Wiederhake
560133a0c6 Everywhere: Remove unused DeprecatedString includes 2023-04-09 22:00:54 +02:00
Nico Weber
1f0b54c857 LibGfx: Limit ICC-size-is-multiple-of-4 check to v4 files
The v2 spec doesn't require it, and it's not true in practice
(e.g. Compact-ICC-Profiles/profiles/sRGB-v2-nano.icc has size 410).
2023-04-09 16:49:49 +02:00
Nico Weber
14581e98ad LibGfx: Remove stray space character in a comment 2023-03-16 09:20:48 -04:00
Nico Weber
efabfd4c66 LibGfx: Fill in remaining values in built-in sRGB profile
The values aren't 100% self-consistent, but it probably doesn't make
a difference for u8 color data. Good enough for now. See all the links
on #17714 for some more background.
2023-03-05 18:21:43 +00:00
Nico Weber
0ba532e14e LibGfx: Add a function to create an in-memory sRGB profile
This might be useful for converting data from arbitrary profiles to
sRGB.

For now, this only encodes the transfer function and puts in zero values
for chromaticities, whitepoint, and chromatic adaptation matrix.
This makes the profile unusable for now. But I've spent a very long time
reading things and need to check in some code, and it's some progress.

The encoded transfer function exactly matches the one in GIMP's built-in
sRGB ICC profile (but not the Compact-ICC-Profiles v4 one or the
RawTherapee v4 one -- I'll add a comment about why later.)
2023-03-04 21:38:47 +00:00
Nico Weber
8f415e7b21 LibGfx: Introduce ICC::Profile::create
This can be used to programmatically create ICC::Profile objects.
2023-03-04 21:38:47 +00:00
Nico Weber
4bf639b635 LibGfx: Drop tags of unknown type instead of writing invalid icc files
We could make UnknownTagData hold on to undecoded, raw input data and
write that back out when serializing. But for now, we don't.

On the flipside, this _does_ write unknown tags that have known types.
We could have a mode where we drop unknown tags with known types.
But for now, we don't have that either.

With this, we can for example reencode
/Library/ColorSync/Profiles/WebSafeColors.icc and icc (and other
tools) can dump the output icc file. The 'ncpi' tag with type 'ncpi'
is dropped while writing it, while the unknown tag 'dscm' with
known type 'mluc' is written to the output. (That file is a v2 file,
so 'desc' has to have type 'desc' instead of type 'mluc' which
it would have in v4 files -- 'dscm' emulates an 'mluc' description
in v2 files.)
2023-02-24 19:42:00 +01:00
Nico Weber
b161f5ea05 LibGfx: Make ICC reader check that profile size is a multiple of 4
With this, I would've found e8bd067ce5 earlier.

(If this turns out to be too strict in practice, we can always relax
it again.)
2023-02-24 19:17:20 +01:00
Nico Weber
e8bd067ce5 LibGfx: Pad last element in ICC files to 4-byte boundary too
The spec wants that to happen.
2023-02-23 16:39:17 +01:00
Nico Weber
7853be7869 LibGfx: Implement serialization of LutAToBTagData and LutBToATagData
With this, we can write all tag types we can currently read :^)
2023-02-23 15:35:02 +01:00
Nico Weber
1d124af66f LibGfx: Implement serialization of Lut16TagData and Lut8TagData 2023-02-19 23:46:36 +01:00
Nico Weber
4bafdaba3f LibGfx: Make Lut16TagData and Lut8TagData ctors verify table sizes
The from_bytes() methods error out on invalid table sizes,
but let's make sure other potential future callers get it right too.
2023-02-19 23:46:36 +01:00
Nico Weber
51be964884 LibGfx: Fix 7-bit ASCII checks in textDescriptionType and textType
This used to check the empty, moved-from parameter instead of
the member variable (-‸ლ)
2023-02-19 23:46:36 +01:00
Nico Weber
8f181e0e94 LibGfx: Implement serialization of NamedColor2TagData 2023-02-19 23:46:36 +01:00
Nico Weber
eac9941766 LibGfx: Make NamedColor2TagData verify inputs are 32-byte 7-bit ASCII
NamedColor2TagData::from_bytes() errors out if that isn't the case,
but let's make sure other potential future callers get it right too.
2023-02-19 23:46:36 +01:00
Nico Weber
7ad11fa59a LibGfx: Mark a few ICC:NamedColor2TagData methods as const 2023-02-19 23:46:36 +01:00
Nico Weber
47cfcf5dca LibGfx: Move NamedColorHeader to BinaryFormat.h 2023-02-19 23:46:36 +01:00
Nico Weber
937d018fc6 LibGfx: Use ICC::Profile::try_for_each_tag in encode_tag_datas() 2023-02-19 23:46:36 +01:00
Nico Weber
8179327068 LibGfx: Add fallible ICC::Profile::try_for_each_tag
Similar to 13b18a1 or d0f3f3d.
2023-02-19 23:46:36 +01:00
Nico Weber
0f0694edb1 LibGfx: Remove an ICC writing FIXME, and a comment 2023-02-19 23:46:36 +01:00
Nico Weber
e2dde64628 LibGfx: Use static_cast in ICC writing code
It's what project leadership wants.
2023-02-19 22:31:41 +01:00
Nico Weber
0e66a5c3ed LibGfx: Write multiLocalizedUnicodeType with multiple strings correctly
Found by reencoding Tests/LibGfx/test-inputs/icc-v2.png, the 'dscm' tag.
2023-02-19 22:31:41 +01:00
Nico Weber
07bf2d944c LibGfx: Add a FIXME to ICC encode_tag_data() 2023-02-19 22:31:41 +01:00
Nico Weber
7e769c7217 LibGfx: Partially implement serialization of TextDescriptionTagData
It only implements serialization of the 7-bit ASCII string, not yet
serialization of the UCS-2 and Macintosh ScriptCode strings.

With this, matrix-based v2 profiles can be reencoded :^)
2023-02-19 22:31:41 +01:00
Nico Weber
b2cf773d85 LibGfx: Make TextDescriptionTagData verify input is 7-bit ASCII
TextDescriptionTagData::from_bytes() errors out if that isn't the case,
but let's make sure other potential future callers get it right too.
2023-02-19 22:31:41 +01:00
Nico Weber
e76f1caf79 LibGfx: Re-alphabetize TagData classes
This moves TextDescriptionTagData below SignatureTagData.
It just moves code around and doesn't change anything.
2023-02-19 22:31:41 +01:00
Nico Weber
4d972ab975 LibGfx: Add spec comment to ICC encode_tag_table() 2023-02-19 22:31:41 +01:00
Sam Atkins
2db168acc1 LibTextCodec+Everywhere: Port Decoders to new Strings 2023-02-19 17:15:47 +01:00
Nico Weber
19e91e5211 LibGfx: Dedupe identical tag data objects when writing ICC data
With this, common v4 profiles, such as embedded into jpgs by iPhones
(when configured to write jpegs) or Pixel phones, are identical to
the input when reexported :^)
2023-02-19 08:12:04 +00:00
Nico Weber
2504f2035c LibGfx: Implement serialization of ViewingConditionsTagData 2023-02-19 08:12:04 +00:00
Nico Weber
933002ae5a LibGfx: Move ICC ViewingConditionsHeader to BinaryFormat.h 2023-02-19 08:12:04 +00:00
Nico Weber
22c0e6b60e LibGfx: Implement serialization of MeasurementTagData 2023-02-19 00:01:44 +01:00
Nico Weber
8e5392f9c0 LibGfx: Move ICC MeasurementHeader to BinaryFormat.h 2023-02-19 00:01:44 +01:00