當前位置: 首頁>>代碼示例>>Golang>>正文


Golang utils.RatioRGBA函數代碼示例

本文整理匯總了Golang中github.com/hawx/img/utils.RatioRGBA函數的典型用法代碼示例。如果您正苦於以下問題:Golang RatioRGBA函數的具體用法?Golang RatioRGBA怎麽用?Golang RatioRGBA使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了RatioRGBA函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/hawx/img/utils.RatioRGBA函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。