@startuml
title PMA alpha blending в blendPixelAtBuffer

start
:Input dst pixel, src PMA pixel,\ntransform opacity;
if (pixel outside buffer?) then (yes)
  stop
endif

if (replace_mode?) then (yes)
  :dst = src;
  stop
endif

:a = (src.a / 255) * opacity;
:inv_a = 1 - a;
:src_rgb = src.rgb * opacity;

:dst.r = clamp(src_r + inv_a * dst.r);
:dst.g = clamp(src_g + inv_a * dst.g);
:dst.b = clamp(src_b + inv_a * dst.b);
:dst.a = clamp(a*255 + inv_a * dst.a);

:Store dst pixel;
stop

@enduml
