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

C / C++ / MFC

 
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 
QuestionRapi use for connect with active sync,now what can i use for connect with Mobile Device Center? Pin
Le@rner8-Apr-09 0:54
Le@rner8-Apr-09 0:54 
QuestionDouble to CString Pin
Davitor7-Apr-09 23:57
Davitor7-Apr-09 23:57 
AnswerRe: Double to CString Pin
«_Superman_»7-Apr-09 23:59
professional«_Superman_»7-Apr-09 23:59 
QuestionQuery related to DllInstall() Pin
narayanagvs7-Apr-09 23:36
narayanagvs7-Apr-09 23:36 
AnswerRe: Query related to DllInstall() Pin
Randor 8-Apr-09 1:33
professional Randor 8-Apr-09 1:33 
QuestionMenu class derived from CMenu Pin
prithaa7-Apr-09 23:30
prithaa7-Apr-09 23:30 
AnswerRe: Menu class derived from CMenu Pin
Iain Clarke, Warrior Programmer8-Apr-09 0:03
Iain Clarke, Warrior Programmer8-Apr-09 0:03 

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.