// 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()) } }
// NewTKey returns an imagetile-specific key component based on the components of a tile request. func NewTKey(tile dvid.ChunkPoint3d, plane dvid.DataShape, scale Scaling) storage.TKey { buf := bytes.NewBuffer(plane.Bytes()) buf.WriteByte(byte(scale)) buf.WriteByte(byte(3)) idx := dvid.IndexZYX(tile) buf.Write(idx.Bytes()) return buf.Bytes() }
func (s *Shape) FromShape(shape dvid.DataShape) error { switch { case shape.Equals(dvid.XY): *s = XY case shape.Equals(dvid.XZ): *s = XZ case shape.Equals(dvid.YZ): *s = YZ case shape.Equals(dvid.Vol3d): *s = XYZ default: return fmt.Errorf("No Google BrainMaps shape corresponds to DVID %s shape", shape) } return nil }
// GetTileSpec returns a TileSpec for a given scale and dvid Geometry. func GetTileSpec(scaling Scaling, shape dvid.DataShape) (*TileSpec, error) { ts := new(TileSpec) ts.scaling = scaling switch { case shape.Equals(dvid.XY): ts.plane = XY case shape.Equals(dvid.XZ): ts.plane = XZ case shape.Equals(dvid.YZ): ts.plane = YZ default: return nil, fmt.Errorf("No Google BrainMaps slice orientation corresponding to DVID %s shape", shape) } return ts, nil }