7 Commits
Author SHA1 Message Date
Milan Nikolic 2b85ae5540 Update metadata 2026-06-27 21:36:10 +02:00
Milan Nikolic 3fac75f088 Update modules 2026-06-27 19:30:21 +02:00
Milan Nikolic 0f6e32c177 Update modules 2026-06-27 19:28:25 +02:00
Milan Nikolic 5344970a55 Update modules 2026-06-27 19:12:27 +02:00
Milan Nikolic 6a54e4d5e8 Optimize cover preview 2026-06-27 15:59:49 +02:00
Milan Nikolic 629d569667 Handle Lossless 2026-06-27 14:36:25 +02:00
Milan Nikolic 7b71fdae99 Use document native resolution, issue #55 2026-06-26 22:26:28 +02:00
25 changed files with 234 additions and 80 deletions
+30 -5
View File
@@ -15,6 +15,7 @@ import (
pngstructure "github.com/dsoprea/go-png-image-structure"
"github.com/dustin/go-humanize"
"github.com/gen2brain/go-fitz"
)
// Options type.
@@ -41,7 +42,7 @@ type Options struct {
Fit bool
// Do not upscale images already smaller than the requested width/height
NoUpscale bool
// Document rendering resolution in DPI (PDF, EPUB, etc.); 0 uses the default
// Document rendering resolution in DPI (PDF, EPUB, etc.); 0 uses the page's native resolution
DPI int
// 0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 5=Gaussian, 6=Lanczos
Filter int
@@ -101,6 +102,8 @@ type Converter struct {
prefix string
// Input root for the current file, used to build recursive output paths
root string
// Target size for fast previews; when set, JPEG covers are IDCT-downscaled while decoding
previewWidth, previewHeight int
// Number of files
Nfiles int
// Index of the current file
@@ -209,13 +212,14 @@ func (o Options) Args() []string {
return args
}
// renderDPI returns the document rendering resolution, falling back to 300 when unset.
func (c *Converter) renderDPI() float64 {
// renderPage renders document page n at the configured DPI, or at the page's
// native resolution when DPI is unset.
func (c *Converter) renderPage(doc *fitz.Document, n int) (*image.RGBA, error) {
if c.Opts.DPI > 0 {
return float64(c.Opts.DPI)
return doc.ImageDPI(n, float64(c.Opts.DPI))
}
return 300
return doc.Image(n)
}
// Cancel cancels the operation.
@@ -552,6 +556,27 @@ func (c *Converter) Preview(fileName string, fileInfo os.FileInfo, width, height
return c.previewImage(fileName, i, width, height)
}
// CoverPreview returns the cover fitted into width x height, skipping the output-codec round-trip.
func (c *Converter) CoverPreview(fileName string, fileInfo os.FileInfo, width, height int) (Image, error) {
c.previewWidth, c.previewHeight = width, height
i, err := c.coverImage(fileName, fileInfo)
if err != nil {
return Image{}, fmt.Errorf("%s: %w", fileName, err)
}
if width != 0 && height != 0 {
i = fit(i, width, height, resampleFilter(c.Opts.Filter))
}
var img Image
img.Image = i
img.Width = i.Bounds().Dx()
img.Height = i.Bounds().Dy()
return img, nil
}
// PreviewPage returns the page-th image (0-based) as an image preview.
func (c *Converter) PreviewPage(fileName string, fileInfo os.FileInfo, page, width, height int) (Image, error) {
i, err := c.pageImage(fileName, fileInfo, page)
+49 -2
View File
@@ -1,6 +1,7 @@
package cbconvert
import (
"bufio"
"bytes"
"context"
"fmt"
@@ -16,6 +17,7 @@ import (
"github.com/gen2brain/avif"
"github.com/gen2brain/go-fitz"
"github.com/gen2brain/jpegli"
"github.com/gen2brain/jpegn"
"github.com/gen2brain/jpegxl"
"github.com/gen2brain/webp"
"github.com/jsummers/gobmp"
@@ -48,7 +50,7 @@ func (c *Converter) convertDocument(ctx context.Context, fileName string) error
return fmt.Errorf("convertDocument: %w", ctx.Err())
}
img, err := doc.ImageDPI(n, c.renderDPI())
img, err := c.renderPage(doc, n)
if err != nil {
return fmt.Errorf("convertDocument: %w", err)
}
@@ -356,8 +358,42 @@ func (c *Converter) imageTransform(img image.Image) image.Image {
}
// imageDecode decodes image from reader.
// jpegnOptions decodes straight to RGBA with high-quality chroma upsampling.
var jpegnOptions = jpegn.Options{ToRGBA: true, UpsampleMethod: jpegn.CatmullRom}
func (c *Converter) imageDecode(reader io.Reader) (image.Image, error) {
img, _, err := image.Decode(reader)
br := bufio.NewReader(reader)
if magic, err := br.Peek(2); err == nil && magic[0] == 0xff && magic[1] == 0xd8 {
opts := jpegnOptions
if c.previewWidth > 0 && c.previewHeight > 0 {
data, err := io.ReadAll(br)
if err != nil {
return nil, fmt.Errorf("imageDecode: %w", err)
}
if cfg, err := jpegn.DecodeConfig(bytes.NewReader(data)); err == nil {
opts.ScaleDenom = scaleDenom(cfg.Width, cfg.Height, c.previewWidth, c.previewHeight)
}
img, err := jpegn.Decode(bytes.NewReader(data), &opts)
if err != nil {
return nil, fmt.Errorf("imageDecode: %w", err)
}
return img, nil
}
img, err := jpegn.Decode(br, &opts)
if err != nil {
return nil, fmt.Errorf("imageDecode: %w", err)
}
return img, nil
}
img, _, err := image.Decode(br)
if err != nil {
return img, fmt.Errorf("imageDecode: %w", err)
}
@@ -365,6 +401,17 @@ func (c *Converter) imageDecode(reader io.Reader) (image.Image, error) {
return img, nil
}
// scaleDenom returns the largest JPEG IDCT denominator (1, 2, 4, 8) that keeps w x h at or above tw x th.
func scaleDenom(w, h, tw, th int) int {
for _, d := range []int{8, 4, 2} {
if w/d >= tw && h/d >= th {
return d
}
}
return 1
}
// imageEncode encodes image to file.
func (c *Converter) imageEncode(img image.Image, w io.Writer) error {
var err error
+2 -2
View File
@@ -52,7 +52,7 @@ func (c *Converter) coverDocument(fileName string) (image.Image, error) {
}
defer doc.Close()
img, err := doc.ImageDPI(0, c.renderDPI())
img, err := c.renderPage(doc, 0)
if err != nil {
return nil, fmt.Errorf("coverDocument: %w", err)
}
@@ -124,7 +124,7 @@ func (c *Converter) pageDocument(fileName string, page int) (image.Image, error)
return nil, fmt.Errorf("pageDocument: page %d out of range (%d pages)", page+1, doc.NumPage())
}
img, err := doc.ImageDPI(page, c.renderDPI())
img, err := c.renderPage(doc, page)
if err != nil {
return nil, fmt.Errorf("pageDocument: %w", err)
}
+38 -20
View File
@@ -70,10 +70,37 @@ func fileDlg(title string, multiple, directory bool, dirKey string) ([]string, e
const dlgPreviewName = "_FILEDLGPREVIEW_"
// previewPad insets the cover from the preview pane edges, in pixels per side.
const previewPad = 8
// previewCover returns a FILE_CB handler that draws the highlighted comic's cover in the dialog preview pane.
// Extracted covers are cached by path so re-highlighting a file doesn't re-extract it.
func previewCover() iup.FileFunc {
var image iup.Ihandle
var lastFile string
const maxCache = 32
cache := make(map[string]iup.Ihandle)
order := make([]string, 0, maxCache)
cover := func(path string, w, h int) iup.Ihandle {
if img, ok := cache[path]; ok {
return img
}
img := loadCover(path, w, h)
cache[path] = img
order = append(order, path)
if len(order) > maxCache {
old := order[0]
order = order[1:]
if oi := cache[old]; oi != 0 {
oi.Destroy()
}
delete(cache, old)
}
return img
}
return func(ih iup.Ihandle, filename, status string) int {
switch status {
@@ -82,19 +109,8 @@ func previewCover() iup.FileFunc {
cw, ch := iup.DrawGetSize(ih)
iup.DrawParentBackground(ih)
if filename != lastFile {
lastFile = filename
if image != 0 {
image.Destroy()
image = 0
}
if img := loadCover(filename, cw, ch); img != 0 {
image = img
iup.SetHandle(dlgPreviewName, image)
}
}
if image != 0 {
if image := cover(filename, cw-2*previewPad, ch-2*previewPad); image != 0 {
iup.SetHandle(dlgPreviewName, image)
iw, iih, _ := iup.DrawGetImageInfo(dlgPreviewName)
iup.DrawImage(ih, dlgPreviewName, (cw-iw)/2, (ch-iih)/2, iw, iih)
} else {
@@ -106,11 +122,13 @@ func previewCover() iup.FileFunc {
iup.DrawEnd(ih)
case "FINISH":
if image != 0 {
image.Destroy()
image = 0
for _, img := range cache {
if img != 0 {
img.Destroy()
}
}
lastFile = ""
cache = make(map[string]iup.Ihandle)
order = order[:0]
}
return iup.DEFAULT
@@ -131,7 +149,7 @@ func loadCover(path string, w, h int) iup.Ihandle {
opts := cbconvert.NewOptions()
opts.DPI = 96
img, err := cbconvert.New(opts).Preview(path, fi, w, h)
img, err := cbconvert.New(opts).CoverPreview(path, fi, w, h)
if err != nil || img.Image == nil {
return 0
}
@@ -38,6 +38,23 @@
<content_rating type="oars-1.1"/>
<releases>
<release version="1.2.0" date="2026-06-27" type="stable">
<description>
<ul>
<li>Support for RAR5</li>
<li>Lossless compression for WebP, AVIF, and JXL</li>
<li>Control over encoder effort and speed</li>
<li>Combine multiple comics into a single file</li>
<li>Save and switch between settings profiles</li>
<li>Multi-language interface</li>
<li>Choose the document rendering resolution (DPI)</li>
<li>Option to skip upscaling of smaller images</li>
<li>Refreshed interface with page-by-page preview and cover thumbnails in the file picker</li>
<li>Various fixes and smaller improvements</li>
</ul>
</description>
<url type="details">https://github.com/gen2brain/cbconvert/releases/tag/v1.2.0</url>
</release>
<release version="1.1.0" date="2024-11-06" type="stable">
<description>
<ul>
+5 -5
View File
@@ -4,8 +4,8 @@ go 1.26
require (
github.com/fvbommel/sortorder v1.1.0
github.com/gen2brain/cbconvert v1.0.5-0.20260626071631-8155626dbb42
github.com/gen2brain/iup-go/iup v0.32.1-0.20260626100855-f328861e3291
github.com/gen2brain/cbconvert v1.0.5-0.20260627172825-0f6e32c177ee
github.com/gen2brain/iup-go/iup v0.32.1-0.20260627135200-7df674d35173
)
require (
@@ -23,15 +23,15 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ebitengine/purego v0.10.1 // indirect
github.com/gen2brain/avif v0.5.1 // indirect
github.com/gen2brain/go-fitz v1.24.15 // indirect
github.com/gen2brain/go-fitz v1.28.0 // indirect
github.com/gen2brain/jpegli v0.4.1 // indirect
github.com/gen2brain/jpegxl v0.5.1 // indirect
github.com/gen2brain/jpegn v0.4.2 // indirect
github.com/gen2brain/jpegxl v0.5.2 // indirect
github.com/gen2brain/webp v0.6.1 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/golang/geo v0.0.0-20260625163123-7c0e84413537 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 // indirect
github.com/jupiterrider/ffi v0.7.0 // indirect
github.com/klauspost/compress v1.18.6 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/mholt/archives v0.1.5 // indirect
+10 -10
View File
@@ -40,16 +40,18 @@ github.com/fvbommel/sortorder v1.1.0 h1:fUmoe+HLsBTctBDoaBwpQo5N+nrCp8g/BjKb/6ZQ
github.com/fvbommel/sortorder v1.1.0/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
github.com/gen2brain/avif v0.5.1 h1:LQzLsJpWyGlsa4wuZ3D57qEbCiICIK7Yidz5ZPEwzTk=
github.com/gen2brain/avif v0.5.1/go.mod h1:QgrYqdVE9y40PCfArK9VakcMIpYeDYpZmCSLkW6C1n8=
github.com/gen2brain/cbconvert v1.0.5-0.20260626071631-8155626dbb42 h1:p1K1jOk+rKDhTgh6fiYMKSqXJdIVUWFLK5jodTtwPOU=
github.com/gen2brain/cbconvert v1.0.5-0.20260626071631-8155626dbb42/go.mod h1:qHzMhKZ7VBTffwDQ/9rc4yZ9FO5677ZSjSFZ7QNfaLw=
github.com/gen2brain/go-fitz v1.24.15 h1:sJNB1MOWkqnzzENPHggFpgxTwW0+S5WF/rM5wUBpJWo=
github.com/gen2brain/go-fitz v1.24.15/go.mod h1:SftkiVbTHqF141DuiLwBBM65zP7ig6AVDQpf2WlHamo=
github.com/gen2brain/iup-go/iup v0.32.1-0.20260626100855-f328861e3291 h1:ad/nhBGhknOGDpiHnQ0ZLltZccG82t4tAKK94SrQ8OY=
github.com/gen2brain/iup-go/iup v0.32.1-0.20260626100855-f328861e3291/go.mod h1:V4f7tHOJAeHtjQ+ju795QKv6DGdLEb4L5cmWB1sjSzU=
github.com/gen2brain/cbconvert v1.0.5-0.20260627172825-0f6e32c177ee h1:9ggHORYXL+0zSdfC0bJA049amaH5wW6jZgO5dGisKm4=
github.com/gen2brain/cbconvert v1.0.5-0.20260627172825-0f6e32c177ee/go.mod h1:KrAZdAzcMj1XQkfDz5bp0hotVFUB2k9hRT+9F4b5f2E=
github.com/gen2brain/go-fitz v1.28.0 h1:RovqgQPAcOuyv5HZrWsTWl8qwlwbAHSKcAZXZUw0Vlk=
github.com/gen2brain/go-fitz v1.28.0/go.mod h1:pY2hqAjp9Zy7qfPI2gwbJMHBFAdZpVXOLrRxD82l3Bs=
github.com/gen2brain/iup-go/iup v0.32.1-0.20260627135200-7df674d35173 h1:nBt0N1ixK8eg/7RXJIC4b0WDPxfENqyT+rH1/STZGj4=
github.com/gen2brain/iup-go/iup v0.32.1-0.20260627135200-7df674d35173/go.mod h1:V4f7tHOJAeHtjQ+ju795QKv6DGdLEb4L5cmWB1sjSzU=
github.com/gen2brain/jpegli v0.4.1 h1:qc11IQU0jTYFltroulT4MXmbu9YRftqHV0YBZ0Bqz5o=
github.com/gen2brain/jpegli v0.4.1/go.mod h1:zJ++s4symmKCN1CLkrY0dGXTY3s0NWbd94Rz9KLdCzk=
github.com/gen2brain/jpegxl v0.5.1 h1:UuBUIkZ35DErImU3bTA6rltfV5zSgVNOA/K5a6JibfE=
github.com/gen2brain/jpegxl v0.5.1/go.mod h1:Wlc6lqx03RJfhiQRyHa2e+8VQwT4/qv7zSRsNv9T+yE=
github.com/gen2brain/jpegn v0.4.2 h1:sxy2yolV1eNA02uYtnqBFm4EIC3ETnars98aG7Dc4LM=
github.com/gen2brain/jpegn v0.4.2/go.mod h1:YvcVOmVPSAsefH6yn9HBW3uY0EHlZwCMoiJXoAWfgL0=
github.com/gen2brain/jpegxl v0.5.2 h1:1ou9YRziU8PbpkfFJIyxrNjYM+WaMl2n9LloABxkKsU=
github.com/gen2brain/jpegxl v0.5.2/go.mod h1:Wlc6lqx03RJfhiQRyHa2e+8VQwT4/qv7zSRsNv9T+yE=
github.com/gen2brain/webp v0.6.1 h1:ei7Y1SWpQcdqz3YNDNyn4y2nQanxs9WLzwW5/2DKS64=
github.com/gen2brain/webp v0.6.1/go.mod h1:iGWMaCSw7t3I/Cv9llzEKmpnR36S8lS8VL/ZVjxU0JE=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
@@ -69,8 +71,6 @@ github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyf
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 h1:YLvr1eE6cdCqjOe972w/cYF+FjW34v27+9Vo5106B4M=
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25/go.mod h1:kLgvv7o6UM+0QSf0QjAse3wReFDsb9qbZJdfexWlrQw=
github.com/jupiterrider/ffi v0.7.0 h1:RKsl6Ascal+3kyAqR5Qcbp83LceQMLc1VZbPfHWoNzs=
github.com/jupiterrider/ffi v0.7.0/go.mod h1:9dauhpOfNqrqk28fxuu0kkdeFtT9Qr4vbfigiuIXN7c=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.18.6 h1:2jupLlAwFm95+YDR+NwD2MEfFO9d4z4Prjl1XXDjuao=
github.com/klauspost/compress v1.18.6/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
+1 -1
View File
@@ -27,7 +27,7 @@ func init() {
LblMinSize: "Minimální velikost (MiB):",
TipSize: "Zpracovat pouze soubory větší než minimální velikost",
LblDPI: "DPI dokumentu:",
TipDPI: "Rozlišení pro vykreslování dokumentů (PDF, EPUB atd.); výchozí je 300",
TipDPI: "Rozlišení pro vykreslování dokumentů (PDF, EPUB atd.); výchozí používá původní rozlišení",
LblOutDir: "Výstupní adresář:",
TipOutDir: "Adresář, do kterého se zapisují převedené soubory (povinné)",
+1 -1
View File
@@ -27,7 +27,7 @@ func init() {
LblMinSize: "Mindestgröße (MiB):",
TipSize: "Nur Dateien größer als die Mindestgröße verarbeiten",
LblDPI: "Dokument-DPI:",
TipDPI: "Auflösung zum Rendern von Dokumenten (PDF, EPUB usw.); Standard ist 300",
TipDPI: "Auflösung zum Rendern von Dokumenten (PDF, EPUB usw.); Standard verwendet die Originalauflösung",
LblOutDir: "Ausgabeverzeichnis:",
TipOutDir: "Verzeichnis, in das konvertierte Dateien geschrieben werden (erforderlich)",
+1 -1
View File
@@ -27,7 +27,7 @@ func init() {
LblMinSize: "Minimum Size (MiB):",
TipSize: "Process only files larger than minimum size",
LblDPI: "Document DPI:",
TipDPI: "Resolution for rendering documents (PDF, EPUB, etc.); Default is 300",
TipDPI: "Resolution for rendering documents (PDF, EPUB, etc.); Default uses the original resolution",
LblOutDir: "Output Directory:",
TipOutDir: "Directory where converted files are written (required)",
+1 -1
View File
@@ -27,7 +27,7 @@ func init() {
LblMinSize: "Tamaño mínimo (MiB):",
TipSize: "Procesar solo archivos mayores que el tamaño mínimo",
LblDPI: "DPI del documento:",
TipDPI: "Resolución para renderizar documentos (PDF, EPUB, etc.); el valor predeterminado es 300",
TipDPI: "Resolución para renderizar documentos (PDF, EPUB, etc.); el valor predeterminado usa la resolución original",
LblOutDir: "Directorio de salida:",
TipOutDir: "Directorio donde se escriben los archivos convertidos (obligatorio)",
+1 -1
View File
@@ -27,7 +27,7 @@ func init() {
LblMinSize: "Taille minimale (Mio) :",
TipSize: "Ne traiter que les fichiers plus grands que la taille minimale",
LblDPI: "DPI du document :",
TipDPI: "Résolution pour le rendu des documents (PDF, EPUB, etc.) ; la valeur par défaut est 300",
TipDPI: "Résolution pour le rendu des documents (PDF, EPUB, etc.) ; la valeur par défaut utilise la résolution d'origine",
LblOutDir: "Dossier de sortie :",
TipOutDir: "Dossier où les fichiers convertis sont écrits (obligatoire)",
+1 -1
View File
@@ -27,7 +27,7 @@ func init() {
LblMinSize: "Dimensione minima (MiB):",
TipSize: "Elabora solo i file più grandi della dimensione minima",
LblDPI: "DPI del documento:",
TipDPI: "Risoluzione per il rendering dei documenti (PDF, EPUB, ecc.); il valore predefinito è 300",
TipDPI: "Risoluzione per il rendering dei documenti (PDF, EPUB, ecc.); il valore predefinito usa la risoluzione originale",
LblOutDir: "Cartella di uscita:",
TipOutDir: "Cartella in cui vengono scritti i file convertiti (obbligatoria)",
+1 -1
View File
@@ -27,7 +27,7 @@ func init() {
LblMinSize: "最小サイズ (MiB)",
TipSize: "最小サイズより大きいファイルのみ処理する",
LblDPI: "ドキュメント DPI",
TipDPI: "ドキュメント(PDF、EPUB など)をレンダリングする解像度。既定値は 300",
TipDPI: "ドキュメント(PDF、EPUB など)をレンダリングする解像度。既定値は元の解像度を使用します",
LblOutDir: "出力ディレクトリ:",
TipOutDir: "変換されたファイルが書き込まれるディレクトリ(必須)",
+1 -1
View File
@@ -27,7 +27,7 @@ func init() {
LblMinSize: "Tamanho mínimo (MiB):",
TipSize: "Processar apenas arquivos maiores que o tamanho mínimo",
LblDPI: "DPI do documento:",
TipDPI: "Resolução para renderizar documentos (PDF, EPUB, etc.); o padrão é 300",
TipDPI: "Resolução para renderizar documentos (PDF, EPUB, etc.); o padrão usa a resolução original",
LblOutDir: "Diretório de saída:",
TipOutDir: "Diretório onde os arquivos convertidos são gravados (obrigatório)",
+1 -1
View File
@@ -27,7 +27,7 @@ func init() {
LblMinSize: "Минимальный размер (МиБ):",
TipSize: "Обрабатывать только файлы больше минимального размера",
LblDPI: "DPI документа:",
TipDPI: "Разрешение для рендеринга документов (PDF, EPUB и т. д.); по умолчанию 300",
TipDPI: "Разрешение для рендеринга документов (PDF, EPUB и т. д.); по умолчанию используется исходное разрешение",
LblOutDir: "Каталог вывода:",
TipOutDir: "Каталог, в который записываются преобразованные файлы (обязательно)",
+1 -1
View File
@@ -27,7 +27,7 @@ func init() {
LblMinSize: "最小大小 (MiB)",
TipSize: "仅处理大于最小大小的文件",
LblDPI: "文档 DPI",
TipDPI: "渲染文档的分辨率(PDF、EPUB 等);默认值为 300",
TipDPI: "渲染文档的分辨率(PDF、EPUB 等);默认使用原始分辨率",
LblOutDir: "输出目录:",
TipOutDir: "写入转换后文件的目录(必填)",
+2
View File
@@ -148,6 +148,8 @@ func settingsApply(group string) {
}
}
userLossless = iup.GetHandle("Lossless").GetAttribute("VALUE") == "ON"
syncLabels()
setActive()
previewPost()
+44 -1
View File
@@ -1,10 +1,40 @@
package main
import (
"runtime/debug"
"strings"
"github.com/gen2brain/cbconvert/cmd/cbconvert-gui/i18n"
"github.com/gen2brain/iup-go/iup"
)
// jxlLosslessBuild reports whether wasm2go and nodynamic leave zune-jpegxl (lossless-only) as the only jxl encoder.
var jxlLosslessBuild = func() bool {
info, ok := debug.ReadBuildInfo()
if !ok {
return false
}
var wasm2go, nodynamic bool
for _, kv := range info.Settings {
if kv.Key != "-tags" {
continue
}
for _, t := range strings.Split(kv.Value, ",") {
switch t {
case "wasm2go":
wasm2go = true
case "nodynamic":
nodynamic = true
}
}
}
return wasm2go && nodynamic
}()
// userLossless is the user's Lossless preference, tracked separately because a jxl
// wasm2go build force-sets the widget on.
var userLossless bool
func setActive() {
if busy {
return
@@ -68,7 +98,15 @@ func setActive() {
}
canLossless := opts.Format == "webp" || opts.Format == "avif" || opts.Format == "jxl"
losslessOn := canLossless && opts.Lossless
jxlLossless := jxlLosslessBuild && opts.Format == "jxl"
// jxl wasm2go forces lossless on; otherwise show the user's preference so it doesn't stay stuck on.
losslessVal := "OFF"
if jxlLossless || userLossless {
losslessVal = "ON"
}
iup.GetHandle("Lossless").SetAttribute("VALUE", losslessVal)
losslessOn := jxlLossless || (canLossless && userLossless)
if (opts.Format == "jpeg" || canLossless) && !opts.NoConvert && !losslessOn {
iup.GetHandle("VboxQuality").SetAttribute("ACTIVE", "YES")
@@ -84,6 +122,11 @@ func setActive() {
iup.GetHandle("Lossless").SetAttribute("ACTIVE", "NO")
}
if jxlLossless {
iup.GetHandle("Lossless").SetAttribute("ACTIVE", "NO")
iup.GetHandle("VboxEffort").SetAttribute("ACTIVE", "NO")
}
if opts.Width != 0 && opts.Height != 0 && !opts.NoConvert {
iup.GetHandle("Fit").SetAttribute("ACTIVE", "YES")
} else {
+2 -1
View File
@@ -60,7 +60,7 @@ func list() iup.Ihandle {
"TITLE1": i18n.Lng(i18n.ColTitle),
"TITLE2": i18n.Lng(i18n.ColType),
"TITLE3": i18n.Lng(i18n.ColSize),
"WIDTH1": "300",
"WIDTH1": "250",
"WIDTH2": "50",
"WIDTH3": "100",
"ALIGNMENT2": "ACENTER",
@@ -568,6 +568,7 @@ func tabImage() iup.Ihandle {
iup.Toggle(i18n.Lng(i18n.TglLossless)).SetHandle("Lossless").
SetAttribute("TIP", i18n.Lng(i18n.TipLossless)).
SetCallback("VALUECHANGED_CB", iup.ValueChangedFunc(func(ih iup.Ihandle) int {
userLossless = ih.GetAttribute("VALUE") == "ON"
setActive()
previewPost()
+4 -4
View File
@@ -3,7 +3,7 @@ module github.com/gen2brain/cbconvert/cmd/cbconvert
go 1.26
require (
github.com/gen2brain/cbconvert v1.0.5-0.20260626071631-8155626dbb42
github.com/gen2brain/cbconvert v1.0.5-0.20260627172825-0f6e32c177ee
github.com/schollz/progressbar/v3 v3.19.0
golang.org/x/term v0.44.0
)
@@ -24,15 +24,15 @@ require (
github.com/ebitengine/purego v0.10.1 // indirect
github.com/fvbommel/sortorder v1.1.0 // indirect
github.com/gen2brain/avif v0.5.1 // indirect
github.com/gen2brain/go-fitz v1.24.15 // indirect
github.com/gen2brain/go-fitz v1.28.0 // indirect
github.com/gen2brain/jpegli v0.4.1 // indirect
github.com/gen2brain/jpegxl v0.5.1 // indirect
github.com/gen2brain/jpegn v0.4.2 // indirect
github.com/gen2brain/jpegxl v0.5.2 // indirect
github.com/gen2brain/webp v0.6.1 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/golang/geo v0.0.0-20260625163123-7c0e84413537 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 // indirect
github.com/jupiterrider/ffi v0.7.0 // indirect
github.com/klauspost/compress v1.18.6 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/mattn/go-runewidth v0.0.24 // indirect
+8 -8
View File
@@ -44,14 +44,16 @@ github.com/fvbommel/sortorder v1.1.0 h1:fUmoe+HLsBTctBDoaBwpQo5N+nrCp8g/BjKb/6ZQ
github.com/fvbommel/sortorder v1.1.0/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
github.com/gen2brain/avif v0.5.1 h1:LQzLsJpWyGlsa4wuZ3D57qEbCiICIK7Yidz5ZPEwzTk=
github.com/gen2brain/avif v0.5.1/go.mod h1:QgrYqdVE9y40PCfArK9VakcMIpYeDYpZmCSLkW6C1n8=
github.com/gen2brain/cbconvert v1.0.5-0.20260626071631-8155626dbb42 h1:p1K1jOk+rKDhTgh6fiYMKSqXJdIVUWFLK5jodTtwPOU=
github.com/gen2brain/cbconvert v1.0.5-0.20260626071631-8155626dbb42/go.mod h1:qHzMhKZ7VBTffwDQ/9rc4yZ9FO5677ZSjSFZ7QNfaLw=
github.com/gen2brain/go-fitz v1.24.15 h1:sJNB1MOWkqnzzENPHggFpgxTwW0+S5WF/rM5wUBpJWo=
github.com/gen2brain/go-fitz v1.24.15/go.mod h1:SftkiVbTHqF141DuiLwBBM65zP7ig6AVDQpf2WlHamo=
github.com/gen2brain/cbconvert v1.0.5-0.20260627172825-0f6e32c177ee h1:9ggHORYXL+0zSdfC0bJA049amaH5wW6jZgO5dGisKm4=
github.com/gen2brain/cbconvert v1.0.5-0.20260627172825-0f6e32c177ee/go.mod h1:KrAZdAzcMj1XQkfDz5bp0hotVFUB2k9hRT+9F4b5f2E=
github.com/gen2brain/go-fitz v1.28.0 h1:RovqgQPAcOuyv5HZrWsTWl8qwlwbAHSKcAZXZUw0Vlk=
github.com/gen2brain/go-fitz v1.28.0/go.mod h1:pY2hqAjp9Zy7qfPI2gwbJMHBFAdZpVXOLrRxD82l3Bs=
github.com/gen2brain/jpegli v0.4.1 h1:qc11IQU0jTYFltroulT4MXmbu9YRftqHV0YBZ0Bqz5o=
github.com/gen2brain/jpegli v0.4.1/go.mod h1:zJ++s4symmKCN1CLkrY0dGXTY3s0NWbd94Rz9KLdCzk=
github.com/gen2brain/jpegxl v0.5.1 h1:UuBUIkZ35DErImU3bTA6rltfV5zSgVNOA/K5a6JibfE=
github.com/gen2brain/jpegxl v0.5.1/go.mod h1:Wlc6lqx03RJfhiQRyHa2e+8VQwT4/qv7zSRsNv9T+yE=
github.com/gen2brain/jpegn v0.4.2 h1:sxy2yolV1eNA02uYtnqBFm4EIC3ETnars98aG7Dc4LM=
github.com/gen2brain/jpegn v0.4.2/go.mod h1:YvcVOmVPSAsefH6yn9HBW3uY0EHlZwCMoiJXoAWfgL0=
github.com/gen2brain/jpegxl v0.5.2 h1:1ou9YRziU8PbpkfFJIyxrNjYM+WaMl2n9LloABxkKsU=
github.com/gen2brain/jpegxl v0.5.2/go.mod h1:Wlc6lqx03RJfhiQRyHa2e+8VQwT4/qv7zSRsNv9T+yE=
github.com/gen2brain/webp v0.6.1 h1:ei7Y1SWpQcdqz3YNDNyn4y2nQanxs9WLzwW5/2DKS64=
github.com/gen2brain/webp v0.6.1/go.mod h1:iGWMaCSw7t3I/Cv9llzEKmpnR36S8lS8VL/ZVjxU0JE=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
@@ -71,8 +73,6 @@ github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyf
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 h1:YLvr1eE6cdCqjOe972w/cYF+FjW34v27+9Vo5106B4M=
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25/go.mod h1:kLgvv7o6UM+0QSf0QjAse3wReFDsb9qbZJdfexWlrQw=
github.com/jupiterrider/ffi v0.7.0 h1:RKsl6Ascal+3kyAqR5Qcbp83LceQMLc1VZbPfHWoNzs=
github.com/jupiterrider/ffi v0.7.0/go.mod h1:9dauhpOfNqrqk28fxuu0kkdeFtT9Qr4vbfigiuIXN7c=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.18.6 h1:2jupLlAwFm95+YDR+NwD2MEfFO9d4z4Prjl1XXDjuao=
github.com/klauspost/compress v1.18.6/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
+3 -3
View File
@@ -216,7 +216,7 @@ func parseFlags() (cbconvert.Options, []string) {
convert.IntVar(&opts.Height, "height", base.Height, "Image height")
convert.BoolVar(&opts.Fit, "fit", base.Fit, "Best fit for required width and height")
convert.BoolVar(&opts.NoUpscale, "no-upscale", base.NoUpscale, "Do not upscale images already smaller than the requested width/height")
convert.IntVar(&opts.DPI, "dpi", base.DPI, "Document rendering resolution in DPI (PDF, EPUB, etc.), 0 uses the default (300)")
convert.IntVar(&opts.DPI, "dpi", base.DPI, "Document rendering resolution in DPI (PDF, EPUB, etc.), 0 uses the original resolution")
convert.StringVar(&opts.Format, "format", base.Format, "Image format, valid values are jpeg, png, tiff, bmp, webp, avif, jxl")
convert.StringVar(&opts.Archive, "archive", base.Archive, "Archive format, valid values are zip, tar")
convert.IntVar(&opts.ZipLevel, "zip-level", base.ZipLevel, "ZIP compression level, 0 disables compression, 1-9 sets deflate level (1 fastest, 9 smallest), -1 uses the default")
@@ -246,7 +246,7 @@ func parseFlags() (cbconvert.Options, []string) {
cover.IntVar(&opts.Height, "height", base.Height, "Image height")
cover.BoolVar(&opts.Fit, "fit", base.Fit, "Best fit for required width and height")
cover.BoolVar(&opts.NoUpscale, "no-upscale", base.NoUpscale, "Do not upscale images already smaller than the requested width/height")
cover.IntVar(&opts.DPI, "dpi", base.DPI, "Document rendering resolution in DPI (PDF, EPUB, etc.), 0 uses the default (300)")
cover.IntVar(&opts.DPI, "dpi", base.DPI, "Document rendering resolution in DPI (PDF, EPUB, etc.), 0 uses the original resolution")
cover.StringVar(&opts.Format, "format", base.Format, "Image format, valid values are jpeg, png, tiff, bmp, webp, avif")
cover.IntVar(&opts.Quality, "quality", base.Quality, "Image quality")
cover.IntVar(&opts.Effort, "effort", base.Effort, "Encoder speed/effort, format-specific (webp method 0-6, avif speed 0-10, jxl effort 1-10), -1 uses the format default")
@@ -263,7 +263,7 @@ func parseFlags() (cbconvert.Options, []string) {
thumbnail.IntVar(&opts.Height, "height", base.Height, "Image height")
thumbnail.BoolVar(&opts.Fit, "fit", base.Fit, "Best fit for required width and height")
thumbnail.BoolVar(&opts.NoUpscale, "no-upscale", base.NoUpscale, "Do not upscale images already smaller than the requested width/height")
thumbnail.IntVar(&opts.DPI, "dpi", base.DPI, "Document rendering resolution in DPI (PDF, EPUB, etc.), 0 uses the default (300)")
thumbnail.IntVar(&opts.DPI, "dpi", base.DPI, "Document rendering resolution in DPI (PDF, EPUB, etc.), 0 uses the original resolution")
thumbnail.IntVar(&opts.Filter, "filter", base.Filter, "0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 5=Gaussian, 6=Lanczos")
thumbnail.StringVar(&opts.OutDir, "outdir", base.OutDir, "Output directory")
thumbnail.StringVar(&opts.OutFile, "outfile", base.OutFile, "Output file")
+3 -3
View File
@@ -8,9 +8,9 @@ require (
github.com/dustin/go-humanize v1.0.1
github.com/fvbommel/sortorder v1.1.0
github.com/gen2brain/avif v0.5.1
github.com/gen2brain/go-fitz v1.24.15
github.com/gen2brain/go-fitz v1.28.1
github.com/gen2brain/jpegli v0.4.1
github.com/gen2brain/jpegxl v0.5.1
github.com/gen2brain/jpegxl v0.5.2
github.com/gen2brain/webp v0.6.1
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25
github.com/mholt/archives v0.1.5
@@ -29,10 +29,10 @@ require (
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd // indirect
github.com/dsoprea/go-utility v0.0.0-20221003172846-a3e1774ef349 // indirect
github.com/ebitengine/purego v0.10.1 // indirect
github.com/gen2brain/jpegn v0.4.2
github.com/go-errors/errors v1.5.1 // indirect
github.com/golang/geo v0.0.0-20260625163123-7c0e84413537 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/jupiterrider/ffi v0.7.0 // indirect
github.com/klauspost/compress v1.18.6 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/mikelolasagasti/xz v1.0.1 // indirect
+7 -6
View File
@@ -40,12 +40,14 @@ github.com/fvbommel/sortorder v1.1.0 h1:fUmoe+HLsBTctBDoaBwpQo5N+nrCp8g/BjKb/6ZQ
github.com/fvbommel/sortorder v1.1.0/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
github.com/gen2brain/avif v0.5.1 h1:LQzLsJpWyGlsa4wuZ3D57qEbCiICIK7Yidz5ZPEwzTk=
github.com/gen2brain/avif v0.5.1/go.mod h1:QgrYqdVE9y40PCfArK9VakcMIpYeDYpZmCSLkW6C1n8=
github.com/gen2brain/go-fitz v1.24.15 h1:sJNB1MOWkqnzzENPHggFpgxTwW0+S5WF/rM5wUBpJWo=
github.com/gen2brain/go-fitz v1.24.15/go.mod h1:SftkiVbTHqF141DuiLwBBM65zP7ig6AVDQpf2WlHamo=
github.com/gen2brain/go-fitz v1.28.1 h1:ToEYb2vN4ByaL2VmRNGk92Sa1UAkCn8bsObpA3WkQ48=
github.com/gen2brain/go-fitz v1.28.1/go.mod h1:pY2hqAjp9Zy7qfPI2gwbJMHBFAdZpVXOLrRxD82l3Bs=
github.com/gen2brain/jpegli v0.4.1 h1:qc11IQU0jTYFltroulT4MXmbu9YRftqHV0YBZ0Bqz5o=
github.com/gen2brain/jpegli v0.4.1/go.mod h1:zJ++s4symmKCN1CLkrY0dGXTY3s0NWbd94Rz9KLdCzk=
github.com/gen2brain/jpegxl v0.5.1 h1:UuBUIkZ35DErImU3bTA6rltfV5zSgVNOA/K5a6JibfE=
github.com/gen2brain/jpegxl v0.5.1/go.mod h1:Wlc6lqx03RJfhiQRyHa2e+8VQwT4/qv7zSRsNv9T+yE=
github.com/gen2brain/jpegn v0.4.2 h1:sxy2yolV1eNA02uYtnqBFm4EIC3ETnars98aG7Dc4LM=
github.com/gen2brain/jpegn v0.4.2/go.mod h1:YvcVOmVPSAsefH6yn9HBW3uY0EHlZwCMoiJXoAWfgL0=
github.com/gen2brain/jpegxl v0.5.2 h1:1ou9YRziU8PbpkfFJIyxrNjYM+WaMl2n9LloABxkKsU=
github.com/gen2brain/jpegxl v0.5.2/go.mod h1:Wlc6lqx03RJfhiQRyHa2e+8VQwT4/qv7zSRsNv9T+yE=
github.com/gen2brain/webp v0.6.1 h1:ei7Y1SWpQcdqz3YNDNyn4y2nQanxs9WLzwW5/2DKS64=
github.com/gen2brain/webp v0.6.1/go.mod h1:iGWMaCSw7t3I/Cv9llzEKmpnR36S8lS8VL/ZVjxU0JE=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
@@ -56,6 +58,7 @@ github.com/go-errors/errors v1.5.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3Bop
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
github.com/golang/geo v0.0.0-20200319012246-673a6f80352d/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
github.com/golang/geo v0.0.0-20260625163123-7c0e84413537 h1:KeIaDS/+VEy/bhDYjG3Z78dOyLAU4HXcVxmd0WYHJTE=
github.com/golang/geo v0.0.0-20260625163123-7c0e84413537/go.mod h1:Mymr9kRGDc64JPr03TSZmuIBODZ3KyswLzm1xL0HFA8=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
@@ -64,8 +67,6 @@ github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyf
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 h1:YLvr1eE6cdCqjOe972w/cYF+FjW34v27+9Vo5106B4M=
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25/go.mod h1:kLgvv7o6UM+0QSf0QjAse3wReFDsb9qbZJdfexWlrQw=
github.com/jupiterrider/ffi v0.7.0 h1:RKsl6Ascal+3kyAqR5Qcbp83LceQMLc1VZbPfHWoNzs=
github.com/jupiterrider/ffi v0.7.0/go.mod h1:9dauhpOfNqrqk28fxuu0kkdeFtT9Qr4vbfigiuIXN7c=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.18.6 h1:2jupLlAwFm95+YDR+NwD2MEfFO9d4z4Prjl1XXDjuao=
github.com/klauspost/compress v1.18.6/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=