1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-12-24 09:30:45 +00:00

pixeleditor: added wpimg, asset editor error msg

This commit is contained in:
Steven Hugg 2022-08-11 13:59:59 -05:00
parent 9c25eb1fe9
commit a3f2496785

View File

@ -27,22 +27,23 @@ export type SelectableTilemap = {
}
export type PixelEditorImageFormat = {
w:number
h:number
count?:number
bpp?:number
np?:number
bpw?:number
sl?:number
pofs?:number
remap?:number[]
reindex?:number[]
brev?:boolean
flip?:boolean
w:number // width
h:number // height
count?:number // # of images
bpp?:number // bits per pixel
np?:number // number of planes
bpw?:number // bits per word
sl?:number // words per line
pofs?:number // plane offset
remap?:number[] // remap array
reindex?:number[] // reindex array
brev?:boolean // bit reverse (msb is leftmost)
flip?:boolean // flip vertically
skip?:number // skip bytes
wpimg?:number // words per image
aspect?:number // aspect ratio
xform?:string // CSS transform
destfmt?:PixelEditorImageFormat
xform?:string
skip?:number
aspect?:number
};
export type PixelEditorPaletteFormat = {
@ -162,12 +163,13 @@ export function convertWordsToImages(words:UintArray, fmt:PixelEditorImageFormat
var mask = (1 << bpp)-1;
var pofs = fmt.pofs || wordsperline*height*count;
var skip = fmt.skip || 0;
var wpimg = fmt.wpimg || wordsperline*height;
var images = [];
for (var n=0; n<count; n++) {
var imgdata = [];
for (var y=0; y<height; y++) {
var yp = fmt.flip ? height-1-y : y;
var ofs0 = n*wordsperline*height + yp*wordsperline;
var ofs0 = wpimg*n + yp*wordsperline;
var shift = 0;
for (var x=0; x<width; x++) {
var color = 0;
@ -202,19 +204,22 @@ export function convertImagesToWords(images:Uint8Array[], fmt:PixelEditorImageFo
var mask = (1 << bpp)-1;
var pofs = fmt.pofs || wordsperline*height*count;
var skip = fmt.skip || 0;
var wpimg = fmt.wpimg || wordsperline*height;
var words;
if (nplanes > 0 && fmt.sl) // TODO?
words = new Uint8Array(wordsperline*height*count);
words = new Uint8Array(wpimg*count);
else if (bitsperword <= 8)
words = new Uint8Array(wordsperline*height*count*nplanes);
words = new Uint8Array(wpimg*count*nplanes);
else
words = new Uint32Array(wordsperline*height*count*nplanes);
words = new Uint32Array(wpimg*count*nplanes);
for (var n=0; n<count; n++) {
var imgdata = images[n];
var i = 0;
for (var y=0; y<height; y++) {
var yp = fmt.flip ? height-1-y : y;
var ofs0 = n*wordsperline*height + yp*wordsperline;
var ofs0 = n*wpimg + yp*wordsperline;
var shift = 0;
for (var x=0; x<width; x++) {
var color = imgdata[i++];
@ -455,7 +460,7 @@ export class TextDataNode extends CodeProjectDataNode {
}
updateLeft() {
if (this.right.words.length != this.words.length)
throw Error("Expected " + this.right.words.length + " bytes; image has " + this.words.length);
throw Error("Cannot put " + this.right.words.length + " image bytes into array of " + this.words.length + " bytes");
this.words = this.right.words;
// TODO: reload editors?
var datastr = this.text.substring(this.start, this.end);
@ -1072,7 +1077,12 @@ class PixEditor extends Viewer {
commit() {
this.updateImage();
this.left.refreshLeft();
try {
this.left.refreshLeft();
} catch (e) {
console.log(e);
alert(`Could not update source code. ${e}`);
}
}
remapPixels(mapfn : (x:number,y:number) => number) {