From 410841562a31142fd65eb1b6dc0594624c0d0cfe Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 26 Sep 2022 03:27:58 +0100 Subject: [PATCH] img2brush: allow customising the channel to pull from --- .docs/img2brush/img2brush.js | 23 +++++++++++++++++++++-- .docs/img2brush/index.html | 12 +++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/.docs/img2brush/img2brush.js b/.docs/img2brush/img2brush.js index ccbea47..5a9f487 100644 --- a/.docs/img2brush/img2brush.js +++ b/.docs/img2brush/img2brush.js @@ -13,6 +13,23 @@ window.addEventListener("load", () => { }) }); +function get_source_channel_offset() { + const select = document.querySelector("#img2brush-channel"); + console.info(`get_source_channel_offset: channel is ${select.value}`) + switch(select.value) { + case "alpha": + return 3; + case "red": + return 0; + case "green": + return 1; + case "blue": + return 2; + default: + throw new Error(`Error : Unknown channel name ${select.value}.`); + } +} + function select_output() { let output = document.querySelector("#brushimg-tsv"); @@ -26,7 +43,6 @@ function select_output() { selection.addRange(range); } - function handle_drag_enter(event) { event.target.classList.add("dropzone-active"); } @@ -80,12 +96,15 @@ function handle_new_image(image) { } function pixels2tsv(pixels) { + const offset = get_source_channel_offset(); + console.info(`pixels2tsv: offset is ${offset}`); let result = ""; for(let y = 0; y < pixels.height; y++) { let row = []; for(let x = 0; x < pixels.width; x++) { // No need to rescale here - this is done automagically by WorldEditAdditions. - row.push(pixels.data[((y*pixels.width + x) * 4) + 3] / 255); + // r/b/g/alpha + row.push(pixels.data[((y*pixels.width + x) * 4) + offset] / 255); } result += row.join(`\t`) + `\n`; } diff --git a/.docs/img2brush/index.html b/.docs/img2brush/index.html index 4e68b2e..ce14662 100644 --- a/.docs/img2brush/index.html +++ b/.docs/img2brush/index.html @@ -6,7 +6,17 @@ title: Image to brush converter

Image to sculpting brush converter

-

Convert any image to a sculpting brush here! The alpha (opacity) channel is used to determine the weight of the brush - all colour is ignored.

+

Convert any image to a sculpting brush here!

+

+ Use this channel to convert: + +

+

Only the selected channel is used to determine the weight of the brush - all other channels are ignored! Change the channel option before you drag + drop the image onto this page.