initial commit
This commit is contained in:
219
source/makewfmap.html
Normal file
219
source/makewfmap.html
Normal file
@@ -0,0 +1,219 @@
|
||||
<!doctype html>
|
||||
|
||||
<!--[if lt IE 7 ]> <html class="ie ie6 ie-lt10 ie-lt9 ie-lt8 ie-lt7 no-js" lang="en"> <![endif]-->
|
||||
<!--[if IE 7 ]> <html class="ie ie7 ie-lt10 ie-lt9 ie-lt8 no-js" lang="en"> <![endif]-->
|
||||
<!--[if IE 8 ]> <html class="ie ie8 ie-lt10 ie-lt9 no-js" lang="en"> <![endif]-->
|
||||
<!--[if IE 9 ]> <html class="ie ie9 ie-lt10 no-js" lang="en"> <![endif]-->
|
||||
<!--[if gt IE 9]><!--><html class="no-js" lang="en"><!--<![endif]-->
|
||||
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
|
||||
<!--
|
||||
HTML5 Reset: https://github.com/murtaugh/HTML5-Reset
|
||||
Free to use
|
||||
-->
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
|
||||
<title>LUT image transform proof of concept</title>
|
||||
<meta name="author" content="Peter Marquardt" />
|
||||
<meta name="description" content="Proof of concept" />
|
||||
|
||||
<meta name="Copyright" content="Peter Marquardt" />
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<link rel="stylesheet" href="assets/css/reset.css" />
|
||||
|
||||
<style>
|
||||
img {
|
||||
border: 1px solid orange;
|
||||
}
|
||||
canvas {
|
||||
display: none;
|
||||
}
|
||||
pre {
|
||||
border: 1px solid green;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="wrapper">
|
||||
<img id="surf" />
|
||||
<img id="shad" />
|
||||
<img id="spec" />
|
||||
<canvas id="result" width="1" height="1"></canvas>
|
||||
<pre id="surfpre"></pre>
|
||||
<pre id="shadpre"></pre>
|
||||
<pre id="specpre"></pre>
|
||||
</div>
|
||||
|
||||
<script src="assets/js/libs/jquery-1.11.3.min.js"></script>
|
||||
<script>
|
||||
function initPage(){
|
||||
|
||||
var canvas = document.getElementById('result');
|
||||
var context = canvas.getContext('2d');
|
||||
|
||||
var surface = new Image();
|
||||
var shadow = new Image();
|
||||
var spec = new Image();
|
||||
|
||||
surface.onload = function() {
|
||||
shadow.onload = function() {
|
||||
spec.onload = function() {
|
||||
makeMaps(context, surface , shadow, spec);
|
||||
}
|
||||
spec.src = 'wfspec.png';
|
||||
}
|
||||
shadow.src = 'wfshad.png';
|
||||
};
|
||||
surface.src = 'wfsurf.png';
|
||||
|
||||
function dec2bin(dec){
|
||||
return (dec >>> 0).toString(2);
|
||||
}
|
||||
|
||||
function makeMaps(context, surfaceObj, shadowObj, specObj) {
|
||||
var canvas = context.canvas;
|
||||
|
||||
var lut = {};
|
||||
lut.width = 256;
|
||||
lut.height = 256;
|
||||
|
||||
canvas.width = shadowObj.width;
|
||||
canvas.height = shadowObj.height;
|
||||
context.drawImage(shadowObj, 0, 0);
|
||||
var shadow = context.getImageData(0, 0, canvas.width, canvas.height);
|
||||
var shadowdata = shadow.data;
|
||||
$('#shad').attr('src', canvas.toDataURL());
|
||||
|
||||
var bitcount = 0;
|
||||
var resulttext = "// black and white image data wrapped in bitmaps<br />";
|
||||
resulttext += "static uint8_t donutshadow[] = {<br />"
|
||||
for(var i = 0; i < shadowdata.length; i += 4) {
|
||||
if (i%(4*8) == 0) {
|
||||
resulttext += "0b";
|
||||
bitcount++;
|
||||
}
|
||||
if (shadowdata[i]<127) {
|
||||
resulttext += 1;
|
||||
} else {
|
||||
resulttext += 0;
|
||||
}
|
||||
if (i%(4*8) == (4*7)) {
|
||||
resulttext += ",";
|
||||
}
|
||||
if ((i-(4*8))%(4*8*12) == (4*8*12)-(4*9)) {
|
||||
resulttext += "<br />";
|
||||
}
|
||||
}
|
||||
while(i%(4*8) != 0) {
|
||||
resulttext += "0";
|
||||
i += 4;
|
||||
}
|
||||
resulttext += ",<br/>};";
|
||||
$('#shadpre').html('// '+Math.ceil(bitcount/8)+' bytes<br />'+resulttext);
|
||||
|
||||
bitcount = 0;
|
||||
canvas.width = specObj.width;
|
||||
canvas.height = specObj.height;
|
||||
context.drawImage(specObj, 0, 0);
|
||||
var specular = context.getImageData(0, 0, canvas.width, canvas.height);
|
||||
var speculardata = specular.data;
|
||||
$('#spec').attr('src', canvas.toDataURL());
|
||||
|
||||
resulttext = "// black and white image data wrapped in bitmaps<br />";
|
||||
resulttext += "static uint8_t donutspecular[] = {<br />";
|
||||
for(var i = 0; i < speculardata.length; i += 4) {
|
||||
if (i%(4*8) == 0) {
|
||||
resulttext += "0b";
|
||||
bitcount++;
|
||||
}
|
||||
if (speculardata[i]>127) {
|
||||
resulttext += 1;
|
||||
} else {
|
||||
resulttext += 0;
|
||||
}
|
||||
if (i%(4*8) == (4*7)) {
|
||||
resulttext += ",";
|
||||
}
|
||||
if ((i-(4*8))%(4*8*12) == (4*8*12)-(4*9)) {
|
||||
resulttext += "<br />";
|
||||
}
|
||||
}
|
||||
while(i%(4*8) != 0) {
|
||||
resulttext += "0";
|
||||
i += 4;
|
||||
}
|
||||
resulttext += ",<br/>};";
|
||||
$('#specpre').html('// '+Math.ceil(bitcount/8)+' bytes<br />'+resulttext);
|
||||
|
||||
bitcount = 0;
|
||||
canvas.width = surfaceObj.width;
|
||||
canvas.height = surfaceObj.height;
|
||||
context.drawImage(surfaceObj, 0, 0);
|
||||
var surface = context.getImageData(0, 0, canvas.width, canvas.height);
|
||||
var surfacedata = surface.data;
|
||||
$('#surf').attr('src', canvas.toDataURL());
|
||||
|
||||
var resultarray = new Array();
|
||||
var counter = 0;
|
||||
resulttext = "// heptets wrapped in octets like 0b00000007,0b11111117,0b22222227,0b33333337,0b44444447,0b55555557,0b66666667<br />";
|
||||
resulttext += "static uint8_t donutsurfacemap[] = {<br/>";
|
||||
for(var i = 0; i < surfacedata.length; i += 4) {
|
||||
counter++;
|
||||
if (surfacedata[i+2] > 0) {
|
||||
resultarray.push("0000000");
|
||||
} else {
|
||||
var str = dec2bin(Math.floor(surfacedata[i+1]/2));
|
||||
var padded = Array(8-str.length).join('0')+str;
|
||||
resultarray.push(padded);
|
||||
}
|
||||
if (counter%7 == 0) {
|
||||
if (surfacedata[i+2] > 0) {
|
||||
resultarray[0] += "0";
|
||||
resultarray[1] += "0";
|
||||
resultarray[2] += "0";
|
||||
resultarray[3] += "0";
|
||||
resultarray[4] += "0";
|
||||
resultarray[5] += "0";
|
||||
resultarray[6] += "0";
|
||||
} else {
|
||||
var str = dec2bin(Math.floor(surfacedata[i+1]/2));
|
||||
var padded = Array(8-str.length).join('0')+str;
|
||||
resultarray[0] += padded[0];
|
||||
resultarray[1] += padded[1];
|
||||
resultarray[2] += padded[2];
|
||||
resultarray[3] += padded[3];
|
||||
resultarray[4] += padded[4];
|
||||
resultarray[5] += padded[5];
|
||||
resultarray[6] += padded[6];
|
||||
}
|
||||
resulttext += "0b";
|
||||
resulttext += resultarray.join(',0b');
|
||||
resultarray = new Array();
|
||||
resulttext += ",<br />";
|
||||
bitcount += 7*8;
|
||||
}
|
||||
}
|
||||
if (resultarray.length > 0) {
|
||||
for (var i = 0; i < resultarray.length; i++) {
|
||||
resulttext += "0b"+resultarray[i]+"0,";
|
||||
bitcount += 8;
|
||||
}
|
||||
}
|
||||
resulttext += "<br />};";
|
||||
$('#surfpre').html('// '+Math.ceil(bitcount/8)+' bytes<br />'+resulttext);
|
||||
}
|
||||
|
||||
};
|
||||
</script>
|
||||
<script>$(document).ready(initPage);</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user