History

avfilter/vf_zscale: add support for half precision float RGB formats

James Almer committed 1 year ago

Commit c3522711 parent 76f09ab1 file · +13 −3Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_zscale.c+13−3
@@ -209,6 +209,7 @@ static int query_formats(const AVFilterContext *ctx, · 208 unmodified lines
209209 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
210210 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
211211 AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP14, AV_PIX_FMT_GBRAP16,
212+ AV_PIX_FMT_GBRPF16, AV_PIX_FMT_GBRAPF16,
212213 AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32,
213214 AV_PIX_FMT_NONE
214215 };
@@ -582,7 +583,8 @@ static void format_init(zimg_image_format *format, AVFrame *frame, const AVPixFm · 367 unmodified lines
582583 format->subsample_w = desc->log2_chroma_w;
583584 format->subsample_h = desc->log2_chroma_h;
584585 format->depth = desc->comp[0].depth;
585− format->pixel_type = (desc->flags & AV_PIX_FMT_FLAG_FLOAT) ? ZIMG_PIXEL_FLOAT : desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
586+ format->pixel_type = (desc->flags & AV_PIX_FMT_FLAG_FLOAT) ? (desc->comp[0].depth > 16 ? ZIMG_PIXEL_FLOAT : ZIMG_PIXEL_HALF)
587+ : (desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE);
586588 format->color_family = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_COLOR_RGB : ZIMG_COLOR_YUV;
587589 format->matrix_coefficients = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_MATRIX_RGB : colorspace == -1 ? convert_matrix(frame->colorspace) : colorspace;
588590 format->color_primaries = primaries == -1 ? convert_primaries(frame->color_primaries) : primaries;
@@ -861,11 +863,13 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 272 unmodified lines
861863 s->alpha_src_format.width = in->width;
862864 s->alpha_src_format.height = in->height;
863865 s->alpha_src_format.depth = desc->comp[0].depth;
864− s->alpha_src_format.pixel_type = (desc->flags & AV_PIX_FMT_FLAG_FLOAT) ? ZIMG_PIXEL_FLOAT : desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
866+ s->alpha_src_format.pixel_type = (desc->flags & AV_PIX_FMT_FLAG_FLOAT) ? (desc->comp[0].depth > 16 ? ZIMG_PIXEL_FLOAT : ZIMG_PIXEL_HALF)
867+ : (desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE);
865868 s->alpha_src_format.color_family = ZIMG_COLOR_GREY;
866869
867870 s->alpha_dst_format.depth = odesc->comp[0].depth;
868− s->alpha_dst_format.pixel_type = (odesc->flags & AV_PIX_FMT_FLAG_FLOAT) ? ZIMG_PIXEL_FLOAT : odesc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
871+ s->alpha_dst_format.pixel_type = (odesc->flags & AV_PIX_FMT_FLAG_FLOAT) ? (odesc->comp[0].depth > 16 ? ZIMG_PIXEL_FLOAT : ZIMG_PIXEL_HALF)
872+ : (odesc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE);
869873 s->alpha_dst_format.color_family = ZIMG_COLOR_GREY;
870874 }
871875
@@ -909,8 +913,14 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 37 unmodified lines
909913 if ((!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) && (odesc->flags & AV_PIX_FMT_FLAG_ALPHA) ){
910914 int x, y;
911915 if (odesc->flags & AV_PIX_FMT_FLAG_FLOAT) {
916+ const uint16_t h_one = 0x3C00; // float2half(1.0f)
912917 for (y = 0; y < out->height; y++) {
913918 const ptrdiff_t row = y * out->linesize[3];
919+ if (odesc->comp[0].depth == 16)
920+ for (x = 0; x < out->width; x++) {
921+ AV_WN16(out->data[3] + x * odesc->comp[3].step + row, h_one);
922+ }
923+ else
914924 for (x = 0; x < out->width; x++) {
915925 AV_WN32(out->data[3] + x * odesc->comp[3].step + row,
916926 av_float2int(1.0f));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t