Click here to Skip to main content
15,887,434 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Ducks that like to ... Pin
MarkTJohnson2-Oct-23 9:58
professionalMarkTJohnson2-Oct-23 9:58 
GeneralRe: Ducks that like to ... Pin
megaadam4-Oct-23 21:50
professionalmegaadam4-Oct-23 21:50 
Generalworld 619 2/6 Pin
jmaida2-Oct-23 8:00
jmaida2-Oct-23 8:00 
GeneralFinishing a hobby project Pin
honey the codewitch2-Oct-23 6:48
mvahoney the codewitch2-Oct-23 6:48 
GeneralRe: Finishing a hobby project Pin
Gerry Schmitz2-Oct-23 8:25
mveGerry Schmitz2-Oct-23 8:25 
GeneralRe: Finishing a hobby project Pin
honey the codewitch2-Oct-23 8:31
mvahoney the codewitch2-Oct-23 8:31 
GeneralRe: Finishing a hobby project Pin
Gerry Schmitz2-Oct-23 8:44
mveGerry Schmitz2-Oct-23 8:44 
GeneralRe: Finishing a hobby project Pin
honey the codewitch2-Oct-23 9:02
mvahoney the codewitch2-Oct-23 9:02 
That was the first thing I did in htcw_gfx (GFX)

I wrote a pixel template that allows you to define its binary footprint and color model using a series of "channel_trait" template instantiations that define the channel properties. Many pixels have R G and B channels, but it's not limited to that. Defining each channel individually to make up a pixel allows me to support virtually any binary footprint and color model. I made a brief pixel declaration in my Winduino example for my GFX lib to write out in DirectX native 32bit BGRx format.

From there I wrote a bitmap template class, which is basically a variable that holds pixel data. It can be written to as it itself is a draw target (both draw destination and draw source) or read from and applied to other draw targets. It's templated by the type of pixel (as above, for example RGB565) and the type of palette (if any)

It's so abstract I can support other formats and screen styles by changing barely anything. All my draw routines take pixels in any format and do behind the scenes conversion transparently (w/ alpha blending as available and called for)

I've written whole applications, only to have the screen hardware changed on me last minute. Takes me minutes to update, if I already wrote it to be resolution agnostic (which I typically do)

Here's a series of pixel declaration templates for color models of various types (including grayscale and indexed/palleted pixels) non-exaustive, just so you can see what it looks like:

C++
// creates an RGB pixel by making each channel 
// one third of the whole. Any remainder bits
// are added to the green channel
template<size_t BitDepth>
using rgb_pixel = pixel<
    channel_traits<channel_name::R,(BitDepth/3)>,
    channel_traits<channel_name::G,((BitDepth/3)+(BitDepth%3))>,
    channel_traits<channel_name::B,(BitDepth/3)>
>;
// creates an RGBA pixel by making each channel 
// one quarter of the whole. Any remainder bits
// are added to the green channel
template<size_t BitDepth>
using rgba_pixel = pixel<
    channel_traits<channel_name::R,(BitDepth/4)>,
    channel_traits<channel_name::G,((BitDepth/4)+(BitDepth%4))>,
    channel_traits<channel_name::B,(BitDepth/4)>,
    channel_traits<channel_name::A,(BitDepth/4),0,(1<<(BitDepth/4))-1,(1<<(BitDepth/4))-1>
>;
// creates a grayscale or monochome pixel
template<size_t BitDepth>
using gsc_pixel = pixel<
    channel_traits<channel_name::L,BitDepth>
>;
// creates a Y'UV pixel by making each channel 
// one third of the whole. Any remainder bits
// are added to the Y' channel
template<size_t BitDepth>
using yuv_pixel = pixel<
    channel_traits<channel_name::Y,((BitDepth/3)+(BitDepth%3))>,
    channel_traits<channel_name::U,(BitDepth/3)>,
    channel_traits<channel_name::V,(BitDepth/3)>
