-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Image part hashing based on @shermp's Kobo-UNCaGED code. * Qt resizing algorithm re-implementation based on our (@NiLuJe, @geek1011) implementation for KU. * Path/ImageID/ContentID conversion based on my seriesmeta code from kepubify.
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
package kobo | ||
|
||
import ( | ||
"fmt" | ||
"image" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// PathToContentID generates the Kobo ContentId for a path relative to the | ||
// internal storage root (slashes are converted to forward slashes automatically). | ||
func PathToContentID(relpath string) string { | ||
return fmt.Sprintf("file:///mnt/onboard/%s", filepath.ToSlash(relpath)) | ||
} | ||
|
||
// ContentIDToImageID converts the Kobo ContentId to the ImageId. | ||
func ContentIDToImageID(contentID string) string { | ||
return strings.NewReplacer( | ||
" ", "_", | ||
"/", "_", | ||
":", "_", | ||
".", "_", | ||
).Replace(contentID) | ||
} | ||
|
||
// resizeKeepAspectRatio resizes sz to fill bounds while keeping the aspect | ||
// ratio. It is based on the code for QSize::scaled with the modes | ||
// Qt::KeepAspectRatio and Qt::KeepAspectRatioByExpanding. | ||
|
@@ -30,6 +48,20 @@ func resizeKeepAspectRatio(sz image.Point, bounds image.Point, expand bool) imag | |
return image.Pt(bounds.X, int(float64(bounds.X)/ar)) | ||
} | ||
|
||
// hashedImageParts returns the parts needed for constructing the path to the | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pgaskin
Author
Owner
|
||
// cached image. The result can be applied like: | ||
// .kobo-images/{dir1}/{dir2}/{basename} - N3_SOMETHING.jpg | ||
func hashedImageParts(imageID string) (dir1, dir2, basename string) { | ||
imgID := []byte(imageID) | ||
h := uint32(0x00000000) | ||
for _, x := range imgID { | ||
h = (h << 4) + uint32(x) | ||
h ^= (h & 0xf0000000) >> 23 | ||
h &= 0x0fffffff | ||
} | ||
return fmt.Sprintf("%d", h&(0xff*1)), fmt.Sprintf("%d", (h&(0xff00*1))>>8), imageID | ||
} | ||
|
||
func strSplitInt(str string) []int64 { | ||
spl := strings.Split(str, ".") | ||
ints := make([]int64, len(spl)) | ||
|
It's Qt4's QtHash, FWIW ;).
(c.f., https://github.com/NiLuJe/kfmon/blob/f19f8582e7b53d14b7a60cc5b8bc43bac1930b48/kfmon.c#L1096)