Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libjpeg turbo #4979

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Modules/ThirdParty/JPEG/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set(ITKJPEG_THIRD_PARTY 1)
option(ITK_USE_SYSTEM_JPEG "Use an outside build of JPEG." ${ITK_USE_SYSTEM_LIBRARIES})
mark_as_advanced(ITK_USE_SYSTEM_JPEG)

option(ITK_USE_JPEG_TURBO "Use libjpeg-turbo build of JPEG" ON)

if(ITK_USE_SYSTEM_JPEG)
find_package(JPEG REQUIRED)
set(ITKJPEG_INCLUDE_DIRS
Expand Down
32 changes: 32 additions & 0 deletions Modules/ThirdParty/JPEG/UpdateFromUpstream.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -e
set -x
shopt -s dotglob

readonly name="jpeg-turbo"
readonly ownership="libjpeg-turbo Upstream <[email protected]>"
readonly subtree="Modules/ThirdParty/JPEG/src/itk$name"
readonly repo="https://github.com/libjpeg-turbo/libjpeg-turbo.git"
readonly tag="3.0.4"
readonly paths="
j*.c
j*.h
jconfig.h.in
jconfigint.h.in
jversion.h.in

LICENSE.md
README.ijg
README.md
"

extract_source () {
git_archive
pushd "${extractdir}/${name}-reduced"
echo "* -whitespace" >> .gitattributes
echo "README.md conflict-marker-size=8" >> .gitattributes
popd
}

. "${BASH_SOURCE%/*}/../../../Utilities/Maintenance/update-third-party.bash"
2 changes: 1 addition & 1 deletion Modules/ThirdParty/JPEG/itk-module.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(DOCUMENTATION "This module contains the third party JPEG
library published by the
<a href=\"http://www.ijg.org/\">Independent JPEG Group</a>.")
<a href=\"http://www.ijg.org/\">Independent JPEG Group</a> and libjpeg-turbo.")

