This has the downside of requiring these tables to be recomputed on every init, but saves ~270 kB of static data.
Unified · Split
| @@ -951,29 +951,42 @@ static int fill_xyztables(SwsInternal *c) · 950 unmodified lines | ||
| 951 | 951 | {1689, 1464, 739}, |
| 952 | 952 | { 871, 2929, 296}, |
| 953 | 953 | { 79, 488, 3891} }; |
| 954 | +#if !CONFIG_SMALL | |
| 954 | 955 | static uint16_t xyzgamma_tab[4096], rgbgammainv_tab[4096]; |
| 955 | 956 | static uint16_t rgbgamma_tab[65536], xyzgammainv_tab[65536]; |
| 957 | +#endif | |
| 958 | + if (c->xyzgamma) | |
| 959 | + return 0; | |
| 956 | 960 | |
| 957 | 961 | memcpy(c->xyz2rgb_matrix, xyz2rgb_matrix, sizeof(c->xyz2rgb_matrix)); |
| 958 | 962 | memcpy(c->rgb2xyz_matrix, rgb2xyz_matrix, sizeof(c->rgb2xyz_matrix)); |
| 963 | + | |
| 964 | +#if CONFIG_SMALL | |
| 965 | + c->xyzgamma = av_malloc(sizeof(uint16_t) * 2 * (4096 + 65536)); | |
| 966 | + if (!c->xyzgamma) | |
| 967 | + return AVERROR(ENOMEM); | |
| 968 | + c->rgbgammainv = c->xyzgamma + 4096; | |
| 969 | + c->rgbgamma = c->rgbgammainv + 4096; | |
| 970 | + c->xyzgammainv = c->rgbgamma + 65536; | |
| 971 | +#else | |
| 959 | 972 | c->xyzgamma = xyzgamma_tab; |
| 960 | 973 | c->rgbgamma = rgbgamma_tab; |
| 961 | 974 | c->xyzgammainv = xyzgammainv_tab; |
| 962 | 975 | c->rgbgammainv = rgbgammainv_tab; |
| 963 | − | |
| 964 | 976 | if (xyzgamma_tab[4095]) |
| 965 | 977 | return 0; |
| 978 | +#endif | |
| 966 | 979 | |
| 967 | 980 | /* set input gamma vectors */ |
| 968 | 981 | for (i = 0; i < 4096; i++) { |
| 969 | − xyzgamma_tab[i] = lrint(pow(i / 4095.0, xyzgamma) * 65535.0); | |
| 970 | − rgbgammainv_tab[i] = lrint(pow(i / 4095.0, rgbgammainv) * 65535.0); | |
| 982 | + c->xyzgamma[i] = lrint(pow(i / 4095.0, xyzgamma) * 65535.0); | |
| 983 | + c->rgbgammainv[i] = lrint(pow(i / 4095.0, rgbgammainv) * 65535.0); | |
| 971 | 984 | } |
| 972 | 985 | |
| 973 | 986 | /* set output gamma vectors */ |
| 974 | 987 | for (i = 0; i < 65536; i++) { |
| 975 | − rgbgamma_tab[i] = lrint(pow(i / 65535.0, rgbgamma) * 4095.0); | |
| 976 | − xyzgammainv_tab[i] = lrint(pow(i / 65535.0, xyzgammainv) * 4095.0); | |
| 988 | + c->rgbgamma[i] = lrint(pow(i / 65535.0, rgbgamma) * 4095.0); | |
| 989 | + c->xyzgammainv[i] = lrint(pow(i / 65535.0, xyzgammainv) * 4095.0); | |
| 977 | 990 | } |
| 978 | 991 | return 0; |
| 979 | 992 | } |
| @@ -2529,6 +2542,9 @@ void sws_freeContext(SwsContext *sws) · 1549 unmodified lines | ||
| 2529 | 2542 | |
| 2530 | 2543 | av_freep(&c->gamma); |
| 2531 | 2544 | av_freep(&c->inv_gamma); |
| 2545 | +#if CONFIG_SMALL | |
| 2546 | + av_freep(&c->xyzgamma); | |
| 2547 | +#endif | |
| 2532 | 2548 | |
| 2533 | 2549 | av_freep(&c->rgb0_scratch); |
| 2534 | 2550 | av_freep(&c->xyz_scratch); |