GithubHelp home page GithubHelp logo

TRUECOLOR vs RGB8 about libspng HOT 4 OPEN

GhostCore07 avatar GhostCore07 commented on June 15, 2024
TRUECOLOR vs RGB8

from libspng.

Comments (4)

randy408 avatar randy408 commented on June 15, 2024

Shouldn't color_type be of type enum spng_color_type rather than uint8_t ?

The fields have the same size as the described by the file format, but I'll probably change that for the next breaking version.

it's pretty confusing to have two different types enum spng_color_type and enum spng_format that have names with identical meaning

When decoding you're converting from ihdr to an spng_format, or from an spng_format to an ihdr when encoding. Formats are different, it's color type, channel order, bit depth and endianness in one enum except for SPNG_FMT_PNG, SPNG_FMT_RAW which only specify endianness and the rest is derived from ihdr.

from libspng.

GhostCore07 avatar GhostCore07 commented on June 15, 2024

The fields have the same size as the described by the file format

Correct. The issue is that you can assign a spng_format to uint8_t color_type due to enum implicitly cast to int. It's much better if the static checker to throw an error in this case.

When decoding you're converting from ihdr to an spng_format, or from an spng_format to an ihdr when encoding.

Thanks for the clarification. I understand the rational for having different types between encoding and decoding steps.

I will try to clarify the point I was trying to make with truecolor.

https://en.wikipedia.org/wiki/Color_depth#True_color_(24-bit)

True color (24-bit), the use of 24 bits to store color information
24 bits almost always use 8 bits each of R, G, and B

Therefore,
"TRUECOLOR" and "RGB8" have the exact same semantic meaning and it's confusing to try and understand why the API uses different words for the same thing.

In my opinion something like:
SPNG_COLOR_TYPE_RGBA8
SPNG_FMT_RGBA8

Makes it expressly clear that we are talking about a color type and a fmt type. Perhaps I will just make this a typedef for myself if you are not interested in changing the API.

from libspng.

randy408 avatar randy408 commented on June 15, 2024

The standard uses the term "truecolor", at the time it made sense to use the exact same words.

I wouldn't add something like SPNG_COLOR_TYPE_RGBA8 because the standard expresses color type and bit depth in separate fields. Some PNG libraries also have *_COLOR_TYPE_RGBA but bit depth is still a separate value.

Makes it expressly clear that we are talking about a color type and a fmt type.

But they already start with SPNG_COLOR_TYPE and SPNG_FMT 🤔

from libspng.

GhostCore07 avatar GhostCore07 commented on June 15, 2024

Doesn't seem too far of a reach to have a COLOR_TYPE that combines the "truecolour"-ness and the 8 or 16 bit-ness in a single flag. That's just an observation. I see now that would be innovating on the standard a little bit. From a practical standpoint I was surprised to not see it is all. Take it for what it's worth.

from libspng.

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.