color fixing measures when alpha is missing

dependencies hashes:
openFrameworks d78075f4bca6be2a2533c6e51a75cc1f18404501
ofxMsdfgen e14da13d02c4dff04fb69d7923469f606924e6c3
ofxGPUFont d482bb7cbdf6b296fa4ab5abcf73fb5ff8c8b239
ofxVariableLab 0b5f9bdebc1e5550621957e73c040c258ec6317b
ofxProfiler a868e34fa1a79189dd4fbdede2938e308535e5e8
theatre 86d3e07f6f2c75fd6e08fca8c97e3617c9e23b18
This commit is contained in:
themancalledjakob 2024-04-01 17:18:28 +02:00
parent d7ac9e834d
commit 996ad358e7
2 changed files with 31 additions and 4 deletions

View file

@ -131,14 +131,39 @@ const Audio = function(tp, record) {
}
};
const fixColor = (color) => {
if (typeof color === 'object') {
const channels = Object.keys(color);
channels.forEach((channel) => {
if (typeof color[channel] !== 'number') {
console.log('Audio::fixColor', `fixing color.${channel} => 1`);
color[channel] = 1;
}
});
}
};
const getAudioMappingOptions = (layer, propTitle) => {
if (savedMapping.hasOwnProperty(layer.id()) && savedMapping[layer.id()].hasOwnProperty(propTitle)) {
if (tp.isSequenced(propTitle, layer)) {
const m = clone(savedMapping[layer.id()][propTitle]);
delete m.letterDelay;
if (propTitle.toLowerCase().indexOf('color') >= 0) {
// fix missing alpha in color
fixColor(m.min_out);
fixColor(m.max_out);
fixColor(m.value);
}
return m;
}
return savedMapping[layer.id()][propTitle];
const m = savedMapping[layer.id()][propTitle];
if (propTitle.toLowerCase().indexOf('color') >= 0) {
// fix missing alpha in color
fixColor(m.min_out);
fixColor(m.max_out);
fixColor(m.value);
}
return m;
} else {
const o = new AudioMappingOptions();
const mm = getDefaultRange(layer, propTitle);
@ -390,7 +415,7 @@ const Audio = function(tp, record) {
});
picker.onChange = (color) => {
min_preview.style.background = color.rgbaString;
min_inputDom.value = color.hex;
min_inputDom.value = color.hex.padEnd(9, 'f');
updateMappingOptions();
//mappingOptions.min_out = {
//r: color.rgba[0] / 255,

View file

@ -515,8 +515,10 @@ const rgbaToHexa = (rgba) => {
};
// NOTE: all output values are range 0-1
const hexaToRgba = (hexa) => {
const o = hexa[0] === '#' ? 1 : 0;
const hexaToRgba = (hex_a) => {
const o = hex_a[0] === '#' ? 1 : 0;
// if it is hex, we need to add alpha
const hexa = hex_a.padEnd(8 + o, 'F');
return {
r: parseInt(hexa.slice(o + 0, o + 2), 16) / 255,
g: parseInt(hexa.slice(o + 2, o + 4), 16) / 255,