Skip to content

Commit

Permalink
change preset
Browse files Browse the repository at this point in the history
  • Loading branch information
Anshul Goyal committed May 17, 2020
1 parent 5e1828c commit 36909ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
32 changes: 16 additions & 16 deletions decode.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package imageflow

// Decode is used to create a decode node in graph
type Decode struct {
type decode struct {
IoID int `json:"io_id"`
}

// toStep is used to convert a Decode to step
func (decode Decode) toStep() map[string]interface{} {
func (decode decode) toStep() map[string]interface{} {
decodeMap := make(map[string]interface{})
decodeMap["decode"] = decode
return decodeMap
}

// Preset is a interface for encoder used to convert to image
type Preset interface {
type presetInterface interface {
toPreset() interface{}
}

// Encode is used to convert to a image
type Encode struct {
type encode struct {
IoID int `json:"io_id"`
Preset interface{} `json:"preset"`
}

// toStep is used to convert a Encode to step
func (encode Encode) toStep() interface{} {
func (encode encode) toStep() interface{} {
encodeMap := make(map[string]interface{})
encodeMap["encode"] = encode
return encodeMap
Expand All @@ -38,7 +38,7 @@ type MozJPEG struct {

// toPreset is used to convert the MozJPG to a preset
func (preset MozJPEG) toPreset() interface{} {
presetMap := make(map[string]Preset)
presetMap := make(map[string]presetInterface)
if preset.Quality == 0 {
preset.Quality = 100
}
Expand All @@ -61,7 +61,7 @@ type LosslessPNG struct {

// toPreset is used to LosslessPNG to Preset
func (preset LosslessPNG) toPreset() interface{} {
presetMap := make(map[string]Preset)
presetMap := make(map[string]presetInterface)
presetMap["lodepng"] = preset
return presetMap
}
Expand All @@ -76,7 +76,7 @@ type LossyPNG struct {

// toPreset is used to convert LossPNG to preset
func (preset LossyPNG) toPreset() interface{} {
presetMap := make(map[string]Preset)
presetMap := make(map[string]presetInterface)
presetMap["pngquant"] = preset
return presetMap
}
Expand All @@ -91,7 +91,7 @@ func (preset WebP) toPreset() interface{} {
if preset.Quality == 0 {
preset.Quality = 100
}
presetMap := make(map[string]Preset)
presetMap := make(map[string]presetInterface)
presetMap["webplossy"] = preset
return presetMap
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func (step Constrain) toStep() interface{} {
if step.CanvasColor != nil {
step.CanvasColor = step.CanvasColor.(Color).toColor()
}
stepMap := make(map[string]Step)
stepMap := make(map[string]stepInterface)
stepMap["constrain"] = step
return stepMap
}
Expand All @@ -223,7 +223,7 @@ type Region struct {
// toStep create a step from Region
func (region Region) toStep() interface{} {
region.BackgroundColor = region.BackgroundColor.(Color).toColor()
stepMap := make(map[string]Step)
stepMap := make(map[string]stepInterface)
stepMap["region"] = region
return stepMap
}
Expand All @@ -241,7 +241,7 @@ type RegionPercentage struct {
// toStep create a step from Region
func (region RegionPercentage) toStep() interface{} {
region.BackgroundColor = region.BackgroundColor.(Color).toColor()
stepMap := make(map[string]Step)
stepMap := make(map[string]stepInterface)
stepMap["region_percent"] = region
return stepMap
}
Expand All @@ -256,7 +256,7 @@ type cropWhitespace struct {

// toStep create a step from Region
func (region cropWhitespace) toStep() interface{} {
stepMap := make(map[string]Step)
stepMap := make(map[string]stepInterface)
stepMap["crop_whitespace"] = region
return stepMap
}
Expand Down Expand Up @@ -312,7 +312,7 @@ type fillRect struct {

// toStep create a step from fillRect
func (region fillRect) toStep() interface{} {
stepMap := make(map[string]Step)
stepMap := make(map[string]stepInterface)
region.Color = region.Color.(Color).toColor()
stepMap["fill_rect"] = region
return stepMap
Expand All @@ -329,7 +329,7 @@ type ExpandCanvas struct {

// toStep create a step from fillRect
func (region ExpandCanvas) toStep() interface{} {
stepMap := make(map[string]Step)
stepMap := make(map[string]stepInterface)
region.Color = region.Color.(Color).toColor()
stepMap["expand_canvas"] = region
return stepMap
Expand Down Expand Up @@ -390,7 +390,7 @@ func (watermark watermark) toStep() interface{} {
if watermark.FitBox != nil {
watermark.FitBox = watermark.FitBox.(FitBox).toFitBox()
}
stepMap := make(map[string]Step)
stepMap := make(map[string]stepInterface)
if watermark.Gravity != nil {
watermark.Gravity = watermark.Gravity.(ConstraintGravity).toGravity()
}
Expand Down
10 changes: 5 additions & 5 deletions imageflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Steps struct {
func (steps *Steps) Decode(task ioOperation) *Steps {
steps.inputs = append(steps.inputs, task)
task.setIo(uint(steps.ioID))
steps.vertex = append(steps.vertex, Decode{
steps.vertex = append(steps.vertex, decode{
IoID: steps.ioID,
}.toStep())
steps.ioID++
Expand Down Expand Up @@ -61,10 +61,10 @@ func constrainWithinMap(w interface{}, h interface{}) map[string]interface{} {
}

// Encode is used to convert the image
func (steps *Steps) Encode(task ioOperation, preset Preset) *Steps {
func (steps *Steps) Encode(task ioOperation, preset presetInterface) *Steps {
task.setIo(uint(steps.ioID))
steps.outputs = append(steps.outputs, task)
steps.input(Encode{
steps.input(encode{
IoID: steps.ioID,
Preset: preset.toPreset(),
}.toStep())
Expand Down Expand Up @@ -113,7 +113,7 @@ func (steps *Steps) input(step interface{}) {
steps.last = uint(len(steps.vertex) - 1)
}

func (steps *Steps) canvas(f func(*Steps), step Step) *Steps {
func (steps *Steps) canvas(f func(*Steps), step stepInterface) *Steps {
last := steps.last
f(steps)
steps.vertex = append(steps.vertex, step.toStep())
Expand Down Expand Up @@ -322,7 +322,7 @@ func (steps *Steps) colorFilterSRGBValue(name string, value float32) *Steps {
}

// Step specify different nodes
type Step interface {
type stepInterface interface {
toStep() interface{}
}

Expand Down

0 comments on commit 36909ab

Please sign in to comment.