add brightness and contrast

This commit is contained in:
Celogeek 2023-01-01 18:45:54 +01:00
parent e8c028d276
commit 8475faa648
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
4 changed files with 46 additions and 20 deletions

View File

@ -76,10 +76,12 @@ The ePub include as a first page:
# go-comic-converter -h
Usage of go-comic-converter:
-algo string
Algo for RGB to Grayscale: default, mean, luma, luster (default "default")
-author string
Author of the epub (default "GO Comic Converter")
-brightness int
Brightness readjustement: between -100 and 100, > 0 lighter, < 0 darker
-contrast int
Contrast readjustement: between -100 and 100, > 0 more contrast, < 0 less contrast
-input string
Source of comic to convert: directory, cbz, zip, cbr, rar, pdf
-limitmb int

View File

@ -18,6 +18,8 @@ type ImageOptions struct {
Quality int
Algo string
Palette color.Palette
Brightness int
Contrast int
}
type EpubOptions struct {

View File

@ -139,9 +139,9 @@ func LoadImages(path string, options *ImageOptions) ([]*Image, error) {
// prepare filter
g := gift.New(
gift.Crop(findMarging(src)),
gift.Contrast(float32(options.Contrast)),
gift.Brightness(float32(options.Brightness)),
gift.ResizeToFit(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
// gift.Gamma(1.8),
// gift.Sigmoid(0.5, 5),
)
g.SetParallelization(false)

54
main.go
View File

@ -56,14 +56,16 @@ func init() {
}
type Option struct {
Input string
Output string
Profile string
Author string
Title string
Quality int
NoCrop bool
LimitMb int
Input string
Output string
Profile string
Author string
Title string
Quality int
NoCrop bool
Brightness int
Contrast int
LimitMb int
}
func (o *Option) String() string {
@ -84,14 +86,16 @@ func (o *Option) String() string {
return fmt.Sprintf(`Go Comic Converter
Options:
Input : %s
Output : %s
Profile : %s - %s - %dx%d - %d levels of gray
Author : %s
Title : %s
Quality : %d
Crop : %v
LimitMb : %s
Input : %s
Output : %s
Profile : %s - %s - %dx%d - %d levels of gray
Author : %s
Title : %s
Quality : %d
Crop : %v
Brightness: %d
Contrast : %d
LimitMb : %s
`,
o.Input,
o.Output,
@ -100,6 +104,8 @@ Options:
o.Title,
o.Quality,
!o.NoCrop,
o.Brightness,
o.Contrast,
limitmb,
)
}
@ -124,6 +130,8 @@ func main() {
flag.StringVar(&opt.Title, "title", "", "Title of the epub")
flag.IntVar(&opt.Quality, "quality", 85, "Quality of the image")
flag.BoolVar(&opt.NoCrop, "nocrop", false, "Disable cropping")
flag.IntVar(&opt.Brightness, "brightness", 0, "Brightness readjustement: between -100 and 100, > 0 lighter, < 0 darker")
flag.IntVar(&opt.Contrast, "contrast", 0, "Contrast readjustement: between -100 and 100, > 0 more contrast, < 0 less contrast")
flag.IntVar(&opt.LimitMb, "limitmb", 0, "Limit size of the ePub: Default nolimit (0), Minimum 20")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", filepath.Base(os.Args[0]))
@ -188,6 +196,18 @@ func main() {
os.Exit(1)
}
if opt.Brightness < -100 || opt.Brightness > 100 {
fmt.Fprintln(os.Stderr, "Brightness should be between -100 and 100")
flag.Usage()
os.Exit(1)
}
if opt.Contrast < -100 || opt.Contrast > 100 {
fmt.Fprintln(os.Stderr, "Contrast should be between -100 and 100")
flag.Usage()
os.Exit(1)
}
if opt.Title == "" {
ext := filepath.Ext(defaultOutput)
opt.Title = filepath.Base(defaultOutput[0 : len(defaultOutput)-len(ext)])
@ -207,6 +227,8 @@ func main() {
Quality: opt.Quality,
Crop: !opt.NoCrop,
Palette: profile.Palette,
Brightness: opt.Brightness,
Contrast: opt.Contrast,
},
}).Write(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)