Click here to Skip to main content
15,388,904 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: Talk about demoralizing Pin
PIEBALDconsult17-Jun-21 11:06
professionalPIEBALDconsult17-Jun-21 11:06 
GeneralRe: Talk about demoralizing Pin
Super Lloyd17-Jun-21 13:48
MemberSuper Lloyd17-Jun-21 13:48 
GeneralRe: Talk about demoralizing Pin
Espen Harlinn17-Jun-21 15:56
professionalEspen Harlinn17-Jun-21 15:56 
GeneralRe: Talk about demoralizing Pin
honey the codewitch17-Jun-21 16:45
mvahoney the codewitch17-Jun-21 16:45 
GeneralRe: Talk about demoralizing Pin
David O'Neil17-Jun-21 20:32
professionalDavid O'Neil17-Jun-21 20:32 
GeneralRe: Talk about demoralizing Pin
lmoelleb17-Jun-21 20:19
Memberlmoelleb17-Jun-21 20:19 
GeneralRe: Talk about demoralizing Pin
honey the codewitch17-Jun-21 20:25
mvahoney the codewitch17-Jun-21 20:25 
QuestionRe: Talk about demoralizing Pin
honey the codewitch17-Jun-21 20:27
mvahoney the codewitch17-Jun-21 20:27 
Adding were you doing color dithering? My black and white bayer dithering is quite fast.

Also if you were doing color dithering there are much faster algos you can use when simply simulating a higher bit depth, but I actually have to do color matching to a palette.

Here's how I have to choose two colors to blend:

C++
template<typename PaletteType>
gfx_result dither_mixing_plan_fast(const PaletteType* palette, typename PaletteType::mapped_pixel_type color, dither_mixing_plan_data_fast* plan) {
    gfx_result rr ;
    if(nullptr==plan || nullptr==palette) {
        return gfx_result::invalid_argument;
    }
    rgb_pixel<24> rgb888;
    rr = convert(color,&rgb888);
    if(gfx_result::success!=rr) {
        return rr;
    }
    const unsigned r= rgb888.template channel<channel_name::R>(), 
                g=rgb888.template channel<channel_name::G>(), 
                b=rgb888.template channel<channel_name::B>();

    *plan = { {0,0}, 0.5 };
    double least_penalty = 1e99;
    for(unsigned index1 = 0; index1 < 16; ++index1)
    for(unsigned index2 = index1; index2 < 16; ++index2)
    {
        // Determine the two component colors
        typename PaletteType::mapped_pixel_type mpx1;
        rr=palette->map(typename PaletteType::pixel_type(index1),&mpx1);
        if(gfx_result::success!=rr) {
            return rr;
        }
        typename PaletteType::mapped_pixel_type mpx2;
        rr=palette->map(typename PaletteType::pixel_type(index2),&mpx1);
        if(gfx_result::success!=rr) {
            return rr;
        }
        rr = convert(mpx1,&rgb888);
        if(gfx_result::success!=rr) {
            return rr;
        }   
        unsigned r1= rgb888.template channel<channel_name::R>(), 
                g1=rgb888.template channel<channel_name::G>(), 
                b1=rgb888.template channel<channel_name::B>();
        rr = convert(mpx2,&rgb888);
        if(gfx_result::success!=rr) {
            return rr;
        }
        unsigned r2= rgb888.template channel<channel_name::R>(), 
                g2=rgb888.template channel<channel_name::G>(), 
                b2=rgb888.template channel<channel_name::B>();
        int ratio = 32;
        if(mpx1.native_value != mpx2.native_value)
        {
            // Determine the ratio of mixing for each channel.
            //   solve(r1 + ratio*(r2-r1)/64 = r, ratio)
            // Take a weighed average of these three ratios according to the
            // perceived luminosity of each channel (according to CCIR 601).
            ratio = ((r2 != r1 ? 299*64 * int(r - r1) / int(r2-r1) : 0)
                +  (g2 != g1 ? 587*64 * int(g - g1) / int(g2-g1) : 0)
                +  (b1 != b2 ? 114*64 * int(b - b1) / int(b2-b1) : 0))
                / ((r2 != r1 ? 299 : 0)
                + (g2 != g1 ? 587 : 0)
                + (b2 != b1 ? 114 : 0));
            if(ratio < 0) ratio = 0; else if(ratio > 63) ratio = 63;   
        }
        // Determine what mixing them in this proportion will produce
        unsigned r0 = r1 + ratio * int(r2-r1) / 64;
        unsigned g0 = g1 + ratio * int(g2-g1) / 64;
        unsigned b0 = b1 + ratio * int(b2-b1) / 64;
        double penalty = dither_mixing_error(
            r,g,b, r0,g0,b0, r1,g1,b1, r2,g2,b2,
            ratio / double(64));
        if(penalty < least_penalty)
        {
            least_penalty = penalty;
            plan->colors[0] = index1;
            plan->colors[1] = index2;
            plan->ratio = ratio / double(64);
        }
    }
    
    return gfx_result::success;
}


