// NewData returns a pointer to new tile data with default values. func (dtype *Type) NewDataService(uuid dvid.UUID, id dvid.InstanceID, name dvid.InstanceName, c dvid.Config) (datastore.DataService, error) { // Make sure we have a valid DataService source sourcename, found, err := c.GetString("Source") if err != nil { return nil, err } if !found { return nil, fmt.Errorf("Cannot make imagetile data without valid 'Source' setting.") } // See if we want placeholder imagetile. placeholder, found, err := c.GetBool("Placeholder") if err != nil { return nil, err } // Determine encoding for tile storage and this dictates what kind of compression we use. encoding, found, err := c.GetString("Format") if err != nil { return nil, err } format := PNG if found { switch strings.ToLower(encoding) { case "lz4": format = LZ4 case "png": format = PNG case "jpg": format = JPG default: return nil, fmt.Errorf("Unknown encoding specified: '%s' (should be 'lz4', 'png', or 'jpg'", encoding) } } // Compression is determined by encoding. Inform user if there's a discrepancy. var compression string switch format { case LZ4: compression = "lz4" case PNG: compression = "none" case JPG: compression = "none" } compressConfig, found, err := c.GetString("Compression") if err != nil { return nil, err } if found && strings.ToLower(compressConfig) != compression { return nil, fmt.Errorf("Conflict between specified compression '%s' and format '%s'. Suggest not dictating compression.", compressConfig, encoding) } c.Set("Compression", compression) // Initialize the imagetile data basedata, err := datastore.NewDataService(dtype, uuid, id, name, c) if err != nil { return nil, err } data := &Data{ Data: basedata, Properties: Properties{ Source: dvid.InstanceName(sourcename), Placeholder: placeholder, Encoding: format, }, } return data, nil }