Skip to content

Commit 4d63284

Browse files
author
Grok Compression
committed
code: a few tweaks
1 parent 539e737 commit 4d63284

File tree

580 files changed

+107255
-44729
lines changed

Some content is hidden

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

580 files changed

+107255
-44729
lines changed

CMakeLists.txt

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
# Copyright (C) 2016-2025 Grok Image Compression Inc.
2+
#
3+
# This source code is free software: you can redistribute it and/or modify
4+
# it under the terms of the GNU Affero General Public License, version 3,
5+
# as published by the Free Software Foundation.
6+
#
7+
# This source code is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU Affero General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU Affero General Public License
13+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
14+
15+
116
cmake_minimum_required(VERSION 3.20)
217

318
project(GROK)
419

520
#######################################
621
# GROK version
7-
set(GROK_VERSION_MAJOR 15)
8-
set(GROK_VERSION_MINOR 1)
22+
set(GROK_VERSION_MAJOR 20)
23+
set(GROK_VERSION_MINOR 0)
924
set(GROK_VERSION_PATCH 0)
1025
set(GROK_VERSION
1126
"${GROK_VERSION_MAJOR}.${GROK_VERSION_MINOR}.${GROK_VERSION_PATCH}")
@@ -27,12 +42,10 @@ set(GROK_CORE_NAME grokj2k)
2742
set(GROK_CODEC_NAME grokj2kcodec)
2843
set(GROK_PLUGIN_NAME grokj2k_plugin)
2944

30-
set(CMAKE_CXX_STANDARD 23)
45+
set(CMAKE_CXX_STANDARD 20)
3146
set(CMAKE_CXX_STANDARD_REQUIRED ON)
32-
if ( (CMAKE_CXX_COMPILER_ID MATCHES "GNU") AND (CMAKE_CXX_COMPILER_VERSION LESS 11.0) )
33-
message(FATAL_ERROR "GNU compiler version must be at least 11.0")
34-
endif()
3547

48+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
3649

3750
if (CMAKE_SYSTEM_PROCESSOR MATCHES "unknown")
3851
# uname -p is broken on this system. Try uname -m
@@ -45,9 +58,13 @@ else (CMAKE_SYSTEM_PROCESSOR MATCHES "unknown")
4558
endif (CMAKE_SYSTEM_PROCESSOR MATCHES "unknown")
4659
message(STATUS "Architecture: " ${GRK_ARCH})
4760

48-
IF(MSVC)
49-
string(APPEND CMAKE_CXX_FLAGS " /EHsc /utf-8")
50-
ENDIF(MSVC)
61+
if(MSVC)
62+
add_compile_options(/EHsc /utf-8)
63+
endif()
64+
65+
if ( (CMAKE_CXX_COMPILER_ID MATCHES "GNU") AND (CMAKE_CXX_COMPILER_VERSION LESS 10.0) )
66+
message(FATAL_ERROR "GNU compiler version must be at least 10.0")
67+
endif()
5168

5269
# Set a default build type if none was specified
5370
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
@@ -64,6 +81,11 @@ check_pie_supported(LANGUAGES CXX)
6481
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
6582
endif()
6683

84+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fno-omit-frame-pointer")
85+
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -fno-omit-frame-pointer")
86+
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} -Wl,--build-id")
87+
88+
6789
# Path to additional CMake modules
6890
set(CMAKE_MODULE_PATH
6991
${GROK_SOURCE_DIR}/cmake
@@ -128,10 +150,11 @@ option(GRK_BUILD_LCMS2 "Build lcms2 library" ON)
128150
option(GRK_BUILD_JPEG "Build jpeg library" ON)
129151
add_subdirectory(thirdparty)
130152

153+
# Build Library
131154
option(BUILD_LUTS_GENERATOR "Build utility to generate t1_luts.h" OFF)
132155

133156
# Build examples
134-
option(GRK_BUILD_CORE_EXAMPLES "Build core examples" OFF)
157+
option(GRK_BUILD_CORE_EXAMPLES "Build core examples" ON)
135158
option(GRK_BUILD_CODEC_EXAMPLES "Build codec examples" OFF)
136159

137160
# examples use files from data folder
@@ -142,6 +165,26 @@ if (GRK_BUILD_CORE_EXAMPLES OR GRK_BUILD_CODEC_EXAMPLES)
142165
NO_CMAKE_FIND_ROOT_PATH)
143166
endif()
144167

