Click here to Skip to main content
15,884,177 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: Things I find buried in the C++ reference Pin
Espen Harlinn13-Mar-21 13:11
professionalEspen Harlinn13-Mar-21 13:11 
GeneralRe: Things I find buried in the C++ reference Pin
Greg Utas13-Mar-21 15:00
professionalGreg Utas13-Mar-21 15:00 
GeneralRe: Things I find buried in the C++ reference Pin
Espen Harlinn14-Mar-21 2:28
professionalEspen Harlinn14-Mar-21 2:28 
GeneralRe: Things I find buried in the C++ reference Pin
honey the codewitch13-Mar-21 16:22
mvahoney the codewitch13-Mar-21 16:22 
GeneralRe: Things I find buried in the C++ reference Pin
Espen Harlinn14-Mar-21 4:04
professionalEspen Harlinn14-Mar-21 4:04 
GeneralRe: Things I find buried in the C++ reference Pin
honey the codewitch14-Mar-21 6:19
mvahoney the codewitch14-Mar-21 6:19 
GeneralRe: Things I find buried in the C++ reference Pin
Espen Harlinn14-Mar-21 10:38
professionalEspen Harlinn14-Mar-21 10:38 
GeneralRe: Things I find buried in the C++ reference Pin
honey the codewitch14-Mar-21 10:52
mvahoney the codewitch14-Mar-21 10:52 
I'm excited to hack my toolchain to enable C++20 but I just haven't gotten to it yet.

On the bright side, it gives me a chance to get up to speed.

I just now caught up to C++11 variadic templates which allows me to do a lot more metaprogramming (or at least more easily) than I used to be able to do.

I'm doing it for now, without using STL for it just because I want to make sure I get the mechanics of any of the library I rely on. The standards docs are just never that helpful to me for expressing concepts and rationales but I can learn those by implementing them myself.

I'm doing pretty well with it right now. I've got a pixel template struct, that takes a series of channel traits that describe "channels" that make up a pixel (usually color channels R, G, B, but also it supports other color models, grayscales, monochromes) etc, - you can specify the bit depth and layout of the bits for the whole thing, including endianness.

I needed it because "device drivers" on IoT devices don't exist, and LCD screens and JPEGs and PNGs each have very different binary pixel formats. And LCD screens come in a variety of binary pixel bitmap formats at a variety of capabilites.

Keep in mind I'm not using iostreams below because it adds static initialization code and other cruft that's interfering with my ability to examine the output in assembly

