Skip to content

Commit

Permalink
Merge branch 'master' of github.com:OSGeo/gdal
Browse files Browse the repository at this point in the history
* 'master' of github.com:OSGeo/gdal:
  NITF: fix writing of COMRAT field in JPEG/JPEG2000 mode, when there are FILE TREs
  autotest/utilities/data/color_*.[qml|txt] - add TXT+QGIS QML color files samples autotest/pyscripts/test_gdal_utils.py - test new color files
  gdal-utils/osgeo_utils/auxiliary/color_palette.py - merge read() + read_color_file() logic and fix the functions for reading qlr, qml files; rename some internal functions gdal-utils/osgeo_utils/auxiliary/color_table.py - get_color_palette now raises an Exception to indicate a failure
  gdal_calc.py - fix type hint - color_table: Optional[ColorTableLike]
  • Loading branch information
a0x8o committed Jun 10, 2022
1 parent 49a7c73 commit 01a6ad8
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 2 deletions.
29 changes: 29 additions & 0 deletions autotest/pyscripts/test_gdal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@

pytest.importorskip('osgeo_utils')

<<<<<<< HEAD
from osgeo_utils.auxiliary import util, raster_creation, base, array_util, color_table
from osgeo_utils.auxiliary.color_palette import ColorPalette
from osgeo_utils.auxiliary.color_table import get_color_table
from osgeo_utils.auxiliary.extent_util import Extent
import gdaltest
=======
from osgeo_utils.auxiliary import util, raster_creation, base, array_util
from osgeo_utils.auxiliary.color_palette import ColorPalette
from osgeo_utils.auxiliary.extent_util import Extent
>>>>>>> 5742ec588f (Merge branch 'master' of github.com:OSGeo/gdal)

temp_files = []

Expand Down Expand Up @@ -165,6 +171,7 @@ def test_utils_np_arrays():
assert isinstance(arr, array_util.ArrayLike.__args__)


<<<<<<< HEAD
@pytest.mark.parametrize("name,count,pal",
[['color_paletted_red_green_0-255.qml', 256, {0: 0x00ffffff, 1: 0xFF808080}],
['color_pseudocolor_spectral_0-100.qml', 5, {0: 0xFFD7191C, 25: 0xFFFFFFBF}]])
Expand Down Expand Up @@ -264,6 +271,28 @@ def test_read_write_color_table_from_raster():
ds = None

gdaltest.tiff_drv.Delete('tmp/ct8.tif')
=======
def test_utils_color_files():
""" test color palettes: read QML and TXT files """
items = [
dict(name='color_paletted_red_green_0-255.qml', count=256, pal={0: 0x00ffffff, 1: 0xFF808080}),
dict(name='colro_pseudocolor_spectral_0-100.qml', count=5, pal={0: 0xFFD7191C, 25: 0xFFFFFFBF}),
]
root = Path(test_py_scripts.get_data_path('utilities'))
for item in items:
path = root / item['name']
path2 = path.with_suffix('.txt')
cp1 = ColorPalette()
cp2 = ColorPalette()
cp1.read_file(path)
# cp1.write_file(path2)
cp2.read_file(path2)
assert cp1 == cp2
assert len(cp1.pal) == item['count']
for k, v in item['pal'].items():
# compare the first values against the hard-coded test sample
assert cp1.pal[k] == v
>>>>>>> 5742ec588f (Merge branch 'master' of github.com:OSGeo/gdal)


