mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 08:12:36 +02:00
move all filters
This commit is contained in:
parent
2b7582e776
commit
721d373a7f
@ -1,19 +1,19 @@
|
|||||||
package epubimage
|
package epubimagefilters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"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"
|
"github.com/disintegration/gift"
|
||||||
)
|
)
|
||||||
|
|
||||||
// create filter to apply to the source
|
// 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 := gift.New()
|
||||||
g.SetParallelization(false)
|
g.SetParallelization(false)
|
||||||
|
|
||||||
if options.Crop {
|
if options.Crop {
|
||||||
g.Add(epubfilters.AutoCrop(
|
g.Add(AutoCrop(
|
||||||
img,
|
img,
|
||||||
options.CropRatioLeft,
|
options.CropRatioLeft,
|
||||||
options.CropRatioUp,
|
options.CropRatioUp,
|
||||||
@ -34,25 +34,26 @@ func NewGift(img image.Image, options *Options) *gift.GIFT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
g.Add(
|
g.Add(
|
||||||
epubfilters.Resize(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
|
Resize(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
|
||||||
epubfilters.Pixel(),
|
Pixel(),
|
||||||
)
|
)
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
// create filters to cut image into 2 equal pieces
|
// 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 := make([]*gift.GIFT, 2)
|
||||||
|
|
||||||
gifts[0] = gift.New(
|
gifts[0] = gift.New(
|
||||||
epubfilters.CropSplitDoublePage(options.Manga),
|
CropSplitDoublePage(options.Manga),
|
||||||
)
|
)
|
||||||
|
|
||||||
gifts[1] = gift.New(
|
gifts[1] = gift.New(
|
||||||
epubfilters.CropSplitDoublePage(!options.Manga),
|
CropSplitDoublePage(!options.Manga),
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, g := range gifts {
|
for _, g := range gifts {
|
||||||
|
g.SetParallelization(false)
|
||||||
if options.Contrast != 0 {
|
if options.Contrast != 0 {
|
||||||
g.Add(gift.Contrast(float32(options.Contrast)))
|
g.Add(gift.Contrast(float32(options.Contrast)))
|
||||||
}
|
}
|
||||||
@ -61,7 +62,7 @@ func NewGiftSplitDoublePage(options *Options) []*gift.GIFT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
g.Add(
|
g.Add(
|
||||||
epubfilters.Resize(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
|
Resize(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package epubfilters
|
package epubimagefilters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/disintegration/gift"
|
"github.com/disintegration/gift"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Lookup for margin and crop
|
||||||
func AutoCrop(img image.Image, cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom int) gift.Filter {
|
func AutoCrop(img image.Image, cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom int) gift.Filter {
|
||||||
return gift.Crop(
|
return gift.Crop(
|
||||||
findMarging(img, cutRatioOptions{cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom}),
|
findMarging(img, cutRatioOptions{cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom}),
|
@ -1,7 +1,4 @@
|
|||||||
/*
|
package epubimagefilters
|
||||||
Create a title with the cover image
|
|
||||||
*/
|
|
||||||
package epubfilters
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
@ -14,6 +11,7 @@ import (
|
|||||||
"golang.org/x/image/font/gofont/gomonobold"
|
"golang.org/x/image/font/gofont/gomonobold"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Create a title with the cover image
|
||||||
func CoverTitle(title string) gift.Filter {
|
func CoverTitle(title string) gift.Filter {
|
||||||
return &coverTitle{title}
|
return &coverTitle{title}
|
||||||
}
|
}
|
@ -1,9 +1,4 @@
|
|||||||
/*
|
package epubimagefilters
|
||||||
cut a double page in 2 part: left and right.
|
|
||||||
|
|
||||||
this will cut in the middle of the page.
|
|
||||||
*/
|
|
||||||
package epubfilters
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
@ -12,6 +7,8 @@ import (
|
|||||||
"github.com/disintegration/gift"
|
"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 {
|
func CropSplitDoublePage(right bool) gift.Filter {
|
||||||
return &cropSplitDoublePage{right}
|
return &cropSplitDoublePage{right}
|
||||||
}
|
}
|
@ -1,9 +1,4 @@
|
|||||||
/*
|
package epubimagefilters
|
||||||
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
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
@ -13,6 +8,8 @@ import (
|
|||||||
"github.com/disintegration/gift"
|
"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 {
|
func Pixel() gift.Filter {
|
||||||
return &pixel{}
|
return &pixel{}
|
||||||
}
|
}
|
@ -1,9 +1,4 @@
|
|||||||
/*
|
package epubimagefilters
|
||||||
Resize image by keeping aspect ratio.
|
|
||||||
|
|
||||||
This will reduce or enlarge image to fit into the viewWidth and viewHeight.
|
|
||||||
*/
|
|
||||||
package epubfilters
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
@ -12,6 +7,8 @@ import (
|
|||||||
"github.com/disintegration/gift"
|
"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 {
|
func Resize(viewWidth, viewHeight int, resampling gift.Resampling) gift.Filter {
|
||||||
return &resizeFilter{
|
return &resizeFilter{
|
||||||
viewWidth, viewHeight, resampling,
|
viewWidth, viewHeight, resampling,
|
@ -14,9 +14,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
epubfilters "github.com/celogeek/go-comic-converter/v2/internal/epub/filters"
|
|
||||||
epubimage "github.com/celogeek/go-comic-converter/v2/internal/epub/image"
|
epubimage "github.com/celogeek/go-comic-converter/v2/internal/epub/image"
|
||||||
epubimagedata "github.com/celogeek/go-comic-converter/v2/internal/epub/imagedata"
|
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"
|
epubprogress "github.com/celogeek/go-comic-converter/v2/internal/epub/progress"
|
||||||
"github.com/disintegration/gift"
|
"github.com/disintegration/gift"
|
||||||
_ "golang.org/x/image/webp"
|
_ "golang.org/x/image/webp"
|
||||||
@ -112,7 +112,7 @@ func LoadImages(o *Options) ([]*epubimage.Image, error) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
g := epubimage.NewGift(src, o.Image)
|
g := epubimagefilters.NewGift(src, o.Image)
|
||||||
// Convert image
|
// Convert image
|
||||||
dst := image.NewGray(g.Bounds(src.Bounds()))
|
dst := image.NewGray(g.Bounds(src.Bounds()))
|
||||||
g.Draw(dst, src)
|
g.Draw(dst, src)
|
||||||
@ -141,7 +141,7 @@ func LoadImages(o *Options) ([]*epubimage.Image, error) {
|
|||||||
if (!o.Image.HasCover || img.Id > 0) &&
|
if (!o.Image.HasCover || img.Id > 0) &&
|
||||||
o.Image.AutoSplitDoublePage &&
|
o.Image.AutoSplitDoublePage &&
|
||||||
src.Bounds().Dx() > src.Bounds().Dy() {
|
src.Bounds().Dx() > src.Bounds().Dy() {
|
||||||
gifts := epubimage.NewGiftSplitDoublePage(o.Image)
|
gifts := epubimagefilters.NewGiftSplitDoublePage(o.Image)
|
||||||
for i, g := range gifts {
|
for i, g := range gifts {
|
||||||
part := i + 1
|
part := i + 1
|
||||||
dst := image.NewGray(g.Bounds(src.Bounds()))
|
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
|
// create a title page with the cover
|
||||||
func LoadCoverTitleData(img *epubimage.Image, title string, quality int) *epubimagedata.ImageData {
|
func LoadCoverTitleData(img *epubimage.Image, title string, quality int) *epubimagedata.ImageData {
|
||||||
// Create a blur version of the cover
|
// 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()))
|
dst := image.NewGray(g.Bounds(img.Raw.Bounds()))
|
||||||
g.Draw(dst, img.Raw)
|
g.Draw(dst, img.Raw)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user