Skip to content

Commit 296b599

Browse files
committed
Add GDT_UInt8 in GDALDataType, and alias GDT_Byte on it
1 parent a55b32a commit 296b599

File tree

5 files changed

+48
-40
lines changed

5 files changed

+48
-40
lines changed

doc/source/user/raster_data_model.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ A raster band is represented in GDAL with the :cpp:class:`GDALRasterBand` class.
219219
A raster band has the following properties:
220220

221221
- A width and height in pixels and lines. This is the same as that defined for the dataset, if this is a full resolution band.
222-
- A datatype (GDALDataType). One of Byte, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64, Float16, Float32, Float64, and the complex types CInt16, CInt32, CFloat16, CFloat32, and CFloat64.
222+
- A datatype (GDALDataType). One of UInt8 (since 3.13, also available as Byte in all versions), Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64, Float16, Float32, Float64, and the complex types CInt16, CInt32, CFloat16, CFloat32, and CFloat64.
223223

224224
UInt64 and Int64 data types have been added in GDAL 3.5. Beyond reading and write pixel values, their support is limited. Some algorithms might use 64-bit floating-point internally (warping), as well as some methods returning only double values (GetMinimum(), GetMaximum(), etc.), or even 32-bit floating point (overview, RasterIO resampling). Hence the range where exact values are preserved can be [0, 2^53] (or less if 32-bit floating-point is used).
225225

gcore/gdal.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,28 @@ CPL_C_START
4747
typedef enum
4848
{
4949
/*! Unknown or unspecified type */ GDT_Unknown = 0,
50-
/*! Eight bit unsigned integer */ GDT_Byte = 1,
50+
/*! 8-bit unsigned integer (GDT_Byte in GDAL < 3.13) */ GDT_UInt8 = 1,
5151
/*! 8-bit signed integer (GDAL >= 3.7) */ GDT_Int8 = 14,
52-
/*! Sixteen bit unsigned integer */ GDT_UInt16 = 2,
53-
/*! Sixteen bit signed integer */ GDT_Int16 = 3,
54-
/*! Thirty two bit unsigned integer */ GDT_UInt32 = 4,
55-
/*! Thirty two bit signed integer */ GDT_Int32 = 5,
52+
/*! 16-bit unsigned integer */ GDT_UInt16 = 2,
53+
/*! 16-bit signed integer */ GDT_Int16 = 3,
54+
/*! 32-bit unsigned integer */ GDT_UInt32 = 4,
55+
/*! 32-bit signed integer */ GDT_Int32 = 5,
5656
/*! 64 bit unsigned integer (GDAL >= 3.5)*/ GDT_UInt64 = 12,
5757
/*! 64 bit signed integer (GDAL >= 3.5)*/ GDT_Int64 = 13,
58-
/*! Sixteen bit floating point */ GDT_Float16 = 15,
59-
/*! Thirty two bit floating point */ GDT_Float32 = 6,
60-
/*! Sixty four bit floating point */ GDT_Float64 = 7,
58+
/*! 16-bit floating point */ GDT_Float16 = 15,
59+
/*! 32-bit floating point */ GDT_Float32 = 6,
60+
/*! 64-bit floating point */ GDT_Float64 = 7,
6161
/*! Complex Int16 */ GDT_CInt16 = 8,
6262
/*! Complex Int32 */ GDT_CInt32 = 9,
63-
/* TODO?(#6879): GDT_CInt64 */
6463
/*! Complex Float16 */ GDT_CFloat16 = 16,
6564
/*! Complex Float32 */ GDT_CFloat32 = 10,
6665
/*! Complex Float64 */ GDT_CFloat64 = 11,
6766
GDT_TypeCount = 17 /* maximum type # + 1 */
6867
} GDALDataType;
6968

