示例#1
0
// Returns function that stores a tile as an optionally compressed PNG image.
func (d *Data) putTileFunc(versionID dvid.VersionID) (outFunc, error) {
	imstore, err := storage.ImmutableStore()
	if err != nil {
		return nil, fmt.Errorf("Cannot open immutable store: %v\n", err)
	}
	ctx := datastore.NewVersionedCtx(d, versionID)

	return func(index *IndexTile, tile *dvid.Image) error {
		var err error
		var data []byte

		switch d.Encoding {
		case LZ4:
			compression, err := dvid.NewCompression(dvid.LZ4, dvid.DefaultCompression)
			if err != nil {
				return err
			}
			data, err = tile.Serialize(compression, d.Checksum())
		case PNG:
			data, err = tile.GetPNG()
		case JPG:
			data, err = tile.GetJPEG(d.Quality)
		}
		if err != nil {
			return err
		}
		return imstore.Put(ctx, index.Bytes(), data)
	}, nil
}
示例#2
0
// getTileData returns 2d tile data straight from storage without decoding.
func (d *Data) getTileData(ctx storage.Context, req tileReq) ([]byte, error) {
	imstore, err := storage.ImmutableStore()
	if err != nil {
		return nil, err
	}

	// Retrieve the tile data from datastore
	data, err := imstore.Get(ctx, req.Bytes())
	if err != nil {
		return nil, fmt.Errorf("Error trying to GET from datastore: %v", err)
	}
	return data, nil
}
示例#3
0
// getTileData returns 2d tile data straight from storage without decoding.
func (d *Data) getTileData(ctx storage.Context, req tileReq) ([]byte, error) {
	if d.Levels == nil {
		return nil, fmt.Errorf("Tiles have not been generated.")
	}
	imstore, err := storage.ImmutableStore()
	if err != nil {
		return nil, err
	}

	// Retrieve the tile data from datastore
	tileIndex := &IndexTile{&req.indexZYX, req.shape, req.scaling}
	data, err := imstore.Get(ctx, tileIndex.Bytes())
	if err != nil {
		return nil, fmt.Errorf("Error trying to GET from datastore: %v", err)
	}
	return data, nil
}
示例#4
0
// PostTile stores a tile.
func (d *Data) PostTile(uuid dvid.UUID, ctx storage.Context, w http.ResponseWriter,
	r *http.Request, parts []string) error {

	tileReq, err := d.parseTileReq(r, parts)
	if err != nil {
		return err
	}

	data, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return err
	}

	imstore, err := storage.ImmutableStore()
	if err != nil {
		return fmt.Errorf("Cannot open immutable store: %v\n", err)
	}
	return imstore.Put(ctx, tileReq.Bytes(), data)
}