示例#1
0
func dist2(a, b *image.RGBA) float32 {
	a0 := a.Bounds().Min
	b0 := b.Bounds().Min
	s := a.Bounds().Size()

	if s.Eq(b.Bounds().Size()) == false {
		return math.MaxFloat32
	}

	d := float32(0.)

	for j := 0; j < s.Y; j++ {
		for i := 0; i < s.X; i++ {
			ca := a.RGBAAt(a0.X+i, a0.Y+j)
			cb := b.RGBAAt(b0.X+i, b0.Y+j)

			dr := (float32(ca.R) - float32(cb.R)) / 255.
			dg := (float32(ca.G) - float32(cb.G)) / 255.
			db := (float32(ca.B) - float32(cb.B)) / 255.
			da := (float32(ca.A) - float32(cb.A)) / 255.

			d += dr*dr + db*db + dg*dg + da*da
		}
	}

	return d
}
示例#2
0
func ImageEnhanceRGB(img *image.RGBA, enhanceDegress float32, enhanceOffset float32, enhanceChannel [3]bool) *image.RGBA {
	rgbFunc := func(xpos, ypos int) (r0, g0, b0, a0 uint8) {
		rgba := img.RGBAAt(xpos, ypos)
		return rgba.R, rgba.G, rgba.B, rgba.A
	}
	imgEnhanced := imenhance(enhanceDegress, enhanceOffset, enhanceChannel, false, img.Rect, rgbFunc)
	return imgEnhanced
}
示例#3
0
func ImageEnhanceRGBWithFunc(img *image.RGBA, enhanceFunc func(r, g, b float32) (float32, float32, float32)) *image.RGBA {
	rgbFunc := func(xpos, ypos int) (r0, g0, b0, a0 uint8) {
		rgba := img.RGBAAt(xpos, ypos)
		r, g, b := enhanceFunc(float32(rgba.R), float32(rgba.G), float32(rgba.B))
		return oneColorCorrect(r), oneColorCorrect(g), oneColorCorrect(b), rgba.A
	}
	imgEnhanced := imenhance(1, 0, [3]bool{true, true, true}, true, img.Rect, rgbFunc)
	return imgEnhanced
}
示例#4
0
func paint(mgr *gpio.Gpio, interval interval, img *image.RGBA) {
	yStride := img.Rect.Dy() / 2
	for y := img.Rect.Min.Y; y < img.Rect.Min.Y+yStride; y++ {
		for i := 1; i < colors; i++ {
			thresh := uint8(i * 256 / colors)
			for x := img.Rect.Min.X; x < img.Rect.Max.X; x++ {
				var data uint32
				color := img.RGBAAt(x, y)
				if color.R >= thresh {
					data |= 1 << pinR1
				}
				if color.G >= thresh {
					data |= 1 << pinG1
				}
				if color.B >= thresh {
					data |= 1 << pinB1
				}
				color = img.RGBAAt(x, y+yStride)
				if color.R >= thresh {
					data |= 1 << pinR2
				}
				if color.G >= thresh {
					data |= 1 << pinG2
				}
				if color.B >= thresh {
					data |= 1 << pinB2
				}
				mgr.Set(data, 1<<pinR1|1<<pinG1|1<<pinB1|1<<pinR2|1<<pinG2|1<<pinB2)
				mgr.Strobe(pinClk)
			}
			// all set up to strobe; wait for end of interval
			interval.wait()
			if i == 1 {
				var addr uint32
				if y&0x8 != 0 {
					addr |= 1 << pinA3
				}
				if y&0x4 != 0 {
					addr |= 1 << pinA2
				}
				if y&0x2 != 0 {
					addr |= 1 << pinA1
				}
				if y&0x1 != 0 {
					addr |= 1 << pinA0
				}
				mgr.Set(1<<pinOE, 1<<pinOE)
				mgr.Set(addr, 1<<pinA3|1<<pinA2|1<<pinA1|1<<pinA0)
			}
			mgr.Strobe(pinLat)
			if i == 1 {
				mgr.Set(0, 1<<pinOE)
			}
		}
	}
}
示例#5
0
func NewPictureFromRGBA(img *image.RGBA) *Picture {
	p := NewPicture(img.Bounds())

	p.Each(func(x, y int) {
		c := img.RGBAAt(x, y)
		l := p.Luma(c)
		p.Set(x, y, l)
	})

	return p
}
示例#6
0
func ImageFilterRGB(img *image.RGBA, filter [][]float32, lowQuality bool) *image.RGBA {
	if lowQuality {
		imgAva := ImageEnhanceRGB(img, filter[0][0], 0, [3]bool{true, true, true})
		return imfilter(filter, img.Rect, func(xpos, ypos int) (r0, g0, b0, a0 uint8) {
			rgba := imgAva.RGBAAt(xpos, ypos)
			return rgba.R, rgba.G, rgba.B, rgba.A
		}, func(filterValue, colorValue float32) float32 {
			return colorValue
		})
	}
	return imfilter(filter, img.Rect, func(xpos, ypos int) (r0, g0, b0, a0 uint8) {
		rgba := img.RGBAAt(xpos, ypos)
		return rgba.R, rgba.G, rgba.B, rgba.A
	}, func(filterValue, colorValue float32) float32 {
		return filterValue * colorValue
	})
}
示例#7
0
文件: nope.go 项目: nf/nope
func sendImage(m *image.RGBA) {
	c, err := net.Dial("udp", "151.217.8.152:6073")
	if err != nil {
		log.Fatal(err)
	}
	uc := c.(*net.UDPConn)
	uc.SetWriteBuffer(width*height*3 + 1)
	var buf bytes.Buffer
	buf.WriteByte(0)
	for y := 0; y < height; y++ {
		for x := 0; x < width; x++ {
			c := m.RGBAAt(x, y)
			buf.WriteByte(c.R)
			buf.WriteByte(c.G)
			buf.WriteByte(c.B)
		}
	}
	c.Write(buf.Bytes())
}