def test_utils_py_cleanup():
Expand Down
78 changes: 78 additions & 0 deletions autotest/utilities/data/colro_pseudocolor_spectral_0-100.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis styleCategories="AllStyleCategories" maxScale="0" version="3.18.0-Zürich" hasScaleBasedVisibilityFlag="0" minScale="1e+08">
<flags>
<Identifiable>1</Identifiable>
<Removable>1</Removable>
<Searchable>1</Searchable>
<Private>0</Private>
</flags>
<temporal fetchMode="0" enabled="0" mode="0">
<fixedRange>
<start></start>
<end></end>
</fixedRange>
</temporal>
<customproperties>
<property value="false" key="WMSBackgroundLayer"/>
<property value="false" key="WMSPublishDataSourceUrl"/>
<property value="0" key="embeddedWidgets/count"/>
<property value="Value" key="identify/format"/>
</customproperties>
<pipe>
<provider>
<resampling zoomedInResamplingMethod="nearestNeighbour" maxOversampling="2" enabled="false" zoomedOutResamplingMethod="nearestNeighbour"/>
</provider>
<rasterrenderer type="singlebandpseudocolor" opacity="1" alphaBand="-1" band="1" classificationMax="100" classificationMin="0" nodataColor="">
<rasterTransparency/>
<minMaxOrigin>
<limits>None</limits>
<extent>WholeRaster</extent>
<statAccuracy>Estimated</statAccuracy>
<cumulativeCutLower>0.02</cumulativeCutLower>
<cumulativeCutUpper>0.98</cumulativeCutUpper>
<stdDevFactor>2</stdDevFactor>
</minMaxOrigin>
<rastershader>
<colorrampshader classificationMode="1" minimumValue="0" maximumValue="100" clip="0" labelPrecision="4" colorRampType="INTERPOLATED">
<colorramp type="gradient" name="[source]">
<Option type="Map">
<Option value="215,25,28,255" type="QString" name="color1"/>
<Option value="43,131,186,255" type="QString" name="color2"/>
<Option value="0" type="QString" name="discrete"/>
<Option value="gradient" type="QString" name="rampType"/>
<Option value="0.25;255,255,191,255:0.5;253,174,97,255:0.75;171,221,164,255" type="QString" name="stops"/>
</Option>
<prop k="color1" v="215,25,28,255"/>
<prop k="color2" v="43,131,186,255"/>
<prop k="discrete" v="0"/>
<prop k="rampType" v="gradient"/>
<prop k="stops" v="0.25;255,255,191,255:0.5;253,174,97,255:0.75;171,221,164,255"/>
</colorramp>
<item value="0" label="0.0000" color="#d7191c" alpha="255"/>
<item value="25" label="25.0000" color="#ffffbf" alpha="255"/>
<item value="50" label="50.0000" color="#fdae61" alpha="255"/>
<item value="75" label="75.0000" color="#abdda4" alpha="255"/>
<item value="100" label="100.0000" color="#2b83ba" alpha="255"/>
<rampLegendSettings prefix="" direction="0" orientation="2" minimumLabel="" maximumLabel="" suffix="">
<numericFormat id="basic">
<Option type="Map">
<Option value="" type="QChar" name="decimal_separator"/>
<Option value="6" type="int" name="decimals"/>
<Option value="0" type="int" name="rounding_type"/>
<Option value="false" type="bool" name="show_plus"/>
<Option value="true" type="bool" name="show_thousand_separator"/>
<Option value="false" type="bool" name="show_trailing_zeros"/>
<Option value="" type="QChar" name="thousand_separator"/>
</Option>
</numericFormat>
</rampLegendSettings>
</colorrampshader>
</rastershader>
</rasterrenderer>
<brightnesscontrast brightness="0" gamma="1" contrast="0"/>
<huesaturation colorizeRed="255" saturation="0" colorizeOn="0" colorizeStrength="100" colorizeGreen="128" colorizeBlue="128" grayscaleMode="0"/>
<rasterresampler maxOversampling="2"/>
<resamplingStage>resamplingFilter</resamplingStage>
</pipe>
<blendMode>0</blendMode>
</qgis>
5 changes: 5 additions & 0 deletions autotest/utilities/data/colro_pseudocolor_spectral_0-100.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0 215 25 28
25 255 255 191
50 253 174 97
75 171 221 164
100 43 131 186
33 changes: 31 additions & 2 deletions frmts/nitf/nitfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static bool NITFPatchImageLength( const char *pszFilename,
GUIntBig nImageOffset,
GIntBig nPixelCount,
const char *pszIC,
<<<<<<< HEAD:frmts/nitf/nitfdataset.cpp
<<<<<<< HEAD:frmts/nitf/nitfdataset.cpp
vsi_l_offset nICOffset,
CSLConstList papszCreationOptions );
Expand All @@ -76,6 +77,9 @@ static bool NITFWriteExtraSegments( const char *pszFilename,
CSLConstList papszTextMD,
CSLConstList papszOptions );
=======
=======
int nICOffset,
>>>>>>> 5742ec588f (Merge branch 'master' of github.com:OSGeo/gdal):gdal/frmts/nitf/nitfdataset.cpp
CSLConstList papszCreationOptions );
static bool NITFWriteCGMSegments( const char *pszFilename, char **papszList );
static bool NITFWriteTextSegments( const char *pszFilename, char **papszList );
Expand Down Expand Up @@ -212,8 +216,12 @@ int NITFDataset::CloseDependentDatasets()
"C8", m_nICOffset, nullptr ));
=======
NITFPatchImageLength( GetDescription(), nImageStart, nPixelCount,
<<<<<<< HEAD:frmts/nitf/nitfdataset.cpp
"C8", nullptr ));
>>>>>>> 33d99249ed (Merge branch 'master' of github.com:OSGeo/gdal):gdal/frmts/nitf/nitfdataset.cpp
=======
"C8", m_nICOffset, nullptr ));
>>>>>>> 5742ec588f (Merge branch 'master' of github.com:OSGeo/gdal):gdal/frmts/nitf/nitfdataset.cpp
}