>;
// creates a Y'UV/A pixel by making each 
// channel 1/4 of the whole. Remaining bits
// are added to Y'
template<size_t BitDepth>
using yuva_pixel = pixel<
    channel_traits<channel_name::Y,((BitDepth/4)+(BitDepth%4))>,
    channel_traits<channel_name::U,(BitDepth/4)>,
    channel_traits<channel_name::V,(BitDepth/4)>,
    channel_traits<channel_name::A,(BitDepth/4),0,(1<<(BitDepth/4))-1,(1<<(BitDepth/4))-1>
>;

// creates a YCbCr pixel by making each channel 
// one third of the whole. Any remainder bits
// are added to the Y channel
template<size_t BitDepth>
using ycbcr_pixel = pixel<
    channel_traits<channel_name::Y,((BitDepth/3)+(BitDepth%3))>,
    channel_traits<channel_name::Cb,(BitDepth/3)>,
    channel_traits<channel_name::Cr,(BitDepth/3)>
>;
// creates a ycbcr pixel by making each 
// channel 1/4 of the whole. Remaining bits
// are added to Y
template<size_t BitDepth>
using ycbcra_pixel = pixel<
    channel_traits<channel_name::Y,((BitDepth/4)+(BitDepth%4))>,
    channel_traits<channel_name::Cb,(BitDepth/4)>,
    channel_traits<channel_name::Cr,(BitDepth/4)>,
    channel_traits<channel_name::A,(BitDepth/4),0,(1<<(BitDepth/4))-1,(1<<(BitDepth/4))-1>
>;
// creates an indexed pixel
template<size_t BitDepth>
using indexed_pixel=pixel<channel_traits<channel_name::index,BitDepth>>;


You then use them like

C++
gfx::rgb_pixel<16> px = gfx::color<gfx::rgb_pixel<16>>::purple; // creates an RGB565 pixel using the above template and purple color

px.channel<gfx::channel_name::G>(31); // set green to half

float r = px.channelr<gfx::channel_name::R>(); // get the red as a real number (scaled 0-1)

Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix


modified 2-Oct-23 15:11pm.

JokeJOTD Pin
Mike Hankey2-Oct-23 5:30
mveMike Hankey2-Oct-23 5:30 
GeneralRe: JOTD Pin
jeron12-Oct-23 5:55
jeron12-Oct-23 5:55 
GeneralRe: JOTD Pin
jmaida2-Oct-23 10:35
jmaida2-Oct-23 10:35 
GeneralRe: JOTD Pin
jeron12-Oct-23 10:57
jeron12-Oct-23 10:57 
GeneralRe: JOTD Pin
Gary R. Wheeler3-Oct-23 8:27
Gary R. Wheeler3-Oct-23 8:27 
GeneralRe: JOTD Pin
honey the codewitch2-Oct-23 6:51
mvahoney the codewitch2-Oct-23 6:51 
GeneralRe: JOTD Pin
Mike Hankey2-Oct-23 7:10
mveMike Hankey2-Oct-23 7:10 
GeneralRe: JOTD Pin
Nelek2-Oct-23 12:42
protectorNelek2-Oct-23 12:42 
GeneralRe: JOTD Pin
Mike Hankey2-Oct-23 12:45
mveMike Hankey2-Oct-23 12:45 
GeneralRe: JOTD Pin
Nelek2-Oct-23 20:00
protectorNelek2-Oct-23 20:00 
GeneralRe: JOTD Pin
dandy724-Oct-23 3:32
dandy724-Oct-23 3:32 
GeneralRe: JOTD Pin
trønderen4-Oct-23 8:36
trønderen4-Oct-23 8:36 
GeneralRe: JOTD Pin
dandy724-Oct-23 10:30
dandy724-Oct-23 10:30 
GeneralRe: JOTD Pin
trønderen4-Oct-23 10:46
trønderen4-Oct-23 10:46 
GeneralRe: JOTD Pin
PIEBALDconsult2-Oct-23 7:43
mvePIEBALDconsult2-Oct-23 7:43 
GeneralRe: JOTD Pin
jmaida2-Oct-23 7:44
jmaida2-Oct-23 7:44 
GeneralRe: JOTD Pin
Daniel Pfeffer2-Oct-23 8:51
professionalDaniel Pfeffer2-Oct-23 8:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.