itk_module(ITKJPEG
DESCRIPTION
Expand Down
6 changes: 5 additions & 1 deletion Modules/ThirdParty/JPEG/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ set(ITK3P_INSTALL_INCLUDE_DIR "${ITKJPEG_INSTALL_INCLUDE_DIR}")
set(ITK3P_INSTALL_RUNTIME_DIR "${ITKJPEG_INSTALL_RUNTIME_DIR}")
set(ITK3P_INSTALL_LIBRARY_DIR "${ITKJPEG_INSTALL_LIBRARY_DIR}")
set(ITK3P_INSTALL_ARCHIVE_DIR "${ITKJPEG_INSTALL_ARCHIVE_DIR}")
add_subdirectory(itkjpeg)
if (ITK_USE_JPEG_TURBO)
add_subdirectory(itkjpeg-turbo)
else()
add_subdirectory(itkjpeg)
endif()
itk_module_target(itkjpeg NO_INSTALL)
4 changes: 4 additions & 0 deletions Modules/ThirdParty/JPEG/src/itk_jpeg.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@

/* Use the jpeg library configured for ITK. */
#cmakedefine ITK_USE_SYSTEM_JPEG
#cmakedefine ITK_USE_JPEG_TURBO
#ifdef ITK_USE_SYSTEM_JPEG
# include <jpeglib.h>
# include <jerror.h>
#elif defined(ITK_USE_JPEG_TURBO)
# include <itkjpeg-turbo/jpeglib.h>
# include <itkjpeg-turbo/jerror.h>
#else
# include <itkjpeg/jpeglib.h>
# include <itkjpeg/jerror.h>
Expand Down
2 changes: 2 additions & 0 deletions Modules/ThirdParty/JPEG/src/itkjpeg-turbo/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* -whitespace
README.md conflict-marker-size=8
139 changes: 139 additions & 0 deletions Modules/ThirdParty/JPEG/src/itkjpeg-turbo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
set(JPEG16_SOURCES jcapistd.c jccolor.c jcdiffct.c jclossls.c jcmainct.c
jcprepct.c jcsample.c jdapistd.c jdcolor.c jddiffct.c jdlossls.c jdmainct.c
jdpostct.c jdsample.c jutils.c)
set(JPEG12_SOURCES ${JPEG16_SOURCES} jccoefct.c jcdctmgr.c jdcoefct.c
jddctmgr.c jdmerge.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c
jidctred.c jquant1.c jquant2.c)
set(JPEG_SOURCES ${JPEG12_SOURCES} jcapimin.c jchuff.c jcicc.c jcinit.c
jclhuff.c jcmarker.c jcmaster.c jcomapi.c jcparam.c jcphuff.c jctrans.c
jdapimin.c jdatadst.c jdatasrc.c jdhuff.c jdicc.c jdinput.c jdlhuff.c
jdmarker.c jdmaster.c jdphuff.c jdtrans.c jerror.c jfdctflt.c jmemmgr.c
jmemnobs.c jpeg_nbits.c)

set(JPEG_SOURCES ${JPEG_SOURCES} jaricom.c jcarith.c jdarith.c)


include(CheckSymbolExists)
check_symbol_exists("memset" "string.h" HAVE_MEMSET)
check_symbol_exists("memcpy" "string.h" HAVE_MEMCPY)
if (NOT HAVE_MEMSET OR NOT HAVE_MEMCPY)
set(NEED_BSD_STRINGS 1)
endif ()

include(CheckIncludeFile)
if(MSVC)
check_include_file("intrin.h" HAVE_INTRIN_H)
endif()

set(BITS_IN_JSAMPLE 8)

set(JPEG_LIB_VERSION 80)
set(LIBJPEG_TURBO_VERSION "3.0.4")
set(LIBJPEG_TURBO_VERSION_NUMBER "003000004")
set(MEM_SRCDST_SUPPORTED 1)
set(C_ARITH_CODING_SUPPORTED 1)
set(D_ARITH_CODING_SUPPORTED 1)
set(NEED_SYS_TYPES_H 1)
#set(WITH_SIMD 1)

set(THREAD_LOCAL "thread_local")


if(UNIX)
if(CMAKE_CROSSCOMPILING)
set(RIGHT_SHIFT_IS_UNSIGNED 0)
else()
include(CheckCSourceRuns)
check_c_source_runs("
#include <stdio.h>
#include <stdlib.h>
static int is_shifting_signed (long arg) {
long res = arg >> 4;
if (res == -0x7F7E80CL)
return 1; /* right shift is signed */
/* see if unsigned-shift hack will fix it. */
/* we can't just test exact value since it depends on width of long... */
res |= 0xFFFFFFFFL << (32-4);
if (res == -0x7F7E80CL)
return 0; /* right shift is unsigned */
printf(\"Right shift isn't acting as I expect it to.\\\\n\");
printf(\"I fear the JPEG software will not work at all.\\\\n\\\\n\");
return 0; /* try it with unsigned anyway */
}
int main (void) {
exit(is_shifting_signed(-0x7F7E80B1L));
}" RIGHT_SHIFT_IS_UNSIGNED)
endif()
endif()


if (BUILD_SHARED_LIBS)
set(JPEG_SHARED_LIBS 1)
else ()
set(JPEG_SHARED_LIBS 0)
endif ()

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}${header_input_dir}/jconfig.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/jconfig.h")

set(headers
jerror.h
jmorecfg.h
jpeglib.h
"${CMAKE_CURRENT_BINARY_DIR}/jconfig.h")

include(CheckTypeSize)
check_type_size("size_t" SIZE_T)

if(SIZE_T EQUAL UNSIGNED_LONG)
check_c_source_compiles("int main(int argc, char **argv) { unsigned long a = argc; return __builtin_ctzl(a); }"
HAVE_BUILTIN_CTZL)
endif()

set(SIZEOF_SIZE_T "${SIZE_T}")
set(VERSION "${LIBJPEG_TURBO_VERSION}")
set(PACKAGE_NAME "itkjpeg")
string(TIMESTAMP BUILD "%Y%m%d")

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/jconfigint.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/jconfigint.h")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/jversion.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/jversion.h")


# Compile a separate version of these source files with 12-bit and 16-bit
# data precision.
add_library(itkjpeg12 OBJECT ${JPEG12_SOURCES})
set_property(TARGET itkjpeg12 PROPERTY COMPILE_FLAGS "-DBITS_IN_JSAMPLE=12")
target_include_directories(itkjpeg12
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
add_library(itkjpeg16 OBJECT ${JPEG16_SOURCES})
set_property(TARGET itkjpeg16 PROPERTY COMPILE_FLAGS "-DBITS_IN_JSAMPLE=16")
target_include_directories(itkjpeg16
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")


add_library(itkjpeg ${JPEG_SOURCES})
target_link_libraries(itkjpeg itkjpeg12 itkjpeg16)
target_include_directories(itkjpeg
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")

# Apply user-defined properties to the library target.
if(ITK_LIBRARY_PROPERTIES)
set_target_properties(itkjpeg PROPERTIES ${ITK_LIBRARY_PROPERTIES})
#set_target_properties(itkjpeg12 PROPERTIES ${ITK_LIBRARY_PROPERTIES})
#set_target_properties(itkjpeg16 PROPERTIES ${ITK_LIBRARY_PROPERTIES})
endif(ITK_LIBRARY_PROPERTIES)

install(TARGETS itkjpeg itkjpeg12 itkjpeg16
EXPORT ${ITK3P_INSTALL_EXPORT_NAME}
RUNTIME DESTINATION ${ITK3P_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${ITK3P_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${ITK3P_INSTALL_ARCHIVE_DIR} COMPONENT Development
)
135 changes: 135 additions & 0 deletions Modules/ThirdParty/JPEG/src/itkjpeg-turbo/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
libjpeg-turbo Licenses
======================

libjpeg-turbo is covered by two compatible BSD-style open source licenses:

- The IJG (Independent JPEG Group) License, which is listed in
[README.ijg](README.ijg)

This license applies to the libjpeg API library and associated programs,
including any code inherited from libjpeg and any modifications to that
code. Note that the libjpeg-turbo SIMD source code bears the
[zlib License](https://opensource.org/licenses/Zlib), but in the context of
the overall libjpeg API library, the terms of the zlib License are subsumed
by the terms of the IJG License.

- The Modified (3-clause) BSD License, which is listed below

This license applies to the TurboJPEG API library and associated programs, as
well as the build system. Note that the TurboJPEG API library wraps the
libjpeg API library, so in the context of the overall TurboJPEG API library,
both the terms of the IJG License and the terms of the Modified (3-clause)
BSD License apply.


Complying with the libjpeg-turbo Licenses
=========================================

This section provides a roll-up of the libjpeg-turbo licensing terms, to the
best of our understanding. This is not a license in and of itself. It is
intended solely for clarification.

1. If you are distributing a modified version of the libjpeg-turbo source,
then:

1. You cannot alter or remove any existing copyright or license notices
from the source.

**Origin**
- Clause 1 of the IJG License
- Clause 1 of the Modified BSD License
- Clauses 1 and 3 of the zlib License

2. You must add your own copyright notice to the header of each source
file you modified, so others can tell that you modified that file. (If
there is not an existing copyright header in that file, then you can
simply add a notice stating that you modified the file.)

**Origin**
- Clause 1 of the IJG License
- Clause 2 of the zlib License

3. You must include the IJG README file, and you must not alter any of the
copyright or license text in that file.

**Origin**
- Clause 1 of the IJG License

2. If you are distributing only libjpeg-turbo binaries without the source, or
if you are distributing an application that statically links with
libjpeg-turbo, then:

1. Your product documentation must include a message stating:

This software is based in part on the work of the Independent JPEG
Group.

**Origin**
- Clause 2 of the IJG license

2. If your binary distribution includes or uses the TurboJPEG API, then
your product documentation must include the text of the Modified BSD
License (see below.)

**Origin**
- Clause 2 of the Modified BSD License

3. You cannot use the name of the IJG or The libjpeg-turbo Project or the
contributors thereof in advertising, publicity, etc.

**Origin**
- IJG License
- Clause 3 of the Modified BSD License

4. The IJG and The libjpeg-turbo Project do not warrant libjpeg-turbo to be
free of defects, nor do we accept any liability for undesirable
consequences resulting from your use of the software.

**Origin**
- IJG License
- Modified BSD License
- zlib License


The Modified (3-clause) BSD License
===================================

Copyright (C)2009-2023 D. R. Commander. All Rights Reserved.<br>
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:

- 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.


Why Two Licenses?
=================

The zlib License could have been used instead of the Modified (3-clause) BSD
License, and since the IJG License effectively subsumes the distribution
conditions of the zlib License, this would have effectively placed
libjpeg-turbo binary distributions under the IJG License. However, the IJG
License specifically refers to the Independent JPEG Group and does not extend
attribution and endorsement protections to other entities. Thus, it was
desirable to choose a license that granted us the same protections for new code
that were granted to the IJG for code derived from their software.
Loading