move all filters

This commit is contained in:
Celogeek 2023-04-26 23:04:31 +02:00
parent 2b7582e776
commit 721d373a7f
Signed by: celogeek
SSH Key Fingerprint: SHA256:njNJLzoLQdbV9PC6ehcruRb0QnEgxABoCYZ+0+aUIYc
7 changed files with 28 additions and 37 deletions

View File

@ -1,19 +1,19 @@
package epubimage
package epubimagefilters
import (
"image"
epubfilters "github.com/celogeek/go-comic-converter/v2/internal/epub/filters"
epubimage "github.com/celogeek/go-comic-converter/v2/internal/epub/image"
"github.com/disintegration/gift"
)
// create filter to apply to the source
func NewGift(img image.Image, options *Options) *gift.GIFT {
func NewGift(img image.Image, options *epubimage.Options) *gift.GIFT {
g := gift.New()
g.SetParallelization(false)
if options.Crop {
g.Add(epubfilters.AutoCrop(
g.Add(AutoCrop(
img,
options.CropRatioLeft,
options.CropRatioUp,
@ -34,25 +34,26 @@ func NewGift(img image.Image, options *Options) *gift.GIFT {
}
g.Add(
epubfilters.Resize(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
epubfilters.Pixel(),
Resize(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
Pixel(),
)
return g
}
// create filters to cut image into 2 equal pieces
func NewGiftSplitDoublePage(options *Options) []*gift.GIFT {
func NewGiftSplitDoublePage(options *epubimage.Options) []*gift.GIFT {
gifts := make([]*gift.GIFT, 2)
gifts[0] = gift.New(
epubfilters.CropSplitDoublePage(options.Manga),
CropSplitDoublePage(options.Manga),
)
gifts[1] = gift.New(
epubfilters.CropSplitDoublePage(!options.Manga),
CropSplitDoublePage(!options.Manga),
)
for _, g := range gifts {
g.SetParallelization(false)
if options.Contrast != 0 {
g.Add(gift.Contrast(float32(options.Contrast)))
}
@ -61,7 +62,7 @@ func NewGiftSplitDoublePage(options *Options) []*gift.GIFT {
}
g.Add(
epubfilters.Resize(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
Resize(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
)
}

View File

@ -1,4 +1,4 @@
package epubfilters
package epubimagefilters
import (
"image"
@ -7,6 +7,7 @@ import (
"github.com/disintegration/gift"
)
// Lookup for margin and crop
func AutoCrop(img image.Image, cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom int) gift.Filter {
return gift.Crop(
findMarging(img, cutRatioOptions{cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom}),

View File

@ -1,7 +1,4 @@
/*
Create a title with the cover image
*/
package epubfilters
package epubimagefilters
import (
"image"
@ -14,6 +11,7 @@ import (
"golang.org/x/image/font/gofont/gomonobold"
)
// Create a title with the cover image
func CoverTitle(title string) gift.Filter {
return &coverTitle{title}
}

View File

@ -1,9 +1,4 @@
/*
cut a double page in 2 part: left and right.
this will cut in the middle of the page.
*/
package epubfilters
package epubimagefilters
import (
"image"
@ -12,6 +7,8 @@ import (
"github.com/disintegration/gift"
)
// Cut a double page in 2 part: left and right.
// This will cut in the middle of the page.
func CropSplitDoublePage(right bool) gift.Filter {
return &cropSplitDoublePage{right}
}

View File

@ -1,9 +1,4 @@
/*
generate a blank pixel 1x1, if the size of the image is 0x0.
An image 0x0 is not a valid image, and failed to read.
*/
package epubfilters
package epubimagefilters
import (
"image"
@ -13,6 +8,8 @@ import (
"github.com/disintegration/gift"
)
// Generate a blank pixel 1x1, if the size of the image is 0x0.
// An image 0x0 is not a valid image, and failed to read.
func Pixel() gift.Filter {
return &pixel{}
}

View File

@ -1,9 +1,4 @@
/*
Resize image by keeping aspect ratio.
This will reduce or enlarge image to fit into the viewWidth and viewHeight.
*/
package epubfilters
package epubimagefilters
import (
"image"
@ -12,6 +7,8 @@ import (
"github.com/disintegration/gift"
)
// Resize image by keeping aspect ratio.
// This will reduce or enlarge image to fit into the viewWidth and viewHeight.
func Resize(viewWidth, viewHeight int, resampling gift.Resampling) gift.Filter {
return &resizeFilter{
viewWidth, viewHeight, resampling,

View File

@ -14,9 +14,9 @@ import (
"strings"
"sync"
epubfilters "github.com/celogeek/go-comic-converter/v2/internal/epub/filters"
epubimage "github.com/celogeek/go-comic-converter/v2/internal/epub/image"
epubimagedata "github.com/celogeek/go-comic-converter/v2/internal/epub/imagedata"
epubimagefilters "github.com/celogeek/go-comic-converter/v2/internal/epub/imagefilters"
epubprogress "github.com/celogeek/go-comic-converter/v2/internal/epub/progress"
"github.com/disintegration/gift"
_ "golang.org/x/image/webp"
@ -112,7 +112,7 @@ func LoadImages(o *Options) ([]*epubimage.Image, error) {
os.Exit(1)
}
g := epubimage.NewGift(src, o.Image)
g := epubimagefilters.NewGift(src, o.Image)
// Convert image
dst := image.NewGray(g.Bounds(src.Bounds()))
g.Draw(dst, src)
@ -141,7 +141,7 @@ func LoadImages(o *Options) ([]*epubimage.Image, error) {
if (!o.Image.HasCover || img.Id > 0) &&
o.Image.AutoSplitDoublePage &&
src.Bounds().Dx() > src.Bounds().Dy() {
gifts := epubimage.NewGiftSplitDoublePage(o.Image)
gifts := epubimagefilters.NewGiftSplitDoublePage(o.Image)
for i, g := range gifts {
part := i + 1
dst := image.NewGray(g.Bounds(src.Bounds()))
@ -190,7 +190,7 @@ func LoadImages(o *Options) ([]*epubimage.Image, error) {
// create a title page with the cover
func LoadCoverTitleData(img *epubimage.Image, title string, quality int) *epubimagedata.ImageData {
// Create a blur version of the cover
g := gift.New(epubfilters.CoverTitle(title))
g := gift.New(epubimagefilters.CoverTitle(title))
dst := image.NewGray(g.Bounds(img.Raw.Bounds()))
g.Draw(dst, img.Raw)