Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add int8 (since gdal 3.7.0) #127

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion godal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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])
Expand Down
6 changes: 6 additions & 0 deletions godal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions godal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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) {
Expand Down
Loading