Sim: greyscale display now respects brightness (#1160)
* Sim: greyscale display now respects brightness * Don't overwrite image * Don't clamp if brightness is at max
This commit is contained in:
parent
d189b023af
commit
3e744b7a8d
@ -134,6 +134,7 @@ namespace pxsim.ImageMethods {
|
|||||||
let cb = getResume();
|
let cb = getResume();
|
||||||
let first = true;
|
let first = true;
|
||||||
|
|
||||||
|
leds = clampPixelBrightness(leds);
|
||||||
board().ledMatrixState.animationQ.enqueue({
|
board().ledMatrixState.animationQ.enqueue({
|
||||||
interval,
|
interval,
|
||||||
frame: () => {
|
frame: () => {
|
||||||
@ -151,6 +152,7 @@ namespace pxsim.ImageMethods {
|
|||||||
export function plotImage(leds: Image, offset: number): void {
|
export function plotImage(leds: Image, offset: number): void {
|
||||||
pxtrt.nullCheck(leds)
|
pxtrt.nullCheck(leds)
|
||||||
|
|
||||||
|
leds = clampPixelBrightness(leds);
|
||||||
board().ledMatrixState.animationQ.enqueue({
|
board().ledMatrixState.animationQ.enqueue({
|
||||||
interval: 0,
|
interval: 0,
|
||||||
frame: () => {
|
frame: () => {
|
||||||
@ -211,6 +213,7 @@ namespace pxsim.ImageMethods {
|
|||||||
let off = stride > 0 ? 0 : leds.width - 1;
|
let off = stride > 0 ? 0 : leds.width - 1;
|
||||||
let display = board().ledMatrixState.image;
|
let display = board().ledMatrixState.image;
|
||||||
|
|
||||||
|
leds = clampPixelBrightness(leds);
|
||||||
board().ledMatrixState.animationQ.enqueue({
|
board().ledMatrixState.animationQ.enqueue({
|
||||||
interval: interval,
|
interval: interval,
|
||||||
frame: () => {
|
frame: () => {
|
||||||
@ -230,6 +233,22 @@ namespace pxsim.ImageMethods {
|
|||||||
whenDone: cb
|
whenDone: cb
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clampPixelBrightness(img: Image): Image {
|
||||||
|
let res = img;
|
||||||
|
if (led.displayMode() === DisplayMode.greyscale && led.brightness() < 0xff) {
|
||||||
|
res = new Image(img.width, img.data);
|
||||||
|
const b = led.brightness();
|
||||||
|
for (let x = 0; x < res.width; ++x) {
|
||||||
|
for (let y = 0; y < 5; ++y) {
|
||||||
|
if (pixelBrightness(res, x, y) > b) {
|
||||||
|
setPixelBrightness(res, x, y, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace pxsim.basic {
|
namespace pxsim.basic {
|
||||||
@ -280,7 +299,7 @@ namespace pxsim.led {
|
|||||||
|
|
||||||
export function plotBrightness(x: number, y: number, brightness: number) {
|
export function plotBrightness(x: number, y: number, brightness: number) {
|
||||||
const state = board().ledMatrixState;
|
const state = board().ledMatrixState;
|
||||||
brightness = Math.max(0, Math.min(0xff, brightness));
|
brightness = Math.max(0, Math.min(led.brightness(), brightness));
|
||||||
if (brightness != 0 && brightness != 0xff && state.displayMode != DisplayMode.greyscale)
|
if (brightness != 0 && brightness != 0xff && state.displayMode != DisplayMode.greyscale)
|
||||||
state.displayMode = DisplayMode.greyscale;
|
state.displayMode = DisplayMode.greyscale;
|
||||||
state.image.set(x, y, brightness);
|
state.image.set(x, y, brightness);
|
||||||
|
Loading…
Reference in New Issue
Block a user