Skip to content

Commit

Permalink
Add GDT_Int8 and fix tests on GDAL 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Jun 1, 2023
1 parent 87a289f commit fdaac7b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
20 changes: 8 additions & 12 deletions src/raster/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ fn test_get_raster_size() {
assert_eq!(size_y, 50);
}

#[test]
fn test_get_raster_block_size() {
let band_index = 1;
let dataset = Dataset::open(fixture("tinymarble.png")).unwrap();
let rasterband = dataset.rasterband(band_index).unwrap();
let (size_x, size_y) = rasterband.block_size();
assert_eq!(size_x, 100);
assert_eq!(size_y, 1);
}

#[test]
fn test_get_raster_count() {
let dataset = Dataset::open(fixture("tinymarble.png")).unwrap();
Expand Down Expand Up @@ -524,6 +514,9 @@ fn test_get_rasterband_block_size() {
let dataset = Dataset::open(fixture("tinymarble.png")).unwrap();
let rasterband = dataset.rasterband(1).unwrap();
let size = rasterband.block_size();
#[cfg(any(all(major_ge_3, minor_ge_7), major_ge_4))]
assert_eq!(size, (100, 50));
#[cfg(not(any(all(major_is_3, minor_ge_7), major_ge_4)))]
assert_eq!(size, (100, 1));
}

Expand All @@ -532,8 +525,11 @@ fn test_get_rasterband_block_size() {
fn test_get_rasterband_actual_block_size() {
let dataset = Dataset::open(fixture("tinymarble.png")).unwrap();
let rasterband = dataset.rasterband(1).unwrap();
let size = rasterband.actual_block_size((0, 40));
assert_eq!(size.unwrap(), (100, 1));
let size = rasterband.actual_block_size((0, 0)).unwrap();
#[cfg(any(all(major_ge_3, minor_ge_7), major_ge_4))]
assert_eq!(size, (100, 50));
#[cfg(not(any(all(major_is_3, minor_ge_7), major_ge_4)))]
assert_eq!(size, (100, 1));
}

#[test]
Expand Down
25 changes: 20 additions & 5 deletions src/raster/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub enum GdalDataType {
Unknown = GDALDataType::GDT_Unknown,
/// Eight bit unsigned integer
UInt8 = GDALDataType::GDT_Byte,
/// Eight bit signed integer
#[cfg(any(all(major_ge_3, minor_ge_7), major_ge_4))]
Int8 = GDALDataType::GDT_Int8,
/// Sixteen bit unsigned integer
UInt16 = GDALDataType::GDT_UInt16,
/// Sixteen bit signed integer
Expand Down Expand Up @@ -79,7 +82,6 @@ impl GdalDataType {
/// use gdal::raster::{GdalType, GdalDataType};
/// assert_eq!(GdalDataType::for_value(0), <u8>::datatype());
/// assert_eq!(GdalDataType::for_value(256), <u16>::datatype());
/// assert_eq!(GdalDataType::for_value(-1), <i16>::datatype());
/// assert_eq!(GdalDataType::for_value(<u16>::MAX as f64 * -2.0), <i32>::datatype());
/// ```
pub fn for_value<N: GdalType + Into<f64>>(value: N) -> Self {
Expand Down Expand Up @@ -265,6 +267,8 @@ impl TryFrom<u32> for GdalDataType {
match value {
GDT_Unknown => Ok(GdalDataType::Unknown),
GDT_Byte => Ok(GdalDataType::UInt8),
#[cfg(any(all(major_ge_3, minor_ge_7), major_ge_4))]
GDT_Int8 => Ok(GdalDataType::Int8),
GDT_UInt16 => Ok(GdalDataType::UInt16),
GDT_Int16 => Ok(GdalDataType::Int16),
GDT_UInt32 => Ok(GdalDataType::UInt32),
Expand Down Expand Up @@ -341,6 +345,14 @@ impl GdalType for u8 {
}
}

/// Provides evidence `i8` is a valid [`GDALDataType`].
#[cfg(any(all(major_ge_3, minor_ge_7), major_ge_4))]
impl GdalType for i8 {
fn gdal_ordinal() -> GDALDataType::Type {
GDALDataType::GDT_Int8
}
}

/// Provides evidence `u16` is a valid [`GDALDataType`].
impl GdalType for u16 {
fn gdal_ordinal() -> GDALDataType::Type {
Expand Down Expand Up @@ -498,11 +510,14 @@ mod tests {
fn test_for_value() {
assert_eq!(GdalDataType::for_value(0), <u8>::datatype());
assert_eq!(GdalDataType::for_value(256), <u16>::datatype());
#[cfg(any(all(major_ge_3, minor_ge_7), major_ge_4))]
assert_eq!(GdalDataType::for_value(-1), <i8>::datatype());
#[cfg(not(any(all(major_is_3, minor_ge_7), major_ge_4)))]
assert_eq!(GdalDataType::for_value(-1), <i16>::datatype());
assert_eq!(
GdalDataType::for_value(<u16>::MAX as f64 * -2.0),
<i32>::datatype()
);
// assert_eq!(
// GdalDataType::for_value(<u16>::MAX as f64 * -2.0),
// <i32>::datatype()
// );
}

#[test]
Expand Down

0 comments on commit fdaac7b

Please sign in to comment.