@@ -1733,123 +1733,30 @@ prepare_JPEGTables(TIFF* tif)
1733
1733
return (1 );
1734
1734
}
1735
1735
1736
- #if BITS_IN_JSAMPLE == 8
1737
- /* The two below functions are borrowed to libjpeg, and work around a
1738
- * bug of libjpeg-9d that no longer initializes default Huffman tables
1739
- * in jpeg_set_defaults(). */
1740
-
1741
- /*
1742
- * Huffman table setup routines
1743
- */
1744
-
1745
- static void
1746
- TIFF_add_huff_table (j_compress_ptr cinfo ,
1747
- JHUFF_TBL * * htblptr , const UINT8 * bits , const UINT8 * val )
1748
- /* Define a Huffman table */
1749
- {
1750
- int nsymbols , len ;
1751
-
1752
- assert (* htblptr == NULL );
1753
- * htblptr = jpeg_alloc_huff_table ((j_common_ptr ) cinfo );
1754
-
1755
- /* Copy the number-of-symbols-of-each-code-length counts */
1756
- memcpy ((* htblptr )-> bits , bits , sizeof ((* htblptr )-> bits ));
1757
-
1758
- nsymbols = 0 ;
1759
- for (len = 1 ; len <= 16 ; len ++ )
1760
- nsymbols += bits [len ];
1761
-
1762
- memcpy ((* htblptr )-> huffval , val , nsymbols );
1763
-
1764
- /* Initialize sent_table FALSE so table will be written to JPEG file. */
1765
- (* htblptr )-> sent_table = FALSE;
1766
- }
1767
-
1768
-
1736
+ #if defined(JPEG_LIB_VERSION_MAJOR ) && (JPEG_LIB_VERSION_MAJOR > 9 || \
1737
+ (JPEG_LIB_VERSION_MAJOR == 9 && JPEG_LIB_VERSION_MINOR >= 4 ))
1738
+ /* This is a modified version of std_huff_tables() from jcparam.c
1739
+ * in libjpeg-9d because it no longer initializes default Huffman
1740
+ * tables in jpeg_set_defaults(). */
1769
1741
static void
1770
1742
TIFF_std_huff_tables (j_compress_ptr cinfo )
1771
- /* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
1772
- /* IMPORTANT: these are only valid for 8-bit data precision! */
1773
- {
1774
- static const UINT8 bits_dc_luminance [17 ] =
1775
- { /* 0-base */ 0 , 0 , 1 , 5 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
1776
- static const UINT8 val_dc_luminance [] =
1777
- { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 };
1778
-
1779
- static const UINT8 bits_dc_chrominance [17 ] =
1780
- { /* 0-base */ 0 , 0 , 3 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 };
1781
- static const UINT8 val_dc_chrominance [] =
1782
- { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 };
1783
-
1784
- static const UINT8 bits_ac_luminance [17 ] =
1785
- { /* 0-base */ 0 , 0 , 2 , 1 , 3 , 3 , 2 , 4 , 3 , 5 , 5 , 4 , 4 , 0 , 0 , 1 , 0x7d };
1786
- static const UINT8 val_ac_luminance [] =
1787
- { 0x01 , 0x02 , 0x03 , 0x00 , 0x04 , 0x11 , 0x05 , 0x12 ,
1788
- 0x21 , 0x31 , 0x41 , 0x06 , 0x13 , 0x51 , 0x61 , 0x07 ,
1789
- 0x22 , 0x71 , 0x14 , 0x32 , 0x81 , 0x91 , 0xa1 , 0x08 ,
1790
- 0x23 , 0x42 , 0xb1 , 0xc1 , 0x15 , 0x52 , 0xd1 , 0xf0 ,
1791
- 0x24 , 0x33 , 0x62 , 0x72 , 0x82 , 0x09 , 0x0a , 0x16 ,
1792
- 0x17 , 0x18 , 0x19 , 0x1a , 0x25 , 0x26 , 0x27 , 0x28 ,
1793
- 0x29 , 0x2a , 0x34 , 0x35 , 0x36 , 0x37 , 0x38 , 0x39 ,
1794
- 0x3a , 0x43 , 0x44 , 0x45 , 0x46 , 0x47 , 0x48 , 0x49 ,
1795
- 0x4a , 0x53 , 0x54 , 0x55 , 0x56 , 0x57 , 0x58 , 0x59 ,
1796
- 0x5a , 0x63 , 0x64 , 0x65 , 0x66 , 0x67 , 0x68 , 0x69 ,
1797
- 0x6a , 0x73 , 0x74 , 0x75 , 0x76 , 0x77 , 0x78 , 0x79 ,
1798
- 0x7a , 0x83 , 0x84 , 0x85 , 0x86 , 0x87 , 0x88 , 0x89 ,
1799
- 0x8a , 0x92 , 0x93 , 0x94 , 0x95 , 0x96 , 0x97 , 0x98 ,
1800
- 0x99 , 0x9a , 0xa2 , 0xa3 , 0xa4 , 0xa5 , 0xa6 , 0xa7 ,
1801
- 0xa8 , 0xa9 , 0xaa , 0xb2 , 0xb3 , 0xb4 , 0xb5 , 0xb6 ,
1802
- 0xb7 , 0xb8 , 0xb9 , 0xba , 0xc2 , 0xc3 , 0xc4 , 0xc5 ,
1803
- 0xc6 , 0xc7 , 0xc8 , 0xc9 , 0xca , 0xd2 , 0xd3 , 0xd4 ,
1804
- 0xd5 , 0xd6 , 0xd7 , 0xd8 , 0xd9 , 0xda , 0xe1 , 0xe2 ,
1805
- 0xe3 , 0xe4 , 0xe5 , 0xe6 , 0xe7 , 0xe8 , 0xe9 , 0xea ,
1806
- 0xf1 , 0xf2 , 0xf3 , 0xf4 , 0xf5 , 0xf6 , 0xf7 , 0xf8 ,
1807
- 0xf9 , 0xfa };
1808
-
1809
- static const UINT8 bits_ac_chrominance [17 ] =
1810
- { /* 0-base */ 0 , 0 , 2 , 1 , 2 , 4 , 4 , 3 , 4 , 7 , 5 , 4 , 4 , 0 , 1 , 2 , 0x77 };
1811
- static const UINT8 val_ac_chrominance [] =
1812
- { 0x00 , 0x01 , 0x02 , 0x03 , 0x11 , 0x04 , 0x05 , 0x21 ,
1813
- 0x31 , 0x06 , 0x12 , 0x41 , 0x51 , 0x07 , 0x61 , 0x71 ,
1814
- 0x13 , 0x22 , 0x32 , 0x81 , 0x08 , 0x14 , 0x42 , 0x91 ,
1815
- 0xa1 , 0xb1 , 0xc1 , 0x09 , 0x23 , 0x33 , 0x52 , 0xf0 ,
1816
- 0x15 , 0x62 , 0x72 , 0xd1 , 0x0a , 0x16 , 0x24 , 0x34 ,
1817
- 0xe1 , 0x25 , 0xf1 , 0x17 , 0x18 , 0x19 , 0x1a , 0x26 ,
1818
- 0x27 , 0x28 , 0x29 , 0x2a , 0x35 , 0x36 , 0x37 , 0x38 ,
1819
- 0x39 , 0x3a , 0x43 , 0x44 , 0x45 , 0x46 , 0x47 , 0x48 ,
1820
- 0x49 , 0x4a , 0x53 , 0x54 , 0x55 , 0x56 , 0x57 , 0x58 ,
1821
- 0x59 , 0x5a , 0x63 , 0x64 , 0x65 , 0x66 , 0x67 , 0x68 ,
1822
- 0x69 , 0x6a , 0x73 , 0x74 , 0x75 , 0x76 , 0x77 , 0x78 ,
1823
- 0x79 , 0x7a , 0x82 , 0x83 , 0x84 , 0x85 , 0x86 , 0x87 ,
1824
- 0x88 , 0x89 , 0x8a , 0x92 , 0x93 , 0x94 , 0x95 , 0x96 ,
1825
- 0x97 , 0x98 , 0x99 , 0x9a , 0xa2 , 0xa3 , 0xa4 , 0xa5 ,
1826
- 0xa6 , 0xa7 , 0xa8 , 0xa9 , 0xaa , 0xb2 , 0xb3 , 0xb4 ,
1827
- 0xb5 , 0xb6 , 0xb7 , 0xb8 , 0xb9 , 0xba , 0xc2 , 0xc3 ,
1828
- 0xc4 , 0xc5 , 0xc6 , 0xc7 , 0xc8 , 0xc9 , 0xca , 0xd2 ,
1829
- 0xd3 , 0xd4 , 0xd5 , 0xd6 , 0xd7 , 0xd8 , 0xd9 , 0xda ,
1830
- 0xe2 , 0xe3 , 0xe4 , 0xe5 , 0xe6 , 0xe7 , 0xe8 , 0xe9 ,
1831
- 0xea , 0xf2 , 0xf3 , 0xf4 , 0xf5 , 0xf6 , 0xf7 , 0xf8 ,
1832
- 0xf9 , 0xfa };
1743
+ {
1833
1744
1834
1745
if ( cinfo -> dc_huff_tbl_ptrs [0 ] == NULL )
1835
1746
{
1836
- TIFF_add_huff_table (cinfo , & cinfo -> dc_huff_tbl_ptrs [0 ],
1837
- bits_dc_luminance , val_dc_luminance );
1747
+ (void ) jpeg_std_huff_table ((j_common_ptr ) cinfo , TRUE, 0 );
1838
1748
}
1839
1749
if ( cinfo -> ac_huff_tbl_ptrs [0 ] == NULL )
1840
1750
{
1841
- TIFF_add_huff_table (cinfo , & cinfo -> ac_huff_tbl_ptrs [0 ],
1842
- bits_ac_luminance , val_ac_luminance );
1751
+ (void ) jpeg_std_huff_table ((j_common_ptr ) cinfo , FALSE, 0 );
1843
1752
}
1844
1753
if ( cinfo -> dc_huff_tbl_ptrs [1 ] == NULL )
1845
1754
{
1846
- TIFF_add_huff_table (cinfo , & cinfo -> dc_huff_tbl_ptrs [1 ],
1847
- bits_dc_chrominance , val_dc_chrominance );
1755
+ (void ) jpeg_std_huff_table ((j_common_ptr ) cinfo , TRUE, 1 );
1848
1756
}
1849
1757
if ( cinfo -> ac_huff_tbl_ptrs [1 ] == NULL )
1850
1758
{
1851
- TIFF_add_huff_table (cinfo , & cinfo -> ac_huff_tbl_ptrs [1 ],
1852
- bits_ac_chrominance , val_ac_chrominance );
1759
+ (void ) jpeg_std_huff_table ((j_common_ptr ) cinfo , FALSE, 1 );
1853
1760
}
1854
1761
}
1855
1762
#endif
@@ -2024,15 +1931,16 @@ JPEGSetupEncode(TIFF* tif)
2024
1931
if ( sp -> jpegtables == NULL
2025
1932
|| memcmp (sp -> jpegtables ,"\0\0\0\0\0\0\0\0\0" ,8 ) == 0 )
2026
1933
{
2027
- #if BITS_IN_JSAMPLE == 8
1934
+ #if defined(JPEG_LIB_VERSION_MAJOR ) && (JPEG_LIB_VERSION_MAJOR > 9 || \
1935
+ (JPEG_LIB_VERSION_MAJOR == 9 && JPEG_LIB_VERSION_MINOR >= 4 ))
2028
1936
if ( (sp -> jpegtablesmode & JPEGTABLESMODE_HUFF ) != 0 &&
2029
1937
(sp -> cinfo .c .dc_huff_tbl_ptrs [0 ] == NULL ||
2030
1938
sp -> cinfo .c .dc_huff_tbl_ptrs [1 ] == NULL ||
2031
1939
sp -> cinfo .c .ac_huff_tbl_ptrs [0 ] == NULL ||
2032
1940
sp -> cinfo .c .ac_huff_tbl_ptrs [1 ] == NULL ) )
2033
1941
{
2034
1942
/* libjpeg-9d no longer initializes default Huffman tables in */
2035
- /* jpeg_set_defaults(), which is likely a bug. */
1943
+ /* jpeg_set_defaults() */
2036
1944
TIFF_std_huff_tables (& sp -> cinfo .c );
2037
1945
}
2038
1946
#endif
0 commit comments