Compare commits

...

4 Commits

Author SHA1 Message Date
f33c095094
test mozJpeg 2024-06-23 11:28:45 +02:00
fee8a037dc
fix position 2024-06-22 12:21:05 +02:00
7e3f0d4fcc
fix doc 2024-06-22 11:56:29 +02:00
0c09c85763
fix aspect ratio computing 2024-06-22 11:56:19 +02:00
8 changed files with 26 additions and 10 deletions

1
go.mod
View File

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

2
go.sum
View File

@ -39,6 +39,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
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/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=
golang.org/x/image v0.16.0 h1:9kloLAKhUufZhA12l5fwnx2NZW39/we1UhBesW433jw=
golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=

View File

@ -1,4 +1,4 @@
// Package options manage options with default value from config.
// Package converter options manage options with default value from config.
package converter
import (

View File

@ -1,4 +1,4 @@
// Package profiles manage supported profiles for go-comic-converter.
// Package converter profiles manage supported profiles for go-comic-converter.
package converter
import (

View File

@ -312,9 +312,10 @@ func (e EPUB) computeAspectRatio(epubParts []epubPart) float64 {
return bestAspectRatio
}
func (e EPUB) computeViewPort(epubParts []epubPart) {
func (e EPUB) computeViewPort(epubParts []epubPart) (int, int) {
if e.Image.View.AspectRatio == -1 {
return //keep device size
//keep device size
return e.Image.View.Width, e.Image.View.Height
}
// readjusting view port
@ -325,9 +326,9 @@ func (e EPUB) computeViewPort(epubParts []epubPart) {
viewWidth, viewHeight := int(float64(e.Image.View.Height)/bestAspectRatio), int(float64(e.Image.View.Width)*bestAspectRatio)
if viewWidth > e.Image.View.Width {
e.Image.View.Height = viewHeight
return e.Image.View.Width, viewHeight
} else {
e.Image.View.Width = viewWidth
return viewWidth, e.Image.View.Height
}
}
@ -445,7 +446,7 @@ func (e EPUB) Write() error {
Json: e.Json,
})
e.computeViewPort(epubParts)
e.Image.View.Width, e.Image.View.Height = e.computeViewPort(epubParts)
for i, part := range epubParts {
ext := filepath.Ext(e.Output)
suffix := ""

View File

@ -1,4 +1,4 @@
// Package epuboptions EPUBOptions for EPUB creation.
// Package epuboptions for EPUB creation.
package epuboptions
type EPUBOptions struct {

View File

@ -227,7 +227,7 @@ func (o Content) getSpineAuto() []tag {
)
}
}
for _, img := range o.Images {
for i, img := range o.Images {
if (img.DoublePage || img.Part == 1) && o.ImageOptions.Manga == isOnTheRight {
spine = append(spine, tag{
"itemref",
@ -242,6 +242,8 @@ func (o Content) getSpineAuto() []tag {
tagAttrs{"idref": img.PageKey(), "properties": img.Position},
"",
})
// save position, img is a value type
o.Images[i] = img
}
if o.ImageOptions.Manga == isOnTheRight {
spine = append(spine, tag{

View File

@ -10,6 +10,8 @@ import (
"image/jpeg"
"image/png"
"time"
mozJpeg "github.com/viam-labs/go-libjpeg/jpeg"
)
type Image struct {
@ -28,7 +30,15 @@ func CompressImage(filename string, format string, img image.Image, quality int)
case "png":
err = png.Encode(&data, img)
case "jpeg":
err = jpeg.Encode(&data, img, &jpeg.Options{Quality: quality})
err = mozJpeg.Encode(&data, img, &mozJpeg.EncoderOptions{
Quality: quality,
OptimizeCoding: true,
ProgressiveMode: true,
DCTMethod: mozJpeg.DCTFloat,
})
if err != nil && err.Error() == "unsupported image type" {
err = jpeg.Encode(&data, img, &jpeg.Options{Quality: quality})
}
default:
err = fmt.Errorf("unknown format %q", format)
}