Skip to content

Commit

Permalink
Update libjpeg-turbo to 3.0.0 (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Aug 25, 2023
1 parent 94b3dbf commit 7cdb539
Show file tree
Hide file tree
Showing 6 changed files with 390 additions and 91 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ deps = {
"third_party/externals/imgui" : "https://skia.googlesource.com/external/github.com/ocornut/imgui.git@55d35d8387c15bf0cfd71861df67af8cfbda7456",
"third_party/externals/libavif" : "https://github.com/AOMediaCodec/libavif.git@f49462dc93784bf34148715eee36ab6697ca0b35",
"third_party/externals/libgav1" : "https://chromium.googlesource.com/codecs/libgav1.git@0fb779c1e169fe6c229cd1fa9cc6ea6feeb441da",
"third_party/externals/libjpeg-turbo" : "https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@ed683925e4897a84b3bffc5c1414c85b97a129a3",
"third_party/externals/libjpeg-turbo" : "https://github.com/libjpeg-turbo/libjpeg-turbo.git@6c87537f60941f3c265c339fe60d1e31d2a42ccf",
"third_party/externals/libjxl" : "https://chromium.googlesource.com/external/gitlab.com/wg1/jpeg-xl.git@a205468bc5d3a353fb15dae2398a101dff52f2d3",
"third_party/externals/libpng" : "https://skia.googlesource.com/third_party/libpng.git@f135775ad4e5d4408d2e12ffcc71bb36e6b48551",
"third_party/externals/libwebp" : "https://chromium.googlesource.com/webm/libwebp.git@fd7b5d48464475408d32d2611bdb6947d4246b97",
Expand Down
229 changes: 139 additions & 90 deletions third_party/libjpeg-turbo/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,106 +14,155 @@ if (skia_use_system_libjpeg_turbo) {
libs = [ "jpeg" ]
}
} else {
third_party("libjpeg") {
public_include_dirs = [
".",
"../externals/libjpeg-turbo",
]
use_simd_optimizations = false
if (!is_win && (current_cpu == "arm" || current_cpu == "arm64")) {
use_simd_optimizations = true
}

libjpeg_include_dirs = [
".",
"../externals/libjpeg-turbo",
]
libjpeg16_sources = [
"../externals/libjpeg-turbo/jcapistd.c",
"../externals/libjpeg-turbo/jccolor.c",
"../externals/libjpeg-turbo/jcdiffct.c",
"../externals/libjpeg-turbo/jclossls.c",
"../externals/libjpeg-turbo/jcmainct.c",
"../externals/libjpeg-turbo/jcprepct.c",
"../externals/libjpeg-turbo/jcsample.c",
"../externals/libjpeg-turbo/jdapistd.c",
"../externals/libjpeg-turbo/jdcolor.c",
"../externals/libjpeg-turbo/jddiffct.c",
"../externals/libjpeg-turbo/jdlossls.c",
"../externals/libjpeg-turbo/jdmainct.c",
"../externals/libjpeg-turbo/jdpostct.c",
"../externals/libjpeg-turbo/jdsample.c",
"../externals/libjpeg-turbo/jutils.c",
]
libjpeg12_sources = [
"../externals/libjpeg-turbo/jccoefct.c",
"../externals/libjpeg-turbo/jcdctmgr.c",
"../externals/libjpeg-turbo/jdcoefct.c",
"../externals/libjpeg-turbo/jddctmgr.c",
"../externals/libjpeg-turbo/jdmerge.c",
"../externals/libjpeg-turbo/jfdctfst.c",
"../externals/libjpeg-turbo/jfdctint.c",
"../externals/libjpeg-turbo/jidctflt.c",
"../externals/libjpeg-turbo/jidctfst.c",
"../externals/libjpeg-turbo/jidctint.c",
"../externals/libjpeg-turbo/jidctred.c",
"../externals/libjpeg-turbo/jquant1.c",
"../externals/libjpeg-turbo/jquant2.c",
]
libjpeg_sources = [
"../externals/libjpeg-turbo/jcapimin.c",
"../externals/libjpeg-turbo/jchuff.c",
"../externals/libjpeg-turbo/jcicc.c",
"../externals/libjpeg-turbo/jcinit.c",
"../externals/libjpeg-turbo/jclhuff.c",
"../externals/libjpeg-turbo/jcmarker.c",
"../externals/libjpeg-turbo/jcmaster.c",
"../externals/libjpeg-turbo/jcomapi.c",
"../externals/libjpeg-turbo/jcparam.c",
"../externals/libjpeg-turbo/jcphuff.c",
"../externals/libjpeg-turbo/jctrans.c",
"../externals/libjpeg-turbo/jdapimin.c",
"../externals/libjpeg-turbo/jdatadst.c",
"../externals/libjpeg-turbo/jdatasrc.c",
"../externals/libjpeg-turbo/jdhuff.c",
"../externals/libjpeg-turbo/jdicc.c",
"../externals/libjpeg-turbo/jdinput.c",
"../externals/libjpeg-turbo/jdlhuff.c",
"../externals/libjpeg-turbo/jdmarker.c",
"../externals/libjpeg-turbo/jdmaster.c",
"../externals/libjpeg-turbo/jdphuff.c",
"../externals/libjpeg-turbo/jdtrans.c",
"../externals/libjpeg-turbo/jerror.c",
"../externals/libjpeg-turbo/jfdctflt.c",
"../externals/libjpeg-turbo/jmemmgr.c",
"../externals/libjpeg-turbo/jmemnobs.c",
"../externals/libjpeg-turbo/jaricom.c", # WITH_ARITH_ENC or WITH_ARITH_DEC
"../externals/libjpeg-turbo/jcarith.c", # WITH_ARITH_ENC
"../externals/libjpeg-turbo/jdarith.c", # WITH_ARITH_DEC
]

source_set("libjpeg16") {
visibility = [ ":*" ]
defines = [ "BITS_IN_JSAMPLE=16" ]
if (!use_simd_optimizations) {
defines += [ "CPU_NO_SIMD" ]
}
include_dirs = libjpeg_include_dirs
sources = libjpeg16_sources
}

defines = [
"TURBO_FOR_WINDOWS",
source_set("libjpeg12") {
visibility = [ ":*" ]
defines = [ "BITS_IN_JSAMPLE=12" ]
if (!use_simd_optimizations) {
defines += [ "CPU_NO_SIMD" ]
}
include_dirs = libjpeg_include_dirs
sources = libjpeg16_sources + libjpeg12_sources
}

# Add support for arithmetic encoding (C_) and decoding (D_).
# This matches Android. Note that such JPEGs are likely rare, given lack of
# support by major browsers.
"C_ARITH_CODING_SUPPORTED=1",
"D_ARITH_CODING_SUPPORTED=1",
source_set("libjpegsimd") {
visibility = [ ":*" ]
defines = [ "NEON_INTRINSICS" ]
include_dirs = libjpeg_include_dirs
include_dirs += [
"../externals/libjpeg-turbo/simd/arm",
]
sources = [
"../externals/libjpeg-turbo/simd/arm/jccolor-neon.c",
"../externals/libjpeg-turbo/simd/arm/jcgray-neon.c",
"../externals/libjpeg-turbo/simd/arm/jcphuff-neon.c",
"../externals/libjpeg-turbo/simd/arm/jcsample-neon.c",
"../externals/libjpeg-turbo/simd/arm/jdcolor-neon.c",
"../externals/libjpeg-turbo/simd/arm/jdmerge-neon.c",
"../externals/libjpeg-turbo/simd/arm/jdsample-neon.c",
"../externals/libjpeg-turbo/simd/arm/jfdctfst-neon.c",
"../externals/libjpeg-turbo/simd/arm/jfdctint-neon.c",
"../externals/libjpeg-turbo/simd/arm/jidctfst-neon.c",
"../externals/libjpeg-turbo/simd/arm/jidctint-neon.c",
"../externals/libjpeg-turbo/simd/arm/jidctred-neon.c",
"../externals/libjpeg-turbo/simd/arm/jquanti-neon.c",
]
if (current_cpu == "arm") {
sources += [
"../externals/libjpeg-turbo/simd/arm/aarch32/jchuff-neon.c",
"../externals/libjpeg-turbo/simd/arm/aarch32/jsimd.c",
]
} else if (current_cpu == "arm64") {
sources += [
"../externals/libjpeg-turbo/simd/arm/aarch64/jchuff-neon.c",
"../externals/libjpeg-turbo/simd/arm/aarch64/jsimd.c",
]
}
}

third_party("libjpeg") {
public_include_dirs = libjpeg_include_dirs

defines = []
if (!is_win || is_clang) {
defines += [ "USE_CLZ_INTRINSIC" ] # Cuts a 64K table.
}
if (!use_simd_optimizations) {
defines += [ "CPU_NO_SIMD" ]
}

sources = [
"../externals/libjpeg-turbo/jaricom.c",
"../externals/libjpeg-turbo/jcapimin.c",
"../externals/libjpeg-turbo/jcapistd.c",
"../externals/libjpeg-turbo/jcarith.c",
"../externals/libjpeg-turbo/jccoefct.c",
"../externals/libjpeg-turbo/jccolor.c",
"../externals/libjpeg-turbo/jcdctmgr.c",
"../externals/libjpeg-turbo/jchuff.c",
"../externals/libjpeg-turbo/jcinit.c",
"../externals/libjpeg-turbo/jcmainct.c",
"../externals/libjpeg-turbo/jcmarker.c",
"../externals/libjpeg-turbo/jcmaster.c",
"../externals/libjpeg-turbo/jcomapi.c",
"../externals/libjpeg-turbo/jcparam.c",
"../externals/libjpeg-turbo/jcphuff.c",
"../externals/libjpeg-turbo/jcprepct.c",
"../externals/libjpeg-turbo/jcsample.c",
"../externals/libjpeg-turbo/jdapimin.c",
"../externals/libjpeg-turbo/jdapistd.c",
"../externals/libjpeg-turbo/jdarith.c",
"../externals/libjpeg-turbo/jdcoefct.c",
"../externals/libjpeg-turbo/jdcolor.c",
"../externals/libjpeg-turbo/jddctmgr.c",
"../externals/libjpeg-turbo/jdhuff.c",
"../externals/libjpeg-turbo/jdinput.c",
"../externals/libjpeg-turbo/jdmainct.c",
"../externals/libjpeg-turbo/jdmarker.c",
"../externals/libjpeg-turbo/jdmaster.c",
"../externals/libjpeg-turbo/jdmerge.c",
"../externals/libjpeg-turbo/jdphuff.c",
"../externals/libjpeg-turbo/jdpostct.c",
"../externals/libjpeg-turbo/jdsample.c",
"../externals/libjpeg-turbo/jerror.c",
"../externals/libjpeg-turbo/jfdctflt.c",
"../externals/libjpeg-turbo/jfdctfst.c",
"../externals/libjpeg-turbo/jfdctint.c",
"../externals/libjpeg-turbo/jidctflt.c",
"../externals/libjpeg-turbo/jidctfst.c",
"../externals/libjpeg-turbo/jidctint.c",
"../externals/libjpeg-turbo/jidctred.c",
"../externals/libjpeg-turbo/jmemmgr.c",
"../externals/libjpeg-turbo/jmemnobs.c",
"../externals/libjpeg-turbo/jpeg_nbits_table.c",
"../externals/libjpeg-turbo/jquant1.c",
"../externals/libjpeg-turbo/jquant2.c",
"../externals/libjpeg-turbo/jutils.c",
]
sources = libjpeg16_sources + libjpeg12_sources + libjpeg_sources

if (!is_win && (current_cpu == "arm" || current_cpu == "arm64")) {
defines += [ "NEON_INTRINSICS" ]
sources += [
"../externals/libjpeg-turbo/simd/arm/jccolor-neon.c",
"../externals/libjpeg-turbo/simd/arm/jcgray-neon.c",
"../externals/libjpeg-turbo/simd/arm/jcphuff-neon.c",
"../externals/libjpeg-turbo/simd/arm/jcsample-neon.c",
"../externals/libjpeg-turbo/simd/arm/jdcolor-neon.c",
"../externals/libjpeg-turbo/simd/arm/jdmerge-neon.c",
"../externals/libjpeg-turbo/simd/arm/jdsample-neon.c",
"../externals/libjpeg-turbo/simd/arm/jfdctfst-neon.c",
"../externals/libjpeg-turbo/simd/arm/jfdctint-neon.c",
"../externals/libjpeg-turbo/simd/arm/jidctfst-neon.c",
"../externals/libjpeg-turbo/simd/arm/jidctint-neon.c",
"../externals/libjpeg-turbo/simd/arm/jidctred-neon.c",
"../externals/libjpeg-turbo/simd/arm/jquanti-neon.c",
deps = [
":libjpeg16",
":libjpeg12",
]
if (use_simd_optimizations) {
deps += [
":libjpegsimd",
]
include_dirs = [ "../externals/libjpeg-turbo/simd/arm" ]
if (current_cpu == "arm") {
sources += [
"../externals/libjpeg-turbo/simd/arm/aarch32/jchuff-neon.c",
"../externals/libjpeg-turbo/simd/arm/aarch32/jsimd.c",
]
} else if (current_cpu == "arm64") {
sources += [
"../externals/libjpeg-turbo/simd/arm/aarch64/jchuff-neon.c",
"../externals/libjpeg-turbo/simd/arm/aarch64/jsimd.c",
]
}
} else {
sources += [ "../externals/libjpeg-turbo/jsimd_none.c" ]
}
}
}
62 changes: 62 additions & 0 deletions third_party/libjpeg-turbo/jconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* Version ID for the JPEG library.
* Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
*/
#define JPEG_LIB_VERSION 62

/* libjpeg-turbo version */
#define LIBJPEG_TURBO_VERSION 3.0.0

/* libjpeg-turbo version in integer form */
#define LIBJPEG_TURBO_VERSION_NUMBER 3000000

/* Support arithmetic encoding when using 8-bit samples */
#define C_ARITH_CODING_SUPPORTED 1

/* Support arithmetic decoding when using 8-bit samples */
#define D_ARITH_CODING_SUPPORTED 1

/* Support in-memory source/destination managers */
#define MEM_SRCDST_SUPPORTED 1

#ifndef CPU_NO_SIMD
/* Use accelerated SIMD routines when using 8-bit samples */
#define WITH_SIMD 1
#endif

/* This version of libjpeg-turbo supports run-time selection of data precision,
* so BITS_IN_JSAMPLE is no longer used to specify the data precision at build
* time. However, some downstream software expects the macro to be defined.
* Since 12-bit data precision is an opt-in feature that requires explicitly
* calling 12-bit-specific libjpeg API functions and using 12-bit-specific data
* types, the unmodified portion of the libjpeg API still behaves as if it were
* built for 8-bit precision, and JSAMPLE is still literally an 8-bit data
* type. Thus, it is correct to define BITS_IN_JSAMPLE to 8 here.
*/
#ifndef BITS_IN_JSAMPLE
#define BITS_IN_JSAMPLE 8
#endif

#ifdef _WIN32

#undef RIGHT_SHIFT_IS_UNSIGNED

/* Define "boolean" as unsigned char, not int, per Windows custom */
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean;
#endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */

/* Define "INT32" as int, not long, per Windows custom */
#if !(defined(_BASETSD_H_) || defined(_BASETSD_H)) /* don't conflict if basetsd.h already read */
typedef short INT16;
typedef signed int INT32;
#endif
#define XMD_H /* prevent jmorecfg.h from redefining it */

#else

/* Define if your (broken) compiler shifts signed values as if they were
unsigned. */
/* #undef RIGHT_SHIFT_IS_UNSIGNED */

#endif
Loading

0 comments on commit 7cdb539

Please sign in to comment.