本文整理汇总了Golang中github.com/janelia-flyem/dvid/dvid.Image.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Image.Get方法的具体用法?Golang Image.Get怎么用?Golang Image.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/janelia-flyem/dvid/dvid.Image
的用法示例。
在下文中一共展示了Image.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getTileImage
// getTileImage returns a 2d tile image or a placeholder, useful for further stitching before
// delivery of a final image.
func (d *Data) getTileImage(ctx storage.Context, req TileReq) (image.Image, error) {
if d.Levels == nil || len(d.Levels) == 0 {
return nil, ErrNoMetadataSet
}
data, err := d.getTileData(ctx, req)
if err != nil {
return nil, err
}
if len(data) == 0 {
if d.Placeholder {
if req.scale < 0 || req.scale >= Scaling(len(d.Levels)) {
return nil, fmt.Errorf("Could not find tile specification at given scale %d", req.scale)
}
message := fmt.Sprintf("%s Tile coord %s @ scale %d", req.plane, req.tile, req.scale)
return dvid.PlaceholderImage(req.plane, d.Levels[req.scale].TileSize, message)
}
return nil, nil // Not found
}
var goImg image.Image
switch d.Encoding {
case LZ4:
var img dvid.Image
err = img.Deserialize(data)
if err != nil {
return nil, err
}
goImg = img.Get()
case PNG:
pngBuffer := bytes.NewBuffer(data)
goImg, err = png.Decode(pngBuffer)
case JPG:
jpgBuffer := bytes.NewBuffer(data)
goImg, err = jpeg.Decode(jpgBuffer)
default:
return nil, fmt.Errorf("Unknown tile encoding: %s", d.Encoding)
}
return goImg, err
}
示例2: GetTile
// GetTile returns a 2d tile image or a placeholder
func (d *Data) GetTile(ctx storage.Context, shape dvid.DataShape, scaling Scaling, index dvid.IndexZYX) (image.Image, error) {
data, err := d.getTileData(ctx, shape, scaling, index)
if err != nil {
return nil, err
}
tileIndex := &IndexTile{&index, shape, scaling}
if data == nil {
if d.Placeholder {
if d.Levels == nil || scaling < 0 || scaling >= Scaling(len(d.Levels)) {
return nil, fmt.Errorf("Could not find tile specification at given scale %d", scaling)
}
message := fmt.Sprintf("%s Tile coord %s @ scale %d", shape, tileIndex, scaling)
return dvid.PlaceholderImage(shape, d.Levels[scaling].TileSize, message)
}
return nil, nil // Not found
}
var goImg image.Image
switch d.Encoding {
case LZ4:
var img dvid.Image
err = img.Deserialize(data)
if err != nil {
return nil, err
}
goImg = img.Get()
case PNG:
pngBuffer := bytes.NewBuffer(data)
goImg, err = png.Decode(pngBuffer)
case JPG:
jpgBuffer := bytes.NewBuffer(data)
goImg, err = jpeg.Decode(jpgBuffer)
default:
return nil, fmt.Errorf("Unknown tile encoding: %s", d.Encoding)
}
return goImg, err
}