Skip to content
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

Have JpegEncoder::new take an owned writer #1608

Merged
merged 1 commit into from
Nov 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/codecs/jpeg/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ struct Component {
_dc_pred: i32,
}

pub(crate) struct BitWriter<'a, W: 'a> {
w: &'a mut W,
pub(crate) struct BitWriter<W> {
w: W,
accumulator: u32,
nbits: u8,
}

impl<'a, W: Write + 'a> BitWriter<'a, W> {
fn new(w: &'a mut W) -> Self {
impl<W: Write> BitWriter<W> {
fn new(w: W) -> Self {
BitWriter {
w,
accumulator: 0,
Expand Down Expand Up @@ -335,8 +335,8 @@ impl Default for PixelDensity {
}

/// The representation of a JPEG encoder
pub struct JpegEncoder<'a, W: 'a> {
writer: BitWriter<'a, W>,
pub struct JpegEncoder<W> {
writer: BitWriter<W>,

components: Vec<Component>,
tables: Vec<[u8; 64]>,
Expand All @@ -349,16 +349,16 @@ pub struct JpegEncoder<'a, W: 'a> {
pixel_density: PixelDensity,
}

impl<'a, W: Write> JpegEncoder<'a, W> {
impl<W: Write> JpegEncoder<W> {
/// Create a new encoder that writes its output to ```w```
pub fn new(w: &mut W) -> JpegEncoder<W> {
pub fn new(w: W) -> JpegEncoder<W> {
JpegEncoder::new_with_quality(w, 75)
}

/// Create a new encoder that writes its output to ```w```, and has
/// the quality parameter ```quality``` with a value in the range 1-100
/// where 1 is the worst and 100 is the best.
pub fn new_with_quality(w: &mut W, quality: u8) -> JpegEncoder<W> {
pub fn new_with_quality(w: W, quality: u8) -> JpegEncoder<W> {
let components = vec![
Component {
id: LUMAID,
Expand Down Expand Up @@ -663,7 +663,7 @@ impl<'a, W: Write> JpegEncoder<'a, W> {
}
}

impl<'a, W: Write> ImageEncoder for JpegEncoder<'a, W> {
impl<W: Write> ImageEncoder for JpegEncoder<W> {
fn write_image(
mut self,
buf: &[u8],
Expand Down