param2 fullpalette support

This commit is contained in:
Thomas Rudin 2019-06-19 21:12:04 +02:00
parent 18c231375d
commit ef6ad8d151
11 changed files with 118 additions and 6 deletions

View File

@ -14,6 +14,7 @@ import (
"mapserver/settings" "mapserver/settings"
"mapserver/tiledb" "mapserver/tiledb"
"mapserver/tilerenderer" "mapserver/tilerenderer"
"mapserver/vfs"
"mapserver/worldconfig" "mapserver/worldconfig"
"time" "time"
@ -105,8 +106,14 @@ func Setup(p params.ParamsType, cfg *Config) *App {
} }
fullpalette, err := colormapping.NewPalette(vfs.FSMustByte(false, "/pics/unifieddyes_palette_extended.png"))
if err != nil {
panic(err)
}
//mapblock renderer //mapblock renderer
a.Mapblockrenderer = mapblockrenderer.NewMapBlockRenderer(a.BlockAccessor, a.Colormapping) a.Mapblockrenderer = mapblockrenderer.NewMapBlockRenderer(a.BlockAccessor, a.Colormapping, fullpalette)
//mapserver database //mapserver database
if a.Worldconfig[worldconfig.CONFIG_PSQL_MAPSERVER] != "" { if a.Worldconfig[worldconfig.CONFIG_PSQL_MAPSERVER] != "" {

45
colormapping/palette.go Normal file
View File

@ -0,0 +1,45 @@
package colormapping
import (
"bytes"
"image/color"
"image/png"
)
type Palette struct {
colors map[int]*color.RGBA
}
func NewPalette(imagefile []byte) (*Palette, error) {
palette := &Palette{
colors: make(map[int]*color.RGBA),
}
reader := bytes.NewReader(imagefile)
img, err := png.Decode(reader)
if err != nil {
return nil, err
}
bounds := img.Bounds()
index := 0
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
c := img.At(x, y)
r, g, b, a := c.RGBA()
//fmt.Println("x ", x, " y ", y, " Index: ", index, " Color ", c)
palette.colors[index] = &color.RGBA{uint8(r), uint8(g), uint8(b), uint8(a)}
index++
}
}
return palette, nil
}
func (m *Palette) GetColor(param2 int) *color.RGBA {
return m.colors[param2]
}

View File

@ -0,0 +1,30 @@
package colormapping
import (
"fmt"
"io/ioutil"
"testing"
)
func TestNewPalette(t *testing.T) {
data, err := ioutil.ReadFile("./testdata/unifieddyes_palette_extended.png")
if err != nil {
t.Fatal(err)
}
palette, err := NewPalette(data)
if err != nil {
t.Fatal(err)
}
color := palette.GetColor(0)
if color == nil {
t.Fatal("color not found!")
}
fmt.Println(color)
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

View File

@ -65,3 +65,8 @@
* atm3_front.png * atm3_front.png
* WTFPL * WTFPL
* Source: http://git.gpcf.eu/?p=atm.git;a=summary * Source: http://git.gpcf.eu/?p=atm.git;a=summary
* unifieddyes_palette_extended.png
* GPL 2.0
* Source: https://gitlab.com/VanessaE/unifieddyes

View File

@ -84,6 +84,11 @@ func (mb *MapBlock) GetNodeId(x, y, z int) int {
return mb.Mapdata.ContentId[pos] return mb.Mapdata.ContentId[pos]
} }
func (mb *MapBlock) GetParam2(x, y, z int) int {
pos := getNodePos(x, y, z)
return mb.Mapdata.Param2[pos]
}
func (mb *MapBlock) GetNodeName(x, y, z int) string { func (mb *MapBlock) GetNodeName(x, y, z int) string {
id := mb.GetNodeId(x, y, z) id := mb.GetNodeId(x, y, z)
return mb.BlockMapping[id] return mb.BlockMapping[id]

View File

@ -39,8 +39,8 @@ func parseMapdata(mapblock *MapBlock, data []byte) (int, error) {
for i := 0; i < 4096; i++ { for i := 0; i < 4096; i++ {
mapd.ContentId[i] = readU16(rawdata, i*2) mapd.ContentId[i] = readU16(rawdata, i*2)
mapd.Param1[i] = readU8(rawdata, (i*2)+2) mapd.Param1[i] = readU8(rawdata, (4096*2)+i)
mapd.Param2[i] = readU8(rawdata, (i*2)+3) //TODO: last item has wrong value mapd.Param2[i] = readU8(rawdata, (4096*3)+i)
} }
return cr.Count, nil return cr.Count, nil

View File

@ -17,14 +17,16 @@ import (
type MapBlockRenderer struct { type MapBlockRenderer struct {
accessor *mapblockaccessor.MapBlockAccessor accessor *mapblockaccessor.MapBlockAccessor
colors *colormapping.ColorMapping colors *colormapping.ColorMapping
fullpalette *colormapping.Palette
enableShadow bool enableShadow bool
enableTransparency bool enableTransparency bool
} }
func NewMapBlockRenderer(accessor *mapblockaccessor.MapBlockAccessor, colors *colormapping.ColorMapping) *MapBlockRenderer { func NewMapBlockRenderer(accessor *mapblockaccessor.MapBlockAccessor, colors *colormapping.ColorMapping, fullpalette *colormapping.Palette) *MapBlockRenderer {
return &MapBlockRenderer{ return &MapBlockRenderer{
accessor: accessor, accessor: accessor,
colors: colors, colors: colors,
fullpalette: fullpalette,
enableShadow: true, enableShadow: true,
enableTransparency: false, enableTransparency: false,
} }
@ -136,6 +138,12 @@ func (r *MapBlockRenderer) Render(pos1, pos2 *coords.MapBlockCoords) (*image.NRG
} }
c := r.colors.GetColor(nodeName) c := r.colors.GetColor(nodeName)
hasfullpalette := nodeName == "unifiedbricks:brickblock"
if hasfullpalette {
param2 := mb.GetParam2(x, y, z)
c = r.fullpalette.GetColor(param2)
}
if c == nil { if c == nil {
continue continue

View File

@ -2,7 +2,6 @@ package mapblockrenderer
import ( import (
"fmt" "fmt"
"github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
"mapserver/colormapping" "mapserver/colormapping"
"mapserver/coords" "mapserver/coords"
@ -13,6 +12,8 @@ import (
"os" "os"
"testing" "testing"
"time" "time"
"github.com/sirupsen/logrus"
) )
func TestSimpleRender(t *testing.T) { func TestSimpleRender(t *testing.T) {
@ -51,7 +52,18 @@ func TestSimpleRender(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
r := NewMapBlockRenderer(cache, c) palettedata, err := ioutil.ReadFile("./testdata/unifieddyes_palette_extended.png")
if err != nil {
t.Fatal(err)
}
palette, err := colormapping.NewPalette(palettedata)
if err != nil {
t.Fatal(err)
}
r := NewMapBlockRenderer(cache, c, palette)
os.Mkdir("../test-output", 0755) os.Mkdir("../test-output", 0755)
results := make(chan JobResult, 100) results := make(chan JobResult, 100)

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B