69+
/** GDT_Byte is the name used before GDAL 3.13 for GDT_UInt8 */
70+
#define GDT_Byte GDT_UInt8
71+
7072
int CPL_DLL CPL_STDCALL GDALGetDataTypeSize(GDALDataType)
7173
/*! @cond Doxygen_Suppress */
7274
CPL_WARN_DEPRECATED("Use GDALGetDataTypeSizeBits() or "

gcore/gdal_misc.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static int GetNonComplexDataTypeElementSizeBits(GDALDataType eDataType)
8787
{
8888
switch (eDataType)
8989
{
90-
case GDT_Byte:
90+
case GDT_UInt8:
9191
case GDT_Int8:
9292
return 8;
9393

@@ -262,7 +262,7 @@ GDALDataType CPL_STDCALL GDALFindDataType(int nBits, int bSigned, int bFloating,
262262
if (!bSigned)
263263
{
264264
if (nBits <= 8)
265-
return GDT_Byte;
265+
return GDT_UInt8;
266266
if (nBits <= 16)
267267
return GDT_UInt16;
268268
if (nBits <= 32)
@@ -367,7 +367,7 @@ GDALDataType CPL_STDCALL GDALFindDataTypeForValue(double dValue, int bComplex)
367367
* Returns the size of a GDT_* type in bytes. In contrast,
368368
* GDALGetDataTypeSize() returns the size in <b>bits</b>.
369369
*
370-
* @param eDataType type, such as GDT_Byte.
370+
* @param eDataType type, such as GDT_UInt8.
371371
* @return the number of bytes or zero if it is not recognised.
372372
*/
373373

@@ -376,7 +376,7 @@ int CPL_STDCALL GDALGetDataTypeSizeBytes(GDALDataType eDataType)
376376
{
377377
switch (eDataType)
378378
{
379-
case GDT_Byte:
379+
case GDT_UInt8:
380380
case GDT_Int8:
381381
return 1;
382382

@@ -419,7 +419,7 @@ int CPL_STDCALL GDALGetDataTypeSizeBytes(GDALDataType eDataType)
419419
* Returns the size of a GDT_* type in bits, <b>not bytes</b>! Use
420420
* GDALGetDataTypeSizeBytes() for bytes.
421421
*
422-
* @param eDataType type, such as GDT_Byte.
422+
* @param eDataType type, such as GDT_UInt8.
423423
* @return the number of bits or zero if it is not recognised.
424424
*/
425425

@@ -441,7 +441,7 @@ int CPL_STDCALL GDALGetDataTypeSizeBits(GDALDataType eDataType)
441441
* Use GDALGetDataTypeSizeBytes() for bytes.
442442
* Use GDALGetDataTypeSizeBits() for bits.
443443
*
444-
* @param eDataType type, such as GDT_Byte.
444+
* @param eDataType type, such as GDT_UInt8.
445445
* @return the number of bits or zero if it is not recognised.
446446
*/
447447

@@ -475,7 +475,7 @@ int CPL_STDCALL GDALDataTypeIsComplex(GDALDataType eDataType)
475475
case GDT_CFloat64:
476476
return TRUE;
477477

478-
case GDT_Byte:
478+
case GDT_UInt8:
479479
case GDT_Int8:
480480
case GDT_Int16:
481481
case GDT_UInt16:
@@ -518,7 +518,7 @@ int CPL_STDCALL GDALDataTypeIsFloating(GDALDataType eDataType)
518518
case GDT_CFloat64:
519519
return TRUE;
520520

521-
case GDT_Byte:
521+
case GDT_UInt8:
522522
case GDT_Int8:
523523
case GDT_Int16:
524524
case GDT_UInt16:
@@ -544,7 +544,7 @@ int CPL_STDCALL GDALDataTypeIsFloating(GDALDataType eDataType)
544544
/**
545545
* \brief Is data type integer? (might be complex)
546546
*
547-
* @return TRUE if the passed type is integer (one of GDT_Byte, GDT_Int16,
547+
* @return TRUE if the passed type is integer (one of GDT_UInt8, GDT_Int16,
548548
* GDT_UInt16, GDT_Int32, GDT_UInt32, GDT_CInt16, GDT_CInt32).
549549
*/
550550

@@ -553,7 +553,7 @@ int CPL_STDCALL GDALDataTypeIsInteger(GDALDataType eDataType)
553553
{
554554
switch (eDataType)
555555
{
556-
case GDT_Byte:
556+
case GDT_UInt8:
557557
case GDT_Int8:
558558
case GDT_Int16:
559559
case GDT_UInt16:
@@ -594,7 +594,7 @@ int CPL_STDCALL GDALDataTypeIsSigned(GDALDataType eDataType)
594594
{
595595
switch (eDataType)
596596
{
597-
case GDT_Byte:
597+
case GDT_UInt8:
598598
case GDT_UInt16:
599599
case GDT_UInt32:
600600
case GDT_UInt64:
@@ -702,7 +702,7 @@ int CPL_STDCALL GDALDataTypeIsConversionLossy(GDALDataType eTypeFrom,
702702
* \brief Get name of data type.
703703
*
704704
* Returns a symbolic name for the data type. This is essentially the
705-
* the enumerated item name with the GDT_ prefix removed. So GDT_Byte returns
705+
* the enumerated item name with the GDT_ prefix removed. So GDT_UInt8 returns
706706
* "Byte". The returned strings are static strings and should not be modified
707707
* or freed by the application. These strings are useful for reporting
708708
* datatypes in debug statements, errors and other user output.
@@ -720,7 +720,8 @@ const char *CPL_STDCALL GDALGetDataTypeName(GDALDataType eDataType)
720720
case GDT_Unknown:
721721
return "Unknown";
722722

723-
case GDT_Byte:
723+
case GDT_UInt8:
724+
// TODO: return UInt8 for GDAL 4 ?
724725
return "Byte";
725726

726727
case GDT_Int8:
@@ -794,6 +795,9 @@ GDALDataType CPL_STDCALL GDALGetDataTypeByName(const char *pszName)
794795
{
795796
VALIDATE_POINTER1(pszName, "GDALGetDataTypeByName", GDT_Unknown);
796797

798+
if (EQUAL(pszName, "UInt8"))
799+
return GDT_UInt8;
800+
797801
for (int iType = 1; iType < GDT_TypeCount; iType++)
798802
{
799803
const auto eType = static_cast<GDALDataType>(iType);
@@ -855,7 +859,7 @@ double GDALAdjustValueToDataType(GDALDataType eDT, double dfValue,
855859
bool bRounded = false;
856860
switch (eDT)
857861
{
858-
case GDT_Byte:
862+
case GDT_UInt8:
859863
ClampAndRound<GByte>(dfValue, bClamped, bRounded);
860864
break;
861865
case GDT_Int8:
@@ -970,7 +974,7 @@ bool GDALIsValueExactAs(double dfValue, GDALDataType eDT)
970974
{
971975
switch (eDT)
972976
{
973-
case GDT_Byte:
977+
case GDT_UInt8:
974978
return GDALIsValueExactAs<uint8_t>(dfValue);
975979
case GDT_Int8:
976980
return GDALIsValueExactAs<int8_t>(dfValue);
@@ -1025,7 +1029,7 @@ bool GDALIsValueInRangeOf(double dfValue, GDALDataType eDT)
10251029
{
10261030
switch (eDT)
10271031
{
1028-
case GDT_Byte:
1032+
case GDT_UInt8:
10291033
return GDALIsValueInRange<uint8_t>(dfValue);
10301034
case GDT_Int8:
10311035
return GDALIsValueInRange<int8_t>(dfValue);
@@ -1089,7 +1093,7 @@ GDALDataType CPL_STDCALL GDALGetNonComplexDataType(GDALDataType eDataType)
10891093
case GDT_CFloat64:
10901094
return GDT_Float64;
10911095

1092-
case GDT_Byte:
1096+
case GDT_UInt8:
10931097
case GDT_UInt16:
10941098
case GDT_UInt32:
10951099
case GDT_UInt64:
@@ -1586,7 +1590,7 @@ int CPL_STDCALL GDALGetRandomRasterSample(GDALRasterBandH hBand, int nSamples,
15861590

15871591
switch (poBlock->GetDataType())
15881592
{
1589-
case GDT_Byte:
1593+
case GDT_UInt8:
15901594
dfValue =
15911595
reinterpret_cast<const GByte *>(pDataRef)[iOffset];
15921596
break;
@@ -5554,7 +5558,7 @@ double GDALGetNoDataReplacementValue(GDALDataType dt, double dfNoDataValue)
55545558
// specified data type and return a replacement value if it is, return
55555559
// 0 otherwise.
55565560
double dfReplacementVal = dfNoDataValue;
5557-
if (dt == GDT_Byte)
5561+
if (dt == GDT_UInt8)
55585562
{
55595563
if (GDALClampDoubleValue(dfNoDataValue,
55605564
cpl::NumericLimits<uint8_t>::lowest(),

swig/include/gdal.i

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,18 @@ typedef int GDALRIOResampleAlg;
129129
%rename (DataType) GDALDataType;
130130
typedef enum {
131131
GDT_Unknown = 0,
132-
/*! Eight bit unsigned integer */ GDT_Byte = 1,
133-
/*! Eight bit signed integer */ GDT_Int8 = 14,
134-
/*! Sixteen bit unsigned integer */ GDT_UInt16 = 2,
135-
/*! Sixteen bit signed integer */ GDT_Int16 = 3,
136-
/*! Thirty two bit unsigned integer */ GDT_UInt32 = 4,
137-
/*! Thirty two bit signed integer */ GDT_Int32 = 5,
138-
/*! 64 bit unsigned integer */ GDT_UInt64 = 12,
139-
/*! 64 bit signed integer */ GDT_Int64 = 13,
140-
/*! Sixteen bit floating point */ GDT_Float16 = 15,
141-
/*! Thirty two bit floating point */ GDT_Float32 = 6,
142-
/*! Sixty four bit floating point */ GDT_Float64 = 7,
132+
/*! 8-bit unsigned integer */ GDT_Byte = 1,
133+
/*! 8-bit unsigned integer */ GDT_UInt8 = 1,
134+
/*! 8-bit signed integer */ GDT_Int8 = 14,
135+
/*! 16-bit unsigned integer */ GDT_UInt16 = 2,
136+
/*! 16-bit signed integer */ GDT_Int16 = 3,
137+
/*! 32-bit unsigned integer */ GDT_UInt32 = 4,
138+
/*! 32-bit signed integer */ GDT_Int32 = 5,
139+
/*! 64-bit unsigned integer */ GDT_UInt64 = 12,
140+
/*! 64-bit signed integer */ GDT_Int64 = 13,
141+
/*! 16-bit floating point */ GDT_Float16 = 15,
142+
/*! 32-bit floating point */ GDT_Float32 = 6,
143+
/*! 64-bit floating point */ GDT_Float64 = 7,
143144
/*! Complex Int16 */ GDT_CInt16 = 8,
144145
/*! Complex Int32 */ GDT_CInt32 = 9,
145146
/*! Complex Float16 */ GDT_CFloat16 = 16,

swig/include/gdalconst.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
// GDALDataType
3737
%constant GDT_Unknown = GDT_Unknown;
3838
%constant GDT_Byte = GDT_Byte;
39+
%constant GDT_UInt8 = GDT_UInt8;
3940
%constant GDT_Int8 = GDT_Int8;
4041
%constant GDT_UInt16 = GDT_UInt16;
4142
%constant GDT_Int16 = GDT_Int16;

0 commit comments

Comments
 (0)