Example #1
1
// Draw renders the given cpu cores on img.
func (app *App) Draw(img draw.Image, cpus []CPU) {
	rect := img.Bounds()
	bg := app.Background
	if bg == nil {
		bg = image.Black
	}
	draw.Draw(img, rect, bg, bg.Bounds().Min, draw.Over)

	if len(cpus) == 0 {
		return
	}

	cpuDx := rect.Dx() / len(cpus)
	ptIncr := image.Point{X: cpuDx}
	ptDelta := image.Point{}
	rectDx := image.Rectangle{
		Min: rect.Min,
		Max: rect.Max,
	}
	rectDx.Max.X = rect.Min.X + cpuDx
	for _, cpu := range cpus {
		irect := image.Rectangle{
			Min: rectDx.Min.Add(ptDelta),
			Max: rectDx.Max.Add(ptDelta),
		}
		subimg := SubImage(img, irect)
		app.renderCPU(subimg, cpu)

		ptDelta = ptDelta.Add(ptIncr)
	}
}
Example #2
0
func drawPoint(point Point, dst *image.RGBA, src image.Image) {
	p := image.Point{point.X, point.Y}
	srcRect := src.Bounds()
	size := srcRect.Size()
	rect := image.Rectangle{p, p.Add(size)}
	draw.Draw(dst, rect, src, srcRect.Min, draw.Src)
}
Example #3
0
func (i *imageSlice) Set(x, y int, c color.Color) {
	p := image.Point{x, y}
	if p.In(i.r) {
		p = p.Add(i.p)
		i.img.Set(p.X, p.Y, c)
	}
}
Example #4
0
// Adjust adjusts the two images aligning ther centers. The background
// of the smaller image is filled with FillColor. The returned images
// are of the same size.
func (c Centerer) Adjust(img1, img2 image.Image) (image.Image, image.Image) {
	img1Rect := img1.Bounds()
	img2Rect := img2.Bounds()
	backgroundRect := img1Rect.Union(img2Rect)

	dstImg1 := image.NewRGBA(backgroundRect)
	dstImg2 := image.NewRGBA(backgroundRect)

	// Fill destination images with FillColor
	draw.Draw(dstImg1, dstImg1.Bounds(), &image.Uniform{c.FillColor}, image.ZP, draw.Src)
	draw.Draw(dstImg2, dstImg2.Bounds(), &image.Uniform{c.FillColor}, image.ZP, draw.Src)

	// Copy img1 to the center of dstImg1
	dp := image.Point{
		(backgroundRect.Max.X-backgroundRect.Min.X)/2 - (img1Rect.Max.X-img1Rect.Min.X)/2,
		(backgroundRect.Max.Y-backgroundRect.Min.Y)/2 - (img1Rect.Max.Y-img1Rect.Min.Y)/2,
	}
	r := image.Rectangle{dp, dp.Add(img1Rect.Size())}
	draw.Draw(dstImg1, r, img1, image.ZP, draw.Src)

	// Copy img2 to the center of dstImg2
	dp = image.Point{
		(backgroundRect.Max.X-backgroundRect.Min.X)/2 - (img2Rect.Max.X-img2Rect.Min.X)/2,
		(backgroundRect.Max.Y-backgroundRect.Min.Y)/2 - (img2Rect.Max.Y-img2Rect.Min.Y)/2,
	}
	r = image.Rectangle{dp, dp.Add(img2Rect.Size())}
	draw.Draw(dstImg2, r, img2, image.ZP, draw.Src)

	return dstImg1, dstImg2
}
Example #5
0
func (c *Context) RenderMultiline(txt []string, size float64, bg, fg color.Color) (*image.RGBA, error) {
	w, h := 0, 0
	imgs := []*image.RGBA{}

	for _, l := range txt {
		i, err := c.Render(l, size, fg)
		if err != nil {
			return nil, err
		}
		if i.Bounds().Dx() > w {
			w = i.Bounds().Dx()
		}
		h += i.Bounds().Dy()
		imgs = append(imgs, i)
	}

	dst := image.NewRGBA(image.Rect(0, 0, w, h))
	draw.Draw(dst, dst.Bounds(), image.NewUniform(bg), image.ZP, draw.Src)
	y := 0
	for _, src := range imgs {
		sr := src.Bounds()
		dp := image.Point{0, y}
		r := image.Rectangle{dp, dp.Add(sr.Size())}
		draw.Draw(dst, r, src, sr.Min, draw.Src)
		y += sr.Dy()
	}

	return dst, nil
}
Example #6
0
func (l *Label) verticalPosition(line int) {
	textHeight := len(l.lines) * l.font.Height()
	var topOffset, tail int

	switch l.VAlign {
	case Top:
		topOffset = 0
	case Middle:
		topOffset = (l.Bounds().Dy() - textHeight) / 2
	case Bottom:
		topOffset = (l.Bounds().Dy() - textHeight)
	}

	totalHeight := textHeight + WRAP_GAP

	if (textHeight > l.Dy()) && l.scroll {
		if l.scrollPos > 0 {
			l.scrollPos -= totalHeight
			//l.scrollPos %= ( totalHeight + WRAP_GAP )
		}
		tail = l.scrollPos + totalHeight
		if tail <= WRAP_GAP {
			// There is only one copy on screen
			l.scrollPos = tail
		}
		topLeft := image.Point{0, topOffset + l.scrollPos + (line * l.font.Height())}
		l.graphics[line].Rect = image.Rectangle{topLeft, topLeft.Add(l.graphics[line].Bounds().Size())}
		l.graphics[line+len(l.lines)].Rect = l.graphics[line].Rect.Add(image.Point{0, totalHeight})
	} else {
		topLeft := image.Point{0, topOffset + (line * l.font.Height())}
		l.graphics[line].Rect = image.Rectangle{topLeft, topLeft.Add(l.graphics[line].Bounds().Size())}
		l.graphics[line+len(l.lines)].Rect = l.graphics[line].Rect
	}
}
Example #7
0
func (b *bucket) addPixel(pixel image.Point) {
	b.group.wire.pixels = append(b.group.wire.pixels, pixel)
	b.group.wire.bounds = b.group.wire.bounds.Union(
		image.Rectangle{
			pixel,
			pixel.Add(image.Point{1, 1})})
}
Example #8
0
func (i *imageSlice) At(x, y int) color.Color {
	p := image.Point{x, y}
	if p.In(i.r) {
		p = p.Add(i.p)
		return i.img.At(p.X, p.Y)
	}
	return color.RGBA{0, 0, 0, 0}
}
func hasNeighbor(p image.Point) bool {
	for _, n := range n8 {
		o := p.Add(n)
		if o.In(g.Rect) && g.At(o.X, o.Y).(color.Gray).Y == frost {
			return true
		}
	}
	return false
}
Example #10
0
// Image returns a new Image which will be drawn using img,
// with p giving the coordinate of the image's top left corner.
//
func NewImage(img image.Image, opaque bool, p image.Point) *Image {
	obj := new(Image)
	obj.Item = &obj.item
	r := img.Bounds()
	obj.item.R = image.Rectangle{p, p.Add(image.Pt(r.Dx(), r.Dy()))}
	obj.item.Image = img
	obj.item.IsOpaque = opaque
	return obj
}
Example #11
0
// SliceImage returns an image which is a view onto a portion of img.
// The returned image has the specified width and height,
// but all draw operations are clipped to r.
// The origin of img is aligned with p. Where img
// overlaps with r, it will be used for drawing operations.
//
func SliceImage(width, height int, r image.Rectangle, img draw.Image, p image.Point) draw.Image {
	// TODO: detect when img is itself a SliceImage and
	// use the underlying image directly.
	i := new(imageSlice)
	i.img = img
	i.r = r.Intersect(image.Rectangle{p, p.Add(img.Bounds().Size())})
	//debugp("actual sliced rectangle %v\n", i.r)
	i.p = p
	return i
}
Example #12
0
func Rect() {
	dst := image.NewRGBA(image.Rect(0, 0, 640, 480))
	sr := image.Rect(0, 0, 200, 200)
	src := image.Black
	dp := image.Point{100, 100}

	// RECT OMIT
	r := image.Rectangle{dp, dp.Add(sr.Size())}
	draw.Draw(dst, r, src, sr.Min, draw.Src)
	// STOP OMIT
}
Example #13
0
File: hog.go Project: jvlmdr/go-cv
func MinInputSize(feat image.Point, conf Config) image.Point {
	// One feature pixel on all sides.
	feat = feat.Add(image.Pt(2, 2))
	// Multiply by cell size to get pixels.
	pix := feat.Mul(conf.CellSize)
	// Add floor(half a cell) on all sides.
	half := conf.CellSize / 2
	pix = pix.Add(image.Pt(half, half).Mul(2))
	// Leave one pixel to compute derivatives.
	pix = pix.Add(image.Pt(1, 1).Mul(2))
	return pix
}
Example #14
0
func (m *Mob) Sprite(offset image.Point) gfx.Sprite {
	// XXX: Hacky way to pass adjust parameter to make big mobs get drawn by
	// their frontmost point. Layer is assumed to be a delta, the view system
	// will adjust it into the correct Z level.
	layer := 0
	if m.isBig {
		layer += 2 * util.ViewLayersPerZ
	}
	return gfx.Sprite{
		Layer:    layer,
		Offset:   offset.Add(m.bob()),
		Drawable: app.Cache().GetDrawable(m.icon)}
}
Example #15
0
File: vnc.go Project: kward/venue
// MouseDrag moves the mouse, clicks, and drags to a new position.
func (v *VNC) MouseDrag(p, d image.Point) error {
	if err := v.MouseMove(p); err != nil {
		return err
	}
	if err := v.conn.PointerEvent(vnclib.ButtonLeft, uint16(p.X), uint16(p.Y)); err != nil {
		return err
	}
	p = p.Add(d) // Add delta.
	if err := v.conn.PointerEvent(vnclib.ButtonLeft, uint16(p.X), uint16(p.Y)); err != nil {
		return err
	}
	return v.conn.PointerEvent(vnclib.ButtonNone, uint16(p.X), uint16(p.Y))
}
Example #16
0
// send image resize request with url in string and size in uint
// receive image type
func cropIn(filename string, paneau draw.Image, location image.Point) {
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		log.Fatal(err)
	}
	reader := strings.NewReader(string(data))
	img, _, _ := image.Decode(reader)
	//bounds := paneau.Bounds()
	sr := img.Bounds()
	r := image.Rectangle{location, location.Add(sr.Size())}
	draw.Draw(paneau, r, img, sr.Min, draw.Src)
	log.Println("cropped")
}
Example #17
0
func ProcessNew(pos image.Point, userObj pf.ProcessIf) (ret *Process) {
	config := DrawConfig{ColorInit(ColorOption(ProcessNormal)),
		ColorInit(ColorOption(ProcessHighlight)),
		ColorInit(ColorOption(ProcessSelected)),
		ColorInit(ColorOption(BoxFrame)),
		ColorInit(ColorOption(Text)),
		image.Point{procPortWidth, procPortHeight}}
	cconfig := ContainerConfig{procPortWidth, procPortHeight, procMinWidth, procMinHeight}
	ret = &Process{ContainerInit(nil, config, userObj, cconfig), userObj, nil}
	shape := image.Point{global.processWidth, global.processHeight}
	ret.box = image.Rectangle{pos, pos.Add(shape)}
	ret.ContainerInit()
	return
}
Example #18
0
func propagateWheel(w sparta.Widget, pt image.Point) sparta.Widget {
	rect := w.Property(sparta.Geometry).(image.Rectangle)
	childs := w.Property(sparta.Childs)
	if childs == nil {
		return w
	}
	for _, ch := range childs.([]sparta.Widget) {
		rect = ch.Property(sparta.Geometry).(image.Rectangle)
		if pt.In(rect) {
			return propagateWheel(ch, pt.Add(rect.Min))
		}
	}
	return w
}
Example #19
0
func (b *ProgressBar) Draw(to draw.Image) image.Rectangle {
	var fillWidth, fillHeight int
	var dp image.Point
	var dr image.Rectangle

	if b.IsDirty() {
		b.Update()

		g := b.graphics[0]
		if debug {
			fmt.Printf("b.Bounds(): %v, canvas.Bounds(): %v, g.Bounds(): %v\n", b.Bounds(), b.canvas.Bounds(), g.Bounds())
		}
		draw.Draw(b.canvas, b.canvas.Bounds(), g, g.Bounds().Min, draw.Src)

		mrange := b.Max - b.Min
		percent := (b.Progress * 100) / mrange
		if percent > 100 {
			percent = 100
		} else if percent < 0 {
			percent = 0
		}
		activeWidth := b.Widget.Dx() - (2 * hIndent) - (2 * borderWidth)
		activeHeight := b.Widget.Dy() - (2 * vIndent) - (2 * borderWidth)

		if b.Direction == Horizontal {
			fillWidth = (activeWidth * percent) / 100
			fillHeight = activeHeight
			dp = image.Point{hIndent + borderWidth, vIndent + borderWidth}
			dr = image.Rectangle{dp, dp.Add(image.Point{fillWidth, fillHeight})}
		} else {
			fillHeight = (activeHeight * percent) / 100
			fillWidth = activeWidth
			dp = image.Point{hIndent + borderWidth + (activeWidth - fillWidth), vIndent + borderWidth + (activeHeight - fillHeight)}
			dr = image.Rectangle{dp, dp.Add(image.Point{fillWidth, fillHeight})}
		}

		if debug {
			fmt.Printf("percent: %v, activeWidth: %v, activeHeight: %v, fillWidth: %v, fillHeight: %v, dr: %v\n", percent, activeWidth, activeHeight, fillWidth, fillHeight, dr)
		}
		draw.Draw(b.canvas, dr, &image.Uniform{b.Widget.Foreground}, image.ZP, draw.Src)

		if b.IsVisible() {
			draw.Draw(to, b.Bounds(), b.canvas, image.ZP, draw.Src)
			return b.Bounds()
		}
		return image.ZR
	}
	return image.ZR
}
Example #20
0
func (i *imageSlice) DrawMask(r image.Rectangle, src image.Image, sp image.Point, mask image.Image, mp image.Point, op draw.Op) bool {
	//debugp("imageslice draw %v; sp %v\n", r, sp)
	dr := r.Intersect(i.r)
	if dr.Empty() {
		//debugp("-> clipped empty (r %v)\n", i.r)
		return true
	}
	delta := dr.Min.Sub(r.Min) // realignment because of clipping.
	sp = sp.Add(delta)
	mp = mp.Add(delta)
	dr = dr.Sub(i.p)
	//debugp("-> draw %v; sp %v\n", dr, sp)
	draw.DrawMask(i.img, dr, src, sp, mask, mp, op)
	return true
}
Example #21
0
func findDiffForPoint(matcher diffMatcher, diffs *list.List, pt image.Point) *image.Rectangle {
	var diff *image.Rectangle = nil
	for e := diffs.Front(); e != nil; e = e.Next() {
		rect := e.Value.(*image.Rectangle)
		if matcher(rect, pt) {
			diff = rect
			break
		}
	}
	if diff == nil {
		// the diffs should never be "empty" and therefore the created
		// rectangle is 1x1 pixels in size upon creation
		diff = &image.Rectangle{pt, pt.Add(image.Pt(1, 1))}
		diffs.PushBack(diff)
	}
	return diff
}
Example #22
0
// write out the actual mosaic to disk
func writeMosaic(flickrGetter HttpGetter, submitPic ImageFile, md5sum string) (bool, string) {
	mosaicImage := image.NewNRGBA(image.Rect(0, 0, submitPic.XEnd*4, submitPic.YEnd*4))
	for _, tile := range submitPic.Tiles {
		var tempImage image.Image
		reader, err := os.Open(flickrGetter.GetSaveDir() + "/" + tile.MatchURL)
		if err != nil {
			logger.Printf("unable to use %v image as tile: %v\n", tile.MatchURL, err)
			tempImage, err = getFlickrPhotoNoSave(tile.MatchURL, flickrGetter)
			if err != nil {
				logger.Println("error getting image from flickr: ", err)
			}
		} else {
			tempImage, _, err = image.Decode(reader)
			if err != nil {
				logger.Println("error decoding tile image: ", err)
			}
		}
		if err == nil {
			tempImageNRGBA := convertToNRGBA(tempImage)
			tempImageNRGBA = resizeNearest(tempImageNRGBA, 40, 40)
			point := image.Point{}
			if tile.XStart == 0 && tile.YStart == 0 {

			} else {
				point = image.Point{Y: tile.YStart * 4, X: tile.XStart * 4}
			}
			rect := tempImageNRGBA.Bounds()
			r := image.Rectangle{point, point.Add(rect.Size())}
			draw.FloydSteinberg.Draw(mosaicImage, r, tempImageNRGBA, rect.Min)
		}
		reader.Close()
	}
	// resize a bit
	mosaicImage = resizeNearest(mosaicImage, mosaicImage.Bounds().Max.X/2, mosaicImage.Bounds().Max.Y/2)
	// write file
	outFileName := "mosaic_" + md5sum + strconv.Itoa(int(time.Now().Unix())) + ".png"
	out, err := os.Create("created/" + outFileName)
	if err != nil {
		logger.Println("error creating file: ", err)
	}
	err = png.Encode(out, mosaicImage)
	if err != nil {
		logger.Println("error encoding mosaic image: ", err)
	}
	return true, outFileName
}
Example #23
0
// Uses half-sample symmetry.
func Symmetric(im image.Image, p image.Point) color.Color {
	b := im.Bounds()
	// Make twice as big.
	d := image.Rectangle{b.Min, b.Max.Add(b.Size())}
	p = p.Mod(d)

	// Move to origin.
	p = p.Sub(b.Min)
	w, h := b.Dx(), b.Dy()
	if p.X > w-1 {
		p.X = 2*w - 1 - p.X
	}
	if p.Y > h-1 {
		p.Y = 2*h - 1 - p.Y
	}
	p = p.Add(b.Min)

	return im.At(p.X, p.Y)
}
Example #24
0
func (w *windowImpl) Upload(dp image.Point, src screen.Buffer, sr image.Rectangle) {
	originalSRMin := sr.Min
	sr = sr.Intersect(src.Bounds())
	if sr.Empty() {
		return
	}
	dp = dp.Add(sr.Min.Sub(originalSRMin))
	// TODO: keep a texture around for this purpose?
	t, err := w.s.NewTexture(sr.Size())
	if err != nil {
		panic(err)
	}
	t.Upload(image.Point{}, src, sr)
	w.Draw(f64.Aff3{
		1, 0, float64(dp.X),
		0, 1, float64(dp.Y),
	}, t, t.Bounds(), draw.Src, nil)
	t.Release()
}
Example #25
0
// BorderOp draws a retangular border of size r and width n, with n positive
// meaning the border is inside r, drawn with the specified draw op.
func (dst *Image) BorderOp(r image.Rectangle, n int, color *Image, sp image.Point, op Op) {
	if n < 0 {
		r = r.Inset(n)
		sp = sp.Add(image.Pt(n, n))
		n = -n
	}
	dst.Display.mu.Lock()
	defer dst.Display.mu.Unlock()
	draw(dst, image.Rect(r.Min.X, r.Min.Y, r.Max.X, r.Min.Y+n),
		color, sp, nil, sp, op)
	pt := image.Pt(sp.X, sp.Y+r.Dy()-n)
	draw(dst, image.Rect(r.Min.X, r.Max.Y-n, r.Max.X, r.Max.Y),
		color, pt, nil, pt, op)
	pt = image.Pt(sp.X, sp.Y+n)
	draw(dst, image.Rect(r.Min.X, r.Min.Y+n, r.Min.X+n, r.Max.Y-n),
		color, pt, nil, pt, op)
	pt = image.Pt(sp.X+r.Dx()-n, sp.Y+n)
	draw(dst, image.Rect(r.Max.X-n, r.Min.Y+n, r.Max.X, r.Max.Y-n),
		color, pt, nil, pt, op)
}
Example #26
0
func collectPegs(origin image.Point, facing Dir4, spec ParseSpec, edge string) (result []Peg, err error) {
	result = []Peg{}
	inPeg := false
	for x, ch := range edge {
		if spec.isPeg(uint8(ch)) {
			if !inPeg {
				inPeg = true
				start := origin.Add(facing.alongVec().Mul(x))
				result = append(result, Peg{start, facing, ""})
			}
			current := &result[len(result)-1]
			current.pattern += string(ch)
		} else if spec.isOverlap(uint8(ch)) {
			if x == 0 || x == len(edge)-1 || !spec.isPeg(edge[x-1]) ||
				!spec.isPeg(edge[x+1]) {
				err = errors.New("Overlap char not between two peg chars")
				return
			}
			if !inPeg {
				panic("Not in peg even though previous char is peg char")
			}

			// The overlap char means that the current and the next peg share
			// the current cell. End the current peg by repeating its last
			// character.
			current := &result[len(result)-1]
			last, _ := utf8.DecodeLastRuneInString(current.pattern)
			current.pattern += string(last)

			// Start the next peg with the same character as its second one.
			start := origin.Add(facing.alongVec().Mul(x))
			result = append(result, Peg{start, facing, string(MapCell(edge[x+1]))})
		} else {
			inPeg = false
		}
	}

	return
}
Example #27
0
func (m *Mapgen) isDoorSite(pt image.Point) bool {
	if !m.terrain(pt).BlocksMove() {
		return false
	}

	up := m.terrain(pt.Add(image.Pt(0, -1))).BlocksMove()
	down := m.terrain(pt.Add(image.Pt(0, 1))).BlocksMove()
	left := m.terrain(pt.Add(image.Pt(-1, 0))).BlocksMove()
	right := m.terrain(pt.Add(image.Pt(1, 0))).BlocksMove()

	if up != down || left != right {
		return false
	}

	return up != left
}
Example #28
0
func (c *Container) ContainerDefaultSetPosition(pos image.Point) {
	if c.selectedChild != -1 {
		child := c.Children[c.selectedChild]
		childpos := child.Position()
		offset := childpos.Sub(c.Position())
		child.SetPosition(pos.Add(offset))
		c.box = c.Layout()
	} else if c.selectedPort != -1 {
		child := c.ports[c.selectedPort]
		childpos := child.Position()
		offset := childpos.Sub(c.Position())
		newPos := pos.Add(offset)
		child.SetPosition(c.portClipPos(newPos))
	} else {
		shift := pos.Sub(c.Position())
		c.BBoxDefaultSetPosition(pos)
		for _, p := range c.Children {
			p.SetPosition(p.Position().Add(shift))
		}
		for _, p := range c.ports {
			p.SetPosition(p.Position().Add(shift))
		}
	}
}
Example #29
0
func (l *Label) horizontalPosition(line int) {
	var tail, leftOffset int

	textWidth := l.font.Width(l.lines[line])
	totalWidth := textWidth + WRAP_GAP

	switch l.HAlign {
	case Left:
		leftOffset = 0
	case Centre:
		leftOffset = (l.Bounds().Dx() - textWidth) / 2
	case Right:
		leftOffset = (l.Bounds().Dx() - textWidth)
	}

	if (textWidth > l.Dx()) && l.scroll {
		// Alias it, so that tail is always to the right
		// scrollpos > 0 can only happen when scroll == true
		if l.scrollPos > 0 {
			l.scrollPos -= totalWidth
		}
		tail = l.scrollPos + totalWidth
		if tail <= WRAP_GAP {
			l.scrollPos = tail
		}
		topLeft := image.Point{leftOffset + l.scrollPos, l.graphics[line].Rect.Min.Y}
		l.graphics[line].Rect = image.Rectangle{topLeft, topLeft.Add(l.graphics[line].Bounds().Size())}
		l.graphics[line+len(l.lines)].Rect = l.graphics[line].Rect.Add(image.Point{totalWidth, 0})
	} else {
		topLeft := image.Point{leftOffset, l.graphics[line].Rect.Min.Y}
		l.graphics[line].Rect = image.Rectangle{topLeft, topLeft.Add(l.graphics[line].Bounds().Size())}
		topLeft = image.Point{leftOffset, l.graphics[line+len(l.lines)].Rect.Min.Y}
		l.graphics[line+len(l.lines)].Rect = image.Rectangle{topLeft, topLeft.Add(l.graphics[line+len(l.lines)].Bounds().Size())}
	}

}
Example #30
0
func TestBuildColorMap(t *testing.T) {
	red := color.NRGBA{255, 0, 0, 255}
	green := color.NRGBA{0, 255, 0, 255}
	blue := color.NRGBA{0, 0, 255, 255}
	white := color.NRGBA{0, 0, 0, 255}

	redSquare := image.NewNRGBA(image.Rect(0, 0, 20, 20))
	draw.Draw(redSquare, redSquare.Bounds(), &image.Uniform{red}, image.ZP, draw.Src)
	greenSquare := image.NewNRGBA(image.Rect(0, 0, 20, 20))
	draw.Draw(greenSquare, greenSquare.Bounds(), &image.Uniform{green}, image.ZP, draw.Src)
	blueSquare := image.NewNRGBA(image.Rect(0, 0, 20, 20))
	draw.Draw(blueSquare, blueSquare.Bounds(), &image.Uniform{blue}, image.ZP, draw.Src)
	whiteSquare := image.NewNRGBA(image.Rect(0, 0, 20, 20))
	draw.Draw(whiteSquare, whiteSquare.Bounds(), &image.Uniform{white}, image.ZP, draw.Src)

	testImage := image.NewNRGBA(image.Rect(0, 0, 40, 40))
	point := image.Point{}
	rect := redSquare.Bounds()
	r := image.Rectangle{point, point.Add(rect.Size())}
	draw.Draw(testImage, r, redSquare, rect.Min, draw.Src)

	point = image.Point{Y: 0, X: 20}
	rect = greenSquare.Bounds()
	r = image.Rectangle{point, point.Add(rect.Size())}
	draw.Draw(testImage, r, greenSquare, rect.Min, draw.Src)

	point = image.Point{Y: 20, X: 0}
	rect = blueSquare.Bounds()
	r = image.Rectangle{point, point.Add(rect.Size())}
	draw.Draw(testImage, r, blueSquare, rect.Min, draw.Src)

	point = image.Point{Y: 20, X: 20}
	rect = whiteSquare.Bounds()
	r = image.Rectangle{point, point.Add(rect.Size())}
	draw.Draw(testImage, r, whiteSquare, rect.Min, draw.Src)

	testPic := ImageFile{Name: "createTiles-test.jpg", Image: testImage}

	testTile := OrigTile{Filename: "createTiles-test.jpg", YStart: 0, YEnd: 19, XStart: 0, XEnd: 19}
	testTile.buildColorMap(testPic)
	if testTile.AvgRGB == nil {
		t.Errorf("NRGBA AvgRGB is nil")
	}
	if testTile.AvgRGB["red"] != 65535 || testTile.AvgRGB["green"] != 0 || testTile.AvgRGB["blue"] != 0 || testTile.AvgRGB["alpha"] != 65535 {
		t.Errorf("NRGBA red is %v, should be 25700", testTile.AvgRGB["red"])
		t.Errorf("NRGBA green is %v, should be 38550", testTile.AvgRGB["green"])
		t.Errorf("NRGBA blue is %v, should be 65535", testTile.AvgRGB["blue"])
		t.Errorf("NRGBA alpha is %v, should be 65535", testTile.AvgRGB["alpha"])
	}

	testTile = OrigTile{Filename: "createTiles-test.jpg", YStart: 0, YEnd: 19, XStart: 20, XEnd: 39}
	testTile.buildColorMap(testPic)
	if testTile.AvgRGB == nil {
		t.Errorf("NRGBA AvgRGB is nil")
	}
	if testTile.AvgRGB["red"] != 0 || testTile.AvgRGB["green"] != 65535 || testTile.AvgRGB["blue"] != 0 || testTile.AvgRGB["alpha"] != 65535 {
		t.Errorf("NRGBA red is %v, should be 25700", testTile.AvgRGB["red"])
		t.Errorf("NRGBA green is %v, should be 38550", testTile.AvgRGB["green"])
		t.Errorf("NRGBA blue is %v, should be 65535", testTile.AvgRGB["blue"])
		t.Errorf("NRGBA alpha is %v, should be 65535", testTile.AvgRGB["alpha"])
	}

	testTile = OrigTile{Filename: "createTiles-test.jpg", YStart: 19, YEnd: 39, XStart: 0, XEnd: 39}
	testTile.buildColorMap(testPic)
	if testTile.AvgRGB == nil {
		t.Errorf("NRGBA AvgRGB is nil")
	}
	if testTile.AvgRGB["red"] != 1680 || testTile.AvgRGB["green"] != 1596 || testTile.AvgRGB["blue"] != 31927 || testTile.AvgRGB["alpha"] != 65535 {
		t.Errorf("NRGBA red is %v, should be 25700", testTile.AvgRGB["red"])
		t.Errorf("NRGBA green is %v, should be 38550", testTile.AvgRGB["green"])
		t.Errorf("NRGBA blue is %v, should be 65535", testTile.AvgRGB["blue"])
		t.Errorf("NRGBA alpha is %v, should be 65535", testTile.AvgRGB["alpha"])
	}

	// simple test for checking our switch case...
	//image.YCbCr
	//m2 := image.NewYCbCr(image.Rect(0, 0, 200, 200), image.YCbCrSubsampleRatio444)
	m2 := image.NewRGBA(image.Rect(0, 0, 200, 200))
	draw.Draw(m2, m2.Bounds(), &image.Uniform{red}, image.ZP, draw.Src)
	testPic.Image = m2
	testTile.buildColorMap(testPic)
	if testTile.AvgRGB == nil {
		t.Errorf("RGBA AvgRGB is nil")
	}
	if testTile.AvgRGB["red"] != 65535 || testTile.AvgRGB["green"] != 0 || testTile.AvgRGB["blue"] != 0 || testTile.AvgRGB["alpha"] != 65535 {
		t.Errorf("RGBA red is %v, should be 32296", testTile.AvgRGB["red"])
		t.Errorf("RGBA green is %v, should be 4683", testTile.AvgRGB["green"])
		t.Errorf("RGBA blue is %v, should be 691", testTile.AvgRGB["blue"])
		t.Errorf("RGBA alpha is %v, should be 65535", testTile.AvgRGB["alpha"])
	}

	m3 := image.NewRGBA64(image.Rect(0, 0, 200, 200))
	draw.Draw(m3, m3.Bounds(), &image.Uniform{red}, image.ZP, draw.Src)
	testPic.Image = m3
	testTile.buildColorMap(testPic)
	if testTile.AvgRGB == nil {
		t.Errorf("RGBA64 AvgRGB is nil")
	}
	if testTile.AvgRGB["red"] != 65535 || testTile.AvgRGB["green"] != 0 || testTile.AvgRGB["blue"] != 0 || testTile.AvgRGB["alpha"] != 65535 {
		t.Errorf("RGBA64 red is %v, should be 32296", testTile.AvgRGB["red"])
		t.Errorf("RGBA64 green is %v, should be 4683", testTile.AvgRGB["green"])
		t.Errorf("RGBA64 blue is %v, should be 691", testTile.AvgRGB["blue"])
		t.Errorf("RGBA64 alpha is %v, should be 65535", testTile.AvgRGB["alpha"])
	}

	m4 := image.NewNRGBA64(image.Rect(0, 0, 200, 200))
	draw.Draw(m4, m4.Bounds(), &image.Uniform{red}, image.ZP, draw.Src)
	testPic.Image = m4
	testTile.buildColorMap(testPic)
	if testTile.AvgRGB == nil {
		t.Errorf("NRGBA64 AvgRGB is nil")
	}
	if testTile.AvgRGB["red"] != 65535 || testTile.AvgRGB["green"] != 0 || testTile.AvgRGB["blue"] != 0 || testTile.AvgRGB["alpha"] != 65535 {
		t.Errorf("NRGBA64 red is %v, should be 32296", testTile.AvgRGB["red"])
		t.Errorf("NRGBA64 green is %v, should be 4683", testTile.AvgRGB["green"])
		t.Errorf("NRGBA64 blue is %v, should be 691", testTile.AvgRGB["blue"])
		t.Errorf("NRGBA64 alpha is %v, should be 65535", testTile.AvgRGB["alpha"])
	}
}