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
209 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,209 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
210 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,210 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
211 AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP14, AV_PIX_FMT_GBRAP16,211 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,
212 AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32,213 AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32,
213 AV_PIX_FMT_NONE214 AV_PIX_FMT_NONE
214 };215 };
@@ -582,7 +583,8 @@ static void format_init(zimg_image_format *format, AVFrame *frame, const AVPixFm · 367 unmodified lines
582 format->subsample_w = desc->log2_chroma_w;583 format->subsample_w = desc->log2_chroma_w;
583 format->subsample_h = desc->log2_chroma_h;584 format->subsample_h = desc->log2_chroma_h;
584 format->depth = desc->comp[0].depth;585 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);
586 format->color_family = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_COLOR_RGB : ZIMG_COLOR_YUV;588 format->color_family = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_COLOR_RGB : ZIMG_COLOR_YUV;
587 format->matrix_coefficients = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_MATRIX_RGB : colorspace == -1 ? convert_matrix(frame->colorspace) : colorspace;589 format->matrix_coefficients = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_MATRIX_RGB : colorspace == -1 ? convert_matrix(frame->colorspace) : colorspace;
588 format->color_primaries = primaries == -1 ? convert_primaries(frame->color_primaries) : primaries;590 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
861 s->alpha_src_format.width = in->width;863 s->alpha_src_format.width = in->width;
862 s->alpha_src_format.height = in->height;864 s->alpha_src_format.height = in->height;
863 s->alpha_src_format.depth = desc->comp[0].depth;865 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);
865 s->alpha_src_format.color_family = ZIMG_COLOR_GREY;868 s->alpha_src_format.color_family = ZIMG_COLOR_GREY;
866 869
867 s->alpha_dst_format.depth = odesc->comp[0].depth;870 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);
869 s->alpha_dst_format.color_family = ZIMG_COLOR_GREY;873 s->alpha_dst_format.color_family = ZIMG_COLOR_GREY;
870 }874 }
871 875
@@ -909,8 +913,14 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 37 unmodified lines
909 if ((!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) && (odesc->flags & AV_PIX_FMT_FLAG_ALPHA) ){913 if ((!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) && (odesc->flags & AV_PIX_FMT_FLAG_ALPHA) ){
910 int x, y;914 int x, y;
911 if (odesc->flags & AV_PIX_FMT_FLAG_FLOAT) {915 if (odesc->flags & AV_PIX_FMT_FLAG_FLOAT) {
916 const uint16_t h_one = 0x3C00; // float2half(1.0f)
912 for (y = 0; y < out->height; y++) {917 for (y = 0; y < out->height; y++) {
913 const ptrdiff_t row = y * out->linesize[3];918 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
914 for (x = 0; x < out->width; x++) {924 for (x = 0; x < out->width; x++) {
915 AV_WN32(out->data[3] + x * odesc->comp[3].step + row,925 AV_WN32(out->data[3] + x * odesc->comp[3].step + row,
916 av_float2int(1.0f));926 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