55 * Copyright (C) 1991-1997, Thomas G. Lane.
66 * libjpeg-turbo Modifications:
77 * Copyright (C) 2009-2011, 2014-2015 D. R. Commander.
8+ * Copyright (C) 2015 Matthieu Darbois.
89 * For conditions of distribution and use, see the accompanying README.ijg
910 * file.
1011 *
2122#include "jinclude.h"
2223#include "jpeglib.h"
2324#include "jchuff.h" /* Declarations shared with jcphuff.c */
25+ #include "jsimdchuff.h"
2426#include <limits.h>
2527
2628/*
@@ -478,6 +480,21 @@ flush_bits (working_state * state)
478480
479481
480482/* Encode a single block's worth of coefficients */
483+ LOCAL (boolean )
484+ encode_one_block_simd (working_state * state , JCOEFPTR block , int last_dc_val ,
485+ c_derived_tbl * dctbl , c_derived_tbl * actbl )
486+ {
487+ JOCTET _buffer [BUFSIZE ], * buffer ;
488+ size_t bytes , bytestocopy ; int localbuf = 0 ;
489+
490+ LOAD_BUFFER ()
491+
492+ buffer = jsimd_chuff_encode_one_block (state , buffer , block , last_dc_val , dctbl , actbl );
493+
494+ STORE_BUFFER ()
495+
496+ return TRUE;
497+ }
481498
482499LOCAL (boolean )
483500encode_one_block (working_state * state , JCOEFPTR block , int last_dc_val ,
@@ -587,7 +604,6 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
587604 return TRUE;
588605}
589606
590-
591607/*
592608 * Emit a restart marker & resynchronize predictions.
593609 */
@@ -624,6 +640,12 @@ encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
624640 working_state state ;
625641 int blkn , ci ;
626642 jpeg_component_info * compptr ;
643+ boolean (* encode_one_block_ptr ) (working_state * , JCOEFPTR , int ,
644+ c_derived_tbl * , c_derived_tbl * ) = encode_one_block ;
645+
646+ if (jsimd_can_chuff_encode_one_block ()) {
647+ encode_one_block_ptr = encode_one_block_simd ;
648+ }
627649
628650 /* Load up working state */
629651 state .next_output_byte = cinfo -> dest -> next_output_byte ;
@@ -642,10 +664,10 @@ encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
642664 for (blkn = 0 ; blkn < cinfo -> blocks_in_MCU ; blkn ++ ) {
643665 ci = cinfo -> MCU_membership [blkn ];
644666 compptr = cinfo -> cur_comp_info [ci ];
645- if (! encode_one_block (& state ,
646- MCU_data [blkn ][0 ], state .cur .last_dc_val [ci ],
647- entropy -> dc_derived_tbls [compptr -> dc_tbl_no ],
648- entropy -> ac_derived_tbls [compptr -> ac_tbl_no ]))
667+ if (! encode_one_block_ptr (& state ,
668+ MCU_data [blkn ][0 ], state .cur .last_dc_val [ci ],
669+ entropy -> dc_derived_tbls [compptr -> dc_tbl_no ],
670+ entropy -> ac_derived_tbls [compptr -> ac_tbl_no ]))
649671 return FALSE;
650672 /* Update last_dc_val */
651673 state .cur .last_dc_val [ci ] = MCU_data [blkn ][0 ][0 ];
0 commit comments