@@ -1645,20 +1645,6 @@ gpujpeg_reader_read_image(struct gpujpeg_decoder* decoder, uint8_t* image, size_
16451645 return 0 ;
16461646}
16471647
1648- static int
1649- gcd (int a , int b )
1650- {
1651- assert (b != 0 );
1652- int c = a % b ;
1653- while (c != 0 ) {
1654- a = b ;
1655- b = c ;
1656- c = a % b ;
1657- }
1658-
1659- return (b );
1660- }
1661-
16621648/* Documented at declaration */
16631649int
16641650gpujpeg_reader_get_image_info (uint8_t * image , size_t image_size , struct gpujpeg_image_info * info , int verbose , unsigned flags )
@@ -1671,6 +1657,7 @@ gpujpeg_reader_get_image_info(uint8_t *image, size_t image_size, struct gpujpeg_
16711657
16721658 struct gpujpeg_reader reader = {
16731659 .param .verbose = verbose ,
1660+ .param_image .pixel_format = GPUJPEG_PIXFMT_AUTODETECT ,
16741661 .image_end = image + image_size ,
16751662 };
16761663
@@ -1784,58 +1771,11 @@ gpujpeg_reader_get_image_info(uint8_t *image, size_t image_size, struct gpujpeg_
17841771
17851772 info -> param = reader .param ;
17861773 info -> param_image = reader .param_image ;
1787- info -> param_image .pixel_format = GPUJPEG_PIXFMT_NONE ;
17881774 info -> segment_count = segments ;
17891775 info -> header_type = reader .header_type ;
17901776 info -> comment = reader .comment ;
17911777 info -> metadata = reader .metadata ;
17921778
1793- if ( info -> param .comp_count == 1 ) {
1794- info -> param_image .pixel_format = GPUJPEG_U8 ;
1795- }
1796- if ( info -> param .comp_count == 3 ) {
1797- // reduce [2, 2; 1, 2; 1, 2] (FFmpeg) to [2, 1; 1, 1; 1, 1]
1798- int horizontal_gcd = info -> param .sampling_factor [0 ].horizontal ;
1799- int vertical_gcd = info -> param .sampling_factor [0 ].vertical ;
1800- for (int i = 1 ; i < 3 ; ++ i ) {
1801- horizontal_gcd = gcd (horizontal_gcd , info -> param .sampling_factor [i ].horizontal );
1802- vertical_gcd = gcd (vertical_gcd , info -> param .sampling_factor [i ].vertical );
1803- }
1804- for (int i = 0 ; i < 3 ; ++ i ) {
1805- info -> param .sampling_factor [i ].horizontal /= horizontal_gcd ;
1806- info -> param .sampling_factor [i ].vertical /= vertical_gcd ;
1807- }
1808-
1809- if (info -> param .sampling_factor [1 ].horizontal == 1 && info -> param .sampling_factor [1 ].vertical == 1
1810- && info -> param .sampling_factor [2 ].horizontal == 1 && info -> param .sampling_factor [2 ].vertical == 1 ) {
1811- int sum = info -> param .interleaved << 16 | info -> param .sampling_factor [0 ].horizontal << 8 |
1812- info -> param .sampling_factor [0 ].vertical ; // NOLINT
1813- switch (sum ) {
1814- case 1 <<16 | 1 <<8 | 1 : info -> param_image .pixel_format = GPUJPEG_444_U8_P012 ; break ; // NOLINT
1815- case 0 <<16 | 1 <<8 | 1 : info -> param_image .pixel_format = GPUJPEG_444_U8_P0P1P2 ; break ; // NOLINT
1816- case 1 <<16 | 2 <<8 | 1 : info -> param_image .pixel_format = GPUJPEG_422_U8_P1020 ; break ; // NOLINT
1817- case 0 <<16 | 2 <<8 | 1 : info -> param_image .pixel_format = GPUJPEG_422_U8_P0P1P2 ; break ; // NOLINT
1818- case 1 <<16 | 2 <<8 | 2 : // we have only one pixfmt for 420, so use for both NOLINT
1819- case 0 <<16 | 2 <<8 | 2 : info -> param_image .pixel_format = GPUJPEG_420_U8_P0P1P2 ; break ; // NOLINT
1820- default : break ;
1821- }
1822- }
1823- }
1824-
1825- if ( info -> param .comp_count == 4 ) {
1826- _Bool subsampling_is4444 = 1 ;
1827- for (int i = 1 ; i < 4 ; ++ i ) {
1828- if (info -> param .sampling_factor [i ].horizontal != info -> param .sampling_factor [0 ].horizontal
1829- || info -> param .sampling_factor [i ].vertical != info -> param .sampling_factor [0 ].vertical ) {
1830- subsampling_is4444 = 0 ;
1831- break ;
1832- }
1833- }
1834- if (subsampling_is4444 ) {
1835- info -> param_image .pixel_format = GPUJPEG_4444_U8_P0123 ;
1836- }
1837- }
1838-
18391779 return 0 ;
18401780}
18411781
0 commit comments