Git Product home page Git Product logo

Comments (6)

fintelia avatar fintelia commented on September 26, 2024 2

The API could use DynamicImage::write_with_encoder. Analogous to how you can control compression parameters for JPEG:

let encoder = JpegEncoder::new_with_quality(&mut writer, 95);
img.write_with_encoder(encoder)?;

That said, TGA compression is not great by modern standards. If you can use a different format, you'll likely get better compression

from image.

marvin-j97 avatar marvin-j97 commented on September 26, 2024

That said, TGA compression is not great by modern standards. If you can use a different format, you'll likely get better compression

It's not my choice, unfortunately ๐Ÿ˜

The API could use DynamicImage::write_with_encoder

So a possible API could be:

pub struct TgaEncoder<W: Write> {
    writer: W,
    use_rle: bool,
}

impl<W: Write> for TgaEncoder<W> {
  // ... new

  pub fn with_rle(w: W) -> TgaEncoder<W> {
    TgaEncoder {
      writer: w,
      use_rle: true,
    }
  }

  pub fn use_rle(mut self) -> TgaEncoder<W> {
    self.use_rle = true;
    self
  }
}

let encoder = TgaEncoder::with_rle(&mut writer);
// or
let encoder = TgaEncoder::new(&mut writer).use_rle();
img.write_with_encoder(encoder);

from image.

fintelia avatar fintelia commented on September 26, 2024

Yeah. Though, I'd probably suggest calling it "rle" or "compression" or something like that. Even the uncompressed version still counts as "encoding".

Another question is whether it makes more sense to add the new option as a constructor ("with_rle") or as a setter ("set_rle"). I think the existing encoders all use constructors, but that doesn't seem as sustainable if we add more options...

from image.

marvin-j97 avatar marvin-j97 commented on September 26, 2024

Yeah. Though, I'd probably suggest calling it "rle" or "compression" or something like that. Even the uncompressed version still counts as "encoding".

Another question is whether it makes more sense to add the new option as a constructor ("with_rle") or as a setter ("set_rle"). I think the existing encoders all use constructors, but that doesn't seem as sustainable if we add more options...

Updated ๐Ÿ‘

from image.

marvin-j97 avatar marvin-j97 commented on September 26, 2024

I'm trying to read a bit into the code, and just documenting my thoughts.

Looks like tga::Header::from_pixel_data would need another parameter use_rle, and extend the match from:

match color_type {
  ColorType::Rgba8 => (8, 24, ImageType::RawTrueColor),
  // ...
}

to

match (color_type, use_rle) {
  (ColorType::Rgba8, false) => (8, 24, ImageType::RawTrueColor),
  (ColorType::Rgba8, true) => (8, 24, ImageType::RunTrueColor),
  // ... etc
}

Need to check the spec to see if this is the only change required for header.rs.

from image.

marvin-j97 avatar marvin-j97 commented on September 26, 2024

Here's my first pass for TGA RLE support:

#2056

from image.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.