forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Even Rouault <[email protected]>
- Loading branch information
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env pytest | ||
# -*- coding: utf-8 -*- | ||
############################################################################### | ||
# | ||
# Project: GDAL/OGR Test Suite | ||
# Purpose: gdalenhance testing | ||
# Author: Daniel Baston <dbaston at gmail.com> | ||
# | ||
############################################################################### | ||
# Copyright (c) 2024, ISciences LLC | ||
# | ||
# SPDX-License-Identifier: MIT | ||
############################################################################### | ||
|
||
import gdaltest | ||
import pytest | ||
import test_cli_utilities | ||
|
||
from osgeo import gdal | ||
|
||
pytestmark = pytest.mark.skipif( | ||
test_cli_utilities.get_gdalenhance_path() is None, | ||
reason="gdalenhance not available", | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
def gdalenhance_path(): | ||
return test_cli_utilities.get_gdalenhance_path() | ||
|
||
|
||
############################################################################### | ||
# Output a lookup table, then apply it to the image | ||
|
||
|
||
def test_gdalenhance_output_histogram(gdalenhance_path, tmp_path): | ||
|
||
out, err = gdaltest.runexternal_out_and_err( | ||
f"{gdalenhance_path} -equalize ../gcore/data/rgbsmall.tif" | ||
) | ||
|
||
assert not err | ||
|
||
lines = out.strip().split("\n") | ||
assert len(lines) == 3 | ||
|
||
assert lines[0].startswith("1:Band ") | ||
assert lines[1].startswith("2:Band ") | ||
assert lines[2].startswith("3:Band ") | ||
|
||
lut_fname = tmp_path / "lut.txt" | ||
|
||
with open(lut_fname, "w") as outfile: | ||
for line in lines: | ||
outfile.write(line.strip()) | ||
outfile.write("\n") | ||
|
||
enhanced_fname = tmp_path / "out.tif" | ||
|
||
out, err = gdaltest.runexternal_out_and_err( | ||
f"{gdalenhance_path} -config {lut_fname} ../gcore/data/rgbsmall.tif {enhanced_fname}" | ||
) | ||
|
||
assert not err | ||
|
||
assert enhanced_fname.exists() | ||
|
||
|
||
############################################################################### | ||
# Write a new image directly | ||
|
||
|
||
def test_gdalenhance_output_image(gdalenhance_path, tmp_path): | ||
|
||
infile = "../gcore/data/rgbsmall.tif" | ||
outfile = tmp_path / "out.tif" | ||
|
||
out, err = gdaltest.runexternal_out_and_err( | ||
f"{gdalenhance_path} -quiet -equalize -co COMPRESS=DEFLATE {infile} {outfile}" | ||
) | ||
|
||
assert not err | ||
|
||
with gdal.Open(infile) as src, gdal.Open(outfile) as dst: | ||
assert src.RasterCount == dst.RasterCount | ||
assert src.RasterXSize == dst.RasterXSize | ||
assert src.RasterYSize == dst.RasterYSize | ||
|
||
# check that -co was honored | ||
assert dst.GetMetadata("IMAGE_STRUCTURE")["COMPRESSION"] == "DEFLATE" |