Skip to content

Commit 24374ba

Browse files
committed
use libjpeg_turbo for improved jpg compatibility and speed
1 parent 0595bb8 commit 24374ba

File tree

129 files changed

+50949
-5263
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+50949
-5263
lines changed

COPYRIGHT.txt

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,18 @@ Comment: Jolt Physics
313313
Copyright: 2021, Jorrit Rouwe
314314
License: Expat
315315

316-
Files: thirdparty/jpeg-compressor/*
317-
Comment: jpeg-compressor
318-
Copyright: 2012, Rich Geldreich
319-
License: public-domain or Apache-2.0
320-
321316
Files: thirdparty/libbacktrace/*
322317
Comment: libbacktrace
323318
Copyright: 2012-2021, Free Software Foundation, Inc.
324319
License: BSD-3-clause
325320

321+
Files: thirdparty/libjpeg-turbo/*
322+
Comment: libjpeg-turbo
323+
Copyright: Copyright (C)2009-2024 D. R. Commander
324+
Copyright (C)2015 Viktor Szathmáry.
325+
1991-2020, Thomas G. Lane, Guido Vollbeding
326+
License: TurboJPEG modified BSD-3-clause, IJG License
327+
326328
Files: thirdparty/libktx/*
327329
Comment: KTX
328330
Copyright: 2013-2020, Mark Callow
@@ -1672,6 +1674,42 @@ License: HarfBuzz
16721674
ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
16731675
PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
16741676

1677+
License: IJG License
1678+
The authors make NO WARRANTY or representation, either express or implied,
1679+
with respect to this software, its quality, accuracy, merchantability, or
1680+
fitness for a particular purpose. This software is provided "AS IS", and you,
1681+
its user, assume the entire risk as to its quality and accuracy.
1682+
1683+
This software is copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding.
1684+
All Rights Reserved except as specified below.
1685+
1686+
Permission is hereby granted to use, copy, modify, and distribute this
1687+
software (or portions thereof) for any purpose, without fee, subject to these
1688+
conditions:
1689+
(1) If any part of the source code for this software is distributed, then this
1690+
README file must be included, with this copyright and no-warranty notice
1691+
unaltered; and any additions, deletions, or changes to the original files
1692+
must be clearly indicated in accompanying documentation.
1693+
(2) If only executable code is distributed, then the accompanying
1694+
documentation must state that "this software is based in part on the work of
1695+
the Independent JPEG Group".
1696+
(3) Permission for use of this software is granted only if the user accepts
1697+
full responsibility for any undesirable consequences; the authors accept
1698+
NO LIABILITY for damages of any kind.
1699+
1700+
These conditions apply to any software derived from or based on the IJG code,
1701+
not just to the unmodified library. If you use our work, you ought to
1702+
acknowledge us.
1703+
1704+
Permission is NOT granted for the use of any IJG author's name or company name
1705+
in advertising or publicity relating to this software or products derived from
1706+
it. This software may be referred to only as "the Independent JPEG Group's
1707+
software".
1708+
1709+
We specifically permit and encourage the use of this software as the basis of
1710+
commercial products, provided that all warranty or liability claims are
1711+
assumed by the product vendor.
1712+
16751713
License: MPL-2.0
16761714
Mozilla Public License Version 2.0
16771715
==================================
@@ -2130,6 +2168,34 @@ License: OFL-1.1
21302168
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21312169
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE.
21322170

2171+
License: TurboJPEG modified BSD-3-clause
2172+
Copyright (C)2009-2024 D. R. Commander. All Rights Reserved.<br>
2173+
Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
2174+
2175+
Redistribution and use in source and binary forms, with or without
2176+
modification, are permitted provided that the following conditions are met:
2177+
2178+
- Redistributions of source code must retain the above copyright notice,
2179+
this list of conditions and the following disclaimer.
2180+
- Redistributions in binary form must reproduce the above copyright notice,
2181+
this list of conditions and the following disclaimer in the documentation
2182+
and/or other materials provided with the distribution.
2183+
- Neither the name of the libjpeg-turbo Project nor the names of its
2184+
contributors may be used to endorse or promote products derived from this
2185+
software without specific prior written permission.
2186+
2187+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
2188+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2189+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2190+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
2191+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2192+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2193+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2194+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2195+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2196+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2197+
POSSIBILITY OF SUCH DAMAGE.
2198+
21332199
License: Unicode
21342200
COPYRIGHT AND PERMISSION NOTICE (ICU 58 and later)
21352201
.

SConstruct

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ opts.Add(BoolVariable("builtin_glslang", "Use the built-in glslang library", Tru
257257
opts.Add(BoolVariable("builtin_graphite", "Use the built-in Graphite library", True))
258258
opts.Add(BoolVariable("builtin_harfbuzz", "Use the built-in HarfBuzz library", True))
259259
opts.Add(BoolVariable("builtin_icu4c", "Use the built-in ICU library", True))
260+
opts.Add(BoolVariable("builtin_libjpeg_turbo", "Use the built-in libjpeg-turbo library", True))
260261
opts.Add(BoolVariable("builtin_libogg", "Use the built-in libogg library", True))
261262
opts.Add(BoolVariable("builtin_libpng", "Use the built-in libpng library", True))
262263
opts.Add(BoolVariable("builtin_libtheora", "Use the built-in libtheora library", True))

misc/error_suppressions/tsan.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ deadlock:tests/core/templates/test_command_queue.h
55
deadlock:modules/text_server_adv/text_server_adv.cpp
66
deadlock:modules/text_server_fb/text_server_fb.cpp
77
race:modules/navigation/nav_map_3d.cpp
8+
race:thirdparty/thorvg/src/loaders/external_jpg/tvgJpgLoader.cpp

misc/error_suppressions/ubsan.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ float-divide-by-zero:thirdparty/thorvg/src/renderer/sw_engine/tvgSwFill.cpp
66
function:thirdparty/embree/common/sys/thread.cpp
77
function:thirdparty/embree/kernels/common/accel.h
88
function:thirdparty/xatlas/xatlas.cpp
9+
implicit-integer-sign-change:thirdparty/basis_universal/encoder/jpgd.cpp
910
implicit-integer-sign-change:thirdparty/basis_universal/transcoder/basisu_astc_helpers.h
1011
implicit-integer-sign-change:thirdparty/embree/common/lexers/../sys/ref.h
1112
implicit-integer-sign-change:thirdparty/embree/common/lexers/tokenstream.cpp
@@ -38,7 +39,6 @@ implicit-integer-sign-change:thirdparty/icu4c/common/unicode/unistr.h
3839
implicit-integer-sign-change:thirdparty/icu4c/common/unistr.cpp
3940
implicit-integer-sign-change:thirdparty/icu4c/common/uresbund.cpp
4041
implicit-integer-sign-change:thirdparty/icu4c/common/ustrtrns.cpp
41-
implicit-integer-sign-change:thirdparty/jpeg-compressor/jpgd.cpp
4242
implicit-integer-sign-change:thirdparty/libogg/bitwise.c
4343
implicit-integer-sign-change:thirdparty/libvorbis/info.c
4444
implicit-integer-sign-change:thirdparty/libvorbis/sharedbook.c

modules/basis_universal/SCsub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ if basisu_encoder:
3636
"basisu_resample_filters.cpp",
3737
"basisu_ssim.cpp",
3838
"basisu_uastc_enc.cpp",
39+
"jpgd.cpp",
3940
"pvpngreader.cpp",
4041
]
4142
encoder_sources = [thirdparty_dir + "encoder/" + file for file in encoder_sources]
@@ -49,7 +50,6 @@ else:
4950
env_basisu.Prepend(CPPPATH=[thirdparty_dir])
5051

5152
if basisu_encoder:
52-
env_basisu.Prepend(CPPPATH=["#thirdparty/jpeg-compressor"])
5353
env_basisu.Prepend(CPPPATH=["#thirdparty/tinyexr"])
5454

5555
if env["builtin_zstd"]:

modules/basis_universal/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
def can_build(env, platform):
22
if env.editor_build: # Encoder dependencies
3-
env.module_add_dependencies("basis_universal", ["jpg", "tinyexr"])
3+
env.module_add_dependencies("basis_universal", ["tinyexr"])
44
return True
55

66

modules/jpg/SCsub

Lines changed: 106 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,125 @@ from misc.utility.scons_hints import *
44
Import("env")
55
Import("env_modules")
66

7-
env_jpg = env_modules.Clone()
8-
9-
# Thirdparty source files
7+
env_jpeg_turbo = env_modules.Clone()
108

119
thirdparty_obj = []
1210

13-
# Not unbundled for now as they are not commonly available as shared library
14-
thirdparty_dir = "#thirdparty/jpeg-compressor/"
15-
thirdparty_sources = [
16-
"jpgd.cpp",
17-
"jpge.cpp",
11+
thirdparty_dir = "#thirdparty/libjpeg-turbo"
12+
13+
thirdparty_sources_common = [
14+
"jaricom.c",
15+
"jcapimin.c",
16+
"jcarith.c",
17+
"jchuff.c",
18+
"jcicc.c",
19+
"jcinit.c",
20+
"jcmarker.c",
21+
"jcmaster.c",
22+
"jcomapi.c",
23+
"jcparam.c",
24+
"jcphuff.c",
25+
"jctrans.c",
26+
"jdapimin.c",
27+
"jdarith.c",
28+
"jdatadst.c",
29+
"jdatadst-tj.c",
30+
"jdatasrc.c",
31+
"jdatasrc-tj.c",
32+
"jdhuff.c",
33+
"jdicc.c",
34+
"jdinput.c",
35+
"jdmarker.c",
36+
"jdmaster.c",
37+
"jdphuff.c",
38+
"jdtrans.c",
39+
"jerror.c",
40+
"jfdctflt.c",
41+
"jmemmgr.c",
42+
"jmemnobs.c",
43+
"jpeg_nbits.c",
44+
"transupp.c",
45+
"turbojpeg.c",
46+
]
47+
48+
thirdparty_sources_bit_dependent = [
49+
"jcapistd.c",
50+
"jccoefct.c",
51+
"jccolor.c",
52+
"jcdctmgr.c",
53+
"jcmainct.c",
54+
"jcprepct.c",
55+
"jcsample.c",
56+
"jdcoefct.c",
57+
"jdcolor.c",
58+
"jdapistd.c",
59+
"jddctmgr.c",
60+
"jdmainct.c",
61+
"jdmerge.c",
62+
"jdpostct.c",
63+
"jdsample.c",
64+
"jfdctfst.c",
65+
"jfdctint.c",
66+
"jidctflt.c",
67+
"jidctfst.c",
68+
"jidctint.c",
69+
"jidctred.c",
70+
"jutils.c",
71+
"jquant1.c",
72+
"jquant2.c",
1873
]
19-
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
2074

21-
env_jpg.Prepend(CPPPATH=[thirdparty_dir])
75+
absent_in_16 = frozenset(
76+
[
77+
"jcdctmgr.c",
78+
"jccoefct.c",
79+
"jdcoefct.c",
80+
"jddctmgr.c",
81+
"jfdctfst.c",
82+
"jfdctint.c",
83+
"jidctflt.c",
84+
"jidctfst.c",
85+
"jidctint.c",
86+
"jidctred.c",
87+
]
88+
)
89+
90+
thirdparty_sources_by_bits = {
91+
8: list(thirdparty_sources_bit_dependent),
92+
12: list(thirdparty_sources_bit_dependent),
93+
16: [x for x in thirdparty_sources_bit_dependent if x not in absent_in_16],
94+
}
95+
96+
97+
def source_paths(files):
98+
return [thirdparty_dir + "/src/" + f for f in files]
99+
100+
101+
env_jpeg_turbo.Prepend(CPPPATH=[thirdparty_dir + "/src"])
102+
103+
104+
def add_bit_depth(bit_depth: int):
105+
env_bit_depth = env_jpeg_turbo.Clone()
106+
env_bit_depth.disable_warnings()
107+
env_bit_depth["OBJSUFFIX"] = f"_{bit_depth}{env_bit_depth['OBJSUFFIX']}"
108+
env_bit_depth.AppendUnique(CPPDEFINES=[f"BITS_IN_JSAMPLE={bit_depth}"]) # to unique or not?
109+
env_bit_depth.add_source_files(thirdparty_obj, source_paths(thirdparty_sources_by_bits[bit_depth]))
110+
111+
112+
add_bit_depth(8)
113+
add_bit_depth(12)
114+
# add_bit_depth(16)
22115

23-
env_thirdparty = env_jpg.Clone()
116+
env_thirdparty = env_jpeg_turbo.Clone()
24117
env_thirdparty.disable_warnings()
25-
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
118+
env_thirdparty.add_source_files(thirdparty_obj, source_paths(thirdparty_sources_common))
26119
env.modules_sources += thirdparty_obj
27120

28121
# Godot source files
29122

30123
module_obj = []
31124

32-
env_jpg.add_source_files(module_obj, "*.cpp")
125+
env_jpeg_turbo.add_source_files(module_obj, "*.cpp")
33126
env.modules_sources += module_obj
34127

35128
# Needed to force rebuilding the module files when the thirdparty library is updated.

0 commit comments

Comments
 (0)