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
This commit is contained in:
Celogeek 2023-04-10 11:53:53 +02:00
parent 34ed40e26c
commit bb5659277b
Signed by: celogeek
SSH Key Fingerprint: SHA256:njNJLzoLQdbV9PC6ehcruRb0QnEgxABoCYZ+0+aUIYc
6 changed files with 28 additions and 84 deletions

View File

@ -117,12 +117,11 @@ func (o *Options) ShowDefault() string {
profile := o.GetProfile() profile := o.GetProfile()
if profile != nil { if profile != nil {
profileDesc = fmt.Sprintf( profileDesc = fmt.Sprintf(
"%s - %s - %dx%d - %d levels of gray", "%s - %s - %dx%d",
o.Profile, o.Profile,
profile.Description, profile.Description,
profile.Width, profile.Width,
profile.Height, profile.Height,
len(profile.Palette),
) )
} }
limitmb := "nolimit" limitmb := "nolimit"

View File

@ -2,10 +2,7 @@ package profiles
import ( import (
"fmt" "fmt"
"image/color"
"strings" "strings"
"github.com/celogeek/go-comic-converter/v2/internal/epub"
) )
type Profile struct { type Profile struct {
@ -13,38 +10,37 @@ type Profile struct {
Description string Description string
Width int Width int
Height int Height int
Palette color.Palette
} }
type Profiles []Profile type Profiles []Profile
func New() Profiles { func New() Profiles {
return []Profile{ return []Profile{
{"K1", "Kindle 1", 600, 670, epub.PALETTE_4}, {"K1", "Kindle 1", 600, 670},
{"K11", "Kindle 11", 1072, 1448, epub.PALETTE_16}, {"K11", "Kindle 11", 1072, 1448},
{"K2", "Kindle 2", 600, 670, epub.PALETTE_15}, {"K2", "Kindle 2", 600, 670},
{"K34", "Kindle Keyboard/Touch", 600, 800, epub.PALETTE_16}, {"K34", "Kindle Keyboard/Touch", 600, 800},
{"K578", "Kindle", 600, 800, epub.PALETTE_16}, {"K578", "Kindle", 600, 800},
{"KDX", "Kindle DX/DXG", 824, 1000, epub.PALETTE_16}, {"KDX", "Kindle DX/DXG", 824, 1000},
{"KPW", "Kindle Paperwhite 1/2", 758, 1024, epub.PALETTE_16}, {"KPW", "Kindle Paperwhite 1/2", 758, 1024},
{"KV", "Kindle Paperwhite 3/4/Voyage/Oasis", 1072, 1448, epub.PALETTE_16}, {"KV", "Kindle Paperwhite 3/4/Voyage/Oasis", 1072, 1448},
{"KPW5", "Kindle Paperwhite 5/Signature Edition", 1236, 1648, epub.PALETTE_16}, {"KPW5", "Kindle Paperwhite 5/Signature Edition", 1236, 1648},
{"KO", "Kindle Oasis 2/3", 1264, 1680, epub.PALETTE_16}, {"KO", "Kindle Oasis 2/3", 1264, 1680},
{"KS", "Kindle Scribe", 1860, 2480, epub.PALETTE_16}, {"KS", "Kindle Scribe", 1860, 2480},
// Kobo // Kobo
{"KoMT", "Kobo Mini/Touch", 600, 800, epub.PALETTE_16}, {"KoMT", "Kobo Mini/Touch", 600, 800},
{"KoG", "Kobo Glo", 768, 1024, epub.PALETTE_16}, {"KoG", "Kobo Glo", 768, 1024},
{"KoGHD", "Kobo Glo HD", 1072, 1448, epub.PALETTE_16}, {"KoGHD", "Kobo Glo HD", 1072, 1448},
{"KoA", "Kobo Aura", 758, 1024, epub.PALETTE_16}, {"KoA", "Kobo Aura", 758, 1024},
{"KoAHD", "Kobo Aura HD", 1080, 1440, epub.PALETTE_16}, {"KoAHD", "Kobo Aura HD", 1080, 1440},
{"KoAH2O", "Kobo Aura H2O", 1080, 1430, epub.PALETTE_16}, {"KoAH2O", "Kobo Aura H2O", 1080, 1430},
{"KoAO", "Kobo Aura ONE", 1404, 1872, epub.PALETTE_16}, {"KoAO", "Kobo Aura ONE", 1404, 1872},
{"KoN", "Kobo Nia", 758, 1024, epub.PALETTE_16}, {"KoN", "Kobo Nia", 758, 1024},
{"KoC", "Kobo Clara HD/Kobo Clara 2E", 1072, 1448, epub.PALETTE_16}, {"KoC", "Kobo Clara HD/Kobo Clara 2E", 1072, 1448},
{"KoL", "Kobo Libra H2O/Kobo Libra 2", 1264, 1680, epub.PALETTE_16}, {"KoL", "Kobo Libra H2O/Kobo Libra 2", 1264, 1680},
{"KoF", "Kobo Forma", 1440, 1920, epub.PALETTE_16}, {"KoF", "Kobo Forma", 1440, 1920},
{"KoS", "Kobo Sage", 1440, 1920, epub.PALETTE_16}, {"KoS", "Kobo Sage", 1440, 1920},
{"KoE", "Kobo Elipsa", 1404, 1872, epub.PALETTE_16}, {"KoE", "Kobo Elipsa", 1404, 1872},
} }
} }
@ -52,10 +48,9 @@ func (p Profiles) String() string {
s := make([]string, 0) s := make([]string, 0)
for _, v := range p { for _, v := range p {
s = append(s, fmt.Sprintf( s = append(s, fmt.Sprintf(
" - %-7s ( %9s ) - %2d levels of gray - %s", " - %-7s ( %9s ) - %s",
v.Code, v.Code,
fmt.Sprintf("%dx%d", v.Width, v.Height), fmt.Sprintf("%dx%d", v.Width, v.Height),
len(v.Palette),
v.Description, v.Description,
)) ))
} }

View File

@ -3,7 +3,6 @@ package epub
import ( import (
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"image/color"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
@ -21,7 +20,6 @@ type ImageOptions struct {
ViewHeight int ViewHeight int
Quality int Quality int
Algo string Algo string
Palette color.Palette
Brightness int Brightness int
Contrast int Contrast int
AutoRotate bool AutoRotate bool

View File

@ -176,7 +176,7 @@ func (e *ePub) LoadImages() ([]*Image, error) {
g := NewGift(e.ImageOptions) g := NewGift(e.ImageOptions)
// Convert image // Convert image
dst := image.NewPaletted(g.Bounds(src.Bounds()), e.ImageOptions.Palette) dst := image.NewGray(g.Bounds(src.Bounds()))
g.Draw(dst, src) g.Draw(dst, src)
imageOutput <- &Image{ imageOutput <- &Image{
@ -202,7 +202,7 @@ func (e *ePub) LoadImages() ([]*Image, error) {
gifts := NewGiftSplitDoublePage(e.ImageOptions) gifts := NewGiftSplitDoublePage(e.ImageOptions)
for i, g := range gifts { for i, g := range gifts {
part := i + 1 part := i + 1
dst := image.NewPaletted(g.Bounds(src.Bounds()), e.ImageOptions.Palette) dst := image.NewGray(g.Bounds(src.Bounds()))
g.Draw(dst, src) g.Draw(dst, src)
imageOutput <- &Image{ imageOutput <- &Image{
Id: img.Id, Id: img.Id,

View File

@ -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},
}

View File

@ -106,7 +106,6 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s
ViewHeight: profile.Height, ViewHeight: profile.Height,
Quality: cmd.Options.Quality, Quality: cmd.Options.Quality,
Crop: cmd.Options.Crop, Crop: cmd.Options.Crop,
Palette: profile.Palette,
Brightness: cmd.Options.Brightness, Brightness: cmd.Options.Brightness,
Contrast: cmd.Options.Contrast, Contrast: cmd.Options.Contrast,
AutoRotate: cmd.Options.AutoRotate, AutoRotate: cmd.Options.AutoRotate,