예제 #1
0
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
}
예제 #2
0
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))
		}
	}
}