1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avcodec/exr: do not output 32bit floats when a file stores 16bit floats

exr should not do a internal pixel format convert

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer
2025-01-09 23:08:23 +01:00
parent 56cfbe3c9f
commit 0e917389fe
43 changed files with 83 additions and 66 deletions

View File

@ -1185,7 +1185,7 @@ static int decode_block(AVCodecContext *avctx, void *tdata,
int line, col = 0;
uint64_t tile_x, tile_y, tile_level_x, tile_level_y;
const uint8_t *src;
int step = s->desc->flags & AV_PIX_FMT_FLAG_FLOAT ? 4 : 2 * s->desc->nb_components;
int step = s->desc->comp[0].step;
int bxmin = 0, axmax = 0, window_xoffset = 0;
int window_xmin, window_xmax, window_ymin, window_ymax;
int data_xoffset, data_yoffset, data_window_offset, xsize, ysize;
@ -1365,7 +1365,7 @@ static int decode_block(AVCodecContext *avctx, void *tdata,
if (s->channel_offsets[3] >= 0)
channel_buffer[3] = src + (td->xsize * s->channel_offsets[3]) + data_window_offset;
if (s->desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
if (s->desc->flags & AV_PIX_FMT_FLAG_PLANAR || s->desc->nb_components == 1 ) {
/* todo: change this when a floating point pixel format with luma with alpha is implemented */
int channel_count = s->channel_offsets[3] >= 0 ? 4 : rgb_channel_count;
if (s->is_luma) {
@ -1379,19 +1379,20 @@ static int decode_block(AVCodecContext *avctx, void *tdata,
for (i = 0; i < ysize; i++, ptr += p->linesize[plane]) {
const uint8_t *src;
union av_intfloat32 *ptr_x;
src = channel_buffer[c];
ptr_x = (union av_intfloat32 *)ptr;
// Zero out the start if xmin is not 0
memset(ptr_x, 0, bxmin);
ptr_x += window_xoffset;
if (s->pixel_type == EXR_FLOAT ||
s->compression == EXR_DWAA ||
s->compression == EXR_DWAB) {
// 32-bit
union av_intfloat32 *ptr_x;
src = channel_buffer[c];
ptr_x = (union av_intfloat32 *)ptr;
// Zero out the start if xmin is not 0
memset(ptr_x, 0, bxmin);
ptr_x += window_xoffset;
union av_intfloat32 t;
if (trc_func && c < 3) {
for (x = 0; x < xsize; x++) {
@ -1412,22 +1413,22 @@ static int decode_block(AVCodecContext *avctx, void *tdata,
*ptr_x++ = t;
}
}
memset(ptr_x, 0, axmax);
} else if (s->pixel_type == EXR_HALF) {
src = channel_buffer[c];
// Zero out the start if xmin is not 0
memset(ptr, 0, bxmin);
// 16-bit
if (c < 3 || !trc_func) {
for (x = 0; x < xsize; x++) {
*ptr_x++ = s->gamma_table[bytestream_get_le16(&src)];
}
} else {
for (x = 0; x < xsize; x++) {
ptr_x[0].i = half2float(bytestream_get_le16(&src), &s->h2f_tables);
ptr_x++;
}
for (x = window_xoffset; x < xsize + window_xoffset; x++) {
int v = bytestream_get_le16(&src);
AV_WN16(ptr + x * sizeof(uint16_t), v);
}
memset(ptr + x * sizeof(uint16_t), 0, axmax);
}
// Zero out the end if xmax+1 is not w
memset(ptr_x, 0, axmax);
channel_buffer[c] += td->channel_line_size;
}
}
@ -2053,8 +2054,25 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture,
}
switch (s->pixel_type) {
case EXR_FLOAT:
case EXR_HALF:
if (!(s->compression == EXR_DWAA || s->compression == EXR_DWAB)) {
if (s->channel_offsets[3] >= 0) {
if (!s->is_luma) {
avctx->pix_fmt = AV_PIX_FMT_GBRAPF16;
} else {
/* todo: change this when a floating point pixel format with luma with alpha is implemented */
avctx->pix_fmt = AV_PIX_FMT_GBRAPF16;
}
} else {
if (!s->is_luma) {
avctx->pix_fmt = AV_PIX_FMT_GBRPF16;
} else {
avctx->pix_fmt = AV_PIX_FMT_GRAYF16;
}
}
break;
}
case EXR_FLOAT:
if (s->channel_offsets[3] >= 0) {
if (!s->is_luma) {
avctx->pix_fmt = AV_PIX_FMT_GBRAPF32;
@ -2139,13 +2157,12 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture,
if (!s->desc)
return AVERROR_INVALIDDATA;
if (s->desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
if (s->desc->flags & AV_PIX_FMT_FLAG_PLANAR) {
planes = s->desc->nb_components;
out_line_size = avctx->width * 4;
} else {
planes = 1;
out_line_size = avctx->width * 2 * s->desc->nb_components;
}
out_line_size = avctx->width * s->desc->comp[0].step;
if (s->is_tile) {
nb_blocks = ((s->xdelta + s->tile_attr.xSize - 1) / s->tile_attr.xSize) *

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 4x4
#sar 0: 1/1
0, 0, 0, 1, 192, 0x5b8e39c0
0, 0, 0, 1, 192, 0x2b0438a0

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0x577d5150
0, 0, 0, 1, 1152, 0xa25c30dd

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0xe84d5b9d
0, 0, 0, 1, 1152, 0xdb43ec2d

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 13x9
#sar 0: 1/1
0, 0, 0, 1, 1404, 0x252cc156
0, 0, 0, 1, 1404, 0x108f51a5

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 34x27
#sar 0: 1/1
0, 0, 0, 1, 11016, 0x1644e1f9
0, 0, 0, 1, 11016, 0xa40e4a99

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 34x40
#sar 0: 1/1
0, 0, 0, 1, 16320, 0xc40939ad
0, 0, 0, 1, 16320, 0xcb1cce31

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 50x50
#sar 0: 1/1
0, 0, 0, 1, 30000, 0xb329ee9c
0, 0, 0, 1, 30000, 0xef01f54f

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 400x300
#sar 0: 1/1
0, 0, 0, 1, 1440000, 0x4800b00b
0, 0, 0, 1, 1440000, 0x28c78688

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 501x401
#sar 0: 1/1
0, 0, 0, 1, 2410812, 0x2dd1b00b
0, 0, 0, 1, 2410812, 0x30fd8688

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 50x50
#sar 0: 1/1
0, 0, 0, 1, 30000, 0xb329ee9c
0, 0, 0, 1, 30000, 0xef01f54f

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1536, 0x04e1137d
0, 0, 0, 1, 1536, 0xff5dd409

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0x8f8c4a81
0, 0, 0, 1, 1152, 0xf8891b1d

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0x8f8c4a81
0, 0, 0, 1, 1152, 0xf8891b1d

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0x8f8c4a81
0, 0, 0, 1, 1152, 0xf8891b1d

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 256x256
#sar 0: 1/1
0, 0, 0, 1, 786432, 0xce9be2be
0, 0, 0, 1, 786432, 0xee1d1d63

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0x8f8c4a81
0, 0, 0, 1, 1152, 0xf8891b1d

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0x8f8c4a81
0, 0, 0, 1, 1152, 0xf8891b1d

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0x8f8c4a81
0, 0, 0, 1, 1152, 0xf8891b1d

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0x577d5150
0, 0, 0, 1, 1152, 0xa25c30dd

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 50x50
#sar 0: 1/1
0, 0, 0, 1, 30000, 0xb329ee9c
0, 0, 0, 1, 30000, 0xa02a541c

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0xd3614640
0, 0, 0, 1, 1152, 0x8d572027

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 501x401
#sar 0: 1/1
0, 0, 0, 1, 2410812, 0x2dd1b00b
0, 0, 0, 1, 2410812, 0x0deb5853

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1536, 0x04e1137d
0, 0, 0, 1, 1536, 0xff5dd409

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0x8f8c4a81
0, 0, 0, 1, 1152, 0xf8891b1d

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0x8f8c4a81
0, 0, 0, 1, 1152, 0xf8891b1d

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0x8f8c4a81
0, 0, 0, 1, 1152, 0xf8891b1d

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0x8f8c4a81
0, 0, 0, 1, 1152, 0xf8891b1d

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1152, 0x8f8c4a81
0, 0, 0, 1, 1152, 0xf8891b1d

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 935x251
#sar 0: 1/1
0, 0, 0, 1, 3754960, 0x8d9af112
0, 0, 0, 1, 3754960, 0xb8d01312

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 9/10
0, 0, 0, 1, 1536, 0x0fca2ff9
0, 0, 0, 1, 1536, 0x08f93871

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 13x9
#sar 0: 9/10
0, 0, 0, 1, 1872, 0xf99e750e
0, 0, 0, 1, 1872, 0x0cc9b33e

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 9/10
0, 0, 0, 1, 1536, 0x0fca2ff9
0, 0, 0, 1, 1536, 0x08f93871

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 13x9
#sar 0: 9/10
0, 0, 0, 1, 1872, 0xf99e750e
0, 0, 0, 1, 1872, 0x0cc9b33e

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 16x32
#sar 0: 1/1
0, 0, 0, 1, 8192, 0x87767180
0, 0, 0, 1, 8192, 0x508ccf49

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 800x800
#sar 0: 1/1
0, 0, 0, 1, 7680000, 0x98f60162
0, 0, 0, 1, 7680000, 0xd261d30c

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 587x675
#sar 0: 1/1
0, 0, 0, 1, 6339600, 0xda3e31df
0, 0, 0, 1, 6339600, 0xeffa4255

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 587x675
#sar 0: 1/1
0, 0, 0, 1, 6339600, 0xda3e31df
0, 0, 0, 1, 6339600, 0xeffa4255

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 587x675
#sar 0: 1/1
0, 0, 0, 1, 6339600, 0xda3e31df
0, 0, 0, 1, 6339600, 0xeffa4255

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 587x675
#sar 0: 1/1
0, 0, 0, 1, 6339600, 0xda3e31df
0, 0, 0, 1, 6339600, 0xeffa4255

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 384, 0x911475c4
0, 0, 0, 1, 384, 0xb9c5ba92

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 384, 0x911475c4
0, 0, 0, 1, 384, 0xb9c5ba92

View File

@ -3,4 +3,4 @@
#codec_id 0: rawvideo
#dimensions 0: 12x8
#sar 0: 1/1
0, 0, 0, 1, 1536, 0x9473ee5c
0, 0, 0, 1, 1536, 0x2b457bd2