From 97e5e3efde31b1a187fe37852e2df45ab8f5ca6c Mon Sep 17 00:00:00 2001 From: Lain Date: Thu, 25 Apr 2024 22:50:41 -0700 Subject: [PATCH] libobs/graphics: Read floating point image files Certain file types (such as .tiff) can contain RGB data of floating point bit depth. This allows reading that data as-is without unnecessarily converting it to a lower bit depth. --- libobs/graphics/graphics-ffmpeg.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libobs/graphics/graphics-ffmpeg.c b/libobs/graphics/graphics-ffmpeg.c index a3a14a7bd..e2caab47f 100644 --- a/libobs/graphics/graphics-ffmpeg.c +++ b/libobs/graphics/graphics-ffmpeg.c @@ -116,9 +116,10 @@ fail: #endif static void *ffmpeg_image_copy_data_straight(struct ffmpeg_image *info, - AVFrame *frame) + AVFrame *frame, + size_t channel_bits) { - const size_t linesize = (size_t)info->cx * 4; + const size_t linesize = (size_t)info->cx * 4 * channel_bits / 8; const size_t totalsize = info->cy * linesize; void *data = bmalloc(totalsize); @@ -369,12 +370,18 @@ static void *ffmpeg_image_reformat_frame(struct ffmpeg_image *info, } if (info->format == AV_PIX_FMT_BGR0) { - data = ffmpeg_image_copy_data_straight(info, frame); + data = ffmpeg_image_copy_data_straight(info, frame, 8); + + } else if (info->format == AV_PIX_FMT_RGBAF16LE) { + data = ffmpeg_image_copy_data_straight(info, frame, 16); + + } else if (info->format == AV_PIX_FMT_RGBAF32LE) { + data = ffmpeg_image_copy_data_straight(info, frame, 32); } else if (info->format == AV_PIX_FMT_RGBA || info->format == AV_PIX_FMT_BGRA) { if (alpha_mode == GS_IMAGE_ALPHA_STRAIGHT) { - data = ffmpeg_image_copy_data_straight(info, frame); + data = ffmpeg_image_copy_data_straight(info, frame, 8); } else { const size_t linesize = (size_t)info->cx * 4; const size_t totalsize = info->cy * linesize; @@ -611,6 +618,10 @@ static inline enum gs_color_format convert_format(enum AVPixelFormat format) return GS_BGRX; case AV_PIX_FMT_RGBA64BE: return GS_RGBA16; + case AV_PIX_FMT_RGBAF16LE: + return GS_RGBA16F; + case AV_PIX_FMT_RGBAF32LE: + return GS_RGBA32F; default: return GS_BGRX; }