From afca241c1208b4b96c4c6e732ea4f4bce1ce5092 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Fri, 12 Sep 2014 17:10:05 +0200 Subject: [PATCH] Cut off border blocks when in shaded output mode. --- tilemapper/main.go | 22 +++++++++++++++------- tilemapper/renderer.go | 21 +++++++++++++++------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/tilemapper/main.go b/tilemapper/main.go index 4abbeca..17b607b 100644 --- a/tilemapper/main.go +++ b/tilemapper/main.go @@ -28,14 +28,14 @@ func main() { flag.IntVar(&port, "port", 6379, "port to of mtredisalize server") flag.IntVar(&port, "p", 6379, "port to of mtredisalize server (shorthand)") flag.StringVar(&host, "host", "localhost", "host to mtredisalize server") - flag.IntVar(&x, "x", -9, "x of query cuboid") + flag.IntVar(&x, "x", 0, "x of query cuboid") flag.IntVar(&y, "y", -75, "y of query cuboid") - flag.IntVar(&z, "z", -9, "z of query cuboid") - flag.IntVar(&width, "width", 18, "width of query cuboid") - flag.IntVar(&height, "height", 18, "height of query cuboid") + flag.IntVar(&z, "z", 0, "z of query cuboid") + flag.IntVar(&width, "width", 16, "width of query cuboid") + flag.IntVar(&height, "height", 16, "height of query cuboid") flag.IntVar(&depth, "depth", 150, "depth of query cuboid") - flag.IntVar(&width, "w", 18, "width of query cuboid (shorthand)") - flag.IntVar(&height, "h", 18, "height of query cuboid (shorthand)") + flag.IntVar(&width, "w", 16, "width of query cuboid (shorthand)") + flag.IntVar(&height, "h", 16, "height of query cuboid (shorthand)") flag.IntVar(&depth, "d", 150, "depth of query cuboid (shorthand)") flag.StringVar(&colorsfile, "colors", "colors.txt", "definition of colors") flag.StringVar(&outfile, "output", "out.png", "image file of result") @@ -60,11 +60,18 @@ func main() { } defer client.Close() + if shaded { + width += 2 + height += 2 + x-- + z-- + } + q1x, q1y, q1z := int16(x), int16(y), int16(z) q2x, q2y, q2z := q1x+int16(width)-1, q1y+int16(depth)-1, q1z+int16(height)-1 renderer := NewRenderer(q1x, q1z, width, height) - yOrder := NewYOrder(renderer, 512) + yOrder := NewYOrder(renderer, 1024) numBlocks := 0 drawBlock := func(block *common.Block) { @@ -97,6 +104,7 @@ func main() { if shaded { image = renderer.CreateShadedImage( + 16, 16, (width-2)*16, (height-2)*16, colors.Colors, color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}) } else { image = renderer.CreateImage( diff --git a/tilemapper/renderer.go b/tilemapper/renderer.go index 80e63fe..7b9611a 100644 --- a/tilemapper/renderer.go +++ b/tilemapper/renderer.go @@ -226,12 +226,20 @@ func safeColor(x int32) uint8 { } } -func (r *Renderer) CreateShadedImage(colors []color.RGBA, background color.RGBA) *image.RGBA { - pw, ph := r.width<<4, r.height<<4 - image := image.NewRGBA(image.Rect(0, 0, pw, ph)) - ofs, numCols := 0, int32(len(colors)) - for z := ph - 1; z >= 0; z-- { - for x := 0; x < pw; x++ { +func (r *Renderer) CreateShadedImage( + xOfs, zOfs, width, height int, + colors []color.RGBA, background color.RGBA) *image.RGBA { + + image := image.NewRGBA(image.Rect(0, 0, width, height)) + + pw := r.width << 4 + + ofs, numCols := zOfs*pw+xOfs, int32(len(colors)) + + stride := pw - width + + for z := height - 1; z >= 0; z-- { + for x := 0; x < width; x++ { colIdx := r.cBuffer[ofs] if colIdx < 0 || colIdx >= numCols { image.Set(x, z, background) @@ -261,6 +269,7 @@ func (r *Renderer) CreateShadedImage(colors []color.RGBA, background color.RGBA) } ofs++ } + ofs += stride } return image }