• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang utils.RatioRGBA函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/hawx/img/utils.RatioRGBA函数的典型用法代码示例。如果您正苦于以下问题:Golang RatioRGBA函数的具体用法?Golang RatioRGBA怎么用?Golang RatioRGBA使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了RatioRGBA函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: BlendPixel

// cb is backdrop colour, cs is source (blend layer) colour
func BlendPixel(cb, cs color.Color, f Blender) color.Color {
	// Uses methods described in "PDF Reference, Third Edition" from Adobe
	//  see: http://www.adobe.com/devnet/pdf/pdf_reference_archive.html

	// result colour
	cr := f(cb, cs)

	rb, gb, bb, ab := utils.RatioRGBA(cb)
	rs, gs, bs, as := utils.RatioRGBA(cs)
	rr, gr, br, _ := utils.RatioRGBA(cr)

	// Color compositing formula, expanded form. (Section 7.2.5)
	red := ((1 - as) * ab * rb) + ((1 - ab) * as * rs) + (ab * as * rr)
	green := ((1 - as) * ab * gb) + ((1 - ab) * as * gs) + (ab * as * gr)
	blue := ((1 - as) * ab * bb) + ((1 - ab) * as * bs) + (ab * as * br)

	// Union function. (Section 7.2.6)
	alpha := ab + as - (ab * as)

	return color.RGBA{
		uint8(utils.Truncatef(red * 255)),
		uint8(utils.Truncatef(green * 255)),
		uint8(utils.Truncatef(blue * 255)),
		uint8(utils.Truncatef(alpha * 255)),
	}
}
开发者ID:surma-dump,项目名称:img,代码行数:27,代码来源:blend.go


示例2: Dissolve

// Dissolve randomly selects pixels from the blend image, depending on their
// opacity. Blend pixels with higher opacities are more likely to be displayed.
func Dissolve(a, b image.Image) image.Image {
	ba := a.Bounds()
	bb := b.Bounds()
	width := int(utils.Min(uint32(ba.Dx()), uint32(bb.Dx())))
	height := int(utils.Min(uint32(ba.Dy()), uint32(bb.Dy())))

	result := image.NewRGBA(image.Rect(0, 0, width, height))

	for y := 0; y < height; y++ {
		for x := 0; x < width; x++ {
			// base colour
			rb, gb, bb, ab := utils.RatioRGBA(a.At(x, y))
			// blend colour
			rs, gs, bs, as := utils.RatioRGBA(b.At(x, y))

			toPaint := ratioNRGBA(rb, gb, bb, ab)

			if rand.Float64() < as {
				toPaint = ratioNRGBA(rs, gs, bs, 1)
			}

			result.Set(x, y, toPaint)
		}
	}

	return result
}
开发者ID:surma-dump,项目名称:img,代码行数:29,代码来源:blend.go


示例3: Lighter

// Lighter chooses the lightest colour by comparing the sum of the colour
// channels.
func Lighter(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, _ := utils.RatioRGBA(c)
		m, n, o, _ := utils.RatioRGBA(d)

		if i+j+k > m+n+o {
			return c
		}
		return d
	})
}
开发者ID:surma-dump,项目名称:img,代码行数:13,代码来源:blend.go


示例4: Dodge

// Dodge brightens the base colour to reflect the blend colour.
func Dodge(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.RatioRGBA(c)
		m, n, o, p := utils.RatioRGBA(d)

		r := i / (1 - m)
		g := j / (1 - n)
		b := k / (1 - o)
		a := p + l*(1-p)

		return ratioNRGBA(r, g, b, a)
	})
}
开发者ID:surma-dump,项目名称:img,代码行数:14,代码来源:blend.go


示例5: Screen

// Screen multiplies the complements of the base and blend colour channel
// values, then complements the result.
func Screen(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.RatioRGBA(c)
		m, n, o, p := utils.RatioRGBA(d)

		r := 1 - ((1 - i) * (1 - m))
		g := 1 - ((1 - j) * (1 - n))
		b := 1 - ((1 - k) * (1 - o))
		a := p + l*(1-p)

		return ratioNRGBA(r, g, b, a)
	})
}
开发者ID:surma-dump,项目名称:img,代码行数:15,代码来源:blend.go


示例6: Lighten

// Lightne selects the lighter of each pixels' colour channels.
func Lighten(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.RatioRGBA(c)
		m, n, o, p := utils.RatioRGBA(d)

		r := utils.Maxf(i, m)
		g := utils.Maxf(j, n)
		b := utils.Maxf(k, o)
		a := utils.Maxf(l, p)

		return ratioNRGBA(r, g, b, a)
	})
}
开发者ID:surma-dump,项目名称:img,代码行数:14,代码来源:blend.go


示例7: LinearBurn

// LinearBurn adds the values of each colour channel together, then subtracts
// white to produce a darker image.
func LinearBurn(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.RatioRGBA(c)
		m, n, o, p := utils.RatioRGBA(d)

		r := i + m - 1
		g := j + n - 1
		b := k + o - 1
		a := p + l*(1-p)

		return ratioNRGBA(r, g, b, a)
	})
}
开发者ID:surma-dump,项目名称:img,代码行数:15,代码来源:blend.go


