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


Golang color.ModelFunc函數代碼示例

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


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

示例1: ColorConverter

// ColorConverter compares a color to another. IF it matches, return
// the new color.
func ColorConverter(c1 color.Color, c2 color.Color) color.Model {
	return color.ModelFunc(func(c color.Color) color.Color {
		cR, cG, cB, cA := c.RGBA()
		c1R, c1G, c1B, c1A := c1.RGBA()
		if cR == c1R && cG == c1G && cB == c1B && cA == c1A {
			return c2
		}
		return c
	})
}
開發者ID:ShaleApps,項目名稱:imgutil,代碼行數:12,代碼來源:imaging.go

示例2: At

// At implements image.Image.At
func (p *Image) At(x, y int) color.Color {
	return p.RGBAAt(x, y)
}

// RGBAAt returns the color of the pixel at (x, y) as RGBA.
func (p *Image) RGBAAt(x, y int) color.RGBA {
	if !(image.Point{x, y}.In(p.Rect)) {
		return color.RGBA{}
	}
	i := (y-p.Rect.Min.Y)*p.Stride + (x-p.Rect.Min.X)*3
	return color.RGBA{p.Pix[i+0], p.Pix[i+1], p.Pix[i+2], 0xFF}
}

// ColorModel is RGB color model instance
var ColorModel = color.ModelFunc(rgbModel)

func rgbModel(c color.Color) color.Color {
	if _, ok := c.(RGB); ok {
		return c
	}
	r, g, b, _ := c.RGBA()
	return RGB{uint8(r >> 8), uint8(g >> 8), uint8(b >> 8)}
}

// RGB color
type RGB struct {
	R, G, B uint8
}

// RGBA implements Color.RGBA
開發者ID:edvakf,項目名稱:go-libjpeg,代碼行數:31,代碼來源:rgb.go

示例3: ColorModel

func (m Image) ColorModel() color.Model {
	return color.ModelFunc(m.rgbaColor)
}
開發者ID:rei-m,項目名稱:go-tour,代碼行數:3,代碼來源:60.go

示例4: RGBA

// 32-bit floating point RGBA color data type.
type Color struct {
	R, G, B, A float32
}

// Implements image/color.Color interface.
func (c Color) RGBA() (r, g, b, a uint32) {
	r = uint32(c.R * fMaxUint16)
	g = uint32(c.G * fMaxUint16)
	b = uint32(c.B * fMaxUint16)
	a = uint32(c.A * fMaxUint16)
	return
}

func colorModel(c color.Color) color.Color {
	if _, ok := c.(Color); ok {
		return c
	}
	r, g, b, a := c.RGBA()
	return Color{
		R: float32(r) / float32(fMaxUint16),
		G: float32(g) / float32(fMaxUint16),
		B: float32(b) / float32(fMaxUint16),
		A: float32(a) / float32(fMaxUint16),
	}
}

// ColorModel represents the graphics color model (i.e. normalized 32-bit
// floating point values RGBA color).
var ColorModel color.Model = color.ModelFunc(colorModel)
開發者ID:pombredanne,項目名稱:rand,代碼行數:30,代碼來源:color.go

示例5: bgraModel

	r |= r >> 8
	g = uint32(c.BGRA) << 8 & 0xf000
	g |= g >> 4
	g |= g >> 8
	b = uint32(c.BGRA) << 12 & 0xf000
	b |= b >> 4
	b |= b >> 8
	a = uint32(c.BGRA) << 0 & 0xf000
	a |= a >> 4
	a |= a >> 8
	return r, g, b, a
}

// Model for RGB565 and BGRA used by Dxt and GL
var (
	BGRAModel     color.Model = color.ModelFunc(bgraModel)
	BGR565Model   color.Model = color.ModelFunc(bgr565Model)
	BGRA5551Model color.Model = color.ModelFunc(bgra5551Model)
	BGRA4444Model color.Model = color.ModelFunc(bgra4444Model)
)

func bgraModel(c color.Color) color.Color {
	if _, ok := c.(BGRA); ok {
		return c
	}
	r, g, b, a := c.RGBA()
	return BGRA{uint8(b >> 8), uint8(g >> 8), uint8(r >> 8), uint8(a >> 8)}
}

