Fix build when SIMD extensions are disabled

(Broken by previous commit)
This commit is contained in:
DRC
2022-11-04 13:08:08 -05:00
parent e8b40f3c2b
commit bf01ed2fbc
5 changed files with 50 additions and 15 deletions

View File

@@ -528,8 +528,6 @@ if(UNIX AND NOT APPLE)
endif() endif()
# Generate files # Generate files
configure_file(jconfig.h.in jconfig.h)
configure_file(jconfigint.h.in jconfigint.h)
configure_file(jversion.h.in jversion.h) configure_file(jversion.h.in jversion.h)
if(UNIX) if(UNIX)
configure_file(libjpeg.map.in libjpeg.map) configure_file(libjpeg.map.in libjpeg.map)
@@ -587,16 +585,18 @@ if(WITH_SIMD)
else() else()
message(STATUS "SIMD extensions: None (WITH_SIMD = ${WITH_SIMD})") message(STATUS "SIMD extensions: None (WITH_SIMD = ${WITH_SIMD})")
endif() 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) if(WITH_SIMD)
message(STATUS "SIMD extensions: ${CPU_TYPE} (WITH_SIMD = ${WITH_SIMD})") message(STATUS "SIMD extensions: ${CPU_TYPE} (WITH_SIMD = ${WITH_SIMD})")
if(MSVC_IDE OR XCODE) if(MSVC_IDE OR XCODE)
set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1) set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1)
endif() endif()
else() set(SIMD_TARGET_OBJECTS $<TARGET_OBJECTS:simd>)
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()
endif() endif()
if(WITH_JAVA) if(WITH_JAVA)
@@ -608,7 +608,7 @@ if(ENABLE_SHARED)
endif() endif()
if(ENABLE_STATIC) if(ENABLE_STATIC)
add_library(jpeg-static STATIC ${JPEG_SOURCES} $<TARGET_OBJECTS:simd> add_library(jpeg-static STATIC ${JPEG_SOURCES} ${SIMD_TARGET_OBJECTS}
${SIMD_OBJS} ${JPEG12_OBJS}) ${SIMD_OBJS} ${JPEG12_OBJS})
if(NOT MSVC) if(NOT MSVC)
set_target_properties(jpeg-static PROPERTIES OUTPUT_NAME jpeg) set_target_properties(jpeg-static PROPERTIES OUTPUT_NAME jpeg)
@@ -617,7 +617,7 @@ endif()
if(WITH_TURBOJPEG) if(WITH_TURBOJPEG)
if(ENABLE_SHARED) if(ENABLE_SHARED)
set(TURBOJPEG_SOURCES ${JPEG_SOURCES} $<TARGET_OBJECTS:simd> ${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 turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c rdbmp.c rdppm.c
wrbmp.c wrppm.c ${JPEG12_OBJS}) wrbmp.c wrppm.c ${JPEG12_OBJS})
set(TJMAPFILE ${CMAKE_CURRENT_SOURCE_DIR}/turbojpeg-mapfile) set(TJMAPFILE ${CMAKE_CURRENT_SOURCE_DIR}/turbojpeg-mapfile)
@@ -669,7 +669,7 @@ if(WITH_TURBOJPEG)
endif() endif()
if(ENABLE_STATIC) if(ENABLE_STATIC)
add_library(turbojpeg-static STATIC ${JPEG_SOURCES} $<TARGET_OBJECTS:simd> add_library(turbojpeg-static STATIC ${JPEG_SOURCES} ${SIMD_TARGET_OBJECTS}
${SIMD_OBJS} turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c rdbmp.c ${SIMD_OBJS} turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c rdbmp.c
rdppm.c wrbmp.c wrppm.c ${JPEG12_OBJS}) rdppm.c wrbmp.c wrppm.c ${JPEG12_OBJS})
set_property(TARGET turbojpeg-static PROPERTY COMPILE_FLAGS set_property(TARGET turbojpeg-static PROPERTY COMPILE_FLAGS

View File

@@ -264,10 +264,14 @@ start_pass_fdctmgr(j_compress_ptr cinfo)
} }
dtbl = fdct->divisors[qtblno]; dtbl = fdct->divisors[qtblno];
for (i = 0; i < DCTSIZE2; i++) { 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]) && if (!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]) &&
fdct->quantize == jsimd_quantize) fdct->quantize == jsimd_quantize)
fdct->quantize = quantize; fdct->quantize = quantize;
#else
compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]);
#endif
#else #else
dtbl[i] = ((DCTELEM)qtbl->quantval[i]) << 3; dtbl[i] = ((DCTELEM)qtbl->quantval[i]) << 3;
#endif #endif
@@ -304,13 +308,20 @@ start_pass_fdctmgr(j_compress_ptr cinfo)
} }
dtbl = fdct->divisors[qtblno]; dtbl = fdct->divisors[qtblno];
for (i = 0; i < DCTSIZE2; i++) { 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( if (!compute_reciprocal(
DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i], DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
(JLONG)aanscales[i]), (JLONG)aanscales[i]),
CONST_BITS - 3), &dtbl[i]) && CONST_BITS - 3), &dtbl[i]) &&
fdct->quantize == jsimd_quantize) fdct->quantize == jsimd_quantize)
fdct->quantize = quantize; fdct->quantize = quantize;
#else
compute_reciprocal(
DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
(JLONG)aanscales[i]),
CONST_BITS-3), &dtbl[i]);
#endif
#else #else
dtbl[i] = (DCTELEM) dtbl[i] = (DCTELEM)
DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i], DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],

