TIFF, BigTIFF and GeoTIFF reading in MoonBit, as geotiff.js 3.0.5 reads them: IFDs, geo tags, blocks decoded into windows
moon add t-ujiie-g/tiff/// The first sample of the first image of an uncompressed, LZW or PackBits TIFF held whole in `file`.
fn first_band(file : Bytes) -> FixedArray[Byte] raise @tiff.TiffError {
let (images, little) = @tiff.read_tiff(file[:])
let image = images[0]
let window = @tiff.Window::new(image, little, 0, 0, image.width, image.height, [0], 0.0)
for i in 0..<(image.across() * image.down()) {
let start = image.offsets[i].to_int()
let end = start + image.counts[i].to_int()
window.block(i, file[start:end], false)
}
window.bands[0]
}pub(all) suberror TiffError {
Invalid(Int, String)
Truncated(Double)
}pub struct Image {
width : Int
height : Int
tiled : Bool
block_width : Int
block_height : Int
samples : Int
bits : Array[Int]
formats : Array[Int]
planar : Int
compression : Int
predictor : Int
photometric : Int
subfile : Int
old_subfile : Int
offsets : Array[Double]
counts : Array[Double]
pixel_scale : Array[Double]
tiepoint : Array[Double]
transform : Array[Double]
epsg : Int
raster_type : Int
nodata : String?
jpeg_tables : Bytes?
}fn packbits(data : BytesView, max : Int) -> FixedArray[Byte]fn unpack_bits(b : FixedArray[Byte], bits : Int, width : Int, rows : Int, count : Int) -> FixedArray[Byte] raise TiffErrorfn unpredict(b : FixedArray[Byte], predictor : Int, width : Int, height : Int, stride : Int, bytes : Int, little : Bool) -> Unit raise TiffErrorInstall
Download zipTIFF, BigTIFF and GeoTIFF reading in MoonBit, as geotiff.js 3.0.5 reads them: IFDs, geo tags, blocks decoded into windows