Skip to content

Commit

Permalink
Add SSE2 huffman encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Dec 28, 2015
1 parent fbe5007 commit 2cb4d41
Show file tree
Hide file tree
Showing 13 changed files with 945 additions and 9 deletions.
32 changes: 27 additions & 5 deletions jchuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, 2014-2015 D. R. Commander.
* Copyright (C) 2015 Matthieu Darbois.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
Expand All @@ -21,6 +22,7 @@
#include "jinclude.h"
#include "jpeglib.h"
#include "jchuff.h" /* Declarations shared with jcphuff.c */
#include "jsimdchuff.h"
#include <limits.h>

/*
Expand Down Expand Up @@ -478,6 +480,21 @@ flush_bits (working_state * state)


/* Encode a single block's worth of coefficients */
LOCAL(boolean)
encode_one_block_simd (working_state * state, JCOEFPTR block, int last_dc_val,
c_derived_tbl *dctbl, c_derived_tbl *actbl)
{
JOCTET _buffer[BUFSIZE], *buffer;
size_t bytes, bytestocopy; int localbuf = 0;

LOAD_BUFFER()

buffer = jsimd_chuff_encode_one_block(state, buffer, block, last_dc_val, dctbl, actbl);

STORE_BUFFER()

return TRUE;
}

LOCAL(boolean)
encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
Expand Down Expand Up @@ -587,7 +604,6 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
return TRUE;
}


/*
* Emit a restart marker & resynchronize predictions.
*/
Expand Down Expand Up @@ -624,6 +640,12 @@ encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
working_state state;
int blkn, ci;
jpeg_component_info * compptr;
boolean (*encode_one_block_ptr) (working_state*, JCOEFPTR, int,
c_derived_tbl *, c_derived_tbl *) = encode_one_block;

if (jsimd_can_chuff_encode_one_block()) {
encode_one_block_ptr = encode_one_block_simd;
}

/* Load up working state */
state.next_output_byte = cinfo->dest->next_output_byte;
Expand All @@ -642,10 +664,10 @@ encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
ci = cinfo->MCU_membership[blkn];
compptr = cinfo->cur_comp_info[ci];
if (! encode_one_block(&state,
MCU_data[blkn][0], state.cur.last_dc_val[ci],
entropy->dc_derived_tbls[compptr->dc_tbl_no],
entropy->ac_derived_tbls[compptr->ac_tbl_no]))
if (! encode_one_block_ptr(&state,
MCU_data[blkn][0], state.cur.last_dc_val[ci],
entropy->dc_derived_tbls[compptr->dc_tbl_no],
entropy->ac_derived_tbls[compptr->ac_tbl_no]))
return FALSE;
/* Update last_dc_val */
state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
Expand Down
19 changes: 19 additions & 0 deletions jsimdchuff.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* jsimdchuff.h
*
* Copyright 2015 Matthieu Darbois
*
* Based on the x86 SIMD extension for IJG JPEG library,
* Copyright (C) 1999-2006, MIYASAKA Masaru.
* For conditions of distribution and use, see copyright notice in jsimdext.inc
*
*/

EXTERN(int)
jsimd_can_chuff_encode_one_block (void);


EXTERN(JOCTET*)
jsimd_chuff_encode_one_block (/*working_state*/void * state, JOCTET *buffer,
JCOEFPTR block, int last_dc_val,
c_derived_tbl *dctbl, c_derived_tbl *actbl);
6 changes: 4 additions & 2 deletions simd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ if(SIMD_X86_64)
set(SIMD_BASENAMES jfdctflt-sse-64 jccolor-sse2-64 jcgray-sse2-64
jcsample-sse2-64 jdcolor-sse2-64 jdmerge-sse2-64 jdsample-sse2-64
jfdctfst-sse2-64 jfdctint-sse2-64 jidctflt-sse2-64 jidctfst-sse2-64
jidctint-sse2-64 jidctred-sse2-64 jquantf-sse2-64 jquanti-sse2-64)
jidctint-sse2-64 jidctred-sse2-64 jquantf-sse2-64 jquanti-sse2-64
jchuff-sse2-64)
message(STATUS "Building x86_64 SIMD extensions")
else()
set(SIMD_BASENAMES jsimdcpu jfdctflt-3dn jidctflt-3dn jquant-3dn jccolor-mmx
jcgray-mmx jcsample-mmx jdcolor-mmx jdmerge-mmx jdsample-mmx jfdctfst-mmx
jfdctint-mmx jidctfst-mmx jidctint-mmx jidctred-mmx jquant-mmx jfdctflt-sse
jidctflt-sse jquant-sse jccolor-sse2 jcgray-sse2 jcsample-sse2 jdcolor-sse2
jdmerge-sse2 jdsample-sse2 jfdctfst-sse2 jfdctint-sse2 jidctflt-sse2
jidctfst-sse2 jidctint-sse2 jidctred-sse2 jquantf-sse2 jquanti-sse2)
jidctfst-sse2 jidctint-sse2 jidctred-sse2 jquantf-sse2 jquanti-sse2
jchuff-sse2)
message(STATUS "Building i386 SIMD extensions")
endif()

Expand Down
6 changes: 4 additions & 2 deletions simd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ libsimd_la_SOURCES = jsimd_x86_64.c jsimd.h jsimdcfg.inc.h jsimdext.inc \
jdcolor-sse2-64.asm jdmerge-sse2-64.asm jdsample-sse2-64.asm \
jfdctfst-sse2-64.asm jfdctint-sse2-64.asm jidctflt-sse2-64.asm \
jidctfst-sse2-64.asm jidctint-sse2-64.asm jidctred-sse2-64.asm \
jquantf-sse2-64.asm jquanti-sse2-64.asm
jquantf-sse2-64.asm jquanti-sse2-64.asm \
jchuff-sse2-64.asm

jccolor-sse2-64.lo: jccolext-sse2-64.asm
jcgray-sse2-64.lo: jcgryext-sse2-64.asm
Expand All @@ -40,7 +41,8 @@ libsimd_la_SOURCES = jsimd_i386.c jsimd.h jsimdcfg.inc.h jsimdext.inc \
jdcolor-sse2.asm jdmerge-sse2.asm jdsample-sse2.asm \
jfdctfst-sse2.asm jfdctint-sse2.asm jidctflt-sse2.asm \
jidctfst-sse2.asm jidctint-sse2.asm jidctred-sse2.asm \
jquantf-sse2.asm jquanti-sse2.asm
jquantf-sse2.asm jquanti-sse2.asm \
jchuff-sse2.asm

jccolor-mmx.lo: jccolext-mmx.asm
jcgray.-mmx.lo: jcgryext-mmx.asm
Expand Down
Loading

0 comments on commit 2cb4d41

Please sign in to comment.