-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add no_std support #226
Open
vstroebel
wants to merge
7
commits into
image-rs:master
Choose a base branch
from
vstroebel:no_std_working
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add no_std support #226
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ccc2dcb
Introduce JpegRead
vstroebel 5c514ee
Add/Change some use statements to use core/alloc
vstroebel be53dbe
Use integer arithmetics to calculate output size
vstroebel 861da02
Replace f32::fract with no_std compliant version
vstroebel ef5f1de
Add no_std compliant integration test
vstroebel a1e586b
Add std feature for no_std support
vstroebel 529b616
Add no_std tests to github actions
vstroebel 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
Replace f32::fract with no_std compliant version
- Loading branch information
commit 861da025067a3af7ac7599dd47d95c9fb50af45c
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,6 +164,13 @@ impl Upsample for UpsamplerH2V1 { | |
} | ||
} | ||
|
||
// no_std version to calculate fractional part of positive numbers | ||
fn fract(v: f32) -> f32 { | ||
debug_assert!(v >= 0.0 && v <= (1 << core::f32::MANTISSA_DIGITS - 1) as f32); | ||
let int = v as usize as f32; | ||
v - int | ||
} | ||
|
||
impl Upsample for UpsamplerH1V2 { | ||
fn upsample_row(&self, | ||
input: &[u8], | ||
|
@@ -176,7 +183,7 @@ impl Upsample for UpsamplerH1V2 { | |
let row_near = row as f32 / 2.0; | ||
// If row_near's fractional is 0.0 we want row_far to be the previous row and if it's 0.5 we | ||
// want it to be the next row. | ||
let row_far = (row_near + row_near.fract() * 3.0 - 0.25).min((input_height - 1) as f32); | ||
let row_far = (row_near + fract(row_near) * 3.0 - 0.25).min((input_height - 1) as f32); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we not just use integer fixed-point math here? |
||
|
||
let input_near = &input[row_near as usize * row_stride ..]; | ||
let input_far = &input[row_far as usize * row_stride ..]; | ||
|
@@ -202,7 +209,7 @@ impl Upsample for UpsamplerH2V2 { | |
let row_near = row as f32 / 2.0; | ||
// If row_near's fractional is 0.0 we want row_far to be the previous row and if it's 0.5 we | ||
// want it to be the next row. | ||
let row_far = (row_near + row_near.fract() * 3.0 - 0.25).min((input_height - 1) as f32); | ||
let row_far = (row_near + fract(row_near) * 3.0 - 0.25).min((input_height - 1) as f32); | ||
|
||
let input_near = &input[row_near as usize * row_stride ..]; | ||
let input_far = &input[row_far as usize * row_stride ..]; | ||
|
@@ -250,3 +257,17 @@ impl Upsample for UpsamplerGeneric { | |
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::upsampler::fract; | ||
|
||
#[test] | ||
fn test_fract() { | ||
let value = 3.6_f32; | ||
let frac = fract(value); | ||
let diff = frac - 0.6_f32; | ||
|
||
assert!(diff >= -core::f32::EPSILON && diff <= core::f32::EPSILON); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are doing this for positive numbers only, then why isn't it using
f32::floor()
? How does the conversion tousize
work but not thefract()
method? I'm just super confused. This needs better justification/eval of alternatives before affectingstd
code as well.