From a94e67dd06bc4c8c90014b01f0d1e14b485a1a06 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Sat, 11 May 2024 14:26:04 +0200 Subject: [PATCH] remove pointer from epub filters --- .../imagefilters/epub_image_filters_autocontrast.go | 12 ++++++------ .../imagefilters/epub_image_filters_cover_title.go | 6 +++--- .../epub_image_filters_crop_split_double_page.go | 6 +++--- .../epub/imagefilters/epub_image_filters_pixel.go | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/epub/imagefilters/epub_image_filters_autocontrast.go b/internal/epub/imagefilters/epub_image_filters_autocontrast.go index 0a9a490..44dbe75 100644 --- a/internal/epub/imagefilters/epub_image_filters_autocontrast.go +++ b/internal/epub/imagefilters/epub_image_filters_autocontrast.go @@ -10,14 +10,14 @@ import ( // AutoContrast Automatically improve contrast func AutoContrast() gift.Filter { - return &autocontrast{} + return autocontrast{} } type autocontrast struct { } // 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{} for x := src.Bounds().Min.X; x < src.Bounds().Max.X; x++ { 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 -func (f *autocontrast) cap(v float32) float32 { +func (f autocontrast) cap(v float32) float32 { if v < 0 { return 0 } @@ -55,12 +55,12 @@ func (f *autocontrast) cap(v float32) float32 { } // power of 2 for float32 -func (f *autocontrast) pow2(v float32) float32 { +func (f autocontrast) pow2(v float32) float32 { return v * v } // 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 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. -func (*autocontrast) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) { +func (autocontrast) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) { dstBounds = srcBounds return } diff --git a/internal/epub/imagefilters/epub_image_filters_cover_title.go b/internal/epub/imagefilters/epub_image_filters_cover_title.go index 7692e91..0d96c5f 100644 --- a/internal/epub/imagefilters/epub_image_filters_cover_title.go +++ b/internal/epub/imagefilters/epub_image_filters_cover_title.go @@ -13,7 +13,7 @@ import ( // CoverTitle Create a title with the cover image 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 { @@ -26,12 +26,12 @@ type coverTitle struct { } // 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 } // 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) if p.title == "" { return diff --git a/internal/epub/imagefilters/epub_image_filters_crop_split_double_page.go b/internal/epub/imagefilters/epub_image_filters_crop_split_double_page.go index 2eb7d65..38dade4 100644 --- a/internal/epub/imagefilters/epub_image_filters_crop_split_double_page.go +++ b/internal/epub/imagefilters/epub_image_filters_crop_split_double_page.go @@ -11,14 +11,14 @@ import ( // // This will cut in the middle of the page. func CropSplitDoublePage(right bool) gift.Filter { - return &cropSplitDoublePage{right} + return cropSplitDoublePage{right} } type cropSplitDoublePage struct { 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 { dstBounds = image.Rect( srcBounds.Max.X/2, srcBounds.Min.Y, @@ -33,6 +33,6 @@ func (p *cropSplitDoublePage) Bounds(srcBounds image.Rectangle) (dstBounds image 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) } diff --git a/internal/epub/imagefilters/epub_image_filters_pixel.go b/internal/epub/imagefilters/epub_image_filters_pixel.go index 97e20fd..376bbc0 100644 --- a/internal/epub/imagefilters/epub_image_filters_pixel.go +++ b/internal/epub/imagefilters/epub_image_filters_pixel.go @@ -12,13 +12,13 @@ import ( // // An image 0x0 is not a valid image, and failed to read. func Pixel() gift.Filter { - return &pixel{} + return pixel{} } 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 { dstBounds = image.Rect(0, 0, 1, 1) } else { @@ -27,7 +27,7 @@ func (p *pixel) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) { 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 { dst.Set(0, 0, color.White) return