Skip to content

Commit

Permalink
Изменен способ парсинга настроек процессоров
Browse files Browse the repository at this point in the history
Добавлено форматирование времени в процессор таймер
Добавлено наложение маски в процессор изображение
Добавлена возможность наложения глитча
Рефакторинг для наложения глитчей
  • Loading branch information
mo3golom committed Jan 1, 2022
1 parent 61b49d1 commit bf42cf8
Show file tree
Hide file tree
Showing 31 changed files with 501 additions and 1,174 deletions.
16 changes: 12 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package main

import (
WonderAnimator "github.com/mo3golom/wonder-animator"
"log"
"time"

"github.com/mitchellh/mapstructure"
WonderAnimator "github.com/mo3golom/wonder-animator"

"encoding/json"
"fmt"

Expand All @@ -14,17 +16,23 @@ import (
func main() {
start := time.Now()

var inputObjectMap map[string]interface{}
var inputObject WonderAnimator.InputObject
decodeErr := json.Unmarshal(

[]byte(`{"duration":5,"width":176,"height":176,"FPS":12,"BackgroundColor":"#b399f1","blocks":[{"type":{"id":"text","options":{"text":"test","width":"64","height":"64","fillColor":"#DA4828","strokeColor":"#EDED49","strokeWidth":"3","padding":"10","radius":"10","margin":"4","lineWidth":"28"}},"effects":[{"id":"move","options":{"distance": "100", "direction": "left"}}],"startAt":0,"duration":5,"position":{"x":50,"y":50},"opacity":1,"rotate":0,"scale":1,"rotatePoint":"right-bottom"}]}`),
&inputObject,
[]byte(`{"duration":5,"width":250,"height":249,"FPS":60,"BackgroundColor":"#b399f1","blocks":[{"processor":{"id":"image","options":{"text":"ехал грека","mask":{"mask":"mask.png","src":"unnamed.jpg","x":50,"y":50},"data":"vinyl.jpg","format":"15:04:05.00","width":250,"height":249,"fillColor":"#DA4828","strokeColor":"#EDED49","strokeWidth":3,"padding":10,"radius":10,"margin":4,"lineWidth":28}},"startAt":0,"duration":5,"position":{"x":0,"y":0},"opacity":1,"rotate":0,"scale":1,"rotatePoint":"right-bottom"}]}`),
&inputObjectMap,
)

if decodeErr != nil {
panic(decodeErr)
}

decodeErr = mapstructure.Decode(inputObjectMap, &inputObject)

if decodeErr != nil {
panic(decodeErr)
}

_, err := WonderAnimator.WonderAnimator().Generate(inputObject, "webp").SaveInFile("test.webp")

PrintMemUsage()
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ require (
github.com/disintegration/imaging v1.6.2
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/llgcode/draw2d v0.0.0-20210904075650-80aa0a2a901d
github.com/mo3golom/wonder-effects v1.1.1
github.com/mitchellh/mapstructure v1.4.3
github.com/mo3golom/wonder-effects v1.2.1
github.com/mo3golom/wonder-glitch v1.0.0
github.com/sizeofint/webpanimation v0.0.0-20210809145948-1d2b32119882
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8
)
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ github.com/llgcode/draw2d v0.0.0-20210904075650-80aa0a2a901d h1:4/ycg+VrwjGurTqi
github.com/llgcode/draw2d v0.0.0-20210904075650-80aa0a2a901d/go.mod h1:mVa0dA29Db2S4LVqDYLlsePDzRJLDfdhVZiI15uY0FA=
github.com/llgcode/ps v0.0.0-20150911083025-f1443b32eedb h1:61ndUreYSlWFeCY44JxDDkngVoI7/1MVhEl98Nm0KOk=
github.com/llgcode/ps v0.0.0-20150911083025-f1443b32eedb/go.mod h1:1l8ky+Ew27CMX29uG+a2hNOKpeNYEQjjtiALiBlFQbY=
github.com/mo3golom/wonder-effects v1.1.0 h1:FpcYcug8dc3NIajOTEInvCWND6Pi2+eD/XZkf3DobpQ=
github.com/mo3golom/wonder-effects v1.1.0/go.mod h1:9mGOpU2EUO1AuOSbjGr6deaquttuiPRWJQCe2zHIIbo=
github.com/mo3golom/wonder-effects v1.1.1 h1:PDhtUoxRpnHdkk7ns7Kb3A4jdUijDDEJ2HunwBziwCo=
github.com/mo3golom/wonder-effects v1.1.1/go.mod h1:9mGOpU2EUO1AuOSbjGr6deaquttuiPRWJQCe2zHIIbo=
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mo3golom/wonder-effects v1.2.1 h1:BklpO9neRYevtAhKYP3osLsFxcFV6CmcrAut5VwUzyA=
github.com/mo3golom/wonder-effects v1.2.1/go.mod h1:WYnSgpyp6GKgTu6cZKP4l+O/qBhg2FdZ3UEapwpCi9U=
github.com/mo3golom/wonder-glitch v1.0.0 h1:epi/oFooWE0XWViW0wNrU8sZQezJ+0zNmUJVVuKoaM8=
github.com/mo3golom/wonder-glitch v1.0.0/go.mod h1:XpE2AF5yT0tX30AuQXuHeN9Ne0rmsp+UhRaV2COAiVo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sizeofint/webpanimation v0.0.0-20210809145948-1d2b32119882 h1:A7o8tOERTtpD/poS+2VoassCjXpjHn916luXbf5QKD0=
Expand Down
14 changes: 7 additions & 7 deletions inputObject.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const (
)

type InputObject struct {
Width int `json:"width"`
Height int `json:"height"`
Duration float32 `json:"duration"`
Blocks *[]dto.Block `json:"blocks"`
FPS *int `json:"fps"`
BackgroundImage *string `json:"backgroundImage"`
BackgroundColor *string `json:"backgroundColor"`
Width int `json:"width" mapstructure:"width"`
Height int `json:"height" mapstructure:"height"`
Duration float32 `json:"duration" mapstructure:"duration"`
Blocks *[]dto.Block `json:"blocks" mapstructure:"blocks"`
FPS *int `json:"fps" mapstructure:"fps"`
BackgroundImage *string `json:"backgroundImage" mapstructure:"backgroundImage"`
BackgroundColor *string `json:"backgroundColor" mapstructure:"backgroundColor"`
}

func (i *InputObject) GetFPS() int {
Expand Down
21 changes: 12 additions & 9 deletions internal/dto/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package dto

import (
"github.com/mo3golom/wonder-effects/wonderEffectDTO"
"github.com/mo3golom/wonder-glitch/wonderGlitchDTO"
)

type Block struct {
Type *Processor `json:"type"`
StartAt float32 `json:"startAt"`
Duration float32 `json:"duration"`
Position *Position `json:"position"`
Effects *[]wonderEffectDTO.Effect `json:"effects"`
Opacity float32 `json:"opacity"`
Rotate float64 `json:"rotate"`
RotatePoint string `json:"rotatePoint"`
Scale float64 `json:"scale"`
Type *Processor `json:"processor" mapstructure:"processor"`
StartAt float32 `json:"startAt" mapstructure:"startAt"`
Duration float32 `json:"duration" mapstructure:"duration"`
Position *Position `json:"position" mapstructure:"position"`
Effects []wonderEffectDTO.Effect `json:"effects" mapstructure:"effects"`
Glitches []wonderGlitchDTO.InputEffect `json:"glitches" mapstructure:"glitches"`
GlitchFactor float64 `json:"glitchFactor" mapstructure:"glitchFactor"`
Opacity float32 `json:"opacity" mapstructure:"opacity"`
Rotate float64 `json:"rotate" mapstructure:"rotate"`
RotatePoint string `json:"rotatePoint" mapstructure:"rotatePoint"`
Scale float64 `json:"scale" mapstructure:"scale"`
}
40 changes: 13 additions & 27 deletions internal/dto/enum/processorTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,27 @@ package enum
import (
"github.com/mo3golom/wonder-animator/internal/service/processor/processorType"
"github.com/mo3golom/wonder-animator/pkg/draw2dExtend"
WonderEffects "github.com/mo3golom/wonder-effects"
)

type ProcessorType struct {
id string
name string
processor processorType.ProcessorInterface
Id string
Name string
Processor processorType.ProcessorInterface
}

func (b *ProcessorType) Id() string {
return b.id
}

func (b *ProcessorType) Name() string {
return b.name
}

func (b *ProcessorType) Processor() processorType.ProcessorInterface {
return b.processor
}

func GetProcessorTypes(builder *draw2dExtend.DrawBuilder, effectHandlerBus *WonderEffects.Handler) []ProcessorType {
func GetProcessorTypes(builder *draw2dExtend.DrawBuilder) []ProcessorType {
// Абстракный процессор, который содержит все что нужно для работы остальных процессоров
mainProcessor := &processorType.ProcessorStruct{}
mainProcessor.
SetDrawBuilder(builder).
SetEffectHandlerBus(effectHandlerBus)
mainProcessor.DrawBuilder = builder

textProcessor := &processorType.TextProcessor{ProcessorStruct: mainProcessor}

return []ProcessorType{
{id: "text", name: "Текст", processor: &processorType.TextProcessor{ProcessorStruct: mainProcessor}},
{id: "multiText", name: "Мульти текст", processor: &processorType.MultiTextProcessor{ProcessorStruct: mainProcessor}},
{id: "timer", name: "Таймер", processor: &processorType.TimerProcessor{ProcessorStruct: mainProcessor}},
{id: "rectangle", name: "Прямоугольник", processor: &processorType.RectangleProcessor{ProcessorStruct: mainProcessor}},
{id: "circle", name: "Круг", processor: &processorType.CircleProcessor{ProcessorStruct: mainProcessor}},
{id: "triangle", name: "Треугольник", processor: &processorType.TriangleProcessor{ProcessorStruct: mainProcessor}},
{id: "image", name: "Изображение", processor: &processorType.ImageProcessor{ProcessorStruct: mainProcessor}},
{Id: "text", Name: "Текст", Processor: textProcessor},
{Id: "timer", Name: "Таймер", Processor: &processorType.TimerProcessor{TextProcessor: textProcessor}},
{Id: "rectangle", Name: "Прямоугольник", Processor: &processorType.RectangleProcessor{ProcessorStruct: mainProcessor}},
{Id: "circle", Name: "Круг", Processor: &processorType.CircleProcessor{ProcessorStruct: mainProcessor}},
{Id: "triangle", Name: "Треугольник", Processor: &processorType.TriangleProcessor{ProcessorStruct: mainProcessor}},
{Id: "image", Name: "Изображение", Processor: &processorType.ImageProcessor{ProcessorStruct: mainProcessor}},
}
}
4 changes: 2 additions & 2 deletions internal/dto/position.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dto

type Position struct {
X float64 `json:"x"`
Y float64 `json:"y"`
X float64 `json:"x" mapstructure:"x"`
Y float64 `json:"y" mapstructure:"y"`
}
4 changes: 2 additions & 2 deletions internal/dto/processor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dto

type Processor struct {
Id string `json:"id"`
Options map[string]string `json:"options"`
Id string `json:"id" mapstructure:"id"`
Options map[string]interface{} `json:"options" mapstructure:"options"`
}
54 changes: 8 additions & 46 deletions internal/dto/processorOptions/circleOptions.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,17 @@
package processorOptions

import "github.com/mo3golom/wonder-animator/pkg/draw2dExtend"

type CircleOptions struct {
radius float64
strokeWidth float64
fillColor draw2dExtend.ExtendColor
strokeColor draw2dExtend.ExtendColor
Radius float64 `mapstructure:"radius"`
StrokeWidth float64 `mapstructure:"strokeWidth"`
FillColor string `mapstructure:"fillColor"`
StrokeColor string `mapstructure:"strokeColor"`
}

func NewCircleOptions() *CircleOptions {
return &CircleOptions{
radius: 0,
strokeWidth: 0,
fillColor: draw2dExtend.ParseHexColor("#ffffff"),
strokeColor: draw2dExtend.ParseHexColor("#000000"),
Radius: 0,
StrokeWidth: 0,
FillColor: "#ffffff",
StrokeColor: "#000000",
}
}

func (c *CircleOptions) Radius() float64 {
return c.radius
}

func (c *CircleOptions) Diameter() float64 {
return c.radius * 2
}

func (c *CircleOptions) SetRadius(radius float64) {
c.radius = radius
}

func (c *CircleOptions) StrokeWidth() float64 {
return c.strokeWidth
}

func (c *CircleOptions) SetStrokeWidth(strokeWidth float64) {
c.strokeWidth = strokeWidth
}

func (c *CircleOptions) FillColor() draw2dExtend.ExtendColor {
return c.fillColor
}

func (c *CircleOptions) SetFillColor(fillColor string) {
c.fillColor = draw2dExtend.ParseHexColor(fillColor)
}

func (c *CircleOptions) StrokeColor() draw2dExtend.ExtendColor {
return c.strokeColor
}

func (c *CircleOptions) SetStrokeColor(strokeColor string) {
c.strokeColor = draw2dExtend.ParseHexColor(strokeColor)
}
34 changes: 6 additions & 28 deletions internal/dto/processorOptions/imageOptions.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
package processorOptions

type ImageOptions struct {
data string
width, height int
Data string `mapstructure:"data"`
Width int `mapstructure:"width"`
Height int `mapstructure:"height"`
Mask *MaskOptions `mapstructure:"mask"`
}

func NewImageOptions() *ImageOptions {
return &ImageOptions{
width: 0,
height: 0,
Width: 0,
Height: 0,
}
}

func (i *ImageOptions) Data() string {
return i.data
}

func (i *ImageOptions) SetData(data string) {
i.data = data
}

func (i *ImageOptions) Width() int {
return i.width
}

func (i *ImageOptions) SetWidth(width int) {
i.width = width
}

func (i *ImageOptions) Height() int {
return i.height
}

func (i *ImageOptions) SetHeight(height int) {
i.height = height
}
46 changes: 0 additions & 46 deletions internal/dto/processorOptions/multiTextOptions.go

This file was deleted.

Loading

0 comments on commit bf42cf8

Please sign in to comment.