ffmpeg | branch: master | Niklas Haas <g...@haasn.dev> | Mon Dec 23 13:21:21 2024 +0100| [59258fb90ee0cff10c3668374dbbb13edbdac86c] | committer: Niklas Haas
swscale/utils: lazily allocate XYZ tables on CONFIG_SMALL This has the downside of requiring these tables to be recomputed on every init, but saves ~270 kB of static data. Signed-off-by: Niklas Haas <g...@haasn.dev> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=59258fb90ee0cff10c3668374dbbb13edbdac86c --- libswscale/utils.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/libswscale/utils.c b/libswscale/utils.c index 82bb93e184..10b1f0701a 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -951,29 +951,42 @@ static int fill_xyztables(SwsInternal *c) {1689, 1464, 739}, { 871, 2929, 296}, { 79, 488, 3891} }; +#if !CONFIG_SMALL static uint16_t xyzgamma_tab[4096], rgbgammainv_tab[4096]; static uint16_t rgbgamma_tab[65536], xyzgammainv_tab[65536]; +#endif + if (c->xyzgamma) + return 0; memcpy(c->xyz2rgb_matrix, xyz2rgb_matrix, sizeof(c->xyz2rgb_matrix)); memcpy(c->rgb2xyz_matrix, rgb2xyz_matrix, sizeof(c->rgb2xyz_matrix)); + +#if CONFIG_SMALL + c->xyzgamma = av_malloc(sizeof(uint16_t) * 2 * (4096 + 65536)); + if (!c->xyzgamma) + return AVERROR(ENOMEM); + c->rgbgammainv = c->xyzgamma + 4096; + c->rgbgamma = c->rgbgammainv + 4096; + c->xyzgammainv = c->rgbgamma + 65536; +#else c->xyzgamma = xyzgamma_tab; c->rgbgamma = rgbgamma_tab; c->xyzgammainv = xyzgammainv_tab; c->rgbgammainv = rgbgammainv_tab; - if (xyzgamma_tab[4095]) return 0; +#endif /* set input gamma vectors */ for (i = 0; i < 4096; i++) { - xyzgamma_tab[i] = lrint(pow(i / 4095.0, xyzgamma) * 65535.0); - rgbgammainv_tab[i] = lrint(pow(i / 4095.0, rgbgammainv) * 65535.0); + c->xyzgamma[i] = lrint(pow(i / 4095.0, xyzgamma) * 65535.0); + c->rgbgammainv[i] = lrint(pow(i / 4095.0, rgbgammainv) * 65535.0); } /* set output gamma vectors */ for (i = 0; i < 65536; i++) { - rgbgamma_tab[i] = lrint(pow(i / 65535.0, rgbgamma) * 4095.0); - xyzgammainv_tab[i] = lrint(pow(i / 65535.0, xyzgammainv) * 4095.0); + c->rgbgamma[i] = lrint(pow(i / 65535.0, rgbgamma) * 4095.0); + c->xyzgammainv[i] = lrint(pow(i / 65535.0, xyzgammainv) * 4095.0); } return 0; } @@ -2529,6 +2542,9 @@ void sws_freeContext(SwsContext *sws) av_freep(&c->gamma); av_freep(&c->inv_gamma); +#if CONFIG_SMALL + av_freep(&c->xyzgamma); +#endif av_freep(&c->rgb0_scratch); av_freep(&c->xyz_scratch); _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".