46 Commits
Author SHA1 Message Date
Brecht Van Lommel ad0abdad52 fix(heif): Invalid read writing 8bit and dimensions not a multiple of 64 (#5095)
Don't copy from memory using the stride, as this can get padded and read
past the end of the input pixel data. The 10 and 12 bit paths were
correct.

Test added, this only failed with address sanitizer.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2026-03-18 10:47:34 -07:00
Brecht Van Lommel bf7bc9c6ef feat(heif): Monochrome channel read and write support, fix crash (#5043)
Implement support for reading and writing monochrome. Reading requires
libheif 1.17+ for heif_image_handle_get_preferred_decoding_colorspace.

Previously writing a single channel image would cause an exception due
to
wrong parameters, but close() would continue writing the image and
crash.
Destroy m_ctx on exception to prevent that for other potential errors.

Test added for monochrome read and write.

---------

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2026-02-13 12:38:19 -08:00
Brecht Van Lommel fb8cde9b35 fix(webp): Missing oiio:UnassociatedAlpha on input (#5020)
Like other file formats, the returned ImageSpec should indicate if the
image contains unassociated alpha.

This was an oversight in #4770.

Test added.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2026-01-29 14:56:15 -08:00
Brecht Van Lommel ae120afe97 feat(heif): Add IOProxy for input and output (#5017)
Add IOProxy support similar to other file formats.

MyHeifWriter was renamed for consistency with other code.

All input and output now goes through the proxy, so this is covered by
existing tests.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2026-01-28 10:17:32 -08:00
Brecht Van Lommel 19c72c117e fix(heif): Error saving multiple images with different bit depths (#5018)
This variable should not have been static.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2026-01-28 10:13:00 -08:00
Brecht Van Lommel e6ccb76a29 fix(heif): Can not output AVIF when libheif has no HEVC support (#5013)
Initializing the encoder to `heif_compression_HEVC` by default throws an
exception when libheif was built without HEVC support, which prevents it
from being used entirely even if there is AVIF support.

So delay that initialization until we are sure which encoding we want.

Not really any practical way to automatically test this.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2026-01-23 11:37:58 -08:00
Brecht Van Lommel ff89654492 feat(JXL): CICP read and write support for JPEG XL (#4968)
The JPEG XL color encoding metadata only supports a subset of CICP. So
for
example `srgb_p3d65_display` and `pq_rec2020_display` are supported, but
`g26_xyzd65_display` is not.

Custom primaries, custom white point and arbitrary gamma could be used
to
support more, but I didn't implement that.

Tests for read and write were added.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2025-12-22 10:24:15 -08:00
Brecht Van Lommel 693b09b4ff feat(exr): Write OpenEXR colorInteropID metadata based on oiio:ColorSpace (#4967)
If the colorspace exists and has an interop ID in an OCIO 2.5 config,
use that.
Otherwise check if the colorspace is equivalent to a known color interop
ID.

Tests were added.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2025-12-19 12:37:06 -08:00
Brecht Van Lommel 9229cf33c9 feat: Auto convert between oiio:ColorSpace and CICP attributes in I/O (#4964)
When reading image files with CICP metadata, automatically set the
corresponding "oiio:ColorSpace". When writing files that support CICP
and no other colorspace metadata can represent "oiio:ColorSpace",
automatically write CICP metadata.

Setting "oiio:ColorSpace" on read prefers scene referred over display
referred color spaces, changing existing behavior as little as possible.
The alternative would have been to interpret the presence of CICP
metadata as an indication that the image is likely display referred,
which might be reasonable too. Either way it's a guess.

There is no automatic mapping from `g22_rec709_display` to CICP
currently to keep behavior unchanged, as this is often not what you want
and further discussion is needed to decided on the right behavior.

Also add new ColorConfig `get_cicp` and `get_color_interop_id` API
functions to share logic between file formats.

## Tests

Tests were updated, the auto detected color space name appears in the
output.

Commands like these should also do the right thing automatically.
```
oiiotool in.exr --ociodisplay "Rec.2100-PQ - Display" "ACES 2.0 - HDR 1000 nits (P3 D65)" -o out.avif
oiiotool out.avif --autocc -o out.exr
```

---------

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2025-12-12 00:03:23 -08:00
Brecht Van Lommel 4a13f4b6df fix(exr): ACES container writes colorInteropId instead of colorInteropID (#4966)
The EXR reading code was correct. These attribute names are case
sensitive in OpenEXR.

Test output was updated.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2025-11-27 22:07:36 -08:00
Brecht Van Lommel aa31926cba fix(ffmpeg): 10 bit video has wrong green channel (#4935)
Due to apparent limitations or bugs in swscale, there is a problem
reading the 16 bit green channel that is not 4 byte aligned like red and
blue. Reading each channel into its own plane solves the issue.

This also addresses an existing comment about 32 bit float being read as
16 bit. This needed the same mechanism of reading separate planes, so
the same code is reused to implement that.

Resolves #4901

I added a 10 bit test file encoded with VP9 and Matroska, same as the
existing 8 bit test file to maximize compatibility. I verified this now
converts correctly to a HDR PNG file.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2025-10-18 20:23:35 -07:00
Brecht Van Lommel b9e3a9931f fix(ffmpeg): FFmpeg sets zero oiio:BitsPerSample (#4885)
Many codecs don't provide `bits_per_raw_sample`. The bit depth of the
luma channel is the closest equivalent to a single bit depth then, while
the chroma channels may be subsampled.

Tested on basically all the video files on my computer, they all give a
non-zero bit depth that looks correct now.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2025-09-15 10:47:05 -07:00
Brecht Van Lommel 40810e2e0b feat(heif): Read and write of CICP and bit depth 10 and 12 (#4880)
* Read and write 10 and 12 bit images
* Read and write CICP

This makes it possible to write HDR images that are much smaller than
PNGs, in a file format that is supported in all modern web browsers.

By setting the matrix coefficients, the library will perform RGB to YUV
conversion on write. The YUV to RBG conversion was already happening on
read automatically.

A future improvement would be a better default choice of matrix
coefficients for writing. When no CICP is specified or when CICP is read
from PNG, then no conversion to YUV will be performed and compression
will not work as well. This is the same behavior as before. When there
is support for conversion between CICP and display interop ID, a good
default choice for matrix coefficients could be made as part of that.

Tests for CICP and 10 bit were added.

---------

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2025-09-13 21:54:02 -07:00
Brecht Van Lommel 4945b57f65 feat(ffmpeg): Read CICP metadata, and add test (#4882)
The actual CICP reading code is trivial.

Also recognize mkv (Matroska) extension for the test.

Add test using Matroska + VP9, to maximize the chance of an ffmpeg build
supporting them. They are royalty free, built into ffmpeg and relatively
old.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2025-09-13 16:50:42 -07:00
Brecht Van Lommel 9979a27ee6 api: Restore OIIO_NAMESPACE_USING (#4603)
This got lost with the 2-level namespace changes in #4567, but is used
by e.g. OpenUSD. Might as well not break the API here.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2025-01-22 09:31:44 -08:00
Brecht Van Lommel 9f62336e33 Don't use (DY)LD_LIBRARY_PATH as plugin search paths (#4245)
Only use the OIIO_LIBRARY_PATH environment variable by default.

Searching through such system paths has some risk loading plugins
installed for another purpose or that may be incompatible.

If the previous behavior is desired, applications can add these
environment variables to the plugin search path manually.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>
2024-04-25 23:34:56 -07:00
Brecht Van Lommel dfb086e130 Fix wrong oiio:UnassociatedAlpha spec for PSD files (#3750)
Refactoring in #1641 incorrectly caused this to be set on the last layer
rather than the composite image as before. Now set it on the composite
image and every layer, as all of them use unassociated alpha.
2023-01-09 11:18:33 -08:00
Brecht Van Lommel 4f97ff6eef Fix excessive memory usage when saving EXR file with many channels (#3176)
Scratch memory allocation in ImageOutput::to_native_rectangle was using
the number of channels squared.
2021-11-11 13:25:55 -08:00
Brecht Van Lommel 6ce93a1334 Fix poor performance with texture cache and HDR files (#2662)
When the texture cache reads scanlines in random order, the same pixels could
be read many times over. Now the file offset for scanlines is cached for quick
random access.
2020-08-06 15:20:00 -07:00
Brecht Van Lommel cad4ad5404 Add USE_WEBP option to disable building WebP. (#2200) 2019-03-29 07:17:40 -07:00
Brecht Van Lommel 8bf4136e5b Fix Windows build to not force enable /MT, it is not need for BUILDSTATIC. (#1702) 2017-06-06 14:25:57 -07:00
Brecht Van Lommel 384b34ae95 Fix Ilmbase linker warning with LINKSTATIC on Windows. (#1701) 2017-06-06 14:25:57 -07:00
Brecht Van Lommel 02b7e855d3 Fix exr_threads value -1 to disable thread pools not working. (#1582) 2016-12-11 08:19:44 -08:00
Brecht Van Lommel 0717ae8b67 Deep OpenEXR: recognize newer AR/AG/AB channel name convention. 2015-12-04 17:58:34 +01:00
Brecht Van Lommel cc0512902a Fix multithreaded build with make -jN no longer working.
GNU make requires ${MAKE} to be used to detect the child process is make.
2015-06-12 19:51:03 +02:00
Brecht Van Lommel 22bcff7ae4 Fix trilinear mipmap texture lookup giving an invalid alpha fill. 2015-06-10 16:29:59 -07:00
Brecht Van Lommel b2f028c343 Fix occasional NaNs in alpha channel with 3 channel images. 2015-04-01 00:14:42 -07:00
Brecht Van Lommel 909867ef21 Fix occasional NaNs in alpha channel with 3 channel images. 2015-03-31 19:13:05 +02:00
Brecht Van Lommel 584d545b28 Fix build error in float4.xyz0() with SSE version < 4. 2015-03-03 18:33:15 +01:00
Brecht Van Lommel 3505e4f5d2 Fix broken bicubic texture sampling with non-power-of-two sized tiles. 2015-01-21 10:29:19 -08:00
Brecht Van Lommel cfe29da2ee Fix compile error due to using SSE 3 _mm_abs_epi32 when compiling for SSE 2. 2014-10-02 16:07:48 +02:00
Brecht Van Lommel 040157653c Fix two issues with unassociated alpha conversion:
* PNG, TIFF and TGA input still had oiio:UnassociatedAlpha set to 1 after they
  convert the alpha to associated.
* PNG output did not take oiio:UnassociatedAlpha into account to determine if
  conversion should be done, while TIFF did.
2013-09-15 13:53:53 -07:00
Brecht Van Lommel 2b0ead1376 TGA output now always writes unassociated alpha, even if the input is associated.
This is because common applications like Gimp, Photoshop and Preview will assume
TGA files to have unassociated alpha.
2013-09-15 13:53:53 -07:00
Brecht Van Lommel 18e9495803 TGA now converts alpha to associated on input if requested, and on output writes
the attribute that indicates if the alpha is premultiplied or not.
2013-09-15 13:53:53 -07:00
Brecht Van Lommel 4e4ec9f54d Fix some JPEG files not being recognized, now only look at the first two bytes. 2013-09-12 09:41:03 -07:00
Brecht Van Lommel bf0a4fdf68 Fix oiiotool # wildcard for frame numbers not working on Windows, it needs a
backslash instead of forward slash.
2013-06-06 16:46:52 +02:00
Brecht van Lommel c3bbc650bb Fix windows build errors with LARGE_INTEGER, strtof, uint32_t and RGB #define. 2013-05-08 20:18:25 +02:00
Brecht Van Lommel ab20291fee Move shared_ptr and intrusive_ptr from the global to the OIIO namespace, to
avoid conflicts when another package already defines them.
2013-04-24 22:03:47 -07:00
Brecht Van Lommel b02f661bcc Fix build errors with alloca/isinf/isnan/isfinite, using MinGW on Windows. 2012-12-22 10:45:34 +01:00
Brecht Van Lommel fdf2d3be58 Fix for handling of UTF-8 file paths on Windows for OpenEXR files.
For most other fileformats this was already fixed, and I thought this wasn't
possible with the current OpenEXR API, but it turns out it is by implementing
a custom input/output stream class.

The code for these is copied from ImfStdIO.h/cpp which are the classes that
would be used otherwise, so exception handling etc should work identical.
2012-09-22 12:46:57 -07:00
Brecht Van Lommel cf9590b044 Fix tiff issue with UTF-8 file paths, now using TIFFOpenW on Windows instead of
passing the file descriptor. This moves platform specific code into the tiff
plugin code, but it should be safer than trying to obtain the right file handle
with fopen.
2012-05-30 10:06:01 -07:00
Brecht Van Lommel 1245bef9be Filesystem changes to handle UTF-8 file paths on Windows.
* New Filesystem utility functions wrap fopen, open, and last_write_time
  but do so in a way that is safe for UTF-8 filenames on Windows (for example,
  we need to call _wfopen rather than fopen on Windows).
* The various plugins that called fopen/etc directly have been changed to
  use these Filesystems wrappers.
* Add Filesystem::convert_native_arguments which modifies an argv[] in
  place to convert Windows native to UTF-8 (does nothing for non-Windows).
* Create a wrapper for last_write_time that, like many other Filesystem
  wrappers, catches the exceptions that can happen
* Fix file handle leak with failed read of tiff/z gzipped files.
2012-05-28 09:52:51 -07:00
brechtvanlommel@gmail.com 63bea5bb7f Fixes for FreeBSD: Arbitrary unix platform detection, use uint64_t for imagesize_t, use TBB instead of gcc builtin atomics on non-x86_64 BSD, FreeBSD build fixes for ptex. 2011-12-15 07:30:14 -08:00
brechtvanlommel@gmail.com 64e2fe7adf Add math functions that are missing on Windows, but used by OSL: expm1f, erff, erfcf, truncf. 2011-03-13 20:56:36 -07:00
brechtvanlommel@gmail.com 73aa0754a8 Fix build with USE_TBB off (on Windows). 2011-03-01 00:50:12 +01:00
brechtvanlommel@gmail.com 87ab6f0971 Export pugixml symbols from windows DLL. 2011-02-24 14:25:21 +01:00