本文整理匯總了Golang中image.Paletted類的典型用法代碼示例。如果您正苦於以下問題:Golang Paletted類的具體用法?Golang Paletted怎麽用?Golang Paletted使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Paletted類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: pixel_is_light
func pixel_is_light(img *image.Paletted, x int, y int) bool {
r, g, b, _ := img.At(x, y).RGBA()
sum := r + g + b
return (sum > 0x18000) && (sum < 0x2e000)
}
示例2: palettedToRGBA
func palettedToRGBA(last *image.RGBA, in *image.Paletted) *image.RGBA {
out := image.NewRGBA(image.Rect(0, 0, 16, 16))
draw.Draw(out, out.Bounds(), last, last.Rect.Min, draw.Src)
draw.Draw(out, in.Bounds(), in, in.Rect.Min, draw.Over)
return out
}
示例3: b1
// 全填充正方形
//
// --------
// |######|
// |######|
// |######|
// --------
func b1(img *image.Paletted, x, y, size float64, angle int) {
isize := int(size)
ix := int(x)
iy := int(y)
for i := ix + 1; i < ix+isize; i++ {
for j := iy + 1; j < iy+isize; j++ {
img.SetColorIndex(i, j, 1)
}
}
}
示例4: newSetFuncPaletted
func newSetFuncPaletted(p *image.Paletted) SetFunc {
return func(x, y int, r, g, b, a uint32) {
i := p.PixOffset(x, y)
p.Pix[i] = uint8(p.Palette.Index(color.RGBA64{
R: uint16(r),
G: uint16(g),
B: uint16(b),
A: uint16(a),
}))
}
}
示例5: b2
// 中間小方塊
// ----------
// | |
// | #### |
// | #### |
// | |
// ----------
func b2(img *image.Paletted, x, y, size float64, angle int) {
l := size / 4
x = x + l
y = y + l
for i := x; i < x+2*l; i++ {
for j := y; j < y+2*l; j++ {
img.SetColorIndex(int(i), int(j), 1)
}
}
}
示例6: toPaletted
func toPaletted(o *ora.ORA, name string, palette color.Palette) (*image.Paletted, error) {
var p *image.Paletted
if l := o.Layer(name); l != nil {
p = image.NewPaletted(o.Bounds(), palette)
i, err := l.Image()
if err != nil {
return nil, err
}
draw.Draw(p, image.Rect(0, 0, p.Bounds().Max.X, p.Bounds().Max.Y), i, image.Point{}, draw.Src)
}
return p, nil
}
示例7: DrawAll
func (s *Simulation) DrawAll(initialImage *image.Paletted, frameCount int) []*image.Paletted {
bounds := initialImage.Bounds()
images := make([]*image.Paletted, frameCount)
s.Draw(initialImage)
images[0] = initialImage
for f := 1; f < frameCount; f++ {
newSimulation := s.Step()
img := image.NewPaletted(bounds, initialImage.Palette)
newSimulation.DiffDraw(s, img)
images[f] = img
s = newSimulation
}
return images
}
示例8: WriteText
// Write a text inside the image
func WriteText(text string, f *truetype.Font, img *image.Paletted) {
// Initialize the context.
fg := image.Black
c := freetype.NewContext()
c.SetDPI(72)
c.SetFont(f)
c.SetFontSize(64)
c.SetClip(img.Bounds())
c.SetDst(img)
c.SetSrc(fg)
// Draw the text.
pt := freetype.Pt(40, 120)
c.DrawString(text, pt)
}
示例9: drawBlock
// 將多邊形points旋轉angle個角度,然後輸出到img上,起點為x,y坐標
func drawBlock(img *image.Paletted, x, y, size float64, angle int, points []float64) {
if angle > 0 { // 0角度不需要轉換
// 中心坐標與x,y的距離,方便下麵指定中心坐標(x+m,y+m),
// 0.5的偏移值不能少,否則坐靠右,非正中央
m := size/2 - 0.5
rotate(points, x+m, y+m, angle)
}
for i := x; i < x+size; i++ {
for j := y; j < y+size; j++ {
if pointInPolygon(i, j, points) {
img.SetColorIndex(int(i), int(j), 1)
}
}
}
}
示例10: uninterlace
// uninterlace rearranges the pixels in m to account for interlaced input.
func uninterlace(m *image.Paletted) {
var nPix []uint8
dx := m.Bounds().Dx()
dy := m.Bounds().Dy()
nPix = make([]uint8, dx*dy)
offset := 0 // steps through the input by sequential scan lines.
for _, pass := range interlacing {
nOffset := pass.start * dx // steps through the output as defined by pass.
for y := pass.start; y < dy; y += pass.skip {
copy(nPix[nOffset:nOffset+dx], m.Pix[offset:offset+dx])
offset += dx
nOffset += dx * pass.skip
}
}
m.Pix = nPix
}
示例11: modeTerrain
func modeTerrain(p *image.Paletted, l int) uint8 {
b := p.Bounds()
modeMap := make([]uint8, l)
var most, mode uint8
for i := b.Min.X; i < b.Max.X; i++ {
for j := b.Min.Y; j < b.Max.Y; j++ {
pos := p.ColorIndexAt(i, j)
modeMap[pos]++
if m := modeMap[pos]; m > most {
most = m
mode = pos
}
}
}
return mode
}
示例12: untile
func untile(m *image.Paletted, data []byte) {
w, h := m.Rect.Dx(), m.Rect.Dy()
for i, x := 0, 0; x < w; x += 8 {
for y := 0; y < h; y += 8 {
for ty := 0; ty < 8; ty++ {
pix := mingle(uint16(data[i]), uint16(data[i+1]))
for tx := 7; tx >= 0; tx-- {
i := m.PixOffset(x+tx, y+ty)
m.Pix[i] = uint8(pix & 3)
pix >>= 2
}
i += 2
}
}
}
}
示例13: ripShinyPokemonBack
func ripShinyPokemonBack(rip *sprites.Ripper, number int, form string, outname string) error {
var m *image.Paletted
var err error
if number == 201 && form != "" {
m, err = rip.UnownBack(form)
} else {
m, err = rip.PokemonBack(number)
}
if err != nil {
return err
}
m.Palette = rip.ShinyPalette(number)
if m.Palette == nil {
return errors.New("couldn't get palette")
}
return write(m, outname)
}
示例14: debarf_frame
func debarf_frame(frame *image.Paletted) error {
xmin := frame.Rect.Min.X
ymin := frame.Rect.Min.Y
xmax := frame.Rect.Max.X
ymax := frame.Rect.Max.Y
for y := ymin; y < ymax; y++ {
for x := xmin; x < xmax; x++ {
c := frame.At(x, y)
r, g, b, a := c.RGBA()
if pixel_is_transparent(frame, x, y) {
fmt.Printf("...")
frame.Set(x, y, color.RGBA64{uint16(r), uint16(g), uint16(b), 0xffff})
} else if should_turn_pixel_transparent(frame, x, y) {
fmt.Printf("xxx")
frame.Set(x, y, color.RGBA64{0, 0, 0, 0xffff})
} else {
r /= 0x1000
g /= 0x1000
b /= 0x1000
if a != 0xffff {
fmt.Printf("barf")
}
fmt.Printf("%x%x%x", r, g, b)
}
}
fmt.Printf("\n")
}
return nil
}
示例15: Quantize
func (q *MedianCutQuantizer) Quantize(dst *image.Paletted, r image.Rectangle, src image.Image, sp image.Point) {
clip(dst, &r, src, &sp)
if r.Empty() {
return
}
points := make([]point, r.Dx()*r.Dy())
colorSet := make(map[uint32]color.Color, q.NumColor)
i := 0
for y := r.Min.Y; y < r.Max.Y; y++ {
for x := r.Min.X; x < r.Max.X; x++ {
c := src.At(x, y)
r, g, b, _ := c.RGBA()
colorSet[(r>>8)<<16|(g>>8)<<8|b>>8] = c
points[i][0] = int(r)
points[i][1] = int(g)
points[i][2] = int(b)
i++
}
}
if len(colorSet) <= q.NumColor {
// No need to quantize since the total number of colors
// fits within the palette.
dst.Palette = make(color.Palette, len(colorSet))
i := 0
for _, c := range colorSet {
dst.Palette[i] = c
i++
}
} else {
dst.Palette = q.medianCut(points)
}
for y := 0; y < r.Dy(); y++ {
for x := 0; x < r.Dx(); x++ {
// TODO: this should be done more efficiently.
dst.Set(sp.X+x, sp.Y+y, src.At(r.Min.X+x, r.Min.Y+y))
}
}
}