MCPcopy
hub / github.com/anthonynsimon/bild / Opacity

Function Opacity

blend/blend.go:286–299  ·  view source on GitHub ↗

Opacity returns an image which blends the two input images by the percentage provided. Percent must be of range 0 <= percent <= 1.0

(bg image.Image, fg image.Image, percent float64)

Source from the content-addressed store, hash-verified

284// Opacity returns an image which blends the two input images by the percentage provided.
285// Percent must be of range 0 <= percent <= 1.0
286func Opacity(bg image.Image, fg image.Image, percent float64) *image.RGBA {
287 percent = f64.Clamp(percent, 0, 1.0)
288
289 dst := Blend(bg, fg, func(c0, c1 fcolor.RGBAF64) fcolor.RGBAF64 {
290 r := c1.R*percent + (1-percent)*c0.R
291 g := c1.G*percent + (1-percent)*c0.G
292 b := c1.B*percent + (1-percent)*c0.B
293
294 c2 := fcolor.RGBAF64{R: r, G: g, B: b, A: c1.A}
295 return alphaComp(c0, c2)
296 })
297
298 return dst
299}
300
301// Darken combines the foreground and background images by picking the darkest value per channel
302// for each pixel. The result is then returned.

Callers 2

buildBlendModeCommandFunction · 0.92
TestOpacityFunction · 0.85

Calls 3

ClampFunction · 0.92
BlendFunction · 0.85
alphaCompFunction · 0.85

Tested by 1

TestOpacityFunction · 0.68