Beispiel #1
0
func superSampling(inputImage image.Image) image.Image {
	rect := inputImage.Bounds()
	width := rect.Size().X
	height := rect.Size().Y
	rect2 := image.Rect(rect.Min.X, rect.Min.Y, rect.Max.X-1, rect.Max.Y-1)
	rgba := image.NewRGBA(rect2)

	for x := 0; x < width-1; x++ {
		for y := 0; y < height-1; y++ {
			var col color.RGBA
			// 座標(x,y)のR, G, B, α の値を取得
			r00, g00, b00, a00 := inputImage.At(x, y).RGBA()
			r01, g01, b01, a01 := inputImage.At(x, y+1).RGBA()
			r10, g10, b10, a10 := inputImage.At(x+1, y).RGBA()
			r11, g11, b11, a11 := inputImage.At(x+1, y+1).RGBA()
			col.R = uint8((uint(uint8(r00)) + uint(uint8(r01)) + uint(uint8(r10)) + uint(uint8(r11))) / 4)
			col.G = uint8((uint(uint8(g00)) + uint(uint8(g01)) + uint(uint8(g10)) + uint(uint8(g11))) / 4)
			col.B = uint8((uint(uint8(b00)) + uint(uint8(b01)) + uint(uint8(b10)) + uint(uint8(b11))) / 4)
			col.A = uint8((uint(uint8(a00)) + uint(uint8(a01)) + uint(uint8(a10)) + uint(uint8(a11))) / 4)
			rgba.Set(x, y, col)
		}
	}

	return rgba.SubImage(rect)
}
Beispiel #2
0
func (c attrColor) RGBA() (r, g, b, a uint32) {
	switch termbox.Attribute(c) {
	case termbox.ColorBlack:
		return 0, 0, 0, math.MaxUint16
	case termbox.ColorRed:
		return math.MaxUint16, 0, 0, math.MaxUint16
	case termbox.ColorGreen:
		return 0, math.MaxUint16, 0, math.MaxUint16
	case termbox.ColorYellow:
		return math.MaxUint16, math.MaxUint16, 0, math.MaxUint16
	case termbox.ColorBlue:
		return 0, 0, math.MaxUint16, math.MaxUint16
	case termbox.ColorMagenta:
		return math.MaxUint16, 0, math.MaxUint16, math.MaxUint16
	case termbox.ColorCyan:
		return 0, math.MaxUint16, math.MaxUint16, math.MaxUint16
	case termbox.ColorWhite:
		return math.MaxUint16, math.MaxUint16, math.MaxUint16, math.MaxUint16
	}

	switch {
	case c >= 16 && c <= 231:
		c -= 16
		rgba := color.RGBA{R: base[(c/36)%6], G: base[(c/6)%6], B: base[c%6], A: 0xff}
		return rgba.RGBA()
	case c >= 232 && c <= 255:
		x := uint8(0x08 + 0xa*(c-232))
		rgba := color.RGBA{R: x, G: x, B: x, A: 0xff}
		return rgba.RGBA()
	}

	panic("not found")
}
func (cf *ColorFinder) findMainColor(colorMap *map[color.RGBA]colorStats, shift uint, targetColor *shiftedRGBA) shiftedRGBA {
	colorWeights := make(map[shiftedRGBA]float64)

	bounds := cf.img.Bounds()
	stepLength := stepLength(bounds)

	for y := bounds.Min.Y; y < bounds.Max.Y; y += stepLength {
		for x := bounds.Min.X; x < bounds.Max.X; x += stepLength {
			r, g, b, a := cf.img.At(x, y).RGBA()
			color := color.RGBA{}
			color.R = uint8(r >> shiftRGB)
			color.G = uint8(g >> shiftRGB)
			color.B = uint8(b >> shiftRGB)
			color.A = uint8(a >> shiftRGB)

			if rgbMatchesTargetColor(targetColor, &color) {
				increaseColorWeight(&colorWeights, colorMap, &color, shift)
			}
		}
	}

	maxColor := shiftedRGBA{}
	maxWeight := 0.0
	for sRGB, weight := range colorWeights {
		if weight > maxWeight {
			maxColor = sRGB
			maxWeight = weight
		}
	}

	return maxColor
}
Beispiel #4
0
func colorForPixel(isBlack bool) color.RGBA {
	col := color.RGBA{}
	if isBlack {
		col.A = 255
	}
	return col
}
func (cf *ColorFinder) buildColorMap() *map[color.RGBA]colorStats {
	colorMap := make(map[color.RGBA]colorStats)
	bounds := cf.img.Bounds()

	for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
		for x := bounds.Min.X; x < bounds.Max.X; x++ {
			r, g, b, a := cf.img.At(x, y).RGBA()
			rgb := color.RGBA{}
			rgb.R = uint8(r >> shiftRGB)
			rgb.G = uint8(g >> shiftRGB)
			rgb.B = uint8(b >> shiftRGB)
			rgb.A = uint8(a >> shiftRGB)

			colrStats, exist := colorMap[rgb]
			if exist {
				colrStats.count++
			} else {
				colrStats := colorStats{count: 1, weight: weight(&rgb)}
				if colrStats.weight <= 0 {
					colrStats.weight = 1e-10
				}
				colorMap[rgb] = colrStats
			}
		}
	}
	return &colorMap
}
Beispiel #6
0
func (s *S) TestColor(c *check.C) {
	for r := 0; r < 256; r += 5 {
		for g := 0; g < 256; g += 5 {
			for b := 0; b < 256; b += 5 {
				col := color.RGBA{uint8(r), uint8(g), uint8(b), 0}
				cDirectR, cDirectG, cDirectB, cDirectA := col.RGBA()
				hsva := RGBAtoHSVA(col.RGBA())
				c.Check(hsva.H, floatWithinRange, float64(0), float64(360))
				c.Check(hsva.S, floatWithinRange, float64(0), float64(1))
				c.Check(hsva.V, floatWithinRange, float64(0), float64(1))
				cFromHSVR, cFromHSVG, cFromHSVB, cFromHSVA := hsva.RGBA()
				c.Check(cFromHSVR, uintWithinRange, uint32(0), uint32(0xFFFF))
				c.Check(cFromHSVG, uintWithinRange, uint32(0), uint32(0xFFFF))
				c.Check(cFromHSVB, uintWithinRange, uint32(0), uint32(0xFFFF))
				back := RGBAtoHSVA(color.RGBA{uint8(cFromHSVR >> 8), uint8(cFromHSVG >> 8), uint8(cFromHSVB >> 8), uint8(cFromHSVA)}.RGBA())
				c.Check(hsva, check.Equals, back)
				c.Check(cFromHSVR, withinEpsilon, cDirectR, e)
				c.Check(cFromHSVG, withinEpsilon, cDirectG, e)
				c.Check(cFromHSVB, withinEpsilon, cDirectB, e)
				c.Check(cFromHSVA, check.Equals, cDirectA)
				if c.Failed() {
					return
				}
			}
		}
	}
}
Beispiel #7
0
func main() {
	img := shapes.FilledImage(500, 300, image.White)

	fill := color.RGBA{200, 200, 200, 255}

	for i := 0; i < 10; i++ {
		width, height := 50+(20*i), 30+(10*i)

		rect, err := shapes.New("rectangle", shapes.Option{Fill: fill, Rect: image.Rect(0, 0, width, height), Filled: true})
		if err != nil {
			log.Fatal(err)
		}

		x := 10 + (20 * i)
		for j := i / 2; j >= 0; j-- {
			rect.Draw(img, x+j, (x/2)+j)
		}

		fill.R -= uint8(i * 5)
		fill.G = fill.R
		fill.B = fill.R
	}

	shapes.SaveImage(img, "rectangle.png")
}
Beispiel #8
0
// Convert a []float64 to an image, reading data with the format specified in
// chans (e.g. RGBA, BGRA, BRG, RRR). If a component is not specified in the
func FromSliceChans(img *Image, chans string, fill float64, data []float64) {
	surf := img.Surf
	cm := surf.ColorModel()
	b := surf.Bounds()
	minX, maxX := b.Min.X, b.Max.X
	minY, maxY := b.Min.Y, b.Max.Y
	k := 0
	nc := len(chans)

	const mk = 0xff
	dfill := clamp8(fill) & mk

	for i := minY; i < maxY; i++ {
		for j := minX; j < maxX; j++ {
			outCol := color.RGBA{dfill, dfill, dfill, dfill}
			for c := 0; c < nc; c++ {
				switch chans[c] {
				case 'r', 'R':
					outCol.R = clamp8(data[k+c]) & mk
				case 'g', 'G':
					outCol.G = clamp8(data[k+c]) & mk
				case 'b', 'B':
					outCol.B = clamp8(data[k+c]) & mk
				case 'a', 'A':
					outCol.A = clamp8(data[k+c]) & mk
				default:
					// Just skip the channel
				}
			}
			k += nc
			img.Surf.Set(j, i, cm.Convert(outCol))
		}
	}
}
// Return the complementary color
func Complementary(v color.RGBA) [2]color.RGBA {
	var result color.RGBA
	result.R = 255 - v.R
	result.G = 255 - v.G
	result.B = 255 - v.B
	result.A = v.A
	return [2]color.RGBA{v, result}
}
Beispiel #10
0
// Apply the given color mapping to the specified image buffers.
func Apply(from, to *Rule, src, dst draw.Image) {
	var x, y int
	var r, g, b, a uint32
	var sc color.Color
	var dc color.RGBA
	var pix pixel

	rect := src.Bounds()

	for y = 0; y < rect.Dy(); y++ {
		for x = 0; x < rect.Dx(); x++ {
			sc = src.At(x, y)

			r, g, b, a = sc.RGBA()
			pix.r = uint8(r >> 8)
			pix.g = uint8(g >> 8)
			pix.b = uint8(b >> 8)
			pix.a = uint8(a >> 8)

			// Check if the pixel matches the filter rule.
			if !(match(pix.r, from.R) && match(pix.g, from.G) && match(pix.b, from.B) && match(pix.a, from.A)) {
				dst.Set(x, y, sc)
				continue
			}

			// Compute three different types of grayscale conversion.
			// These can be applied by named references.
			pix.average = uint8(((r + g + b) / 3) >> 8)
			pix.lightness = uint8(((min(min(r, g), b) + max(max(r, g), b)) / 2) >> 8)

			// For luminosity it is necessary to apply an inverse of the gamma
			// function for the color space before calculating the inner product.
			// Then you apply the gamma function to the reduced value. Failure to
			// incorporate the gamma function can result in errors of up to 20%.
			//
			// For typical computer stuff, the color space is sRGB. The right
			// numbers for sRGB are approx. 0.21, 0.72, 0.07. Gamma for sRGB
			// is a composite function that approximates exponentiation by 1/2.2
			//
			// This is a rather expensive operation, but gives a much more accurate
			// and satisfactory result than the average and lightness versions.
			pix.luminosity = gammaSRGB(
				0.212655*invGammaSRGB(pix.r) +
					0.715158*invGammaSRGB(pix.g) +
					0.072187*invGammaSRGB(pix.b))

			// Transform color.
			dc.R = transform(&pix, pix.r, to.R)
			dc.G = transform(&pix, pix.g, to.G)
			dc.B = transform(&pix, pix.b, to.B)
			dc.A = transform(&pix, pix.a, to.A)

			// Set new pixel.
			dst.Set(x, y, dc)
		}
	}
}
Beispiel #11
0
func setAlpha(c color.RGBA, a uint8) color.RGBA {
	if c.A == 0 {
		return c
	}
	c.R = mult(c.R, a, c.A)
	c.G = mult(c.G, a, c.A)
	c.B = mult(c.B, a, c.A)
	c.A = a
	return c
}
Beispiel #12
0
func TestColor(t *testing.T) {
	for r := 0; r < 256; r += 5 {
		for g := 0; g < 256; g += 5 {
			for b := 0; b < 256; b += 5 {
				col := color.RGBA{uint8(r), uint8(g), uint8(b), 0}
				cDirectR, cDirectG, cDirectB, cDirectA := col.RGBA()
				hsva := rgbaToHsva(col.RGBA())
				if hsva.H < 0 || hsva.H > 1 {
					t.Errorf("unexpected values for H: want [0, 1] got:%f", hsva.H)
				}
				if hsva.S < 0 || hsva.S > 1 {
					t.Errorf("unexpected values for S: want [0, 1] got:%f", hsva.S)
				}
				if hsva.V < 0 || hsva.V > 1 {
					t.Errorf("unexpected values for V: want [0, 1] got:%f", hsva.V)
				}

				cFromHSVR, cFromHSVG, cFromHSVB, cFromHSVA := hsva.RGBA()
				if cFromHSVR < 0 || cFromHSVR > 0xFFFF {
					t.Errorf("unexpected values for H: want [0x0, 0xFFFF] got:%f", hsva.H)
				}
				if cFromHSVG < 0 || cFromHSVG > 0xFFFF {
					t.Errorf("unexpected values for S: want [0x0, 0xFFFF] got:%f", hsva.S)
				}
				if cFromHSVB < 0 || cFromHSVB > 0xFFFF {
					t.Errorf("unexpected values for V: want [0x0, 0xFFFF] got:%f", hsva.V)
				}
				if cFromHSVA < 0 || cFromHSVA > 0xFFFF {
					t.Errorf("unexpected values for V: want [0x0, 0xFFFF] got:%f", hsva.V)
				}

				back := rgbaToHsva(color.RGBA{uint8(cFromHSVR >> 8), uint8(cFromHSVG >> 8), uint8(cFromHSVB >> 8), uint8(cFromHSVA)}.RGBA())
				if hsva != back {
					t.Errorf("roundtrip error: got:%#v want:%#v", back, hsva)
				}
				const epsilon = 1
				if !withinEpsilon(cFromHSVR, cDirectR, epsilon) {
					t.Errorf("roundtrip error for R: got:%d want:%d", cFromHSVR, cDirectR)
				}
				if !withinEpsilon(cFromHSVG, cDirectG, epsilon) {
					t.Errorf("roundtrip error for G: got:%d want:%d %d", cFromHSVG, cDirectG, cFromHSVG-cDirectG)
				}
				if !withinEpsilon(cFromHSVB, cDirectB, epsilon) {
					t.Errorf("roundtrip error for B: got:%d want:%d", cFromHSVB, cDirectB)
				}
				if cFromHSVA != cDirectA {
					t.Errorf("roundtrip error for A: got:%d want:%d", cFromHSVA, cDirectA)
				}
				if t.Failed() {
					return
				}
			}
		}
	}
}
func DistanceBetweenColors(color1, color2 color.RGBA) float64 {
	r1, g1, b1, _ := color1.RGBA()
	r2, g2, b2, _ := color2.RGBA()

	rDiff := math.Pow(lolDiff(r1, r2), 2.0)
	gDiff := math.Pow(lolDiff(g1, g2), 2.0)
	bDiff := math.Pow(lolDiff(b1, b2), 2.0)
	sum := rDiff + gDiff + bDiff

	return math.Sqrt(sum)
}
Beispiel #14
0
// SetAll sets the given values for the channels
func (d *Dioder) SetAll(colorSet color.RGBA) {
	d.ColorConfiguration = colorSet
	//Red
	colorSet.R = calculateOpacity(colorSet.R, colorSet.A)
	d.SetChannelInteger(colorSet.R, d.PinConfiguration.Red)
	//Green
	colorSet.G = calculateOpacity(colorSet.G, colorSet.A)
	d.SetChannelInteger(colorSet.G, d.PinConfiguration.Green)

	//Blue
	colorSet.B = calculateOpacity(colorSet.B, colorSet.A)
	d.SetChannelInteger(colorSet.B, d.PinConfiguration.Blue)
}
func plot(img *image.RGBA, x, y int, c *color.RGBA) {
	r0, g0, b0, a0 := img.At(x, y).RGBA()            // background color
	r1, g1, b1, a1 := c.RGBA()                       // foreground color
	var alpha0 float64 = float64(a0) / float64(0xff) // background alpha
	var alpha1 float64 = float64(a1) / float64(0xff) // foreground alpha
	// resulting colors
	var r uint8 = uint8(alpha1*float64(r1) + (1.0-alpha1)*float64(r0))
	var g uint8 = uint8(alpha1*float64(g1) + (1.0-alpha1)*float64(g0))
	var b uint8 = uint8(alpha1*float64(b1) + (1.0-alpha1)*float64(b0))
	var a uint8 = uint8(0xff * (alpha1 + alpha0*(1.0-alpha1)))
	pxl := color.RGBA{r, g, b, a} // resulting pixel
	img.Set(x, y, pxl)
}
Beispiel #16
0
func mapToColor(o map[string]interface{}) color.Color {
	var c color.RGBA

	// Because JavaScript
	switch x := o["r"].(type) {
	case int64:
		c.R = uint8(colorF(float64(x)))
	case float64:
		c.R = uint8(colorF(x))
	}
	switch x := o["g"].(type) {
	case int64:
		c.G = uint8(colorF(float64(x)))
	case float64:
		c.G = uint8(colorF(x))
	}
	switch x := o["b"].(type) {
	case int64:
		c.B = uint8(colorF(float64(x)))
	case float64:
		c.B = uint8(colorF(x))
	}
	c.A = 0xff
	return c
}
Beispiel #17
0
func TestWritePng(t *testing.T) {
	img1 := NewImage(100, 100)
	col1 := color.RGBA{0, 11, 0, 255}
	img1.DrawDot(4, 5, col1)
	var buf bytes.Buffer
	img1.WritePng(&buf)
	img2, _ := png.Decode(&buf)
	col2 := img2.At(4, 5)
	_, r1, _, _ := col1.RGBA()
	_, r2, _, _ := col2.RGBA()
	if r2 != r1 {
		t.Errorf("expected '%v' but got '%v'", r1, r2)
	}
}
Beispiel #18
0
func parseColors(args []*ast.BasicLit) (color.RGBA, error) {
	ints := make([]uint8, 4)
	var ret color.RGBA
	var u uint8
	for i := range args {
		v := args[i]
		switch v.Kind {
		case token.FLOAT:
			f, err := strconv.ParseFloat(args[i].Value, 8)
			if err != nil {
				return ret, err
			}
			// Has to be alpha, or bust
			u = uint8(f * 100)
		case token.INT:
			i, err := strconv.Atoi(v.Value)
			if err != nil {
				return ret, err
			}
			u = uint8(i)
		case token.COLOR:
			if i != 0 {
				return ret, fmt.Errorf("hex is only allowed as the first argumetn found: % #v", v)
			}
			var err error
			ret, err = ast.ColorFromHexString(v.Value)
			if err != nil {
				return ret, err
			}
			// This is only allowed as the first argument
			i = i + 2
		default:
			log.Fatalf("unsupported kind %s % #v\n", v.Kind, v)
		}
		ints[i] = u
	}
	if ints[0] > 0 {
		ret.R = ints[0]
	}
	if ints[1] > 0 {
		ret.G = ints[1]
	}
	if ints[2] > 0 {
		ret.B = ints[2]
	}
	if ints[3] > 0 {
		ret.A = ints[3]
	}
	return ret, nil
}
Beispiel #19
0
func adjustColor(ca color.RGBA, cb color.Color, n uint8) color.RGBA {
	r, g, b, a := ca.RGBA()
	retR := uint8(r)
	retG := uint8(g)
	retB := uint8(b)
	retA := uint8(a)

	r, g, b, a = cb.RGBA()
	retR += uint8(r) / n
	retG += uint8(g) / n
	retB += uint8(b) / n
	retA += uint8(a) / n

	return color.RGBA{retR, retG, retB, retA}
}
Beispiel #20
0
func blend(orig image.Image) (m image.Image) {
	// deviation range
	dev := uint16(50 << 8)

	c := new(color.RGBA)
	c.A = 255

	bounds := orig.Bounds()

	// iterations
	for i := 0; i < 10; i++ {
		newm := image.NewRGBA(bounds)

		for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
			for x := bounds.Min.X; x < bounds.Max.X; x++ {

				var r, g, b, ct uint32

				_r, _g, _b, _ := orig.At(x, y).RGBA()

				for i := -1; i < 2; i++ {
					for j := -1; j < 2; j++ {
						rt, gt, bt, _ := orig.At(x+i, y+j).RGBA()

						if uint16(rt-_r) > dev || uint16(gt-_g) > dev || uint16(bt-_b) > dev {
							continue
						}

						r += rt
						g += gt
						b += bt
						ct++
					}
				}
				c.R = uint8((r / ct) >> 8)
				c.G = uint8((g / ct) >> 8)
				c.B = uint8((b / ct) >> 8)

				newm.Set(x, y, c)

			}
		}

		m = newm
	}

	return
}
Beispiel #21
0
func main() {
	img := shapes.FilledImage(420, 220, image.White)
	fill := color.RGBA{200, 200, 200, 0xFF} // light gray
	for i := 0; i < 10; i++ {
		width, height := 40+(20*i), 20+(10*i)
		rectangle := shapes.Rectangle{fill,
			image.Rect(0, 0, width, height), true}
		x := 10 + (20 * i)
		for j := i / 2; j >= 0; j-- {
			rectangle.Draw(img, x+j, (x/2)+j)
		}
		fill.R -= uint8(i * 5)
		fill.G = fill.R
		fill.B = fill.R
	}
	shapes.SaveImage(img, "rectangle.png")
}
func DrawImage(src image.Image, dest draw.Image, tr MatrixTransform, op draw.Op, filter ImageFilter) {
	bounds := src.Bounds()
	x0, y0, x1, y1 := float64(bounds.Min.X), float64(bounds.Min.Y), float64(bounds.Max.X), float64(bounds.Max.Y)
	tr.TransformRectangle(&x0, &y0, &x1, &y1)
	var x, y, u, v float64
	var c1, c2, cr color.Color
	var r, g, b, a, ia, r1, g1, b1, a1, r2, g2, b2, a2 uint32
	var color color.RGBA
	for x = x0; x < x1; x++ {
		for y = y0; y < y1; y++ {
			u = x
			v = y
			tr.InverseTransform(&u, &v)
			if bounds.Min.X <= int(u) && bounds.Max.X > int(u) && bounds.Min.Y <= int(v) && bounds.Max.Y > int(v) {
				c1 = dest.At(int(x), int(y))
				switch filter {
				case LinearFilter:
					c2 = src.At(int(u), int(v))
				case BilinearFilter:
					c2 = getColorBilinear(src, u, v)
				case BicubicFilter:
					c2 = getColorBicubic(src, u, v)
				}
				switch op {
				case draw.Over:
					r1, g1, b1, a1 = c1.RGBA()
					r2, g2, b2, a2 = c2.RGBA()
					ia = M - a2
					r = ((r1 * ia) / M) + r2
					g = ((g1 * ia) / M) + g2
					b = ((b1 * ia) / M) + b2
					a = ((a1 * ia) / M) + a2
					color.R = uint8(r >> 8)
					color.G = uint8(g >> 8)
					color.B = uint8(b >> 8)
					color.A = uint8(a >> 8)
					cr = color
				default:
					cr = c2
				}
				dest.Set(int(x), int(y), cr)
			}
		}
	}
}
Beispiel #23
0
func TestColor(t *testing.T) {
	baseColor := color.RGBA{251, 252, 253, 254}
	hex := ColorToHexString(baseColor)
	n, _ := strconv.ParseInt(hex, 0, 64)

	f64 := ColorToFloat64(baseColor)

	if n != int64(f64) {
		t.Fatal("Color convertion not equal ?")
	}

	recolor := Float64ToColor(f64)
	r, g, b, _ := baseColor.RGBA()
	rr, rg, rb, _ := recolor.RGBA()
	if rr != r || rg != g || rb != b {
		t.Fatal("Cant convert back to color !, ", rr, r, rg, g, rb, b)
	}
}
//Takes a list of words (i.e. from a book), finds words that match the search term,
//and creates an image based on the usage of those words with each pixel representing
//the specified number of words (sectionSize). The channel will be sent a value of 1
//upon the successful completion of the task
func CreateImage(words []string, searchTerm string, sectionSize int, quit chan int) {
	searchTerms := strings.Fields(searchTerm)

	imageHeight := 20

	//Setup the image
	totalWords := len(words)
	imageWidth := int(math.Ceil(float64(totalWords) / float64(sectionSize)))
	newImg := image.NewRGBA(image.Rect(0, 0, imageWidth, imageHeight))

	usedInSection := make([]bool, imageWidth, imageWidth)

	usedCount := 0

	for index, word := range words {
		section := int(math.Floor(float64(index) / float64(sectionSize)))
		for _, term := range searchTerms {
			if word == term {
				usedInSection[section] = true
				usedCount++
				break
			}
		}
	}

	fmt.Println("The terms", searchTerm, "were found", usedCount, "times")

	for x := 0; x < imageWidth; x++ {
		color := color.RGBA{255, 255, 255, 255}
		if usedInSection[x] == true {
			color.R = 0
			color.G = 0
			color.B = 0
		}
		for y := 0; y < imageHeight; y++ {
			newImg.SetRGBA(x, y, color)
		}
	}

	SaveImage(searchTerm+".png", newImg)

	quit <- 1
}
Beispiel #25
0
// SetColor sets the fore color of the window.
func (win *window) SetColor(p sparta.Property, c color.RGBA) {
	if (p != sparta.Background) && (p != sparta.Foreground) {
		return
	}
	s := xwin.DefaultScreen()
	code := getColorCode(c)
	px, ok := pixelMap[code]
	if !ok {
		r, g, b, _ := c.RGBA()
		cl, _ := xwin.AllocColor(s.DefaultColormap, uint16(r), uint16(g), uint16(b))
		px = cl.Pixel
		pixelMap[code] = px
	}
	if p == sparta.Foreground {
		xwin.ChangeGC(win.gc, xgb.GCForeground, []uint32{px})
	} else {
		xwin.ChangeGC(win.gc, xgb.GCBackground, []uint32{px})
	}
}
Beispiel #26
0
// linterp performs linear interpolation between the first (p[0]) and
// the last (pal[len(p) - 1]) colors in palette "pal". It fills the
// remaining (pal[1:len(p) - 1]) palette slots with the intepolated
// colors. Colors in slots pal[0] and pal[len(p) - 1] MUST be of type
// color.RGBA. The remaining slots will also be filled with colors of
// type color.RGBA
func linterp(pal color.Palette) {
	n := len(pal)
	if n <= 2 {
		return
	}
	s, e := pal[0].(color.RGBA), pal[n-1].(color.RGBA)
	dr := int(e.R) - int(s.R)
	dg := int(e.G) - int(s.G)
	db := int(e.B) - int(s.B)
	da := int(e.A) - int(s.A)
	for i := 1; i < n-1; i++ {
		c := color.RGBA{}
		c.R = uint8(int(s.R) + i*dr/(n-1))
		c.G = uint8(int(s.G) + i*dg/(n-1))
		c.B = uint8(int(s.B) + i*db/(n-1))
		c.A = uint8(int(s.A) + i*da/(n-1))
		pal[i] = c
	}
}
Beispiel #27
0
// colorOpColor combines two colors with the requested operation
// applying appropriate overflows as Sass expects
func colorOpColor(tok token.Token, x, y *BasicLit, combine bool) (*BasicLit, error) {
	colX, err := ColorFromHexString(x.Value)
	if err != nil {
		return nil, err
	}
	colY, err := ColorFromHexString(y.Value)
	if err != nil {
		return nil, err
	}

	var z color.RGBA
	z.R = overflowMath(tok, colX.R, colY.R)
	z.G = overflowMath(tok, colX.G, colY.G)
	z.B = overflowMath(tok, colX.B, colY.B)

	s := colorToHex(z)
	return &BasicLit{
		Kind:  token.COLOR,
		Value: LookupColor(s),
	}, nil
}
Beispiel #28
0
// Compare compares a and b using binary comparison.
func (d *binary) Compare(a, b image.Image) (image.Image, int, error) {
	ab, bb := a.Bounds(), b.Bounds()
	w, h := ab.Dx(), ab.Dy()
	if w != bb.Dx() || h != bb.Dy() {
		return nil, -1, ErrSize
	}
	diff := image.NewNRGBA(image.Rect(0, 0, w, h))
	n := 0
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			d := diffColor(a.At(ab.Min.X+x, ab.Min.Y+y), b.At(bb.Min.X+x, bb.Min.Y+y))
			c := color.RGBA{0, 0, 0, 0xff}
			if d > 0 {
				c.R = 0xff
				//c.A = uint8(100 + d*0xff/0xffff)
				n++
			}
			diff.Set(x, y, c)
		}
	}
	return diff, n, nil
}
Beispiel #29
-1
func imgServingExample2(w http.ResponseWriter, r *http.Request) {

	c := appengine.NewContext(r)

	// prepare a rectangle
	var p1, p2 image.Point
	p1.X, p1.Y = 10, 10
	p2.X, p2.Y = 400, 255
	var rec image.Rectangle = image.Rectangle{Min: p1, Max: p2}

	// prepare a line color
	lineCol := color.RGBA{}
	lineCol.R, lineCol.G, lineCol.B = 255, 44, 22
	//lineCol.A = 0
	c.Infof("brush color %#v \n", lineCol)

	// create empty memory image - all pixels are 0 => black
	imgRGBA := image.NewRGBA(rec)

	for i := 20; i < 140; i++ {
		lineCol.A = uint8(i)
		imgRGBA.Set(i, i, lineCol)
		imgRGBA.Set(i+1, i, lineCol)
		imgRGBA.Set(i+2, i, lineCol)
		imgRGBA.Set(i+3, i, lineCol)
		imgRGBA.Set(i+3, i+1, lineCol)
	}
	w.Header().Set("Content-Type", "image/jpeg")
	jpeg.Encode(w, imgRGBA, &jpeg.Options{Quality: jpeg.DefaultQuality})

}
Beispiel #30
-1
func init_calc(x, y int) color.RGBA {
	//t_ray ray
	var x1, y1, z1 float32
	var pixel color.RGBA

	pixel.R = 255
	pixel.A = 255

	x1 = float32(D)
	y1 = float32((WinX / 2) - x)
	z1 = float32((WinY / 2) - y)

	/*
		ray.Vx = x1 - eye->pos.X;
		ray.Vy = y1 - eye->pos.Y;
		ray.Vz = z1 - eye->pos.Z;

		ray.top_mesh = llist;
		ray.top_spot = spot;
		ray.bool = 1;
		rotate_x(&ray.Vx, &ray.Vy, &ray.Vz, -eye->rot.X);
		rotate_y(&ray.Vx, &ray.Vy, &ray.Vz, -eye->rot.Y);
		rotate_z(&ray.Vx, &ray.Vy, &ray.Vz, -eye->rot.Z);
		color = calc(eye, llist, spot, &ray);
	*/
	return pixel
}