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/tiledb"
"mapserver/tilerenderer"
"mapserver/vfs"
"mapserver/worldconfig"
"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
a.Mapblockrenderer = mapblockrenderer.NewMapBlockRenderer(a.BlockAccessor, a.Colormapping)
a.Mapblockrenderer = mapblockrenderer.NewMapBlockRenderer(a.BlockAccessor, a.Colormapping, fullpalette)
//mapserver database
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
* WTFPL
* 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]
}
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 {
id := mb.GetNodeId(x, y, z)
return mb.BlockMapping[id]

View File

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

View File

@ -17,14 +17,16 @@ import (
type MapBlockRenderer struct {
accessor *mapblockaccessor.MapBlockAccessor
colors *colormapping.ColorMapping
fullpalette *colormapping.Palette
enableShadow 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{
accessor: accessor,
colors: colors,
fullpalette: fullpalette,
enableShadow: true,
enableTransparency: false,
}
@ -136,6 +138,12 @@ func (r *MapBlockRenderer) Render(pos1, pos2 *coords.MapBlockCoords) (*image.NRG
}
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 {
continue

View File

@ -2,7 +2,6 @@ package mapblockrenderer
import (
"fmt"
"github.com/sirupsen/logrus"
"io/ioutil"
"mapserver/colormapping"
"mapserver/coords"
@ -13,6 +12,8 @@ import (
"os"
"testing"
"time"
"github.com/sirupsen/logrus"
)
func TestSimpleRender(t *testing.T) {
@ -51,7 +52,18 @@ func TestSimpleRender(t *testing.T) {
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)
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