11#include <fmt/format.h>
39 ImageSpec config, spec;
40 config.attribute(
"oiio:UnassociatedAlpha", 1);
44 .file_format =
"heif",
50 const int bits_per_sample = spec.get_int_attribute(
"oiio:BitsPerSample", 8);
51 if (bits_per_sample == 10) {
54 else if (bits_per_sample == 12) {
78 const bool prefer_float)
81 const bool use_float = prefer_float && (ibuf->
float_data() !=
nullptr);
86 const size_t size_orig = size_t(ibuf->
y) * (-ctx.
mem_span.ystride());
91 memcpy(buf_padded, src_base, size_orig);
94 const size_t y_flip_offset = size_t(ibuf->
y - 1) * (-ctx.
mem_span.ystride());
95 ctx.
mem_span = image_span<const std::byte>(
96 reinterpret_cast<const std::byte *
>(buf_padded + y_flip_offset),
113 MEM_delete(buf_padded);
121 const bool use_float = bits_per_sample > 8;
124 if (file_channels == 2) {
127 const TypeDesc data_format = use_float ? TypeDesc::UINT16 : TypeDesc::UINT8;
134 file_spec.attribute(
"oiio:UnassociatedAlpha", 0);
137 file_spec.attribute(
"oiio:UnassociatedAlpha", 1);
140 file_spec.attribute(
"Compression", fmt::format(
"avif:{}",
int(ibuf->
foptions.
quality)));
141 file_spec.attribute(
"oiio:BitsPerSample", bits_per_sample);
143 return {ctx, file_spec, use_float};
149 const uchar *buf_padded =
nullptr;
150 if (OIIO_VERSION_LESS(3, 1, 12)) {
161 const uchar *buf_padded =
nullptr;
162 if (OIIO_VERSION_LESS(3, 1, 12)) {
Read Blender memory allocation and freeing.
bool imb_oiio_write(const WriteContext &ctx, const char *filepath, const ImageSpec &file_spec)
ImBuf * imb_oiio_read(const ReadContext &ctx, const ImageSpec &config, ImFileColorSpace &r_colorspace, ImageSpec &r_newspec)
bool imb_oiio_check(const uchar *mem, size_t mem_size, const char *file_format)
ImageSpec imb_create_write_spec(const WriteContext &ctx, int file_channels, TypeDesc data_format)
WriteContext imb_create_write_context(const char *file_format, const ImBuf *ibuf, ImBufFlags flags, bool prefer_float)
Vector< uint8_t > imb_oiio_write_buffer(const WriteContext &ctx, const ImageSpec &file_spec)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void imb_save_avif_padding_workaround_end(const uchar *buf_padded)
ImBuf * imb_load_avif(const uchar *mem, size_t size, ImBufFlags flags, ImFileColorSpace &r_colorspace)
bool imb_is_a_avif(const uchar *mem, size_t size)
const char * imb_file_extensions_avif[]
static constexpr int AVIF_BLOCK_SIZE
bool imb_save_avif(ImBuf *ibuf, const char *filepath, ImBufFlags flags)
Vector< uint8_t > imb_save_buffer_avif(ImBuf *ibuf, ImBufFlags flags)
static uchar * imb_save_avif_padding_workaround_begin(const ImBuf *ibuf, WriteContext &ctx, const bool prefer_float)
static std::tuple< WriteContext, ImageSpec, bool > prepare_save_avif(ImBuf *ibuf, ImBufFlags flags)
const ColorSpace * colorspace
ImbFormatOptions foptions
ImBufFloatBuffer float_buffer
const uint8_t * byte_data() const
bool colorspace_is_data() const
const float * float_data() const
int color_mode_channels_get() const
OIIO::image_span< const std::byte > mem_span