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.
This commit is contained in:
Lain
2024-04-25 22:50:41 -07:00
parent 0d8f54a4b8
commit 97e5e3efde
+15 -4
View File
@@ -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;
}