Click here to Skip to main content
15,887,027 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralNot a question, just a lament about metaprogramming Pin
honey the codewitch28-Oct-23 22:19
mvahoney the codewitch28-Oct-23 22:19 
GeneralRe: Not a question, just a lament about metaprogramming Pin
jschell8-Nov-23 6:06
jschell8-Nov-23 6:06 
GeneralRe: Not a question, just a lament about metaprogramming Pin
honey the codewitch8-Nov-23 6:07
mvahoney the codewitch8-Nov-23 6:07 
GeneralRe: Not a question, just a lament about metaprogramming Pin
jschell9-Nov-23 7:03
jschell9-Nov-23 7:03 
GeneralRe: Not a question, just a lament about metaprogramming Pin
honey the codewitch9-Nov-23 7:10
mvahoney the codewitch9-Nov-23 7:10 
GeneralRe: Not a question, just a lament about metaprogramming Pin
jschell10-Nov-23 5:23
jschell10-Nov-23 5:23 
GeneralRe: Not a question, just a lament about metaprogramming Pin
honey the codewitch10-Nov-23 5:37
mvahoney the codewitch10-Nov-23 5:37 
GeneralRe: Not a question, just a lament about metaprogramming Pin
honey the codewitch8-Nov-23 6:17
mvahoney the codewitch8-Nov-23 6:17 
Forgive the multiple replies but I think maybe I'm not explaining the above.

That is user code in the OP. That defines a pixel type that DirectX can consume.

There are others. I've pasted a swath of additional definitions for other types of pixels that are commonly used in my library.

You can then take a pixel type and do like this

using fb_t = bitmap<bgrx_pixel<32>>;<br />
uint8_t fb_buffer[fb_t::sizeof_buffer(screen_size)];<br />
fb_t fb(screen_size,fb_buffer);


Then when you proceed to draw to fb it's begin() method (pointing to fb_buffer in this case) contains bitmap data of that format based on the definition in the OP.

If it was an 18 bit pixel, as some weird graphics devices support, it would do that too. They aren't necessarily even on clean byte boundaries.

Forgive the following, but hopefully it provides useful context
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>>;
    
    // creates a HSV pixel by making each channel 
    // one third of the whole. Any remainder bits
    // are added to the V channel
    template<size_t BitDepth>
    using hsv_pixel = pixel<
        channel_traits<channel_name::H,(BitDepth/3)>,
        channel_traits<channel_name::S,(BitDepth/3)>,
        channel_traits<channel_name::V,((BitDepth/3)+(BitDepth%3))>
    >;
    // creates a HSV/A pixel by making each 
    // channel 1/4 of the whole. Remaining bits
    // are added to V
    template<size_t BitDepth>
    using hsva_pixel = pixel<
        channel_traits<channel_name::H,(BitDepth/4)>,
        channel_traits<channel_name::S,(BitDepth/4)>,
        channel_traits<channel_name::V,((BitDepth/4)+(BitDepth%4))>,
        channel_traits<channel_name::A,(BitDepth/4),0,(1<<(BitDepth/4))-1,(1<<(BitDepth/4))-1>
    >;

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

QuestionHow to extract all words - using regular expression Pin
Salvatore Terress26-Oct-23 6:35
Salvatore Terress26-Oct-23 6:35 
AnswerRe: How to extract all words - using regular expression Pin
k505426-Oct-23 7:21
mvek505426-Oct-23 7:21 
AnswerRe: How to extract all words - using regular expression Pin
Richard Andrew x6426-Oct-23 8:51
professionalRichard Andrew x6426-Oct-23 8:51 
AnswerRe: How to extract all words - using regular expression Pin
Richard MacCutchan26-Oct-23 22:16
mveRichard MacCutchan26-Oct-23 22:16 
GeneralRe: How to extract all words - using regular expression Pin
Salvatore Terress27-Oct-23 10:21
Salvatore Terress27-Oct-23 10:21 
GeneralRe: How to extract all words - using regular expression Pin
Richard MacCutchan27-Oct-23 22:13
mveRichard MacCutchan27-Oct-23 22:13 
AnswerRe: How to extract all words - using regular expression Pin
jschell27-Oct-23 10:11
jschell27-Oct-23 10:11 
GeneralRe: How to extract all words - using regular expression Pin
Salvatore Terress27-Oct-23 14:01
Salvatore Terress27-Oct-23 14:01 
GeneralRe: How to extract all words - using regular expression Pin
Salvatore Terress28-Oct-23 5:21
Salvatore Terress28-Oct-23 5:21 
GeneralRe: How to extract all words - using regular expression Pin
k505428-Oct-23 6:27
mvek505428-Oct-23 6:27 
GeneralRe: How to extract all words - using regular expression Pin
jschell30-Oct-23 5:23
jschell30-Oct-23 5:23 
AnswerRe: How to extract all words - using regular expression Pin
Salvatore Terress29-Oct-23 4:48
Salvatore Terress29-Oct-23 4:48 
Questioncalled pointer is null... Pin
Salvatore Terress24-Oct-23 6:50
Salvatore Terress24-Oct-23 6:50 
AnswerRe: called pointer is null... Pin
k505424-Oct-23 7:01
mvek505424-Oct-23 7:01 
AnswerRe: called pointer is null... Pin
Dave Kreskowiak24-Oct-23 7:10
mveDave Kreskowiak24-Oct-23 7:10 
GeneralMessage Closed Pin
24-Oct-23 8:15
Salvatore Terress24-Oct-23 8:15 
GeneralRe: called pointer is null... Pin
Dave Kreskowiak24-Oct-23 9:00
mveDave Kreskowiak24-Oct-23 9:00 

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.