{"id":325,"date":"2024-02-19T11:22:40","date_gmt":"2024-02-19T10:22:40","guid":{"rendered":"https:\/\/melander.dk\/graphics32\/?page_id=325"},"modified":"2024-03-05T05:14:51","modified_gmt":"2024-03-05T04:14:51","slug":"alpha-composition","status":"publish","type":"page","link":"https:\/\/melander.dk\/graphics32\/alpha-composition\/","title":{"rendered":"Alpha composition"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Alpha composition<\/strong>, or <strong>alpha blending<\/strong> as it is perhaps better known, is the process of combining one image with another while taking the transparency of the images into account.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Graphics32 supports three fundamental blend operations: <strong><a href=\"#blend\" data-type=\"internal\" data-id=\"#blend\">Blend<\/a><\/strong>, <strong><a href=\"#merge\" data-type=\"internal\" data-id=\"#merge\">Merge<\/a><\/strong>, and <strong><a href=\"#combine\" data-type=\"internal\" data-id=\"#combine\">Combine<\/a><\/strong>.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"blend\">Blend<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:75%\">\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"wp-block-paragraph\">The Blend operation mixes a foreground color <strong>F<\/strong> with a background color <strong>B<\/strong> using the alpha component of the foreground color.<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\[S_{RGB} = F_A * F_{RGB} + (1 &#8211; F_A) * B_{RGB}\\]<script id=\"wp-hooks-js\" src=\"https:\/\/melander.dk\/graphics32\/wp-includes\/js\/dist\/hooks.min.js?ver=7496969728ca0f95732d\"><\/script>\n<script id=\"wp-i18n-js\" src=\"https:\/\/melander.dk\/graphics32\/wp-includes\/js\/dist\/i18n.min.js?ver=781d11515ad3d91786ec\"><\/script>\n<script id=\"wp-i18n-js-after\">\nwp.i18n.setLocaleData( { 'text direction\\u0004ltr': [ 'ltr' ] } );\n\/\/# sourceURL=wp-i18n-js-after\n<\/script>\n<script  async id=\"mathjax-js\" src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/mathjax\/2.7.7\/MathJax.js?config=TeX-MML-AM_CHTML\"><\/script>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The blend operation is a simplification of the <a href=\"#merge\" data-type=\"internal\" data-id=\"#merge\">merge<\/a> operation; It is an optimization that, by assuming that <strong>the background is fully opaque<\/strong> (i.e. has an alpha value A = 255), avoids the merge operation&#8217;s costly calculation of the result alpha.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note that while the blend operation assume that the background alpha is 255, for performance reasons, many blend functions still calculate the result alpha using the blend formula:<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\[S_A = F_A * F_A + (1 &#8211; F_A) * B_A\\]<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">In most cases this alpha calculation only makes sense when the background is opaque.<\/p>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-table is-style-regular has-small-font-size\"><table><thead><tr><th>Note<\/th><\/tr><\/thead><tbody><tr><td>The <strong>Blend<\/strong> operation is almost exclusively used when drawing onto an opaque (i.e. non-transparent) background.<br>If you are drawing onto a semi-transparent background then the <strong>Merge<\/strong> operation is most likely what you want to use.<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"merge\">Merge<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:75%\">\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"wp-block-paragraph\">The Merge operation merges a foreground color <strong>F<\/strong> with the background color <strong>B<\/strong> using the alpha component of the foreground color. It merges both the RGB and alpha-channels.<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\[S_A = 1 &#8211; (1 &#8211; F_A) * (1 &#8211; B_A)\\]\n\\[S_{RGB} = \\frac{ F_A * F_{RGB} + B_A * (1 &#8211; F_A) * B_{RGB} }{S_A} \\]<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Note<\/th><\/tr><\/thead><tbody><tr><td>The <strong>Merge<\/strong> operation is expensive. If you are drawing onto a fully opaque (i.e. non-transparent) background then it is much more efficient to use the <strong>Blend<\/strong> operation.<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"combine\">Combine<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The Combine operation performs <em>linear interpolation<\/em> between two colors: <strong>X<\/strong> and <strong>Y<\/strong>. The <strong>W<\/strong> parameter, which must be in [0..255] range, specifies the weight of the first color (<strong>X<\/strong>). The alpha channel is interpolated as well.<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\[S_{RGBA} = W * X_{RGBA} + (1 &#8211; W) * Y_{RGBA} = W * (X_{RGBA} &#8211; Y_{RGBA}) + Y_{RGBA}\\]<\/div>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The Combine operation is also known as <em>Lerp<\/em> or <em>Cross-fade<\/em>.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Alpha composition functions<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:75%\">\n<p class=\"wp-block-paragraph\">For both <strong>Blend<\/strong> and <strong>Merge<\/strong>, Graphics32 implements a suite of highly optimized low-level functions.<br>Implementations of these functions are available in both Pascal and hand optimized 32-bit and 64-bit assembler using various levels of processor features, such as MMX, SSE, SSE2, SSE4.1, etc. At run-time Graphics32 will <a href=\"https:\/\/melander.dk\/graphics32\/cpu-feature-detection\/\" data-type=\"page\" data-id=\"382\">automatically select<\/a> the fastest version to use based on what the host system supports.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Note<\/th><\/tr><\/thead><tbody><tr><td>The Blend and Merge functions that are implemented using MMX instructions alters the CPU floating point flags. Therefore, after using <em>any<\/em> of these functions, you <em>must<\/em> call the <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32_Blend\/Routines\/EMMS.htm\">EMMS<\/a> function to reset the floating point state. Otherwise the CPU will be unable to handle subsequent floating point instructions.<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n<\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Blend<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nfunction BlendReg(F, B: TColor32): TColor32;\nprocedure BlendMem(F: TColor32; var B: TColor32);\nprocedure BlendMems(F: TColor32; B: PColor32; Count: Integer);\nfunction BlendRegEx(F, B: TColor32; M: Cardinal): TColor32;\nprocedure BlendMemEx(F: TColor32; var B: TColor32; M: Cardinal);\nprocedure BlendLine(Src, Dst: PColor32; Count: Integer);\nprocedure BlendLineEx(Src, Dst: PColor32; Count: Integer; M: Cardinal);\nprocedure BlendLine1(Src: TColor32; Dst: PColor32; Count: Integer);\nfunction BlendRegRGB(F, B: TColor32; W: Cardinal): TColor32;\nprocedure BlendMemRGB(F: TColor32; var B: TColor32; W: Cardinal);\n<\/pre><\/div>\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Merge<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nfunction MergeReg(F, B: TColor32): TColor32;\nprocedure MergeMem(F: TColor32; var B: TColor32);\nfunction MergeRegEx(F, B: TColor32; M: Cardinal): TColor32;\nprocedure MergeMemEx(F: TColor32; var B: TColor32; M: Cardinal);\nprocedure MergeLine(Src, Dst: PColor32; Count: Integer);\nprocedure MergeLineEx(Src, Dst: PColor32; Count: Integer; M: Cardinal);\nprocedure MergeLine1(Src: TColor32; Dst: PColor32; Count: Integer);\n<\/pre><\/div>\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Combine<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\nfunction CombineReg(X, Y: TColor32; W: Cardinal): TColor32;\nprocedure CombineMem(X: TColor32; var Y: TColor32; W: Cardinal);\n<\/pre><\/div>\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Master alpha functions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Some blend functions, notably those with the <strong>Ex<\/strong> suffix, takes an extra parameter <strong>M<\/strong> specifying a <em>master alpha<\/em> value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This master alpha is used to scale the alpha values used in the Blend or Merge operations. Thus the Blend operation becomes:<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\[S_{ARGB} = (M * F_A) * F_{ARGB} + (1 &#8211; (M * F_A)) * B_{ARGB}\\]<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">and the Merge operation becomes:<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\[S_A = 1 &#8211; (1 &#8211; (M * F_A)) * (1 &#8211; B_A)\\]\n\\[S_{RGB} = \\frac{ (M * F_A) * F_{RGB} + B_A * (1 &#8211; (M * F_A)) * B_{RGB} }{S_A} \\]<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Note that while <strong>M<\/strong> is declared as a Cardinal, it should only contain values in the [0..255] range when used with the standard blend and merge functions; They do not perform range checking and the result in case <strong>M<\/strong> &gt; 255 is undefined. For custom blend functions, such as those you write yourself, there are no restriction on the value of <strong>M<\/strong>; The interpretation of the value depends entirely on the function.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">RGB alpha functions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Most blend functions applies a single alpha value to each of the R, G, and B channels. However in some situations it is necessary to blend each channel independently and for this we have the functions with the <strong>RGB<\/strong> suffix; These functions does not use the alpha channel of <strong>F<\/strong> when blending. Instead they use the individual R, G, and B components of the <strong>W<\/strong> parameter as the alpha value:<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\[S_{RGB} = (F_{RGB} &#8211; B_{RGB}) * W_{RGB} + B_{RGB}\\]<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Note that the <strong>W<\/strong> parameter, while declared as a Cardinal, is in fact a TColor32 value where the A channel is ignored.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">BlendReg, MergeReg<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nfunction BlendReg(F, B: TColor32): TColor32;\nfunction MergeReg(F, B: TColor32): TColor32;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Blends or Merges <strong>F<\/strong> onto <strong>B<\/strong>, returning <strong>S<\/strong>.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">BlendMem, MergeMem<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nprocedure BlendMem(F: TColor32; var B: TColor32);\nprocedure MergeMem(F: TColor32; var B: TColor32);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Blends or Merges <strong>F<\/strong> onto <strong>B<\/strong>, returning <strong>S<\/strong> in <strong>B<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">BlendMem is optimized so that it excludes writing operation for fully transparent foreground pixels and reading operation for fully opaque ones.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">BlendMems<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nprocedure BlendMems(F: TColor32; B: PColor32; Count: Integer);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Blends <strong>F<\/strong> onto an array of <strong>Count<\/strong> pixels pointed to by <strong>B<\/strong>.<br>Corresponds to the following pseudo code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\nprocedure BlendMems(F: TColor32; B: PColor32; Count: Integer);\nbegin\n  while (Count &gt; 0) do\n  begin\n    BlendMem(F, B^);\n    Inc(B);\n    Dec(Count);\n  end;\nend;\n<\/pre><\/div>\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">BlendRegEx, MergeRegEx<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nfunction BlendRegEx(F, B: TColor32; M: Cardinal): TColor32;\nfunction MergeRegEx(F, B: TColor32; M: Cardinal): TColor32;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Blends or Merges, applying the master alpha <strong>M<\/strong>, <strong>F<\/strong> onto <strong>B<\/strong>, returning <strong>S<\/strong>.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">BlendMemEx. MergeMemEx<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nprocedure BlendMemEx(F: TColor32; var B: TColor32; M: Cardinal);\nprocedure MergeMemEx(F: TColor32; var B: TColor32; M: Cardinal);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Blends or Merges, applying the master alpha <strong>M<\/strong>, <strong>F<\/strong> onto <strong>B<\/strong>, returning <strong>S<\/strong> in <strong>B<\/strong>.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">BlendRegRGB<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nfunction BlendRegRGB(F, B: TColor32; W: Cardinal): TColor32;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Blends <strong>F<\/strong> onto <strong>B<\/strong>, using the alpha specified by <strong>W<\/strong>, returning <strong>S<\/strong>.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">BlendMemRGB<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nprocedure BlendMemRGB(F: TColor32; var B: TColor32; W: Cardinal);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Blends or Merges <strong>F<\/strong> onto <strong>B<\/strong>, using the alpha specified by <strong>W<\/strong>, returning <strong>S<\/strong> in <strong>B<\/strong>.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">BlendLine, MergeLine<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nprocedure BlendLine(Src, Dst: PColor32; Count: Integer);\nprocedure MergeLine(Src, Dst: PColor32; Count: Integer);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Blends or Merges an array of <strong>Count<\/strong> pixels pointed to by <strong>Src<\/strong> onto an array of pixels pointed to by <strong>Dst<\/strong>.<br>Corresponds to the following pseudo code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\nprocedure BlendLine(Src, Dst: PColor32; Count: Integer);\nbegin\n  while (Count &gt; 0) do\n  begin\n    BlendMem(Src^, Dst^);\n    Inc(Src);\n    Inc(Dst);\n    Dec(Count);\n  end;\nend;\n<\/pre><\/div>\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">BlendLineEx, MergeLineEx<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nprocedure BlendLineEx(Src, Dst: PColor32; Count: Integer; M: Cardinal);\nprocedure MergeLineEx(Src, Dst: PColor32; Count: Integer; M: Cardinal);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Blends or Merges, applying the master alpha <strong>M<\/strong>, an array of <strong>Count<\/strong> pixels pointed to by <strong>Src<\/strong> onto an array of pixels pointed to by <strong>Dst<\/strong>.<br>Corresponds to the following pseudo code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\nprocedure BlendLineEx(Src, Dst: PColor32; Count: Integer; M: Cardinal);\nbegin\n  while (Count &gt; 0) do\n  begin\n    BlendMemEx(Src^, Dst^, M);\n    Inc(Src);\n    Inc(Dst);\n    Dec(Count);\n  end;\nend;\n<\/pre><\/div>\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">BlendLine1, MergeLine1<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nprocedure BlendLine1(Src: TColor32; Dst: PColor32; Count: Integer);\nprocedure MergeLine1(Src: TColor32; Dst: PColor32; Count: Integer);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Blends or Merges the single color <strong>Src<\/strong> onto an array of <strong>Count<\/strong> pixels pointed to by <strong>Dst<\/strong>.<br>Corresponds to the following pseudo code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\nprocedure BlendLine1(Src: TColor32; Dst: PColor32; Count: Integer);\nbegin\n  while (Count &gt; 0) do\n  begin\n    BlendMem(Src, Dst^);\n    Inc(Dst);\n    Dec(Count);\n  end;\nend;\n<\/pre><\/div>\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">CombineReg<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nfunction CombineReg(X, Y: TColor32; W: Cardinal): TColor32;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Interpolates between <strong>X<\/strong> and <strong>Y<\/strong>, using the weight <strong>W<\/strong>, returning <strong>S<\/strong>.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">CombineMem<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nprocedure CombineMem(X: TColor32; var Y: TColor32; W: Cardinal);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Interpolates between <strong>X<\/strong> and <strong>Y<\/strong>, using the weight <strong>W<\/strong>, returning <strong>S<\/strong> in <strong>Y<\/strong>.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">CombineLine<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; gutter: false; title: ; notranslate\" title=\"\">\nprocedure CombineLine(Src, Dst: PColor32; Count: Integer; W: Cardinal);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Interpolates between the colors of the <strong>Count<\/strong> individual pixels in the arrays <strong>Src<\/strong> and <strong>Dst<\/strong>, using the weight <strong>W<\/strong>, and stores the result in the <strong>Dst<\/strong> pixels.<br>Corresponds to the following pseudo code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\nprocedure CombineLine(Src, Dst: PColor32; Count: Integer; W: Cardinal);\nbegin\n  while (Count &gt; 0) do\n  begin\n    CombineMem(Src^, Dst^, W);\n    Inc(Src);\n    Inc(Dst);\n    Dec(Count);\n  end;\nend;\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Alpha composition, or alpha blending as it is perhaps better known, is the process of combining one image with another while taking the transparency of the images into account. Graphics32 supports three fundamental blend operations: Blend, Merge, and Combine. Blend<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-325","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/pages\/325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/comments?post=325"}],"version-history":[{"count":25,"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/pages\/325\/revisions"}],"predecessor-version":[{"id":405,"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/pages\/325\/revisions\/405"}],"wp:attachment":[{"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/media?parent=325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}