diff --git a/godal.go b/godal.go index b205e54..657782b 100644 --- a/godal.go +++ b/godal.go @@ -45,6 +45,9 @@ const ( Byte = DataType(C.GDT_Byte) //UInt16 DataType UInt16 = DataType(C.GDT_UInt16) + //Int8 DataType (GDAL>=3.7.0) + // [RFC 87]: https://gdal.org/development/rfc/rfc87_signed_int8.html + Int8 = DataType(C.GDT_Int8) //Int16 DataType Int16 = DataType(C.GDT_Int16) //UInt32 DataType @@ -89,7 +92,7 @@ func (dtype DataType) String() string { // Size retruns the number of bytes needed for one instance of DataType func (dtype DataType) Size() int { switch dtype { - case Byte: + case Byte, Int8: return 1 case Int16, UInt16: return 2 @@ -1780,6 +1783,8 @@ func bufferType(buffer interface{}) DataType { switch buffer.(type) { case []byte: return Byte + case []int8: + return Int8 case []int16: return Int16 case []uint16: @@ -1813,6 +1818,9 @@ func cBuffer(buffer interface{}, minsize int) unsafe.Pointer { case []byte: sizecheck(len(buf)) return unsafe.Pointer(&buf[0]) + case []int8: + sizecheck(len(buf)) + return unsafe.Pointer(&buf[0]) case []int16: sizecheck(len(buf)) return unsafe.Pointer(&buf[0]) diff --git a/godal.h b/godal.h index f7d5a79..c019678 100644 --- a/godal.h +++ b/godal.h @@ -27,6 +27,12 @@ #error "this code is only compatible with gdal version >= 3.0" #endif +#if GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(3, 7, 0) +typedef enum { + /*! 8-bit signed integer (GDAL >= 3.7) */ GDT_Int8 = 14 +} FutureGDALDataType; +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/godal_test.go b/godal_test.go index 61e5973..d52af08 100644 --- a/godal_test.go +++ b/godal_test.go @@ -77,6 +77,12 @@ func TestCBuffer(t *testing.T) { assert.Equal(t, 1, bufferType(buf).Size()) assert.Panics(t, func() { cBuffer(buf, 101) }) + buf = make([]int8, 100) + _ = cBuffer(buf, 100) + assert.Equal(t, Int8, bufferType(buf)) + assert.Equal(t, 1, bufferType(buf).Size()) + assert.Panics(t, func() { cBuffer(buf, 101) }) + buf = make([]int16, 100) _ = cBuffer(buf, 100) assert.Equal(t, Int16, bufferType(buf)) @@ -223,6 +229,19 @@ func TestCreate(t *testing.T) { if st1.Size() == st2.Size() { t.Errorf("sizes: %d/%d", st1.Size(), st2.Size()) } + + ehc = eh() + tmpname3 := tempfile() + defer os.Remove(tmpname3) + ds, err = Create(GTiff, tmpname3, 1, Int8, 20, 20, ErrLogger(ehc.ErrorHandler)) + if CheckMinVersion(3, 7, 0) { + assert.NoError(t, err) + + err = ds.Close(ErrLogger(ehc.ErrorHandler)) + assert.NoError(t, err) + } else { + assert.Error(t, err, "godal.Int8 is not supported with GDAL<3.7.0, but godal.Create did not return an error") + } } func TestRegisterDrivers(t *testing.T) {