| 1 |
# Checks for JPEG codec support |
| 2 |
# |
| 3 |
# Copyright © 2015 Open Microscopy Environment / University of Dundee |
| 4 |
# Copyright © 2021 Roger Leigh <[email protected]> |
| 5 |
# Written by Roger Leigh <[email protected]> |
| 6 |
# |
| 7 |
# Permission to use, copy, modify, distribute, and sell this software and |
| 8 |
# its documentation for any purpose is hereby granted without fee, provided |
| 9 |
# that (i) the above copyright notices and this permission notice appear in |
| 10 |
# all copies of the software and related documentation, and (ii) the names of |
| 11 |
# Sam Leffler and Silicon Graphics may not be used in any advertising or |
| 12 |
# publicity relating to the software without the specific, prior written |
| 13 |
# permission of Sam Leffler and Silicon Graphics. |
| 14 |
# |
| 15 |
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, |
| 16 |
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY |
| 17 |
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. |
| 18 |
# |
| 19 |
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR |
| 20 |
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, |
| 21 |
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
| 22 |
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF |
| 23 |
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 24 |
# OF THIS SOFTWARE. |
| 25 |
|
| 26 |
|
| 27 |
# JPEG |
| 28 |
set(JPEG_SUPPORT FALSE) |
| 29 |
find_package(JPEG) |
| 30 |
option(jpeg "use libjpeg (required for JPEG compression)" ${JPEG_FOUND}) |
| 31 |
if (jpeg AND JPEG_FOUND) |
| 32 |
set(JPEG_SUPPORT TRUE) |
| 33 |
endif() |
| 34 |
|
| 35 |
# Old-jpeg |
| 36 |
set(OJPEG_SUPPORT FALSE) |
| 37 |
option(old-jpeg "support for Old JPEG compression (read-only)" ${JPEG_SUPPORT}) |
| 38 |
if (old-jpeg AND JPEG_SUPPORT) |
| 39 |
set(OJPEG_SUPPORT TRUE) |
| 40 |
endif() |
| 41 |
|
| 42 |
if (JPEG_SUPPORT) |
| 43 |
# Check for jpeg12_read_scanlines() which has been added in libjpeg-turbo 2.2 |
| 44 |
# for dual 8/12 bit mode. |
| 45 |
include(CheckCSourceCompiles) |
| 46 |
include(CMakePushCheckState) |
| 47 |
cmake_push_check_state(RESET) |
| 48 |
set(CMAKE_REQUIRED_INCLUDES "${JPEG_INCLUDE_DIRS}") |
| 49 |
set(CMAKE_REQUIRED_LIBRARIES "${JPEG_LIBRARIES}") |
| 50 |
check_c_source_compiles( |
| 51 |
" |
| 52 |
#include <stddef.h> |
| 53 |
#include <stdio.h> |
| 54 |
#include \"jpeglib.h\" |
| 55 |
int main() |
| 56 |
{ |
| 57 |
jpeg_read_scanlines(0,0,0); |
| 58 |
jpeg12_read_scanlines(0,0,0); |
| 59 |
return 0; |
| 60 |
} |
| 61 |
" |
| 62 |
HAVE_JPEGTURBO_DUAL_MODE_8_12) |
| 63 |
cmake_pop_check_state() |
| 64 |
endif() |
| 65 |
|
| 66 |
if (NOT HAVE_JPEGTURBO_DUAL_MODE_8_12) |
| 67 |
|
| 68 |
# 12-bit jpeg mode in a dedicated libjpeg12 library |
| 69 |
set(JPEG12_INCLUDE_DIR JPEG12_INCLUDE_DIR-NOTFOUND CACHE PATH "Include directory for 12-bit libjpeg") |
| 70 |
set(JPEG12_LIBRARY JPEG12_LIBRARY-NOTFOUND CACHE FILEPATH "12-bit libjpeg library") |
| 71 |
set(JPEG_DUAL_MODE_8_12 FALSE) |
| 72 |
if (JPEG12_INCLUDE_DIR AND JPEG12_LIBRARY) |
| 73 |
set(JPEG12_LIBRARIES ${JPEG12_LIBRARY}) |
| 74 |
set(JPEG12_FOUND TRUE) |
| 75 |
else() |
| 76 |
set(JPEG12_FOUND FALSE) |
| 77 |
endif() |
| 78 |
option(jpeg12 "enable libjpeg 8/12-bit dual mode (requires separate 12-bit libjpeg build)" ${JPEG12_FOUND}) |
| 79 |
if (jpeg12 AND JPEG12_FOUND) |
| 80 |
set(JPEG_DUAL_MODE_8_12 TRUE) |
| 81 |
set(LIBJPEG_12_PATH "${JPEG12_INCLUDE_DIR}/jpeglib.h") |
| 82 |
endif() |
| 83 |
|
| 84 |
endif() |