@@ -692,13 +692,35 @@ static void fill_rgb2yuv_table(SwsInternal *c, const int table[4], int dstRange)
692
692
AV_WL16 (p + 16 * 4 + 2 * i , map [i ] >= 0 ? c -> input_rgb2yuv_table [map [i ]] : 0 );
693
693
}
694
694
695
- static int fill_xyztables (SwsInternal * c )
695
+ #if CONFIG_SMALL
696
+ static void init_xyz_tables (uint16_t xyzgamma_tab [4096 ], uint16_t xyzgammainv_tab [65536 ],
697
+ uint16_t rgbgamma_tab [65536 ], uint16_t rgbgammainv_tab [4096 ])
698
+ #else
699
+ static uint16_t xyzgamma_tab [4096 ], rgbgammainv_tab [4096 ];
700
+ static uint16_t rgbgamma_tab [65536 ], xyzgammainv_tab [65536 ];
701
+ static av_cold void init_xyz_tables (void )
702
+ #endif
696
703
{
697
- int i ;
698
- double xyzgamma = XYZ_GAMMA ;
699
- double rgbgamma = 1.0 / RGB_GAMMA ;
704
+ double xyzgamma = XYZ_GAMMA ;
705
+ double rgbgamma = 1.0 / RGB_GAMMA ;
700
706
double xyzgammainv = 1.0 / XYZ_GAMMA ;
701
707
double rgbgammainv = RGB_GAMMA ;
708
+
709
+ /* set input gamma vectors */
710
+ for (int i = 0 ; i < 4096 ; i ++ ) {
711
+ xyzgamma_tab [i ] = lrint (pow (i / 4095.0 , xyzgamma ) * 65535.0 );
712
+ rgbgammainv_tab [i ] = lrint (pow (i / 4095.0 , rgbgammainv ) * 65535.0 );
713
+ }
714
+
715
+ /* set output gamma vectors */
716
+ for (int i = 0 ; i < 65536 ; i ++ ) {
717
+ rgbgamma_tab [i ] = lrint (pow (i / 65535.0 , rgbgamma ) * 4095.0 );
718
+ xyzgammainv_tab [i ] = lrint (pow (i / 65535.0 , xyzgammainv ) * 4095.0 );
719
+ }
720
+ }
721
+
722
+ static int fill_xyztables (SwsInternal * c )
723
+ {
702
724
static const int16_t xyz2rgb_matrix [3 ][4 ] = {
703
725
{13270 , -6295 , -2041 },
704
726
{-3969 , 7682 , 170 },
@@ -707,10 +729,7 @@ static int fill_xyztables(SwsInternal *c)
707
729
{1689 , 1464 , 739 },
708
730
{ 871 , 2929 , 296 },
709
731
{ 79 , 488 , 3891 } };
710
- #if !CONFIG_SMALL
711
- static uint16_t xyzgamma_tab [4096 ], rgbgammainv_tab [4096 ];
712
- static uint16_t rgbgamma_tab [65536 ], xyzgammainv_tab [65536 ];
713
- #endif
732
+
714
733
if (c -> xyzgamma )
715
734
return 0 ;
716
735
@@ -724,26 +743,16 @@ static int fill_xyztables(SwsInternal *c)
724
743
c -> rgbgammainv = c -> xyzgamma + 4096 ;
725
744
c -> rgbgamma = c -> rgbgammainv + 4096 ;
726
745
c -> xyzgammainv = c -> rgbgamma + 65536 ;
746
+ init_xyz_tables (c -> xyzgamma , c -> xyzgammainv , c -> rgbgamma , c -> rgbgammainv );
727
747
#else
728
748
c -> xyzgamma = xyzgamma_tab ;
729
749
c -> rgbgamma = rgbgamma_tab ;
730
750
c -> xyzgammainv = xyzgammainv_tab ;
731
751
c -> rgbgammainv = rgbgammainv_tab ;
732
- if (xyzgamma_tab [4095 ])
733
- return 0 ;
734
- #endif
735
752
736
- /* set input gamma vectors */
737
- for (i = 0 ; i < 4096 ; i ++ ) {
738
- c -> xyzgamma [i ] = lrint (pow (i / 4095.0 , xyzgamma ) * 65535.0 );
739
- c -> rgbgammainv [i ] = lrint (pow (i / 4095.0 , rgbgammainv ) * 65535.0 );
740
- }
741
-
742
- /* set output gamma vectors */
743
- for (i = 0 ; i < 65536 ; i ++ ) {
744
- c -> rgbgamma [i ] = lrint (pow (i / 65535.0 , rgbgamma ) * 4095.0 );
745
- c -> xyzgammainv [i ] = lrint (pow (i / 65535.0 , xyzgammainv ) * 4095.0 );
746
- }
753
+ static AVOnce xyz_init_static_once = AV_ONCE_INIT ;
754
+ ff_thread_once (& xyz_init_static_once , init_xyz_tables );
755
+ #endif
747
756
return 0 ;
748
757
}
749
758
0 commit comments