8000 better handling of rgb8, removing some code duplication by blefaudeux · Pull Request #101 · Photoroom/datago · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

better handling of rgb8, removing some code duplication #101

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 1 commit into from
Mar 25, 2025
Merged

Conversation

blefaudeux
Copy link
Contributor

tackle #100 and #93

@pytest.mark.parametrize("pre_encode_images", [False, True])
def test_get_sample_filesystem(pre_encode_images: bool):
@pytest.mark.parametrize(
["pre_encode_images", "rgb16", "rgba"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

making the test a bit more complete, generate test cases

// Encode the image if needed
let mut image_bytes: Vec<u8> = Vec::new();
if encode_images {
if new_image.color() != image::ColorType::Rgb8 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

what you were seeing was not a bug per say @tarek-ayed, it's just that the sanitization was coupled with image encoding, this PR decouples the two

if encode_images {
if new_image.color() != image::ColorType::Rgb8 {
new_image = image::DynamicImage::ImageRgb8(new_image.to_rgb8());
bit_depth = (new_image.color().bits_per_pixel()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

there was a small bug here though, in that channels was not updated, so RGBA would return 4 channels. Fixed

channels,
bit_depth,
})
Ok(new_image) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored, both codepaths were essentially doing the same thing, now in a dedicated function

@@ -58,9 +62,16 @@ def test_get_sample_filesystem(pre_encode_images: bool):
assert data.image.width == 100
assert data.image.height == 100

if pre_encode_images:
if rgb16:
Copy link
Contributor

Choose a reason for hiding this comment

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

I got a bit confused by the name of the variable
rgb16 means "convert RGB 16 to RGB 8" right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's "test rgb16 conversion by generating a rgb16 and checking that it's a rgb8 at the end of the pipe" really, sorry that it's not super clear

Copy link
Contributor
@tarek-ayed tarek-ayed 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! Thanks!

@blefaudeux blefaudeux merged commit d37cd31 into main Mar 25, 2025
8 checks passed
Copy link
Contributor
@photoroman photoroman left a comment

Choose a reason for hiding this comment

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

Looks great!



def generate_tmp_files(dir, limit):
def generate_tmp_files(dir: str, limit: int, rgb16: bool = False, rgba: bool = False):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This is a good candidate for using pytest fixtures. It allows you to make sure that test resources are cleaned up and you can also parametrize them and have one resource depend on another one etc.

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
0