-
Notifications
You must be signed in to change notification settings - Fork 21
Image inference #217
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
Merged
Merged
Image inference #217
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c56ac45
Alter SnifferFileContent to work with fs.File
chocolatkey f715407
Add size property to Link
chocolatkey f9184ca
Prevent panic when HREF string is empty
chocolatkey c132136
Add WIP image analyzer
chocolatkey b7f4f18
Implement remote streaming of publications (#211)
chocolatkey 310bd35
fix archive reading EOF issue
chocolatkey 9a468c5
simplify exploded archive read
chocolatkey 7b1866e
Add link properties hash structure
chocolatkey 28d63f8
tidy LinkList usage
chocolatkey 4a9e404
improvements to image analyzer
chocolatkey 420865c
fix link test
chocolatkey f6d7e94
add note about hashes
chocolatkey aa472d2
add image inspection to rwp manifest utility
chocolatkey 9ceaecf
remove analyzer test utility
chocolatkey d744ca3
update dependencies
chocolatkey d282ef2
split rwp manifest code into helpers package
chocolatkey ed511a2
Add doc to image.Image, make imageProperties private
chocolatkey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package helpers | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| "github.com/readium/go-toolkit/pkg/streamer" | ||
| ) | ||
|
|
||
| type InferA11yMetadata streamer.InferA11yMetadata | ||
|
|
||
| // String is used both by fmt.Print and by Cobra in help text | ||
| func (e *InferA11yMetadata) String() string { | ||
| if e == nil { | ||
| return "no" | ||
| } | ||
| switch *e { | ||
| case InferA11yMetadata(streamer.InferA11yMetadataMerged): | ||
| return "merged" | ||
| case InferA11yMetadata(streamer.InferA11yMetadataSplit): | ||
| return "split" | ||
| default: | ||
| return "no" | ||
| } | ||
| } | ||
|
|
||
| func (e *InferA11yMetadata) Set(v string) error { | ||
| switch v { | ||
| case "no": | ||
| *e = InferA11yMetadata(streamer.InferA11yMetadataNo) | ||
| case "merged": | ||
| *e = InferA11yMetadata(streamer.InferA11yMetadataMerged) | ||
| case "split": | ||
| *e = InferA11yMetadata(streamer.InferA11yMetadataSplit) | ||
| default: | ||
| return errors.New(`must be one of "no", "merged", or "split"`) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Type is only used in help text. | ||
| func (e *InferA11yMetadata) Type() string { | ||
| return "string" | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package helpers | ||
|
|
||
| import ( | ||
| "io/fs" | ||
|
|
||
| "github.com/pkg/errors" | ||
| "github.com/readium/go-toolkit/pkg/analyzer" | ||
| "github.com/readium/go-toolkit/pkg/manifest" | ||
| ) | ||
|
|
||
| type ImageInspector struct { | ||
| Filesystem fs.FS | ||
| Algorithms []manifest.HashAlgorithm | ||
| err error | ||
| } | ||
|
|
||
| func (n *ImageInspector) Error() error { | ||
| return n.err | ||
| } | ||
|
|
||
| // TransformHREF implements ManifestTransformer | ||
| func (n *ImageInspector) TransformHREF(href manifest.HREF) manifest.HREF { | ||
| // Identity | ||
| return href | ||
| } | ||
|
|
||
| // TransformLink implements ManifestTransformer | ||
| func (n *ImageInspector) TransformLink(link manifest.Link) manifest.Link { | ||
| if n.err != nil || link.MediaType == nil || !link.MediaType.IsBitmap() { | ||
| return link | ||
| } | ||
|
|
||
| newLink, err := analyzer.Image(n.Filesystem, link, n.Algorithms) | ||
| if err != nil { | ||
| n.err = errors.Wrap(err, "failed inspecting image "+link.Href.String()) | ||
| return link | ||
| } | ||
| return *newLink | ||
| } | ||
|
|
||
| // TransformManifest implements ManifestTransformer | ||
| func (n *ImageInspector) TransformManifest(manifest manifest.Manifest) manifest.Manifest { | ||
| // Identity | ||
| return manifest | ||
| } | ||
|
|
||
| // TransformMetadata implements ManifestTransformer | ||
| func (n *ImageInspector) TransformMetadata(metadata manifest.Metadata) manifest.Metadata { | ||
| // Identity | ||
| return metadata | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.