bJP2Writing = FALSE;
Expand Down Expand Up @@ -4199,6 +4207,7 @@ NITFDataset::NITFDatasetCreate( const char *pszFilename, int nXSize, int nYSize,
/* Create the file. */
/* -------------------------------------------------------------------- */

<<<<<<< HEAD:frmts/nitf/nitfdataset.cpp
int nIMIndex = 0;
int nImageCount = 0;
vsi_l_offset nImageOffset = 0;
Expand All @@ -4207,6 +4216,12 @@ NITFDataset::NITFDatasetCreate( const char *pszFilename, int nXSize, int nYSize,
GDALGetDataTypeSize( eType ), pszPVType,
papszFullOptions,
&nIMIndex, &nImageCount, &nImageOffset, &nICOffset ) )
=======
int nICOffset = 0;
if( !NITFCreateEx( pszFilename, nXSize, nYSize, nBands,
GDALGetDataTypeSize( eType ), pszPVType,
papszFullOptions, &nICOffset ) )
>>>>>>> 5742ec588f (Merge branch 'master' of github.com:OSGeo/gdal):gdal/frmts/nitf/nitfdataset.cpp
{
CSLDestroy(papszTextMD);
CSLDestroy(papszCgmMD);
Expand Down Expand Up @@ -4248,9 +4263,12 @@ NITFDataset::NITFDatasetCreate( const char *pszFilename, int nXSize, int nYSize,
NITFDataset::OpenInternal(&oOpenInfo, poWritableJ2KDataset, true, nIMIndex);
if (poDS)
{
<<<<<<< HEAD:frmts/nitf/nitfdataset.cpp
poDS->m_nImageOffset = nImageOffset;
poDS->m_nIMIndex = nIMIndex;
poDS->m_nImageCount = nImageCount;
=======
>>>>>>> 5742ec588f (Merge branch 'master' of github.com:OSGeo/gdal):gdal/frmts/nitf/nitfdataset.cpp
poDS->m_nICOffset = nICOffset;
poDS->papszTextMDToWrite = papszTextMD;
poDS->papszCgmMDToWrite = papszCgmMD;
Expand Down Expand Up @@ -5027,6 +5045,7 @@ NITFDataset::NITFCreateCopy(
}
}

<<<<<<< HEAD:frmts/nitf/nitfdataset.cpp
int nIMIndex = 0;
int nImageCount = 0;
vsi_l_offset nImageOffset = 0;
Expand All @@ -5035,6 +5054,12 @@ NITFDataset::NITFCreateCopy(
GDALGetDataTypeSize( eType ), pszPVType,
papszFullOptions,
&nIMIndex, &nImageCount, &nImageOffset, &nICOffset ) )
=======
int nICOffset = 0;
if (!NITFCreateEx( pszFilename, nXSize, nYSize, poSrcDS->GetRasterCount(),
GDALGetDataTypeSize( eType ), pszPVType,
papszFullOptions, &nICOffset ))
>>>>>>> 5742ec588f (Merge branch 'master' of github.com:OSGeo/gdal):gdal/frmts/nitf/nitfdataset.cpp
{
CSLDestroy( papszFullOptions );
CSLDestroy(papszCgmMD);
Expand Down Expand Up @@ -5122,7 +5147,7 @@ NITFDataset::NITFCreateCopy(
}
=======
bool bOK = NITFPatchImageLength( pszFilename, nImageOffset, nPixelCount,
"C8", papszFullOptions );
"C8", nICOffset, papszFullOptions );
bOK &= NITFWriteCGMSegments( pszFilename, papszCgmMD );
bOK &= NITFWriteTextSegments( pszFilename, papszTextMD );
>>>>>>> 33d99249ed (Merge branch 'master' of github.com:OSGeo/gdal):gdal/frmts/nitf/nitfdataset.cpp
Expand Down Expand Up @@ -5197,7 +5222,7 @@ NITFDataset::NITFCreateCopy(
}
=======
bool bOK = NITFPatchImageLength( pszFilename, nImageOffset,
nPixelCount, pszIC, papszFullOptions );
nPixelCount, pszIC, nICOffset, papszFullOptions );

