mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 08:12:36 +02:00
add brightness and contrast
This commit is contained in:
parent
e8c028d276
commit
8475faa648
@ -76,10 +76,12 @@ The ePub include as a first page:
|
|||||||
# go-comic-converter -h
|
# go-comic-converter -h
|
||||||
|
|
||||||
Usage of go-comic-converter:
|
Usage of go-comic-converter:
|
||||||
-algo string
|
|
||||||
Algo for RGB to Grayscale: default, mean, luma, luster (default "default")
|
|
||||||
-author string
|
-author string
|
||||||
Author of the epub (default "GO Comic Converter")
|
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
|
-input string
|
||||||
Source of comic to convert: directory, cbz, zip, cbr, rar, pdf
|
Source of comic to convert: directory, cbz, zip, cbr, rar, pdf
|
||||||
-limitmb int
|
-limitmb int
|
||||||
|
@ -18,6 +18,8 @@ type ImageOptions struct {
|
|||||||
Quality int
|
Quality int
|
||||||
Algo string
|
Algo string
|
||||||
Palette color.Palette
|
Palette color.Palette
|
||||||
|
Brightness int
|
||||||
|
Contrast int
|
||||||
}
|
}
|
||||||
|
|
||||||
type EpubOptions struct {
|
type EpubOptions struct {
|
||||||
|
@ -139,9 +139,9 @@ func LoadImages(path string, options *ImageOptions) ([]*Image, error) {
|
|||||||
// prepare filter
|
// prepare filter
|
||||||
g := gift.New(
|
g := gift.New(
|
||||||
gift.Crop(findMarging(src)),
|
gift.Crop(findMarging(src)),
|
||||||
|
gift.Contrast(float32(options.Contrast)),
|
||||||
|
gift.Brightness(float32(options.Brightness)),
|
||||||
gift.ResizeToFit(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
|
gift.ResizeToFit(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
|
||||||
// gift.Gamma(1.8),
|
|
||||||
// gift.Sigmoid(0.5, 5),
|
|
||||||
)
|
)
|
||||||
g.SetParallelization(false)
|
g.SetParallelization(false)
|
||||||
|
|
||||||
|
54
main.go
54
main.go
@ -56,14 +56,16 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Option struct {
|
type Option struct {
|
||||||
Input string
|
Input string
|
||||||
Output string
|
Output string
|
||||||
Profile string
|
Profile string
|
||||||
Author string
|
Author string
|
||||||
Title string
|
Title string
|
||||||
Quality int
|
Quality int
|
||||||
NoCrop bool
|
NoCrop bool
|
||||||
LimitMb int
|
Brightness int
|
||||||
|
Contrast int
|
||||||
|
LimitMb int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Option) String() string {
|
func (o *Option) String() string {
|
||||||
@ -84,14 +86,16 @@ func (o *Option) String() string {
|
|||||||
return fmt.Sprintf(`Go Comic Converter
|
return fmt.Sprintf(`Go Comic Converter
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
Input : %s
|
Input : %s
|
||||||
Output : %s
|
Output : %s
|
||||||
Profile : %s - %s - %dx%d - %d levels of gray
|
Profile : %s - %s - %dx%d - %d levels of gray
|
||||||
Author : %s
|
Author : %s
|
||||||
Title : %s
|
Title : %s
|
||||||
Quality : %d
|
Quality : %d
|
||||||
Crop : %v
|
Crop : %v
|
||||||
LimitMb : %s
|
Brightness: %d
|
||||||
|
Contrast : %d
|
||||||
|
LimitMb : %s
|
||||||
`,
|
`,
|
||||||
o.Input,
|
o.Input,
|
||||||
o.Output,
|
o.Output,
|
||||||
@ -100,6 +104,8 @@ Options:
|
|||||||
o.Title,
|
o.Title,
|
||||||
o.Quality,
|
o.Quality,
|
||||||
!o.NoCrop,
|
!o.NoCrop,
|
||||||
|
o.Brightness,
|
||||||
|
o.Contrast,
|
||||||
limitmb,
|
limitmb,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -124,6 +130,8 @@ func main() {
|
|||||||
flag.StringVar(&opt.Title, "title", "", "Title of the epub")
|
flag.StringVar(&opt.Title, "title", "", "Title of the epub")
|
||||||
flag.IntVar(&opt.Quality, "quality", 85, "Quality of the image")
|
flag.IntVar(&opt.Quality, "quality", 85, "Quality of the image")
|
||||||
flag.BoolVar(&opt.NoCrop, "nocrop", false, "Disable cropping")
|
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.IntVar(&opt.LimitMb, "limitmb", 0, "Limit size of the ePub: Default nolimit (0), Minimum 20")
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Fprintf(os.Stderr, "Usage of %s:\n", filepath.Base(os.Args[0]))
|
fmt.Fprintf(os.Stderr, "Usage of %s:\n", filepath.Base(os.Args[0]))
|
||||||
@ -188,6 +196,18 @@ func main() {
|
|||||||
os.Exit(1)
|
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 == "" {
|
if opt.Title == "" {
|
||||||
ext := filepath.Ext(defaultOutput)
|
ext := filepath.Ext(defaultOutput)
|
||||||
opt.Title = filepath.Base(defaultOutput[0 : len(defaultOutput)-len(ext)])
|
opt.Title = filepath.Base(defaultOutput[0 : len(defaultOutput)-len(ext)])
|
||||||
@ -207,6 +227,8 @@ func main() {
|
|||||||
Quality: opt.Quality,
|
Quality: opt.Quality,
|
||||||
Crop: !opt.NoCrop,
|
Crop: !opt.NoCrop,
|
||||||
Palette: profile.Palette,
|
Palette: profile.Palette,
|
||||||
|
Brightness: opt.Brightness,
|
||||||
|
Contrast: opt.Contrast,
|
||||||
},
|
},
|
||||||
}).Write(); err != nil {
|
}).Write(); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user