13b921b29Sopenharmony_cidiff --git a/cdjpeg.h b/cdjpeg.h
23b921b29Sopenharmony_ciindex 082687c..840cd2d 100644
33b921b29Sopenharmony_ci--- a/cdjpeg.h
43b921b29Sopenharmony_ci+++ b/cdjpeg.h
53b921b29Sopenharmony_ci@@ -103,39 +103,39 @@ typedef struct cdjpeg_progress_mgr *cd_progress_ptr;
63b921b29Sopenharmony_ci 
73b921b29Sopenharmony_ci /* Module selection routines for I/O modules. */
83b921b29Sopenharmony_ci 
93b921b29Sopenharmony_ci-EXTERN(cjpeg_source_ptr) jinit_read_bmp(j_compress_ptr cinfo,
103b921b29Sopenharmony_ci+HIDE(EXTERN)(cjpeg_source_ptr) jinit_read_bmp(j_compress_ptr cinfo,
113b921b29Sopenharmony_ci                                         boolean use_inversion_array);
123b921b29Sopenharmony_ci-EXTERN(djpeg_dest_ptr) jinit_write_bmp(j_decompress_ptr cinfo, boolean is_os2,
133b921b29Sopenharmony_ci+HIDE(EXTERN)(djpeg_dest_ptr) jinit_write_bmp(j_decompress_ptr cinfo, boolean is_os2,
143b921b29Sopenharmony_ci                                        boolean use_inversion_array);
153b921b29Sopenharmony_ci-EXTERN(cjpeg_source_ptr) jinit_read_gif(j_compress_ptr cinfo);
163b921b29Sopenharmony_ci-EXTERN(djpeg_dest_ptr) jinit_write_gif(j_decompress_ptr cinfo, boolean is_lzw);
173b921b29Sopenharmony_ci-EXTERN(cjpeg_source_ptr) jinit_read_ppm(j_compress_ptr cinfo);
183b921b29Sopenharmony_ci-EXTERN(djpeg_dest_ptr) jinit_write_ppm(j_decompress_ptr cinfo);
193b921b29Sopenharmony_ci-EXTERN(cjpeg_source_ptr) jinit_read_targa(j_compress_ptr cinfo);
203b921b29Sopenharmony_ci-EXTERN(djpeg_dest_ptr) jinit_write_targa(j_decompress_ptr cinfo);
213b921b29Sopenharmony_ci+HIDE(EXTERN)(cjpeg_source_ptr) jinit_read_gif(j_compress_ptr cinfo);
223b921b29Sopenharmony_ci+HIDE(EXTERN)(djpeg_dest_ptr) jinit_write_gif(j_decompress_ptr cinfo, boolean is_lzw);
233b921b29Sopenharmony_ci+HIDE(EXTERN)(cjpeg_source_ptr) jinit_read_ppm(j_compress_ptr cinfo);
243b921b29Sopenharmony_ci+HIDE(EXTERN)(djpeg_dest_ptr) jinit_write_ppm(j_decompress_ptr cinfo);
253b921b29Sopenharmony_ci+HIDE(EXTERN)(cjpeg_source_ptr) jinit_read_targa(j_compress_ptr cinfo);
263b921b29Sopenharmony_ci+HIDE(EXTERN)(djpeg_dest_ptr) jinit_write_targa(j_decompress_ptr cinfo);
273b921b29Sopenharmony_ci 
283b921b29Sopenharmony_ci /* cjpeg support routines (in rdswitch.c) */
293b921b29Sopenharmony_ci 
303b921b29Sopenharmony_ci-EXTERN(boolean) read_quant_tables(j_compress_ptr cinfo, char *filename,
313b921b29Sopenharmony_ci+HIDE(EXTERN)(boolean) read_quant_tables(j_compress_ptr cinfo, char *filename,
323b921b29Sopenharmony_ci                                   boolean force_baseline);
333b921b29Sopenharmony_ci-EXTERN(boolean) read_scan_script(j_compress_ptr cinfo, char *filename);
343b921b29Sopenharmony_ci-EXTERN(boolean) set_quality_ratings(j_compress_ptr cinfo, char *arg,
353b921b29Sopenharmony_ci+HIDE(EXTERN)(boolean) read_scan_script(j_compress_ptr cinfo, char *filename);
363b921b29Sopenharmony_ci+HIDE(EXTERN)(boolean) set_quality_ratings(j_compress_ptr cinfo, char *arg,
373b921b29Sopenharmony_ci                                     boolean force_baseline);
383b921b29Sopenharmony_ci-EXTERN(boolean) set_quant_slots(j_compress_ptr cinfo, char *arg);
393b921b29Sopenharmony_ci-EXTERN(boolean) set_sample_factors(j_compress_ptr cinfo, char *arg);
403b921b29Sopenharmony_ci+HIDE(EXTERN)(boolean) set_quant_slots(j_compress_ptr cinfo, char *arg);
413b921b29Sopenharmony_ci+HIDE(EXTERN)(boolean) set_sample_factors(j_compress_ptr cinfo, char *arg);
423b921b29Sopenharmony_ci 
433b921b29Sopenharmony_ci /* djpeg support routines (in rdcolmap.c) */
443b921b29Sopenharmony_ci 
453b921b29Sopenharmony_ci-EXTERN(void) read_color_map(j_decompress_ptr cinfo, FILE *infile);
463b921b29Sopenharmony_ci+HIDE(EXTERN)(void) read_color_map(j_decompress_ptr cinfo, FILE *infile);
473b921b29Sopenharmony_ci 
483b921b29Sopenharmony_ci /* common support routines (in cdjpeg.c) */
493b921b29Sopenharmony_ci 
503b921b29Sopenharmony_ci-EXTERN(void) start_progress_monitor(j_common_ptr cinfo,
513b921b29Sopenharmony_ci+HIDE(EXTERN)(void) start_progress_monitor(j_common_ptr cinfo,
523b921b29Sopenharmony_ci                                     cd_progress_ptr progress);
533b921b29Sopenharmony_ci-EXTERN(void) end_progress_monitor(j_common_ptr cinfo);
543b921b29Sopenharmony_ci-EXTERN(boolean) keymatch(char *arg, const char *keyword, int minchars);
553b921b29Sopenharmony_ci-EXTERN(FILE *) read_stdin(void);
563b921b29Sopenharmony_ci-EXTERN(FILE *) write_stdout(void);
573b921b29Sopenharmony_ci+HIDE(EXTERN)(void) end_progress_monitor(j_common_ptr cinfo);
583b921b29Sopenharmony_ci+HIDE(EXTERN)(boolean) keymatch(char *arg, const char *keyword, int minchars);
593b921b29Sopenharmony_ci+HIDE(EXTERN)(FILE *) read_stdin(void);
603b921b29Sopenharmony_ci+HIDE(EXTERN)(FILE *) write_stdout(void);
613b921b29Sopenharmony_ci 
623b921b29Sopenharmony_ci /* miscellaneous useful macros */
633b921b29Sopenharmony_ci 
643b921b29Sopenharmony_cidiff --git a/jchuff.h b/jchuff.h
653b921b29Sopenharmony_ciindex da7809a..57e9f8c 100644
663b921b29Sopenharmony_ci--- a/jchuff.h
673b921b29Sopenharmony_ci+++ b/jchuff.h
683b921b29Sopenharmony_ci@@ -42,9 +42,9 @@ typedef struct {
693b921b29Sopenharmony_ci } c_derived_tbl;
703b921b29Sopenharmony_ci 
713b921b29Sopenharmony_ci /* Expand a Huffman table definition into the derived format */
723b921b29Sopenharmony_ci-EXTERN(void) jpeg_make_c_derived_tbl(j_compress_ptr cinfo, boolean isDC,
733b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_make_c_derived_tbl(j_compress_ptr cinfo, boolean isDC,
743b921b29Sopenharmony_ci                                      int tblno, c_derived_tbl **pdtbl);
753b921b29Sopenharmony_ci 
763b921b29Sopenharmony_ci /* Generate an optimal table definition given the specified counts */
773b921b29Sopenharmony_ci-EXTERN(void) jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl,
783b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl,
793b921b29Sopenharmony_ci                                     long freq[]);
803b921b29Sopenharmony_cidiff --git a/jdatadst-tj.c b/jdatadst-tj.c
813b921b29Sopenharmony_ciindex fdaa2de..dc53970 100644
823b921b29Sopenharmony_ci--- a/jdatadst-tj.c
833b921b29Sopenharmony_ci+++ b/jdatadst-tj.c
843b921b29Sopenharmony_ci@@ -27,7 +27,7 @@
853b921b29Sopenharmony_ci extern void *malloc(size_t size);
863b921b29Sopenharmony_ci extern void free(void *ptr);
873b921b29Sopenharmony_ci #endif
883b921b29Sopenharmony_ci-void jpeg_mem_dest_tj(j_compress_ptr cinfo, unsigned char **outbuffer,
893b921b29Sopenharmony_ci+HIDE(void) jpeg_mem_dest_tj(j_compress_ptr cinfo, unsigned char **outbuffer,
903b921b29Sopenharmony_ci                       unsigned long *outsize, boolean alloc);
913b921b29Sopenharmony_ci 
923b921b29Sopenharmony_ci 
933b921b29Sopenharmony_cidiff --git a/jdatasrc-tj.c b/jdatasrc-tj.c
943b921b29Sopenharmony_ciindex 69fb5ea..1808dd9 100644
953b921b29Sopenharmony_ci--- a/jdatasrc-tj.c
963b921b29Sopenharmony_ci+++ b/jdatasrc-tj.c
973b921b29Sopenharmony_ci@@ -23,7 +23,7 @@
983b921b29Sopenharmony_ci #include "jpeglib.h"
993b921b29Sopenharmony_ci #include "jerror.h"
1003b921b29Sopenharmony_ci 
1013b921b29Sopenharmony_ci-void jpeg_mem_src_tj(j_decompress_ptr cinfo, const unsigned char *inbuffer,
1023b921b29Sopenharmony_ci+HIDE(void) jpeg_mem_src_tj(j_decompress_ptr cinfo, const unsigned char *inbuffer,
1033b921b29Sopenharmony_ci                      unsigned long insize);
1043b921b29Sopenharmony_ci 
1053b921b29Sopenharmony_ci 
1063b921b29Sopenharmony_cidiff --git a/jdct.h b/jdct.h
1073b921b29Sopenharmony_ciindex 66d1718..7273ec0 100644
1083b921b29Sopenharmony_ci--- a/jdct.h
1093b921b29Sopenharmony_ci+++ b/jdct.h
1103b921b29Sopenharmony_ci@@ -90,62 +90,62 @@ typedef FAST_FLOAT FLOAT_MULT_TYPE;  /* preferred floating type */
1113b921b29Sopenharmony_ci 
1123b921b29Sopenharmony_ci /* Extern declarations for the forward and inverse DCT routines. */
1133b921b29Sopenharmony_ci 
1143b921b29Sopenharmony_ci-EXTERN(void) jpeg_fdct_islow(DCTELEM *data);
1153b921b29Sopenharmony_ci-EXTERN(void) jpeg_fdct_ifast(DCTELEM *data);
1163b921b29Sopenharmony_ci-EXTERN(void) jpeg_fdct_float(FAST_FLOAT *data);
1173b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_fdct_islow(DCTELEM *data);
1183b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_fdct_ifast(DCTELEM *data);
1193b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_fdct_float(FAST_FLOAT *data);
1203b921b29Sopenharmony_ci 
1213b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_islow(j_decompress_ptr cinfo,
1223b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_islow(j_decompress_ptr cinfo,
1233b921b29Sopenharmony_ci                              jpeg_component_info *compptr, JCOEFPTR coef_block,
1243b921b29Sopenharmony_ci                              JSAMPARRAY output_buf, JDIMENSION output_col);
1253b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_ifast(j_decompress_ptr cinfo,
1263b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_ifast(j_decompress_ptr cinfo,
1273b921b29Sopenharmony_ci                              jpeg_component_info *compptr, JCOEFPTR coef_block,
1283b921b29Sopenharmony_ci                              JSAMPARRAY output_buf, JDIMENSION output_col);
1293b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_float(j_decompress_ptr cinfo,
1303b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_float(j_decompress_ptr cinfo,
1313b921b29Sopenharmony_ci                              jpeg_component_info *compptr, JCOEFPTR coef_block,
1323b921b29Sopenharmony_ci                              JSAMPARRAY output_buf, JDIMENSION output_col);
1333b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_7x7(j_decompress_ptr cinfo,
1343b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_7x7(j_decompress_ptr cinfo,
1353b921b29Sopenharmony_ci                            jpeg_component_info *compptr, JCOEFPTR coef_block,
1363b921b29Sopenharmony_ci                            JSAMPARRAY output_buf, JDIMENSION output_col);
1373b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_6x6(j_decompress_ptr cinfo,
1383b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_6x6(j_decompress_ptr cinfo,
1393b921b29Sopenharmony_ci                            jpeg_component_info *compptr, JCOEFPTR coef_block,
1403b921b29Sopenharmony_ci                            JSAMPARRAY output_buf, JDIMENSION output_col);
1413b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_5x5(j_decompress_ptr cinfo,
1423b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_5x5(j_decompress_ptr cinfo,
1433b921b29Sopenharmony_ci                            jpeg_component_info *compptr, JCOEFPTR coef_block,
1443b921b29Sopenharmony_ci                            JSAMPARRAY output_buf, JDIMENSION output_col);
1453b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_4x4(j_decompress_ptr cinfo,
1463b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_4x4(j_decompress_ptr cinfo,
1473b921b29Sopenharmony_ci                            jpeg_component_info *compptr, JCOEFPTR coef_block,
1483b921b29Sopenharmony_ci                            JSAMPARRAY output_buf, JDIMENSION output_col);
1493b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_3x3(j_decompress_ptr cinfo,
1503b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_3x3(j_decompress_ptr cinfo,
1513b921b29Sopenharmony_ci                            jpeg_component_info *compptr, JCOEFPTR coef_block,
1523b921b29Sopenharmony_ci                            JSAMPARRAY output_buf, JDIMENSION output_col);
1533b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_2x2(j_decompress_ptr cinfo,
1543b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_2x2(j_decompress_ptr cinfo,
1553b921b29Sopenharmony_ci                            jpeg_component_info *compptr, JCOEFPTR coef_block,
1563b921b29Sopenharmony_ci                            JSAMPARRAY output_buf, JDIMENSION output_col);
1573b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_1x1(j_decompress_ptr cinfo,
1583b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_1x1(j_decompress_ptr cinfo,
1593b921b29Sopenharmony_ci                            jpeg_component_info *compptr, JCOEFPTR coef_block,
1603b921b29Sopenharmony_ci                            JSAMPARRAY output_buf, JDIMENSION output_col);
1613b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_9x9(j_decompress_ptr cinfo,
1623b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_9x9(j_decompress_ptr cinfo,
1633b921b29Sopenharmony_ci                            jpeg_component_info *compptr, JCOEFPTR coef_block,
1643b921b29Sopenharmony_ci                            JSAMPARRAY output_buf, JDIMENSION output_col);
1653b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_10x10(j_decompress_ptr cinfo,
1663b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_10x10(j_decompress_ptr cinfo,
1673b921b29Sopenharmony_ci                              jpeg_component_info *compptr, JCOEFPTR coef_block,
1683b921b29Sopenharmony_ci                              JSAMPARRAY output_buf, JDIMENSION output_col);
1693b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_11x11(j_decompress_ptr cinfo,
1703b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_11x11(j_decompress_ptr cinfo,
1713b921b29Sopenharmony_ci                              jpeg_component_info *compptr, JCOEFPTR coef_block,
1723b921b29Sopenharmony_ci                              JSAMPARRAY output_buf, JDIMENSION output_col);
1733b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_12x12(j_decompress_ptr cinfo,
1743b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_12x12(j_decompress_ptr cinfo,
1753b921b29Sopenharmony_ci                              jpeg_component_info *compptr, JCOEFPTR coef_block,
1763b921b29Sopenharmony_ci                              JSAMPARRAY output_buf, JDIMENSION output_col);
1773b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_13x13(j_decompress_ptr cinfo,
1783b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_13x13(j_decompress_ptr cinfo,
1793b921b29Sopenharmony_ci                              jpeg_component_info *compptr, JCOEFPTR coef_block,
1803b921b29Sopenharmony_ci                              JSAMPARRAY output_buf, JDIMENSION output_col);
1813b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_14x14(j_decompress_ptr cinfo,
1823b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_14x14(j_decompress_ptr cinfo,
1833b921b29Sopenharmony_ci                              jpeg_component_info *compptr, JCOEFPTR coef_block,
1843b921b29Sopenharmony_ci                              JSAMPARRAY output_buf, JDIMENSION output_col);
1853b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_15x15(j_decompress_ptr cinfo,
1863b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_15x15(j_decompress_ptr cinfo,
1873b921b29Sopenharmony_ci                              jpeg_component_info *compptr, JCOEFPTR coef_block,
1883b921b29Sopenharmony_ci                              JSAMPARRAY output_buf, JDIMENSION output_col);
1893b921b29Sopenharmony_ci-EXTERN(void) jpeg_idct_16x16(j_decompress_ptr cinfo,
1903b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_idct_16x16(j_decompress_ptr cinfo,
1913b921b29Sopenharmony_ci                              jpeg_component_info *compptr, JCOEFPTR coef_block,
1923b921b29Sopenharmony_ci                              JSAMPARRAY output_buf, JDIMENSION output_col);
1933b921b29Sopenharmony_ci 
1943b921b29Sopenharmony_cidiff --git a/jdhuff.h b/jdhuff.h
1953b921b29Sopenharmony_ciindex cfa0b7f..6cc2344 100644
1963b921b29Sopenharmony_ci--- a/jdhuff.h
1973b921b29Sopenharmony_ci+++ b/jdhuff.h
1983b921b29Sopenharmony_ci@@ -16,10 +16,55 @@
1993b921b29Sopenharmony_ci 
2003b921b29Sopenharmony_ci #include "jconfigint.h"
2013b921b29Sopenharmony_ci 
2023b921b29Sopenharmony_ci-
2033b921b29Sopenharmony_ci+#ifndef HUFF_DECODE_OPT
2043b921b29Sopenharmony_ci+#define HUFF_LOOKAHEAD  8
2053b921b29Sopenharmony_ci+#define HUFF_CODE_LARGE_LONG_ALIGNED 0
2063b921b29Sopenharmony_ci+#else
2073b921b29Sopenharmony_ci+// OH ISSUE: jpeg optimize
2083b921b29Sopenharmony_ci /* Derived data constructed for each Huffman table */
2093b921b29Sopenharmony_ci-
2103b921b29Sopenharmony_ci-#define HUFF_LOOKAHEAD  8       /* # of bits of lookahead */
2113b921b29Sopenharmony_ci+#define MAX_HUFF_CODE_LEN 16
2123b921b29Sopenharmony_ci+
2133b921b29Sopenharmony_ci+#define HUFF_LOOKAHEAD  10      /* # of bits of lookahead  9-13 maybe */
2143b921b29Sopenharmony_ci+#define HUFF_AC_SYMBOLS 192
2153b921b29Sopenharmony_ci+
2163b921b29Sopenharmony_ci+#define HUFF_L_REM (16 - HUFF_LOOKAHEAD)
2173b921b29Sopenharmony_ci+#define HUFF_L_DUP ((1 << HUFF_L_REM) - (HUFF_L_REM + 1))
2183b921b29Sopenharmony_ci+#define HUFF_L_UNUSED ((1 << HUFF_L_REM) - (1 << ((HUFF_L_REM)/2)) - (1 << ((HUFF_L_REM + 1)/2)) + 1)
2193b921b29Sopenharmony_ci+#define HUFF_L_SIZE (HUFF_AC_SYMBOLS + HUFF_L_DUP + HUFF_L_UNUSED)
2203b921b29Sopenharmony_ci+#define HUFF_CODE_LARGE_LONG_ALIGNED (HUFF_L_SIZE + (-HUFF_L_SIZE & 0xf))
2213b921b29Sopenharmony_ci+
2223b921b29Sopenharmony_ci+#define COEF_BITS_OFFSET 0
2233b921b29Sopenharmony_ci+#define COEF_BITS_BITS 4
2243b921b29Sopenharmony_ci+#define ZERO_NUM1_OFFSET 4
2253b921b29Sopenharmony_ci+#define ZERO_NUM_BITS 7
2263b921b29Sopenharmony_ci+#define NB_OFFSET 11
2273b921b29Sopenharmony_ci+#define NB_BITS 5
2283b921b29Sopenharmony_ci+#define COEF1_OFFSET 16
2293b921b29Sopenharmony_ci+#define COEF_VALUE_BITS 16
2303b921b29Sopenharmony_ci+
2313b921b29Sopenharmony_ci+#define EXTRA_BITS_OFFSET COEF_BITS_OFFSET  // 2nd table offset bits
2323b921b29Sopenharmony_ci+#define EXTRA_BITS_BITS COEF_BITS_BITS
2333b921b29Sopenharmony_ci+
2343b921b29Sopenharmony_ci+#define SYM_OFFSET COEF_BITS_OFFSET
2353b921b29Sopenharmony_ci+
2363b921b29Sopenharmony_ci+#define MAKE_BITS(x, s)  (x) << (s)
2373b921b29Sopenharmony_ci+#define GETS_BITS(x, s, l)  (((x) >> (s)) & ((0x1L << (l)) - 1))
2383b921b29Sopenharmony_ci+
2393b921b29Sopenharmony_ci+#define MAKE_ZERO_NUM1(x) MAKE_BITS((x), ZERO_NUM1_OFFSET)
2403b921b29Sopenharmony_ci+#define MAKE_COEF_BITS(x) MAKE_BITS((x), COEF_BITS_OFFSET)
2413b921b29Sopenharmony_ci+#define MAKE_SYM(x) MAKE_BITS((x), SYM_OFFSET)
2423b921b29Sopenharmony_ci+#define MAKE_NB(x) MAKE_BITS((x), NB_OFFSET)
2433b921b29Sopenharmony_ci+#define MAKE_COEF1(x) (unsigned long long) MAKE_BITS((UINT16) (x), COEF1_OFFSET)
2443b921b29Sopenharmony_ci+#define MAKE_BASE(x) MAKE_BITS((x), COEF1_OFFSET)
2453b921b29Sopenharmony_ci+#define MAKE_EXTRA_BITS(x) MAKE_BITS((x), EXTRA_BITS_OFFSET)
2463b921b29Sopenharmony_ci+
2473b921b29Sopenharmony_ci+#define GET_ZERO_NUM1(x) GETS_BITS((x), ZERO_NUM1_OFFSET, ZERO_NUM_BITS)
2483b921b29Sopenharmony_ci+#define GET_COEF_BITS(x) GETS_BITS((x), COEF_BITS_OFFSET, COEF_BITS_BITS)
2493b921b29Sopenharmony_ci+#define GET_NB(x) GETS_BITS((x), NB_OFFSET, NB_BITS)
2503b921b29Sopenharmony_ci+#define GET_COEF1(x) GETS_BITS((x), COEF1_OFFSET, COEF_VALUE_BITS)
2513b921b29Sopenharmony_ci+#define GET_BASE(x) GETS_BITS((x), COEF1_OFFSET, COEF_VALUE_BITS)
2523b921b29Sopenharmony_ci+#define GET_EXTRA_BITS(x) GETS_BITS((x), EXTRA_BITS_OFFSET, EXTRA_BITS_BITS)
2533b921b29Sopenharmony_ci+#endif
2543b921b29Sopenharmony_ci 
2553b921b29Sopenharmony_ci typedef struct {
2563b921b29Sopenharmony_ci   /* Basic tables: (element [0] of each array is unused) */
2573b921b29Sopenharmony_ci@@ -44,11 +89,11 @@ typedef struct {
2583b921b29Sopenharmony_ci    * if too long.  The next 8 bits of each entry contain the
2593b921b29Sopenharmony_ci    * symbol.
2603b921b29Sopenharmony_ci    */
2613b921b29Sopenharmony_ci-  int lookup[1 << HUFF_LOOKAHEAD];
2623b921b29Sopenharmony_ci+  int lookup[(1 << HUFF_LOOKAHEAD) + HUFF_CODE_LARGE_LONG_ALIGNED];
2633b921b29Sopenharmony_ci } d_derived_tbl;
2643b921b29Sopenharmony_ci 
2653b921b29Sopenharmony_ci /* Expand a Huffman table definition into the derived format */
2663b921b29Sopenharmony_ci-EXTERN(void) jpeg_make_d_derived_tbl(j_decompress_ptr cinfo, boolean isDC,
2673b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_make_d_derived_tbl(j_decompress_ptr cinfo, boolean isDC,
2683b921b29Sopenharmony_ci                                      int tblno, d_derived_tbl **pdtbl);
2693b921b29Sopenharmony_ci 
2703b921b29Sopenharmony_ci 
2713b921b29Sopenharmony_ci@@ -172,7 +217,7 @@ typedef struct {                /* Bitreading working state within an MCU */
2723b921b29Sopenharmony_ci   (bits_left -= (nbits))
2733b921b29Sopenharmony_ci 
2743b921b29Sopenharmony_ci /* Load up the bit buffer to a depth of at least nbits */
2753b921b29Sopenharmony_ci-EXTERN(boolean) jpeg_fill_bit_buffer(bitread_working_state *state,
2763b921b29Sopenharmony_ci+HIDE(EXTERN)(boolean) jpeg_fill_bit_buffer(bitread_working_state *state,
2773b921b29Sopenharmony_ci                                      register bit_buf_type get_buffer,
2783b921b29Sopenharmony_ci                                      register int bits_left, int nbits);
2793b921b29Sopenharmony_ci 
2803b921b29Sopenharmony_ci@@ -241,7 +286,7 @@ slowlabel: \
2813b921b29Sopenharmony_ci   }
2823b921b29Sopenharmony_ci 
2833b921b29Sopenharmony_ci /* Out-of-line case for Huffman code fetching */
2843b921b29Sopenharmony_ci-EXTERN(int) jpeg_huff_decode(bitread_working_state *state,
2853b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jpeg_huff_decode(bitread_working_state *state,
2863b921b29Sopenharmony_ci                              register bit_buf_type get_buffer,
2873b921b29Sopenharmony_ci                              register int bits_left, d_derived_tbl *htbl,
2883b921b29Sopenharmony_ci                              int min_bits);
2893b921b29Sopenharmony_cidiff --git a/jdhuff_opt.c b/jdhuff_opt.c
2903b921b29Sopenharmony_cinew file mode 100644
2913b921b29Sopenharmony_ciindex 0000000..5b1875c
2923b921b29Sopenharmony_ci--- /dev/null
2933b921b29Sopenharmony_ci+++ b/jdhuff_opt.c
2943b921b29Sopenharmony_ci@@ -0,0 +1,1046 @@
2953b921b29Sopenharmony_ci+/*
2963b921b29Sopenharmony_ci+ * jdhuff_opt.c
2973b921b29Sopenharmony_ci+ *
2983b921b29Sopenharmony_ci+ * This file was part of the Independent JPEG Group's software:
2993b921b29Sopenharmony_ci+ * Copyright (C) 1991-1997, Thomas G. Lane.
3003b921b29Sopenharmony_ci+ * libjpeg-turbo Modifications:
3013b921b29Sopenharmony_ci+ * Copyright (C) 2009-2011, 2016, 2018-2019, D. R. Commander.
3023b921b29Sopenharmony_ci+ * Copyright (C) 2018, Matthias Räncker.
3033b921b29Sopenharmony_ci+ * For conditions of distribution and use, see the accompanying README.ijg
3043b921b29Sopenharmony_ci+ * file.
3053b921b29Sopenharmony_ci+ *
3063b921b29Sopenharmony_ci+ * This file contains Huffman entropy decoding routines.
3073b921b29Sopenharmony_ci+ *
3083b921b29Sopenharmony_ci+ * Much of the complexity here has to do with supporting input suspension.
3093b921b29Sopenharmony_ci+ * If the data source module demands suspension, we want to be able to back
3103b921b29Sopenharmony_ci+ * up to the start of the current MCU.  To do this, we copy state variables
3113b921b29Sopenharmony_ci+ * into local working storage, and update them back to the permanent
3123b921b29Sopenharmony_ci+ * storage only upon successful completion of an MCU.
3133b921b29Sopenharmony_ci+ *
3143b921b29Sopenharmony_ci+ * NOTE: All referenced figures are from
3153b921b29Sopenharmony_ci+ * Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994.
3163b921b29Sopenharmony_ci+ */
3173b921b29Sopenharmony_ci+
3183b921b29Sopenharmony_ci+#define JPEG_INTERNALS
3193b921b29Sopenharmony_ci+#include "jinclude.h"
3203b921b29Sopenharmony_ci+#include "jpeglib.h"
3213b921b29Sopenharmony_ci+#include "jdhuff.h"             /* Declarations shared with jdphuff.c */
3223b921b29Sopenharmony_ci+#include "jpegcomp.h"
3233b921b29Sopenharmony_ci+#include "jstdhuff.c"
3243b921b29Sopenharmony_ci+
3253b921b29Sopenharmony_ci+
3263b921b29Sopenharmony_ci+/*
3273b921b29Sopenharmony_ci+ * Expanded entropy decoder object for Huffman decoding.
3283b921b29Sopenharmony_ci+ *
3293b921b29Sopenharmony_ci+ * The savable_state subrecord contains fields that change within an MCU,
3303b921b29Sopenharmony_ci+ * but must not be updated permanently until we complete the MCU.
3313b921b29Sopenharmony_ci+ */
3323b921b29Sopenharmony_ci+
3333b921b29Sopenharmony_ci+typedef struct {
3343b921b29Sopenharmony_ci+  int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
3353b921b29Sopenharmony_ci+} savable_state;
3363b921b29Sopenharmony_ci+
3373b921b29Sopenharmony_ci+typedef struct {
3383b921b29Sopenharmony_ci+  struct jpeg_entropy_decoder pub; /* public fields */
3393b921b29Sopenharmony_ci+
3403b921b29Sopenharmony_ci+  /* These fields are loaded into local variables at start of each MCU.
3413b921b29Sopenharmony_ci+   * In case of suspension, we exit WITHOUT updating them.
3423b921b29Sopenharmony_ci+   */
3433b921b29Sopenharmony_ci+  bitread_perm_state bitstate;  /* Bit buffer at start of MCU */
3443b921b29Sopenharmony_ci+  savable_state saved;          /* Other state at start of MCU */
3453b921b29Sopenharmony_ci+
3463b921b29Sopenharmony_ci+  /* These fields are NOT loaded into local working state. */
3473b921b29Sopenharmony_ci+  unsigned int restarts_to_go;  /* MCUs left in this restart interval */
3483b921b29Sopenharmony_ci+
3493b921b29Sopenharmony_ci+  /* Pointers to derived tables (these workspaces have image lifespan) */
3503b921b29Sopenharmony_ci+  d_derived_tbl *dc_derived_tbls[NUM_HUFF_TBLS];
3513b921b29Sopenharmony_ci+  d_derived_tbl *ac_derived_tbls[NUM_HUFF_TBLS];
3523b921b29Sopenharmony_ci+
3533b921b29Sopenharmony_ci+  /* Precalculated info set up by start_pass for use in decode_mcu: */
3543b921b29Sopenharmony_ci+
3553b921b29Sopenharmony_ci+  /* Pointers to derived tables to be used for each block within an MCU */
3563b921b29Sopenharmony_ci+  d_derived_tbl *dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
3573b921b29Sopenharmony_ci+  d_derived_tbl *ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
3583b921b29Sopenharmony_ci+  /* Whether we care about the DC and AC coefficient values for each block */
3593b921b29Sopenharmony_ci+  boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
3603b921b29Sopenharmony_ci+  boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
3613b921b29Sopenharmony_ci+} huff_entropy_decoder;
3623b921b29Sopenharmony_ci+
3633b921b29Sopenharmony_ci+typedef huff_entropy_decoder *huff_entropy_ptr;
3643b921b29Sopenharmony_ci+
3653b921b29Sopenharmony_ci+/*
3663b921b29Sopenharmony_ci+ * Figure F.12: extend sign bit.
3673b921b29Sopenharmony_ci+ * On some machines, a shift and add will be faster than a table lookup.
3683b921b29Sopenharmony_ci+ */
3693b921b29Sopenharmony_ci+
3703b921b29Sopenharmony_ci+#define AVOID_TABLES
3713b921b29Sopenharmony_ci+#ifdef AVOID_TABLES
3723b921b29Sopenharmony_ci+
3733b921b29Sopenharmony_ci+#define NEG_1  ((unsigned int)-1)
3743b921b29Sopenharmony_ci+#define HUFF_EXTEND(x, s) \
3753b921b29Sopenharmony_ci+  ((x) + ((((x) - (1 << ((s) - 1))) >> 31) & (((NEG_1) << (s)) + 1)))
3763b921b29Sopenharmony_ci+
3773b921b29Sopenharmony_ci+#else
3783b921b29Sopenharmony_ci+
3793b921b29Sopenharmony_ci+#define HUFF_EXTEND(x, s) \
3803b921b29Sopenharmony_ci+  ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
3813b921b29Sopenharmony_ci+
3823b921b29Sopenharmony_ci+static const int extend_test[16] = {   /* entry n is 2**(n-1) */
3833b921b29Sopenharmony_ci+  0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3843b921b29Sopenharmony_ci+  0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000
3853b921b29Sopenharmony_ci+};
3863b921b29Sopenharmony_ci+
3873b921b29Sopenharmony_ci+static const int extend_offset[16] = { /* entry n is (-1 << n) + 1 */
3883b921b29Sopenharmony_ci+  0, ((-1) << 1) + 1, ((-1) << 2) + 1, ((-1) << 3) + 1, ((-1) << 4) + 1,
3893b921b29Sopenharmony_ci+  ((-1) << 5) + 1, ((-1) << 6) + 1, ((-1) << 7) + 1, ((-1) << 8) + 1,
3903b921b29Sopenharmony_ci+  ((-1) << 9) + 1, ((-1) << 10) + 1, ((-1) << 11) + 1, ((-1) << 12) + 1,
3913b921b29Sopenharmony_ci+  ((-1) << 13) + 1, ((-1) << 14) + 1, ((-1) << 15) + 1
3923b921b29Sopenharmony_ci+};
3933b921b29Sopenharmony_ci+
3943b921b29Sopenharmony_ci+#endif /* AVOID_TABLES */
3953b921b29Sopenharmony_ci+
3963b921b29Sopenharmony_ci+/*
3973b921b29Sopenharmony_ci+ * Initialize for a Huffman-compressed scan.
3983b921b29Sopenharmony_ci+ */
3993b921b29Sopenharmony_ci+
4003b921b29Sopenharmony_ci+METHODDEF(void)
4013b921b29Sopenharmony_ci+start_pass_huff_decoder(j_decompress_ptr cinfo)
4023b921b29Sopenharmony_ci+{
4033b921b29Sopenharmony_ci+  huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
4043b921b29Sopenharmony_ci+  int ci, blkn, dctbl, actbl;
4053b921b29Sopenharmony_ci+  d_derived_tbl **pdtbl;
4063b921b29Sopenharmony_ci+  jpeg_component_info *compptr;
4073b921b29Sopenharmony_ci+
4083b921b29Sopenharmony_ci+  /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
4093b921b29Sopenharmony_ci+   * This ought to be an error condition, but we make it a warning because
4103b921b29Sopenharmony_ci+   * there are some baseline files out there with all zeroes in these bytes.
4113b921b29Sopenharmony_ci+   */
4123b921b29Sopenharmony_ci+  if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2 - 1 ||
4133b921b29Sopenharmony_ci+      cinfo->Ah != 0 || cinfo->Al != 0)
4143b921b29Sopenharmony_ci+    WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
4153b921b29Sopenharmony_ci+
4163b921b29Sopenharmony_ci+  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
4173b921b29Sopenharmony_ci+    compptr = cinfo->cur_comp_info[ci];
4183b921b29Sopenharmony_ci+    dctbl = compptr->dc_tbl_no;
4193b921b29Sopenharmony_ci+    actbl = compptr->ac_tbl_no;
4203b921b29Sopenharmony_ci+    /* Compute derived values for Huffman tables */
4213b921b29Sopenharmony_ci+    /* We may do this more than once for a table, but it's not expensive */
4223b921b29Sopenharmony_ci+    pdtbl = (d_derived_tbl **)(entropy->dc_derived_tbls) + dctbl;
4233b921b29Sopenharmony_ci+    jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl, pdtbl);
4243b921b29Sopenharmony_ci+    pdtbl = (d_derived_tbl **)(entropy->ac_derived_tbls) + actbl;
4253b921b29Sopenharmony_ci+    jpeg_make_d_derived_tbl(cinfo, FALSE, actbl, pdtbl);
4263b921b29Sopenharmony_ci+    /* Initialize DC predictions to 0 */
4273b921b29Sopenharmony_ci+    entropy->saved.last_dc_val[ci] = 0;
4283b921b29Sopenharmony_ci+  }
4293b921b29Sopenharmony_ci+
4303b921b29Sopenharmony_ci+  /* Precalculate decoding info for each block in an MCU of this scan */
4313b921b29Sopenharmony_ci+  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
4323b921b29Sopenharmony_ci+    ci = cinfo->MCU_membership[blkn];
4333b921b29Sopenharmony_ci+    compptr = cinfo->cur_comp_info[ci];
4343b921b29Sopenharmony_ci+    /* Precalculate which table to use for each block */
4353b921b29Sopenharmony_ci+    entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
4363b921b29Sopenharmony_ci+    entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
4373b921b29Sopenharmony_ci+    /* Decide whether we really care about the coefficient values */
4383b921b29Sopenharmony_ci+    if (compptr->component_needed) {
4393b921b29Sopenharmony_ci+      entropy->dc_needed[blkn] = TRUE;
4403b921b29Sopenharmony_ci+      /* we don't need the ACs if producing a 1/8th-size image */
4413b921b29Sopenharmony_ci+      entropy->ac_needed[blkn] = (compptr->_DCT_scaled_size > 1);
4423b921b29Sopenharmony_ci+    } else {
4433b921b29Sopenharmony_ci+      entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
4443b921b29Sopenharmony_ci+    }
4453b921b29Sopenharmony_ci+  }
4463b921b29Sopenharmony_ci+
4473b921b29Sopenharmony_ci+  /* Initialize bitread state variables */
4483b921b29Sopenharmony_ci+  entropy->bitstate.bits_left = 0;
4493b921b29Sopenharmony_ci+  entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
4503b921b29Sopenharmony_ci+  entropy->pub.insufficient_data = FALSE;
4513b921b29Sopenharmony_ci+
4523b921b29Sopenharmony_ci+  /* Initialize restart counter */
4533b921b29Sopenharmony_ci+  entropy->restarts_to_go = cinfo->restart_interval;
4543b921b29Sopenharmony_ci+}
4553b921b29Sopenharmony_ci+
4563b921b29Sopenharmony_ci+LOCAL(void)
4573b921b29Sopenharmony_ci+jpeg_make_d_ac_derived_tbl(JHUFF_TBL *htbl, d_derived_tbl *dtbl, const unsigned int* huffcode)
4583b921b29Sopenharmony_ci+{
4593b921b29Sopenharmony_ci+  // Look up tables for AC, index is huffman code, value is the symbol and the length
4603b921b29Sopenharmony_ci+  // htbl->bits[l], number of symbol that of which the code length is l
4613b921b29Sopenharmony_ci+  // htbl->huffval[l], symbol in order
4623b921b29Sopenharmony_ci+  int p, i, l, lookbits, ctr;
4633b921b29Sopenharmony_ci+  // nb <= LOOKAHEAD
4643b921b29Sopenharmony_ci+  p = 0;
4653b921b29Sopenharmony_ci+  int coef0;
4663b921b29Sopenharmony_ci+  for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
4673b921b29Sopenharmony_ci+    for (i = 1; i <= (int)htbl->bits[l]; i++, p++) {
4683b921b29Sopenharmony_ci+      /* l = current code's length, p = its index in huffcode[] & huffval[]. */
4693b921b29Sopenharmony_ci+      /* Generate left-justified code followed by all possible bit sequences */
4703b921b29Sopenharmony_ci+      UINT8 rs = htbl->huffval[p]; // run length symbol (zero num + coeff bits)
4713b921b29Sopenharmony_ci+      UINT8 coef_bits = rs & 0x0F;
4723b921b29Sopenharmony_ci+      if ((l + coef_bits) <= HUFF_LOOKAHEAD) {
4733b921b29Sopenharmony_ci+        // save DCT coeffs in higher bits
4743b921b29Sopenharmony_ci+        for (coef0 = 0; coef0 < (1 << coef_bits); coef0++) {
4753b921b29Sopenharmony_ci+          INT16 coef_value = HUFF_EXTEND(coef0, coef_bits);  // save value after extended.
4763b921b29Sopenharmony_ci+          lookbits = (huffcode[p] << (HUFF_LOOKAHEAD - l)) | (coef0 << (HUFF_LOOKAHEAD - l - coef_bits));
4773b921b29Sopenharmony_ci+          for (ctr = 1 << (HUFF_LOOKAHEAD - l - coef_bits); ctr > 0; ctr--) {
4783b921b29Sopenharmony_ci+            if (coef_bits == 0 && (rs >> 4) != 0xF) { // the low 4 bits are number of coef bits
4793b921b29Sopenharmony_ci+              // use 63 to exit the loop when symbol is 00
4803b921b29Sopenharmony_ci+              dtbl->lookup[lookbits] = MAKE_COEF1(coef_value) | MAKE_NB(l + coef_bits) | MAKE_ZERO_NUM1(63);
4813b921b29Sopenharmony_ci+             } else { // F0 and other symbols
4823b921b29Sopenharmony_ci+              // save the low 4 bits
4833b921b29Sopenharmony_ci+              dtbl->lookup[lookbits] = MAKE_COEF1(coef_value) | MAKE_NB(l + coef_bits) | MAKE_ZERO_NUM1(rs >> 4);
4843b921b29Sopenharmony_ci+            }
4853b921b29Sopenharmony_ci+            lookbits++;
4863b921b29Sopenharmony_ci+          }
4873b921b29Sopenharmony_ci+        }
4883b921b29Sopenharmony_ci+      } else {
4893b921b29Sopenharmony_ci+        // same as the original lookup table
4903b921b29Sopenharmony_ci+        lookbits = huffcode[p] << (HUFF_LOOKAHEAD - l);
4913b921b29Sopenharmony_ci+        for (ctr = 1 << (HUFF_LOOKAHEAD - l); ctr > 0; ctr--) {
4923b921b29Sopenharmony_ci+          dtbl->lookup[lookbits] = MAKE_NB(l) | MAKE_SYM(rs);
4933b921b29Sopenharmony_ci+          lookbits++;
4943b921b29Sopenharmony_ci+        }
4953b921b29Sopenharmony_ci+      }
4963b921b29Sopenharmony_ci+    }
4973b921b29Sopenharmony_ci+  }
4983b921b29Sopenharmony_ci+  // nb > LOOKAHEAD
4993b921b29Sopenharmony_ci+  int offset = 0;
5003b921b29Sopenharmony_ci+  int base = 1 << HUFF_LOOKAHEAD;
5013b921b29Sopenharmony_ci+  int short_tbl_index = 0xFFFFFFFF;
5023b921b29Sopenharmony_ci+  int cur_long_tbl_base = 1 << HUFF_LOOKAHEAD;
5033b921b29Sopenharmony_ci+  int left;
5043b921b29Sopenharmony_ci+  int offset_bit = 0;
5053b921b29Sopenharmony_ci+  int first = p;  // the index of the first code of this length.
5063b921b29Sopenharmony_ci+  int max_code_len;
5073b921b29Sopenharmony_ci+  for (max_code_len = MAX_HUFF_CODE_LEN; max_code_len >= 1; max_code_len--) {
5083b921b29Sopenharmony_ci+    if (htbl->bits[max_code_len]) {
5093b921b29Sopenharmony_ci+        break;
5103b921b29Sopenharmony_ci+    }
5113b921b29Sopenharmony_ci+  }
5123b921b29Sopenharmony_ci+  for (l = HUFF_LOOKAHEAD + 1; l <= MAX_HUFF_CODE_LEN; l++) {
5133b921b29Sopenharmony_ci+    for (i = 1; i <= (int)htbl->bits[l]; i++, p++) {
5143b921b29Sopenharmony_ci+      UINT8 rs = htbl->huffval[p]; // run length symbol (zero num + coeff bits)
5153b921b29Sopenharmony_ci+      UINT8 coef_bits = rs & 0x0f;
5163b921b29Sopenharmony_ci+      // similar as 1st table as before
5173b921b29Sopenharmony_ci+      lookbits = huffcode[p] >> (l - HUFF_LOOKAHEAD); // index in 1st table
5183b921b29Sopenharmony_ci+      // check if a new 2nd tbl should be created
5193b921b29Sopenharmony_ci+      if (lookbits != short_tbl_index) {
5203b921b29Sopenharmony_ci+        short_tbl_index = lookbits;
5213b921b29Sopenharmony_ci+        cur_long_tbl_base += offset;
5223b921b29Sopenharmony_ci+        offset = 0;
5233b921b29Sopenharmony_ci+        offset_bit = l - HUFF_LOOKAHEAD;
5243b921b29Sopenharmony_ci+        left = (1 << offset_bit) - (htbl->bits[l] - (p - first));
5253b921b29Sopenharmony_ci+        while (offset_bit + HUFF_LOOKAHEAD < max_code_len && left > 0) {
5263b921b29Sopenharmony_ci+          offset_bit++;
5273b921b29Sopenharmony_ci+          left = (left << 1) - htbl->bits[offset_bit + HUFF_LOOKAHEAD];
5283b921b29Sopenharmony_ci+        }
5293b921b29Sopenharmony_ci+      }
5303b921b29Sopenharmony_ci+      base = cur_long_tbl_base;
5313b921b29Sopenharmony_ci+      // set 1st table value
5323b921b29Sopenharmony_ci+      dtbl->lookup[lookbits] = MAKE_BASE(base) | MAKE_NB(l) | MAKE_EXTRA_BITS(offset_bit);
5333b921b29Sopenharmony_ci+      // set 2nd table value
5343b921b29Sopenharmony_ci+      // index is guarenteed to be valid
5353b921b29Sopenharmony_ci+      for (ctr = 0; ctr < (1 << (offset_bit - (l - HUFF_LOOKAHEAD))); ctr++) {
5363b921b29Sopenharmony_ci+        if (coef_bits == 0) {
5373b921b29Sopenharmony_ci+          dtbl->lookup[base + offset] = MAKE_NB(l) | MAKE_SYM(rs) | MAKE_COEF_BITS(0xF);
5383b921b29Sopenharmony_ci+        } else {
5393b921b29Sopenharmony_ci+          dtbl->lookup[base + offset] = MAKE_NB(l) | MAKE_SYM(rs);
5403b921b29Sopenharmony_ci+        }
5413b921b29Sopenharmony_ci+        offset++;
5423b921b29Sopenharmony_ci+      }
5433b921b29Sopenharmony_ci+    }
5443b921b29Sopenharmony_ci+    first = p;
5453b921b29Sopenharmony_ci+  }
5463b921b29Sopenharmony_ci+}
5473b921b29Sopenharmony_ci+
5483b921b29Sopenharmony_ci+/*
5493b921b29Sopenharmony_ci+ * Compute the derived values for a Huffman table.
5503b921b29Sopenharmony_ci+ * This routine also performs some validation checks on the table.
5513b921b29Sopenharmony_ci+ *
5523b921b29Sopenharmony_ci+ * Note this is also used by jdphuff.c.
5533b921b29Sopenharmony_ci+ */
5543b921b29Sopenharmony_ci+
5553b921b29Sopenharmony_ci+GLOBAL(void)
5563b921b29Sopenharmony_ci+jpeg_make_d_derived_tbl(j_decompress_ptr cinfo, boolean isDC, int tblno,
5573b921b29Sopenharmony_ci+                        d_derived_tbl **pdtbl)
5583b921b29Sopenharmony_ci+{
5593b921b29Sopenharmony_ci+  JHUFF_TBL *htbl;
5603b921b29Sopenharmony_ci+  d_derived_tbl *dtbl;
5613b921b29Sopenharmony_ci+  int p, i, l, si, numsymbols;
5623b921b29Sopenharmony_ci+  int lookbits, ctr;
5633b921b29Sopenharmony_ci+  char huffsize[257];
5643b921b29Sopenharmony_ci+  unsigned int huffcode[257];
5653b921b29Sopenharmony_ci+  unsigned int code;
5663b921b29Sopenharmony_ci+
5673b921b29Sopenharmony_ci+  /* Note that huffsize[] and huffcode[] are filled in code-length order,
5683b921b29Sopenharmony_ci+   * paralleling the order of the symbols themselves in htbl->huffval[].
5693b921b29Sopenharmony_ci+   */
5703b921b29Sopenharmony_ci+
5713b921b29Sopenharmony_ci+  /* Find the input Huffman table */
5723b921b29Sopenharmony_ci+  if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
5733b921b29Sopenharmony_ci+    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
5743b921b29Sopenharmony_ci+  htbl =
5753b921b29Sopenharmony_ci+    isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
5763b921b29Sopenharmony_ci+  if (htbl == NULL)
5773b921b29Sopenharmony_ci+    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
5783b921b29Sopenharmony_ci+
5793b921b29Sopenharmony_ci+  /* Allocate a workspace if we haven't already done so. */
5803b921b29Sopenharmony_ci+  if (*pdtbl == NULL)
5813b921b29Sopenharmony_ci+    *pdtbl = (d_derived_tbl *)
5823b921b29Sopenharmony_ci+      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
5833b921b29Sopenharmony_ci+                                  sizeof(d_derived_tbl));
5843b921b29Sopenharmony_ci+  dtbl = *pdtbl;
5853b921b29Sopenharmony_ci+  dtbl->pub = htbl;             /* fill in back link */
5863b921b29Sopenharmony_ci+
5873b921b29Sopenharmony_ci+  /* Figure C.1: make table of Huffman code length for each symbol */
5883b921b29Sopenharmony_ci+
5893b921b29Sopenharmony_ci+  p = 0;
5903b921b29Sopenharmony_ci+  for (l = 1; l <= MAX_HUFF_CODE_LEN; l++) {
5913b921b29Sopenharmony_ci+    i = (int)htbl->bits[l];
5923b921b29Sopenharmony_ci+    if (i < 0 || p + i > 256)   /* protect against table overrun, 256 is the max number of symbols */
5933b921b29Sopenharmony_ci+      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
5943b921b29Sopenharmony_ci+    while (i--)
5953b921b29Sopenharmony_ci+      huffsize[p++] = (char)l;
5963b921b29Sopenharmony_ci+  }
5973b921b29Sopenharmony_ci+  huffsize[p] = 0;
5983b921b29Sopenharmony_ci+  numsymbols = p;
5993b921b29Sopenharmony_ci+
6003b921b29Sopenharmony_ci+  /* Figure C.2: generate the codes themselves */
6013b921b29Sopenharmony_ci+  /* We also validate that the counts represent a legal Huffman code tree. */
6023b921b29Sopenharmony_ci+
6033b921b29Sopenharmony_ci+  code = 0;
6043b921b29Sopenharmony_ci+  si = huffsize[0];
6053b921b29Sopenharmony_ci+  p = 0;
6063b921b29Sopenharmony_ci+  while (huffsize[p]) {
6073b921b29Sopenharmony_ci+    while (((int)huffsize[p]) == si) {
6083b921b29Sopenharmony_ci+      huffcode[p++] = code;
6093b921b29Sopenharmony_ci+      code++;
6103b921b29Sopenharmony_ci+    }
6113b921b29Sopenharmony_ci+    /* code is now 1 more than the last code used for codelength si; but
6123b921b29Sopenharmony_ci+     * it must still fit in si bits, since no code is allowed to be all ones.
6133b921b29Sopenharmony_ci+     */
6143b921b29Sopenharmony_ci+    if (((JLONG)code) >= (((JLONG)1) << si))
6153b921b29Sopenharmony_ci+      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
6163b921b29Sopenharmony_ci+    code <<= 1;
6173b921b29Sopenharmony_ci+    si++;
6183b921b29Sopenharmony_ci+  }
6193b921b29Sopenharmony_ci+
6203b921b29Sopenharmony_ci+  /* Figure F.15: generate decoding tables for bit-sequential decoding */
6213b921b29Sopenharmony_ci+
6223b921b29Sopenharmony_ci+  p = 0;
6233b921b29Sopenharmony_ci+  for (l = 1; l <= MAX_HUFF_CODE_LEN; l++) {
6243b921b29Sopenharmony_ci+    if (htbl->bits[l]) {
6253b921b29Sopenharmony_ci+      /* valoffset[l] = huffval[] index of 1st symbol of code length l,
6263b921b29Sopenharmony_ci+       * minus the minimum code of length l
6273b921b29Sopenharmony_ci+       */
6283b921b29Sopenharmony_ci+      dtbl->valoffset[l] = (JLONG)p - (JLONG)huffcode[p];
6293b921b29Sopenharmony_ci+      p += htbl->bits[l];
6303b921b29Sopenharmony_ci+      dtbl->maxcode[l] = huffcode[p - 1]; /* maximum code of length l */
6313b921b29Sopenharmony_ci+    } else {
6323b921b29Sopenharmony_ci+      dtbl->maxcode[l] = -1;    /* -1 if no codes of this length */
6333b921b29Sopenharmony_ci+    }
6343b921b29Sopenharmony_ci+  }
6353b921b29Sopenharmony_ci+  dtbl->valoffset[17] = 0;  /* 17 is always max symbol length in Huffman spec */
6363b921b29Sopenharmony_ci+  dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates, 17 has the same meaning above */
6373b921b29Sopenharmony_ci+
6383b921b29Sopenharmony_ci+  /* Compute lookahead tables to speed up decoding.
6393b921b29Sopenharmony_ci+   * First we set all the table entries to 0, indicating "too long";
6403b921b29Sopenharmony_ci+   * then we iterate through the Huffman codes that are short enough and
6413b921b29Sopenharmony_ci+   * fill in all the entries that correspond to bit sequences starting
6423b921b29Sopenharmony_ci+   * with that code.
6433b921b29Sopenharmony_ci+   */
6443b921b29Sopenharmony_ci+
6453b921b29Sopenharmony_ci+  for (i = 0; i < (1 << HUFF_LOOKAHEAD); i++) {
6463b921b29Sopenharmony_ci+    dtbl->lookup[i] = (HUFF_LOOKAHEAD + 1) << HUFF_LOOKAHEAD;
6473b921b29Sopenharmony_ci+  }
6483b921b29Sopenharmony_ci+  if (!isDC) {
6493b921b29Sopenharmony_ci+    jpeg_make_d_ac_derived_tbl(htbl, dtbl, huffcode);
6503b921b29Sopenharmony_ci+  } else {
6513b921b29Sopenharmony_ci+    for (i = 0; i < (1 << HUFF_LOOKAHEAD); i++)
6523b921b29Sopenharmony_ci+      dtbl->lookup[i] = (HUFF_LOOKAHEAD + 1) << HUFF_LOOKAHEAD;
6533b921b29Sopenharmony_ci+    p = 0;
6543b921b29Sopenharmony_ci+    for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
6553b921b29Sopenharmony_ci+      for (i = 1; i <= (int)htbl->bits[l]; i++, p++) {
6563b921b29Sopenharmony_ci+        /* l = current code's length, p = its index in huffcode[] & huffval[]. */
6573b921b29Sopenharmony_ci+        /* Generate left-justified code followed by all possible bit sequences */
6583b921b29Sopenharmony_ci+        lookbits = huffcode[p] << (HUFF_LOOKAHEAD - l);
6593b921b29Sopenharmony_ci+        for (ctr = 1 << (HUFF_LOOKAHEAD - l); ctr > 0; ctr--) {
6603b921b29Sopenharmony_ci+          dtbl->lookup[lookbits] = (l << HUFF_LOOKAHEAD) | htbl->huffval[p];
6613b921b29Sopenharmony_ci+          lookbits++;
6623b921b29Sopenharmony_ci+        }
6633b921b29Sopenharmony_ci+      }
6643b921b29Sopenharmony_ci+    }
6653b921b29Sopenharmony_ci+  }
6663b921b29Sopenharmony_ci+
6673b921b29Sopenharmony_ci+  /* Validate symbols as being reasonable.
6683b921b29Sopenharmony_ci+   * For AC tables, we make no check, but accept all byte values 0..255.
6693b921b29Sopenharmony_ci+   * For DC tables, we require the symbols to be in range 0..15.
6703b921b29Sopenharmony_ci+   * (Tighter bounds could be applied depending on the data depth and mode,
6713b921b29Sopenharmony_ci+   * but this is sufficient to ensure safe decoding.)
6723b921b29Sopenharmony_ci+   */
6733b921b29Sopenharmony_ci+  if (isDC) {
6743b921b29Sopenharmony_ci+    for (i = 0; i < numsymbols; i++) {
6753b921b29Sopenharmony_ci+      int sym = htbl->huffval[i];
6763b921b29Sopenharmony_ci+      if (sym < 0 || sym > 15)  // 15 is the max value of DC symbol
6773b921b29Sopenharmony_ci+        ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
6783b921b29Sopenharmony_ci+    }
6793b921b29Sopenharmony_ci+  }
6803b921b29Sopenharmony_ci+}
6813b921b29Sopenharmony_ci+
6823b921b29Sopenharmony_ci+
6833b921b29Sopenharmony_ci+/*
6843b921b29Sopenharmony_ci+ * Out-of-line code for bit fetching (shared with jdphuff.c).
6853b921b29Sopenharmony_ci+ * See jdhuff.h for info about usage.
6863b921b29Sopenharmony_ci+ * Note: current values of get_buffer and bits_left are passed as parameters,
6873b921b29Sopenharmony_ci+ * but are returned in the corresponding fields of the state struct.
6883b921b29Sopenharmony_ci+ *
6893b921b29Sopenharmony_ci+ * On most machines MIN_GET_BITS should be 25 to allow the full 32-bit width
6903b921b29Sopenharmony_ci+ * of get_buffer to be used.  (On machines with wider words, an even larger
6913b921b29Sopenharmony_ci+ * buffer could be used.)  However, on some machines 32-bit shifts are
6923b921b29Sopenharmony_ci+ * quite slow and take time proportional to the number of places shifted.
6933b921b29Sopenharmony_ci+ * (This is true with most PC compilers, for instance.)  In this case it may
6943b921b29Sopenharmony_ci+ * be a win to set MIN_GET_BITS to the minimum value of 15.  This reduces the
6953b921b29Sopenharmony_ci+ * average shift distance at the cost of more calls to jpeg_fill_bit_buffer.
6963b921b29Sopenharmony_ci+ */
6973b921b29Sopenharmony_ci+
6983b921b29Sopenharmony_ci+#ifdef SLOW_SHIFT_32
6993b921b29Sopenharmony_ci+#define MIN_GET_BITS  15        /* minimum allowable value */
7003b921b29Sopenharmony_ci+#else
7013b921b29Sopenharmony_ci+#define MIN_GET_BITS  (BIT_BUF_SIZE - 7)
7023b921b29Sopenharmony_ci+#endif
7033b921b29Sopenharmony_ci+
7043b921b29Sopenharmony_ci+
7053b921b29Sopenharmony_ci+GLOBAL(boolean)
7063b921b29Sopenharmony_ci+jpeg_fill_bit_buffer(bitread_working_state *state,
7073b921b29Sopenharmony_ci+                     register bit_buf_type get_buffer, register int bits_left,
7083b921b29Sopenharmony_ci+                     int nbits)
7093b921b29Sopenharmony_ci+/* Load up the bit buffer to a depth of at least nbits */
7103b921b29Sopenharmony_ci+{
7113b921b29Sopenharmony_ci+  /* Copy heavily used state fields into locals (hopefully registers) */
7123b921b29Sopenharmony_ci+  register const JOCTET *next_input_byte = state->next_input_byte;
7133b921b29Sopenharmony_ci+  register size_t bytes_in_buffer = state->bytes_in_buffer;
7143b921b29Sopenharmony_ci+  j_decompress_ptr cinfo = state->cinfo;
7153b921b29Sopenharmony_ci+
7163b921b29Sopenharmony_ci+  /* Attempt to load at least MIN_GET_BITS bits into get_buffer. */
7173b921b29Sopenharmony_ci+  /* (It is assumed that no request will be for more than that many bits.) */
7183b921b29Sopenharmony_ci+  /* We fail to do so only if we hit a marker or are forced to suspend. */
7193b921b29Sopenharmony_ci+
7203b921b29Sopenharmony_ci+  if (cinfo->unread_marker == 0) {      /* cannot advance past a marker */
7213b921b29Sopenharmony_ci+    while (bits_left < MIN_GET_BITS) {
7223b921b29Sopenharmony_ci+      register int c;
7233b921b29Sopenharmony_ci+
7243b921b29Sopenharmony_ci+      /* Attempt to read a byte */
7253b921b29Sopenharmony_ci+      if (bytes_in_buffer == 0) {
7263b921b29Sopenharmony_ci+        if (!(*cinfo->src->fill_input_buffer) (cinfo))
7273b921b29Sopenharmony_ci+          return FALSE;
7283b921b29Sopenharmony_ci+        next_input_byte = cinfo->src->next_input_byte;
7293b921b29Sopenharmony_ci+        bytes_in_buffer = cinfo->src->bytes_in_buffer;
7303b921b29Sopenharmony_ci+      }
7313b921b29Sopenharmony_ci+      bytes_in_buffer--;
7323b921b29Sopenharmony_ci+      c = *next_input_byte++;
7333b921b29Sopenharmony_ci+
7343b921b29Sopenharmony_ci+      /* If it's 0xFF, check and discard stuffed zero byte */
7353b921b29Sopenharmony_ci+      if (c == 0xFF) {
7363b921b29Sopenharmony_ci+        /* Loop here to discard any padding FF's on terminating marker,
7373b921b29Sopenharmony_ci+         * so that we can save a valid unread_marker value.  NOTE: we will
7383b921b29Sopenharmony_ci+         * accept multiple FF's followed by a 0 as meaning a single FF data
7393b921b29Sopenharmony_ci+         * byte.  This data pattern is not valid according to the standard.
7403b921b29Sopenharmony_ci+         */
7413b921b29Sopenharmony_ci+        do {
7423b921b29Sopenharmony_ci+          if (bytes_in_buffer == 0) {
7433b921b29Sopenharmony_ci+            if (!(*cinfo->src->fill_input_buffer) (cinfo))
7443b921b29Sopenharmony_ci+              return FALSE;
7453b921b29Sopenharmony_ci+            next_input_byte = cinfo->src->next_input_byte;
7463b921b29Sopenharmony_ci+            bytes_in_buffer = cinfo->src->bytes_in_buffer;
7473b921b29Sopenharmony_ci+          }
7483b921b29Sopenharmony_ci+          bytes_in_buffer--;
7493b921b29Sopenharmony_ci+          c = *next_input_byte++;
7503b921b29Sopenharmony_ci+        } while (c == 0xFF);
7513b921b29Sopenharmony_ci+
7523b921b29Sopenharmony_ci+        if (c == 0) {
7533b921b29Sopenharmony_ci+          /* Found FF/00, which represents an FF data byte */
7543b921b29Sopenharmony_ci+          c = 0xFF;
7553b921b29Sopenharmony_ci+        } else {
7563b921b29Sopenharmony_ci+          /* Oops, it's actually a marker indicating end of compressed data.
7573b921b29Sopenharmony_ci+           * Save the marker code for later use.
7583b921b29Sopenharmony_ci+           * Fine point: it might appear that we should save the marker into
7593b921b29Sopenharmony_ci+           * bitread working state, not straight into permanent state.  But
7603b921b29Sopenharmony_ci+           * once we have hit a marker, we cannot need to suspend within the
7613b921b29Sopenharmony_ci+           * current MCU, because we will read no more bytes from the data
7623b921b29Sopenharmony_ci+           * source.  So it is OK to update permanent state right away.
7633b921b29Sopenharmony_ci+           */
7643b921b29Sopenharmony_ci+          cinfo->unread_marker = c;
7653b921b29Sopenharmony_ci+          /* See if we need to insert some fake zero bits. */
7663b921b29Sopenharmony_ci+          goto no_more_bytes;
7673b921b29Sopenharmony_ci+        }
7683b921b29Sopenharmony_ci+      }
7693b921b29Sopenharmony_ci+
7703b921b29Sopenharmony_ci+      /* OK, load c into get_buffer */
7713b921b29Sopenharmony_ci+      get_buffer = (get_buffer << 8) | c; // read 8 bits every time
7723b921b29Sopenharmony_ci+      bits_left += 8; // read 8 bits every time
7733b921b29Sopenharmony_ci+    } /* end while */
7743b921b29Sopenharmony_ci+  } else {
7753b921b29Sopenharmony_ci+no_more_bytes:
7763b921b29Sopenharmony_ci+    /* We get here if we've read the marker that terminates the compressed
7773b921b29Sopenharmony_ci+     * data segment.  There should be enough bits in the buffer register
7783b921b29Sopenharmony_ci+     * to satisfy the request; if so, no problem.
7793b921b29Sopenharmony_ci+     */
7803b921b29Sopenharmony_ci+    if (nbits > bits_left) {
7813b921b29Sopenharmony_ci+      /* Uh-oh.  Report corrupted data to user and stuff zeroes into
7823b921b29Sopenharmony_ci+       * the data stream, so that we can produce some kind of image.
7833b921b29Sopenharmony_ci+       * We use a nonvolatile flag to ensure that only one warning message
7843b921b29Sopenharmony_ci+       * appears per data segment.
7853b921b29Sopenharmony_ci+       */
7863b921b29Sopenharmony_ci+      if (!cinfo->entropy->insufficient_data) {
7873b921b29Sopenharmony_ci+        WARNMS(cinfo, JWRN_HIT_MARKER);
7883b921b29Sopenharmony_ci+        cinfo->entropy->insufficient_data = TRUE;
7893b921b29Sopenharmony_ci+      }
7903b921b29Sopenharmony_ci+      /* Fill the buffer with zero bits */
7913b921b29Sopenharmony_ci+      get_buffer <<= MIN_GET_BITS - bits_left;
7923b921b29Sopenharmony_ci+      bits_left = MIN_GET_BITS;
7933b921b29Sopenharmony_ci+    }
7943b921b29Sopenharmony_ci+  }
7953b921b29Sopenharmony_ci+
7963b921b29Sopenharmony_ci+  /* Unload the local registers */
7973b921b29Sopenharmony_ci+  state->next_input_byte = next_input_byte;
7983b921b29Sopenharmony_ci+  state->bytes_in_buffer = bytes_in_buffer;
7993b921b29Sopenharmony_ci+  state->get_buffer = get_buffer;
8003b921b29Sopenharmony_ci+  state->bits_left = bits_left;
8013b921b29Sopenharmony_ci+
8023b921b29Sopenharmony_ci+  return TRUE;
8033b921b29Sopenharmony_ci+}
8043b921b29Sopenharmony_ci+
8053b921b29Sopenharmony_ci+
8063b921b29Sopenharmony_ci+/* Macro version of the above, which performs much better but does not
8073b921b29Sopenharmony_ci+   handle markers.  We have to hand off any blocks with markers to the
8083b921b29Sopenharmony_ci+   slower routines. */
8093b921b29Sopenharmony_ci+
8103b921b29Sopenharmony_ci+#define GET_BYTE { \
8113b921b29Sopenharmony_ci+  register int c0, c1; \
8123b921b29Sopenharmony_ci+  c0 = *buffer++; \
8133b921b29Sopenharmony_ci+  c1 = *buffer; \
8143b921b29Sopenharmony_ci+  /* Pre-execute most common case */ \
8153b921b29Sopenharmony_ci+  get_buffer = (get_buffer << 8) | c0; \
8163b921b29Sopenharmony_ci+  bits_left += 8; \
8173b921b29Sopenharmony_ci+  if (c0 == 0xFF) { \
8183b921b29Sopenharmony_ci+    /* Pre-execute case of FF/00, which represents an FF data byte */ \
8193b921b29Sopenharmony_ci+    buffer++; \
8203b921b29Sopenharmony_ci+    if (c1 != 0) { \
8213b921b29Sopenharmony_ci+      /* Oops, it's actually a marker indicating end of compressed data. */ \
8223b921b29Sopenharmony_ci+      cinfo->unread_marker = c1; \
8233b921b29Sopenharmony_ci+      /* Back out pre-execution and fill the buffer with zero bits */ \
8243b921b29Sopenharmony_ci+      buffer -= 2; \
8253b921b29Sopenharmony_ci+      get_buffer &= ~0xFF; \
8263b921b29Sopenharmony_ci+    } \
8273b921b29Sopenharmony_ci+  } \
8283b921b29Sopenharmony_ci+}
8293b921b29Sopenharmony_ci+
8303b921b29Sopenharmony_ci+#if SIZEOF_SIZE_T == 8 || defined(_WIN64) || (defined(__x86_64__) && defined(__ILP32__))
8313b921b29Sopenharmony_ci+
8323b921b29Sopenharmony_ci+/* Pre-fetch 48 bytes, because the holding register is 64-bit */
8333b921b29Sopenharmony_ci+#define FILL_BIT_BUFFER_FAST \
8343b921b29Sopenharmony_ci+  if (bits_left <= 16) { \
8353b921b29Sopenharmony_ci+    GET_BYTE GET_BYTE GET_BYTE GET_BYTE GET_BYTE GET_BYTE \
8363b921b29Sopenharmony_ci+  }
8373b921b29Sopenharmony_ci+
8383b921b29Sopenharmony_ci+#else
8393b921b29Sopenharmony_ci+
8403b921b29Sopenharmony_ci+/* Pre-fetch 16 bytes, because the holding register is 32-bit */
8413b921b29Sopenharmony_ci+#define FILL_BIT_BUFFER_FAST \
8423b921b29Sopenharmony_ci+  if (bits_left <= 16) { \
8433b921b29Sopenharmony_ci+    GET_BYTE GET_BYTE \
8443b921b29Sopenharmony_ci+  }
8453b921b29Sopenharmony_ci+
8463b921b29Sopenharmony_ci+#endif
8473b921b29Sopenharmony_ci+
8483b921b29Sopenharmony_ci+
8493b921b29Sopenharmony_ci+/*
8503b921b29Sopenharmony_ci+ * Out-of-line code for Huffman code decoding.
8513b921b29Sopenharmony_ci+ * See jdhuff.h for info about usage.
8523b921b29Sopenharmony_ci+ */
8533b921b29Sopenharmony_ci+
8543b921b29Sopenharmony_ci+GLOBAL(int)
8553b921b29Sopenharmony_ci+jpeg_huff_decode(bitread_working_state *state,
8563b921b29Sopenharmony_ci+                 register bit_buf_type get_buffer, register int bits_left,
8573b921b29Sopenharmony_ci+                 d_derived_tbl *htbl, int min_bits)
8583b921b29Sopenharmony_ci+{
8593b921b29Sopenharmony_ci+  register int l = min_bits;
8603b921b29Sopenharmony_ci+  register JLONG code;
8613b921b29Sopenharmony_ci+
8623b921b29Sopenharmony_ci+  /* HUFF_DECODE has determined that the code is at least min_bits */
8633b921b29Sopenharmony_ci+  /* bits long, so fetch that many bits in one swoop. */
8643b921b29Sopenharmony_ci+
8653b921b29Sopenharmony_ci+  CHECK_BIT_BUFFER(*state, l, return -1);
8663b921b29Sopenharmony_ci+  code = GET_BITS(l);
8673b921b29Sopenharmony_ci+
8683b921b29Sopenharmony_ci+  /* Collect the rest of the Huffman code one bit at a time. */
8693b921b29Sopenharmony_ci+  /* This is per Figure F.16. */
8703b921b29Sopenharmony_ci+
8713b921b29Sopenharmony_ci+  while (code > htbl->maxcode[l]) {
8723b921b29Sopenharmony_ci+    code <<= 1;
8733b921b29Sopenharmony_ci+    CHECK_BIT_BUFFER(*state, 1, return -1);
8743b921b29Sopenharmony_ci+    code |= GET_BITS(1);
8753b921b29Sopenharmony_ci+    l++;
8763b921b29Sopenharmony_ci+  }
8773b921b29Sopenharmony_ci+
8783b921b29Sopenharmony_ci+  /* Unload the local registers */
8793b921b29Sopenharmony_ci+  state->get_buffer = get_buffer;
8803b921b29Sopenharmony_ci+  state->bits_left = bits_left;
8813b921b29Sopenharmony_ci+
8823b921b29Sopenharmony_ci+  /* With garbage input we may reach the sentinel value l = 17. */
8833b921b29Sopenharmony_ci+
8843b921b29Sopenharmony_ci+  if (l > MAX_HUFF_CODE_LEN) {
8853b921b29Sopenharmony_ci+    WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
8863b921b29Sopenharmony_ci+    return 0;                   /* fake a zero as the safest result */
8873b921b29Sopenharmony_ci+  }
8883b921b29Sopenharmony_ci+
8893b921b29Sopenharmony_ci+  return htbl->pub->huffval[(int)(code + htbl->valoffset[l])];
8903b921b29Sopenharmony_ci+}
8913b921b29Sopenharmony_ci+
8923b921b29Sopenharmony_ci+/*
8933b921b29Sopenharmony_ci+ * Check for a restart marker & resynchronize decoder.
8943b921b29Sopenharmony_ci+ * Returns FALSE if must suspend.
8953b921b29Sopenharmony_ci+ */
8963b921b29Sopenharmony_ci+
8973b921b29Sopenharmony_ci+LOCAL(boolean)
8983b921b29Sopenharmony_ci+process_restart(j_decompress_ptr cinfo)
8993b921b29Sopenharmony_ci+{
9003b921b29Sopenharmony_ci+  huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
9013b921b29Sopenharmony_ci+  int ci;
9023b921b29Sopenharmony_ci+
9033b921b29Sopenharmony_ci+  /* Throw away any unused bits remaining in bit buffer; */
9043b921b29Sopenharmony_ci+  /* include any full bytes in next_marker's count of discarded bytes */
9053b921b29Sopenharmony_ci+  cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8; // 8 bits in a byte
9063b921b29Sopenharmony_ci+  entropy->bitstate.bits_left = 0;
9073b921b29Sopenharmony_ci+
9083b921b29Sopenharmony_ci+  /* Advance past the RSTn marker */
9093b921b29Sopenharmony_ci+  if (!(*cinfo->marker->read_restart_marker) (cinfo))
9103b921b29Sopenharmony_ci+    return FALSE;
9113b921b29Sopenharmony_ci+
9123b921b29Sopenharmony_ci+  /* Re-initialize DC predictions to 0 */
9133b921b29Sopenharmony_ci+  for (ci = 0; ci < cinfo->comps_in_scan; ci++)
9143b921b29Sopenharmony_ci+    entropy->saved.last_dc_val[ci] = 0;
9153b921b29Sopenharmony_ci+
9163b921b29Sopenharmony_ci+  /* Reset restart counter */
9173b921b29Sopenharmony_ci+  entropy->restarts_to_go = cinfo->restart_interval;
9183b921b29Sopenharmony_ci+
9193b921b29Sopenharmony_ci+  /* Reset out-of-data flag, unless read_restart_marker left us smack up
9203b921b29Sopenharmony_ci+   * against a marker.  In that case we will end up treating the next data
9213b921b29Sopenharmony_ci+   * segment as empty, and we can avoid producing bogus output pixels by
9223b921b29Sopenharmony_ci+   * leaving the flag set.
9233b921b29Sopenharmony_ci+   */
9243b921b29Sopenharmony_ci+  if (cinfo->unread_marker == 0)
9253b921b29Sopenharmony_ci+    entropy->pub.insufficient_data = FALSE;
9263b921b29Sopenharmony_ci+
9273b921b29Sopenharmony_ci+  return TRUE;
9283b921b29Sopenharmony_ci+}
9293b921b29Sopenharmony_ci+
9303b921b29Sopenharmony_ci+
9313b921b29Sopenharmony_ci+#if defined(__has_feature)
9323b921b29Sopenharmony_ci+#if __has_feature(undefined_behavior_sanitizer)
9333b921b29Sopenharmony_ci+__attribute__((no_sanitize("signed-integer-overflow"),
9343b921b29Sopenharmony_ci+               no_sanitize("unsigned-integer-overflow")))
9353b921b29Sopenharmony_ci+#endif
9363b921b29Sopenharmony_ci+#endif
9373b921b29Sopenharmony_ci+LOCAL(boolean)
9383b921b29Sopenharmony_ci+decode_mcu_slow(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
9393b921b29Sopenharmony_ci+{
9403b921b29Sopenharmony_ci+  huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
9413b921b29Sopenharmony_ci+  BITREAD_STATE_VARS;
9423b921b29Sopenharmony_ci+  int blkn;
9433b921b29Sopenharmony_ci+  savable_state state;
9443b921b29Sopenharmony_ci+  /* Outer loop handles each block in the MCU */
9453b921b29Sopenharmony_ci+
9463b921b29Sopenharmony_ci+  /* Load up working state */
9473b921b29Sopenharmony_ci+  BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
9483b921b29Sopenharmony_ci+  state = entropy->saved;
9493b921b29Sopenharmony_ci+
9503b921b29Sopenharmony_ci+  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
9513b921b29Sopenharmony_ci+    JBLOCKROW block = MCU_data ? MCU_data[blkn] : NULL;
9523b921b29Sopenharmony_ci+    d_derived_tbl *dctbl = entropy->dc_cur_tbls[blkn];
9533b921b29Sopenharmony_ci+    d_derived_tbl *actbl = entropy->ac_cur_tbls[blkn];
9543b921b29Sopenharmony_ci+    register int s, k, r;
9553b921b29Sopenharmony_ci+
9563b921b29Sopenharmony_ci+    /* Decode a single block's worth of coefficients */
9573b921b29Sopenharmony_ci+
9583b921b29Sopenharmony_ci+    /* Section F.2.2.1: decode the DC coefficient difference */
9593b921b29Sopenharmony_ci+    HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
9603b921b29Sopenharmony_ci+    if (s) {
9613b921b29Sopenharmony_ci+      CHECK_BIT_BUFFER(br_state, s, return FALSE);
9623b921b29Sopenharmony_ci+      r = GET_BITS(s);
9633b921b29Sopenharmony_ci+      s = HUFF_EXTEND(r, s);
9643b921b29Sopenharmony_ci+    }
9653b921b29Sopenharmony_ci+
9663b921b29Sopenharmony_ci+    if (entropy->dc_needed[blkn]) {
9673b921b29Sopenharmony_ci+      /* Convert DC difference to actual value, update last_dc_val */
9683b921b29Sopenharmony_ci+      int ci = cinfo->MCU_membership[blkn];
9693b921b29Sopenharmony_ci+      /* Certain malformed JPEG images produce repeated DC coefficient
9703b921b29Sopenharmony_ci+       * differences of 2047 or -2047, which causes state.last_dc_val[ci] to
9713b921b29Sopenharmony_ci+       * grow until it overflows or underflows a 32-bit signed integer.  This
9723b921b29Sopenharmony_ci+       * behavior is, to the best of our understanding, innocuous, and it is
9733b921b29Sopenharmony_ci+       * unclear how to work around it without potentially affecting
9743b921b29Sopenharmony_ci+       * performance.  Thus, we (hopefully temporarily) suppress UBSan integer
9753b921b29Sopenharmony_ci+       * overflow errors for this function and decode_mcu_fast().
9763b921b29Sopenharmony_ci+       */
9773b921b29Sopenharmony_ci+      s += state.last_dc_val[ci];
9783b921b29Sopenharmony_ci+      state.last_dc_val[ci] = s;
9793b921b29Sopenharmony_ci+      if (block) {
9803b921b29Sopenharmony_ci+        /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */
9813b921b29Sopenharmony_ci+        (*block)[0] = (JCOEF)s;
9823b921b29Sopenharmony_ci+      }
9833b921b29Sopenharmony_ci+    }
9843b921b29Sopenharmony_ci+
9853b921b29Sopenharmony_ci+    if (entropy->ac_needed[blkn] && block) {
9863b921b29Sopenharmony_ci+      /* Section F.2.2.2: decode the AC coefficients */
9873b921b29Sopenharmony_ci+      /* Since zeroes are skipped, output area must be cleared beforehand */
9883b921b29Sopenharmony_ci+      for (k = 1; k < DCTSIZE2; k++) {
9893b921b29Sopenharmony_ci+        register int nb, look;
9903b921b29Sopenharmony_ci+        if (bits_left < HUFF_LOOKAHEAD) {
9913b921b29Sopenharmony_ci+          if (!jpeg_fill_bit_buffer(&br_state, get_buffer, bits_left, 0)) {
9923b921b29Sopenharmony_ci+            return FALSE;
9933b921b29Sopenharmony_ci+          }
9943b921b29Sopenharmony_ci+          get_buffer = br_state.get_buffer;
9953b921b29Sopenharmony_ci+          bits_left = br_state.bits_left;
9963b921b29Sopenharmony_ci+          if (bits_left < HUFF_LOOKAHEAD) {
9973b921b29Sopenharmony_ci+            nb = 1;
9983b921b29Sopenharmony_ci+            goto slowlabel;
9993b921b29Sopenharmony_ci+          }
10003b921b29Sopenharmony_ci+        }
10013b921b29Sopenharmony_ci+        look = PEEK_BITS(HUFF_LOOKAHEAD);
10023b921b29Sopenharmony_ci+        r = actbl->lookup[look];
10033b921b29Sopenharmony_ci+        nb = GET_NB(r);
10043b921b29Sopenharmony_ci+        unsigned int zero_num;
10053b921b29Sopenharmony_ci+        unsigned int coef_bits = GET_COEF_BITS(r);
10063b921b29Sopenharmony_ci+        if (nb <= HUFF_LOOKAHEAD) {
10073b921b29Sopenharmony_ci+          DROP_BITS(nb);
10083b921b29Sopenharmony_ci+          s = actbl->lookup[look] & ((1 << HUFF_LOOKAHEAD) - 1);
10093b921b29Sopenharmony_ci+          zero_num = GET_ZERO_NUM1(r);
10103b921b29Sopenharmony_ci+          k += zero_num;
10113b921b29Sopenharmony_ci+          if (coef_bits == 0) {
10123b921b29Sopenharmony_ci+            s = GET_COEF1(r);
10133b921b29Sopenharmony_ci+            (*block)[jpeg_natural_order[k]] = (JCOEF)s;
10143b921b29Sopenharmony_ci+          } else {
10153b921b29Sopenharmony_ci+            CHECK_BIT_BUFFER(br_state, (int)coef_bits, return FALSE);
10163b921b29Sopenharmony_ci+            r = GET_BITS(coef_bits);
10173b921b29Sopenharmony_ci+            s = HUFF_EXTEND(r, coef_bits);
10183b921b29Sopenharmony_ci+            (*block)[jpeg_natural_order[k]] = (JCOEF)s;
10193b921b29Sopenharmony_ci+          }
10203b921b29Sopenharmony_ci+        } else {
10213b921b29Sopenharmony_ci+        slowlabel:
10223b921b29Sopenharmony_ci+          nb = 1;
10233b921b29Sopenharmony_ci+          if ((s = jpeg_huff_decode(&br_state, get_buffer, bits_left, actbl, nb)) < 0) { return FALSE; }
10243b921b29Sopenharmony_ci+          get_buffer = br_state.get_buffer;
10253b921b29Sopenharmony_ci+          bits_left = br_state.bits_left;
10263b921b29Sopenharmony_ci+
10273b921b29Sopenharmony_ci+          r = s >> 4; // get higher 4 bits
10283b921b29Sopenharmony_ci+          s &= 15;  // use 15 as a mask to get the lower 4 bits
10293b921b29Sopenharmony_ci+
10303b921b29Sopenharmony_ci+          if (s) {
10313b921b29Sopenharmony_ci+            k += r;
10323b921b29Sopenharmony_ci+            CHECK_BIT_BUFFER(br_state, s, return FALSE);
10333b921b29Sopenharmony_ci+            r = GET_BITS(s);
10343b921b29Sopenharmony_ci+            s = HUFF_EXTEND(r, s);
10353b921b29Sopenharmony_ci+            /* Output coefficient in natural (dezigzagged) order.
10363b921b29Sopenharmony_ci+             * Note: the extra entries in jpeg_natural_order[] will save us
10373b921b29Sopenharmony_ci+             * if k >= DCTSIZE2, which could happen if the data is corrupted.
10383b921b29Sopenharmony_ci+             */
10393b921b29Sopenharmony_ci+            (*block)[jpeg_natural_order[k]] = (JCOEF)s;
10403b921b29Sopenharmony_ci+          } else {
10413b921b29Sopenharmony_ci+            if (r != 15)  // 15 = 0xF0 is a special symbol means 16 zeros in RLE coding
10423b921b29Sopenharmony_ci+              break;
10433b921b29Sopenharmony_ci+            k += 15;  // use 15 to skip DCT coef zero
10443b921b29Sopenharmony_ci+          }
10453b921b29Sopenharmony_ci+        }
10463b921b29Sopenharmony_ci+      }
10473b921b29Sopenharmony_ci+    } else {
10483b921b29Sopenharmony_ci+      /* Section F.2.2.2: decode the AC coefficients */
10493b921b29Sopenharmony_ci+      /* In this path we just discard the values */
10503b921b29Sopenharmony_ci+      for (k = 1; k < DCTSIZE2; k++) {
10513b921b29Sopenharmony_ci+        register int nb, look;
10523b921b29Sopenharmony_ci+        if (bits_left < HUFF_LOOKAHEAD) {
10533b921b29Sopenharmony_ci+          if (!jpeg_fill_bit_buffer(&br_state, get_buffer, bits_left, 0)) {
10543b921b29Sopenharmony_ci+            return FALSE;
10553b921b29Sopenharmony_ci+          }
10563b921b29Sopenharmony_ci+          get_buffer = br_state.get_buffer;
10573b921b29Sopenharmony_ci+          bits_left = br_state.bits_left;
10583b921b29Sopenharmony_ci+          if (bits_left < HUFF_LOOKAHEAD) {
10593b921b29Sopenharmony_ci+            nb = 1;
10603b921b29Sopenharmony_ci+            goto slowlabel2;
10613b921b29Sopenharmony_ci+          }
10623b921b29Sopenharmony_ci+        }
10633b921b29Sopenharmony_ci+        look = PEEK_BITS(HUFF_LOOKAHEAD);
10643b921b29Sopenharmony_ci+        r = actbl->lookup[look];
10653b921b29Sopenharmony_ci+        nb = GET_NB(r);
10663b921b29Sopenharmony_ci+        unsigned int zero_num;
10673b921b29Sopenharmony_ci+        unsigned int coef_bits = GET_COEF_BITS(r);
10683b921b29Sopenharmony_ci+        if (nb <= HUFF_LOOKAHEAD) {
10693b921b29Sopenharmony_ci+          DROP_BITS(nb);
10703b921b29Sopenharmony_ci+          s = actbl->lookup[look] & ((1 << HUFF_LOOKAHEAD) - 1);
10713b921b29Sopenharmony_ci+          zero_num = GET_ZERO_NUM1(r);
10723b921b29Sopenharmony_ci+          k += zero_num;
10733b921b29Sopenharmony_ci+          if (coef_bits != 0) {
10743b921b29Sopenharmony_ci+            CHECK_BIT_BUFFER(br_state, (int)coef_bits, return FALSE);
10753b921b29Sopenharmony_ci+            DROP_BITS(coef_bits);
10763b921b29Sopenharmony_ci+          }
10773b921b29Sopenharmony_ci+        } else {
10783b921b29Sopenharmony_ci+        slowlabel2:
10793b921b29Sopenharmony_ci+          nb = 1;
10803b921b29Sopenharmony_ci+          if ((s = jpeg_huff_decode(&br_state, get_buffer, bits_left, actbl, nb)) < 0) { return FALSE; }
10813b921b29Sopenharmony_ci+          get_buffer = br_state.get_buffer;
10823b921b29Sopenharmony_ci+          bits_left = br_state.bits_left;
10833b921b29Sopenharmony_ci+
10843b921b29Sopenharmony_ci+          r = s >> 4; // get higher 4 bits
10853b921b29Sopenharmony_ci+          s &= 15; // use 15 as a mask to get the lower 4 bits
10863b921b29Sopenharmony_ci+
10873b921b29Sopenharmony_ci+          if (s) {
10883b921b29Sopenharmony_ci+            k += r;
10893b921b29Sopenharmony_ci+            CHECK_BIT_BUFFER(br_state, s, return FALSE);
10903b921b29Sopenharmony_ci+            DROP_BITS(s);
10913b921b29Sopenharmony_ci+          } else {
10923b921b29Sopenharmony_ci+            if (r != 15) // 15 = 0xF0 is a special symbol means 16 zeros in RLE coding
10933b921b29Sopenharmony_ci+              break;
10943b921b29Sopenharmony_ci+            k += 15;  // use 15 to skip DCT coef zero
10953b921b29Sopenharmony_ci+          }
10963b921b29Sopenharmony_ci+        }
10973b921b29Sopenharmony_ci+      }
10983b921b29Sopenharmony_ci+    }
10993b921b29Sopenharmony_ci+  }
11003b921b29Sopenharmony_ci+
11013b921b29Sopenharmony_ci+  /* Completed MCU, so update state */
11023b921b29Sopenharmony_ci+  BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
11033b921b29Sopenharmony_ci+  entropy->saved = state;
11043b921b29Sopenharmony_ci+  return TRUE;
11053b921b29Sopenharmony_ci+}
11063b921b29Sopenharmony_ci+
11073b921b29Sopenharmony_ci+
11083b921b29Sopenharmony_ci+#if defined(__has_feature)
11093b921b29Sopenharmony_ci+#if __has_feature(undefined_behavior_sanitizer)
11103b921b29Sopenharmony_ci+__attribute__((no_sanitize("signed-integer-overflow"),
11113b921b29Sopenharmony_ci+               no_sanitize("unsigned-integer-overflow")))
11123b921b29Sopenharmony_ci+#endif
11133b921b29Sopenharmony_ci+#endif
11143b921b29Sopenharmony_ci+LOCAL(boolean)
11153b921b29Sopenharmony_ci+decode_mcu_fast(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
11163b921b29Sopenharmony_ci+{
11173b921b29Sopenharmony_ci+  huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
11183b921b29Sopenharmony_ci+  BITREAD_STATE_VARS;
11193b921b29Sopenharmony_ci+  JOCTET *buffer;
11203b921b29Sopenharmony_ci+  int blkn;
11213b921b29Sopenharmony_ci+  savable_state state;
11223b921b29Sopenharmony_ci+  /* Outer loop handles each block in the MCU */
11233b921b29Sopenharmony_ci+
11243b921b29Sopenharmony_ci+  /* Load up working state */
11253b921b29Sopenharmony_ci+  BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
11263b921b29Sopenharmony_ci+  buffer = (JOCTET *)br_state.next_input_byte;
11273b921b29Sopenharmony_ci+  state = entropy->saved;
11283b921b29Sopenharmony_ci+
11293b921b29Sopenharmony_ci+  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
11303b921b29Sopenharmony_ci+    JBLOCKROW block = MCU_data ? MCU_data[blkn] : NULL;
11313b921b29Sopenharmony_ci+    d_derived_tbl *dctbl = entropy->dc_cur_tbls[blkn];
11323b921b29Sopenharmony_ci+    d_derived_tbl *actbl = entropy->ac_cur_tbls[blkn];
11333b921b29Sopenharmony_ci+    register int s, k, r, l;
11343b921b29Sopenharmony_ci+
11353b921b29Sopenharmony_ci+    HUFF_DECODE_FAST(s, l, dctbl);
11363b921b29Sopenharmony_ci+    if (s) {
11373b921b29Sopenharmony_ci+      FILL_BIT_BUFFER_FAST
11383b921b29Sopenharmony_ci+      r = GET_BITS(s);
11393b921b29Sopenharmony_ci+      s = HUFF_EXTEND(r, s);
11403b921b29Sopenharmony_ci+    }
11413b921b29Sopenharmony_ci+
11423b921b29Sopenharmony_ci+    if (entropy->dc_needed[blkn]) {
11433b921b29Sopenharmony_ci+      int ci = cinfo->MCU_membership[blkn];
11443b921b29Sopenharmony_ci+      /* Refer to the comment in decode_mcu_slow() regarding the supression of
11453b921b29Sopenharmony_ci+       * a UBSan integer overflow error in this line of code.
11463b921b29Sopenharmony_ci+       */
11473b921b29Sopenharmony_ci+      s += state.last_dc_val[ci];
11483b921b29Sopenharmony_ci+      state.last_dc_val[ci] = s;
11493b921b29Sopenharmony_ci+      if (block)
11503b921b29Sopenharmony_ci+        (*block)[0] = (JCOEF)s;
11513b921b29Sopenharmony_ci+    }
11523b921b29Sopenharmony_ci+
11533b921b29Sopenharmony_ci+    if (entropy->ac_needed[blkn] && block) {
11543b921b29Sopenharmony_ci+      for (k = 1; k < DCTSIZE2; k++) {
11553b921b29Sopenharmony_ci+        FILL_BIT_BUFFER_FAST;
11563b921b29Sopenharmony_ci+        r = PEEK_BITS(HUFF_LOOKAHEAD);    // 先读取look_ahead位
11573b921b29Sopenharmony_ci+        r = actbl->lookup[r];
11583b921b29Sopenharmony_ci+        l = GET_NB(r);
11593b921b29Sopenharmony_ci+        unsigned int zero_num;
11603b921b29Sopenharmony_ci+        unsigned int coef_bits = GET_COEF_BITS(r);
11613b921b29Sopenharmony_ci+
11623b921b29Sopenharmony_ci+        if (l <= HUFF_LOOKAHEAD) {
11633b921b29Sopenharmony_ci+          zero_num = GET_ZERO_NUM1(r);
11643b921b29Sopenharmony_ci+          DROP_BITS(l);
11653b921b29Sopenharmony_ci+          if (coef_bits == 0) {
11663b921b29Sopenharmony_ci+            s = GET_COEF1(r);
11673b921b29Sopenharmony_ci+            k += zero_num;
11683b921b29Sopenharmony_ci+            (*block)[jpeg_natural_order[k]] = (JCOEF)s;
11693b921b29Sopenharmony_ci+          } else {
11703b921b29Sopenharmony_ci+            FILL_BIT_BUFFER_FAST
11713b921b29Sopenharmony_ci+            r = GET_BITS(coef_bits);
11723b921b29Sopenharmony_ci+            s = HUFF_EXTEND(r, coef_bits);
11733b921b29Sopenharmony_ci+            k += zero_num;
11743b921b29Sopenharmony_ci+            (*block)[jpeg_natural_order[k]] = (JCOEF)s;
11753b921b29Sopenharmony_ci+          }
11763b921b29Sopenharmony_ci+        } else {
11773b921b29Sopenharmony_ci+          unsigned int base = GET_BASE(r);  // 高16位为base
11783b921b29Sopenharmony_ci+          unsigned int offset_bits = GET_EXTRA_BITS(r);  // 低8位为offset_bits, l = nb 为二级表的最大码长
11793b921b29Sopenharmony_ci+          r = PEEK_BITS(l); // 前HUFF_LOOKAHEAD位已使用,只使用低nb - HUFF_LOOKAHEAD位, 取低offset_bits作为二级表索引
11803b921b29Sopenharmony_ci+          s = actbl->lookup[base + (r & ((1 << offset_bits) - 1))];
11813b921b29Sopenharmony_ci+          l = GET_NB(s); // 实际码长
11823b921b29Sopenharmony_ci+          coef_bits = GET_COEF_BITS(s);
11833b921b29Sopenharmony_ci+          zero_num = GET_ZERO_NUM1(s);
11843b921b29Sopenharmony_ci+          DROP_BITS(l);
11853b921b29Sopenharmony_ci+          if (coef_bits == 0xF) {
11863b921b29Sopenharmony_ci+            if (zero_num != 0xF) {
11873b921b29Sopenharmony_ci+              break;
11883b921b29Sopenharmony_ci+            } else {
11893b921b29Sopenharmony_ci+              k += 15; // use 15 to skip DCT coef zero
11903b921b29Sopenharmony_ci+            }
11913b921b29Sopenharmony_ci+          } else {
11923b921b29Sopenharmony_ci+            FILL_BIT_BUFFER_FAST
11933b921b29Sopenharmony_ci+            r = GET_BITS(coef_bits);
11943b921b29Sopenharmony_ci+            s = HUFF_EXTEND(r, coef_bits);
11953b921b29Sopenharmony_ci+            k += zero_num;
11963b921b29Sopenharmony_ci+            (*block)[jpeg_natural_order[k]] = (JCOEF)s;
11973b921b29Sopenharmony_ci+          }
11983b921b29Sopenharmony_ci+        }
11993b921b29Sopenharmony_ci+      }
12003b921b29Sopenharmony_ci+    } else {
12013b921b29Sopenharmony_ci+      for (k = 1; k < DCTSIZE2; k++) {
12023b921b29Sopenharmony_ci+        FILL_BIT_BUFFER_FAST;
12033b921b29Sopenharmony_ci+        r = PEEK_BITS(HUFF_LOOKAHEAD);    // 先读取look_ahead位
12043b921b29Sopenharmony_ci+        r = actbl->lookup[r];
12053b921b29Sopenharmony_ci+        l = GET_NB(r);
12063b921b29Sopenharmony_ci+        unsigned int zero_num;
12073b921b29Sopenharmony_ci+        unsigned int coef_bits = GET_COEF_BITS(r);
12083b921b29Sopenharmony_ci+
12093b921b29Sopenharmony_ci+        if (l <= HUFF_LOOKAHEAD) {
12103b921b29Sopenharmony_ci+          zero_num = GET_ZERO_NUM1(r);
12113b921b29Sopenharmony_ci+          DROP_BITS(l);
12123b921b29Sopenharmony_ci+          if (coef_bits == 0) {
12133b921b29Sopenharmony_ci+            s = GET_COEF1(r);
12143b921b29Sopenharmony_ci+            k += zero_num;
12153b921b29Sopenharmony_ci+          } else {
12163b921b29Sopenharmony_ci+            FILL_BIT_BUFFER_FAST
12173b921b29Sopenharmony_ci+            DROP_BITS(coef_bits);
12183b921b29Sopenharmony_ci+            k += zero_num;
12193b921b29Sopenharmony_ci+          }
12203b921b29Sopenharmony_ci+        } else {
12213b921b29Sopenharmony_ci+          unsigned int base = GET_BASE(r);  // 高16位为base
12223b921b29Sopenharmony_ci+          unsigned int offset_bits = GET_EXTRA_BITS(r);  // 低8位为offset_bits, l = nb 为二级表的最大码长
12233b921b29Sopenharmony_ci+          r = PEEK_BITS(l); // 前HUFF_LOOKAHEAD位已使用,只使用低nb - HUFF_LOOKAHEAD位, 取低offset_bits作为二级表索引
12243b921b29Sopenharmony_ci+          s = actbl->lookup[base + (r & ((1 << offset_bits) - 1))];
12253b921b29Sopenharmony_ci+          l = GET_NB(s); // 实际码长
12263b921b29Sopenharmony_ci+          coef_bits = GET_COEF_BITS(s);
12273b921b29Sopenharmony_ci+          zero_num = GET_ZERO_NUM1(s);
12283b921b29Sopenharmony_ci+          DROP_BITS(l);
12293b921b29Sopenharmony_ci+          if (coef_bits == 0xF) {
12303b921b29Sopenharmony_ci+            if (zero_num != 0xF) {
12313b921b29Sopenharmony_ci+              break;
12323b921b29Sopenharmony_ci+            } else {
12333b921b29Sopenharmony_ci+              k += 15; // use 15 to skip DCT coef zero
12343b921b29Sopenharmony_ci+            }
12353b921b29Sopenharmony_ci+          } else {
12363b921b29Sopenharmony_ci+            FILL_BIT_BUFFER_FAST
12373b921b29Sopenharmony_ci+            DROP_BITS(coef_bits);
12383b921b29Sopenharmony_ci+            k += zero_num;
12393b921b29Sopenharmony_ci+          }
12403b921b29Sopenharmony_ci+        }
12413b921b29Sopenharmony_ci+      }
12423b921b29Sopenharmony_ci+    }
12433b921b29Sopenharmony_ci+  }
12443b921b29Sopenharmony_ci+
12453b921b29Sopenharmony_ci+  if (cinfo->unread_marker != 0) {
12463b921b29Sopenharmony_ci+    cinfo->unread_marker = 0;
12473b921b29Sopenharmony_ci+    return FALSE;
12483b921b29Sopenharmony_ci+  }
12493b921b29Sopenharmony_ci+
12503b921b29Sopenharmony_ci+  br_state.bytes_in_buffer -= (buffer - br_state.next_input_byte);
12513b921b29Sopenharmony_ci+  br_state.next_input_byte = buffer;
12523b921b29Sopenharmony_ci+  BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
12533b921b29Sopenharmony_ci+  entropy->saved = state;
12543b921b29Sopenharmony_ci+  return TRUE;
12553b921b29Sopenharmony_ci+}
12563b921b29Sopenharmony_ci+
12573b921b29Sopenharmony_ci+
12583b921b29Sopenharmony_ci+/*
12593b921b29Sopenharmony_ci+ * Decode and return one MCU's worth of Huffman-compressed coefficients.
12603b921b29Sopenharmony_ci+ * The coefficients are reordered from zigzag order into natural array order,
12613b921b29Sopenharmony_ci+ * but are not dequantized.
12623b921b29Sopenharmony_ci+ *
12633b921b29Sopenharmony_ci+ * The i'th block of the MCU is stored into the block pointed to by
12643b921b29Sopenharmony_ci+ * MCU_data[i].  WE ASSUME THIS AREA HAS BEEN ZEROED BY THE CALLER.
12653b921b29Sopenharmony_ci+ * (Wholesale zeroing is usually a little faster than retail...)
12663b921b29Sopenharmony_ci+ *
12673b921b29Sopenharmony_ci+ * Returns FALSE if data source requested suspension.  In that case no
12683b921b29Sopenharmony_ci+ * changes have been made to permanent state.  (Exception: some output
12693b921b29Sopenharmony_ci+ * coefficients may already have been assigned.  This is harmless for
12703b921b29Sopenharmony_ci+ * this module, since we'll just re-assign them on the next call.)
12713b921b29Sopenharmony_ci+ */
12723b921b29Sopenharmony_ci+
12733b921b29Sopenharmony_ci+#define BUFSIZE  (DCTSIZE2 * 8)
12743b921b29Sopenharmony_ci+
12753b921b29Sopenharmony_ci+METHODDEF(boolean)
12763b921b29Sopenharmony_ci+decode_mcu(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
12773b921b29Sopenharmony_ci+{
12783b921b29Sopenharmony_ci+  huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
12793b921b29Sopenharmony_ci+  int usefast = 1;
12803b921b29Sopenharmony_ci+
12813b921b29Sopenharmony_ci+  /* Process restart marker if needed; may have to suspend */
12823b921b29Sopenharmony_ci+  if (cinfo->restart_interval) {
12833b921b29Sopenharmony_ci+    if (entropy->restarts_to_go == 0)
12843b921b29Sopenharmony_ci+      if (!process_restart(cinfo))
12853b921b29Sopenharmony_ci+        return FALSE;
12863b921b29Sopenharmony_ci+    usefast = 0;
12873b921b29Sopenharmony_ci+  }
12883b921b29Sopenharmony_ci+
12893b921b29Sopenharmony_ci+  if (cinfo->src->bytes_in_buffer < BUFSIZE * (size_t)cinfo->blocks_in_MCU ||
12903b921b29Sopenharmony_ci+      cinfo->unread_marker != 0)
12913b921b29Sopenharmony_ci+    usefast = 0;
12923b921b29Sopenharmony_ci+
12933b921b29Sopenharmony_ci+  /* If we've run out of data, just leave the MCU set to zeroes.
12943b921b29Sopenharmony_ci+   * This way, we return uniform gray for the remainder of the segment.
12953b921b29Sopenharmony_ci+   */
12963b921b29Sopenharmony_ci+  if (!entropy->pub.insufficient_data) {
12973b921b29Sopenharmony_ci+    if (usefast) {
12983b921b29Sopenharmony_ci+      if (!decode_mcu_fast(cinfo, MCU_data)) goto use_slow;
12993b921b29Sopenharmony_ci+    } else {
13003b921b29Sopenharmony_ci+use_slow:
13013b921b29Sopenharmony_ci+      if (!decode_mcu_slow(cinfo, MCU_data)) return FALSE;
13023b921b29Sopenharmony_ci+    }
13033b921b29Sopenharmony_ci+  }
13043b921b29Sopenharmony_ci+
13053b921b29Sopenharmony_ci+  /* Account for restart interval (no-op if not using restarts) */
13063b921b29Sopenharmony_ci+  if (cinfo->restart_interval)
13073b921b29Sopenharmony_ci+    entropy->restarts_to_go--;
13083b921b29Sopenharmony_ci+
13093b921b29Sopenharmony_ci+  return TRUE;
13103b921b29Sopenharmony_ci+}
13113b921b29Sopenharmony_ci+
13123b921b29Sopenharmony_ci+
13133b921b29Sopenharmony_ci+/*
13143b921b29Sopenharmony_ci+ * Module initialization routine for Huffman entropy decoding.
13153b921b29Sopenharmony_ci+ */
13163b921b29Sopenharmony_ci+
13173b921b29Sopenharmony_ci+GLOBAL(void)
13183b921b29Sopenharmony_ci+jinit_huff_decoder(j_decompress_ptr cinfo)
13193b921b29Sopenharmony_ci+{
13203b921b29Sopenharmony_ci+  huff_entropy_ptr entropy;
13213b921b29Sopenharmony_ci+  int i;
13223b921b29Sopenharmony_ci+
13233b921b29Sopenharmony_ci+  /* Motion JPEG frames typically do not include the Huffman tables if they
13243b921b29Sopenharmony_ci+     are the default tables.  Thus, if the tables are not set by the time
13253b921b29Sopenharmony_ci+     the Huffman decoder is initialized (usually within the body of
13263b921b29Sopenharmony_ci+     jpeg_start_decompress()), we set them to default values. */
13273b921b29Sopenharmony_ci+  std_huff_tables((j_common_ptr)cinfo);
13283b921b29Sopenharmony_ci+
13293b921b29Sopenharmony_ci+  entropy = (huff_entropy_ptr)
13303b921b29Sopenharmony_ci+    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
13313b921b29Sopenharmony_ci+                                sizeof(huff_entropy_decoder));
13323b921b29Sopenharmony_ci+  cinfo->entropy = (struct jpeg_entropy_decoder *)entropy;
13333b921b29Sopenharmony_ci+  entropy->pub.start_pass = start_pass_huff_decoder;
13343b921b29Sopenharmony_ci+  entropy->pub.decode_mcu = decode_mcu;
13353b921b29Sopenharmony_ci+
13363b921b29Sopenharmony_ci+  /* Mark tables unallocated */
13373b921b29Sopenharmony_ci+  for (i = 0; i < NUM_HUFF_TBLS; i++) {
13383b921b29Sopenharmony_ci+    entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
13393b921b29Sopenharmony_ci+  }
13403b921b29Sopenharmony_ci+}
13413b921b29Sopenharmony_cidiff --git a/jdphuff.c b/jdphuff.c
13423b921b29Sopenharmony_ciindex c6d82ca..25e3b1d 100644
13433b921b29Sopenharmony_ci--- a/jdphuff.c
13443b921b29Sopenharmony_ci+++ b/jdphuff.c
13453b921b29Sopenharmony_ci@@ -71,6 +71,129 @@ METHODDEF(boolean) decode_mcu_DC_refine(j_decompress_ptr cinfo,
13463b921b29Sopenharmony_ci METHODDEF(boolean) decode_mcu_AC_refine(j_decompress_ptr cinfo,
13473b921b29Sopenharmony_ci                                         JBLOCKROW *MCU_data);
13483b921b29Sopenharmony_ci 
13493b921b29Sopenharmony_ci+#ifdef HUFF_DECODE_OPT
13503b921b29Sopenharmony_ci+// OH ISSUE: jpeg optimize
13513b921b29Sopenharmony_ci+LOCAL(void)
13523b921b29Sopenharmony_ci+jpeg_make_dp_derived_tbl(j_decompress_ptr cinfo, boolean isDC, int tblno,
13533b921b29Sopenharmony_ci+                        d_derived_tbl **pdtbl)
13543b921b29Sopenharmony_ci+{
13553b921b29Sopenharmony_ci+  JHUFF_TBL *htbl;
13563b921b29Sopenharmony_ci+  d_derived_tbl *dtbl;
13573b921b29Sopenharmony_ci+  int p, i, l, si, numsymbols;
13583b921b29Sopenharmony_ci+  int lookbits, ctr;
13593b921b29Sopenharmony_ci+  char huffsize[257];
13603b921b29Sopenharmony_ci+  unsigned int huffcode[257];
13613b921b29Sopenharmony_ci+  unsigned int code;
13623b921b29Sopenharmony_ci+
13633b921b29Sopenharmony_ci+  /* Note that huffsize[] and huffcode[] are filled in code-length order,
13643b921b29Sopenharmony_ci+   * paralleling the order of the symbols themselves in htbl->huffval[].
13653b921b29Sopenharmony_ci+   */
13663b921b29Sopenharmony_ci+
13673b921b29Sopenharmony_ci+  /* Find the input Huffman table */
13683b921b29Sopenharmony_ci+  if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
13693b921b29Sopenharmony_ci+    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
13703b921b29Sopenharmony_ci+  htbl =
13713b921b29Sopenharmony_ci+    isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
13723b921b29Sopenharmony_ci+  if (htbl == NULL)
13733b921b29Sopenharmony_ci+    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
13743b921b29Sopenharmony_ci+
13753b921b29Sopenharmony_ci+  /* Allocate a workspace if we haven't already done so. */
13763b921b29Sopenharmony_ci+  if (*pdtbl == NULL)
13773b921b29Sopenharmony_ci+    *pdtbl = (d_derived_tbl *)
13783b921b29Sopenharmony_ci+      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
13793b921b29Sopenharmony_ci+                                  sizeof(d_derived_tbl));
13803b921b29Sopenharmony_ci+  dtbl = *pdtbl;
13813b921b29Sopenharmony_ci+  dtbl->pub = htbl;             /* fill in back link */
13823b921b29Sopenharmony_ci+
13833b921b29Sopenharmony_ci+  /* Figure C.1: make table of Huffman code length for each symbol */
13843b921b29Sopenharmony_ci+
13853b921b29Sopenharmony_ci+  p = 0;
13863b921b29Sopenharmony_ci+  for (l = 1; l <= MAX_HUFF_CODE_LEN; l++) {
13873b921b29Sopenharmony_ci+    i = (int)htbl->bits[l];
13883b921b29Sopenharmony_ci+    if (i < 0 || p + i > 256)   /* protect against table overrun, 256 is the max number of symbols */
13893b921b29Sopenharmony_ci+      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
13903b921b29Sopenharmony_ci+    while (i--)
13913b921b29Sopenharmony_ci+      huffsize[p++] = (char)l;
13923b921b29Sopenharmony_ci+  }
13933b921b29Sopenharmony_ci+  huffsize[p] = 0;
13943b921b29Sopenharmony_ci+  numsymbols = p;
13953b921b29Sopenharmony_ci+
13963b921b29Sopenharmony_ci+  /* Figure C.2: generate the codes themselves */
13973b921b29Sopenharmony_ci+  /* We also validate that the counts represent a legal Huffman code tree. */
13983b921b29Sopenharmony_ci+
13993b921b29Sopenharmony_ci+  code = 0;
14003b921b29Sopenharmony_ci+  si = huffsize[0];
14013b921b29Sopenharmony_ci+  p = 0;
14023b921b29Sopenharmony_ci+  while (huffsize[p]) {
14033b921b29Sopenharmony_ci+    while (((int)huffsize[p]) == si) {
14043b921b29Sopenharmony_ci+      huffcode[p++] = code;
14053b921b29Sopenharmony_ci+      code++;
14063b921b29Sopenharmony_ci+    }
14073b921b29Sopenharmony_ci+    /* code is now 1 more than the last code used for codelength si; but
14083b921b29Sopenharmony_ci+     * it must still fit in si bits, since no code is allowed to be all ones.
14093b921b29Sopenharmony_ci+     */
14103b921b29Sopenharmony_ci+    if (((JLONG)code) >= (((JLONG)1) << si))
14113b921b29Sopenharmony_ci+      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
14123b921b29Sopenharmony_ci+    code <<= 1;
14133b921b29Sopenharmony_ci+    si++;
14143b921b29Sopenharmony_ci+  }
14153b921b29Sopenharmony_ci+
14163b921b29Sopenharmony_ci+  /* Figure F.15: generate decoding tables for bit-sequential decoding */
14173b921b29Sopenharmony_ci+
14183b921b29Sopenharmony_ci+  p = 0;
14193b921b29Sopenharmony_ci+  for (l = 1; l <= MAX_HUFF_CODE_LEN; l++) {
14203b921b29Sopenharmony_ci+    if (htbl->bits[l]) {
14213b921b29Sopenharmony_ci+      /* valoffset[l] = huffval[] index of 1st symbol of code length l,
14223b921b29Sopenharmony_ci+       * minus the minimum code of length l
14233b921b29Sopenharmony_ci+       */
14243b921b29Sopenharmony_ci+      dtbl->valoffset[l] = (JLONG)p - (JLONG)huffcode[p];
14253b921b29Sopenharmony_ci+      p += htbl->bits[l];
14263b921b29Sopenharmony_ci+      dtbl->maxcode[l] = huffcode[p - 1]; /* maximum code of length l */
14273b921b29Sopenharmony_ci+    } else {
14283b921b29Sopenharmony_ci+      dtbl->maxcode[l] = -1;    /* -1 if no codes of this length */
14293b921b29Sopenharmony_ci+    }
14303b921b29Sopenharmony_ci+  }
14313b921b29Sopenharmony_ci+  dtbl->valoffset[17] = 0; /* 17 is always max symbol length in Huffman spec */
14323b921b29Sopenharmony_ci+  dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates, 17 has the same meaning above */
14333b921b29Sopenharmony_ci+
14343b921b29Sopenharmony_ci+  /* Compute lookahead tables to speed up decoding.
14353b921b29Sopenharmony_ci+   * First we set all the table entries to 0, indicating "too long";
14363b921b29Sopenharmony_ci+   * then we iterate through the Huffman codes that are short enough and
14373b921b29Sopenharmony_ci+   * fill in all the entries that correspond to bit sequences starting
14383b921b29Sopenharmony_ci+   * with that code.
14393b921b29Sopenharmony_ci+   */
14403b921b29Sopenharmony_ci+
14413b921b29Sopenharmony_ci+  for (i = 0; i < (1 << HUFF_LOOKAHEAD); i++)
14423b921b29Sopenharmony_ci+    dtbl->lookup[i] = (HUFF_LOOKAHEAD + 1) << HUFF_LOOKAHEAD;
14433b921b29Sopenharmony_ci+
14443b921b29Sopenharmony_ci+  p = 0;
14453b921b29Sopenharmony_ci+  for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
14463b921b29Sopenharmony_ci+    for (i = 1; i <= (int)htbl->bits[l]; i++, p++) {
14473b921b29Sopenharmony_ci+      /* l = current code's length, p = its index in huffcode[] & huffval[]. */
14483b921b29Sopenharmony_ci+      /* Generate left-justified code followed by all possible bit sequences */
14493b921b29Sopenharmony_ci+      lookbits = huffcode[p] << (HUFF_LOOKAHEAD - l);
14503b921b29Sopenharmony_ci+      for (ctr = 1 << (HUFF_LOOKAHEAD - l); ctr > 0; ctr--) {
14513b921b29Sopenharmony_ci+        dtbl->lookup[lookbits] = (l << HUFF_LOOKAHEAD) | htbl->huffval[p];
14523b921b29Sopenharmony_ci+        lookbits++;
14533b921b29Sopenharmony_ci+      }
14543b921b29Sopenharmony_ci+    }
14553b921b29Sopenharmony_ci+  }
14563b921b29Sopenharmony_ci+
14573b921b29Sopenharmony_ci+  /* Validate symbols as being reasonable.
14583b921b29Sopenharmony_ci+   * For AC tables, we make no check, but accept all byte values 0..255.
14593b921b29Sopenharmony_ci+   * For DC tables, we require the symbols to be in range 0..15.
14603b921b29Sopenharmony_ci+   * (Tighter bounds could be applied depending on the data depth and mode,
14613b921b29Sopenharmony_ci+   * but this is sufficient to ensure safe decoding.)
14623b921b29Sopenharmony_ci+   */
14633b921b29Sopenharmony_ci+  if (isDC) {
14643b921b29Sopenharmony_ci+    for (i = 0; i < numsymbols; i++) {
14653b921b29Sopenharmony_ci+      int sym = htbl->huffval[i];
14663b921b29Sopenharmony_ci+      if (sym < 0 || sym > 15) // 15 is the max value of DC symbol
14673b921b29Sopenharmony_ci+        ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
14683b921b29Sopenharmony_ci+    }
14693b921b29Sopenharmony_ci+  }
14703b921b29Sopenharmony_ci+}
14713b921b29Sopenharmony_ci+#endif
14723b921b29Sopenharmony_ci 
14733b921b29Sopenharmony_ci /*
14743b921b29Sopenharmony_ci  * Initialize for a Huffman-compressed scan.
14753b921b29Sopenharmony_ci@@ -163,12 +286,22 @@ start_pass_phuff_decoder(j_decompress_ptr cinfo)
14763b921b29Sopenharmony_ci       if (cinfo->Ah == 0) {     /* DC refinement needs no table */
14773b921b29Sopenharmony_ci         tbl = compptr->dc_tbl_no;
14783b921b29Sopenharmony_ci         pdtbl = (d_derived_tbl **)(entropy->derived_tbls) + tbl;
14793b921b29Sopenharmony_ci+#ifdef HUFF_DECODE_OPT
14803b921b29Sopenharmony_ci+        // OH ISSUE: jpeg optimize
14813b921b29Sopenharmony_ci+        jpeg_make_dp_derived_tbl(cinfo, TRUE, tbl, pdtbl);
14823b921b29Sopenharmony_ci+#else
14833b921b29Sopenharmony_ci         jpeg_make_d_derived_tbl(cinfo, TRUE, tbl, pdtbl);
14843b921b29Sopenharmony_ci+#endif
14853b921b29Sopenharmony_ci       }
14863b921b29Sopenharmony_ci     } else {
14873b921b29Sopenharmony_ci       tbl = compptr->ac_tbl_no;
14883b921b29Sopenharmony_ci       pdtbl = (d_derived_tbl **)(entropy->derived_tbls) + tbl;
14893b921b29Sopenharmony_ci+#ifdef HUFF_DECODE_OPT
14903b921b29Sopenharmony_ci+      // OH ISSUE: jpeg optimize
14913b921b29Sopenharmony_ci+      jpeg_make_dp_derived_tbl(cinfo, FALSE, tbl, pdtbl);
14923b921b29Sopenharmony_ci+#else
14933b921b29Sopenharmony_ci       jpeg_make_d_derived_tbl(cinfo, FALSE, tbl, pdtbl);
14943b921b29Sopenharmony_ci+#endif
14953b921b29Sopenharmony_ci       /* remember the single active table */
14963b921b29Sopenharmony_ci       entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
14973b921b29Sopenharmony_ci     }
14983b921b29Sopenharmony_cidiff --git a/jmemsys.h b/jmemsys.h
14993b921b29Sopenharmony_ciindex 9229550..a17f46c 100644
15003b921b29Sopenharmony_ci--- a/jmemsys.h
15013b921b29Sopenharmony_ci+++ b/jmemsys.h
15023b921b29Sopenharmony_ci@@ -31,8 +31,8 @@
15033b921b29Sopenharmony_ci  * size of the object being freed, just in case it's needed.
15043b921b29Sopenharmony_ci  */
15053b921b29Sopenharmony_ci 
15063b921b29Sopenharmony_ci-EXTERN(void *) jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject);
15073b921b29Sopenharmony_ci-EXTERN(void) jpeg_free_small(j_common_ptr cinfo, void *object,
15083b921b29Sopenharmony_ci+HIDE(EXTERN)(void *) jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject);
15093b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_free_small(j_common_ptr cinfo, void *object,
15103b921b29Sopenharmony_ci                              size_t sizeofobject);
15113b921b29Sopenharmony_ci 
15123b921b29Sopenharmony_ci /*
15133b921b29Sopenharmony_ci@@ -43,8 +43,8 @@ EXTERN(void) jpeg_free_small(j_common_ptr cinfo, void *object,
15143b921b29Sopenharmony_ci  * large chunks.
15153b921b29Sopenharmony_ci  */
15163b921b29Sopenharmony_ci 
15173b921b29Sopenharmony_ci-EXTERN(void *) jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject);
15183b921b29Sopenharmony_ci-EXTERN(void) jpeg_free_large(j_common_ptr cinfo, void *object,
15193b921b29Sopenharmony_ci+HIDE(EXTERN)(void *) jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject);
15203b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_free_large(j_common_ptr cinfo, void *object,
15213b921b29Sopenharmony_ci                              size_t sizeofobject);
15223b921b29Sopenharmony_ci 
15233b921b29Sopenharmony_ci /*
15243b921b29Sopenharmony_ci@@ -84,7 +84,7 @@ EXTERN(void) jpeg_free_large(j_common_ptr cinfo, void *object,
15253b921b29Sopenharmony_ci  * Conversely, zero may be returned to always use the minimum amount of memory.
15263b921b29Sopenharmony_ci  */
15273b921b29Sopenharmony_ci 
15283b921b29Sopenharmony_ci-EXTERN(size_t) jpeg_mem_available(j_common_ptr cinfo, size_t min_bytes_needed,
15293b921b29Sopenharmony_ci+HIDE(EXTERN)(size_t) jpeg_mem_available(j_common_ptr cinfo, size_t min_bytes_needed,
15303b921b29Sopenharmony_ci                                   size_t max_bytes_needed,
15313b921b29Sopenharmony_ci                                   size_t already_allocated);
15323b921b29Sopenharmony_ci 
15333b921b29Sopenharmony_ci@@ -157,7 +157,7 @@ typedef struct backing_store_struct {
15343b921b29Sopenharmony_ci  * just take an error exit.)
15353b921b29Sopenharmony_ci  */
15363b921b29Sopenharmony_ci 
15373b921b29Sopenharmony_ci-EXTERN(void) jpeg_open_backing_store(j_common_ptr cinfo,
15383b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_open_backing_store(j_common_ptr cinfo,
15393b921b29Sopenharmony_ci                                      backing_store_ptr info,
15403b921b29Sopenharmony_ci                                      long total_bytes_needed);
15413b921b29Sopenharmony_ci 
15423b921b29Sopenharmony_ci@@ -174,5 +174,5 @@ EXTERN(void) jpeg_open_backing_store(j_common_ptr cinfo,
15433b921b29Sopenharmony_ci  * all opened backing-store objects have been closed.
15443b921b29Sopenharmony_ci  */
15453b921b29Sopenharmony_ci 
15463b921b29Sopenharmony_ci-EXTERN(long) jpeg_mem_init(j_common_ptr cinfo);
15473b921b29Sopenharmony_ci-EXTERN(void) jpeg_mem_term(j_common_ptr cinfo);
15483b921b29Sopenharmony_ci+HIDE(EXTERN)(long) jpeg_mem_init(j_common_ptr cinfo);
15493b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jpeg_mem_term(j_common_ptr cinfo);
15503b921b29Sopenharmony_cidiff --git a/jmorecfg.h b/jmorecfg.h
15513b921b29Sopenharmony_ciindex 1a63a14..f4b3903 100644
15523b921b29Sopenharmony_ci--- a/jmorecfg.h
15533b921b29Sopenharmony_ci+++ b/jmorecfg.h
15543b921b29Sopenharmony_ci@@ -178,7 +178,12 @@ typedef unsigned int JDIMENSION;
15553b921b29Sopenharmony_ci #define GLOBAL(type)            type
15563b921b29Sopenharmony_ci /* a reference to a GLOBAL function: */
15573b921b29Sopenharmony_ci #define EXTERN(type)            extern type
15583b921b29Sopenharmony_ci-
15593b921b29Sopenharmony_ci+/* a function used only in this lib: */
15603b921b29Sopenharmony_ci+#ifdef HIDE_INTERNAL
15613b921b29Sopenharmony_ci+  #define HIDE(type)            __attribute__((visibility("hidden"))) type
15623b921b29Sopenharmony_ci+#else
15633b921b29Sopenharmony_ci+  #define HIDE(type)            type
15643b921b29Sopenharmony_ci+#endif
15653b921b29Sopenharmony_ci 
15663b921b29Sopenharmony_ci /* Originally, this macro was used as a way of defining function prototypes
15673b921b29Sopenharmony_ci  * for both modern compilers as well as older compilers that did not support
15683b921b29Sopenharmony_cidiff --git a/jpegint.h b/jpegint.h
15693b921b29Sopenharmony_ciindex 8c85347..7798a89 100644
15703b921b29Sopenharmony_ci--- a/jpegint.h
15713b921b29Sopenharmony_ci+++ b/jpegint.h
15723b921b29Sopenharmony_ci@@ -318,53 +318,53 @@ struct jpeg_color_quantizer {
15733b921b29Sopenharmony_ci 
15743b921b29Sopenharmony_ci 
15753b921b29Sopenharmony_ci /* Compression module initialization routines */
15763b921b29Sopenharmony_ci-EXTERN(void) jinit_compress_master(j_compress_ptr cinfo);
15773b921b29Sopenharmony_ci-EXTERN(void) jinit_c_master_control(j_compress_ptr cinfo,
15783b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_compress_master(j_compress_ptr cinfo);
15793b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_c_master_control(j_compress_ptr cinfo,
15803b921b29Sopenharmony_ci                                     boolean transcode_only);
15813b921b29Sopenharmony_ci-EXTERN(void) jinit_c_main_controller(j_compress_ptr cinfo,
15823b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_c_main_controller(j_compress_ptr cinfo,
15833b921b29Sopenharmony_ci                                      boolean need_full_buffer);
15843b921b29Sopenharmony_ci-EXTERN(void) jinit_c_prep_controller(j_compress_ptr cinfo,
15853b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_c_prep_controller(j_compress_ptr cinfo,
15863b921b29Sopenharmony_ci                                      boolean need_full_buffer);
15873b921b29Sopenharmony_ci-EXTERN(void) jinit_c_coef_controller(j_compress_ptr cinfo,
15883b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_c_coef_controller(j_compress_ptr cinfo,
15893b921b29Sopenharmony_ci                                      boolean need_full_buffer);
15903b921b29Sopenharmony_ci-EXTERN(void) jinit_color_converter(j_compress_ptr cinfo);
15913b921b29Sopenharmony_ci-EXTERN(void) jinit_downsampler(j_compress_ptr cinfo);
15923b921b29Sopenharmony_ci-EXTERN(void) jinit_forward_dct(j_compress_ptr cinfo);
15933b921b29Sopenharmony_ci-EXTERN(void) jinit_huff_encoder(j_compress_ptr cinfo);
15943b921b29Sopenharmony_ci-EXTERN(void) jinit_phuff_encoder(j_compress_ptr cinfo);
15953b921b29Sopenharmony_ci-EXTERN(void) jinit_arith_encoder(j_compress_ptr cinfo);
15963b921b29Sopenharmony_ci-EXTERN(void) jinit_marker_writer(j_compress_ptr cinfo);
15973b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_color_converter(j_compress_ptr cinfo);
15983b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_downsampler(j_compress_ptr cinfo);
15993b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_forward_dct(j_compress_ptr cinfo);
16003b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_huff_encoder(j_compress_ptr cinfo);
16013b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_phuff_encoder(j_compress_ptr cinfo);
16023b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_arith_encoder(j_compress_ptr cinfo);
16033b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_marker_writer(j_compress_ptr cinfo);
16043b921b29Sopenharmony_ci /* Decompression module initialization routines */
16053b921b29Sopenharmony_ci-EXTERN(void) jinit_master_decompress(j_decompress_ptr cinfo);
16063b921b29Sopenharmony_ci-EXTERN(void) jinit_d_main_controller(j_decompress_ptr cinfo,
16073b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_master_decompress(j_decompress_ptr cinfo);
16083b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_d_main_controller(j_decompress_ptr cinfo,
16093b921b29Sopenharmony_ci                                      boolean need_full_buffer);
16103b921b29Sopenharmony_ci-EXTERN(void) jinit_d_coef_controller(j_decompress_ptr cinfo,
16113b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_d_coef_controller(j_decompress_ptr cinfo,
16123b921b29Sopenharmony_ci                                      boolean need_full_buffer);
16133b921b29Sopenharmony_ci-EXTERN(void) jinit_d_post_controller(j_decompress_ptr cinfo,
16143b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_d_post_controller(j_decompress_ptr cinfo,
16153b921b29Sopenharmony_ci                                      boolean need_full_buffer);
16163b921b29Sopenharmony_ci-EXTERN(void) jinit_input_controller(j_decompress_ptr cinfo);
16173b921b29Sopenharmony_ci-EXTERN(void) jinit_marker_reader(j_decompress_ptr cinfo);
16183b921b29Sopenharmony_ci-EXTERN(void) jinit_huff_decoder(j_decompress_ptr cinfo);
16193b921b29Sopenharmony_ci-EXTERN(void) jinit_phuff_decoder(j_decompress_ptr cinfo);
16203b921b29Sopenharmony_ci-EXTERN(void) jinit_arith_decoder(j_decompress_ptr cinfo);
16213b921b29Sopenharmony_ci-EXTERN(void) jinit_inverse_dct(j_decompress_ptr cinfo);
16223b921b29Sopenharmony_ci-EXTERN(void) jinit_upsampler(j_decompress_ptr cinfo);
16233b921b29Sopenharmony_ci-EXTERN(void) jinit_color_deconverter(j_decompress_ptr cinfo);
16243b921b29Sopenharmony_ci-EXTERN(void) jinit_1pass_quantizer(j_decompress_ptr cinfo);
16253b921b29Sopenharmony_ci-EXTERN(void) jinit_2pass_quantizer(j_decompress_ptr cinfo);
16263b921b29Sopenharmony_ci-EXTERN(void) jinit_merged_upsampler(j_decompress_ptr cinfo);
16273b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_input_controller(j_decompress_ptr cinfo);
16283b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_marker_reader(j_decompress_ptr cinfo);
16293b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_huff_decoder(j_decompress_ptr cinfo);
16303b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_phuff_decoder(j_decompress_ptr cinfo);
16313b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_arith_decoder(j_decompress_ptr cinfo);
16323b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_inverse_dct(j_decompress_ptr cinfo);
16333b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_upsampler(j_decompress_ptr cinfo);
16343b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_color_deconverter(j_decompress_ptr cinfo);
16353b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_1pass_quantizer(j_decompress_ptr cinfo);
16363b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_2pass_quantizer(j_decompress_ptr cinfo);
16373b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_merged_upsampler(j_decompress_ptr cinfo);
16383b921b29Sopenharmony_ci /* Memory manager initialization */
16393b921b29Sopenharmony_ci-EXTERN(void) jinit_memory_mgr(j_common_ptr cinfo);
16403b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jinit_memory_mgr(j_common_ptr cinfo);
16413b921b29Sopenharmony_ci 
16423b921b29Sopenharmony_ci /* Utility routines in jutils.c */
16433b921b29Sopenharmony_ci-EXTERN(long) jdiv_round_up(long a, long b);
16443b921b29Sopenharmony_ci-EXTERN(long) jround_up(long a, long b);
16453b921b29Sopenharmony_ci-EXTERN(void) jcopy_sample_rows(JSAMPARRAY input_array, int source_row,
16463b921b29Sopenharmony_ci+HIDE(EXTERN)(long) jdiv_round_up(long a, long b);
16473b921b29Sopenharmony_ci+HIDE(EXTERN)(long) jround_up(long a, long b);
16483b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jcopy_sample_rows(JSAMPARRAY input_array, int source_row,
16493b921b29Sopenharmony_ci                                JSAMPARRAY output_array, int dest_row,
16503b921b29Sopenharmony_ci                                int num_rows, JDIMENSION num_cols);
16513b921b29Sopenharmony_ci-EXTERN(void) jcopy_block_row(JBLOCKROW input_row, JBLOCKROW output_row,
16523b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jcopy_block_row(JBLOCKROW input_row, JBLOCKROW output_row,
16533b921b29Sopenharmony_ci                              JDIMENSION num_blocks);
16543b921b29Sopenharmony_ci-EXTERN(void) jzero_far(void *target, size_t bytestozero);
16553b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jzero_far(void *target, size_t bytestozero);
16563b921b29Sopenharmony_ci /* Constant tables in jutils.c */
16573b921b29Sopenharmony_ci #if 0                           /* This table is not actually needed in v6a */
16583b921b29Sopenharmony_ci extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
16593b921b29Sopenharmony_cidiff --git a/jsimd.h b/jsimd.h
16603b921b29Sopenharmony_ciindex f3a87ee..ea094f6 100644
16613b921b29Sopenharmony_ci--- a/jsimd.h
16623b921b29Sopenharmony_ci+++ b/jsimd.h
16633b921b29Sopenharmony_ci@@ -14,110 +14,110 @@
16643b921b29Sopenharmony_ci 
16653b921b29Sopenharmony_ci #include "jchuff.h"             /* Declarations shared with jcphuff.c */
16663b921b29Sopenharmony_ci 
16673b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_rgb_ycc(void);
16683b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_rgb_gray(void);
16693b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_ycc_rgb(void);
16703b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_ycc_rgb565(void);
16713b921b29Sopenharmony_ci-EXTERN(int) jsimd_c_can_null_convert(void);
16723b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_rgb_ycc(void);
16733b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_rgb_gray(void);
16743b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_ycc_rgb(void);
16753b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_ycc_rgb565(void);
16763b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_c_can_null_convert(void);
16773b921b29Sopenharmony_ci 
16783b921b29Sopenharmony_ci-EXTERN(void) jsimd_rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
16793b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
16803b921b29Sopenharmony_ci                                    JSAMPIMAGE output_buf,
16813b921b29Sopenharmony_ci                                    JDIMENSION output_row, int num_rows);
16823b921b29Sopenharmony_ci-EXTERN(void) jsimd_rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
16833b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
16843b921b29Sopenharmony_ci                                     JSAMPIMAGE output_buf,
16853b921b29Sopenharmony_ci                                     JDIMENSION output_row, int num_rows);
16863b921b29Sopenharmony_ci-EXTERN(void) jsimd_ycc_rgb_convert(j_decompress_ptr cinfo,
16873b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_ycc_rgb_convert(j_decompress_ptr cinfo,
16883b921b29Sopenharmony_ci                                    JSAMPIMAGE input_buf, JDIMENSION input_row,
16893b921b29Sopenharmony_ci                                    JSAMPARRAY output_buf, int num_rows);
16903b921b29Sopenharmony_ci-EXTERN(void) jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo,
16913b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo,
16923b921b29Sopenharmony_ci                                       JSAMPIMAGE input_buf,
16933b921b29Sopenharmony_ci                                       JDIMENSION input_row,
16943b921b29Sopenharmony_ci                                       JSAMPARRAY output_buf, int num_rows);
16953b921b29Sopenharmony_ci-EXTERN(void) jsimd_c_null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
16963b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_c_null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
16973b921b29Sopenharmony_ci                                   JSAMPIMAGE output_buf, JDIMENSION output_row,
16983b921b29Sopenharmony_ci                                   int num_rows);
16993b921b29Sopenharmony_ci 
17003b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_h2v2_downsample(void);
17013b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_h2v1_downsample(void);
17023b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_h2v2_downsample(void);
17033b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_h2v1_downsample(void);
17043b921b29Sopenharmony_ci 
17053b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_downsample(j_compress_ptr cinfo,
17063b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_downsample(j_compress_ptr cinfo,
17073b921b29Sopenharmony_ci                                    jpeg_component_info *compptr,
17083b921b29Sopenharmony_ci                                    JSAMPARRAY input_data,
17093b921b29Sopenharmony_ci                                    JSAMPARRAY output_data);
17103b921b29Sopenharmony_ci 
17113b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_h2v2_smooth_downsample(void);
17123b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_h2v2_smooth_downsample(void);
17133b921b29Sopenharmony_ci 
17143b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_smooth_downsample(j_compress_ptr cinfo,
17153b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_smooth_downsample(j_compress_ptr cinfo,
17163b921b29Sopenharmony_ci                                           jpeg_component_info *compptr,
17173b921b29Sopenharmony_ci                                           JSAMPARRAY input_data,
17183b921b29Sopenharmony_ci                                           JSAMPARRAY output_data);
17193b921b29Sopenharmony_ci 
17203b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_downsample(j_compress_ptr cinfo,
17213b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_downsample(j_compress_ptr cinfo,
17223b921b29Sopenharmony_ci                                    jpeg_component_info *compptr,
17233b921b29Sopenharmony_ci                                    JSAMPARRAY input_data,
17243b921b29Sopenharmony_ci                                    JSAMPARRAY output_data);
17253b921b29Sopenharmony_ci 
17263b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_h2v2_upsample(void);
17273b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_h2v1_upsample(void);
17283b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_int_upsample(void);
17293b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_h2v2_upsample(void);
17303b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_h2v1_upsample(void);
17313b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_int_upsample(void);
17323b921b29Sopenharmony_ci 
17333b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_upsample(j_decompress_ptr cinfo,
17343b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_upsample(j_decompress_ptr cinfo,
17353b921b29Sopenharmony_ci                                  jpeg_component_info *compptr,
17363b921b29Sopenharmony_ci                                  JSAMPARRAY input_data,
17373b921b29Sopenharmony_ci                                  JSAMPARRAY *output_data_ptr);
17383b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_upsample(j_decompress_ptr cinfo,
17393b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_upsample(j_decompress_ptr cinfo,
17403b921b29Sopenharmony_ci                                  jpeg_component_info *compptr,
17413b921b29Sopenharmony_ci                                  JSAMPARRAY input_data,
17423b921b29Sopenharmony_ci                                  JSAMPARRAY *output_data_ptr);
17433b921b29Sopenharmony_ci-EXTERN(void) jsimd_int_upsample(j_decompress_ptr cinfo,
17443b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_int_upsample(j_decompress_ptr cinfo,
17453b921b29Sopenharmony_ci                                 jpeg_component_info *compptr,
17463b921b29Sopenharmony_ci                                 JSAMPARRAY input_data,
17473b921b29Sopenharmony_ci                                 JSAMPARRAY *output_data_ptr);
17483b921b29Sopenharmony_ci 
17493b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_h2v2_fancy_upsample(void);
17503b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_h2v1_fancy_upsample(void);
17513b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_h1v2_fancy_upsample(void);
17523b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_h2v2_fancy_upsample(void);
17533b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_h2v1_fancy_upsample(void);
17543b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_h1v2_fancy_upsample(void);
17553b921b29Sopenharmony_ci 
17563b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo,
17573b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo,
17583b921b29Sopenharmony_ci                                        jpeg_component_info *compptr,
17593b921b29Sopenharmony_ci                                        JSAMPARRAY input_data,
17603b921b29Sopenharmony_ci                                        JSAMPARRAY *output_data_ptr);
17613b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo,
17623b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo,
17633b921b29Sopenharmony_ci                                        jpeg_component_info *compptr,
17643b921b29Sopenharmony_ci                                        JSAMPARRAY input_data,
17653b921b29Sopenharmony_ci                                        JSAMPARRAY *output_data_ptr);
17663b921b29Sopenharmony_ci-EXTERN(void) jsimd_h1v2_fancy_upsample(j_decompress_ptr cinfo,
17673b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h1v2_fancy_upsample(j_decompress_ptr cinfo,
17683b921b29Sopenharmony_ci                                        jpeg_component_info *compptr,
17693b921b29Sopenharmony_ci                                        JSAMPARRAY input_data,
17703b921b29Sopenharmony_ci                                        JSAMPARRAY *output_data_ptr);
17713b921b29Sopenharmony_ci 
17723b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_h2v2_merged_upsample(void);
17733b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_h2v1_merged_upsample(void);
17743b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_h2v2_merged_upsample(void);
17753b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_h2v1_merged_upsample(void);
17763b921b29Sopenharmony_ci 
17773b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo,
17783b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo,
17793b921b29Sopenharmony_ci                                         JSAMPIMAGE input_buf,
17803b921b29Sopenharmony_ci                                         JDIMENSION in_row_group_ctr,
17813b921b29Sopenharmony_ci                                         JSAMPARRAY output_buf);
17823b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo,
17833b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo,
17843b921b29Sopenharmony_ci                                         JSAMPIMAGE input_buf,
17853b921b29Sopenharmony_ci                                         JDIMENSION in_row_group_ctr,
17863b921b29Sopenharmony_ci                                         JSAMPARRAY output_buf);
17873b921b29Sopenharmony_ci 
17883b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_huff_encode_one_block(void);
17893b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_huff_encode_one_block(void);
17903b921b29Sopenharmony_ci 
17913b921b29Sopenharmony_ci-EXTERN(JOCTET *) jsimd_huff_encode_one_block(void *state, JOCTET *buffer,
17923b921b29Sopenharmony_ci+HIDE(EXTERN)(JOCTET *) jsimd_huff_encode_one_block(void *state, JOCTET *buffer,
17933b921b29Sopenharmony_ci                                              JCOEFPTR block, int last_dc_val,
17943b921b29Sopenharmony_ci                                              c_derived_tbl *dctbl,
17953b921b29Sopenharmony_ci                                              c_derived_tbl *actbl);
17963b921b29Sopenharmony_ci 
17973b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_encode_mcu_AC_first_prepare(void);
17983b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_encode_mcu_AC_first_prepare(void);
17993b921b29Sopenharmony_ci 
18003b921b29Sopenharmony_ci-EXTERN(void) jsimd_encode_mcu_AC_first_prepare
18013b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_encode_mcu_AC_first_prepare
18023b921b29Sopenharmony_ci   (const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
18033b921b29Sopenharmony_ci    UJCOEF *values, size_t *zerobits);
18043b921b29Sopenharmony_ci 
18053b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_encode_mcu_AC_refine_prepare(void);
18063b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_encode_mcu_AC_refine_prepare(void);
18073b921b29Sopenharmony_ci 
18083b921b29Sopenharmony_ci-EXTERN(int) jsimd_encode_mcu_AC_refine_prepare
18093b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_encode_mcu_AC_refine_prepare
18103b921b29Sopenharmony_ci   (const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
18113b921b29Sopenharmony_ci    UJCOEF *absvalues, size_t *bits);
18123b921b29Sopenharmony_cidiff --git a/jsimddct.h b/jsimddct.h
18133b921b29Sopenharmony_ciindex 55ee8cf..c19fe41 100644
18143b921b29Sopenharmony_ci--- a/jsimddct.h
18153b921b29Sopenharmony_ci+++ b/jsimddct.h
18163b921b29Sopenharmony_ci@@ -9,62 +9,62 @@
18173b921b29Sopenharmony_ci  *
18183b921b29Sopenharmony_ci  */
18193b921b29Sopenharmony_ci 
18203b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_convsamp(void);
18213b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_convsamp_float(void);
18223b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_convsamp(void);
18233b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_convsamp_float(void);
18243b921b29Sopenharmony_ci 
18253b921b29Sopenharmony_ci-EXTERN(void) jsimd_convsamp(JSAMPARRAY sample_data, JDIMENSION start_col,
18263b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_convsamp(JSAMPARRAY sample_data, JDIMENSION start_col,
18273b921b29Sopenharmony_ci                             DCTELEM *workspace);
18283b921b29Sopenharmony_ci-EXTERN(void) jsimd_convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
18293b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
18303b921b29Sopenharmony_ci                                   FAST_FLOAT *workspace);
18313b921b29Sopenharmony_ci 
18323b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_fdct_islow(void);
18333b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_fdct_ifast(void);
18343b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_fdct_float(void);
18353b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_fdct_islow(void);
18363b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_fdct_ifast(void);
18373b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_fdct_float(void);
18383b921b29Sopenharmony_ci 
18393b921b29Sopenharmony_ci-EXTERN(void) jsimd_fdct_islow(DCTELEM *data);
18403b921b29Sopenharmony_ci-EXTERN(void) jsimd_fdct_ifast(DCTELEM *data);
18413b921b29Sopenharmony_ci-EXTERN(void) jsimd_fdct_float(FAST_FLOAT *data);
18423b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_fdct_islow(DCTELEM *data);
18433b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_fdct_ifast(DCTELEM *data);
18443b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_fdct_float(FAST_FLOAT *data);
18453b921b29Sopenharmony_ci 
18463b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_quantize(void);
18473b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_quantize_float(void);
18483b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_quantize(void);
18493b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_quantize_float(void);
18503b921b29Sopenharmony_ci 
18513b921b29Sopenharmony_ci-EXTERN(void) jsimd_quantize(JCOEFPTR coef_block, DCTELEM *divisors,
18523b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_quantize(JCOEFPTR coef_block, DCTELEM *divisors,
18533b921b29Sopenharmony_ci                             DCTELEM *workspace);
18543b921b29Sopenharmony_ci-EXTERN(void) jsimd_quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
18553b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
18563b921b29Sopenharmony_ci                                   FAST_FLOAT *workspace);
18573b921b29Sopenharmony_ci 
18583b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_idct_2x2(void);
18593b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_idct_4x4(void);
18603b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_idct_6x6(void);
18613b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_idct_12x12(void);
18623b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_idct_2x2(void);
18633b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_idct_4x4(void);
18643b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_idct_6x6(void);
18653b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_idct_12x12(void);
18663b921b29Sopenharmony_ci 
18673b921b29Sopenharmony_ci-EXTERN(void) jsimd_idct_2x2(j_decompress_ptr cinfo,
18683b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_idct_2x2(j_decompress_ptr cinfo,
18693b921b29Sopenharmony_ci                             jpeg_component_info *compptr, JCOEFPTR coef_block,
18703b921b29Sopenharmony_ci                             JSAMPARRAY output_buf, JDIMENSION output_col);
18713b921b29Sopenharmony_ci-EXTERN(void) jsimd_idct_4x4(j_decompress_ptr cinfo,
18723b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_idct_4x4(j_decompress_ptr cinfo,
18733b921b29Sopenharmony_ci                             jpeg_component_info *compptr, JCOEFPTR coef_block,
18743b921b29Sopenharmony_ci                             JSAMPARRAY output_buf, JDIMENSION output_col);
18753b921b29Sopenharmony_ci-EXTERN(void) jsimd_idct_6x6(j_decompress_ptr cinfo,
18763b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_idct_6x6(j_decompress_ptr cinfo,
18773b921b29Sopenharmony_ci                             jpeg_component_info *compptr, JCOEFPTR coef_block,
18783b921b29Sopenharmony_ci                             JSAMPARRAY output_buf, JDIMENSION output_col);
18793b921b29Sopenharmony_ci-EXTERN(void) jsimd_idct_12x12(j_decompress_ptr cinfo,
18803b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_idct_12x12(j_decompress_ptr cinfo,
18813b921b29Sopenharmony_ci                               jpeg_component_info *compptr,
18823b921b29Sopenharmony_ci                               JCOEFPTR coef_block, JSAMPARRAY output_buf,
18833b921b29Sopenharmony_ci                               JDIMENSION output_col);
18843b921b29Sopenharmony_ci 
18853b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_idct_islow(void);
18863b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_idct_ifast(void);
18873b921b29Sopenharmony_ci-EXTERN(int) jsimd_can_idct_float(void);
18883b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_idct_islow(void);
18893b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_idct_ifast(void);
18903b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_can_idct_float(void);
18913b921b29Sopenharmony_ci 
18923b921b29Sopenharmony_ci-EXTERN(void) jsimd_idct_islow(j_decompress_ptr cinfo,
18933b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_idct_islow(j_decompress_ptr cinfo,
18943b921b29Sopenharmony_ci                               jpeg_component_info *compptr,
18953b921b29Sopenharmony_ci                               JCOEFPTR coef_block, JSAMPARRAY output_buf,
18963b921b29Sopenharmony_ci                               JDIMENSION output_col);
18973b921b29Sopenharmony_ci-EXTERN(void) jsimd_idct_ifast(j_decompress_ptr cinfo,
18983b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_idct_ifast(j_decompress_ptr cinfo,
18993b921b29Sopenharmony_ci                               jpeg_component_info *compptr,
19003b921b29Sopenharmony_ci                               JCOEFPTR coef_block, JSAMPARRAY output_buf,
19013b921b29Sopenharmony_ci                               JDIMENSION output_col);
19023b921b29Sopenharmony_ci-EXTERN(void) jsimd_idct_float(j_decompress_ptr cinfo,
19033b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_idct_float(j_decompress_ptr cinfo,
19043b921b29Sopenharmony_ci                               jpeg_component_info *compptr,
19053b921b29Sopenharmony_ci                               JCOEFPTR coef_block, JSAMPARRAY output_buf,
19063b921b29Sopenharmony_ci                               JDIMENSION output_col);
19073b921b29Sopenharmony_cidiff --git a/jutils.c b/jutils.c
19083b921b29Sopenharmony_ciindex 5c5bb17..cd14e74 100644
19093b921b29Sopenharmony_ci--- a/jutils.c
19103b921b29Sopenharmony_ci+++ b/jutils.c
19113b921b29Sopenharmony_ci@@ -53,6 +53,27 @@ const int jpeg_zigzag_order[DCTSIZE2] = {
19123b921b29Sopenharmony_ci  * fake entries.
19133b921b29Sopenharmony_ci  */
19143b921b29Sopenharmony_ci 
19153b921b29Sopenharmony_ci+#ifdef HUFF_DECODE_OPT
19163b921b29Sopenharmony_ci+// OH ISSUE: jpeg optimize
19173b921b29Sopenharmony_ci+const int jpeg_natural_order[DCTSIZE2 + 64] = {
19183b921b29Sopenharmony_ci+  0,  1,  8, 16,  9,  2,  3, 10,
19193b921b29Sopenharmony_ci+ 17, 24, 32, 25, 18, 11,  4,  5,
19203b921b29Sopenharmony_ci+ 12, 19, 26, 33, 40, 48, 41, 34,
19213b921b29Sopenharmony_ci+ 27, 20, 13,  6,  7, 14, 21, 28,
19223b921b29Sopenharmony_ci+ 35, 42, 49, 56, 57, 50, 43, 36,
19233b921b29Sopenharmony_ci+ 29, 22, 15, 23, 30, 37, 44, 51,
19243b921b29Sopenharmony_ci+ 58, 59, 52, 45, 38, 31, 39, 46,
19253b921b29Sopenharmony_ci+ 53, 60, 61, 54, 47, 55, 62, 63,
19263b921b29Sopenharmony_ci+ 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
19273b921b29Sopenharmony_ci+ 63, 63, 63, 63, 63, 63, 63, 63,
19283b921b29Sopenharmony_ci+ 63, 63, 63, 63, 63, 63, 63, 63,
19293b921b29Sopenharmony_ci+ 63, 63, 63, 63, 63, 63, 63, 63,
19303b921b29Sopenharmony_ci+ 63, 63, 63, 63, 63, 63, 63, 63,
19313b921b29Sopenharmony_ci+ 63, 63, 63, 63, 63, 63, 63, 63,
19323b921b29Sopenharmony_ci+ 63, 63, 63, 63, 63, 63, 63, 63,
19333b921b29Sopenharmony_ci+ 63, 63, 63, 63, 63, 63, 63, 63
19343b921b29Sopenharmony_ci+};
19353b921b29Sopenharmony_ci+#else
19363b921b29Sopenharmony_ci const int jpeg_natural_order[DCTSIZE2 + 16] = {
19373b921b29Sopenharmony_ci   0,  1,  8, 16,  9,  2,  3, 10,
19383b921b29Sopenharmony_ci  17, 24, 32, 25, 18, 11,  4,  5,
19393b921b29Sopenharmony_ci@@ -65,6 +86,7 @@ const int jpeg_natural_order[DCTSIZE2 + 16] = {
19403b921b29Sopenharmony_ci  63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
19413b921b29Sopenharmony_ci  63, 63, 63, 63, 63, 63, 63, 63
19423b921b29Sopenharmony_ci };
19433b921b29Sopenharmony_ci+#endif
19443b921b29Sopenharmony_ci 
19453b921b29Sopenharmony_ci 
19463b921b29Sopenharmony_ci /*
19473b921b29Sopenharmony_cidiff --git a/simd/jsimd.h b/simd/jsimd.h
19483b921b29Sopenharmony_ciindex abebbf4..1d45a56 100644
19493b921b29Sopenharmony_ci--- a/simd/jsimd.h
19503b921b29Sopenharmony_ci+++ b/simd/jsimd.h
19513b921b29Sopenharmony_ci@@ -102,34 +102,34 @@ EXTERN(void) jsimd_extxrgb_ycc_convert_avx2
19523b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
19533b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
19543b921b29Sopenharmony_ci 
19553b921b29Sopenharmony_ci-EXTERN(void) jsimd_rgb_ycc_convert_neon
19563b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_rgb_ycc_convert_neon
19573b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
19583b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
19593b921b29Sopenharmony_ci-EXTERN(void) jsimd_extrgb_ycc_convert_neon
19603b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extrgb_ycc_convert_neon
19613b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
19623b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
19633b921b29Sopenharmony_ci-EXTERN(void) jsimd_extrgbx_ycc_convert_neon
19643b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extrgbx_ycc_convert_neon
19653b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
19663b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
19673b921b29Sopenharmony_ci-EXTERN(void) jsimd_extbgr_ycc_convert_neon
19683b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extbgr_ycc_convert_neon
19693b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
19703b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
19713b921b29Sopenharmony_ci-EXTERN(void) jsimd_extbgrx_ycc_convert_neon
19723b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extbgrx_ycc_convert_neon
19733b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
19743b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
19753b921b29Sopenharmony_ci-EXTERN(void) jsimd_extxbgr_ycc_convert_neon
19763b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extxbgr_ycc_convert_neon
19773b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
19783b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
19793b921b29Sopenharmony_ci-EXTERN(void) jsimd_extxrgb_ycc_convert_neon
19803b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extxrgb_ycc_convert_neon
19813b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
19823b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
19833b921b29Sopenharmony_ci 
19843b921b29Sopenharmony_ci #ifndef NEON_INTRINSICS
19853b921b29Sopenharmony_ci 
19863b921b29Sopenharmony_ci-EXTERN(void) jsimd_extrgb_ycc_convert_neon_slowld3
19873b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extrgb_ycc_convert_neon_slowld3
19883b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
19893b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
19903b921b29Sopenharmony_ci-EXTERN(void) jsimd_extbgr_ycc_convert_neon_slowld3
19913b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extbgr_ycc_convert_neon_slowld3
19923b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
19933b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
19943b921b29Sopenharmony_ci 
19953b921b29Sopenharmony_ci@@ -270,25 +270,25 @@ EXTERN(void) jsimd_extxrgb_gray_convert_avx2
19963b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
19973b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
19983b921b29Sopenharmony_ci 
19993b921b29Sopenharmony_ci-EXTERN(void) jsimd_rgb_gray_convert_neon
20003b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_rgb_gray_convert_neon
20013b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
20023b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
20033b921b29Sopenharmony_ci-EXTERN(void) jsimd_extrgb_gray_convert_neon
20043b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extrgb_gray_convert_neon
20053b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
20063b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
20073b921b29Sopenharmony_ci-EXTERN(void) jsimd_extrgbx_gray_convert_neon
20083b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extrgbx_gray_convert_neon
20093b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
20103b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
20113b921b29Sopenharmony_ci-EXTERN(void) jsimd_extbgr_gray_convert_neon
20123b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extbgr_gray_convert_neon
20133b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
20143b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
20153b921b29Sopenharmony_ci-EXTERN(void) jsimd_extbgrx_gray_convert_neon
20163b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extbgrx_gray_convert_neon
20173b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
20183b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
20193b921b29Sopenharmony_ci-EXTERN(void) jsimd_extxbgr_gray_convert_neon
20203b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extxbgr_gray_convert_neon
20213b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
20223b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
20233b921b29Sopenharmony_ci-EXTERN(void) jsimd_extxrgb_gray_convert_neon
20243b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_extxrgb_gray_convert_neon
20253b921b29Sopenharmony_ci   (JDIMENSION img_width, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
20263b921b29Sopenharmony_ci    JDIMENSION output_row, int num_rows);
20273b921b29Sopenharmony_ci 
20283b921b29Sopenharmony_ci@@ -427,37 +427,37 @@ EXTERN(void) jsimd_ycc_extxrgb_convert_avx2
20293b921b29Sopenharmony_ci   (JDIMENSION out_width, JSAMPIMAGE input_buf, JDIMENSION input_row,
20303b921b29Sopenharmony_ci    JSAMPARRAY output_buf, int num_rows);
20313b921b29Sopenharmony_ci 
20323b921b29Sopenharmony_ci-EXTERN(void) jsimd_ycc_rgb_convert_neon
20333b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_ycc_rgb_convert_neon
20343b921b29Sopenharmony_ci   (JDIMENSION out_width, JSAMPIMAGE input_buf, JDIMENSION input_row,
20353b921b29Sopenharmony_ci    JSAMPARRAY output_buf, int num_rows);
20363b921b29Sopenharmony_ci-EXTERN(void) jsimd_ycc_extrgb_convert_neon
20373b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_ycc_extrgb_convert_neon
20383b921b29Sopenharmony_ci   (JDIMENSION out_width, JSAMPIMAGE input_buf, JDIMENSION input_row,
20393b921b29Sopenharmony_ci    JSAMPARRAY output_buf, int num_rows);
20403b921b29Sopenharmony_ci-EXTERN(void) jsimd_ycc_extrgbx_convert_neon
20413b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_ycc_extrgbx_convert_neon
20423b921b29Sopenharmony_ci   (JDIMENSION out_width, JSAMPIMAGE input_buf, JDIMENSION input_row,
20433b921b29Sopenharmony_ci    JSAMPARRAY output_buf, int num_rows);
20443b921b29Sopenharmony_ci-EXTERN(void) jsimd_ycc_extbgr_convert_neon
20453b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_ycc_extbgr_convert_neon
20463b921b29Sopenharmony_ci   (JDIMENSION out_width, JSAMPIMAGE input_buf, JDIMENSION input_row,
20473b921b29Sopenharmony_ci    JSAMPARRAY output_buf, int num_rows);
20483b921b29Sopenharmony_ci-EXTERN(void) jsimd_ycc_extbgrx_convert_neon
20493b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_ycc_extbgrx_convert_neon
20503b921b29Sopenharmony_ci   (JDIMENSION out_width, JSAMPIMAGE input_buf, JDIMENSION input_row,
20513b921b29Sopenharmony_ci    JSAMPARRAY output_buf, int num_rows);
20523b921b29Sopenharmony_ci-EXTERN(void) jsimd_ycc_extxbgr_convert_neon
20533b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_ycc_extxbgr_convert_neon
20543b921b29Sopenharmony_ci   (JDIMENSION out_width, JSAMPIMAGE input_buf, JDIMENSION input_row,
20553b921b29Sopenharmony_ci    JSAMPARRAY output_buf, int num_rows);
20563b921b29Sopenharmony_ci-EXTERN(void) jsimd_ycc_extxrgb_convert_neon
20573b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_ycc_extxrgb_convert_neon
20583b921b29Sopenharmony_ci   (JDIMENSION out_width, JSAMPIMAGE input_buf, JDIMENSION input_row,
20593b921b29Sopenharmony_ci    JSAMPARRAY output_buf, int num_rows);
20603b921b29Sopenharmony_ci-EXTERN(void) jsimd_ycc_rgb565_convert_neon
20613b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_ycc_rgb565_convert_neon
20623b921b29Sopenharmony_ci   (JDIMENSION out_width, JSAMPIMAGE input_buf, JDIMENSION input_row,
20633b921b29Sopenharmony_ci    JSAMPARRAY output_buf, int num_rows);
20643b921b29Sopenharmony_ci 
20653b921b29Sopenharmony_ci #ifndef NEON_INTRINSICS
20663b921b29Sopenharmony_ci 
20673b921b29Sopenharmony_ci-EXTERN(void) jsimd_ycc_extrgb_convert_neon_slowst3
20683b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_ycc_extrgb_convert_neon_slowst3
20693b921b29Sopenharmony_ci   (JDIMENSION out_width, JSAMPIMAGE input_buf, JDIMENSION input_row,
20703b921b29Sopenharmony_ci    JSAMPARRAY output_buf, int num_rows);
20713b921b29Sopenharmony_ci-EXTERN(void) jsimd_ycc_extbgr_convert_neon_slowst3
20723b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_ycc_extbgr_convert_neon_slowst3
20733b921b29Sopenharmony_ci   (JDIMENSION out_width, JSAMPIMAGE input_buf, JDIMENSION input_row,
20743b921b29Sopenharmony_ci    JSAMPARRAY output_buf, int num_rows);
20753b921b29Sopenharmony_ci 
20763b921b29Sopenharmony_ci@@ -547,7 +547,7 @@ EXTERN(void) jsimd_h2v1_downsample_avx2
20773b921b29Sopenharmony_ci   (JDIMENSION image_width, int max_v_samp_factor, JDIMENSION v_samp_factor,
20783b921b29Sopenharmony_ci    JDIMENSION width_in_blocks, JSAMPARRAY input_data, JSAMPARRAY output_data);
20793b921b29Sopenharmony_ci 
20803b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_downsample_neon
20813b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_downsample_neon
20823b921b29Sopenharmony_ci   (JDIMENSION image_width, int max_v_samp_factor, JDIMENSION v_samp_factor,
20833b921b29Sopenharmony_ci    JDIMENSION width_in_blocks, JSAMPARRAY input_data, JSAMPARRAY output_data);
20843b921b29Sopenharmony_ci 
20853b921b29Sopenharmony_ci@@ -572,7 +572,7 @@ EXTERN(void) jsimd_h2v2_downsample_avx2
20863b921b29Sopenharmony_ci   (JDIMENSION image_width, int max_v_samp_factor, JDIMENSION v_samp_factor,
20873b921b29Sopenharmony_ci    JDIMENSION width_in_blocks, JSAMPARRAY input_data, JSAMPARRAY output_data);
20883b921b29Sopenharmony_ci 
20893b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_downsample_neon
20903b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_downsample_neon
20913b921b29Sopenharmony_ci   (JDIMENSION image_width, int max_v_samp_factor, JDIMENSION v_samp_factor,
20923b921b29Sopenharmony_ci    JDIMENSION width_in_blocks, JSAMPARRAY input_data, JSAMPARRAY output_data);
20933b921b29Sopenharmony_ci 
20943b921b29Sopenharmony_ci@@ -617,10 +617,10 @@ EXTERN(void) jsimd_h2v2_upsample_avx2
20953b921b29Sopenharmony_ci   (int max_v_samp_factor, JDIMENSION output_width, JSAMPARRAY input_data,
20963b921b29Sopenharmony_ci    JSAMPARRAY *output_data_ptr);
20973b921b29Sopenharmony_ci 
20983b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_upsample_neon
20993b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_upsample_neon
21003b921b29Sopenharmony_ci   (int max_v_samp_factor, JDIMENSION output_width, JSAMPARRAY input_data,
21013b921b29Sopenharmony_ci    JSAMPARRAY *output_data_ptr);
21023b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_upsample_neon
21033b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_upsample_neon
21043b921b29Sopenharmony_ci   (int max_v_samp_factor, JDIMENSION output_width, JSAMPARRAY input_data,
21053b921b29Sopenharmony_ci    JSAMPARRAY *output_data_ptr);
21063b921b29Sopenharmony_ci 
21073b921b29Sopenharmony_ci@@ -667,13 +667,13 @@ EXTERN(void) jsimd_h2v2_fancy_upsample_avx2
21083b921b29Sopenharmony_ci   (int max_v_samp_factor, JDIMENSION downsampled_width, JSAMPARRAY input_data,
21093b921b29Sopenharmony_ci    JSAMPARRAY *output_data_ptr);
21103b921b29Sopenharmony_ci 
21113b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_fancy_upsample_neon
21123b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_fancy_upsample_neon
21133b921b29Sopenharmony_ci   (int max_v_samp_factor, JDIMENSION downsampled_width, JSAMPARRAY input_data,
21143b921b29Sopenharmony_ci    JSAMPARRAY *output_data_ptr);
21153b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_fancy_upsample_neon
21163b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_fancy_upsample_neon
21173b921b29Sopenharmony_ci   (int max_v_samp_factor, JDIMENSION downsampled_width, JSAMPARRAY input_data,
21183b921b29Sopenharmony_ci    JSAMPARRAY *output_data_ptr);
21193b921b29Sopenharmony_ci-EXTERN(void) jsimd_h1v2_fancy_upsample_neon
21203b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h1v2_fancy_upsample_neon
21213b921b29Sopenharmony_ci   (int max_v_samp_factor, JDIMENSION downsampled_width, JSAMPARRAY input_data,
21223b921b29Sopenharmony_ci    JSAMPARRAY *output_data_ptr);
21233b921b29Sopenharmony_ci 
21243b921b29Sopenharmony_ci@@ -833,47 +833,47 @@ EXTERN(void) jsimd_h2v2_extxrgb_merged_upsample_avx2
21253b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21263b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21273b921b29Sopenharmony_ci 
21283b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_merged_upsample_neon
21293b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_merged_upsample_neon
21303b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21313b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21323b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_extrgb_merged_upsample_neon
21333b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_extrgb_merged_upsample_neon
21343b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21353b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21363b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_extrgbx_merged_upsample_neon
21373b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_extrgbx_merged_upsample_neon
21383b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21393b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21403b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_extbgr_merged_upsample_neon
21413b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_extbgr_merged_upsample_neon
21423b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21433b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21443b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_extbgrx_merged_upsample_neon
21453b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_extbgrx_merged_upsample_neon
21463b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21473b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21483b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_extxbgr_merged_upsample_neon
21493b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_extxbgr_merged_upsample_neon
21503b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21513b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21523b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v1_extxrgb_merged_upsample_neon
21533b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v1_extxrgb_merged_upsample_neon
21543b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21553b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21563b921b29Sopenharmony_ci 
21573b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_merged_upsample_neon
21583b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_merged_upsample_neon
21593b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21603b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21613b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_extrgb_merged_upsample_neon
21623b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_extrgb_merged_upsample_neon
21633b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21643b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21653b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_extrgbx_merged_upsample_neon
21663b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_extrgbx_merged_upsample_neon
21673b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21683b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21693b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_extbgr_merged_upsample_neon
21703b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_extbgr_merged_upsample_neon
21713b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21723b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21733b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_extbgrx_merged_upsample_neon
21743b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_extbgrx_merged_upsample_neon
21753b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21763b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21773b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_extxbgr_merged_upsample_neon
21783b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_extxbgr_merged_upsample_neon
21793b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21803b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21813b921b29Sopenharmony_ci-EXTERN(void) jsimd_h2v2_extxrgb_merged_upsample_neon
21823b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_h2v2_extxrgb_merged_upsample_neon
21833b921b29Sopenharmony_ci   (JDIMENSION output_width, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
21843b921b29Sopenharmony_ci    JSAMPARRAY output_buf);
21853b921b29Sopenharmony_ci 
21863b921b29Sopenharmony_ci@@ -1019,7 +1019,7 @@ EXTERN(void) jsimd_convsamp_sse2
21873b921b29Sopenharmony_ci EXTERN(void) jsimd_convsamp_avx2
21883b921b29Sopenharmony_ci   (JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace);
21893b921b29Sopenharmony_ci 
21903b921b29Sopenharmony_ci-EXTERN(void) jsimd_convsamp_neon
21913b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_convsamp_neon
21923b921b29Sopenharmony_ci   (JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace);
21933b921b29Sopenharmony_ci 
21943b921b29Sopenharmony_ci EXTERN(void) jsimd_convsamp_dspr2
21953b921b29Sopenharmony_ci@@ -1050,7 +1050,7 @@ EXTERN(void) jsimd_fdct_islow_sse2(DCTELEM *data);
21963b921b29Sopenharmony_ci extern const int jconst_fdct_islow_avx2[];
21973b921b29Sopenharmony_ci EXTERN(void) jsimd_fdct_islow_avx2(DCTELEM *data);
21983b921b29Sopenharmony_ci 
21993b921b29Sopenharmony_ci-EXTERN(void) jsimd_fdct_islow_neon(DCTELEM *data);
22003b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_fdct_islow_neon(DCTELEM *data);
22013b921b29Sopenharmony_ci 
22023b921b29Sopenharmony_ci EXTERN(void) jsimd_fdct_islow_dspr2(DCTELEM *data);
22033b921b29Sopenharmony_ci 
22043b921b29Sopenharmony_ci@@ -1064,7 +1064,7 @@ EXTERN(void) jsimd_fdct_ifast_mmx(DCTELEM *data);
22053b921b29Sopenharmony_ci extern const int jconst_fdct_ifast_sse2[];
22063b921b29Sopenharmony_ci EXTERN(void) jsimd_fdct_ifast_sse2(DCTELEM *data);
22073b921b29Sopenharmony_ci 
22083b921b29Sopenharmony_ci-EXTERN(void) jsimd_fdct_ifast_neon(DCTELEM *data);
22093b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_fdct_ifast_neon(DCTELEM *data);
22103b921b29Sopenharmony_ci 
22113b921b29Sopenharmony_ci EXTERN(void) jsimd_fdct_ifast_dspr2(DCTELEM *data);
22123b921b29Sopenharmony_ci 
22133b921b29Sopenharmony_ci@@ -1088,7 +1088,7 @@ EXTERN(void) jsimd_quantize_sse2
22143b921b29Sopenharmony_ci EXTERN(void) jsimd_quantize_avx2
22153b921b29Sopenharmony_ci   (JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace);
22163b921b29Sopenharmony_ci 
22173b921b29Sopenharmony_ci-EXTERN(void) jsimd_quantize_neon
22183b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_quantize_neon
22193b921b29Sopenharmony_ci   (JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace);
22203b921b29Sopenharmony_ci 
22213b921b29Sopenharmony_ci EXTERN(void) jsimd_quantize_dspr2
22223b921b29Sopenharmony_ci@@ -1129,10 +1129,10 @@ EXTERN(void) jsimd_idct_4x4_sse2
22233b921b29Sopenharmony_ci   (void *dct_table, JCOEFPTR coef_block, JSAMPARRAY output_buf,
22243b921b29Sopenharmony_ci    JDIMENSION output_col);
22253b921b29Sopenharmony_ci 
22263b921b29Sopenharmony_ci-EXTERN(void) jsimd_idct_2x2_neon
22273b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_idct_2x2_neon
22283b921b29Sopenharmony_ci   (void *dct_table, JCOEFPTR coef_block, JSAMPARRAY output_buf,
22293b921b29Sopenharmony_ci    JDIMENSION output_col);
22303b921b29Sopenharmony_ci-EXTERN(void) jsimd_idct_4x4_neon
22313b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_idct_4x4_neon
22323b921b29Sopenharmony_ci   (void *dct_table, JCOEFPTR coef_block, JSAMPARRAY output_buf,
22333b921b29Sopenharmony_ci    JDIMENSION output_col);
22343b921b29Sopenharmony_ci 
22353b921b29Sopenharmony_ci@@ -1165,7 +1165,7 @@ EXTERN(void) jsimd_idct_islow_avx2
22363b921b29Sopenharmony_ci   (void *dct_table, JCOEFPTR coef_block, JSAMPARRAY output_buf,
22373b921b29Sopenharmony_ci    JDIMENSION output_col);
22383b921b29Sopenharmony_ci 
22393b921b29Sopenharmony_ci-EXTERN(void) jsimd_idct_islow_neon
22403b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_idct_islow_neon
22413b921b29Sopenharmony_ci   (void *dct_table, JCOEFPTR coef_block, JSAMPARRAY output_buf,
22423b921b29Sopenharmony_ci    JDIMENSION output_col);
22433b921b29Sopenharmony_ci 
22443b921b29Sopenharmony_ci@@ -1190,7 +1190,7 @@ EXTERN(void) jsimd_idct_ifast_sse2
22453b921b29Sopenharmony_ci   (void *dct_table, JCOEFPTR coef_block, JSAMPARRAY output_buf,
22463b921b29Sopenharmony_ci    JDIMENSION output_col);
22473b921b29Sopenharmony_ci 
22483b921b29Sopenharmony_ci-EXTERN(void) jsimd_idct_ifast_neon
22493b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_idct_ifast_neon
22503b921b29Sopenharmony_ci   (void *dct_table, JCOEFPTR coef_block, JSAMPARRAY output_buf,
22513b921b29Sopenharmony_ci    JDIMENSION output_col);
22523b921b29Sopenharmony_ci 
22533b921b29Sopenharmony_ci@@ -1230,13 +1230,13 @@ EXTERN(JOCTET *) jsimd_huff_encode_one_block_sse2
22543b921b29Sopenharmony_ci   (void *state, JOCTET *buffer, JCOEFPTR block, int last_dc_val,
22553b921b29Sopenharmony_ci    c_derived_tbl *dctbl, c_derived_tbl *actbl);
22563b921b29Sopenharmony_ci 
22573b921b29Sopenharmony_ci-EXTERN(JOCTET *) jsimd_huff_encode_one_block_neon
22583b921b29Sopenharmony_ci+HIDE(EXTERN)(JOCTET *) jsimd_huff_encode_one_block_neon
22593b921b29Sopenharmony_ci   (void *state, JOCTET *buffer, JCOEFPTR block, int last_dc_val,
22603b921b29Sopenharmony_ci    c_derived_tbl *dctbl, c_derived_tbl *actbl);
22613b921b29Sopenharmony_ci 
22623b921b29Sopenharmony_ci #ifndef NEON_INTRINSICS
22633b921b29Sopenharmony_ci 
22643b921b29Sopenharmony_ci-EXTERN(JOCTET *) jsimd_huff_encode_one_block_neon_slowtbl
22653b921b29Sopenharmony_ci+HIDE(EXTERN)(JOCTET *) jsimd_huff_encode_one_block_neon_slowtbl
22663b921b29Sopenharmony_ci   (void *state, JOCTET *buffer, JCOEFPTR block, int last_dc_val,
22673b921b29Sopenharmony_ci    c_derived_tbl *dctbl, c_derived_tbl *actbl);
22683b921b29Sopenharmony_ci 
22693b921b29Sopenharmony_ci@@ -1247,7 +1247,7 @@ EXTERN(void) jsimd_encode_mcu_AC_first_prepare_sse2
22703b921b29Sopenharmony_ci   (const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
22713b921b29Sopenharmony_ci    UJCOEF *values, size_t *zerobits);
22723b921b29Sopenharmony_ci 
22733b921b29Sopenharmony_ci-EXTERN(void) jsimd_encode_mcu_AC_first_prepare_neon
22743b921b29Sopenharmony_ci+HIDE(EXTERN)(void) jsimd_encode_mcu_AC_first_prepare_neon
22753b921b29Sopenharmony_ci   (const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
22763b921b29Sopenharmony_ci    UJCOEF *values, size_t *zerobits);
22773b921b29Sopenharmony_ci 
22783b921b29Sopenharmony_ci@@ -1255,6 +1255,6 @@ EXTERN(int) jsimd_encode_mcu_AC_refine_prepare_sse2
22793b921b29Sopenharmony_ci   (const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
22803b921b29Sopenharmony_ci    UJCOEF *absvalues, size_t *bits);
22813b921b29Sopenharmony_ci 
22823b921b29Sopenharmony_ci-EXTERN(int) jsimd_encode_mcu_AC_refine_prepare_neon
22833b921b29Sopenharmony_ci+HIDE(EXTERN)(int) jsimd_encode_mcu_AC_refine_prepare_neon
22843b921b29Sopenharmony_ci   (const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
22853b921b29Sopenharmony_ci    UJCOEF *absvalues, size_t *bits);
2286