Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for decoding tiff images with cmyk pixel data #2268

Merged
merged 3 commits into from
Oct 14, 2022

Conversation

brianpopow
Copy link
Collaborator

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

This PR adds support for decoding tiff images with cmyk pixel data.

Related issue: #2263

@@ -31,8 +31,8 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
for (int x = 0; x < pixelRow.Length; x++)
{
float l = (data[offset] & 0xFF) * 100f * Inv255;
var lab = new CieLab(l, (sbyte)data[offset + 1], (sbyte)data[offset + 2]);
var rgb = ColorSpaceConverter.ToRgb(lab);
CieLab lab = new(l, (sbyte)data[offset + 1], (sbyte)data[offset + 2]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious to how the data is encoded here.

The CieLab A, B values usually range from −128 to 127 when working with integer values.
Casting to sbyte and using overflow is a neat trick.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To cite the spec:

Tiff is defined such that each quantity be encoded with 8 bits. This provides 256 levels of L* lightness;
256 levels (+/- 127) of a*, and 256 levels (+/- 127) of b*.  
...
Limiting the theoretically unbounded a* and b*
ranges to +/- 127 allows encoding in 8 bits without eliminating any but the most
saturated self-luminous colors. It is anticipated that the rare specialized applications
requiring support of these extreme cases would be unlikely to use CIELAB
anyway. All object colors, in fact all colors within the theoretical MacAdam limits,
fall within the +/- 127 a*/b* range.

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants