Skip to content

Commit

Permalink
Replace jpeglib with libjpeg-turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Apr 23, 2024
1 parent 9f437a5 commit 422d74a
Show file tree
Hide file tree
Showing 94 changed files with 120 additions and 36,680 deletions.
19 changes: 7 additions & 12 deletions CMakeLists.txt
Expand Up @@ -40,7 +40,6 @@ enable_testing()
option(USE_SHARED_CMARK "Use your installed copy of cmark" off)
option(USE_SHARED_CURL "Use your installed copy of curl" off)
option(USE_SHARED_GIFLIB "Use your installed copy of giflib" off)
option(USE_SHARED_JPEGLIB "Use your installed copy of jpeglib" off)
option(USE_SHARED_ZLIB "Use your installed copy of zlib" off)
option(USE_SHARED_LIBPNG "Use your installed copy of libpng" off)
option(USE_SHARED_TINYXML "Use your installed copy of tinyxml" off)
Expand Down Expand Up @@ -156,7 +155,6 @@ set(SOURCE_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data)
set(CMARK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/cmark)
set(CURL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/curl)
set(GIFLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/giflib)
set(LIBJPEG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/jpeg)
set(LIBPNG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/libpng)
set(LIBWEBP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/libwebp)
set(PIXMAN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/pixman)
Expand Down Expand Up @@ -277,17 +275,10 @@ else()
endif()
include_directories(${GIF_INCLUDE_DIRS})

if(USE_SHARED_JPEGLIB)
find_package(JPEG REQUIRED)
else()
set(JPEG_FOUND ON)
set(JPEG_INCLUDE_DIR ${LIBJPEG_DIR})
set(JPEG_LIBRARY jpeg CACHE FILEPATH "")
set(JPEG_LIBRARIES ${JPEG_LIBRARY})
set(JPEG_INCLUDE_DIRS ${JPEG_INCLUDE_DIR})
endif()
include_directories(${JPEG_INCLUDE_DIRS})
# libjpeg-turbo
find_package(JpegTurbo)

# cmark
if(USE_SHARED_CMARK)
find_library(CMARK_LIBRARIES NAMES cmark)
find_path(CMARK_INCLUDE_DIRS NAMES cmark.h)
Expand Down Expand Up @@ -340,7 +331,11 @@ if(ENABLE_WEBP)
endif()
include_directories(${WEBP_INCLUDE_DIR})
endif()

# Print paths to used libraries
message(STATUS "aseprite giflib: ${GIF_LIBRARY}")
message(STATUS "aseprite libwebp: ${WEBP_LIBRARIES}")
message(STATUS "aseprite libjpeg-turbo: ${LIBJPEG_TURBO_LIBRARY}")

# LAF libraries + Aseprite are compiled with config.h
target_include_directories(laf-base PUBLIC src)
Expand Down
61 changes: 61 additions & 0 deletions cmake/FindJpegTurbo.cmake
@@ -0,0 +1,61 @@
# Get libjpeg-turbo package
# Copyright (c) 2024 Igara Studio S.A.
#
# This file is released under the terms of the MIT license.
# Read LICENSE.txt for more information.
#
# Makes the libjpeg-turbo target available.
#

if(LAF_BACKEND STREQUAL "skia")

find_library(LIBJPEG_TURBO_LIBRARY NAMES libjpeg jpeg
HINTS "${SKIA_LIBRARY_DIR}" NO_DEFAULT_PATH)
set(LIBJPEG_TURBO_INCLUDE_DIRS "${SKIA_DIR}/third_party/externals/libjpeg-turbo")

add_library(libjpeg-turbo STATIC IMPORTED)
set_target_properties(libjpeg-turbo PROPERTIES
IMPORTED_LOCATION "${LIBJPEG_TURBO_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES ${LIBJPEG_TURBO_INCLUDE_DIRS})

else()

if(WIN32)
set(LIBJPEG_TURBO_STATIC_SUFFIX "-static")
else()
set(LIBJPEG_TURBO_STATIC_SUFFIX "")
endif()

include(ExternalProject)
ExternalProject_Add(libjpeg-turbo-project
URL https://github.com/libjpeg-turbo/libjpeg-turbo/archive/refs/tags/3.0.2.zip
URL_HASH SHA512=c048c041f0bf205a8a3c8b8928d7a44299466253789f533db91f6ae4209a9074d5baef2fbb8e0a4215b4e3d2ba30c784f51b6c79ce0d2b1ea75440b8ffb23859
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libjpeg-turbo"
INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/libjpeg-turbo"
BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/libjpeg-turbo/lib/${CMAKE_STATIC_LIBRARY_PREFIX}jpeg${LIBJPEG_TURBO_STATIC_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}"
CMAKE_CACHE_ARGS
-DENABLE_SHARED:BOOL=OFF
-DENABLE_STATIC:BOOL=ON
-DWITH_ARITH_DEC:BOOL=ON
-DWITH_ARITH_ENC:BOOL=ON
-DWITH_JPEG8:BOOL=OFF
-DWITH_JPEG7:BOOL=OFF
-DWITH_TURBOJPEG:BOOL=OFF
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_INSTALL_LIBDIR:PATH=<INSTALL_DIR>/lib)

ExternalProject_Get_Property(libjpeg-turbo-project install_dir)
set(LIBJPEG_TURBO_INCLUDE_DIRS "${install_dir}/include")
set(LIBJPEG_TURBO_LIBRARY "${install_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}jpeg${LIBJPEG_TURBO_STATIC_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}")

# Create the directory so changing INTERFACE_INCLUDE_DIRECTORIES doesn't fail
file(MAKE_DIRECTORY ${LIBJPEG_TURBO_INCLUDE_DIRS})

add_library(libjpeg-turbo STATIC IMPORTED)
set_target_properties(libjpeg-turbo PROPERTIES
IMPORTED_LOCATION ${LIBJPEG_TURBO_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${LIBJPEG_TURBO_INCLUDE_DIRS})
add_dependencies(libjpeg-turbo libjpeg-turbo-project)

endif()
88 changes: 51 additions & 37 deletions docs/LICENSES.md
Expand Up @@ -695,15 +695,36 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

# [libjpeg](http://www.ijg.org/)
# [libjpeg-turbo](https://libjpeg-turbo.org/)

```
libjpeg-turbo is covered by three compatible BSD-style open source licenses:
- The IJG (Independent JPEG Group) License, which is listed in
[README.ijg](https://raw.githubusercontent.com/libjpeg-turbo/libjpeg-turbo/main/README.ijg)
This license applies to the libjpeg API library and associated programs
(any code inherited from libjpeg, and any modifications to that code.)
- The Modified (3-clause) BSD License, which is listed below
This license covers the TurboJPEG API library and associated programs, as
well as the build system.
- The [zlib License](https://opensource.org/licenses/Zlib)
This license is a subset of the other two, and it covers the libjpeg-turbo
SIMD extensions.
The Independent JPEG Group's JPEG software
==========================================
The authors make NO WARRANTY or representation, either express or implied,
with respect to this software, its quality, accuracy, merchantability, or
fitness for a particular purpose. This software is provided "AS IS", and you,
its user, assume the entire risk as to its quality and accuracy.
This software is copyright (C) 1991-1998, Thomas G. Lane.
This software is copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding.
All Rights Reserved except as specified below.
Permission is hereby granted to use, copy, modify, and distribute this
Expand Down Expand Up @@ -733,42 +754,35 @@ We specifically permit and encourage the use of this software as the basis of
commercial products, provided that all warranty or liability claims are
assumed by the product vendor.
The Modified (3-clause) BSD License
===================================
Copyright (C)2009-2022 D. R. Commander. All Rights Reserved.
Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
ansi2knr.c is included in this distribution by permission of L. Peter Deutsch,
sole proprietor of its copyright holder, Aladdin Enterprises of Menlo Park, CA.
ansi2knr.c is NOT covered by the above copyright and conditions, but instead
by the usual distribution terms of the Free Software Foundation; principally,
that you must include source code if you redistribute it. (See the file
ansi2knr.c for full details.) However, since ansi2knr.c is not needed as part
of any program generated from the IJG code, this does not limit you more than
the foregoing paragraphs do.
The Unix configuration script "configure" was produced with GNU Autoconf.
It is copyright by the Free Software Foundation but is freely distributable.
The same holds for its supporting scripts (config.guess, config.sub,
ltconfig, ltmain.sh). Another support script, install-sh, is copyright
by M.I.T. but is also freely distributable.
It appears that the arithmetic coding option of the JPEG spec is covered by
patents owned by IBM, AT&T, and Mitsubishi. Hence arithmetic coding cannot
legally be used without obtaining one or more licenses. For this reason,
support for arithmetic coding has been removed from the free JPEG software.
(Since arithmetic coding provides only a marginal gain over the unpatented
Huffman mode, it is unlikely that very many implementations will support it.)
So far as we are aware, there are no patent restrictions on the remaining
code.
The IJG distribution formerly included code to read and write GIF files.
To avoid entanglement with the Unisys LZW patent, GIF reading support has
been removed altogether, and the GIF writer has been simplified to produce
"uncompressed GIFs". This technique does not use the LZW algorithm; the
resulting GIF files are larger than usual, but are readable by all standard
GIF decoders.
We are required to state that
"The Graphics Interchange Format(c) is the Copyright property of
CompuServe Incorporated. GIF(sm) is a Service Mark property of
CompuServe Incorporated."
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of the libjpeg-turbo Project nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
```

# [libpng](http://www.libpng.org/pub/png/)
Expand Down
2 changes: 1 addition & 1 deletion src/app/CMakeLists.txt
Expand Up @@ -720,13 +720,13 @@ target_link_libraries(app-lib
undo
${CMARK_LIBRARIES}
${TINYXML_LIBRARY}
${JPEG_LIBRARIES}
${GIF_LIBRARIES}
${PNG_LIBRARIES}
${WEBP_LIBRARIES}
${ZLIB_LIBRARIES}
${FREETYPE_LIBRARIES}
${HARFBUZZ_LIBRARIES}
libjpeg-turbo
json11
archive_static
fmt
Expand Down
4 changes: 0 additions & 4 deletions third_party/CMakeLists.txt
Expand Up @@ -8,10 +8,6 @@ if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif(MSVC)

if(NOT USE_SHARED_JPEGLIB)
add_subdirectory(jpeg)
endif()

if(NOT USE_SHARED_ZLIB)
set(SKIP_INSTALL_ALL on)
# Don't build zlib tests
Expand Down
50 changes: 0 additions & 50 deletions third_party/jpeg/CMakeLists.txt

This file was deleted.

0 comments on commit 422d74a

Please sign in to comment.