Documentation
¶
Overview ¶
Package dem2hm reads normalized heightmaps produced by the dem2hm converter.
Index ¶
Examples ¶
Constants ¶
const ( // NoDataPixel is the value reserved for a pixel with no elevation data. NoDataPixel int32 = -2147483648 // ErrInvalidByteOrder indicates that the file does not start with the // version 1 magic value in little-endian byte order. ErrInvalidByteOrder = Error("invalid heightmap byte order or format") // ErrInvalidHeader indicates that the 12-byte heightmap header is incomplete. ErrInvalidHeader = Error("invalid heightmap header") // ErrInvalidDimensions indicates that the height or width is not positive, // or that the resulting payload size cannot be represented safely. ErrInvalidDimensions = Error("invalid heightmap dimensions") // ErrInvalidGzip indicates that the payload is not a valid gzip stream. ErrInvalidGzip = Error("invalid heightmap gzip stream") // ErrInvalidPayload indicates that the decompressed pixel payload does not // conform to the version 1 heightmap format. ErrInvalidPayload = Error("invalid heightmap payload") // ErrMultipleGzipMembers indicates that a second gzip member follows the // required payload member. ErrMultipleGzipMembers = Error("multiple gzip members") // ErrTrailingData indicates that data follows the single gzip member. ErrTrailingData = Error("trailing heightmap data") // ErrOutOfBounds indicates that a requested pixel or row is outside the map. ErrOutOfBounds = Error("heightmap coordinates out of bounds") // ErrLimitExceeded indicates that the heightmap exceeds a configured limit. ErrLimitExceeded = Error("heightmap resource limit exceeded") // ErrCanceled indicates that reading was canceled or its deadline expired. ErrCanceled = Error("heightmap read canceled") )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HeightMap ¶
HeightMap is a normalized raster stored in top-to-bottom row-major order.
func Read ¶
Read reads a version 1 heightmap from r without an application-defined resource limit or cancellation context.
Example ¶
package main
import (
"bytes"
_ "embed"
"fmt"
"github.com/maloquacious/dem2hm"
)
//go:embed testdata/example.hmz
var exampleHMZ []byte
func main() {
heightmap, err := dem2hm.Read(bytes.NewReader(exampleHMZ))
if err != nil {
fmt.Println("error:", err)
return
}
emptyPixels := 0
for _, pixel := range heightmap.Data {
if pixel == dem2hm.NoDataPixel {
emptyPixels++
}
}
fmt.Println("height:", heightmap.Height)
fmt.Println("width:", heightmap.Width)
fmt.Println("empty pixels:", emptyPixels)
}
Output: height: 2 width: 3 empty pixels: 2
func ReadWithOptions ¶
ReadWithOptions reads a version 1 heightmap from r using options.
func (*HeightMap) At ¶
At returns the pixel at column x and row y. It panics if the coordinates are outside the heightmap.
type Options ¶
type Options struct {
// Context is checked while reading and decoding. A nil Context is treated
// as context.Background(). Cancellation cannot interrupt an underlying
// io.Reader blocked in Read unless that reader also honors cancellation,
// deadlines, or closure.
Context context.Context
// MaxPixels is the largest decoded heightmap to accept. Zero disables the
// additional limit; format and address-space limits still apply.
MaxPixels uint64
}
Options controls resource use while reading a heightmap.