From 64a1c071343786dfbe6966f124c217a53edd6a8c Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Mon, 22 Jan 2018 20:23:10 +0000 Subject: [PATCH 1/2] Temp commit --- index.html | 5 +---- package.json | 2 +- src/actionlist.ts | 12 ++++++++++++ src/actionnode.ts | 15 +++++++++++++++ src/bmptools.ts | 2 -- src/editor.ts | 6 +++--- src/linkedlist.ts | 31 +++++++++++++++++++++++++++++++ src/linkednode.ts | 34 ++++++++++++++++++++++++++++++++++ src/main.ts | 2 +- 9 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 src/actionlist.ts create mode 100644 src/actionnode.ts create mode 100644 src/linkedlist.ts create mode 100644 src/linkednode.ts diff --git a/index.html b/index.html index d826544..edf1e4b 100644 --- a/index.html +++ b/index.html @@ -4,10 +4,7 @@ BittMapp - - - - +
diff --git a/package.json b/package.json index 4dbb7d3..97a6d41 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "description": "BittMapp - A monochrome bitmap editor", "scripts": { - "build": "tslint -c tslint.json \"src/**/*.ts\" && tsc" + "build": "rm static/js/*.js && tslint -c tslint.json \"src/**/*.ts\" && tsc && cat static/js/*.js > static/js/dist.js" }, "author": "Nathan Kunicki ", "license": "MIT", diff --git a/src/actionlist.ts b/src/actionlist.ts new file mode 100644 index 0000000..6299a6a --- /dev/null +++ b/src/actionlist.ts @@ -0,0 +1,12 @@ +class ActionList extends LinkedList { + + + private _current: ActionNode; + + + public push (node: LinkedNode): void { + // super(node); + } + + +} diff --git a/src/actionnode.ts b/src/actionnode.ts new file mode 100644 index 0000000..1bb29ad --- /dev/null +++ b/src/actionnode.ts @@ -0,0 +1,15 @@ +class ActionNode extends LinkedNode { + + + public undo: () => void; + public redo: () => void; + + + constructor (undo: () => void, redo: () => void) { + super(); + this.undo = undo; + this.redo = redo; + } + + +} diff --git a/src/bmptools.ts b/src/bmptools.ts index 547595f..7a81df3 100644 --- a/src/bmptools.ts +++ b/src/bmptools.ts @@ -15,11 +15,9 @@ interface IBMPHeaderData { interface IBittMappData { - data: Uint8Array; width: number; height: number; - } diff --git a/src/editor.ts b/src/editor.ts index 5b7373d..1c20130 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -1,4 +1,4 @@ -interface IBittMappEditorConstructorOptions { +interface IEditorConstructorOptions { canvas: HTMLCanvasElement; canvasWidth: number; canvasHeight: number; @@ -20,7 +20,7 @@ enum Mode { } -class BittMappEditor { +class Editor { public canvasWidth: number; @@ -55,7 +55,7 @@ class BittMappEditor { private _selection: Uint8Array; - constructor (options: IBittMappEditorConstructorOptions) { + constructor (options: IEditorConstructorOptions) { options = options || {}; diff --git a/src/linkedlist.ts b/src/linkedlist.ts new file mode 100644 index 0000000..284724b --- /dev/null +++ b/src/linkedlist.ts @@ -0,0 +1,31 @@ +class LinkedList { + + + private _start: LinkedNode; + private _end: LinkedNode; + + public push (node: LinkedNode): void { + + if (!this._start) { + this._start = node; + this._end = node; + return; + } + + this._end.next = node; + this._end = node; + + } + + public pop (): LinkedNode | null { + if (!this._end) { + return null; + } + + const node: LinkedNode = this._end; + this._end = this._end.prev; + return node; + + } + +} diff --git a/src/linkednode.ts b/src/linkednode.ts new file mode 100644 index 0000000..6e8ab58 --- /dev/null +++ b/src/linkednode.ts @@ -0,0 +1,34 @@ +class LinkedNode { + + + private _prev: LinkedNode; + private _next: LinkedNode; + + + get next (): LinkedNode { + return this._next; + } + + + set next (node: LinkedNode) { + this._next = node; + if (node.prev !== this) { + node.prev = this; + } + } + + + get prev (): LinkedNode { + return this._prev; + } + + + set prev (node: LinkedNode) { + this._prev = node; + if (node.next !== this) { + node.next = this; + } + } + + +} diff --git a/src/main.ts b/src/main.ts index 3966cc9..3a79626 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,6 @@ window.onload = (): void => { - const editor: BittMappEditor = new BittMappEditor({ + const editor: Editor = new Editor({ canvas: document.getElementById("editor") as HTMLCanvasElement, canvasHeight: 480, canvasWidth: 480, From 43d1fe7cb59d1bfcd402fd518fb5c403c072a35c Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Tue, 23 Jan 2018 09:28:55 +0000 Subject: [PATCH 2/2] Working bmp reading --- package.json | 2 +- src/bmptools.ts | 30 ++++++++---------------------- src/serialisers.ts | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 97a6d41..d7fb0fb 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "description": "BittMapp - A monochrome bitmap editor", "scripts": { - "build": "rm static/js/*.js && tslint -c tslint.json \"src/**/*.ts\" && tsc && cat static/js/*.js > static/js/dist.js" + "build": "rm -rf static/js/*.js && tslint -c tslint.json \"src/**/*.ts\" && tsc && cat static/js/*.js > static/js/dist.js" }, "author": "Nathan Kunicki ", "license": "MIT", diff --git a/src/bmptools.ts b/src/bmptools.ts index 7a81df3..7b69571 100644 --- a/src/bmptools.ts +++ b/src/bmptools.ts @@ -42,32 +42,14 @@ class BMPTools { const inputByte: number = Math.floor(x / 8); const outputByte: number = Math.floor((((headerData.height - 1 - y) * headerData.width) + x) / 8); const inputMask: number = 1 << (x % 8); - const outputMask: number = 1 << (bitCount % 8); - const val: number = pixelData[rowStart + inputByte] & inputMask; - // console.log(val); + const val: number = Serialisers.reverseUint32BitOrder(~pixelData[rowStart + inputByte] & inputMask) >> 24; outputData[outputByte] = val + outputData[outputByte]; - // console.log((rowStart + inputByte), inputMask, outputByte, outputMask); bitCount++; } } - } /* else { - let bitCount: number = 0; - for (let y: number = 0; y < headerData.height; y++) { - const rowStart: number = rowSize * y; - console.log(pixelData[rowStart], pixelData[rowStart + 1], pixelData[rowStart + 2], pixelData[rowStart + 3]); - for (let x: number = 0; x < headerData.width; x++) { - const inputByte: number = Math.floor(x / 8); - const outputByte: number = Math.floor(((y * headerData.width) + x) / 8); - const inputMask: number = 1 << (x % 8); - const outputMask: number = 1 << (bitCount % 8); - let val: number = pixelData[rowStart + inputByte]; - console.log(val); - //outputData[outputByte] = val |= outputMask; - console.log((rowStart + inputByte), inputMask, outputByte, outputMask); - bitCount++; - } - } - }*/ + } else { + throw new Error("Cannot read bitmaps of inverted height"); + } return { data: outputData, @@ -99,6 +81,10 @@ class BMPTools { headerData.headerLength = Serialisers.readUint32(inputData, 14, true); headerData.width = Serialisers.readUint32(inputData, 18, true); headerData.height = Serialisers.readInt32(inputData, 22, true); + if (headerData.height <= 0) { + throw new Error("Cannot read bitmaps of inverted height"); + } + headerData.planes = Serialisers.readUint16(inputData, 26, true); if (headerData.planes !== 1) { throw new Error("Data not valid (Only one plane supported)"); diff --git a/src/serialisers.ts b/src/serialisers.ts index 294a5e2..ec33124 100644 --- a/src/serialisers.ts +++ b/src/serialisers.ts @@ -18,4 +18,20 @@ class Serialisers { return new DataView(data.buffer).getUint16(start, littleEndian); } + + public static reverseUint32BitOrder(data: number): number { + let i: number = 0; + let reversed: number = 0; + let last: number = 0; + while (i < 31) { + last = data & 1; + data >>= 1; + reversed += last; + reversed <<= 1; + i++; + } + return reversed; + } + + }