diff --git a/CMakeLists.txt b/CMakeLists.txt index 6895f00c..a1897086 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -528,8 +528,6 @@ if(UNIX AND NOT APPLE) endif() # Generate files -configure_file(jconfig.h.in jconfig.h) -configure_file(jconfigint.h.in jconfigint.h) configure_file(jversion.h.in jversion.h) if(UNIX) configure_file(libjpeg.map.in libjpeg.map) @@ -587,16 +585,18 @@ if(WITH_SIMD) else() message(STATUS "SIMD extensions: None (WITH_SIMD = ${WITH_SIMD})") endif() + +# We have to generate these here, because if the build system tries and fails +# to enable the SIMD extensions, the value of WITH_SIMD will have changed. +configure_file(jconfig.h.in jconfig.h) +configure_file(jconfigint.h.in jconfigint.h) + if(WITH_SIMD) message(STATUS "SIMD extensions: ${CPU_TYPE} (WITH_SIMD = ${WITH_SIMD})") if(MSVC_IDE OR XCODE) set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1) endif() -else() - add_library(simd OBJECT jsimd_none.c) - if(NOT WIN32 AND (CMAKE_POSITION_INDEPENDENT_CODE OR ENABLE_SHARED)) - set_target_properties(simd PROPERTIES POSITION_INDEPENDENT_CODE 1) - endif() + set(SIMD_TARGET_OBJECTS $) endif() if(WITH_JAVA) @@ -608,7 +608,7 @@ if(ENABLE_SHARED) endif() if(ENABLE_STATIC) - add_library(jpeg-static STATIC ${JPEG_SOURCES} $ + add_library(jpeg-static STATIC ${JPEG_SOURCES} ${SIMD_TARGET_OBJECTS} ${SIMD_OBJS} ${JPEG12_OBJS}) if(NOT MSVC) set_target_properties(jpeg-static PROPERTIES OUTPUT_NAME jpeg) @@ -617,7 +617,7 @@ endif() if(WITH_TURBOJPEG) if(ENABLE_SHARED) - set(TURBOJPEG_SOURCES ${JPEG_SOURCES} $ ${SIMD_OBJS} + set(TURBOJPEG_SOURCES ${JPEG_SOURCES} ${SIMD_TARGET_OBJECTS} ${SIMD_OBJS} turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c rdbmp.c rdppm.c wrbmp.c wrppm.c ${JPEG12_OBJS}) set(TJMAPFILE ${CMAKE_CURRENT_SOURCE_DIR}/turbojpeg-mapfile) @@ -669,7 +669,7 @@ if(WITH_TURBOJPEG) endif() if(ENABLE_STATIC) - add_library(turbojpeg-static STATIC ${JPEG_SOURCES} $ + add_library(turbojpeg-static STATIC ${JPEG_SOURCES} ${SIMD_TARGET_OBJECTS} ${SIMD_OBJS} turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c rdbmp.c rdppm.c wrbmp.c wrppm.c ${JPEG12_OBJS}) set_property(TARGET turbojpeg-static PROPERTY COMPILE_FLAGS diff --git a/jcdctmgr.c b/jcdctmgr.c index ac0b40b9..7191ee73 100644 --- a/jcdctmgr.c +++ b/jcdctmgr.c @@ -264,10 +264,14 @@ start_pass_fdctmgr(j_compress_ptr cinfo) } dtbl = fdct->divisors[qtblno]; for (i = 0; i < DCTSIZE2; i++) { -#if defined(WITH_SIMD) && BITS_IN_JSAMPLE == 8 +#if BITS_IN_JSAMPLE == 8 +#ifdef WITH_SIMD if (!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]) && fdct->quantize == jsimd_quantize) fdct->quantize = quantize; +#else + compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]); +#endif #else dtbl[i] = ((DCTELEM)qtbl->quantval[i]) << 3; #endif @@ -304,13 +308,20 @@ start_pass_fdctmgr(j_compress_ptr cinfo) } dtbl = fdct->divisors[qtblno]; for (i = 0; i < DCTSIZE2; i++) { -#if defined(WITH_SIMD) && BITS_IN_JSAMPLE == 8 +#if BITS_IN_JSAMPLE == 8 +#ifdef WITH_SIMD if (!compute_reciprocal( DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i], (JLONG)aanscales[i]), CONST_BITS - 3), &dtbl[i]) && fdct->quantize == jsimd_quantize) fdct->quantize = quantize; +#else + compute_reciprocal( + DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i], + (JLONG)aanscales[i]), + CONST_BITS-3), &dtbl[i]); +#endif #else dtbl[i] = (DCTELEM) DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i], diff --git a/jchuff.c b/jchuff.c index c57f10d3..cef5c880 100644 --- a/jchuff.c +++ b/jchuff.c @@ -27,7 +27,11 @@ #define JPEG_INTERNALS #include "jinclude.h" #include "jpeglib.h" +#ifdef WITH_SIMD #include "jsimd.h" +#else +#include "jchuff.h" +#endif #include /* @@ -180,7 +184,9 @@ start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics) entropy->pub.finish_pass = finish_pass_huff; } +#ifdef WITH_SIMD entropy->simd = jsimd_can_huff_encode_one_block(); +#endif for (ci = 0; ci < cinfo->comps_in_scan; ci++) { compptr = cinfo->cur_comp_info[ci]; @@ -220,6 +226,7 @@ start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics) } /* Initialize bit buffer to empty */ +#ifdef WITH_SIMD if (entropy->simd) { entropy->saved.put_buffer.simd = 0; #if defined(__aarch64__) && !defined(NEON_INTRINSICS) @@ -227,7 +234,9 @@ start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics) #else entropy->saved.free_bits = SIMD_BIT_BUF_SIZE; #endif - } else { + } else +#endif + { entropy->saved.put_buffer.c = 0; entropy->saved.free_bits = BIT_BUF_SIZE; } @@ -542,6 +551,8 @@ flush_bits(working_state *state) } +#ifdef WITH_SIMD + /* Encode a single block's worth of coefficients */ LOCAL(boolean) @@ -561,6 +572,8 @@ encode_one_block_simd(working_state *state, JCOEFPTR block, int last_dc_val, return TRUE; } +#endif + LOCAL(boolean) encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val, c_derived_tbl *dctbl, c_derived_tbl *actbl) @@ -705,6 +718,7 @@ encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data) } /* Encode the MCU data blocks */ +#ifdef WITH_SIMD if (entropy->simd) { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { ci = cinfo->MCU_membership[blkn]; @@ -717,7 +731,9 @@ encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data) /* Update last_dc_val */ state.cur.last_dc_val[ci] = MCU_data[blkn][0][0]; } - } else { + } else +#endif + { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { ci = cinfo->MCU_membership[blkn]; compptr = cinfo->cur_comp_info[ci]; diff --git a/jcphuff.c b/jcphuff.c index d11f6510..25107f60 100644 --- a/jcphuff.c +++ b/jcphuff.c @@ -21,7 +21,11 @@ #define JPEG_INTERNALS #include "jinclude.h" #include "jpeglib.h" +#ifdef WITH_SIMD #include "jsimd.h" +#else +#include "jchuff.h" +#endif #include #ifdef HAVE_INTRIN_H @@ -223,18 +227,22 @@ start_pass_phuff(j_compress_ptr cinfo, boolean gather_statistics) entropy->pub.encode_mcu = encode_mcu_DC_first; else entropy->pub.encode_mcu = encode_mcu_AC_first; +#ifdef WITH_SIMD if (jsimd_can_encode_mcu_AC_first_prepare()) entropy->AC_first_prepare = jsimd_encode_mcu_AC_first_prepare; else +#endif entropy->AC_first_prepare = encode_mcu_AC_first_prepare; } else { if (is_DC_band) entropy->pub.encode_mcu = encode_mcu_DC_refine; else { entropy->pub.encode_mcu = encode_mcu_AC_refine; +#ifdef WITH_SIMD if (jsimd_can_encode_mcu_AC_refine_prepare()) entropy->AC_refine_prepare = jsimd_encode_mcu_AC_refine_prepare; else +#endif entropy->AC_refine_prepare = encode_mcu_AC_refine_prepare; /* AC refinement needs a correction bit buffer */ if (entropy->bit_buffer == NULL) diff --git a/sharedlib/CMakeLists.txt b/sharedlib/CMakeLists.txt index ca7880d7..ed23f876 100644 --- a/sharedlib/CMakeLists.txt +++ b/sharedlib/CMakeLists.txt @@ -36,7 +36,7 @@ if(MSVC) ${CMAKE_BINARY_DIR}/win/jpeg.rc) set(JPEG_SRCS ${JPEG_SRCS} ${CMAKE_BINARY_DIR}/win/jpeg.rc) endif() -add_library(jpeg SHARED ${JPEG_SRCS} ${DEFFILE} $ +add_library(jpeg SHARED ${JPEG_SRCS} ${DEFFILE} ${SIMD_TARGET_OBJECTS} ${SIMD_OBJS} ${JPEG12_OBJS}) set_target_properties(jpeg PROPERTIES SOVERSION ${SO_MAJOR_VERSION}