168+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
169+
if(WIN32)
170+
# Ensure no debug symbols & remove Debug Directory
171+
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG:NONE /RELEASE")
172+
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG:NONE /RELEASE")
173+
174+
if(MSVC)
175+
# Ensure MSVC does not generate .pdb files
176+
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "None")
177+
endif()
178+
elseif(APPLE)
179+
# Strip all local symbols for macOS
180+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-x")
181+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-x")
182+
else()
183+
# Strip all symbols for shared libraries on other non-Windows platforms (e.g., Linux)
184+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--strip-all")
185+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--strip-all")
186+
endif()
187+
endif()
145188

146189
# Build Applications
147190
option(GRK_BUILD_CODEC "Build the CODEC executables" ON)
@@ -151,20 +194,24 @@ mark_as_advanced(GRK_BUILD_PLUGIN_LOADER)
151194
# Add an option to enable or disable the ExifTool check
152195
option(GRK_ENABLE_EXIFTOOL "Enable detection of ExifTool Perl module" ON)
153196

154-
# Check for Perl library
197+
# Check for Perl libraries and ExifTool only if the option is enabled
155198
if (GRK_ENABLE_EXIFTOOL)
156-
find_package(PerlLibs)
157-
if (PERLLIBS_FOUND)
158-
message(STATUS "Perl libraries found")
159-
execute_process(COMMAND ${PERL_EXECUTABLE} -MImage::ExifTool -e ""
160-
ERROR_QUIET RESULT_VARIABLE status)
161-
if (NOT status)
162-
message(STATUS "ExifTool Perl module found")
163-
set(GROK_HAVE_EXIFTOOL define)
164-
else()
165-
message(STATUS "ExifTool Perl module not found")
166-
endif()
167-
endif(PERLLIBS_FOUND)
199+
find_package(PerlLibs)
200+
if (PERLLIBS_FOUND)
201+
message(STATUS "Perl libraries found")
202+
execute_process(COMMAND ${PERL_EXECUTABLE} -MImage::ExifTool -e ""
203+
ERROR_QUIET RESULT_VARIABLE status)
204+
if (NOT status)
205+
message(STATUS "ExifTool Perl module found")
206+
set(GROK_HAVE_EXIFTOOL define)
207+
else()
208+
message(STATUS "ExifTool Perl module not found")
209+
endif()
210+
else()
211+
message(STATUS "Perl libraries not found")
212+
endif()
213+
else()
214+
message(STATUS "ExifTool detection is disabled")
168215
endif()
169216

170217
add_subdirectory(src/lib/core)
@@ -183,6 +230,7 @@ if(GRK_BUILD_CORE_SWIG_BINDINGS)
183230
endif()
184231

185232

233+
186234
if(GRK_BUILD_CODEC)
187235
add_subdirectory(src/bin)
188236
add_subdirectory(src/lib/codec)
@@ -214,6 +262,7 @@ if(BUILD_TESTING AND GRK_BUILD_CODEC)
214262
PATHS $ENV{GRK_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../grok-test-data
215263
NO_CMAKE_FIND_ROOT_PATH)
216264
add_subdirectory(tests)
265+
set(GRK_BUILD_CORE_EXAMPLES ON CACHE BOOL "Build core examples" FORCE)
217266
endif()
218267

219268
# install all targets referenced as GrokTargets
@@ -236,7 +285,6 @@ if (BUILD_SHARED_LIBS AND NOT CMAKE_SYSTEM_NAME STREQUAL Emscripten)
236285
DESTINATION ${GROK_INSTALL_PACKAGE_DIR})
237286
endif()
238287

239-
240288
if(GRK_BUILD_DOC)
241289
install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
242290
endif()

