Make Image ref-counted; fixes #171
This commit is contained in:
parent
b6fed71c58
commit
538f08052d
17
sim/state.ts
17
sim/state.ts
@ -470,7 +470,7 @@ namespace pxsim {
|
|||||||
radio: RadioBus;
|
radio: RadioBus;
|
||||||
|
|
||||||
// display
|
// display
|
||||||
image = createImage(5);
|
image = createInternalImage(5);
|
||||||
brigthness = 255;
|
brigthness = 255;
|
||||||
displayMode = DisplayMode.bw;
|
displayMode = DisplayMode.bw;
|
||||||
font: Image = createFont();
|
font: Image = createFont();
|
||||||
@ -608,14 +608,19 @@ namespace pxsim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Image {
|
export class Image extends RefObject {
|
||||||
public static height: number = 5;
|
public static height: number = 5;
|
||||||
public width: number;
|
public width: number;
|
||||||
public data: number[];
|
public data: number[];
|
||||||
constructor(width: number, data: number[]) {
|
constructor(width: number, data: number[]) {
|
||||||
|
super()
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public print() {
|
||||||
|
console.log(`Image id:${this.id} refs:${this.refcnt} size:${this.width}x${Image.height}`)
|
||||||
|
}
|
||||||
public get(x: number, y: number): number {
|
public get(x: number, y: number): number {
|
||||||
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
|
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
|
||||||
return this.data[y * this.width + x];
|
return this.data[y * this.width + x];
|
||||||
@ -650,6 +655,12 @@ namespace pxsim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createInternalImage(width: number): Image {
|
||||||
|
let img = createImage(width)
|
||||||
|
pxsim.noLeakTracking(img)
|
||||||
|
return img
|
||||||
|
}
|
||||||
|
|
||||||
export function createImage(width: number): Image {
|
export function createImage(width: number): Image {
|
||||||
return new Image(width, new Array(width * 5));
|
return new Image(width, new Array(width * 5));
|
||||||
}
|
}
|
||||||
@ -685,7 +696,7 @@ namespace pxsim {
|
|||||||
|
|
||||||
let nb = data.length;
|
let nb = data.length;
|
||||||
let n = nb / 5;
|
let n = nb / 5;
|
||||||
let font = createImage(nb);
|
let font = createInternalImage(nb);
|
||||||
for (let c = 0; c < n; c++) {
|
for (let c = 0; c < n; c++) {
|
||||||
for (let row = 0; row < 5; row++) {
|
for (let row = 0; row < 5; row++) {
|
||||||
let char = data[c * 5 + row];
|
let char = data[c * 5 + row];
|
||||||
|
Loading…
Reference in New Issue
Block a user