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

TiffSaver: produce valid 4-channel RGBA images #4059

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion components/formats-bsd/src/loci/formats/tiff/TiffSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -1021,13 +1021,22 @@ private void makeValidIFD(IFD ifd, int pixelType, int nChannels) {
if (nChannels == 1 && ifd.getIFDValue(IFD.COLOR_MAP) != null) {
pi = PhotoInterp.RGB_PALETTE;
}
else if (nChannels == 3) {
else if (nChannels == 3 || nChannels == 4) {
// TODO: handle CMYK; nChannels == 4, extraSamples 0 (can be omitted)
if (ifd.getIFDValue(IFD.COMPRESSION).equals(TiffCompression.JPEG.getCode())) {
// see https://github.com/ome/bioformats/issues/3856
pi = PhotoInterp.Y_CB_CR;
if (nChannels == 4) {
int[] extraSamplesArray = {2};
CGDogan marked this conversation as resolved.
Show resolved Hide resolved
ifd.putIFDValue(IFD.EXTRA_SAMPLES, extraSamplesArray);
}
}
else {
pi = PhotoInterp.RGB;
if (nChannels == 4) {
int[] extraSamplesArray = {1};
CGDogan marked this conversation as resolved.
Show resolved Hide resolved
ifd.putIFDValue(IFD.EXTRA_SAMPLES, extraSamplesArray);
}
}
}
ifd.putIFDValue(IFD.PHOTOMETRIC_INTERPRETATION, pi.getCode());
Expand Down