Fixed merge
This commit is contained in:
commit
69d20601bf
@ -4,10 +4,7 @@
|
|||||||
<title>BittMapp</title>
|
<title>BittMapp</title>
|
||||||
<link rel="stylesheet" href="./static/css/reset.css" />
|
<link rel="stylesheet" href="./static/css/reset.css" />
|
||||||
<link rel="stylesheet" href="./static/css/styles.css" />
|
<link rel="stylesheet" href="./static/css/styles.css" />
|
||||||
<script src="./static/js/serialisers.js"></script>
|
<script src="./static/js/dist.js"></script>
|
||||||
<script src="./static/js/bmptools.js"></script>
|
|
||||||
<script src="./static/js/editor.js"></script>
|
|
||||||
<script src="./static/js/main.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "BittMapp - A monochrome bitmap editor",
|
"description": "BittMapp - A monochrome bitmap editor",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tslint -c tslint.json \"src/**/*.ts\" && tsc"
|
"build": "rm -rf static/js/*.js && tslint -c tslint.json \"src/**/*.ts\" && tsc && cat static/js/*.js > static/js/dist.js"
|
||||||
},
|
},
|
||||||
"author": "Nathan Kunicki <me@nathankunicki.com>",
|
"author": "Nathan Kunicki <me@nathankunicki.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -15,11 +15,9 @@ interface IBMPHeaderData {
|
|||||||
|
|
||||||
|
|
||||||
interface IBittMappData {
|
interface IBittMappData {
|
||||||
|
|
||||||
data: Uint8Array;
|
data: Uint8Array;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -44,32 +42,14 @@ class BMPTools {
|
|||||||
const inputByte: number = Math.floor(x / 8);
|
const inputByte: number = Math.floor(x / 8);
|
||||||
const outputByte: number = Math.floor((((headerData.height - 1 - y) * headerData.width) + x) / 8);
|
const outputByte: number = Math.floor((((headerData.height - 1 - y) * headerData.width) + x) / 8);
|
||||||
const inputMask: number = 1 << (x % 8);
|
const inputMask: number = 1 << (x % 8);
|
||||||
const outputMask: number = 1 << (bitCount % 8);
|
const val: number = Serialisers.reverseUint32BitOrder(~pixelData[rowStart + inputByte] & inputMask) >> 24;
|
||||||
const val: number = pixelData[rowStart + inputByte] & inputMask;
|
|
||||||
// console.log(val);
|
|
||||||
outputData[outputByte] = val + outputData[outputByte];
|
outputData[outputByte] = val + outputData[outputByte];
|
||||||
// console.log((rowStart + inputByte), inputMask, outputByte, outputMask);
|
|
||||||
bitCount++;
|
bitCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* else {
|
} else {
|
||||||
let bitCount: number = 0;
|
throw new Error("Cannot read bitmaps of inverted height");
|
||||||
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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: outputData,
|
data: outputData,
|
||||||
@ -101,6 +81,10 @@ class BMPTools {
|
|||||||
headerData.headerLength = Serialisers.readUint32(inputData, 14, true);
|
headerData.headerLength = Serialisers.readUint32(inputData, 14, true);
|
||||||
headerData.width = Serialisers.readUint32(inputData, 18, true);
|
headerData.width = Serialisers.readUint32(inputData, 18, true);
|
||||||
headerData.height = Serialisers.readInt32(inputData, 22, 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);
|
headerData.planes = Serialisers.readUint16(inputData, 26, true);
|
||||||
if (headerData.planes !== 1) {
|
if (headerData.planes !== 1) {
|
||||||
throw new Error("Data not valid (Only one plane supported)");
|
throw new Error("Data not valid (Only one plane supported)");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
interface IBittMappEditorConstructorOptions {
|
interface IEditorConstructorOptions {
|
||||||
canvas: HTMLCanvasElement;
|
canvas: HTMLCanvasElement;
|
||||||
canvasWidth: number;
|
canvasWidth: number;
|
||||||
canvasHeight: number;
|
canvasHeight: number;
|
||||||
@ -20,7 +20,7 @@ enum Mode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class BittMappEditor {
|
class Editor {
|
||||||
|
|
||||||
|
|
||||||
public canvasWidth: number;
|
public canvasWidth: number;
|
||||||
@ -55,7 +55,7 @@ class BittMappEditor {
|
|||||||
private _selection: Uint8Array;
|
private _selection: Uint8Array;
|
||||||
|
|
||||||
|
|
||||||
constructor (options: IBittMappEditorConstructorOptions) {
|
constructor (options: IEditorConstructorOptions) {
|
||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
31
src/linkedlist.ts
Normal file
31
src/linkedlist.ts
Normal file
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
34
src/linkednode.ts
Normal file
34
src/linkednode.ts
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
window.onload = (): void => {
|
window.onload = (): void => {
|
||||||
|
|
||||||
const editor: BittMappEditor = new BittMappEditor({
|
const editor: Editor = new Editor({
|
||||||
canvas: document.getElementById("editor") as HTMLCanvasElement,
|
canvas: document.getElementById("editor") as HTMLCanvasElement,
|
||||||
canvasHeight: 480,
|
canvasHeight: 480,
|
||||||
canvasWidth: 480,
|
canvasWidth: 480,
|
||||||
|
@ -18,4 +18,20 @@ class Serialisers {
|
|||||||
return new DataView(data.buffer).getUint16(start, littleEndian);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user