libcosmic/cosmic/cosmic_theme/palette/blend/index.html
2026-04-18 20:11:25 +00:00

30 lines
No EOL
7.9 KiB
HTML

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Color blending and blending equations."><title>cosmic::cosmic_theme::palette::blend - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../static.files/storage-68b7e25d.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module blend</a></h2><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#traits" title="Traits">Traits</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In cosmic::<wbr>cosmic_<wbr>theme::<wbr>palette</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../index.html">cosmic</a>::<wbr><a href="../../index.html">cosmic_theme</a>::<wbr><a href="../index.html">palette</a></div><h1>Module <span>blend</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="https://docs.rs/palette/0.7.6/src/palette/lib.rs.html#345">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Color blending and blending equations.</p>
<p>Palette offers both OpenGL style blending equations, as well as most of the
SVG composition operators (also common in photo manipulation software). The
composition operators are all implemented in the <a href="trait.Compose.html" title="trait cosmic::cosmic_theme::palette::blend::Compose"><code>Compose</code></a> and <a href="trait.Blend.html" title="trait cosmic::cosmic_theme::palette::blend::Blend"><code>Blend</code></a>
traits, and ready to use with any appropriate color type:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::{blend::Blend, LinSrgba};
<span class="kw">let </span>a = LinSrgba::new(<span class="number">0.2</span>, <span class="number">0.5</span>, <span class="number">0.1</span>, <span class="number">0.8</span>);
<span class="kw">let </span>b = LinSrgba::new(<span class="number">0.6</span>, <span class="number">0.3</span>, <span class="number">0.5</span>, <span class="number">0.1</span>);
<span class="kw">let </span>c = a.overlay(b);</code></pre></div>
<p>Blending equations can be defined using the <a href="struct.Equations.html" title="struct cosmic::cosmic_theme::palette::blend::Equations"><code>Equations</code></a> type, which is
then passed to the <code>blend</code> function, from the <code>Blend</code> trait:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::LinSrgba;
<span class="kw">use </span>palette::blend::{BlendWith, Equations, Parameter};
<span class="kw">let </span>blend_mode = Equations::from_parameters(
Parameter::SourceAlpha,
Parameter::OneMinusSourceAlpha
);
<span class="kw">let </span>a = LinSrgba::new(<span class="number">0.2</span>, <span class="number">0.5</span>, <span class="number">0.1</span>, <span class="number">0.8</span>);
<span class="kw">let </span>b = LinSrgba::new(<span class="number">0.6</span>, <span class="number">0.3</span>, <span class="number">0.5</span>, <span class="number">0.1</span>);
<span class="kw">let </span>c = a.blend_with(b, blend_mode);</code></pre></div>
<p>Note that blending will use <a href="../alpha/struct.PreAlpha.html" title="struct cosmic::cosmic_theme::palette::alpha::PreAlpha">premultiplied alpha</a>,
which may result in loss of some color information in some cases. One such
case is that a completely transparent resultant color will become black.</p>
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.Equations.html" title="struct cosmic::cosmic_theme::palette::blend::Equations">Equations</a></dt><dd>A pair of blending equations and corresponding parameters.</dd><dt><a class="struct" href="struct.Parameters.html" title="struct cosmic::cosmic_theme::palette::blend::Parameters">Parameters</a></dt><dd>A pair of source and destination parameters.</dd><dt><a class="struct" href="struct.PreAlpha.html" title="struct cosmic::cosmic_theme::palette::blend::PreAlpha">PreAlpha</a></dt><dd>Premultiplied alpha wrapper.</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.Equation.html" title="enum cosmic::cosmic_theme::palette::blend::Equation">Equation</a></dt><dd>A blending equation.</dd><dt><a class="enum" href="enum.Parameter.html" title="enum cosmic::cosmic_theme::palette::blend::Parameter">Parameter</a></dt><dd>A blending parameter.</dd></dl><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><dl class="item-table"><dt><a class="trait" href="trait.Blend.html" title="trait cosmic::cosmic_theme::palette::blend::Blend">Blend</a></dt><dd>A trait for different ways of mixing colors together.</dd><dt><a class="trait" href="trait.BlendFunction.html" title="trait cosmic::cosmic_theme::palette::blend::BlendFunction">Blend<wbr>Function</a></dt><dd>A trait for custom blend functions.</dd><dt><a class="trait" href="trait.BlendWith.html" title="trait cosmic::cosmic_theme::palette::blend::BlendWith">Blend<wbr>With</a></dt><dd>Blending with a custom blend function.</dd><dt><a class="trait" href="trait.Compose.html" title="trait cosmic::cosmic_theme::palette::blend::Compose">Compose</a></dt><dd>The Porter Duff composition operators, <a href="https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators">as described by
W3C</a>.</dd><dt><a class="trait" href="trait.Premultiply.html" title="trait cosmic::cosmic_theme::palette::blend::Premultiply">Premultiply</a></dt><dd>Alpha masking and unmasking.</dd></dl></section></div></main></body></html>