示例8: Burn

// Burn darkens the base colour to reflect the blend colour.
func Burn(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.RatioRGBA(c)
		m, n, o, p := utils.RatioRGBA(d)

		r := 1 - ((1 - i) / m)
		g := 1 - ((1 - j) / n)
		b := 1 - ((1 - k) / o)
		a := p + l*(1-p)

		return ratioNRGBA(r, g, b, a)
	})
}
开发者ID:surma-dump,项目名称:img,代码行数:14,代码来源:blend.go


示例9: Multiply

// Multiply multiplies the base and blend image colour channels.
func Multiply(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.RatioRGBA(c)
		m, n, o, p := utils.RatioRGBA(d)

		r := i * m
		g := j * n
		b := k * o
		a := l * p

		return ratioNRGBA(r, g, b, a)
	})
}
开发者ID:surma-dump,项目名称:img,代码行数:14,代码来源:blend.go


示例10: Exclusion

// Exclusion creates an effect similar to, but lower in contrast than,
// difference.
func Exclusion(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.RatioRGBA(c)
		m, n, o, p := utils.RatioRGBA(d)

		r := m + i - (2 * m * i)
		g := n + j - (2 * n * j)
		b := o + k - (2 * o * k)
		a := p + l*(1-p)

		return ratioNRGBA(r, g, b, a)
	})
}
开发者ID:surma-dump,项目名称:img,代码行数:15,代码来源:blend.go


示例11: Difference

// Difference finds the absolute difference between the base and blend colours.
func Difference(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.RatioRGBA(c)
		m, n, o, p := utils.RatioRGBA(d)

		r := math.Abs(m - i)
		g := math.Abs(n - j)
		b := math.Abs(o - k)
		a := p + l*(1-p)

		return ratioNRGBA(r, g, b, a)
	})
}
开发者ID:surma-dump,项目名称:img,代码行数:14,代码来源:blend.go


示例12: BlendPixels

// BlendPixels takes the base and blend images and applies the given Blender to
// each of their pixel pairs.
func BlendPixels(a, b image.Image, f Blender) image.Image {
	ba := a.Bounds()
	bb := b.Bounds()
	width := int(utils.Min(uint32(ba.Dx()), uint32(bb.Dx())))
	height := int(utils.Min(uint32(ba.Dy()), uint32(bb.Dy())))

	result := image.NewRGBA(image.Rect(0, 0, width, height))

	for y := 0; y < height; y++ {
		for x := 0; x < width; x++ {
			// Uses methods described in "PDF Reference, Third Edition" from Adobe
			//  see: http://www.adobe.com/devnet/pdf/pdf_reference_archive.html

			// backdrop colour
			cb := a.At(x, y)
			// source colour
			cs := b.At(x, y)
			// result colour
			cr := f(cb, cs)

			rb, gb, bb, ab := utils.RatioRGBA(cb)
			rs, gs, bs, as := utils.RatioRGBA(cs)
			rr, gr, br, _ := utils.RatioRGBA(cr)

			// Color compositing formula, expanded form. (Section 7.2.5)
			red := ((1 - as) * ab * rb) + ((1 - ab) * as * rs) + (ab * as * rr)
			green := ((1 - as) * ab * gb) + ((1 - ab) * as * gs) + (ab * as * gr)
			blue := ((1 - as) * ab * bb) + ((1 - ab) * as * bs) + (ab * as * br)

			// Union function. (Section 7.2.6)
			alpha := ab + as - (ab * as)

			result.Set(x, y, color.RGBA{
				uint8(utils.Truncatef(red * 255)),
				uint8(utils.Truncatef(green * 255)),
				uint8(utils.Truncatef(blue * 255)),
				uint8(utils.Truncatef(alpha * 255)),
			})
		}
	}

	return result
}
开发者ID:surma-dump,项目名称:img,代码行数:45,代码来源:blend.go


示例13: HardMix

// HardMix adds the red, green and blue channel values of the blend colour to
// the RGB values of the base colour. It sets any values greater than 255 to
// 255, and anything less to 0. This therefore makes all pixels either red,
// green, blue, white or black.
func HardMix(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.RatioRGBA(c)
		m, n, o, p := utils.RatioRGBA(d)

		f := func(i, j float64) float64 {
			if j < 1-i {
				return 0
			}
			return 1
		}

		r := f(i, m)
		g := f(j, n)
		b := f(k, o)
		a := p + l*(1-p)

		return ratioNRGBA(r, g, b, a)
	})
}
开发者ID:surma-dump,项目名称:img,代码行数:24,代码来源:blend.go


示例14: LinearLight

