GithubHelp home page GithubHelp logo

Comments (6)

Kagami avatar Kagami commented on August 15, 2024

The simplest way is to add from_u16 method which would create Frame from u16 planes.

A bit better method is to implement #11 and accept either u8 or u16 depending on the colorspace. But it would be impossible to create high bitdepth frame from u8 planes then (unless introducing something like from_u8).

Also I'm not entirely sure y4m should deal with concept of pixels. Because u8 vs u16 is about the pixel values, not the data stream. Any frame can be represented as a stream of u8.

What do you think?

from y4m.

rzumer avatar rzumer commented on August 15, 2024

Handling pixel values instead of raw data does introduce some additional concerns. We can leave it as is and leave the user with the responsibility of providing the raw data in u8 format. On the other hand, converting from high bit depth u16 data to u8 in safe Rust seems to require a significant amount of boilerplate for a use case that should be fairly common, so there is a clear benefit in handling this conversion as part of y4m.

from y4m.

Kagami avatar Kagami commented on August 15, 2024

for a use case that should be fairly common

Seems like it, accepting u16 planes might give better user experience in real world use-cases.

Would you like to implement from_u16 for Frame?

from y4m.

rzumer avatar rzumer commented on August 15, 2024

Sure, I will give it a try.

The conversion could look like this:

planes.iter().map(|&plane| plane.iter()
        .flat_map(|&plane_value| vec![(plane_value >> 8) as u8, plane_value as u8])
        .collect()).collect();

Which results in a Vec<Vec<u8>>. Afterwards slicing the inner vectors for 3 planes should be enough, but due to the Frame structure containing a reference to frame data rather than owning that data, I have not been able to figure out a clean way to persist this processed data, as the borrow dies as the constructor returns. Changing plane data to a vector type would allow it to own the data, but I'm not sure that this is desirable.

from y4m.

Kagami avatar Kagami commented on August 15, 2024

(Haven't seen github notifications for last post editings.)

I think we should unsafely represent u16 as u8 with from_raw_parts.

from y4m.

rzumer avatar rzumer commented on August 15, 2024

OK, I was trying to avoid unsafe code but that should work, I will try it soon.

from y4m.

Related Issues (11)

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.