diff --git a/internal/epub/image/epub_image_filters.go b/internal/epub/imagefilters/epub_image_filters.go similarity index 63% rename from internal/epub/image/epub_image_filters.go rename to internal/epub/imagefilters/epub_image_filters.go index b21520b..807692a 100644 --- a/internal/epub/image/epub_image_filters.go +++ b/internal/epub/imagefilters/epub_image_filters.go @@ -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), ) } diff --git a/internal/epub/filters/epub_filters_autocrop.go b/internal/epub/imagefilters/epub_image_filters_autocrop.go similarity index 97% rename from internal/epub/filters/epub_filters_autocrop.go rename to internal/epub/imagefilters/epub_image_filters_autocrop.go index 467013c..9669347 100644 --- a/internal/epub/filters/epub_filters_autocrop.go +++ b/internal/epub/imagefilters/epub_image_filters_autocrop.go @@ -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}), diff --git a/internal/epub/filters/epub_filters_cover_title.go b/internal/epub/imagefilters/epub_image_filters_cover_title.go similarity index 97% rename from internal/epub/filters/epub_filters_cover_title.go rename to internal/epub/imagefilters/epub_image_filters_cover_title.go index 546f790..b6f0cf8 100644 --- a/internal/epub/filters/epub_filters_cover_title.go +++ b/internal/epub/imagefilters/epub_image_filters_cover_title.go @@ -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} } diff --git a/internal/epub/filters/epub_filters_crop_split_double_page.go b/internal/epub/imagefilters/epub_image_filters_crop_split_double_page.go similarity index 85% rename from internal/epub/filters/epub_filters_crop_split_double_page.go rename to internal/epub/imagefilters/epub_image_filters_crop_split_double_page.go index a3044a5..4205b0a 100644 --- a/internal/epub/filters/epub_filters_crop_split_double_page.go +++ b/internal/epub/imagefilters/epub_image_filters_crop_split_double_page.go @@ -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} } diff --git a/internal/epub/filters/epub_filters_pixel.go b/internal/epub/imagefilters/epub_image_filters_pixel.go similarity index 80% rename from internal/epub/filters/epub_filters_pixel.go rename to internal/epub/imagefilters/epub_image_filters_pixel.go index ecb4b6f..c8dbff6 100644 --- a/internal/epub/filters/epub_filters_pixel.go +++ b/internal/epub/imagefilters/epub_image_filters_pixel.go @@ -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{} } diff --git a/internal/epub/filters/epub_filters_resize.go b/internal/epub/imagefilters/epub_image_filters_resize.go similarity index 87% rename from internal/epub/filters/epub_filters_resize.go rename to internal/epub/imagefilters/epub_image_filters_resize.go index a91f179..3e910fb 100644 --- a/internal/epub/filters/epub_filters_resize.go +++ b/internal/epub/imagefilters/epub_image_filters_resize.go @@ -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, diff --git a/internal/epub/imageprocessing/epub_image_processing.go b/internal/epub/imageprocessing/epub_image_processing.go index 96684b8..3dc3610 100644 --- a/internal/epub/imageprocessing/epub_image_processing.go +++ b/internal/epub/imageprocessing/epub_image_processing.go @@ -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)