Skip to content

Commit

Permalink
JPGrok: new Grok JPEG 2000 driver based on Grok JPEG 2000 Library
Browse files Browse the repository at this point in the history
  • Loading branch information
boxerab committed Jul 29, 2023
1 parent 9a9ba5e commit 2c17d88
Show file tree
Hide file tree
Showing 12 changed files with 4,718 additions and 0 deletions.
3,013 changes: 3,013 additions & 0 deletions autotest/gdrivers/jp2grok.py

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions cmake/helpers/CheckDependentLibraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,19 @@ gdal_check_package(MONGOCXX "Enable MongoDBV3 driver" CAN_DISABLE)
define_find_package2(HEIF libheif/heif.h heif PKGCONFIG_NAME libheif)
gdal_check_package(HEIF "HEIF >= 1.1" CAN_DISABLE)

find_package(Grok MODULE)
if (GDAL_USE_GROK)
if (NOT GROK_FOUND)
message(FATAL_ERROR "Configured to use GDAL_USE_GROK, but not found")
endif ()
endif ()
cmake_dependent_option(GDAL_USE_GROK "Set ON to use grok" ON GROK_FOUND OFF)
if (GDAL_USE_GROK)
string(APPEND GDAL_IMPORT_DEPENDENCIES "find_dependency(Grok MODULE)\n")
endif ()



# OpenJPEG's cmake-CONFIG is broken, so call module explicitly
find_package(OpenJPEG MODULE)
if (GDAL_USE_OPENJPEG)
Expand Down
78 changes: 78 additions & 0 deletions cmake/modules/packages/FindGrok.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
###
# File: FindGrok.cmake
#

function(transform_version _numerical_result _version_major _version_minor _version_patch)
set(factor 100)
if(_version_minor GREATER 99)
set(factor 1000)
endif()
if(_verion_patch GREATER 99)
set(factor 1000)
endif()
math(EXPR _internal_numerical_result
"${_version_major}*${factor}*${factor} + ${_version_minor}*${factor} + ${_version_patch}"
)
set(${_numerical_result} ${_internal_numerical_result} PARENT_SCOPE)
endfunction()


# - Find Grok
# Find the Grok includes and library
#
# IMPORTED Target
# GROK::Grok
#
# This module defines
# GROK_INCLUDE_DIR, where to find openjpeg.h, etc.
# GROK_LIBRARIES, the libraries needed to use Grok.
# GROK_FOUND, If false, do not try to use Grok.
# also defined, but not for general use are
# GROK_LIBRARY, where to find the Grok library.

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_GROK QUIET libgrokj2k)
set(GROK_VERSION_STRING ${PC_GROK_VERSION})
endif()


find_path(GROK_INCLUDE_DIR grk_config.h
PATH_SUFFIXES
grok-10.0
HINTS ${PC_GROK_INCLUDE_DIRS}
DOC "Location of Grok Headers"
)

find_library(GROK_LIBRARY
NAMES grokj2k
HINTS ${PC_GROK_LIBRARY_DIRS}
)
mark_as_advanced(GROK_LIBRARY GROK_INCLUDE_DIR)

if(GROK_INCLUDE_DIR)
string(REGEX MATCH "([0-9]+).([0-9]+).([0-9]+)" GRK_VERSION ${GROK_VERSION_STRING})
if(GRK_VERSION)
transform_version(GROK_VERSION_NUM ${CMAKE_MATCH_1} ${CMAKE_MATCH_2} ${CMAKE_MATCH_3})
else()
message(FATAL "Grok version not found")
endif()
endif ()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Grok
FOUND_VAR GROK_FOUND
REQUIRED_VARS GROK_LIBRARY GROK_INCLUDE_DIR
VERSION_VAR GROK_VERSION_STRING)
if(GROK_FOUND)
set(GROK_LIBRARIES "${GROK_LIBRARY}")
set(GROK_INCLUDE_DIRS "${GROK_INCLUDE_DIR}")

if(NOT TARGET GROK::Grok)
add_library(GROK::Grok UNKNOWN IMPORTED)
set_target_properties(GROK::Grok PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${GROK_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${GROK_LIBRARY}")
endif()
endif()
17 changes: 17 additions & 0 deletions doc/source/development/building_from_source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,23 @@ JPEG-2000 codec written in C language. It is required for the

Control whether to use OpenJPEG. Defaults to ON when OpenJPEG is found.

Grok
****

The `Grok <https://github.com/GrokImageCompression/grok>`_ library is an open-source
JPEG-2000 codec written in the C++ language.

.. option:: GROK_INCLUDE_DIR

Path to an include directory with the ``grok.h`` header file.

.. option:: GROK_LIBRARY

Path to a shared or static library file.

.. option:: GDAL_USE_GROK=ON/OFF

Control whether to use Grok or not. Defaults to ON when Grok is found.

OpenSSL
*******
Expand Down
1 change: 1 addition & 0 deletions doc/source/drivers/raster/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Raster drivers
isis3
jdem
jp2ecw
jp2grok
jp2kak
jp2lura
jp2mrsid
Expand Down

0 comments on commit 2c17d88

Please sign in to comment.