From cdb9e1f7240cb0716b7d99df5e1fd7c3fc3407a8 Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Mon, 5 Dec 2022 21:45:18 -0500 Subject: v2.2, color space + brush improvements --- prenderer.cpp | 79 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 33 deletions(-) (limited to 'prenderer.cpp') diff --git a/prenderer.cpp b/prenderer.cpp index cf5990e..0940d16 100644 --- a/prenderer.cpp +++ b/prenderer.cpp @@ -530,15 +530,6 @@ Transform_Calculate(project_state *State, memory *Memory, project_data *File, bl }\ } break;\ }\ -\ - R_Blend = (R_Dest * (1.0f - LayerAlpha)) + (R_Blend * LayerAlpha);\ - G_Blend = (G_Dest * (1.0f - LayerAlpha)) + (G_Blend * LayerAlpha);\ - B_Blend = (B_Dest * (1.0f - LayerAlpha)) + (B_Blend * LayerAlpha);\ -\ - if (T.BlendMode == blend_normal)\ - A_Blend = A_Dest + LayerAlpha;\ - else\ - A_Blend = A_Dest;\ static void Fallback_RenderDirect(direct_info T, void *OutputBuffer, rectangle RenderRegion) @@ -571,7 +562,10 @@ Fallback_RenderDirect(direct_info T, void *OutputBuffer, rectangle RenderRegion) real32 B_Col = (real32)(*B_SrcAddress & T.BufferBits.MaskPixel) * T.BufferBits.Normalized; real32 A_Col = (real32)(*A_SrcAddress & T.BufferBits.MaskPixel) * T.BufferBits.Normalized; - real32 LayerAlpha = A_Col * 1; // brush opacity + if (A_Col == 0) + continue; + + real32 LayerAlpha = A_Col * T.Opacity; uint8 *DestPixel =((uint8 *)OutputBuffer + ((uint16)Y * (uint16)T.BufferPitch) + ((uint16)X * (uint16)T.BufferBytesPerPixel)); @@ -589,14 +583,27 @@ Fallback_RenderDirect(direct_info T, void *OutputBuffer, rectangle RenderRegion) real32 G_Dest = (real32)(G_DestInt) * T.BufferBits.Normalized; real32 B_Dest = (real32)(B_DestInt) * T.BufferBits.Normalized; real32 A_Dest = (real32)(A_DestInt) * T.BufferBits.Normalized; + real32 Test = (A_Dest > 0.01) ? 1 : 0; real32 R_Blend = R_Col; real32 G_Blend = G_Col; real32 B_Blend = B_Col; real32 A_Blend = A_Col; + // A_Blend = (A_Blend >= 0.04045) ? pow((A_Blend + 0.055) / (1 + 0.055), 2.4) : A_Blend / 12.92; if (LayerAlpha != 1.0f || T.BlendMode != blend_normal) { + Fallback_Blend(); + + if (A_Dest == 0) { + A_Blend = LayerAlpha; + } else { + A_Blend = A_Dest + ((1.0f - A_Dest) * LayerAlpha); + real32 Alpha = pow(LayerAlpha, A_Dest); + R_Blend = (R_Dest * (1.0f - Alpha)) + (R_Blend * Alpha); + G_Blend = (G_Dest * (1.0f - Alpha)) + (G_Blend * Alpha); + B_Blend = (B_Dest * (1.0f - Alpha)) + (B_Blend * Alpha); + } } uint32 R_Out = (uint32)(Normalize(R_Blend) * T.BufferBits.Bits); @@ -712,29 +719,7 @@ Fallback_RenderLayer(transform_info T, void *OutputBuffer, rectangle RenderRegio real32 TexGD = (real32)(*(uint32 *)(TexPTR3 + T.LayerBits.ByteOffset * 1) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; real32 TexBD = (real32)(*(uint32 *)(TexPTR3 + T.LayerBits.ByteOffset * 2) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; real32 TexAD = (real32)(*(uint32 *)(TexPTR3 + T.LayerBits.ByteOffset * 3) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; -#if 0 - for (int i = 0; i < 50; i++) { - real32 TexRA = (real32)(*(uint32 *)(TexPTR0 + T.LayerBits.ByteOffset * 0) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - real32 TexGA = (real32)(*(uint32 *)(TexPTR0 + T.LayerBits.ByteOffset * 1) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - real32 TexBA = (real32)(*(uint32 *)(TexPTR0 + T.LayerBits.ByteOffset * 2) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - real32 TexAA = (real32)(*(uint32 *)(TexPTR0 + T.LayerBits.ByteOffset * 3) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - - real32 TexRB = (real32)(*(uint32 *)(TexPTR1 + T.LayerBits.ByteOffset * 0) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - real32 TexGB = (real32)(*(uint32 *)(TexPTR1 + T.LayerBits.ByteOffset * 1) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - real32 TexBB = (real32)(*(uint32 *)(TexPTR1 + T.LayerBits.ByteOffset * 2) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - real32 TexAB = (real32)(*(uint32 *)(TexPTR1 + T.LayerBits.ByteOffset * 3) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - - real32 TexRC = (real32)(*(uint32 *)(TexPTR2 + T.LayerBits.ByteOffset * 0) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - real32 TexGC = (real32)(*(uint32 *)(TexPTR2 + T.LayerBits.ByteOffset * 1) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - real32 TexBC = (real32)(*(uint32 *)(TexPTR2 + T.LayerBits.ByteOffset * 2) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - real32 TexAC = (real32)(*(uint32 *)(TexPTR2 + T.LayerBits.ByteOffset * 3) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - - real32 TexRD = (real32)(*(uint32 *)(TexPTR3 + T.LayerBits.ByteOffset * 0) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - real32 TexGD = (real32)(*(uint32 *)(TexPTR3 + T.LayerBits.ByteOffset * 1) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - real32 TexBD = (real32)(*(uint32 *)(TexPTR3 + T.LayerBits.ByteOffset * 2) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - real32 TexAD = (real32)(*(uint32 *)(TexPTR3 + T.LayerBits.ByteOffset * 3) & T.LayerBits.MaskPixel) * T.LayerBits.Normalized; - } -#endif + #endif real32 R_Col = (TexBothInv * TexRA) + (TexBothYInv * TexRB) @@ -748,6 +733,13 @@ Fallback_RenderLayer(transform_info T, void *OutputBuffer, rectangle RenderRegio real32 LayerAlpha = A_Col * T.LayerOpacity; +#if DEBUG + if (Debug.DisableAlpha == 1) { + A_Col = 1; + LayerAlpha = 1; + } +#endif + real32 R_Blend = R_Col; real32 G_Blend = G_Col; real32 B_Blend = B_Col; @@ -769,6 +761,27 @@ Fallback_RenderLayer(transform_info T, void *OutputBuffer, rectangle RenderRegio real32 A_Dest = (real32)(*A_DestAddress & T.BufferBits.MaskPixel) * T.BufferBits.Normalized; Fallback_Blend(); + + R_Blend = (R_Dest * (1.0f - LayerAlpha)) + (R_Blend * LayerAlpha); + G_Blend = (G_Dest * (1.0f - LayerAlpha)) + (G_Blend * LayerAlpha); + B_Blend = (B_Dest * (1.0f - LayerAlpha)) + (B_Blend * LayerAlpha); + + if (T.BlendMode == blend_normal) + A_Blend = A_Dest + LayerAlpha; + // A_Blend = A_Dest + ((1.0f - A_Dest) * LayerAlpha); + else + A_Blend = A_Dest; +#if DEBUG + if (Debug.DisableAlpha == 1) { + G_Blend = R_Blend; + B_Blend = R_Blend; + } else + if (Debug.DisableAlpha == 2) { + R_Blend = LayerAlpha; + G_Blend = LayerAlpha; + B_Blend = LayerAlpha; + } +#endif } uint8 R_Out = (uint8)(Normalize(R_Blend) * T.BufferBits.Bits); -- cgit v1.2.3