From bb5659277b3b9dfbb1fa2418af6d27c765ccc008 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Mon, 10 Apr 2023 11:53:53 +0200 Subject: [PATCH] use 8bits gray scale instead of palette Palette limit the number of color to 16. But kindle seems to handle more. Remove the palette, and let the kindle handle the shade of gray --- internal/converter/options/core.go | 3 +- internal/converter/profiles/core.go | 55 +++++++++++++---------------- internal/epub/core.go | 2 -- internal/epub/image_processing.go | 4 +-- internal/epub/palettes.go | 47 ------------------------ main.go | 1 - 6 files changed, 28 insertions(+), 84 deletions(-) delete mode 100644 internal/epub/palettes.go diff --git a/internal/converter/options/core.go b/internal/converter/options/core.go index 66e5dac..bf45a4f 100644 --- a/internal/converter/options/core.go +++ b/internal/converter/options/core.go @@ -117,12 +117,11 @@ func (o *Options) ShowDefault() string { profile := o.GetProfile() if profile != nil { profileDesc = fmt.Sprintf( - "%s - %s - %dx%d - %d levels of gray", + "%s - %s - %dx%d", o.Profile, profile.Description, profile.Width, profile.Height, - len(profile.Palette), ) } limitmb := "nolimit" diff --git a/internal/converter/profiles/core.go b/internal/converter/profiles/core.go index 90abfd2..0a5a2fd 100644 --- a/internal/converter/profiles/core.go +++ b/internal/converter/profiles/core.go @@ -2,10 +2,7 @@ package profiles import ( "fmt" - "image/color" "strings" - - "github.com/celogeek/go-comic-converter/v2/internal/epub" ) type Profile struct { @@ -13,38 +10,37 @@ type Profile struct { Description string Width int Height int - Palette color.Palette } type Profiles []Profile func New() Profiles { return []Profile{ - {"K1", "Kindle 1", 600, 670, epub.PALETTE_4}, - {"K11", "Kindle 11", 1072, 1448, epub.PALETTE_16}, - {"K2", "Kindle 2", 600, 670, epub.PALETTE_15}, - {"K34", "Kindle Keyboard/Touch", 600, 800, epub.PALETTE_16}, - {"K578", "Kindle", 600, 800, epub.PALETTE_16}, - {"KDX", "Kindle DX/DXG", 824, 1000, epub.PALETTE_16}, - {"KPW", "Kindle Paperwhite 1/2", 758, 1024, epub.PALETTE_16}, - {"KV", "Kindle Paperwhite 3/4/Voyage/Oasis", 1072, 1448, epub.PALETTE_16}, - {"KPW5", "Kindle Paperwhite 5/Signature Edition", 1236, 1648, epub.PALETTE_16}, - {"KO", "Kindle Oasis 2/3", 1264, 1680, epub.PALETTE_16}, - {"KS", "Kindle Scribe", 1860, 2480, epub.PALETTE_16}, + {"K1", "Kindle 1", 600, 670}, + {"K11", "Kindle 11", 1072, 1448}, + {"K2", "Kindle 2", 600, 670}, + {"K34", "Kindle Keyboard/Touch", 600, 800}, + {"K578", "Kindle", 600, 800}, + {"KDX", "Kindle DX/DXG", 824, 1000}, + {"KPW", "Kindle Paperwhite 1/2", 758, 1024}, + {"KV", "Kindle Paperwhite 3/4/Voyage/Oasis", 1072, 1448}, + {"KPW5", "Kindle Paperwhite 5/Signature Edition", 1236, 1648}, + {"KO", "Kindle Oasis 2/3", 1264, 1680}, + {"KS", "Kindle Scribe", 1860, 2480}, // Kobo - {"KoMT", "Kobo Mini/Touch", 600, 800, epub.PALETTE_16}, - {"KoG", "Kobo Glo", 768, 1024, epub.PALETTE_16}, - {"KoGHD", "Kobo Glo HD", 1072, 1448, epub.PALETTE_16}, - {"KoA", "Kobo Aura", 758, 1024, epub.PALETTE_16}, - {"KoAHD", "Kobo Aura HD", 1080, 1440, epub.PALETTE_16}, - {"KoAH2O", "Kobo Aura H2O", 1080, 1430, epub.PALETTE_16}, - {"KoAO", "Kobo Aura ONE", 1404, 1872, epub.PALETTE_16}, - {"KoN", "Kobo Nia", 758, 1024, epub.PALETTE_16}, - {"KoC", "Kobo Clara HD/Kobo Clara 2E", 1072, 1448, epub.PALETTE_16}, - {"KoL", "Kobo Libra H2O/Kobo Libra 2", 1264, 1680, epub.PALETTE_16}, - {"KoF", "Kobo Forma", 1440, 1920, epub.PALETTE_16}, - {"KoS", "Kobo Sage", 1440, 1920, epub.PALETTE_16}, - {"KoE", "Kobo Elipsa", 1404, 1872, epub.PALETTE_16}, + {"KoMT", "Kobo Mini/Touch", 600, 800}, + {"KoG", "Kobo Glo", 768, 1024}, + {"KoGHD", "Kobo Glo HD", 1072, 1448}, + {"KoA", "Kobo Aura", 758, 1024}, + {"KoAHD", "Kobo Aura HD", 1080, 1440}, + {"KoAH2O", "Kobo Aura H2O", 1080, 1430}, + {"KoAO", "Kobo Aura ONE", 1404, 1872}, + {"KoN", "Kobo Nia", 758, 1024}, + {"KoC", "Kobo Clara HD/Kobo Clara 2E", 1072, 1448}, + {"KoL", "Kobo Libra H2O/Kobo Libra 2", 1264, 1680}, + {"KoF", "Kobo Forma", 1440, 1920}, + {"KoS", "Kobo Sage", 1440, 1920}, + {"KoE", "Kobo Elipsa", 1404, 1872}, } } @@ -52,10 +48,9 @@ func (p Profiles) String() string { s := make([]string, 0) for _, v := range p { s = append(s, fmt.Sprintf( - " - %-7s ( %9s ) - %2d levels of gray - %s", + " - %-7s ( %9s ) - %s", v.Code, fmt.Sprintf("%dx%d", v.Width, v.Height), - len(v.Palette), v.Description, )) } diff --git a/internal/epub/core.go b/internal/epub/core.go index a9300d3..a0eb703 100644 --- a/internal/epub/core.go +++ b/internal/epub/core.go @@ -3,7 +3,6 @@ package epub import ( "encoding/xml" "fmt" - "image/color" "os" "path/filepath" "regexp" @@ -21,7 +20,6 @@ type ImageOptions struct { ViewHeight int Quality int Algo string - Palette color.Palette Brightness int Contrast int AutoRotate bool diff --git a/internal/epub/image_processing.go b/internal/epub/image_processing.go index 80c1c95..f1e345a 100644 --- a/internal/epub/image_processing.go +++ b/internal/epub/image_processing.go @@ -176,7 +176,7 @@ func (e *ePub) LoadImages() ([]*Image, error) { g := NewGift(e.ImageOptions) // Convert image - dst := image.NewPaletted(g.Bounds(src.Bounds()), e.ImageOptions.Palette) + dst := image.NewGray(g.Bounds(src.Bounds())) g.Draw(dst, src) imageOutput <- &Image{ @@ -202,7 +202,7 @@ func (e *ePub) LoadImages() ([]*Image, error) { gifts := NewGiftSplitDoublePage(e.ImageOptions) for i, g := range gifts { part := i + 1 - dst := image.NewPaletted(g.Bounds(src.Bounds()), e.ImageOptions.Palette) + dst := image.NewGray(g.Bounds(src.Bounds())) g.Draw(dst, src) imageOutput <- &Image{ Id: img.Id, diff --git a/internal/epub/palettes.go b/internal/epub/palettes.go deleted file mode 100644 index 1335378..0000000 --- a/internal/epub/palettes.go +++ /dev/null @@ -1,47 +0,0 @@ -package epub - -import "image/color" - -var PALETTE_16 = color.Palette{ - color.Gray{0x00}, - color.Gray{0x11}, - color.Gray{0x22}, - color.Gray{0x33}, - color.Gray{0x44}, - color.Gray{0x55}, - color.Gray{0x66}, - color.Gray{0x77}, - color.Gray{0x88}, - color.Gray{0x99}, - color.Gray{0xaa}, - color.Gray{0xbb}, - color.Gray{0xcc}, - color.Gray{0xdd}, - color.Gray{0xee}, - color.Gray{0xff}, -} - -var PALETTE_15 = color.Palette{ - color.Gray{0x00}, - color.Gray{0x11}, - color.Gray{0x22}, - color.Gray{0x33}, - color.Gray{0x44}, - color.Gray{0x55}, - color.Gray{0x66}, - color.Gray{0x77}, - color.Gray{0x88}, - color.Gray{0x99}, - color.Gray{0xaa}, - color.Gray{0xbb}, - color.Gray{0xcc}, - color.Gray{0xdd}, - color.Gray{0xff}, -} - -var PALETTE_4 = color.Palette{ - color.Gray{0x00}, - color.Gray{0x55}, - color.Gray{0xaa}, - color.Gray{0xff}, -} diff --git a/main.go b/main.go index 1354150..51c6b0f 100644 --- a/main.go +++ b/main.go @@ -106,7 +106,6 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s ViewHeight: profile.Height, Quality: cmd.Options.Quality, Crop: cmd.Options.Crop, - Palette: profile.Palette, Brightness: cmd.Options.Brightness, Contrast: cmd.Options.Contrast, AutoRotate: cmd.Options.AutoRotate,