func bgr565Model(c color.Color) color.Color {
	if _, ok := c.(BGR565); ok {
開發者ID:spate,項目名稱:glimage,代碼行數:31,代碼來源:color.go

示例6: ColorModel

func ColorModel(channels int, dataType reflect.Kind) color.Model {
	return color.ModelFunc(func(c color.Color) color.Color {
		return colorModelConvert(channels, dataType, c)
	})
}
開發者ID:bradberger,項目名稱:webp,代碼行數:5,代碼來源:image_color.go

示例7: RGBA

// Copyright 2012 The Gorilla Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package color

import (
	"image/color"
	"math"
)

// HSLModel converts any Color to a HSL color.
var HSLModel = color.ModelFunc(hslModel)

// HSL represents a cylindrical coordinate of points in an RGB color model.
//
// Values are in the range 0 to 1.
type HSL struct {
	H, S, L float64
}

// RGBA returns the alpha-premultiplied red, green, blue and alpha values
// for the HSL.
func (c HSL) RGBA() (uint32, uint32, uint32, uint32) {
	r, g, b := HSLToRGB(c.H, c.S, c.L)
	return uint32(r) * 0x101, uint32(g) * 0x101, uint32(b) * 0x101, 0xffff
}

// hslModel converts a Color to HSL.
func hslModel(c color.Color) color.Color {
	if _, ok := c.(HSL); ok {
開發者ID:shawnps,項目名稱:kanjihub,代碼行數:31,代碼來源:hsl.go

示例8: Bounds

// Its contents can be found in the enclosed LICENSE file.

package framebuffer

import (
	"image"
	"image/color"
)

var RGB555Model = color.ModelFunc(
	func(c color.Color) color.Color {
		if _, ok := c.(RGBColor); ok {
			return c
		}

		r, g, b, _ := c.RGBA()
		return RGBColor{
			uint8(r>>8) & mask5,
			uint8(g>>8) & mask5,
			uint8(b>>8) & mask5,
		}
	})

type RGB555 struct {
	Pix    []byte
	Rect   image.Rectangle
	Stride int
}

func (i *RGB555) Bounds() image.Rectangle { return i.Rect }
func (i *RGB555) ColorModel() color.Model { return RGB555Model }
開發者ID:576613133,項目名稱:framebuffer,代碼行數:31,代碼來源:rgb555.go

示例9: Bounds

// Its contents can be found in the enclosed LICENSE file.

package framebuffer

import (
	"image"
	"image/color"
)

var RGB565Model = color.ModelFunc(
	func(c color.Color) color.Color {
		if _, ok := c.(RGBColor); ok {
			return c
		}

		r, g, b, _ := c.RGBA()
		return RGBColor{
			uint8(r >> (8 + (8 - 5))),
			uint8(g >> (8 + (8 - 6))),
			uint8(b >> (8 + (8 - 5))),
		}
	})

type RGB565 struct {
	Pix    []byte
	Rect   image.Rectangle
	Stride int
}

func (i *RGB565) Bounds() image.Rectangle { return i.Rect }
func (i *RGB565) ColorModel() color.Model { return RGB565Model }
開發者ID:samuel,項目名稱:framebuffer,代碼行數:31,代碼來源:rgb565.go

示例10: Less

func (s QuantizedColorSlice) Less(i, j int) bool { return uint16(s[i]) < uint16(s[j]) }
func (s QuantizedColorSlice) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }

// QuantizedColorGenerator creates a new QuantizedColor from a given red, green, and blue value.
var QuantizedColorGenerator = func(r, g, b uint8) QuantizedColor {
	quantizedRed := quantizeColorValue(r)
	quantizedGreen := quantizeColorValue(g)
	quantizedBlue := quantizeColorValue(b)
	return QuantizedColor((quantizedRed << (quantizeWordWidth + quantizeWordWidth)) | (quantizedGreen << quantizeWordWidth) | quantizedBlue)
}

// QuantizedColorModel is the color.Model for the QuantizedColor type.
var QuantizedColorModel = color.ModelFunc(func(c color.Color) color.Color {
	if _, ok := c.(QuantizedColor); ok {
		return c
	}
	nrgba := color.NRGBAModel.Convert(c).(color.NRGBA)
	return QuantizedColorGenerator(nrgba.R, nrgba.G, nrgba.B)
})

// QuantizedColor represents a reduced RGB color space.
type QuantizedColor uint16

// RGBA implements the color.Color interface.
func (q QuantizedColor) RGBA() (uint32, uint32, uint32, uint32) {
	r := uint32(q.ApproximateRed())
	r |= r << 8
	g := uint32(q.ApproximateGreen())
	g |= g << 8
	b := uint32(q.ApproximateBlue())
	b |= b << 8
開發者ID:RobCherry,項目名稱:vibrant,代碼行數:31,代碼來源:quantized_color.go

示例11: PackedRGB

}

// PackedRGB is the packed int representing the RGB value (ignores the alpha channel).
func (c RGBAInt) PackedRGB() uint32 {
	return c.PackedRGBA() | (uint32(0xFF) << 24)
}

func (c RGBAInt) String() string {
	return fmt.Sprintf("0x%06s", strings.ToUpper(strconv.FormatUint(uint64(c.PackedRGBA()), 16)))
}

// RGBAIntModel is the color.Model for the RGBAInt type.
var RGBAIntModel = color.ModelFunc(func(c color.Color) color.Color {
	if _, ok := c.(RGBAInt); ok {
		return c
	}
	nrgba := color.NRGBAModel.Convert(c).(color.NRGBA)
	return RGBAInt((uint32(nrgba.A) << 24) | (uint32(nrgba.R) << 16) | (uint32(nrgba.G) << 8) | uint32(nrgba.B))
})

// HSL represents the HSL value for an RGBA color.
type HSL struct {
	H, S, L float64
	A       uint8
}

// RGBA implements the color.Color interface.
func (c HSL) RGBA() (uint32, uint32, uint32, uint32) {
	r, g, b := hslToRGB(c.H, c.S, c.L)
	return color.NRGBA{r, g, b, c.A}.RGBA()
}
開發者ID:RobCherry,項目名稱:vibrant,代碼行數:31,代碼來源:color.go

示例12: RGBA

	if littleEndian {
		self.Pix[i+0] = c1.B
		self.Pix[i+1] = c1.G
		self.Pix[i+2] = c1.R
	} else {
		self.Pix[i+1] = c1.R
		self.Pix[i+2] = c1.G
		self.Pix[i+3] = c1.B
	}
}

var BGRNColorModel = color.ModelFunc(
	func(c color.Color) color.Color {
		if _, ok := c.(BGRNColor); ok {
			return c
		}
		r, g, b, _ := c.RGBA()
		return BGRNColor{R: uint8(r >> 8), G: uint8(g >> 8), B: uint8(b >> 8)}
	},
)

type BGRNColor struct {
	B, G, R uint8
}

func (c BGRNColor) RGBA() (r, g, b, a uint32) {
	r = uint32(c.R)
	r |= r << 8

	g = uint32(c.G)
	g |= g << 8
開發者ID:mantyr,項目名稱:go-cairo,代碼行數:31,代碼來源:bgrnimage.go

示例13: ColorModel

func (c Color) ColorModel() color.Model { return color.ModelFunc(toColor) }
開發者ID:zxpbenson,項目名稱:rog-go,代碼行數:1,代碼來源:color.go

示例14: RGBA

func (c YCbCrColor) RGBA() (uint32, uint32, uint32, uint32) {
	r, g, b := YCbCrToRGB(c.Y, c.Cb, c.Cr)
	return uint32(r) * 0x101, uint32(g) * 0x101, uint32(b) * 0x101, 0xffff
}

func toYCbCrColor(c color.Color) color.Color {
	if _, ok := c.(YCbCrColor); ok {
		return c
	}
	r, g, b, _ := c.RGBA()
	y, u, v := RGBToYCbCr(uint8(r>>8), uint8(g>>8), uint8(b>>8))
	return YCbCrColor{y, u, v}
}

// YCbCrColorModel is the color model for YCbCrColor.
var YCbCrColorModel color.Model = color.ModelFunc(toYCbCrColor)

// SubsampleRatio is the chroma subsample ratio used in a YCbCr image.
type SubsampleRatio int

const (
	SubsampleRatio444 SubsampleRatio = iota
	SubsampleRatio422
	SubsampleRatio420
)

// YCbCr is an in-memory image of YCbCr colors. There is one Y sample per pixel,
// but each Cb and Cr sample can span one or more pixels.
// YStride is the Y slice index delta between vertically adjacent pixels.
// CStride is the Cb and Cr slice index delta between vertically adjacent pixels
// that map to separate chroma samples.
開發者ID:Sunmonds,項目名稱:gcc,代碼行數:31,代碼來源:ycbcr.go

示例15: Color

}

//Color returns a without the alpha channel.
func (a AlphaColor) Color() Color {
	return Color{a.R, a.G, a.B}
}

//These models can convert any color.Color to themselves.
//
//The conversion may be lossy.
var (
	ColorModel = color.ModelFunc(func(c color.Color) color.Color {
		if c, ok := c.(Color); ok {
			return c
		}
		if c, ok := c.(AlphaColor); ok {
			return Color{c.R, c.G, c.B}
		}
		r, g, b, _ := c.RGBA()
		return Color{cto01(r), cto01(g), cto01(b)}
	})
	AlphaColorModel = color.ModelFunc(func(c color.Color) color.Color {
		if c, ok := c.(AlphaColor); ok {
			return c
		}
		if c, ok := c.(Color); ok {
			return AlphaColor{c.R, c.G, c.B, 1}
		}
		r, g, b, a := c.RGBA()
		return AlphaColor{cto01(r), cto01(g), cto01(b), cto01(a)}
	})
)
開發者ID:jimmyfrasche,項目名稱:cairo,代碼行數:32,代碼來源:color.go


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