bOK &= NITFWriteCGMSegments( pszFilename, papszCgmMD );
bOK &= NITFWriteTextSegments( pszFilename, papszTextMD );
Expand Down Expand Up @@ -5414,10 +5439,14 @@ static bool NITFPatchImageLength( const char *pszFilename,
GUIntBig nImageOffset,
GIntBig nPixelCount,
const char *pszIC,
<<<<<<< HEAD:frmts/nitf/nitfdataset.cpp
<<<<<<< HEAD:frmts/nitf/nitfdataset.cpp
vsi_l_offset nICOffset,
=======
>>>>>>> 33d99249ed (Merge branch 'master' of github.com:OSGeo/gdal):gdal/frmts/nitf/nitfdataset.cpp
=======
int nICOffset,
>>>>>>> 5742ec588f (Merge branch 'master' of github.com:OSGeo/gdal):gdal/frmts/nitf/nitfdataset.cpp
CSLConstList papszCreationOptions )

{
Expand Down
4 changes: 4 additions & 0 deletions frmts/nitf/nitfdataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ class NITFDataset final: public GDALPamDataset

GDALDataset *poJ2KDataset;
int bJP2Writing;
<<<<<<< HEAD:frmts/nitf/nitfdataset.h
vsi_l_offset m_nImageOffset = 0;
int m_nIMIndex = 0;
int m_nImageCount = 0;
vsi_l_offset m_nICOffset = 0;
=======
int m_nICOffset = 0;
>>>>>>> 5742ec588f (Merge branch 'master' of github.com:OSGeo/gdal):gdal/frmts/nitf/nitfdataset.h

GDALDataset *poJPEGDataset;

Expand Down
15 changes: 15 additions & 0 deletions frmts/nitf/nitffile.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ int NITFCreate( const char *pszFilename,

{
return NITFCreateEx(pszFilename, nPixels, nLines, nBands, nBitsPerSample,
<<<<<<< HEAD:frmts/nitf/nitffile.c
pszPVType, papszOptions, NULL, NULL, NULL, NULL);
}

Expand All @@ -555,6 +556,15 @@ int NITFCreateEx( const char *pszFilename,
int* pnImageCount,
vsi_l_offset* pnImageOffset,
vsi_l_offset* pnICOffset )
=======
pszPVType, papszOptions, NULL);
}

int NITFCreateEx( const char *pszFilename,
int nPixels, int nLines, int nBands,
int nBitsPerSample, const char *pszPVType,
char **papszOptions, int* pnICOffset )
>>>>>>> 5742ec588f (Merge branch 'master' of github.com:OSGeo/gdal):gdal/frmts/nitf/nitffile.c

{
VSILFILE *fp;
Expand Down Expand Up @@ -1092,11 +1102,16 @@ int NITFCreateEx( const char *pszFilename,
}
}

<<<<<<< HEAD:frmts/nitf/nitffile.c
if( pnICOffset )
{
if( iIM == 0 || bAppendSubdataset )
*pnICOffset = nCur+nOffset+1;
}
=======
if( pnICOffset && iIM == 0 )
*pnICOffset = (int)(nCur+nOffset+1);
>>>>>>> 5742ec588f (Merge branch 'master' of github.com:OSGeo/gdal):gdal/frmts/nitf/nitffile.c
OVR( 2,nCur+nOffset+1, IC , "NC" );

if( pszIC[0] != 'N' )
Expand Down
6 changes: 6 additions & 0 deletions frmts/nitf/nitflib.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,19 @@ int CPL_DLL NITFCreate( const char *pszFilename,
char **papszOptions );

int NITFCreateEx( const char *pszFilename,
<<<<<<< HEAD:frmts/nitf/nitflib.h
int nPixels, int nLines, int nBands,
int nBitsPerSample, const char *pszPVType,
char **papszOptions,
int* pnIndex,
int* pnImageCount,
vsi_l_offset* pnImageOffset,
vsi_l_offset* pnICOffset );
=======
int nPixels, int nLines, int nBands,
int nBitsPerSample, const char *pszPVType,
char **papszOptions, int* pnICOffset );
>>>>>>> 5742ec588f (Merge branch 'master' of github.com:OSGeo/gdal):gdal/frmts/nitf/nitflib.h

const char CPL_DLL *NITFFindTRE( const char *pszTREData, int nTREBytes,
const char *pszTag, int *pnFoundTRESize );
Expand Down
Loading

0 comments on commit 01a6ad8

Please sign in to comment.