add libjpeg-turbo

This commit is contained in:
Celogeek 2023-07-04 09:44:02 +02:00
parent 9a1d62c583
commit a3c9667d63
Signed by: celogeek
SSH Key Fingerprint: SHA256:DEDfxIK2nUWXbslbRkww3zsauDjhWHlTXar+ak4lDJ4
5 changed files with 54 additions and 7 deletions

1
go.mod
View File

@ -23,6 +23,7 @@ require (
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/rivo/uniseg v0.4.4 // indirect github.com/rivo/uniseg v0.4.4 // indirect
github.com/stretchr/testify v1.8.4 // indirect github.com/stretchr/testify v1.8.4 // indirect
github.com/viam-labs/go-libjpeg v0.3.1 // indirect
golang.org/x/net v0.10.0 // indirect golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect golang.org/x/term v0.8.0 // indirect

2
go.sum
View File

@ -40,6 +40,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e h1:IWllFTiDjjLIf2oeKxpIUmtiDV5sn71VgeQgg6vcE7k= github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e h1:IWllFTiDjjLIf2oeKxpIUmtiDV5sn71VgeQgg6vcE7k=
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e/go.mod h1:d7u6HkTYKSv5m6MCKkOQlHwaShTMl3HjqSGW3XtVhXM= github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e/go.mod h1:d7u6HkTYKSv5m6MCKkOQlHwaShTMl3HjqSGW3XtVhXM=
github.com/viam-labs/go-libjpeg v0.3.1 h1:J/byavXHFqRI1PFPrnPbP+wFCr1y+Cn1CwKXrORCPD0=
github.com/viam-labs/go-libjpeg v0.3.1/go.mod h1:b0ISpf9lJv9MO1h1gXAmSA/osG19cKGYjfYc6aeEjqs=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=

View File

@ -0,0 +1,17 @@
//go:build !turbo
package epubimageprocessor
import (
"image"
_ "image/jpeg"
_ "image/png"
"io"
_ "golang.org/x/image/webp"
)
func DecodeImage(name string, f io.ReadCloser) (img image.Image, err error) {
img, _, err = image.Decode(f)
return
}

View File

@ -0,0 +1,31 @@
//go:build turbo
package epubimageprocessor
import (
"fmt"
"image"
_ "image/jpeg"
_ "image/png"
"io"
"path/filepath"
"strings"
_ "golang.org/x/image/webp"
turbojpeg "github.com/viam-labs/go-libjpeg/jpeg"
)
func DecodeImage(name string, f io.ReadCloser) (img image.Image, err error) {
switch strings.ToLower(filepath.Ext(name)) {
case ".jpeg", ".jpg":
img, err = turbojpeg.Decode(f, &turbojpeg.DecoderOptions{})
if err != nil {
fmt.Println(err)
img, _, err = image.Decode(f)
}
default:
img, _, err = image.Decode(f)
}
return
}

View File

@ -6,8 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"image" "image"
_ "image/jpeg"
_ "image/png"
"io" "io"
"io/fs" "io/fs"
"os" "os"
@ -16,8 +14,6 @@ import (
"strings" "strings"
"sync" "sync"
_ "golang.org/x/image/webp"
"github.com/celogeek/go-comic-converter/v2/internal/sortpath" "github.com/celogeek/go-comic-converter/v2/internal/sortpath"
"github.com/nwaples/rardecode/v2" "github.com/nwaples/rardecode/v2"
pdfimage "github.com/raff/pdfreader/image" pdfimage "github.com/raff/pdfreader/image"
@ -125,7 +121,7 @@ func (e *EPUBImageProcessor) loadDir() (totalImages int, output chan *tasks, err
fmt.Fprintf(os.Stderr, "\nerror processing image %s: %s\n", job.Path, err) fmt.Fprintf(os.Stderr, "\nerror processing image %s: %s\n", job.Path, err)
os.Exit(1) os.Exit(1)
} }
img, _, err = image.Decode(f) img, err = DecodeImage(job.Path, f)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "\nerror processing image %s: %s\n", job.Path, err) fmt.Fprintf(os.Stderr, "\nerror processing image %s: %s\n", job.Path, err)
os.Exit(1) os.Exit(1)
@ -217,7 +213,7 @@ func (e *EPUBImageProcessor) loadCbz() (totalImages int, output chan *tasks, err
fmt.Fprintf(os.Stderr, "\nerror processing image %s: %s\n", job.F.Name, err) fmt.Fprintf(os.Stderr, "\nerror processing image %s: %s\n", job.F.Name, err)
os.Exit(1) os.Exit(1)
} }
img, _, err = image.Decode(f) img, err = DecodeImage(job.F.Name, f)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "\nerror processing image %s: %s\n", job.F.Name, err) fmt.Fprintf(os.Stderr, "\nerror processing image %s: %s\n", job.F.Name, err)
os.Exit(1) os.Exit(1)
@ -336,7 +332,7 @@ func (e *EPUBImageProcessor) loadCbr() (totalImages int, output chan *tasks, err
fmt.Fprintf(os.Stderr, "\nerror processing image %s: %s\n", job.Name, err) fmt.Fprintf(os.Stderr, "\nerror processing image %s: %s\n", job.Name, err)
os.Exit(1) os.Exit(1)
} }
img, _, err = image.Decode(f) img, err = DecodeImage(job.Name, f)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "\nerror processing image %s: %s\n", job.Name, err) fmt.Fprintf(os.Stderr, "\nerror processing image %s: %s\n", job.Name, err)
os.Exit(1) os.Exit(1)