It's not easy. I know it could be faster, but I don't think I can make many algorithmic improvements and that's the sort of improvement I need to achieve orders of magnitude reduction in time requirements - that's what I need right now.
Real programmers use butterflies

AnswerRe: Talk about demoralizing Pin
lmoelleb21-Jun-21 3:49
Memberlmoelleb21-Jun-21 3:49 
GeneralRe: Talk about demoralizing Pin
honey the codewitch21-Jun-21 6:30
mvahoney the codewitch21-Jun-21 6:30 
GeneralRe: Talk about demoralizing Pin
lmoelleb22-Jun-21 1:45
Memberlmoelleb22-Jun-21 1:45 
GeneralRe: Talk about demoralizing Pin
honey the codewitch22-Jun-21 1:59
mvahoney the codewitch22-Jun-21 1:59 
GeneralRe: Talk about demoralizing Pin
Daniel Pfeffer17-Jun-21 22:50
professionalDaniel Pfeffer17-Jun-21 22:50 
GeneralRe: Talk about demoralizing Pin
honey the codewitch18-Jun-21 2:09
mvahoney the codewitch18-Jun-21 2:09 
GeneralThought of the Day Pin
OriginalGriff17-Jun-21 4:34
mveOriginalGriff17-Jun-21 4:34 
GeneralRe: Thought of the Day Pin
Daniel Pfeffer17-Jun-21 4:58
professionalDaniel Pfeffer17-Jun-21 4:58 
GeneralRe: Thought of the Day Pin
W Balboos, GHB17-Jun-21 5:15
mveW Balboos, GHB17-Jun-21 5:15 
GeneralRe: Thought of the Day Pin
Daniel Pfeffer17-Jun-21 5:33
professionalDaniel Pfeffer17-Jun-21 5:33 
GeneralRe: Thought of the Day Pin
W Balboos, GHB17-Jun-21 5:13
mveW Balboos, GHB17-Jun-21 5:13 
GeneralRe: Thought of the Day Pin
PIEBALDconsult17-Jun-21 5:30
professionalPIEBALDconsult17-Jun-21 5:30 
GeneralRe: Thought of the Day Pin
Daniel Pfeffer17-Jun-21 5:40
professionalDaniel Pfeffer17-Jun-21 5:40 
JokeThings that make you go hmm... Pin
Mike Hankey17-Jun-21 4:30
professionalMike Hankey17-Jun-21 4:30 
GeneralRe: Things that make you go hmm... Pin
Daniel Pfeffer17-Jun-21 5:05
professionalDaniel Pfeffer17-Jun-21 5:05 
GeneralRe: Things that make you go hmm... Pin
PIEBALDconsult17-Jun-21 5:36
professionalPIEBALDconsult17-Jun-21 5:36 
GeneralRe: Things that make you go hmm... Pin
Mike Hankey17-Jun-21 5:40
professionalMike Hankey17-Jun-21 5:40 

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.


Straw Poll

Have you ever taught anyone to code?
"Teaching" can mean from start to finish, or simply just helping someone learning to code work through a coding issue (like helping with homework or being a support tutor)
And how did it go?
  Results   672 votes