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

Generate TIFF with Metadata - TAG_STRIP_OFFSETS not working properly #32

Open
leordev opened this issue Feb 28, 2017 · 0 comments
Open

Comments

@leordev
Copy link

leordev commented Feb 28, 2017

Guys, I'm trying to generate a TIFF image and it must have compression G4 (CCITT_T_6) and also the StripOffsets must be 8.

The problem that I have is that when I don't set the TAG_STRIP_OFFSETS it's creating usually with the vale 188 on this tag. But if I try to set TAG_STRIP_OFFSETS as 8, it's changing the compression to LZW.

Can you check my below code and give me any idea in how to solve this?

private IIOMetadata getMetadata(ImageWriter iw) throws IIOInvalidTreeException {
        TIFFImageMetadata tiffMd = (TIFFImageMetadata) iw.getDefaultImageMetadata(null, tiffImageWriteParam);
        tiffMd.addShortOrLongField(BaselineTIFFTagSet.TAG_NEW_SUBFILE_TYPE,0);
        tiffMd.addShortOrLongField(BaselineTIFFTagSet.TAG_IMAGE_WIDTH,CHECK_WIDTH);
        tiffMd.addShortOrLongField(BaselineTIFFTagSet.TAG_IMAGE_LENGTH,CHECK_HEIGHT);
        tiffMd.addShortOrLongField(BaselineTIFFTagSet.TAG_BITS_PER_SAMPLE,1);
        tiffMd.addShortOrLongField(BaselineTIFFTagSet.TAG_COMPRESSION,BaselineTIFFTagSet.COMPRESSION_CCITT_T_6);
        tiffMd.addShortOrLongField(BaselineTIFFTagSet.TAG_PHOTOMETRIC_INTERPRETATION,0);
        tiffMd.addShortOrLongField(BaselineTIFFTagSet.TAG_SAMPLES_PER_PIXEL,1);
        tiffMd.addShortOrLongField(BaselineTIFFTagSet.TAG_ROWS_PER_STRIP,CHECK_HEIGHT);
        tiffMd.addShortOrLongField(BaselineTIFFTagSet.TAG_STRIP_OFFSETS,8); // Problematic line -> changes to LZW

        // Workaround for Rational X/Y Resolutions
        long[] xRes = new long[]{200, 1};
        long[] yRes = new long[]{200, 1};
        Node node = tiffMd.getAsTree(tiffMd.getNativeMetadataFormatName());
        TIFFField fieldXRes = new TIFFField(
                BaselineTIFFTagSet.getInstance().getTag(BaselineTIFFTagSet.TAG_X_RESOLUTION),
                TIFFTag.TIFF_RATIONAL, 1, new long[][]{xRes});
        TIFFField fieldYRes = new TIFFField(
                BaselineTIFFTagSet.getInstance().getTag(BaselineTIFFTagSet.TAG_Y_RESOLUTION),
                TIFFTag.TIFF_RATIONAL, 1, new long[][]{yRes});
        node.getFirstChild().appendChild(fieldXRes.getAsNativeNode());
        node.getFirstChild().appendChild(fieldYRes.getAsNativeNode());
        tiffMd.mergeTree(tiffMd.getNativeMetadataFormatName(), node);

        tiffMd.addShortOrLongField(BaselineTIFFTagSet.TAG_RESOLUTION_UNIT, 2);
        return tiffMd;
    }

Thank you, and sorry if it's not an issue in the library.

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

No branches or pull requests

1 participant