1
0
Fork 0

openstmap If in 3 bit mode, go through all the data beforehand and

turn the saturation up to maximum, so when thresholded it
          works a lot better  - see #1276
master
Gordon Williams 2022-01-19 15:13:13 +00:00
parent 5e5d23c921
commit 16ebe01df3
1 changed files with 27 additions and 2 deletions

View File

@ -116,8 +116,33 @@ TODO:
if (document.getElementById("3bit").checked) { if (document.getElementById("3bit").checked) {
options = { options = {
compression:false, output:"raw", compression:false, output:"raw",
mode:"3bit", brightness:-64, mode:"3bit",
}; };
/* If in 3 bit mode, go through all the data beforehand and
turn the saturation up to maximum, so when thresholded it
works a lot better */
var imageData = ctx.getImageData(0,0,width,height);
var rgba = imageData.data;
var l = width*height*4;
for (var i=0;i<l;i+=4) {
var min = Math.min(rgba[i+0],rgba[i+1],rgba[i+2]);
var max = Math.max(rgba[i+0],rgba[i+1],rgba[i+2]);
var d = max-min;
if (max<120) { // black
rgba[i+0]=0;
rgba[i+1]=0;
rgba[i+2]=0;
} else if (min>240 || d<8) { // white or grey
rgba[i+0]=255;
rgba[i+1]=255;
rgba[i+2]=255;
} else { // another colour - use max saturation
rgba[i+0] = (rgba[i+0]-min) * 255 / d;
rgba[i+1] = (rgba[i+1]-min) * 255 / d;
rgba[i+2] = (rgba[i+2]-min) * 255 / d;
}
}
ctx.putImageData(imageData,0,0);
} }
console.log("Compression options", options); console.log("Compression options", options);
var w = Math.round(width / TILESIZE); var w = Math.round(width / TILESIZE);
@ -131,7 +156,7 @@ TODO:
options.width = TILESIZE; options.width = TILESIZE;
options.height = TILESIZE; options.height = TILESIZE;
var imgstr = imageconverter.RGBAtoString(rgba, options); var imgstr = imageconverter.RGBAtoString(rgba, options);
ctx.putImageData(imageData,x*TILESIZE, y*TILESIZE); ctx.putImageData(imageData,x*TILESIZE, y*TILESIZE); // write preview
/*var compress = 'require("heatshrink").decompress(' /*var compress = 'require("heatshrink").decompress('
if (!imgstr.startsWith(compress)) throw "Data in wrong format"; if (!imgstr.startsWith(compress)) throw "Data in wrong format";
imgstr = imgstr.slice(compress.length,-1);*/ imgstr = imgstr.slice(compress.length,-1);*/