Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch thumbnail image resize library #18

Merged
merged 5 commits into from
May 27, 2019
Merged

Switch thumbnail image resize library #18

merged 5 commits into from
May 27, 2019

Conversation

shermp
Copy link
Owner

@shermp shermp commented May 25, 2019

This PR changes the image resizing library used from disintegration/imaging to bamiaux/rez, as discussed in #16

The change is primarily around performance. An initial "full thumbnail" test using the bicubic algorithm seems very promising performance wise.

I have also exposed some thumbnail generation configuration to the user in ku.toml. See that file for available options. This allows us to test various options and combinations to come up with a sane set of defaults, and to allow easy experimentation.

@NiLuJe would you mind testing this please?
@geek1011 would you mind reviewing the code on this please?

@shermp shermp changed the title Switch thumbnail generation library Switch thumbnail image resize library May 25, 2019
@NiLuJe
Copy link
Contributor

NiLuJe commented May 25, 2019

That is indeed much better :).

May 25 14:15:05 KoboUNCaGED[2031]: 2019/05/25 14:15:05 Resizing (887,1429) cover to (887,1429) (target (1080,1429)) for N3_FULL
May 25 14:15:05 KoboUNCaGED[2031]: 2019/05/25 14:15:05  -- Skipped resize: already correct size
May 25 14:15:06 KoboUNCaGED[2031]: 2019/05/25 14:15:06 Resizing (887,1429) cover to (355,571) (target (355,530)) for N3_LIBRARY_FULL
May 25 14:15:06 KoboUNCaGED[2031]: 2019/05/25 14:15:06  -- Resized to (355,571)
May 25 14:15:07 KoboUNCaGED[2031]: 2019/05/25 14:15:07 Resizing (887,1429) cover to (149,240) (target (149,223)) for N3_LIBRARY_GRID
May 25 14:15:07 KoboUNCaGED[2031]: 2019/05/25 14:15:07  -- Resized to (149,240)
May 25 14:15:07 KoboUNCaGED[2031]: 2019/05/25 14:15:07 Resizing (903,1429) cover to (903,1429) (target (1080,1429)) for N3_FULL
May 25 14:15:07 KoboUNCaGED[2031]: 2019/05/25 14:15:07  -- Skipped resize: already correct size
May 25 14:15:08 KoboUNCaGED[2031]: 2019/05/25 14:15:08 Resizing (903,1429) cover to (355,561) (target (355,530)) for N3_LIBRARY_FULL
May 25 14:15:08 KoboUNCaGED[2031]: 2019/05/25 14:15:08  -- Resized to (355,561)
May 25 14:15:09 KoboUNCaGED[2031]: 2019/05/25 14:15:09 Resizing (903,1429) cover to (149,235) (target (149,223)) for N3_LIBRARY_GRID
May 25 14:15:09 KoboUNCaGED[2031]: 2019/05/25 14:15:09  -- Resized to (149,235)
May 25 14:15:12 KoboUNCaGED[2031]: 2019/05/25 14:15:12 Resizing (943,1429) cover to (943,1429) (target (1080,1429)) for N3_FULL
May 25 14:15:12 KoboUNCaGED[2031]: 2019/05/25 14:15:12  -- Skipped resize: already correct size
May 25 14:15:13 KoboUNCaGED[2031]: 2019/05/25 14:15:13 Resizing (943,1429) cover to (355,537) (target (355,530)) for N3_LIBRARY_FULL
May 25 14:15:14 KoboUNCaGED[2031]: 2019/05/25 14:15:14  -- Resized to (355,537)
May 25 14:15:14 KoboUNCaGED[2031]: 2019/05/25 14:15:14 Resizing (943,1429) cover to (149,225) (target (149,223)) for N3_LIBRARY_GRID
May 25 14:15:14 KoboUNCaGED[2031]: 2019/05/25 14:15:14  -- Resized to (149,225)

That's with a tiny bit of extra logging just to make things obvious ;).

diff --git a/kobo-uncaged/main.go b/kobo-uncaged/main.go
index 95cecd4..660cf25 100644
--- a/kobo-uncaged/main.go
+++ b/kobo-uncaged/main.go
@@ -518,6 +518,7 @@ func (ku *KoboUncaged) saveCoverImage(contentID string, size image.Point, imgB64
                if !sz.Eq(nsz) {
                        nimg = image.NewYCbCr(image.Rect(0, 0, nsz.X, nsz.Y), img.(*image.YCbCr).SubsampleRatio)
                        rez.Convert(nimg, img, ku.KuConfig.Thumbnail.rezFilter)
+                       log.Printf(" -- Resized to %s\n", nimg.Bounds().Size())
                } else {
                        nimg = img
                        log.Println(" -- Skipped resize: already correct size")

@shermp
Copy link
Owner Author

shermp commented May 25, 2019

How's the quality? Seemed fine to me, but I'm not picky...

@NiLuJe
Copy link
Contributor

NiLuJe commented May 25, 2019

Yup, it's in the same ballpark as what Calibre would do.

@shermp
Copy link
Owner Author

shermp commented May 25, 2019

Yup, it's in the same ballpark as what Calibre would do.

Cool.

It's never going to be great anyway. IIRC calibre sends the thumbnail at 75 JPEG quality to begin with.

@NiLuJe
Copy link
Contributor

NiLuJe commented May 25, 2019

FWIW, the original cover (the one stored in the Library) is encoded @ 95, and the ones sent over USB @ 90.

@shermp
Copy link
Owner Author

shermp commented May 25, 2019

FWIW, the original cover (the one stored in the Library) is encoded @ 95, and the ones sent over USB @ 90.

Just double checked. The default quality for the wireless server is indeed 75. It's configurable by the user though in the "device options" when KU (or CC) is connected

@shermp shermp marked this pull request as ready for review May 27, 2019 01:00
@shermp
Copy link
Owner Author

shermp commented May 27, 2019

Well, I've heard no screams, so unless there are any concern, I'll merge this one.

Copy link
Contributor

@pgaskin pgaskin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general.

go.mod Outdated Show resolved Hide resolved
kobo-uncaged/main.go Outdated Show resolved Hide resolved
@shermp
Copy link
Owner Author

shermp commented May 27, 2019

My only slight concern is I'm not 100% sure whether Calibre always sends the thumbnail as a JPEG. Current code doesn't deal with PNG at all, although it will error gracefully if a PNG is encountered.

Trying to navigate the Calibre source code is an exercise of frustration, i have to admit...

@pgaskin
Copy link
Contributor

pgaskin commented May 27, 2019

Try using sourcegraph, as it really helps navigate large codebases. Based on a quick glance, I'm pretty certain Calibre only sends JPEGs.

Update: Here's some proof: scale_image, cover_to_thumbnail, THUMBNAIL_WIDTH.

Update 2: And here's where it uses PNG thumbnails (content server, generating comic thumbnail, hanvon).

@NiLuJe
Copy link
Contributor

NiLuJe commented May 27, 2019

Yup, pretty sure it'll only ever send JPGs, and that the source (i.e., cover.jpg in the Library's book folder) can only ever be a JPG, too.

In fact, even if you feed the metadata editor a PNG cover, it'll re-encode it as a JPG and store that.

@shermp
Copy link
Owner Author

shermp commented May 27, 2019

Sounds good to me. Won't worry about it then, Thanks

@shermp shermp merged commit a49abba into master May 27, 2019
@shermp shermp deleted the thumbnail-rez branch May 27, 2019 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants