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