History

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.

Niklas Haas committed 1 year ago

Commit 59258fb1 parent 60bfafc1 file · +21 −5Browse files

Unified · Split

libswscale/utils.c+21−5
@@ -951,29 +951,42 @@ static int fill_xyztables(SwsInternal *c) · 950 unmodified lines
951951 {1689, 1464, 739},
952952 { 871, 2929, 296},
953953 { 79, 488, 3891} };
954+#if !CONFIG_SMALL
954955 static uint16_t xyzgamma_tab[4096], rgbgammainv_tab[4096];
955956 static uint16_t rgbgamma_tab[65536], xyzgammainv_tab[65536];
957+#endif
958+ if (c->xyzgamma)
959+ return 0;
956960
957961 memcpy(c->xyz2rgb_matrix, xyz2rgb_matrix, sizeof(c->xyz2rgb_matrix));
958962 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
959972 c->xyzgamma = xyzgamma_tab;
960973 c->rgbgamma = rgbgamma_tab;
961974 c->xyzgammainv = xyzgammainv_tab;
962975 c->rgbgammainv = rgbgammainv_tab;
963−
964976 if (xyzgamma_tab[4095])
965977 return 0;
978+#endif
966979
967980 /* set input gamma vectors */
968981 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);
971984 }
972985
973986 /* set output gamma vectors */
974987 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);
977990 }
978991 return 0;
979992 }
@@ -2529,6 +2542,9 @@ void sws_freeContext(SwsContext *sws) · 1549 unmodified lines
25292542
25302543 av_freep(&c->gamma);
25312544 av_freep(&c->inv_gamma);
2545+#if CONFIG_SMALL
2546+ av_freep(&c->xyzgamma);
2547+#endif
25322548
25332549 av_freep(&c->rgb0_scratch);
25342550 av_freep(&c->xyz_scratch);

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