From 09630243fb33dcf9868bf4dc31c693684807cd82 Mon Sep 17 00:00:00 2001 From: Milan Nikolic Date: Tue, 23 Jun 2026 04:39:03 +0200 Subject: [PATCH] Fix 4-bit 16 color palette --- cbconvert.go | 4 ++-- cbconvert_archive.go | 2 +- cbconvert_func.go | 2 +- cbconvert_image.go | 38 +++++++++++++++++++------------------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/cbconvert.go b/cbconvert.go index cfda7ca..4523d03 100644 --- a/cbconvert.go +++ b/cbconvert.go @@ -87,7 +87,7 @@ type Converter struct { Workdir string // Number of files Nfiles int - // Index of current file + // Index of the current file CurrFile int // Number of contents in archive/document Ncontents int @@ -486,7 +486,7 @@ func (c *Converter) Preview(fileName string, fileInfo os.FileInfo, width, height return img, nil } -// Convert converts comic book. +// Convert converts a comic book. func (c *Converter) Convert(fileName string, fileInfo os.FileInfo) error { c.CurrFile++ diff --git a/cbconvert_archive.go b/cbconvert_archive.go index 763a303..4928d3f 100644 --- a/cbconvert_archive.go +++ b/cbconvert_archive.go @@ -336,7 +336,7 @@ func (c *Converter) archiveSetComment(fileName, commentBody string) error { return nil } -// archiveFileAdd adds file to archive. +// archiveFileAdd adds a file to the archive. func (c *Converter) archiveFileAdd(fileName, newFileName string) error { zr, err := zip.OpenReader(fileName) if err != nil { diff --git a/cbconvert_func.go b/cbconvert_func.go index 43b76b3..b9917d2 100644 --- a/cbconvert_func.go +++ b/cbconvert_func.go @@ -59,7 +59,7 @@ func imagesFromSlice(files []string) []string { return images } -// isArchive checks if file is archive. +// isArchive checks if a file is archive. func isArchive(f string) bool { var types = []string{".rar", ".zip", ".7z", ".tar", ".cbr", ".cbz", ".cb7", ".cbt"} for _, t := range types { diff --git a/cbconvert_image.go b/cbconvert_image.go index 3e65a3d..94bda06 100644 --- a/cbconvert_image.go +++ b/cbconvert_image.go @@ -22,7 +22,7 @@ const ( mitchellNetravali // CatmullRom is a sharp bicubic filter. catmullRom - // Gaussian is a blurring filter that uses gaussian function, useful for noise removal. + // Gaussian is a blurring filter, which uses gaussian function, useful for noise removal. gaussian // Lanczos is a high-quality resampling filter, it's slower than cubic filters. lanczos @@ -124,7 +124,7 @@ func imageToGray(src image.Image) *image.Gray { return dst } -// isGrayScale checks if image is grayscale. +// isGrayScale checks if the image is grayscale. func isGrayScale(img image.Image) bool { model := img.ColorModel() if model == color.GrayModel || model == color.Gray16Model { @@ -135,29 +135,29 @@ func isGrayScale(img image.Image) bool { } var colors16 = []color.Color{ - color.RGBA{0, 0, 0, 255}, - color.RGBA{17, 17, 17, 255}, - color.RGBA{34, 34, 34, 255}, - color.RGBA{51, 51, 51, 255}, - color.RGBA{68, 68, 68, 255}, - color.RGBA{85, 85, 85, 255}, - color.RGBA{102, 102, 102, 255}, - color.RGBA{119, 119, 119, 255}, - color.RGBA{136, 136, 136, 255}, - color.RGBA{153, 153, 153, 255}, - color.RGBA{170, 170, 170, 255}, - color.RGBA{187, 187, 187, 255}, - color.RGBA{204, 204, 204, 255}, - color.RGBA{221, 221, 221, 255}, - color.RGBA{238, 238, 238, 255}, - color.RGBA{255, 255, 255, 255}, + color.RGBA{A: 255}, + color.RGBA{R: 17, G: 17, B: 17, A: 255}, + color.RGBA{R: 34, G: 34, B: 34, A: 255}, + color.RGBA{R: 51, G: 51, B: 51, A: 255}, + color.RGBA{R: 68, G: 68, B: 68, A: 255}, + color.RGBA{R: 85, G: 85, B: 85, A: 255}, + color.RGBA{R: 102, G: 102, B: 102, A: 255}, + color.RGBA{R: 119, G: 119, B: 119, A: 255}, + color.RGBA{R: 136, G: 136, B: 136, A: 255}, + color.RGBA{R: 153, G: 153, B: 153, A: 255}, + color.RGBA{R: 170, G: 170, B: 170, A: 255}, + color.RGBA{R: 187, G: 187, B: 187, A: 255}, + color.RGBA{R: 204, G: 204, B: 204, A: 255}, + color.RGBA{R: 221, G: 221, B: 221, A: 255}, + color.RGBA{R: 238, G: 238, B: 238, A: 255}, + color.RGBA{R: 255, G: 255, B: 255, A: 255}, } // imageToPaletted converts an image.Image to *image.Paletted using 16-color palette. func imageToPaletted(src image.Image) *image.Paletted { b := src.Bounds() dst := image.NewPaletted(b, colors16) - draw.Draw(dst, dst.Bounds(), src, b.Min, draw.Src) + draw.FloydSteinberg.Draw(dst, b, imageToGray(src), b.Min) return dst }