mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 16:22:37 +02:00
support grayscale or color mode
grayscale is on by default as the conversion is mainly useful for eInk device.
This commit is contained in:
parent
1c1c1fd38c
commit
8b04cbc38f
@ -101,6 +101,7 @@ func (c *Converter) InitParse() {
|
|||||||
c.AddSection("Config")
|
c.AddSection("Config")
|
||||||
c.AddStringParam(&c.Options.Profile, "profile", c.Options.Profile, fmt.Sprintf("Profile to use: \n%s", c.Options.AvailableProfiles()))
|
c.AddStringParam(&c.Options.Profile, "profile", c.Options.Profile, fmt.Sprintf("Profile to use: \n%s", c.Options.AvailableProfiles()))
|
||||||
c.AddIntParam(&c.Options.Quality, "quality", c.Options.Quality, "Quality of the image")
|
c.AddIntParam(&c.Options.Quality, "quality", c.Options.Quality, "Quality of the image")
|
||||||
|
c.AddBoolParam(&c.Options.Grayscale, "grayscale", c.Options.Grayscale, "Grayscale image. Ideal for eInk devices.")
|
||||||
c.AddBoolParam(&c.Options.Crop, "crop", c.Options.Crop, "Crop images")
|
c.AddBoolParam(&c.Options.Crop, "crop", c.Options.Crop, "Crop images")
|
||||||
c.AddIntParam(&c.Options.CropRatioLeft, "crop-ratio-left", c.Options.CropRatioLeft, "Crop ratio left: ratio of pixels allow to be non blank while cutting on the left.")
|
c.AddIntParam(&c.Options.CropRatioLeft, "crop-ratio-left", c.Options.CropRatioLeft, "Crop ratio left: ratio of pixels allow to be non blank while cutting on the left.")
|
||||||
c.AddIntParam(&c.Options.CropRatioUp, "crop-ratio-up", c.Options.CropRatioUp, "Crop ratio up: ratio of pixels allow to be non blank while cutting on the top.")
|
c.AddIntParam(&c.Options.CropRatioUp, "crop-ratio-up", c.Options.CropRatioUp, "Crop ratio up: ratio of pixels allow to be non blank while cutting on the top.")
|
||||||
|
@ -23,6 +23,7 @@ type Options struct {
|
|||||||
// Config
|
// Config
|
||||||
Profile string `yaml:"profile"`
|
Profile string `yaml:"profile"`
|
||||||
Quality int `yaml:"quality"`
|
Quality int `yaml:"quality"`
|
||||||
|
Grayscale bool `yaml:"grayscale"`
|
||||||
Crop bool `yaml:"crop"`
|
Crop bool `yaml:"crop"`
|
||||||
CropRatioLeft int `yaml:"crop_ratio_left"`
|
CropRatioLeft int `yaml:"crop_ratio_left"`
|
||||||
CropRatioUp int `yaml:"crop_ratio_up"`
|
CropRatioUp int `yaml:"crop_ratio_up"`
|
||||||
@ -64,6 +65,7 @@ func New() *Options {
|
|||||||
return &Options{
|
return &Options{
|
||||||
Profile: "",
|
Profile: "",
|
||||||
Quality: 85,
|
Quality: 85,
|
||||||
|
Grayscale: true,
|
||||||
Crop: true,
|
Crop: true,
|
||||||
CropRatioLeft: 1,
|
CropRatioLeft: 1,
|
||||||
CropRatioUp: 1,
|
CropRatioUp: 1,
|
||||||
@ -174,6 +176,7 @@ func (o *Options) ShowConfig() string {
|
|||||||
{"ViewRatio", fmt.Sprintf("1:%s", strings.TrimRight(fmt.Sprintf("%f", profiles.PerfectRatio), "0"))},
|
{"ViewRatio", fmt.Sprintf("1:%s", strings.TrimRight(fmt.Sprintf("%f", profiles.PerfectRatio), "0"))},
|
||||||
{"View", viewDesc},
|
{"View", viewDesc},
|
||||||
{"Quality", o.Quality},
|
{"Quality", o.Quality},
|
||||||
|
{"Grayscale", o.Grayscale},
|
||||||
{"Crop", o.Crop},
|
{"Crop", o.Crop},
|
||||||
{"CropRatio", fmt.Sprintf("%d Left - %d Up - %d Right - %d Bottom", o.CropRatioLeft, o.CropRatioUp, o.CropRatioRight, o.CropRatioBottom)},
|
{"CropRatio", fmt.Sprintf("%d Left - %d Up - %d Right - %d Bottom", o.CropRatioLeft, o.CropRatioUp, o.CropRatioRight, o.CropRatioBottom)},
|
||||||
{"Brightness", o.Brightness},
|
{"Brightness", o.Brightness},
|
||||||
|
@ -6,6 +6,7 @@ package epubimageprocessor
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
|
"image/draw"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -126,6 +127,37 @@ func (e *EPUBImageProcessor) Load() (images []*epubimage.Image, err error) {
|
|||||||
return images, nil
|
return images, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *EPUBImageProcessor) createImage(src image.Image, r image.Rectangle) draw.Image {
|
||||||
|
if e.Options.Image.GrayScale {
|
||||||
|
return image.NewGray(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch t := src.(type) {
|
||||||
|
case *image.Gray:
|
||||||
|
return image.NewGray(r)
|
||||||
|
case *image.Gray16:
|
||||||
|
return image.NewGray16(r)
|
||||||
|
case *image.RGBA:
|
||||||
|
return image.NewRGBA(r)
|
||||||
|
case *image.RGBA64:
|
||||||
|
return image.NewRGBA64(r)
|
||||||
|
case *image.NRGBA:
|
||||||
|
return image.NewNRGBA(r)
|
||||||
|
case *image.NRGBA64:
|
||||||
|
return image.NewNRGBA64(r)
|
||||||
|
case *image.Alpha:
|
||||||
|
return image.NewAlpha(r)
|
||||||
|
case *image.Alpha16:
|
||||||
|
return image.NewAlpha16(r)
|
||||||
|
case *image.CMYK:
|
||||||
|
return image.NewCMYK(r)
|
||||||
|
case *image.Paletted:
|
||||||
|
return image.NewPaletted(r, t.Palette)
|
||||||
|
default:
|
||||||
|
return image.NewNRGBA64(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// transform image into 1 or 3 images
|
// transform image into 1 or 3 images
|
||||||
// only doublepage with autosplit has 3 versions
|
// only doublepage with autosplit has 3 versions
|
||||||
func (e *EPUBImageProcessor) transformImage(src image.Image, srcId int) []image.Image {
|
func (e *EPUBImageProcessor) transformImage(src image.Image, srcId int) []image.Image {
|
||||||
@ -177,7 +209,7 @@ func (e *EPUBImageProcessor) transformImage(src image.Image, srcId int) []image.
|
|||||||
// convert
|
// convert
|
||||||
{
|
{
|
||||||
g := gift.New(filters...)
|
g := gift.New(filters...)
|
||||||
dst := image.NewGray(g.Bounds(src.Bounds()))
|
dst := e.createImage(src, g.Bounds(src.Bounds()))
|
||||||
g.Draw(dst, src)
|
g.Draw(dst, src)
|
||||||
images = append(images, dst)
|
images = append(images, dst)
|
||||||
}
|
}
|
||||||
@ -204,7 +236,7 @@ func (e *EPUBImageProcessor) transformImage(src image.Image, srcId int) []image.
|
|||||||
epubimagefilters.CropSplitDoublePage(b),
|
epubimagefilters.CropSplitDoublePage(b),
|
||||||
epubimagefilters.Resize(e.Image.View.Width, e.Image.View.Height, gift.LanczosResampling),
|
epubimagefilters.Resize(e.Image.View.Width, e.Image.View.Height, gift.LanczosResampling),
|
||||||
)
|
)
|
||||||
dst := image.NewGray(g.Bounds(src.Bounds()))
|
dst := e.createImage(src, g.Bounds(src.Bounds()))
|
||||||
g.Draw(dst, src)
|
g.Draw(dst, src)
|
||||||
images = append(images, dst)
|
images = append(images, dst)
|
||||||
}
|
}
|
||||||
@ -213,11 +245,11 @@ func (e *EPUBImageProcessor) transformImage(src image.Image, srcId int) []image.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create a title page with the cover
|
// create a title page with the cover
|
||||||
func (e *EPUBImageProcessor) CoverTitleData(img image.Image, title string) (*epubzip.ZipImage, error) {
|
func (e *EPUBImageProcessor) CoverTitleData(src image.Image, title string) (*epubzip.ZipImage, error) {
|
||||||
// Create a blur version of the cover
|
// Create a blur version of the cover
|
||||||
g := gift.New(epubimagefilters.CoverTitle(title))
|
g := gift.New(epubimagefilters.CoverTitle(title))
|
||||||
dst := image.NewGray(g.Bounds(img.Bounds()))
|
dst := e.createImage(src, g.Bounds(src.Bounds()))
|
||||||
g.Draw(dst, img)
|
g.Draw(dst, src)
|
||||||
|
|
||||||
return epubzip.CompressImage("OEBPS/Images/title.jpg", dst, e.Image.Quality)
|
return epubzip.CompressImage("OEBPS/Images/title.jpg", dst, e.Image.Quality)
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ type Image struct {
|
|||||||
Manga bool
|
Manga bool
|
||||||
HasCover bool
|
HasCover bool
|
||||||
View *View
|
View *View
|
||||||
|
GrayScale bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
|
3
main.go
3
main.go
@ -114,6 +114,8 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s
|
|||||||
DryVerbose: cmd.Options.DryVerbose,
|
DryVerbose: cmd.Options.DryVerbose,
|
||||||
Quiet: cmd.Options.Quiet,
|
Quiet: cmd.Options.Quiet,
|
||||||
Image: &epuboptions.Image{
|
Image: &epuboptions.Image{
|
||||||
|
Quality: cmd.Options.Quality,
|
||||||
|
GrayScale: cmd.Options.Grayscale,
|
||||||
Crop: &epuboptions.Crop{
|
Crop: &epuboptions.Crop{
|
||||||
Enabled: cmd.Options.Crop,
|
Enabled: cmd.Options.Crop,
|
||||||
Left: cmd.Options.CropRatioLeft,
|
Left: cmd.Options.CropRatioLeft,
|
||||||
@ -121,7 +123,6 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s
|
|||||||
Right: cmd.Options.CropRatioRight,
|
Right: cmd.Options.CropRatioRight,
|
||||||
Bottom: cmd.Options.CropRatioBottom,
|
Bottom: cmd.Options.CropRatioBottom,
|
||||||
},
|
},
|
||||||
Quality: cmd.Options.Quality,
|
|
||||||
Brightness: cmd.Options.Brightness,
|
Brightness: cmd.Options.Brightness,
|
||||||
Contrast: cmd.Options.Contrast,
|
Contrast: cmd.Options.Contrast,
|
||||||
AutoRotate: cmd.Options.AutoRotate,
|
AutoRotate: cmd.Options.AutoRotate,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user