Skip to content

Commit 8a1f5d7

Browse files
committed
use libjpeg_turbo for improved jpg compatibility and speed
1 parent 730adf4 commit 8a1f5d7

File tree

131 files changed

+50952
-5277
lines changed

Some content is hidden

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

131 files changed

+50952
-5277
lines changed

COPYRIGHT.txt

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,18 @@ Comment: Jolt Physics
324324
Copyright: 2021, Jorrit Rouwe
325325
License: Expat
326326

327-
Files: thirdparty/jpeg-compressor/*
328-
Comment: jpeg-compressor
329-
Copyright: 2012, Rich Geldreich
330-
License: public-domain or Apache-2.0
331-
332327
Files: thirdparty/libbacktrace/*
333328
Comment: libbacktrace
334329
Copyright: 2012-2021, Free Software Foundation, Inc.
335330
License: BSD-3-clause
336331

332+
Files: thirdparty/libjpeg-turbo/*
333+
Comment: libjpeg-turbo
334+
Copyright: Copyright (C)2009-2024 D. R. Commander
335+
Copyright (C)2015 Viktor Szathmáry.
336+
1991-2020, Thomas G. Lane, Guido Vollbeding
337+
License: TurboJPEG modified BSD-3-clause, IJG License
338+
337339
Files: thirdparty/libktx/*
338340
Comment: KTX
339341
Copyright: 2013-2020, Mark Callow
@@ -1683,6 +1685,42 @@ License: HarfBuzz
16831685
ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
16841686
PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
16851687

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

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

SConstruct

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ opts.Add(BoolVariable("builtin_glslang", "Use the built-in glslang library", Tru
276276
opts.Add(BoolVariable("builtin_graphite", "Use the built-in Graphite library", True))
277277
opts.Add(BoolVariable("builtin_harfbuzz", "Use the built-in HarfBuzz library", True))
278278
opts.Add(BoolVariable("builtin_icu4c", "Use the built-in ICU library", True))
279+
opts.Add(BoolVariable("builtin_libjpeg_turbo", "Use the built-in libjpeg-turbo library", True))
279280
opts.Add(BoolVariable("builtin_libogg", "Use the built-in libogg library", True))
280281
opts.Add(BoolVariable("builtin_libpng", "Use the built-in libpng library", True))
281282
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
@@ -6,3 +6,4 @@ deadlock:modules/text_server_adv/text_server_adv.cpp
66
deadlock:modules/text_server_fb/text_server_fb.cpp
77
race:modules/navigation_2d/nav_map_2d.cpp
88
race:modules/navigation_3d/nav_map_3d.cpp
9+
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
@@ -38,6 +38,7 @@ if basisu_encoder:
3838
"basisu_ssim.cpp",
3939
"basisu_uastc_enc.cpp",
4040
"basisu_uastc_hdr_4x4_enc.cpp",
41+
"jpgd.cpp",
4142
"pvpngreader.cpp",
4243
]
4344
encoder_sources = [thirdparty_dir + "encoder/" + file for file in encoder_sources]
@@ -47,7 +48,6 @@ transcoder_sources = [thirdparty_dir + "transcoder/basisu_transcoder.cpp"]
4748
env_basisu.Prepend(CPPEXTPATH=[thirdparty_dir])
4849

4950
if basisu_encoder:
50-
env_basisu.Prepend(CPPEXTPATH=["#thirdparty/jpeg-compressor"])
5151
env_basisu.Prepend(CPPEXTPATH=["#thirdparty/tinyexr"])
5252

5353
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(CPPEXTPATH=[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(CPPEXTPATH=[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)