INSTALL.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ to `glibc`. For a purely static build, the library can be built
112112
on [Alpine Linux](https://www.alpinelinux.org/). Alpine uses
113113
[musl libc](https://musl.libc.org/), which can be linked to statically.
114114

115-
`cmake` must also be configured with `-DBUILD_SHARED_LIBS:bool=off -DGRK_ENABLE_EXIFTOOL:bool=off -DCMAKE_EXE_LINKER_FLAGS="-static"`.
115+
Note: `cmake` must also be configured with `-DCMAKE_EXE_LINKER_FLAGS="-static"`.
116116

117117
### Fedora
118118

@@ -122,8 +122,8 @@ from the build folder, then
122122
must be added to the `.bashrc` file. Note that the build binary folder is
123123
entered before the system binary folder, so that build shared libraries
124124
are given priority when loading at run time.
125-
1. for a static build, the following libraries must be installed:
126-
`sudo dnf install libstdc++-static glibc-static`
125+
1. for a static build, the following library must be installed:
126+
`sudo dnf install libstdc++-static`
127127

128128
### Debug/Release
129129

@@ -219,4 +219,10 @@ Type `cmake --help` for available generators on your platform.
219219
Third party libraries such as `libtiff` are built by default. To disable
220220
`libtiff` library build and use the version installed on your system, set :
221221

222-
`-DGRK_BUILD_LiBTIFF:BOOL=OFF`
222+
`-DGRK_BUILD_LiBTIFF:BOOL=OFF`
223+
224+
## Linking with other Cmake Projects
225+
226+
1. set `CMAKE_INSTALL_PREFIX` to `/PATH/TO/INSTALL/DIR`
227+
1. build and install
228+
1. on other project, set `CMAKE_PREFIX_PATH` to `/PATH/TO/INSTALL/DIR`

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
### Features
1414

15-
* support for High Throughput JPEG 2000 (HTJ2K) encode/decode
15+
* support for new **High Throughput JPEG 2000 (HTJ2K)** standard
16+
* fast random-access sub-image decoding using `TLM` and `PLT` markers
1617
* full encode/decode support for `ICC` colour profiles
1718
* full encode/decode support for `XML`,`IPTC`, `XMP` and `EXIF` meta-data
1819
* full encode/decode support for `monochrome`, `sRGB`, `palette`, `YCC`, `extended YCC`, `CIELab` and `CMYK` colour spaces
@@ -28,14 +29,44 @@
2829
2. [Generating Lossy Access JP2s With Grok](https://www.bitsgalore.org/2022/03/30/generating-lossy-access-jp2s-from-lossless-preservation-masters)
2930

3031

32+
### Performance
33+
34+
Below is a benchmark comparing time and memory performance for **Grok 9.7.8** and **Kakadu 8.05** on the following workflows:
35+
36+
1. decompress large single-tiled [image of Mars](https://hirise.lpl.arizona.edu/PDS/RDR/ESP/ORB_011200_011299/ESP_011277_1825/ESP_011277_1825_RED.JP2) to TIF output
37+
1. decompress region `(1000,1000,5000,5000)` from large single-tiled [image of Mars](https://hirise.lpl.arizona.edu/PDS/RDR/ESP/ORB_011200_011299/ESP_011277_1825/ESP_011277_1825_RED.JP2) to TIF output
38+
1. decompress 6 resolutions from `580000x825000` single-tiled [image of Luxembourg](https://s3.eu-central-1.amazonaws.com/download.data.public.lu/resources/orthophoto-officelle-du-grand-duche-de-luxembourg-edition-2020/20210602-110516/Luxembourg-2020_ortho10cm_RVB_LUREF.jp2)
39+
1. decompress 7 resolutions from `580000x825000` single-tiled [image of Luxembourg](https://s3.eu-central-1.amazonaws.com/download.data.public.lu/resources/orthophoto-officelle-du-grand-duche-de-luxembourg-edition-2020/20210602-110516/Luxembourg-2020_ortho10cm_RVB_LUREF.jp2)
40+
1. decompress 8 resolutions from `580000x825000` single-tiled [image of Luxembourg](https://s3.eu-central-1.amazonaws.com/download.data.public.lu/resources/orthophoto-officelle-du-grand-duche-de-luxembourg-edition-2020/20210602-110516/Luxembourg-2020_ortho10cm_RVB_LUREF.jp2)
41+
1. decompress region `(574200,816750,580000,825000)` from `580000x825000` single-tiled [image of Luxembourg](https://s3.eu-central-1.amazonaws.com/download.data.public.lu/resources/orthophoto-officelle-du-grand-duche-de-luxembourg-edition-2020/20210602-110516/Luxembourg-2020_ortho10cm_RVB_LUREF.jp2)
42+
43+
44+
45+
#### Benchmark Details
46+
47+
* test system : 24 core / 48 thread `AMD Threadripper`
48+
running `Fedora 36` with `5.17` Linux kernel and `xfs` file system
49+
* codecs were configured to use all 48 threads
50+
* file cache was cleared before each decompression using `$ sudo sysctl vm.drop_caches=3`
51+
* Grok was built in release mode using `GCC 10`
52+
53+
#### Results
54+
55+
| Test | Grok | Kakadu
56+
| :---- | :----- | :------:
57+
| 1 | 13.74 s / 16.6 GB | 9.02 s / 0.05 GB
58+
| 2 | 0.25 s / 0.4 GB | 0.12 s
59+
| 3 | 0.37 s / 0.7 GB | 2.72 s / 1.0 GB
60+
| 4 | 0.67 s / 1.0 GB | 3.02 s / 1.0 GB
61+
| 5 | 1.76 s / 1.8 GB | 3.72 s / 1.1 GB
62+
| 6 | 2.89 s / 6.0 GB | 7.39 s / 1.1 GB
3163

3264
### Library Details
3365

3466
* [INSTALL](https://github.com/GrokImageCompression/grok/blob/master/INSTALL.md)
3567
* [WIKI](https://github.com/GrokImageCompression/grok/wiki)
3668
* [LICENSE][link-license]
3769

38-
3970
### Current Build Status
4071
[![badge-actions]][link-actions]
4172
[![badge-oss-fuzz]][link-oss-fuzz]
@@ -52,4 +83,4 @@ For more information please contact :
5283
[badge-actions]: https://github.com/GrokImageCompression/grok/actions/workflows/build.yml/badge.svg?branch=master
5384
[link-actions]: https://github.com/GrokImageCompression/grok/actions
5485
[badge-oss-fuzz]: https://oss-fuzz-build-logs.storage.googleapis.com/badges/grok.svg
55-
[link-oss-fuzz]: https://issues.oss-fuzz.com/issues?q=proj:grok
86+
[link-oss-fuzz]: https://issues.oss-fuzz.com/issues?q=proj:grok

Testing/Temporary/CTestCostData.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

benchmark/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.png

benchmark/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
## Windows Benchmarks
3+
4+
powershell
5+
6+
Measure-Command {$HOME\src\grok\build\bin\Release\grk_decompress.exe -i $HOME\temp\IMG_PHR1B_P_202406071720183_SEN_7038440101-1_R1C1.JP2 -o $HOME\temp\temp.tif -t 0 -H 1}
7+
8+
Measure-Command {$HOME\src\grok\build\bin\Release\core_decompress.exe -i $HOME\temp\IMG_PHR1B_P_202406071720183_SEN_7038440101-1_R1C1.JP2 -t 0 -H 1}
9+
10+
Measure-Command {$HOME\bin\kdu_expand.exe -i $HOME\temp\IMG_PHR1B_P_202406071720183_SEN_7038440101-1_R1C1.JP2 -o $HOME\temp\temp.tif -region "{0.00000000000000000,0.00000000000000000},{0.10101109741060420,0.09905204101373573}" -num_threads 1 }
11+
12+
## Image Stitching
13+
14+
1. Create TIFFs with Fake Coordinates
15+
16+
17+
```
18+
gdal_translate -a_srs EPSG:3857 -a_ullr 0 20000 20000 0 input.JP2 input_georef1.tif
19+
gdal_translate -a_srs EPSG:3857 -a_ullr 20000 20000 40000 0 input.JP2 input_georef2.tif
20+
gdal_translate -a_srs EPSG:3857 -a_ullr 40000 20000 60000 0 input.JP2 input_georef3.tif
21+
gdal_translate -a_srs EPSG:3857 -a_ullr 60000 20000 80000 0 input.JP2 input_georef4.tif
22+
23+
gdal_translate -a_srs EPSG:3857 -a_ullr 0 40000 20000 20000 input.JP2 input_georef5.tif
24+
gdal_translate -a_srs EPSG:3857 -a_ullr 20000 40000 40000 20000 input.JP2 input_georef6.tif
25+
gdal_translate -a_srs EPSG:3857 -a_ullr 40000 40000 60000 20000 input.JP2 input_georef7.tif
26+
gdal_translate -a_srs EPSG:3857 -a_ullr 60000 40000 80000 20000 input.JP2 input_georef8.tif
27+
28+
gdal_translate -a_srs EPSG:3857 -a_ullr 0 60000 20000 40000 input.JP2 input_georef9.tif
29+
gdal_translate -a_srs EPSG:3857 -a_ullr 20000 60000 40000 40000 input.JP2 input_georef10.tif
30+
gdal_translate -a_srs EPSG:3857 -a_ullr 40000 60000 60000 40000 input.JP2 input_georef11.tif
31+
gdal_translate -a_srs EPSG:3857 -a_ullr 60000 60000 80000 40000 input.JP2 input_georef12.tif
32+
33+
gdal_translate -a_srs EPSG:3857 -a_ullr 0 80000 20000 60000 input.JP2 input_georef13.tif
34+
gdal_translate -a_srs EPSG:3857 -a_ullr 20000 80000 40000 60000 input.JP2 input_georef14.tif
35+
gdal_translate -a_srs EPSG:3857 -a_ullr 40000 80000 60000 60000 input.JP2 input_georef15.tif
36+
gdal_translate -a_srs EPSG:3857 -a_ullr 60000 80000 80000 60000 input.JP2 input_georef16.tif
37+
```
38+
39+
2. Build Virtual Raster
40+
41+
```
42+
gdalbuildvrt -overwrite output.vrt \
43+
input_georef1.tif input_georef2.tif input_georef3.tif input_georef4.tif \
44+
input_georef5.tif input_georef6.tif input_georef7.tif input_georef8.tif \
45+
input_georef9.tif input_georef10.tif input_georef11.tif input_georef12.tif \
46+
input_georef13.tif input_georef14.tif input_georef15.tif input_georef16.tif
47+
48+
```
49+
50+
3. Convert to BigTIFF
51+
52+
```
53+
gdal_translate -of GTiff -co BIGTIFF=YES -co TILED=NO output.vrt output.tif
54+
```
55+
56+
4. Kakadu compression
57+
58+
```
59+
kdu_compress -i pleiades4x4.tif -o pleiades4x4.jp2 -rate 90,80,70,60,50,40,30,20,10,9,8,7,6,5,1 Clayers=15 Stiles="{1024,1024}" ORGgen_plt=yes Clevels=6 Corder=LRCP Cblk="{64,64}" Cuse_sop=yes Cuse_eph=yes Creversible=no
60+
```
61+
62+
```
63+
kdu_compress -i output.tif -o output.jp2 -rate 90,80,70,60,50,40,30,20,10,9,8,7,6,5,1 Clayers=15 Stiles="{128,128}" ORGgen_plt=yes ORGtparts=R Clevels=6 Corder=RPCL Cblk="{64,64}" Cuse_sop=yes Cuse_eph=yes Creversible=no
64+
```
65+
66+
5. Add TLM Marker
67+
68+
```
69+
kdu_maketlm output.jp2 output_tlm.jp2
70+
```

0 commit comments

Comments
 (0)