Skip to content

Load wide TIFF files when FreeImage is 3.19.29 - #8626

Draft
danoli3 wants to merge 1 commit into
openframeworks:masterfrom
danoli3:freeimage-3.19.29-io64
Draft

danoli3 wants to merge 1 commit into
openframeworks:masterfrom
danoli3:freeimage-3.19.29-io64

Conversation

@danoli3

@danoli3 danoli3 commented Oct 28, 2026

Copy link
Copy Markdown
Member

Summary

ofLoadImage uses FreeImage's 64-bit TIFF input API when the FreeImage header included by the build is 3.19.29 or newer. The public ofImage / ofLoadImage signatures are unchanged, and this pull request does not vendor a new libFreeImage.

FreeImage PR 197 adds an additive read API:

  • FreeImageIO64
  • FreeImage_Load64
  • FreeImage_LoadFromHandle64

That API reads one TIFF or BigTIFF, including images whose directories or strips sit past 2 GiB. Other formats return null from those entry points. Saving, multipage TIFF, and FreeImage_OpenMemory (still a DWORD stored as int) are outside that change. There is no FreeImage_LoadU64.

3.19.29 is not released yet. The header on PR 197 is still FREEIMAGE_RELEASE_SERIAL 28, so a build against that branch keeps the existing loader. The wide path turns on when a shipped header reports 3.19.29 or newer:

#define OF_FREEIMAGE_VERSION_NUMBER \
    (FREEIMAGE_MAJOR_VERSION * 10000 + FREEIMAGE_MINOR_VERSION * 100 + FREEIMAGE_RELEASE_SERIAL)
#if OF_FREEIMAGE_VERSION_NUMBER >= 31929

The openFrameworks libraries published today include FreeImage 3.19.21, so current builds keep FreeImage_Load / FreeImage_LoadFromMemory.

Behavior

  • A TIFF file is loaded with FreeImage_Load64. On Windows the path stays UTF-16: the file is opened with _wfopen and read through FreeImage_LoadFromHandle64 using _fseeki64 / _ftelli64.
  • An in-memory TIFF, including BigTIFF (II+ / MM+), is loaded through FreeImage_LoadFromHandle64.
  • A buffer larger than numeric_limits<int>::max() is not given to FreeImage_OpenMemory. A TIFF signature takes the 64-bit stream. Any other format logs an error and returns false.
  • JPEG decode flags are still applied for JPEG. Non-TIFF files keep FreeImage_Load / FreeImage_LoadU / FreeImage_LoadFromMemory.

Test

Syntax-only compile of ofImage.cpp (C++17, macOS headers):

  • FreeImage 3.19.21: OF_FREEIMAGE_IO64 is 0 and the file compiles. FreeImage_Load64 is not referenced.
  • PR 197 header as published (serial 28): the same gate stays off.
  • That header with FREEIMAGE_RELEASE_SERIAL set to 29: OF_FREEIMAGE_IO64 is 1 and the new TIFF calls type-check against FreeImageIO64.

A wide TIFF has not been decoded here. That needs a FreeImage 3.19.29 library, which is not published yet.

FreeImage 3.19.29 adds FreeImage_Load64 and FreeImage_LoadFromHandle64 for single-image TIFF and BigTIFF input. ofImage uses that path when the included header is 3.19.29 or newer. Headers before that keep FreeImage_Load and FreeImage_LoadFromMemory.

Memory buffers larger than the legacy int limit are not passed to FreeImage_OpenMemory. A TIFF signature is read through the 64-bit stream. On Windows, TIFF files stay on the UTF-16 path and use LoadFromHandle64, because the new API has no LoadU64.
@danoli3
danoli3 marked this pull request as draft October 29, 2026 23:50
@danoli3 danoli3 added this to the 0.13.0 milestone Oct 30, 2026
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

Successfully merging this pull request may close these issues.

1 participant