Click here to Skip to main content
15,868,292 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: Opera Just Went Silent Pin
C-P-User-311-Jul-22 1:02
C-P-User-311-Jul-22 1:02 
GeneralRe: Opera Just Went Silent Pin
David O'Neil11-Jul-22 4:46
professionalDavid O'Neil11-Jul-22 4:46 
GeneralRe: Opera Just Went Silent Pin
C-P-User-312-Jul-22 21:12
C-P-User-312-Jul-22 21:12 
GeneralRe: Opera Just Went Silent Pin
David O'Neil12-Jul-22 21:49
professionalDavid O'Neil12-Jul-22 21:49 
GeneralRe: Opera Just Went Silent Pin
Eddy Vluggen10-Jul-22 9:35
professionalEddy Vluggen10-Jul-22 9:35 
GeneralRe: Opera Just Went Silent Pin
C-P-User-311-Jul-22 1:03
C-P-User-311-Jul-22 1:03 
GeneralRe: Opera Just Went Silent Pin
dandy7210-Jul-22 11:16
dandy7210-Jul-22 11:16 
PraiseSo this is satisfying. Free code performance upgrade! Pin
honey the codewitch9-Jul-22 21:42
mvahoney the codewitch9-Jul-22 21:42 
I have a little graphics library for IoT: GFX (htcw_gfx)[^]

I originally targeted C++17 but the Arduino toolchain did not have a new enough GCC version to support it. I had to fork it a bit to support C++14.

One reason was a massive function that is computed 90% at compile time down to a very few asm instructions. Which depend on how you call it which is why there's several pages of code.

What it does is convert one pixel format to another, including doing things like grayscale or HSV conversion.

The trouble with C++14 is it couldn't do the entire function at compile time. With C++17 the compiler can run the function so if the color value is constant there is no runtime overhead for doing the conversion.

The bottom line is a bit of a performance win since this function is used all over the place for virtually every drawing operation. If the user passes in a constant color value, which is typical, the conversions no longer require any runtime overhead!

Gosh that's neat, and one of the reasons I love C++ so much, and every version keeps allowing the compiler to compute more and more during the compile phase. It's actually kind of amazing how much you can get it to do. I joke that the C++ compiler will make your bed. There's no other language like it.

Feeling pretty good about all this. It's deeply satisfying.

Here's something C++17 can do at compile time if all input values are known at that point:

C++
const int CVACC = (sizeof(int) > 2) ? 1024 : 128; /* Adaptive accuracy for both 16-/32-bit systems */
// destination color model is RGB
using trindexR = typename PixelTypeRhs::template channel_index_by_name<channel_name::R>;
using trchR = typename PixelTypeRhs::template channel_by_index_unchecked<trindexR::value>;

using trindexG = typename PixelTypeRhs::template channel_index_by_name<channel_name::G>;
using trchG = typename PixelTypeRhs::template channel_by_index_unchecked<trindexG::value>;

using trindexB = typename PixelTypeRhs::template channel_index_by_name<channel_name::B>;
using trchB = typename PixelTypeRhs::template channel_by_index_unchecked<trindexB::value>;

const auto chY = uint8_t(source.template channelr_unchecked<chiY>()*255);
const auto chCb = uint8_t(source.template channelr_unchecked<chiCb>()*255);
const auto chCr = uint8_t(source.template channelr_unchecked<chiCr>()*255);
const int cBA = chCb-128;
const int cRA = chCr-128;
const auto cnR = (uint8_t)helpers::clamp((int)(chY + ((int)(1.402 * CVACC) * cRA) / (float)CVACC),0,255);
const auto cnG = (uint8_t)helpers::clamp((int)(chY - ((int)(0.344 * CVACC) * cBA + (int)(0.714 * CVACC) * cRA) / (float)CVACC),0,255);
const auto cnB = (uint8_t)helpers::clamp((int)(chY + ((int)(1.772 * CVACC) * cBA) / (float)CVACC),0,255);

const auto r = typename trchR::int_type(cnR*(trchR::scale/255.0));
helpers::set_channel_direct_unchecked<PixelTypeRhs,trindexR::value>(native_value,r);
const auto g = typename trchG::int_type(cnG*(trchG::scale/255.0));
helpers::set_channel_direct_unchecked<PixelTypeRhs,trindexG::value>(native_value,g);
const auto b = typename trchB::int_type(cnB*(trchB::scale/255.0));
helpers::set_channel_direct_unchecked<PixelTypeRhs,trindexB::value>(native_value,b);
good = true;                    


Just amazing. There's actually compile time computed bit shifts to get and set channel values behind that mess. *shaking my head*. It's incredible.
To err is human. Fortune favors the monsters.


modified 10-Jul-22 6:04am.

GeneralRe: So this is satisfying. Free code performance upgrade! Pin
Peter_in_278010-Jul-22 1:12
professionalPeter_in_278010-Jul-22 1:12 
GeneralRe: So this is satisfying. Free code performance upgrade! Pin
Greg Utas10-Jul-22 1:26
professionalGreg Utas10-Jul-22 1:26 
GeneralRe: So this is satisfying. Free code performance upgrade! Pin
Eddy Vluggen10-Jul-22 3:57
professionalEddy Vluggen10-Jul-22 3:57 
GeneralRe: So this is satisfying. Free code performance upgrade! Pin
jmaida10-Jul-22 9:53
jmaida10-Jul-22 9:53 
GeneralRe: So this is satisfying. Free code performance upgrade! Pin
Greg Utas10-Jul-22 15:17
professionalGreg Utas10-Jul-22 15:17 
GeneralRe: So this is satisfying. Free code performance upgrade! Pin
jmaida10-Jul-22 15:41
jmaida10-Jul-22 15:41 
GeneralRe: So this is satisfying. Free code performance upgrade! Pin
jmaida10-Jul-22 15:42
jmaida10-Jul-22 15:42 
GeneralRe: So this is satisfying. Free code performance upgrade! Pin
jmaida10-Jul-22 15:47
jmaida10-Jul-22 15:47 
GeneralRe: So this is satisfying. Free code performance upgrade! Pin
honey the codewitch10-Jul-22 19:10
mvahoney the codewitch10-Jul-22 19:10 
GeneralRe: So this is satisfying. Free code performance upgrade! Pin
Greg Utas11-Jul-22 0:09
professionalGreg Utas11-Jul-22 0:09 
GeneralRe: So this is satisfying. Free code performance upgrade! Pin
honey the codewitch11-Jul-22 0:26
mvahoney the codewitch11-Jul-22 0:26 
GeneralRe: So this is satisfying. Free code performance upgrade! Pin
honey the codewitch10-Jul-22 19:13
mvahoney the codewitch10-Jul-22 19:13 
GeneralRe: So this is satisfying. Free code performance upgrade! Pin
jmaida11-Jul-22 10:13
jmaida11-Jul-22 10:13 
GeneralRe: So this is satisfying. Free code performance upgrade! Pin
jmaida11-Jul-22 11:18
jmaida11-Jul-22 11:18 
GeneralWordle 386 Pin
Amarnath S9-Jul-22 15:02
professionalAmarnath S9-Jul-22 15:02 
GeneralRe: Wordle 386 Pin
Peter_in_27809-Jul-22 16:15
professionalPeter_in_27809-Jul-22 16:15 
GeneralRe: Wordle 386 Pin
OriginalGriff9-Jul-22 18:46
mveOriginalGriff9-Jul-22 18:46 

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.