// LinearLight lightens or darkens the image by changing the brightness. If the
// blend colour is lighter, the image is lightened; if the blend colour is
// darker, the image is darkened. It uses linear burn and linear dodge to darken
// or lighten.
func LinearLight(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.RatioRGBA(c)
		m, n, o, p := utils.RatioRGBA(d)

		f := func(i, j float64) float64 {
			if j > 0.5 {
				return i + 2*(j-0.5)
			}
			return i + 2*j - 1
		}

		r := f(i, m)
		g := f(j, n)
		b := f(k, o)
		a := p + l*(1-p)

		return ratioNRGBA(r, g, b, a)
	})
}
开发者ID:surma-dump,项目名称:img,代码行数:24,代码来源:blend.go


示例15: VividLight

// VividLight combines Dodge and Burn. Dodge applies to lighter colours, and
// Burn to darker.
func VividLight(a, b image.Image) image.Image {
	return BlendPixels(a, b, func(c, d color.Color) color.Color {
		i, j, k, l := utils.RatioRGBA(c)
		m, n, o, p := utils.RatioRGBA(d)

		f := func(i, j float64) float64 {
			if j > 0.5 {
				return i / (2 * (1 - j))
			}
			return 1 - (1-i)/(2*j)
		}

		r := f(i, m)
		g := f(j, n)
		b := f(k, o)
		a := p + l*(1-p)

		return ratioNRGBA(r, g, b, a)
	})
}
开发者ID:surma-dump,项目名称:img,代码行数:22,代码来源:blend.go


示例16: AdjustC

func AdjustC(value float64) utils.Composable {
	return func(c color.Color) color.Color {
		r, g, b, a := utils.RatioRGBA(c)

		r = utils.Truncatef(math.Pow(r, 1/value) * 255)
		g = utils.Truncatef(math.Pow(g, 1/value) * 255)
		b = utils.Truncatef(math.Pow(b, 1/value) * 255)

		return color.NRGBA{uint8(r), uint8(g), uint8(b), uint8(a * 255)}
	}
}
开发者ID:surma-dump,项目名称:img,代码行数:11,代码来源:gamma.go


示例17: UnsharpMask

// UnsharpMask sharpens the given Image using the unsharp mask technique.
// Basically the image is blurred, then subtracted from the original for
// differences above the threshold value.
func UnsharpMask(in image.Image, radius int, sigma, amount, threshold float64) image.Image {
	blurred := blur.Gaussian(in, radius, sigma, blur.IGNORE)
	bounds := in.Bounds()
	out := image.NewRGBA(bounds)

	// Absolute difference between a and b, returns float64 between 0 and 1.
	diff := func(a, b float64) float64 {
		if a > b {
			return a - b
		}
		return b - a
	}

	for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
		for x := bounds.Min.X; x < bounds.Max.X; x++ {
			ar, ag, ab, aa := utils.RatioRGBA(in.At(x, y))
			br, bg, bb, _ := utils.RatioRGBA(blurred.At(x, y))

			if diff(ar, br) >= threshold {
				ar = amount*(ar-br) + ar
			}

			if diff(ag, bg) >= threshold {
				ag = amount*(ag-bg) + ag
			}

			if diff(ab, bb) >= threshold {
				ab = amount*(ab-bb) + ab
			}

			out.Set(x, y, color.NRGBA{
				uint8(utils.Truncatef(ar * 255)),
				uint8(utils.Truncatef(ag * 255)),
				uint8(utils.Truncatef(ab * 255)),
				uint8(aa * 255),
			})
		}
	}

	return out
}
开发者ID:surma-dump,项目名称:img,代码行数:44,代码来源:sharpen.go


示例18: AlphaC

func AlphaC(adj utils.Adjuster) utils.Composable {
	return func(c color.Color) color.Color {
		r, g, b, a := utils.RatioRGBA(c)
		a = adj(a)
		if a > 1 {
			a = 1
		} else if a < 0 {
			a = 0
		}
		return color.NRGBA{uint8(r * 255), uint8(g * 255), uint8(b * 255), uint8(a * 255)}
	}
}
开发者ID:surma-dump,项目名称:img,代码行数:12,代码来源:channel.go


示例19: BlueC

func BlueC(adj utils.Adjuster) utils.Composable {
	return func(c color.Color) color.Color {
		r, g, b, a := utils.RatioRGBA(c)
		b = adj(b)
		if b > 1 {
			b = 1
		} else if b < 0 {
			b = 0
		}
		return color.NRGBA{uint8(r * 255), uint8(g * 255), uint8(b * 255), uint8(a * 255)}
	}
}
开发者ID:surma-dump,项目名称:img,代码行数:12,代码来源:channel.go


示例20: GreenC

func GreenC(adj utils.Adjuster) utils.Composable {
	return func(c color.Color) color.Color {
		r, g, b, a := utils.RatioRGBA(c)
		g = adj(g)
		if g > 1 {
			g = 1
		} else if g < 0 {
			g = 0
		}
		return color.NRGBA{uint8(r * 255), uint8(g * 255), uint8(b * 255), uint8(a * 255)}
	}
}
开发者ID:surma-dump,项目名称:img,代码行数:12,代码来源:channel.go



注:本文中的github.com/hawx/img/utils.RatioRGBA函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang db.Connection类代码示例发布时间:2022-05-28
下一篇:
Golang metrics.Parameters类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap