mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 15:52:38 +02:00
remove pointer from epub filters
This commit is contained in:
parent
5404390fd8
commit
a94e67dd06
@ -10,14 +10,14 @@ import (
|
|||||||
|
|
||||||
// AutoContrast Automatically improve contrast
|
// AutoContrast Automatically improve contrast
|
||||||
func AutoContrast() gift.Filter {
|
func AutoContrast() gift.Filter {
|
||||||
return &autocontrast{}
|
return autocontrast{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type autocontrast struct {
|
type autocontrast struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute the color number between 0 and 1 that hold half of the pixel
|
// compute the color number between 0 and 1 that hold half of the pixel
|
||||||
func (f *autocontrast) mean(src image.Image) float32 {
|
func (f autocontrast) mean(src image.Image) float32 {
|
||||||
bucket := map[int]int{}
|
bucket := map[int]int{}
|
||||||
for x := src.Bounds().Min.X; x < src.Bounds().Max.X; x++ {
|
for x := src.Bounds().Min.X; x < src.Bounds().Max.X; x++ {
|
||||||
for y := src.Bounds().Min.Y; y < src.Bounds().Max.Y; y++ {
|
for y := src.Bounds().Min.Y; y < src.Bounds().Max.Y; y++ {
|
||||||
@ -44,7 +44,7 @@ func (f *autocontrast) mean(src image.Image) float32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ensure value stay into 0 to 1 bound
|
// ensure value stay into 0 to 1 bound
|
||||||
func (f *autocontrast) cap(v float32) float32 {
|
func (f autocontrast) cap(v float32) float32 {
|
||||||
if v < 0 {
|
if v < 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -55,12 +55,12 @@ func (f *autocontrast) cap(v float32) float32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// power of 2 for float32
|
// power of 2 for float32
|
||||||
func (f *autocontrast) pow2(v float32) float32 {
|
func (f autocontrast) pow2(v float32) float32 {
|
||||||
return v * v
|
return v * v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw into the dst after applying the filter
|
// Draw into the dst after applying the filter
|
||||||
func (f *autocontrast) Draw(dst draw.Image, src image.Image, options *gift.Options) {
|
func (f autocontrast) Draw(dst draw.Image, src image.Image, options *gift.Options) {
|
||||||
// half of the pixel has this color idx
|
// half of the pixel has this color idx
|
||||||
colorMean := f.mean(src)
|
colorMean := f.mean(src)
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ func (f *autocontrast) Draw(dst draw.Image, src image.Image, options *gift.Optio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Bounds calculates the appropriate bounds of an image after applying the filter.
|
// Bounds calculates the appropriate bounds of an image after applying the filter.
|
||||||
func (*autocontrast) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
|
func (autocontrast) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
|
||||||
dstBounds = srcBounds
|
dstBounds = srcBounds
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
// CoverTitle Create a title with the cover image
|
// CoverTitle Create a title with the cover image
|
||||||
func CoverTitle(title string, align string, pctWidth int, pctMargin int, maxFontSize int, borderSize int) gift.Filter {
|
func CoverTitle(title string, align string, pctWidth int, pctMargin int, maxFontSize int, borderSize int) gift.Filter {
|
||||||
return &coverTitle{title, align, pctWidth, pctMargin, maxFontSize, borderSize}
|
return coverTitle{title, align, pctWidth, pctMargin, maxFontSize, borderSize}
|
||||||
}
|
}
|
||||||
|
|
||||||
type coverTitle struct {
|
type coverTitle struct {
|
||||||
@ -26,12 +26,12 @@ type coverTitle struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Bounds size is the same as source
|
// Bounds size is the same as source
|
||||||
func (p *coverTitle) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
|
func (p coverTitle) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
|
||||||
return srcBounds
|
return srcBounds
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw blur the src image, and create a box with the title in the middle
|
// Draw blur the src image, and create a box with the title in the middle
|
||||||
func (p *coverTitle) Draw(dst draw.Image, src image.Image, _ *gift.Options) {
|
func (p coverTitle) Draw(dst draw.Image, src image.Image, _ *gift.Options) {
|
||||||
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
|
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
|
||||||
if p.title == "" {
|
if p.title == "" {
|
||||||
return
|
return
|
||||||
|
@ -11,14 +11,14 @@ import (
|
|||||||
//
|
//
|
||||||
// This will cut in the middle of the page.
|
// 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}
|
||||||
}
|
}
|
||||||
|
|
||||||
type cropSplitDoublePage struct {
|
type cropSplitDoublePage struct {
|
||||||
right bool
|
right bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *cropSplitDoublePage) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
|
func (p cropSplitDoublePage) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
|
||||||
if p.right {
|
if p.right {
|
||||||
dstBounds = image.Rect(
|
dstBounds = image.Rect(
|
||||||
srcBounds.Max.X/2, srcBounds.Min.Y,
|
srcBounds.Max.X/2, srcBounds.Min.Y,
|
||||||
@ -33,6 +33,6 @@ func (p *cropSplitDoublePage) Bounds(srcBounds image.Rectangle) (dstBounds image
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *cropSplitDoublePage) Draw(dst draw.Image, src image.Image, options *gift.Options) {
|
func (p cropSplitDoublePage) Draw(dst draw.Image, src image.Image, options *gift.Options) {
|
||||||
gift.Crop(dst.Bounds()).Draw(dst, src, options)
|
gift.Crop(dst.Bounds()).Draw(dst, src, options)
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,13 @@ import (
|
|||||||
//
|
//
|
||||||
// An image 0x0 is not a valid image, and failed to read.
|
// An image 0x0 is not a valid image, and failed to read.
|
||||||
func Pixel() gift.Filter {
|
func Pixel() gift.Filter {
|
||||||
return &pixel{}
|
return pixel{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type pixel struct {
|
type pixel struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *pixel) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
|
func (p pixel) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
|
||||||
if srcBounds.Dx() == 0 || srcBounds.Dy() == 0 {
|
if srcBounds.Dx() == 0 || srcBounds.Dy() == 0 {
|
||||||
dstBounds = image.Rect(0, 0, 1, 1)
|
dstBounds = image.Rect(0, 0, 1, 1)
|
||||||
} else {
|
} else {
|
||||||
@ -27,7 +27,7 @@ func (p *pixel) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *pixel) Draw(dst draw.Image, src image.Image, _ *gift.Options) {
|
func (p pixel) Draw(dst draw.Image, src image.Image, _ *gift.Options) {
|
||||||
if dst.Bounds().Dx() == 1 && dst.Bounds().Dy() == 1 {
|
if dst.Bounds().Dx() == 1 && dst.Bounds().Dy() == 1 {
|
||||||
dst.Set(0, 0, color.White)
|
dst.Set(0, 0, color.White)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user