And I can't afford to mess with any of this at run time. So I've made a little something to give me rich compile time pixel information I can use to do things like resolve the shifts I need to do pixel channel manipulation (like changing the "green" color component of a 16-bit rgb565be value (big endian) which is six bits squashed in the middle and then (if you're on an LE platform) flipped.

Anyway, I'm still working on it, but what I have so far incurs no overhead for anything.

So:

C++
typedef channel_traits<channel_name::R, channel_kind::color, uint8_t, 5> red_5bit_color_channel_t;
typedef channel_traits<channel_name::G, channel_kind::color, uint8_t, 6> green_6bit_color_channel_t;
typedef channel_traits<channel_name::B, channel_kind::color, uint8_t, 5> blue_5bit_color_channel_t;
typedef pixel<uint16_t, color_model::rgb, false, red_5bit_color_channel_t, green_6bit_color_channel_t, red_5bit_color_channel_t> rgb565be_t;
rgb565be_t p;

constexpr static const int index = 1;

using ch = rgb565be_t::get_channel<index>;
printf("index: %llu ",(unsigned long long)ch::index);
printf("name: %s, ",ch::name);
printf("type: %s, ",to_string(ch::kind));
printf("int-type size: %llu, ",(unsigned long long)sizeof(ch::int_type));
printf("min: %llu, ",(unsigned long long)ch::min);
printf("max: %llu, ",(unsigned long long)ch::max);
printf("bit-depth: %llu, ",(unsigned long long)ch::bit_depth);
printf("bits_to_left: %llu, ",(unsigned long long)ch::bits_to_left);
printf("bits_to_right: %llu, ",(unsigned long long)ch::bits_to_right);
printf("mask: %llx, ",(unsigned long long)ch::mask);
printf("pixel_mask: %llx\r\n",(unsigned long long)ch::pixel_mask);


Ouput
index: 1 name: G, type: color, int-type size: 1, min: 0, max: 63, bit-depth: 6, bits_to_left: 5, bits_to_right: 5, mask: 3f, pixel_mask: 7e0


Assembly
ASM
.LC0:
        .string "index: %llu "
.LC1:
        .string "G"
.LC2:
        .string "name: %s, "
.LC3:
        .string "color"
.LC4:
        .string "type: %s, "
.LC5:
        .string "int-type size: %llu, "
.LC6:
        .string "min: %llu, "
.LC7:
        .string "max: %llu, "
.LC8:
        .string "bit-depth: %llu, "
.LC9:
        .string "bits_to_left: %llu, "
.LC10:
        .string "bits_to_right: %llu, "
.LC11:
        .string "mask: %llx, "
.LC12:
        .string "pixel_mask: %llx\r\n"
main:
        push    rax
        mov     esi, 1
        mov     edi, OFFSET FLAT:.LC0
        xor     eax, eax
        call    printf
        mov     esi, OFFSET FLAT:.LC1
        mov     edi, OFFSET FLAT:.LC2
        xor     eax, eax
        call    printf
        mov     esi, OFFSET FLAT:.LC3
        mov     edi, OFFSET FLAT:.LC4
        xor     eax, eax
        call    printf
        mov     esi, 1
        mov     edi, OFFSET FLAT:.LC5
        xor     eax, eax
        call    printf
        xor     esi, esi
        mov     edi, OFFSET FLAT:.LC6
        xor     eax, eax
        call    printf
        mov     esi, 63
        mov     edi, OFFSET FLAT:.LC7
        xor     eax, eax
        call    printf
        mov     esi, 6
        mov     edi, OFFSET FLAT:.LC8
        xor     eax, eax
        call    printf
        mov     esi, 5
        mov     edi, OFFSET FLAT:.LC9
        xor     eax, eax
        call    printf
        mov     esi, 5
        mov     edi, OFFSET FLAT:.LC10
        xor     eax, eax
        call    printf
        mov     esi, 63
        mov     edi, OFFSET FLAT:.LC11
        xor     eax, eax
        call    printf
        mov     esi, 2016
        mov     edi, OFFSET FLAT:.LC12
        xor     eax, eax
        call    printf
        xor     eax, eax
        pop     rdx
        ret

Real programmers use butterflies

GeneralRe: Things I find buried in the C++ reference Pin
Espen Harlinn14-Mar-21 12:42
professionalEspen Harlinn14-Mar-21 12:42 
GeneralRe: Things I find buried in the C++ reference Pin
honey the codewitch14-Mar-21 12:54
mvahoney the codewitch14-Mar-21 12:54 
GeneralRe: Things I find buried in the C++ reference Pin
Espen Harlinn15-Mar-21 11:29
professionalEspen Harlinn15-Mar-21 11:29 
GeneralRe: Things I find buried in the C++ reference Pin
honey the codewitch15-Mar-21 11:57
mvahoney the codewitch15-Mar-21 11:57 
GeneralRe: Things I find buried in the C++ reference Pin
Stuart Dootson15-Mar-21 1:09
professionalStuart Dootson15-Mar-21 1:09 
GeneralRe: Things I find buried in the C++ reference Pin
honey the codewitch15-Mar-21 2:22
mvahoney the codewitch15-Mar-21 2:22 
GeneralRe: Things I find buried in the C++ reference Pin
Stuart Dootson15-Mar-21 3:31
professionalStuart Dootson15-Mar-21 3:31 
GeneralRe: Things I find buried in the C++ reference Pin
honey the codewitch15-Mar-21 3:52
mvahoney the codewitch15-Mar-21 3:52 
GeneralRe: Things I find buried in the C++ reference Pin
James Curran15-Mar-21 4:43
James Curran15-Mar-21 4:43 
GeneralOh no! Pin
Jörgen Andersson12-Mar-21 9:45
professionalJörgen Andersson12-Mar-21 9:45 
GeneralRe: Oh no! Pin
NotTodayYo12-Mar-21 10:09
NotTodayYo12-Mar-21 10:09 
GeneralRe: Oh no! Pin
RickZeeland12-Mar-21 21:04
mveRickZeeland12-Mar-21 21:04 
GeneralExploding Plastic Pin
honey the codewitch12-Mar-21 9:08
mvahoney the codewitch12-Mar-21 9:08 
GeneralRe: Exploding Plastic Pin
OriginalGriff12-Mar-21 11:17
mveOriginalGriff12-Mar-21 11:17 
GeneralThought of the Day Pin
OriginalGriff12-Mar-21 4:44
mveOriginalGriff12-Mar-21 4:44 
GeneralRe: Thought of the Day Pin
W Balboos, GHB12-Mar-21 5:22
W Balboos, GHB12-Mar-21 5:22 
GeneralThis was sent to me today ... Pin
CHill6012-Mar-21 3:29
mveCHill6012-Mar-21 3:29 

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.