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
Improve encode_gray performance in BmpEncoder #2193
Conversation
Could you share any benchmarks results you've measured from these changes? |
src/codecs/bmp/encoder.rs
Outdated
// alpha is never written as it's not widely supported | ||
|
||
// color value is equal to the palette index | ||
if bytes_per_pixel == 1 { |
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.
Could you make this x_stride == 1
?
src/codecs/bmp/encoder.rs
Outdated
} | ||
// alpha is never written as it's not widely supported |
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.
Could you move this comment into the else
branch?
src/codecs/bmp/encoder.rs
Outdated
// improve performance by writing the whole row at once | ||
let row_end = row_start + y_stride; | ||
self.writer | ||
.write_all(&image[row_start as usize..row_end as usize])?; |
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.
Mostly comes down to style, but I think this would be slightly nicer as .write_all(&image[row_start as usize..][..y_stride as usize]
@fintelia |
Thanks! |
Hi
image-rs
team,This Pull Request focuses on enhancing the performance of the encode_gray function within BmpEncoder.
It optimizes the buffer writing process, thereby improving the overall execution speed of the function.
This modification has significantly improved the encoding speed for large-resolution BMP files.