History

avfilter/vf_ciescope: little optimizations

Paul B Mahol committed 4 years ago

Commit da4b7c21 parent 8b717a41 file · +167 −137Browse files

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

Unified · Split

libavfilter/vf_ciescope.c+167−137
@@ -62,12 +62,14 @@ typedef struct CiescopeContext { · 61 unmodified lines
62 float contrast;62 float contrast;
63 int background;63 int background;
64 64
65 double log2lin[65536];65 float log2lin[65536];
66 double igamma;66 float igamma;
67 double i[3][3];67 float i[3][3];
68 double m[3][3];68 float m[3][3];
69 AVFrame *f;69 AVFrame *f;
70 void (*filter)(AVFilterContext *ctx, AVFrame *in, double *cx, double *cy, int x, int y);70 void (*filter)(AVFilterContext *ctx, const uint8_t *ptr,
71 ptrdiff_t linesize,
72 float *cx, float *cy, int x, int y);
71} CiescopeContext;73} CiescopeContext;
72 74
73#define OFFSET(x) offsetof(CiescopeContext, x)75#define OFFSET(x) offsetof(CiescopeContext, x)
@@ -163,11 +165,11 @@ static int config_output(AVFilterLink *outlink) · 89 unmodified lines
163 point. */165 point. */
164 166
165struct ColorSystem {167struct ColorSystem {
166 double xRed, yRed, /* Red primary illuminant */168 float xRed, yRed, /* Red primary illuminant */
167 xGreen, yGreen, /* Green primary illuminant */169 xGreen, yGreen, /* Green primary illuminant */
168 xBlue, yBlue, /* Blue primary illuminant */170 xBlue, yBlue, /* Blue primary illuminant */
169 xWhite, yWhite, /* White point */171 xWhite, yWhite, /* White point */
170 gamma; /* gamma of nonlinear correction */172 gamma; /* gamma of nonlinear correction */
171};173};
172 174
173static float const spectral_chromaticity[][3] = {175static float const spectral_chromaticity[][3] = {
@@ -712,23 +714,23 @@ static struct ColorSystem CustomSystem = { · 538 unmodified lines
712*/714*/
713 715
714static void716static void
715uv_to_xy(double const u,717uv_to_xy(float const u,
716 double const v,718 float const v,
717 double * const xc,719 float *const xc,
718 double * const yc)720 float *const yc)
719{721{
720/*722/*
721 Given 1970 coordinates u, v, determine 1931 chromaticities x, y723 Given 1970 coordinates u, v, determine 1931 chromaticities x, y
722*/724*/
723 *xc = 3*u / (2*u - 8*v + 4);725 *xc = 3.f*u / (2.f*u - 8.f*v + 4.f);
724 *yc = 2*v / (2*u - 8*v + 4);726 *yc = 2.f*v / (2.f*u - 8.f*v + 4.f);
725}727}
726 728
727static void729static void
728upvp_to_xy(double const up,730upvp_to_xy(float const up,
729 double const vp,731 float const vp,
730 double * const xc,732 float * const xc,
731 double * const yc)733 float * const yc)
732{734{
733/*735/*
734 Given 1976 coordinates u', v', determine 1931 chromaticities x, y736 Given 1976 coordinates u', v', determine 1931 chromaticities x, y
@@ -738,48 +740,50 @@ upvp_to_xy(double const up, · 3 unmodified lines
738}740}
739 741
740static void742static void
741xy_to_upvp(double xc,743xy_to_upvp(float xc,
742 double yc,744 float yc,
743 double * const up,745 float * const up,
744 double * const vp)746 float * const vp)
745{747{
746/*748/*
747 Given 1931 chromaticities x, y, determine 1976 coordinates u', v'749 Given 1931 chromaticities x, y, determine 1976 coordinates u', v'
748*/750*/
749 *up = 4*xc / (- 2*xc + 12*yc + 3);751 const float scale = 1.f / (-2.f*xc + 12.f*yc + 3.f);
750 *vp = 9*yc / (- 2*xc + 12*yc + 3);752 *up = 4.f*xc * scale;
753 *vp = 9.f*yc * scale;
751}754}
752 755
753static void756static void
754xy_to_uv(double xc,757xy_to_uv(float xc,
755 double yc,758 float yc,
756 double * const u,759 float * const u,
757 double * const v)760 float * const v)
758{761{
759/*762/*
760 Given 1931 chromaticities x, y, determine 1960 coordinates u, v763 Given 1931 chromaticities x, y, determine 1960 coordinates u, v
761*/764*/
762 *u = 4*xc / (- 2*xc + 12*yc + 3);765 const float scale = 1.f / (-2.f*xc + 12.f*yc + 3.f);
763 *v = 6*yc / (- 2*xc + 12*yc + 3);766 *u = 4.f*xc * scale;
767 *v = 6.f*yc * scale;
764}768}
765 769
766static void770static void
767xyz_to_rgb(const double m[3][3],771xyz_to_rgb(const float m[3][3],
768 double xc, double yc, double zc,772 float xc, float yc, float zc,
769 double * const r, double * const g, double * const b)773 float * const r, float * const g, float * const b)
770{774{
771 *r = m[0][0]*xc + m[0][1]*yc + m[0][2]*zc;775 *r = m[0][0]*xc + m[0][1]*yc + m[0][2]*zc;
772 *g = m[1][0]*xc + m[1][1]*yc + m[1][2]*zc;776 *g = m[1][0]*xc + m[1][1]*yc + m[1][2]*zc;
773 *b = m[2][0]*xc + m[2][1]*yc + m[2][2]*zc;777 *b = m[2][0]*xc + m[2][1]*yc + m[2][2]*zc;
774}778}
775 779
776static void invert_matrix3x3(double in[3][3], double out[3][3])780static void invert_matrix3x3(float in[3][3], float out[3][3])
777{781{
778 double m00 = in[0][0], m01 = in[0][1], m02 = in[0][2],782 float m00 = in[0][0], m01 = in[0][1], m02 = in[0][2],
779 m10 = in[1][0], m11 = in[1][1], m12 = in[1][2],783 m10 = in[1][0], m11 = in[1][1], m12 = in[1][2],
780 m20 = in[2][0], m21 = in[2][1], m22 = in[2][2];784 m20 = in[2][0], m21 = in[2][1], m22 = in[2][2];
781 int i, j;785 int i, j;
782 double det;786 float det;
783 787
784 out[0][0] = (m11 * m22 - m21 * m12);788 out[0][0] = (m11 * m22 - m21 * m12);
785 out[0][1] = -(m01 * m22 - m21 * m02);789 out[0][1] = -(m01 * m22 - m21 * m02);
@@ -800,9 +804,9 @@ static void invert_matrix3x3(double in[3][3], double out[3][3]) · 14 unmodified lines
800 }804 }
801}805}
802 806
803static void get_rgb2xyz_matrix(struct ColorSystem system, double m[3][3])807static void get_rgb2xyz_matrix(struct ColorSystem system, float m[3][3])
804{808{
805 double S[3], X[4], Z[4];809 float S[3], X[4], Z[4];
806 int i;810 int i;
807 811
808 X[0] = system.xRed / system.yRed;812 X[0] = system.xRed / system.yRed;
@@ -834,31 +838,32 @@ static void get_rgb2xyz_matrix(struct ColorSystem system, double m[3][3]) · 25 unmodified lines
834}838}
835 839
836static void840static void
837rgb_to_xy(double rc,841rgb_to_xy(float rc,
838 double gc,842 float gc,
839 double bc,843 float bc,
840 double * const x,844 float * const x,
841 double * const y,845 float * const y,
842 double * const z,846 float * const z,
843 const double m[3][3])847 const float m[3][3])
844{848{
845 double sum;849 float scale;
846 850
847 *x = m[0][0] * rc + m[0][1] * gc + m[0][2] * bc;851 *x = m[0][0] * rc + m[0][1] * gc + m[0][2] * bc;
848 *y = m[1][0] * rc + m[1][1] * gc + m[1][2] * bc;852 *y = m[1][0] * rc + m[1][1] * gc + m[1][2] * bc;
849 *z = m[2][0] * rc + m[2][1] * gc + m[2][2] * bc;853 *z = m[2][0] * rc + m[2][1] * gc + m[2][2] * bc;
850 854
851 sum = *x + *y + *z;855 scale = *x + *y + *z;
852 if (sum == 0)856 if (scale == 0.f)
853 sum = 1;857 scale = 1.f;
854 *x = *x / sum;858 scale = 1.f / scale;
855 *y = *y / sum;859 *x = *x * scale;
860 *y = *y * scale;
856}861}
857 862
858static int863static int
859constrain_rgb(double * const r,864constrain_rgb(float * const r,
860 double * const g,865 float * const g,
861 double * const b)866 float * const b)
862{867{
863/*----------------------------------------------------------------------------868/*----------------------------------------------------------------------------
864 If the requested RGB shade contains a negative weight for one of869 If the requested RGB shade contains a negative weight for one of
@@ -866,7 +871,7 @@ constrain_rgb(double * const r, · 1 unmodified line
866 the given triple of primaries. Desaturate it by adding white,871 the given triple of primaries. Desaturate it by adding white,
867 equal quantities of R, G, and B, enough to make RGB all positive.872 equal quantities of R, G, and B, enough to make RGB all positive.
868-----------------------------------------------------------------------------*/873-----------------------------------------------------------------------------*/
869 double w;874 float w;
870 875
871 /* Amount of white needed is w = - min(0, *r, *g, *b) */876 /* Amount of white needed is w = - min(0, *r, *g, *b) */
872 w = (0 < *r) ? 0 : *r;877 w = (0 < *r) ? 0 : *r;
@@ -886,7 +891,7 @@ constrain_rgb(double * const r, · 13 unmodified lines
886 891
887static void892static void
888gamma_correct(const struct ColorSystem * const cs,893gamma_correct(const struct ColorSystem * const cs,
889 double * const c)894 float * const c)
890{895{
891/*----------------------------------------------------------------------------896/*----------------------------------------------------------------------------
892 Transform linear RGB values to nonlinear RGB values.897 Transform linear RGB values to nonlinear RGB values.
@@ -899,8 +904,8 @@ gamma_correct(const struct ColorSystem * const cs, · 6 unmodified lines
899 http://www.inforamp.net/~poynton/ColorFAQ.html904 http://www.inforamp.net/~poynton/ColorFAQ.html
900 http://www.inforamp.net/~poynton/GammaFAQ.html905 http://www.inforamp.net/~poynton/GammaFAQ.html
901-----------------------------------------------------------------------------*/906-----------------------------------------------------------------------------*/
902 double gamma;907 float gamma;
903 double cc;908 float cc;
904 909
905 gamma = cs->gamma;910 gamma = cs->gamma;
906 911
@@ -922,9 +927,9 @@ gamma_correct(const struct ColorSystem * const cs, · 15 unmodified lines
922 927
923static void928static void
924gamma_correct_rgb(const struct ColorSystem * const cs,929gamma_correct_rgb(const struct ColorSystem * const cs,
925 double * const r,930 float * const r,
926 double * const g,931 float * const g,
927 double * const b)932 float * const b)
928{933{
929 gamma_correct(cs, r);934 gamma_correct(cs, r);
930 gamma_correct(cs, g);935 gamma_correct(cs, g);
@@ -938,24 +943,24 @@ gamma_correct_rgb(const struct ColorSystem * const cs, · 7 unmodified lines
938#define Sz(x) (((x) * (int)FFMIN(w, h)) / 512)943#define Sz(x) (((x) * (int)FFMIN(w, h)) / 512)
939 944
940static void945static void
941monochrome_color_location(double waveLength, int w, int h,946monochrome_color_location(float waveLength, int w, int h,
942 int cie, int *xP, int *yP)947 int cie, int *xP, int *yP)
943{948{
944 const int ix = waveLength - 360;949 const int ix = waveLength - 360;
945 const double pX = spectral_chromaticity[ix][0];950 const float pX = spectral_chromaticity[ix][0];
946 const double pY = spectral_chromaticity[ix][1];951 const float pY = spectral_chromaticity[ix][1];
947 const double pZ = spectral_chromaticity[ix][2];952 const float pZ = spectral_chromaticity[ix][2];
948 const double px = pX / (pX + pY + pZ);953 const float px = pX / (pX + pY + pZ);
949 const double py = pY / (pX + pY + pZ);954 const float py = pY / (pX + pY + pZ);
950 955
951 if (cie == LUV) {956 if (cie == LUV) {
952 double up, vp;957 float up, vp;
953 958
954 xy_to_upvp(px, py, &up, &vp);959 xy_to_upvp(px, py, &up, &vp);
955 *xP = up * (w - 1);960 *xP = up * (w - 1);
956 *yP = (h - 1) - vp * (h - 1);961 *yP = (h - 1) - vp * (h - 1);
957 } else if (cie == UCS) {962 } else if (cie == UCS) {
958 double u, v;963 float u, v;
959 964
960 xy_to_uv(px, py, &u, &v);965 xy_to_uv(px, py, &u, &v);
961 *xP = u * (w - 1);966 *xP = u * (w - 1);
@@ -1099,7 +1104,7 @@ fill_in_tongue(uint16_t* const pixels, · 137 unmodified lines
1099 int const h,1104 int const h,
1100 uint16_t const maxval,1105 uint16_t const maxval,
1101 const struct ColorSystem * const cs,1106 const struct ColorSystem * const cs,
1102 double const m[3][3],1107 float const m[3][3],
1103 int const cie,1108 int const cie,
1104 int const correct_gamma,1109 int const correct_gamma,
1105 float const contrast)1110 float const contrast)
@@ -1122,24 +1127,24 @@ fill_in_tongue(uint16_t* const pixels, · 16 unmodified lines
1122 int x;1127 int x;
1123 1128
1124 for (x = leftEdge; x <= rightEdge; ++x) {1129 for (x = leftEdge; x <= rightEdge; ++x) {
1125 double cx, cy, cz, jr, jg, jb, jmax;1130 float cx, cy, cz, jr, jg, jb, jmax;
1126 int r, g, b, mx = maxval;1131 int r, g, b, mx = maxval;
1127 1132
1128 if (cie == LUV) {1133 if (cie == LUV) {
1129 double up, vp;1134 float up, vp;
1130 up = ((double) x) / (w - 1);1135 up = ((float) x) / (w - 1);
1131 vp = 1.0 - ((double) y) / (h - 1);1136 vp = 1.0 - ((float) y) / (h - 1);
1132 upvp_to_xy(up, vp, &cx, &cy);1137 upvp_to_xy(up, vp, &cx, &cy);
1133 cz = 1.0 - (cx + cy);1138 cz = 1.0 - (cx + cy);
1134 } else if (cie == UCS) {1139 } else if (cie == UCS) {
1135 double u, v;1140 float u, v;
1136 u = ((double) x) / (w - 1);1141 u = ((float) x) / (w - 1);
1137 v = 1.0 - ((double) y) / (h - 1);1142 v = 1.0 - ((float) y) / (h - 1);
1138 uv_to_xy(u, v, &cx, &cy);1143 uv_to_xy(u, v, &cx, &cy);
1139 cz = 1.0 - (cx + cy);1144 cz = 1.0 - (cx + cy);
1140 } else if (cie == XYY) {1145 } else if (cie == XYY) {
1141 cx = ((double) x) / (w - 1);1146 cx = ((float) x) / (w - 1);
1142 cy = 1.0 - ((double) y) / (h - 1);1147 cy = 1.0 - ((float) y) / (h - 1);
1143 cz = 1.0 - (cx + cy);1148 cz = 1.0 - (cx + cy);
1144 } else {1149 } else {
1145 av_assert0(0);1150 av_assert0(0);
@@ -1189,12 +1194,12 @@ plot_white_point(uint16_t* pixels, · 43 unmodified lines
1189 int wx, wy;1194 int wx, wy;
1190 1195
1191 if (cie == LUV) {1196 if (cie == LUV) {
1192 double wup, wvp;1197 float wup, wvp;
1193 xy_to_upvp(cs->xWhite, cs->yWhite, &wup, &wvp);1198 xy_to_upvp(cs->xWhite, cs->yWhite, &wup, &wvp);
1194 wx = (w - 1) * wup;1199 wx = (w - 1) * wup;
1195 wy = (h - 1) - ((int) ((h - 1) * wvp));1200 wy = (h - 1) - ((int) ((h - 1) * wvp));
1196 } else if (cie == UCS) {1201 } else if (cie == UCS) {
1197 double wu, wv;1202 float wu, wv;
1198 xy_to_uv(cs->xWhite, cs->yWhite, &wu, &wv);1203 xy_to_uv(cs->xWhite, cs->yWhite, &wu, &wv);
1199 wx = (w - 1) * wu;1204 wx = (w - 1) * wu;
1200 wy = (h - 1) - ((int) ((h - 1) * wv));1205 wy = (h - 1) - ((int) ((h - 1) * wv));
@@ -1234,68 +1239,82 @@ static int draw_background(AVFilterContext *ctx) · 33 unmodified lines
1234 1239
1235 tongue_outline(pixels, s->f->linesize[0] / 2, w, h, 65535, s->cie);1240 tongue_outline(pixels, s->f->linesize[0] / 2, w, h, 65535, s->cie);
1236 1241
1237 fill_in_tongue(pixels, s->f->linesize[0] / 2, w, h, 65535, cs, (const double (*)[3])s->i, s->cie,1242 fill_in_tongue(pixels, s->f->linesize[0] / 2, w, h, 65535, cs, (const float (*)[3])s->i, s->cie,
1238 s->correct_gamma, s->contrast);1243 s->correct_gamma, s->contrast);
1239 1244
1240 return 0;1245 return 0;
1241}1246}
1242 1247
1243static void filter_rgb48(AVFilterContext *ctx, AVFrame *in, double *cx, double *cy, int x, int y)1248static void filter_rgb48(AVFilterContext *ctx, const uint8_t *ptr,
1249 ptrdiff_t linesize,
1250 float *cx, float *cy, int x, int y)
1244{1251{
1245 CiescopeContext *s = ctx->priv;1252 CiescopeContext *s = ctx->priv;
1246 const uint16_t* src = (const uint16_t*)(in->data[0] + in->linesize[0] * y + x * 6);1253 const float scale = 1. / 65535.;
1247 double r = src[0] / 65535.;1254 const uint16_t *src = (const uint16_t*)(ptr + linesize * y + x * 6);
1248 double g = src[1] / 65535.;1255 float r = src[0] * scale;
1249 double b = src[2] / 65535.;1256 float g = src[1] * scale;
1250 double cz;1257 float b = src[2] * scale;
1251 1258 float cz;
1252 rgb_to_xy(r, g, b, cx, cy, &cz, (const double (*)[3])s->m);1259
1260 rgb_to_xy(r, g, b, cx, cy, &cz, (const float (*)[3])s->m);
1253}1261}
1254 1262
1255static void filter_rgba64(AVFilterContext *ctx, AVFrame *in, double *cx, double *cy, int x, int y)1263static void filter_rgba64(AVFilterContext *ctx, const uint8_t *ptr,
1264 ptrdiff_t linesize,
1265 float *cx, float *cy, int x, int y)
1256{1266{
1257 CiescopeContext *s = ctx->priv;1267 CiescopeContext *s = ctx->priv;
1258 const uint16_t* src = (const uint16_t*)(in->data[0] + in->linesize[0] * y + x * 8);1268 const float scale = 1. / 65535.;
1259 double r = src[0] / 65535.;1269 const uint16_t *src = (const uint16_t*)(ptr + linesize * y + x * 8);
1260 double g = src[1] / 65535.;1270 float r = src[0] * scale;
1261 double b = src[2] / 65535.;1271 float g = src[1] * scale;
1262 double cz;1272 float b = src[2] * scale;
1263 1273 float cz;
1264 rgb_to_xy(r, g, b, cx, cy, &cz, (const double (*)[3])s->m);1274
1275 rgb_to_xy(r, g, b, cx, cy, &cz, (const float (*)[3])s->m);
1265}1276}
1266 1277
1267static void filter_rgb24(AVFilterContext *ctx, AVFrame *in, double *cx, double *cy, int x, int y)1278static void filter_rgb24(AVFilterContext *ctx, const uint8_t *ptr,
1279 ptrdiff_t linesize,
1280 float *cx, float *cy, int x, int y)
1268{1281{
1269 CiescopeContext *s = ctx->priv;1282 CiescopeContext *s = ctx->priv;
1270 const uint8_t* src = in->data[0] + in->linesize[0] * y + x * 3;1283 const float scale = 1. / 255.;
1271 double r = src[0] / 255.;1284 const uint8_t *src = ptr + linesize * y + x * 3;
1272 double g = src[1] / 255.;1285 float r = src[0] * scale;
1273 double b = src[2] / 255.;1286 float g = src[1] * scale;
1274 double cz;1287 float b = src[2] * scale;
1275 1288 float cz;
1276 rgb_to_xy(r, g, b, cx, cy, &cz, (const double (*)[3])s->m);1289
1290 rgb_to_xy(r, g, b, cx, cy, &cz, (const float (*)[3])s->m);
1277}1291}
1278 1292
1279static void filter_rgba(AVFilterContext *ctx, AVFrame *in, double *cx, double *cy, int x, int y)1293static void filter_rgba(AVFilterContext *ctx, const uint8_t *ptr,
1294 ptrdiff_t linesize,
1295 float *cx, float *cy, int x, int y)
1280{1296{
1281 CiescopeContext *s = ctx->priv;1297 CiescopeContext *s = ctx->priv;
1282 const uint8_t* src = in->data[0] + in->linesize[0] * y + x * 4;1298 const float scale = 1. / 255.;
1283 double r = src[0] / 255.;1299 const uint8_t *src = ptr + linesize * y + x * 4;
1284 double g = src[1] / 255.;1300 float r = src[0] * scale;
1285 double b = src[2] / 255.;1301 float g = src[1] * scale;
1286 double cz;1302 float b = src[2] * scale;
1287 1303 float cz;
1288 rgb_to_xy(r, g, b, cx, cy, &cz, (const double (*)[3])s->m);1304
1305 rgb_to_xy(r, g, b, cx, cy, &cz, (const float (*)[3])s->m);
1289}1306}
1290 1307
1291static void filter_xyz(AVFilterContext *ctx, AVFrame *in, double *cx, double *cy, int x, int y)1308static void filter_xyz(AVFilterContext *ctx, const uint8_t *ptr,
1309 ptrdiff_t linesize,
1310 float *cx, float *cy, int x, int y)
1292{1311{
1293 CiescopeContext *s = ctx->priv;1312 CiescopeContext *s = ctx->priv;
1294 const uint16_t* src = (uint16_t *)(in->data[0] + in->linesize[0] * y + x * 6);1313 const uint16_t* src = (uint16_t *)(ptr + linesize * y + x * 6);
1295 double lx = s->log2lin[src[0]];1314 float lx = s->log2lin[src[0]];
1296 double ly = s->log2lin[src[1]];1315 float ly = s->log2lin[src[1]];
1297 double lz = s->log2lin[src[2]];1316 float lz = s->log2lin[src[2]];
1298 double sum = lx + ly + lz;1317 float sum = lx + ly + lz;
1299 1318
1300 if (sum == 0)1319 if (sum == 0)
1301 sum = 1;1320 sum = 1;
@@ -1315,7 +1334,7 @@ static void plot_gamuts(uint16_t *pixels, int linesize, int w, int h, · 13 unmodified lines
1315 if (!((1 << i) & gamuts))1334 if (!((1 << i) & gamuts))
1316 continue;1335 continue;
1317 if (cie == LUV) {1336 if (cie == LUV) {
1318 double wup, wvp;1337 float wup, wvp;
1319 xy_to_upvp(cs->xRed, cs->yRed, &wup, &wvp);1338 xy_to_upvp(cs->xRed, cs->yRed, &wup, &wvp);
1320 rx = (w - 1) * wup;1339 rx = (w - 1) * wup;
1321 ry = (h - 1) - ((int) ((h - 1) * wvp));1340 ry = (h - 1) - ((int) ((h - 1) * wvp));
@@ -1326,7 +1345,7 @@ static void plot_gamuts(uint16_t *pixels, int linesize, int w, int h, · 4 unmodified lines
1326 bx = (w - 1) * wup;1345 bx = (w - 1) * wup;
1327 by = (h - 1) - ((int) ((h - 1) * wvp));1346 by = (h - 1) - ((int) ((h - 1) * wvp));
1328 } else if (cie == UCS) {1347 } else if (cie == UCS) {
1329 double wu, wv;1348 float wu, wv;
1330 xy_to_uv(cs->xRed, cs->yRed, &wu, &wv);1349 xy_to_uv(cs->xRed, cs->yRed, &wu, &wv);
1331 rx = (w - 1) * wu;1350 rx = (w - 1) * wu;
1332 ry = (h - 1) - ((int) ((h - 1) * wv));1351 ry = (h - 1) - ((int) ((h - 1) * wv));
@@ -1384,37 +1403,48 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 51 unmodified lines
1384 }1403 }
1385 1404
1386 for (y = 0; y < in->height; y++) {1405 for (y = 0; y < in->height; y++) {
1406 const uint8_t *src = in->data[0];
1407 const ptrdiff_t src_linesize = in->linesize[0];
1408 uint16_t *dst = (uint16_t *)out->data[0];
1409 const ptrdiff_t linesize = out->linesize[0] / 2;
1410 const int w_1 = w - 1;
1411 const int h_1 = h - 1;
1412
1387 for (x = 0; x < in->width; x++) {1413 for (x = 0; x < in->width; x++) {
1388 double cx, cy;1414 float cx, cy;
1389 uint16_t *dst;1415 int wx, wy, pos;
1390 int wx, wy;1416 int r, g, b;
1391 1417
1392 s->filter(ctx, in, &cx, &cy, x, y);1418 s->filter(ctx, src, src_linesize, &cx, &cy, x, y);
1393 1419
1394 if (s->cie == LUV) {1420 if (s->cie == LUV) {
1395 double up, vp;1421 float up, vp;
1396 xy_to_upvp(cx, cy, &up, &vp);1422 xy_to_upvp(cx, cy, &up, &vp);
1397 cx = up;1423 cx = up;
1398 cy = vp;1424 cy = vp;
1399 } else if (s->cie == UCS) {1425 } else if (s->cie == UCS) {
1400 double u, v;1426 float u, v;
1401 xy_to_uv(cx, cy, &u, &v);1427 xy_to_uv(cx, cy, &u, &v);
1402 cx = u;1428 cx = u;
1403 cy = v;1429 cy = v;
1404 }1430 }
1405 1431
1406 wx = (w - 1) * cx;1432 wx = w_1 * cx;
1407 wy = (h - 1) - ((h - 1) * cy);1433 wy = h_1 - h_1 * cy;
1408 1434
1409 if (wx < 0 || wx >= w ||1435 if (wx < 0 || wx >= w ||
1410 wy < 0 || wy >= h)1436 wy < 0 || wy >= h)
1411 continue;1437 continue;
1412 1438
1413 dst = (uint16_t *)(out->data[0] + wy * out->linesize[0] + wx * 8 + 0);1439 pos = wy * linesize + wx * 4;
1414 dst[0] = FFMIN(dst[0] + i, 65535);1440 r = dst[pos + 0] + i;
1415 dst[1] = FFMIN(dst[1] + i, 65535);1441 g = dst[pos + 1] + i;
1416 dst[2] = FFMIN(dst[2] + i, 65535);1442 b = dst[pos + 2] + i;
1417 dst[3] = 65535;1443
1444 dst[pos + 0] = FFMIN(r, 65535);
1445 dst[pos + 1] = FFMIN(g, 65535);
1446 dst[pos + 2] = FFMIN(b, 65535);
1447 dst[pos + 3] = 65535;
1418 }1448 }
1419 }1449 }
1420 1450

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