Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小雨青年
bild
提交
c58fb61a
B
bild
项目概览
小雨青年
/
bild
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
bild
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
c58fb61a
编写于
4月 22, 2020
作者:
A
Anthony N. Simon
提交者:
GitHub
4月 22, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #81 from BluePsyduck/export-blend
Make blend() exported to allow for custom blending implementations.
上级
e55eddad
12e94265
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
18 addition
and
18 deletion
+18
-18
blend/blend.go
blend/blend.go
+18
-18
未找到文件。
blend/blend.go
浏览文件 @
c58fb61a
...
...
@@ -14,7 +14,7 @@ import (
// Normal combines the foreground and background images by placing the foreground over the
// background using alpha compositing. The resulting image is then returned.
func
Normal
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
return
alphaComp
(
c0
,
c1
)
})
...
...
@@ -24,7 +24,7 @@ func Normal(bg image.Image, fg image.Image) *image.RGBA {
// Add combines the foreground and background images by adding their values and
// returns the resulting image.
func
Add
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
r
:=
c0
.
R
+
c1
.
R
g
:=
c0
.
G
+
c1
.
G
b
:=
c0
.
B
+
c1
.
B
...
...
@@ -39,7 +39,7 @@ func Add(bg image.Image, fg image.Image) *image.RGBA {
// Multiply combines the foreground and background images by multiplying their
// normalized values and returns the resulting image.
func
Multiply
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
r
:=
c0
.
R
*
c1
.
R
g
:=
c0
.
G
*
c1
.
G
b
:=
c0
.
B
*
c1
.
B
...
...
@@ -54,7 +54,7 @@ func Multiply(bg image.Image, fg image.Image) *image.RGBA {
// Overlay combines the foreground and background images by using Multiply when channel values < 0.5
// or using Screen otherwise and returns the resulting image.
func
Overlay
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
var
r
,
g
,
b
float64
if
c0
.
R
>
0.5
{
r
=
1
-
(
1
-
2
*
(
c0
.
R
-
0.5
))
*
(
1
-
c1
.
R
)
...
...
@@ -82,7 +82,7 @@ func Overlay(bg image.Image, fg image.Image) *image.RGBA {
// SoftLight combines the foreground and background images by using Pegtop's Soft Light formula and
// returns the resulting image.
func
SoftLight
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
r
:=
(
1
-
2
*
c1
.
R
)
*
c0
.
R
*
c0
.
R
+
2
*
c0
.
R
*
c1
.
R
g
:=
(
1
-
2
*
c1
.
G
)
*
c0
.
G
*
c0
.
G
+
2
*
c0
.
G
*
c1
.
G
b
:=
(
1
-
2
*
c1
.
B
)
*
c0
.
B
*
c0
.
B
+
2
*
c0
.
B
*
c1
.
B
...
...
@@ -96,7 +96,7 @@ func SoftLight(bg image.Image, fg image.Image) *image.RGBA {
// Screen combines the foreground and background images by inverting, multiplying and inverting the output.
// The result is a brighter image which is then returned.
func
Screen
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
r
:=
1
-
(
1
-
c0
.
R
)
*
(
1
-
c1
.
R
)
g
:=
1
-
(
1
-
c0
.
G
)
*
(
1
-
c1
.
G
)
b
:=
1
-
(
1
-
c0
.
B
)
*
(
1
-
c1
.
B
)
...
...
@@ -111,7 +111,7 @@ func Screen(bg image.Image, fg image.Image) *image.RGBA {
// Difference calculates the absolute difference between the foreground and background images and
// returns the resulting image.
func
Difference
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
r
:=
math
.
Abs
(
c0
.
R
-
c1
.
R
)
g
:=
math
.
Abs
(
c0
.
G
-
c1
.
G
)
b
:=
math
.
Abs
(
c0
.
B
-
c1
.
B
)
...
...
@@ -126,7 +126,7 @@ func Difference(bg image.Image, fg image.Image) *image.RGBA {
// Divide combines the foreground and background images by diving the values from the background
// by the foreground and returns the resulting image.
func
Divide
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
var
r
,
g
,
b
float64
if
c1
.
R
==
0
{
r
=
1
...
...
@@ -154,7 +154,7 @@ func Divide(bg image.Image, fg image.Image) *image.RGBA {
// ColorBurn combines the foreground and background images by dividing the inverted
// background by the foreground image and then inverting the result which is then returned.
func
ColorBurn
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
var
r
,
g
,
b
float64
if
c1
.
R
==
0
{
r
=
0
...
...
@@ -182,7 +182,7 @@ func ColorBurn(bg image.Image, fg image.Image) *image.RGBA {
// Exclusion combines the foreground and background images applying the Exclusion blend mode and
// returns the resulting image.
func
Exclusion
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
r
:=
0.5
-
2
*
(
c0
.
R
-
0.5
)
*
(
c1
.
R
-
0.5
)
g
:=
0.5
-
2
*
(
c0
.
G
-
0.5
)
*
(
c1
.
G
-
0.5
)
b
:=
0.5
-
2
*
(
c0
.
B
-
0.5
)
*
(
c1
.
B
-
0.5
)
...
...
@@ -198,7 +198,7 @@ func Exclusion(bg image.Image, fg image.Image) *image.RGBA {
// ColorDodge combines the foreground and background images by dividing background by the
// inverted foreground image and returns the result.
func
ColorDodge
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
var
r
,
g
,
b
float64
if
c1
.
R
==
1
{
r
=
1
...
...
@@ -226,7 +226,7 @@ func ColorDodge(bg image.Image, fg image.Image) *image.RGBA {
// LinearBurn combines the foreground and background images by adding them and
// then subtracting 255 (1.0 in normalized scale). The resulting image is then returned.
func
LinearBurn
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
r
:=
c0
.
R
+
c1
.
R
-
1
g
:=
c0
.
G
+
c1
.
G
-
1
b
:=
c0
.
B
+
c1
.
B
-
1
...
...
@@ -241,7 +241,7 @@ func LinearBurn(bg image.Image, fg image.Image) *image.RGBA {
// LinearLight combines the foreground and background images by a mix of a Linear Dodge and
// Linear Burn operation. The resulting image is then returned.
func
LinearLight
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
var
r
,
g
,
b
float64
if
c1
.
R
>
0.5
{
r
=
c0
.
R
+
2
*
c1
.
R
-
0.5
...
...
@@ -269,7 +269,7 @@ func LinearLight(bg image.Image, fg image.Image) *image.RGBA {
// Subtract combines the foreground and background images by Subtracting the background from the
// foreground. The result is then returned.
func
Subtract
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
r
:=
c1
.
R
-
c0
.
R
g
:=
c1
.
G
-
c0
.
G
b
:=
c1
.
B
-
c0
.
B
...
...
@@ -286,7 +286,7 @@ func Subtract(bg image.Image, fg image.Image) *image.RGBA {
func
Opacity
(
bg
image
.
Image
,
fg
image
.
Image
,
percent
float64
)
*
image
.
RGBA
{
percent
=
f64
.
Clamp
(
percent
,
0
,
1.0
)
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
r
:=
c1
.
R
*
percent
+
(
1
-
percent
)
*
c0
.
R
g
:=
c1
.
G
*
percent
+
(
1
-
percent
)
*
c0
.
G
b
:=
c1
.
B
*
percent
+
(
1
-
percent
)
*
c0
.
B
...
...
@@ -301,7 +301,7 @@ func Opacity(bg image.Image, fg image.Image, percent float64) *image.RGBA {
// Darken combines the foreground and background images by picking the darkest value per channel
// for each pixel. The result is then returned.
func
Darken
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
r
:=
math
.
Min
(
c0
.
R
,
c1
.
R
)
g
:=
math
.
Min
(
c0
.
G
,
c1
.
G
)
b
:=
math
.
Min
(
c0
.
B
,
c1
.
B
)
...
...
@@ -316,7 +316,7 @@ func Darken(bg image.Image, fg image.Image) *image.RGBA {
// Lighten combines the foreground and background images by picking the brightest value per channel
// for each pixel. The result is then returned.
func
Lighten
(
bg
image
.
Image
,
fg
image
.
Image
)
*
image
.
RGBA
{
dst
:=
b
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
dst
:=
B
lend
(
bg
,
fg
,
func
(
c0
,
c1
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
{
r
:=
math
.
Max
(
c0
.
R
,
c1
.
R
)
g
:=
math
.
Max
(
c0
.
G
,
c1
.
G
)
b
:=
math
.
Max
(
c0
.
B
,
c1
.
B
)
...
...
@@ -331,7 +331,7 @@ func Lighten(bg image.Image, fg image.Image) *image.RGBA {
// Blend two images together by applying the provided function for each pixel.
// If images differ in size, the minimum width and height will be picked from each one
// when creating the resulting image.
func
b
lend
(
bg
image
.
Image
,
fg
image
.
Image
,
fn
func
(
fcolor
.
RGBAF64
,
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
)
*
image
.
RGBA
{
func
B
lend
(
bg
image
.
Image
,
fg
image
.
Image
,
fn
func
(
fcolor
.
RGBAF64
,
fcolor
.
RGBAF64
)
fcolor
.
RGBAF64
)
*
image
.
RGBA
{
bgBounds
:=
bg
.
Bounds
()
fgBounds
:=
fg
.
Bounds
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录