Click here to Skip to main content
15,905,427 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Setting REG_MULTI_SZ value Pin
csrss8-Apr-09 8:06
csrss8-Apr-09 8:06 
GeneralRe: Setting REG_MULTI_SZ value Pin
CPallini8-Apr-09 10:14
mveCPallini8-Apr-09 10:14 
Questiona managed array cannot have this element type Pin
Member 20210228-Apr-09 3:55
Member 20210228-Apr-09 3:55 
AnswerRe: a managed array cannot have this element type Pin
Cedric Moonen8-Apr-09 4:03
Cedric Moonen8-Apr-09 4:03 
AnswerAsked and answered 2 weeks ago Pin
led mike8-Apr-09 4:23
led mike8-Apr-09 4:23 
QuestionTripleDES ECB in Visual C++ Pin
annese8-Apr-09 2:55
annese8-Apr-09 2:55 
AnswerRe: TripleDES ECB in Visual C++ Pin
Chris Losinger8-Apr-09 6:34
professionalChris Losinger8-Apr-09 6:34 
Questionborder of the childframe Pin
prithaa8-Apr-09 2:36
prithaa8-Apr-09 2:36 
AnswerRe: border of the childframe Pin
Code-o-mat8-Apr-09 2:52
Code-o-mat8-Apr-09 2:52 
GeneralRe: border of the childframe Pin
prithaa8-Apr-09 3:09
prithaa8-Apr-09 3:09 
QuestionHelp with how to add/mix RGBA values Pin
spiffen8-Apr-09 1:17
spiffen8-Apr-09 1:17 
AnswerRe: Help with how to add/mix RGBA values Pin
Iain Clarke, Warrior Programmer8-Apr-09 1:24
Iain Clarke, Warrior Programmer8-Apr-09 1:24 
GeneralRe: Help with how to add/mix RGBA values Pin
spiffen8-Apr-09 2:22
spiffen8-Apr-09 2:22 
GeneralRe: Help with how to add/mix RGBA values Pin
Iain Clarke, Warrior Programmer8-Apr-09 2:32
Iain Clarke, Warrior Programmer8-Apr-09 2:32 
GeneralRe: Help with how to add/mix RGBA values Pin
spiffen8-Apr-09 4:16
spiffen8-Apr-09 4:16 
Hi.

Yes this works if the bottom color has an alpha of 1.0

I guess it will work for me, since my bottom layer always have full alpha.

But still I can't figure out how it works when having opacity set on the bottom layer.

I've looked in the Paint.NET source, and I can't find anything that explains how they calculate the colors when both pixels have opacity set. Only found functions that works same as you described.

BTW, thank you for your help!

If you want to take a look at the source it is available here: http://www.afterdawn.com/software/source_codes/paint.net.cfm

In UnaryPixelOps.cs
public override ColorBgra Apply(ColorBgra color)
{
    int a = blendColor.A;
    int invA = 255 - a;

    int r = ((color.R * invA) + (blendColor.R * a)) / 256;
    int g = ((color.G * invA) + (blendColor.G * a)) / 256;
    int b = ((color.B * invA) + (blendColor.B * a)) / 256;
    byte a2 = ComputeAlpha(color.A, blendColor.A);

    return ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, a2);
}

In ColorBgra.cs
public static ColorBgra Blend(ColorBgra ca, ColorBgra cb, byte cbAlpha)
{
    uint caA = (uint)Utility.FastScaleByteByByte((byte)(255 - cbAlpha), ca.A);
    uint cbA = (uint)Utility.FastScaleByteByByte(cbAlpha, cb.A);
    uint cbAT = caA + cbA;

    uint r;
    uint g;
    uint b;

    if (cbAT == 0)
    {
        r = 0;
        g = 0;
        b = 0;
    }
    else
    {
        r = ((ca.R * caA) + (cb.R * cbA)) / cbAT;
        g = ((ca.G * caA) + (cb.G * cbA)) / cbAT;
        b = ((ca.B * caA) + (cb.B * cbA)) / cbAT;
    }

    return ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)cbAT);
}

public static int FastScaleByteByByte(byte a, byte b)
{
    int r1 = a * b + 0x80;
    int r2 = ((r1 >> 8) + r1) >> 8;
    return (byte)r2;
}

Can't figure out what function 'FastScaleByteByByte' does and why the 3rd parameter 'cbAlpha' is required..
GeneralRe: Help with how to add/mix RGBA values Pin
Iain Clarke, Warrior Programmer8-Apr-09 6:00
Iain Clarke, Warrior Programmer8-Apr-09 6:00 
GeneralRe: Help with how to add/mix RGBA values Pin
Iain Clarke, Warrior Programmer8-Apr-09 2:34
Iain Clarke, Warrior Programmer8-Apr-09 2:34 
GeneralRe: Help with how to add/mix RGBA values Pin
CPallini8-Apr-09 7:19
mveCPallini8-Apr-09 7:19 
QuestionHow to convert LZW type tiff file to PDF c++? Pin
raesa8-Apr-09 0:58
raesa8-Apr-09 0:58 
AnswerRe: How to convert LZW type tiff file to PDF c++? Pin
Rajesh R Subramanian8-Apr-09 1:07
professionalRajesh R Subramanian8-Apr-09 1:07 
AnswerRe: How to convert LZW type tiff file to PDF c++? Pin
Jijo.Raj8-Apr-09 1:13
Jijo.Raj8-Apr-09 1:13 
GeneralRe: How to convert LZW type tiff file to PDF c++? Pin
raesa8-Apr-09 1:38
raesa8-Apr-09 1:38 
GeneralRe: How to convert LZW type tiff file to PDF c++? Pin
Rajesh R Subramanian8-Apr-09 2:02
professionalRajesh R Subramanian8-Apr-09 2:02 
GeneralRe: How to convert LZW type tiff file to PDF c++? Pin
Stuart Dootson8-Apr-09 2:40
professionalStuart Dootson8-Apr-09 2:40 
GeneralRe: How to convert LZW type tiff file to PDF c++? Pin
raesa8-Apr-09 17:40
raesa8-Apr-09 17: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.