I eventually worked out what was happening:

The very act of writing the data added two additional fields to the base IFD
- specifically:

 

StripOffsets (3 Long): 514, 16771762, 33543010

StripByteCounts (3 Long): 16771248, 16771248, 2496960 

 

They were added by the libtiff code internally (not by my code).

 

Which meant that the base IFD was larger after writing the data than it was
before. Thus, TIFFWriteDirectory over-wrote the EXIF IFD resulting in the
EXIF IFD being overwritten . and the file therefore failed validation.
Therefore, there's no way to avoid the base IFD being at the end of the
file.

 

From: Tiff <tiff-boun...@lists.osgeo.org> On Behalf Of David C. Partridge
Sent: 13 April 2023 10:33
To: tiff@lists.osgeo.org
Subject: Re: [Tiff] TIffWriteDirectory() causes problems

 

Grump

I changed the code so this is done before I write the image data:

                    //

                    TIFFSetDirectory(m_tiff, 0);

                    TIFFSetField(m_tiff, TIFFTAG_EXIFIFD, dir_offset_EXIF);

                    //TIFFCheckpointDirectory(m_tiff);

                    TIFFWriteDirectory(m_tiff);

                    TIFFSetDirectory(m_tiff, 0);


(is CheckpointDirectory() supposed to have the same effect as WriteDirectory
followed by SetDirectory ???)

But while it solved the issue with scanline size, the main IFD ended up at
the END of the file again:

 

C:\Users\amonra\jhove>jhove "C:\Users\amonra\Documents\Astrophotography\DSS
Test Images\Covington\TestImages\Bias\MasterOffset_ISO200.tif"

Jhove (Rel. 1.26.1, 2022-07-14)

Date: 2023-04-13 10:17:09 BST

RepresentationInformation: C:\Users\amonra\Documents\Astrophotography\DSS
Test Images\Covington\TestImages\Bias\MasterOffset_ISO200.tif

  ReportingModule: TIFF-hul, Rel. 1.9.3 (2022-04-22)

  LastModified: 2023-04-13 06:46:48 BST

  Size: 36040428

  Format: TIFF

  Version: 6.0

  Status: Well-Formed and valid

  SignatureMatches:

   TIFF-hul

  InfoMessage: Unknown TIFF IFD tag: 340

   ID: TIFF-HUL-12

   Offset: 36040184

  InfoMessage: Unknown TIFF IFD tag: 341

   ID: TIFF-HUL-12

   Offset: 36040196

  InfoMessage: Unknown TIFF IFD tag: 50002

   ID: TIFF-HUL-12

   Offset: 36040244

  InfoMessage: Unknown TIFF IFD tag: 50006

   ID: TIFF-HUL-12

   Offset: 36040256

  InfoMessage: Unknown TIFF IFD tag: 50007

   ID: TIFF-HUL-12

   Offset: 36040268

  InfoMessage: Unknown TIFF IFD tag: 50008

   ID: TIFF-HUL-12

   Offset: 36040280

  InfoMessage: Unknown TIFF IFD tag: 50009

   ID: TIFF-HUL-12

   Offset: 36040292

  InfoMessage: Unknown TIFF IFD tag: 50010

   ID: TIFF-HUL-12

   Offset: 36040304

  MIMEtype: image/tiff

  Profile: TIFF/IT-MP (ISO 12639:1998)

  TIFFMetadata:

   ByteOrder: little-endian

   IFDs:

    Number: 2

    IFD:

     Offset: 36039970

     Type: TIFF

     Entries:

      NisoImageMetadata:

etc .

 

I don't (now) issue any TIFF calls from Write() apart from
TIFFScanlineSize(m_tiff) and TIFFWriteEncodedStrip().

 

I tried issuing another TIFFWriteDirectory call just before I called
TIFFClose, just that resulted in a TIFF that I could read in my code without
any issues, but when I tried to validate it using jHove I got:

C:\Users\amonra\jhove>jhove "C:\Users\amonra\Documents\Astrophotography\DSS
Test Images\Covington\TestImages\Bias\MasterOffset_ISO200.tif" | more

Jhove (Rel. 1.26.1, 2022-07-14)

Date: 2023-04-13 10:27:10 BST

RepresentationInformation: C:\Users\amonra\Documents\Astrophotography\DSS
Test Images\Covington\TestImages\Bias\MasterOffset_ISO200.tif

  ReportingModule: BYTESTREAM, Rel. 1.4 (2018-10-01)

  LastModified: 2023-04-13 10:26:44 BST

  Size: 36039970

  Format: bytestream

  Status: Well-Formed and valid

  SignatureMatches:

   TIFF-hul

  MIMEtype: application/octet-stream

 

Or if I specified -m TIFF-hul 

:\Users\amonra\jhove>jhove -m TIFF-hul
"C:\Users\amonra\Documents\Astrophotography\DSS Test
Images\Covington\TestImages\Bias\MasterOffset_ISO200.tif"

| more

hove (Rel. 1.26.1, 2022-07-14)

Date: 2023-04-13 10:30:14 BST

RepresentationInformation: C:\Users\amonra\Documents\Astrophotography\DSS
Test Images\Covington\TestImages\Bias\MasterOffset_ISO200.tif

ReportingModule: TIFF-hul, Rel. 1.9.3 (2022-04-22)

LastModified: 2023-04-13 10:26:44 BST

Size: 36039970

Format: TIFF

Version: 6.0

Status: Not well-formed

SignatureMatches:

  TIFF-hul

InfoMessage: Unknown TIFF IFD tag: 340

  ID: TIFF-HUL-12

  Offset: 222

InfoMessage: Unknown TIFF IFD tag: 341

  ID: TIFF-HUL-12

  Offset: 234

InfoMessage: Unknown TIFF IFD tag: 50002

  ID: TIFF-HUL-12

  Offset: 282

InfoMessage: Unknown TIFF IFD tag: 50006

  ID: TIFF-HUL-12

  Offset: 294

InfoMessage: Unknown TIFF IFD tag: 50007

  ID: TIFF-HUL-12

  Offset: 306

InfoMessage: Unknown TIFF IFD tag: 50008

  ID: TIFF-HUL-12

  Offset: 318

InfoMessage: Unknown TIFF IFD tag: 50009

  ID: TIFF-HUL-12

  Offset: 330

InfoMessage: Unknown TIFF IFD tag: 50010

  ID: TIFF-HUL-12

  Offset: 342

ErrorMessage: Unknown data type: Type = 30068, Tag = 25449

  ID: TIFF-HUL-3

  Offset: 422

ErrorMessage: Unknown data type: Type = 8307, Tag = 25970

  ID: TIFF-HUL-3

  Offset: 434

ErrorMessage: Tag 19752 out of sequence

  ID: TIFF-HUL-2

  Offset: 444

ErrorMessage: Unknown data type: Type = 25701, Tag = 19752

  ID: TIFF-HUL-3

  Offset: 446

ErrorMessage: Unknown data type: Type = 10606, Tag = 24937

  ID: TIFF-HUL-3

  Offset: 458

ErrorMessage: Tag 0 out of sequence

  ID: TIFF-HUL-2

How can I get that root IFD to be at the start of the file please?

 

Thanks, David

_______________________________________________
Tiff mailing list
Tiff@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/tiff

Reply via email to