View File

@@ -27,7 +27,11 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#ifdef WITH_SIMD
#include "jsimd.h" #include "jsimd.h"
#else
#include "jchuff.h"
#endif
#include <limits.h> #include <limits.h>
/* /*
@@ -180,7 +184,9 @@ start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics)
entropy->pub.finish_pass = finish_pass_huff; entropy->pub.finish_pass = finish_pass_huff;
} }
#ifdef WITH_SIMD
entropy->simd = jsimd_can_huff_encode_one_block(); entropy->simd = jsimd_can_huff_encode_one_block();
#endif
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[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 */ /* Initialize bit buffer to empty */
#ifdef WITH_SIMD
if (entropy->simd) { if (entropy->simd) {
entropy->saved.put_buffer.simd = 0; entropy->saved.put_buffer.simd = 0;
#if defined(__aarch64__) && !defined(NEON_INTRINSICS) #if defined(__aarch64__) && !defined(NEON_INTRINSICS)
@@ -227,7 +234,9 @@ start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics)
#else #else
entropy->saved.free_bits = SIMD_BIT_BUF_SIZE; entropy->saved.free_bits = SIMD_BIT_BUF_SIZE;
#endif #endif
} else { } else
#endif
{
entropy->saved.put_buffer.c = 0; entropy->saved.put_buffer.c = 0;
entropy->saved.free_bits = BIT_BUF_SIZE; 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 */ /* Encode a single block's worth of coefficients */
LOCAL(boolean) LOCAL(boolean)
@@ -561,6 +572,8 @@ encode_one_block_simd(working_state *state, JCOEFPTR block, int last_dc_val,
return TRUE; return TRUE;
} }
#endif
LOCAL(boolean) LOCAL(boolean)
encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val, encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val,
c_derived_tbl *dctbl, c_derived_tbl *actbl) 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 */ /* Encode the MCU data blocks */
#ifdef WITH_SIMD
if (entropy->simd) { if (entropy->simd) {
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
ci = cinfo->MCU_membership[blkn]; ci = cinfo->MCU_membership[blkn];
@@ -717,7 +731,9 @@ encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Update last_dc_val */ /* Update last_dc_val */
state.cur.last_dc_val[ci] = MCU_data[blkn][0][0]; state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
} }
} else { } else
#endif
{
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
ci = cinfo->MCU_membership[blkn]; ci = cinfo->MCU_membership[blkn];
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];

View File

@@ -21,7 +21,11 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#ifdef WITH_SIMD
#include "jsimd.h" #include "jsimd.h"
#else
#include "jchuff.h"
#endif
#include <limits.h> #include <limits.h>
#ifdef HAVE_INTRIN_H #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; entropy->pub.encode_mcu = encode_mcu_DC_first;
else else
entropy->pub.encode_mcu = encode_mcu_AC_first; entropy->pub.encode_mcu = encode_mcu_AC_first;
#ifdef WITH_SIMD
if (jsimd_can_encode_mcu_AC_first_prepare()) if (jsimd_can_encode_mcu_AC_first_prepare())
entropy->AC_first_prepare = jsimd_encode_mcu_AC_first_prepare; entropy->AC_first_prepare = jsimd_encode_mcu_AC_first_prepare;
else else
#endif
entropy->AC_first_prepare = encode_mcu_AC_first_prepare; entropy->AC_first_prepare = encode_mcu_AC_first_prepare;
} else { } else {
if (is_DC_band) if (is_DC_band)
entropy->pub.encode_mcu = encode_mcu_DC_refine; entropy->pub.encode_mcu = encode_mcu_DC_refine;
else { else {
entropy->pub.encode_mcu = encode_mcu_AC_refine; entropy->pub.encode_mcu = encode_mcu_AC_refine;
#ifdef WITH_SIMD
if (jsimd_can_encode_mcu_AC_refine_prepare()) if (jsimd_can_encode_mcu_AC_refine_prepare())
entropy->AC_refine_prepare = jsimd_encode_mcu_AC_refine_prepare; entropy->AC_refine_prepare = jsimd_encode_mcu_AC_refine_prepare;
else else
#endif
entropy->AC_refine_prepare = encode_mcu_AC_refine_prepare; entropy->AC_refine_prepare = encode_mcu_AC_refine_prepare;
/* AC refinement needs a correction bit buffer */ /* AC refinement needs a correction bit buffer */
if (entropy->bit_buffer == NULL) if (entropy->bit_buffer == NULL)

View File

@@ -36,7 +36,7 @@ if(MSVC)
${CMAKE_BINARY_DIR}/win/jpeg.rc) ${CMAKE_BINARY_DIR}/win/jpeg.rc)
set(JPEG_SRCS ${JPEG_SRCS} ${CMAKE_BINARY_DIR}/win/jpeg.rc) set(JPEG_SRCS ${JPEG_SRCS} ${CMAKE_BINARY_DIR}/win/jpeg.rc)
endif() endif()
add_library(jpeg SHARED ${JPEG_SRCS} ${DEFFILE} $<TARGET_OBJECTS:simd> add_library(jpeg SHARED ${JPEG_SRCS} ${DEFFILE} ${SIMD_TARGET_OBJECTS}
${SIMD_OBJS} ${JPEG12_OBJS}) ${SIMD_OBJS} ${JPEG12_OBJS})
set_target_properties(jpeg PROPERTIES SOVERSION ${SO_MAJOR_VERSION} set_target_properties(jpeg PROPERTIES SOVERSION ${SO_MAJOR_VERSION}