Skip to content

Commit

Permalink
Merge pull request #4059 from CGDogan/patch-3
Browse files Browse the repository at this point in the history
TiffSaver: produce valid 4-channel RGBA images
  • Loading branch information
dgault authored Nov 28, 2023
2 parents ec22ea2 + 1ad16dd commit e265284
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 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,14 +1021,19 @@ 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, EXTRA_SAMPLES must not be present
if (ifd.getIFDValue(IFD.COMPRESSION).equals(TiffCompression.JPEG.getCode())) {
// see https://github.com/ome/bioformats/issues/3856
pi = PhotoInterp.Y_CB_CR;
}
else {
pi = PhotoInterp.RGB;
}
if (nChannels == 4) {
int[] extraSamplesArray = {0};
ifd.putIFDValue(IFD.EXTRA_SAMPLES, extraSamplesArray);
}
}
ifd.putIFDValue(IFD.PHOTOMETRIC_INTERPRETATION, pi.getCode());

Expand Down

0 comments on commit e265284

Please sign in to comment.