move filters

This commit is contained in:
Celogeek 2023-01-14 16:39:03 +01:00
parent 54c156625c
commit 991e95f02e
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
2 changed files with 33 additions and 23 deletions

View File

@ -0,0 +1,31 @@
package filters
import (
"image"
"image/draw"
"github.com/disintegration/gift"
)
func AutoRotate() *autoRotateFilter {
return &autoRotateFilter{}
}
type autoRotateFilter struct{}
func (p *autoRotateFilter) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
if srcBounds.Dx() > srcBounds.Dy() {
dstBounds = gift.Rotate90().Bounds(srcBounds)
} else {
dstBounds = srcBounds
}
return
}
func (p *autoRotateFilter) Draw(dst draw.Image, src image.Image, options *gift.Options) {
if src.Bounds().Dx() > src.Bounds().Dy() {
gift.Rotate90().Draw(dst, src, options)
} else {
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
}
}

View File

@ -1,9 +1,7 @@
package epub
import (
"image"
"image/draw"
"github.com/celogeek/go-comic-converter/internal/epub/filters"
"github.com/disintegration/gift"
)
@ -12,7 +10,7 @@ func NewGift(options *ImageOptions) *gift.GIFT {
g.SetParallelization(false)
if options.AutoRotate {
g.Add(&autoRotateFilter{})
g.Add(filters.AutoRotate())
}
if options.Contrast != 0 {
g.Add(gift.Contrast(float32(options.Contrast)))
@ -25,22 +23,3 @@ func NewGift(options *ImageOptions) *gift.GIFT {
)
return g
}
type autoRotateFilter struct{}
func (p *autoRotateFilter) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
if srcBounds.Dx() > srcBounds.Dy() {
dstBounds = gift.Rotate90().Bounds(srcBounds)
} else {
dstBounds = srcBounds
}
return
}
func (p *autoRotateFilter) Draw(dst draw.Image, src image.Image, options *gift.Options) {
if src.Bounds().Dx() > src.Bounds().Dy() {
gift.Rotate90().Draw(dst, src, options)
} else {
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
}
}