Skip to content

Commit cbfe83c

Browse files
committed
add new lut for new VR
1 parent 91d192f commit cbfe83c

1 file changed

Lines changed: 95 additions & 28 deletions

File tree

  • bluelight/scripts/plugin/3D

bluelight/scripts/plugin/3D/vr2.js

Lines changed: 95 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,47 @@ function loadVR2() {
176176

177177
VR2_LutArray.push(Combine_LutArray);
178178

179+
////////////////
180+
181+
var colormap = [
182+
{ value: 0.0, r: 0, g: 0, b: 0, a: 0.00, hu: -1000 }, // -1000
183+
{ value: 0.12, r: 90, g: 180, b: 255, a: 0.05, hu: -700 }, // -700
184+
{ value: 0.28, r: 245, g: 220, b: 180, a: 0.10, hu: -300 }, // -300
185+
{ value: 0.40, r: 200, g: 200, b: 200, a: 0.15, hu: 0 }, // 0
186+
{ value: 0.44, r: 180, g: 100, b: 100, a: 0.30, hu: 100 }, // 100
187+
{ value: 0.52, r: 255, g: 0, b: 0, a: 0.50, hu: 300 }, // 300
188+
{ value: 0.68, r: 255, g: 255, b: 255, a: 0.80, hu: 700 }, // 700
189+
{ value: 0.80, r: 255, g: 255, b: 200, a: 1.00, hu: 1000 }, // 1000
190+
{ value: 1.0, r: 255, g: 255, b: 255, a: 1.00, hu: 1500 }, // 1500
191+
];
192+
var ColorMap = new Array(2500);
193+
for (var m = 1; m < colormap.length; m++) {
194+
var distance = Math.abs(colormap[m].hu - colormap[m - 1].hu);
195+
for (var i = 0; i <= distance; i++) {
196+
var ratio = i / distance;
197+
var r = parseInt(colormap[m - 1].r + (colormap[m].r - colormap[m - 1].r) * ratio);
198+
var g = parseInt(colormap[m - 1].g + (colormap[m].g - colormap[m - 1].g) * ratio);
199+
var b = parseInt(colormap[m - 1].b + (colormap[m].b - colormap[m - 1].b) * ratio);
200+
var a = parseInt(colormap[m - 1].a + (colormap[m].a - colormap[m - 1].a) * ratio * 255);
201+
var hu = parseInt(colormap[m - 1].hu + (colormap[m].hu - colormap[m - 1].hu) * ratio);
202+
//console.log(i, r, g, b, a);
203+
ColorMap[hu + 1000] = [r, g, b, a];
204+
}
205+
}
206+
for (var c = 1; c < ColorMap.length; c++)
207+
if (!ColorMap[c]) ColorMap[c] = ColorMap[c - 1];
208+
209+
210+
var CT_LutArray = {
211+
name: "CT", array: ColorMap, defaultWindow: {
212+
windowWidth: "origin", windowCenter: "origin"
213+
}
214+
}
215+
216+
VR2_LutArray.push(CT_LutArray);
217+
218+
///////////////////////
219+
179220
var MIP_LutArray = {
180221
name: "MIP", filter: "lighten", defaultWindow: {
181222
windowWidth: "origin", windowCenter: "origin",
@@ -1280,43 +1321,69 @@ endsolid name`
12801321
const multiplication = 255 / ((high - low)) * slope;
12811322
const addition = (- low + intercept) / (high - low) * 255;
12821323
const data = imgData.data;
1283-
if (color == true) {
1284-
for (var i = data.length - 4; i >= 0; i -= 4) {
1285-
data[i + 0] = pixelData[i] * multiplication + addition;
1286-
data[i + 1] = pixelData[i + 1] * multiplication + addition;
1287-
data[i + 2] = pixelData[i + 2] * multiplication + addition;
1288-
}
1289-
} else {
1290-
//沒壓縮
1291-
if (step == 1) {
1292-
for (var i = 0, j = 0; i < data.length, j < pixelData.length; i += 4, j++) {
1293-
data[i + 0] = data[i + 1] = data[i + 2] = pixelData[j] * multiplication + addition;
1294-
if (data[i + 0] == 0) data[i + 3] = 0;
1295-
}
1296-
}
1297-
//有壓縮
1298-
else {
1299-
for (var i = 0, j = 0; i < data.length, j < pixelData.length; i += 4, j += step) {
1300-
data[i + 0] = data[i + 1] = data[i + 2] = pixelData[j] * multiplication + addition;
1301-
if (data[i + 0] == 0) data[i + 3] = 0;
1302-
if (j % (canvas.width * step) == 0) j += (step - 1) * canvas.width * step;
1303-
}
1304-
}
1305-
}
13061324

1307-
if (this.lut != "MIP" && this.lut != "MinIP" && this.lut != "default") {
1325+
if (this.lut == "CT") {
13081326
if (VR2_LutArray[0]) {
13091327
var lut = null;
13101328
for (var lutobj of VR2_LutArray) if (lutobj.name == this.lut) lut = lutobj;
13111329
if (lut) {
1312-
var data_ = canvas.imgData;
1313-
var arr = lut.array;
1314-
for (var i = 0, i4 = 0; i < data_.length; i++, i4 += 4) {
1315-
data_[i] = arr[data[i4]];
1330+
var colorMap = lut.array;
1331+
for (var i = 0, j = 0; i < data.length, j < pixelData.length; i += 4, j++) {
1332+
if (pixelData[j] <= -1000) data[i + 0] = data[i + 1] = data[i + 2] = data[i + 3] = 0;
1333+
else if (pixelData[j] >= 1500) data[i + 0] = data[i + 1] = data[i + 2] = data[i + 3] = 255;
1334+
else {
1335+
data[i + 0] = colorMap[pixelData[j] + 1000][0];
1336+
data[i + 1] = colorMap[pixelData[j] + 1000][1];
1337+
data[i + 2] = colorMap[pixelData[j] + 1000][2];
1338+
data[i + 3] = colorMap[pixelData[j] + 1000][3];
1339+
}
1340+
if (pixelData[j] * multiplication + addition <= 0)
1341+
data[i + 0] = data[i + 1] = data[i + 2] = data[i + 3] = 0;
1342+
}
1343+
}
1344+
}
1345+
1346+
}
1347+
else {
1348+
if (color == true) {
1349+
for (var i = data.length - 4; i >= 0; i -= 4) {
1350+
data[i + 0] = pixelData[i] * multiplication + addition;
1351+
data[i + 1] = pixelData[i + 1] * multiplication + addition;
1352+
data[i + 2] = pixelData[i + 2] * multiplication + addition;
1353+
}
1354+
} else {
1355+
//沒壓縮
1356+
if (step == 1) {
1357+
for (var i = 0, j = 0; i < data.length, j < pixelData.length; i += 4, j++) {
1358+
data[i + 0] = data[i + 1] = data[i + 2] = pixelData[j] * multiplication + addition;
1359+
if (data[i + 0] == 0) data[i + 3] = 0;
1360+
}
1361+
}
1362+
//有壓縮
1363+
else {
1364+
for (var i = 0, j = 0; i < data.length, j < pixelData.length; i += 4, j += step) {
1365+
data[i + 0] = data[i + 1] = data[i + 2] = pixelData[j] * multiplication + addition;
1366+
if (data[i + 0] == 0) data[i + 3] = 0;
1367+
if (j % (canvas.width * step) == 0) j += (step - 1) * canvas.width * step;
1368+
}
1369+
}
1370+
}
1371+
1372+
if (this.lut != "MIP" && this.lut != "MinIP" && this.lut != "default") {
1373+
if (VR2_LutArray[0]) {
1374+
var lut = null;
1375+
for (var lutobj of VR2_LutArray) if (lutobj.name == this.lut) lut = lutobj;
1376+
if (lut) {
1377+
var data_ = canvas.imgData;
1378+
var arr = lut.array;
1379+
for (var i = 0, i4 = 0; i < data_.length; i++, i4 += 4) {
1380+
data_[i] = arr[data[i4]];
1381+
}
13161382
}
13171383
}
13181384
}
13191385
}
1386+
13201387
if (this.smooth) {
13211388
for (var i = data.length - 4; i >= 0; i -= 4) {
13221389
data[i + 3] = parseInt((data[i] + data[i + 1] + data[i + 2]) / 3 * 2);

0 commit comments

Comments
 (0)