Beispiel #1
0
// getBlankTileData returns zero 2d tile data with a given scaling and format.
func (d *Data) getBlankTileImage(uuid dvid.UUID, shape dvid.DataShape, scaling Scaling) (image.Image, error) {
	levelSpec, found := d.Levels[scaling]
	if !found {
		return nil, fmt.Errorf("Could not extract tiles for unspecified scale level %d", scaling)
	}
	tileW, tileH, err := shape.GetSize2D(levelSpec.TileSize)
	if err != nil {
		return nil, err
	}
	source, err := datastore.GetDataByUUID(uuid, d.Source)
	if err != nil {
		return nil, err
	}
	src, ok := source.(*imageblk.Data)
	if !ok {
		return nil, fmt.Errorf("Data instance %q for uuid %q is not imageblk.Data", d.Source, uuid)
	}
	bytesPerVoxel := src.Values.BytesPerElement()
	switch bytesPerVoxel {
	case 1, 2, 4, 8:
		numBytes := tileW * tileH * bytesPerVoxel
		data := make([]byte, numBytes, numBytes)
		return dvid.GoImageFromData(data, int(tileW), int(tileH))
	default:
		return nil, fmt.Errorf("Cannot construct blank tile for data %q with %d bytes/voxel",
			d.Source, src.Values.BytesPerElement())
	}
}
Beispiel #2
0
// getBlankTileData returns a background 2d tile data
func (d *Data) getBlankTileImage(tile *GoogleSubvolGeom) (image.Image, error) {
	if tile == nil {
		return nil, fmt.Errorf("Can't get blank tile for unknown tile spec")
	}
	if d.Scales == nil || len(d.Scales) <= int(tile.gi) {
		return nil, fmt.Errorf("Scaled volumes for %d not suitable for tile spec", d.DataName())
	}

	// Generate the blank image
	numBytes := tile.sizeWant[0] * tile.sizeWant[1] * tile.bytesPerVoxel
	data := make([]byte, numBytes, numBytes)
	return dvid.GoImageFromData(data, int(tile.sizeWant[0]), int(tile.sizeWant[1]))
}