Compare commits

..

1 Commits

Author SHA1 Message Date
d1265a5135
set static naive JFIF headers for compatibility with kindle 2024-06-18 12:41:15 +02:00
8 changed files with 26 additions and 26 deletions

1
go.mod
View File

@ -23,7 +23,6 @@ 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,8 +39,6 @@ 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 converter options manage options with default value from config.
// Package options manage options with default value from config.
package converter
import (

View File

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

View File

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

View File

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

View File

@ -227,7 +227,7 @@ func (o Content) getSpineAuto() []tag {
)
}
}
for i, img := range o.Images {
for _, img := range o.Images {
if (img.DoublePage || img.Part == 1) && o.ImageOptions.Manga == isOnTheRight {
spine = append(spine, tag{
"itemref",
@ -242,8 +242,6 @@ 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,8 +10,6 @@ import (
"image/jpeg"
"image/png"
"time"
mozJpeg "github.com/viam-labs/go-libjpeg/jpeg"
)
type Image struct {
@ -19,6 +17,18 @@ type Image struct {
Data []byte
}
var naiveJFIFHeader = []byte{
0xFF, 0xD8, // SOI
0xFF, 0xE0, // APP0 Marker
0x00, 0x10, // Length
0x4A, 0x46, 0x49, 0x46, 0x00, // JFIF\0
0x01, 0x02, // 1.02
0x00, // Density type
0x00, 0x01, // X Density
0x00, 0x01, // Y Density
0x00, 0x00, // No Thumbnail
}
// CompressImage create gzip encoded jpeg
func CompressImage(filename string, format string, img image.Image, quality int) (Image, error) {
var (
@ -30,15 +40,11 @@ func CompressImage(filename string, format string, img image.Image, quality int)
case "png":
err = png.Encode(&data, img)
case "jpeg":
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})
}
// static JFIF header for better compatibility with Kindle devices
var b bytes.Buffer
err = jpeg.Encode(&b, img, &jpeg.Options{Quality: quality})
data.Write(naiveJFIFHeader)
data.Write(b.Bytes()[2:])
default:
err = fmt.Errorf("unknown format %q", format)
}