xxxxxxxxxx
64
/*jshint esversion: 11 */
class BitmapInteger
{
static get TW() { return 8; }
static get TH() { return 8; }
constructor(img)
{
this.Image = img;
this.W = img.width;
this.H = img.height;
this.Cols = Math.ceil(this.W / BitmapInteger.TW);
this.Rows = Math.ceil(this.H / BitmapInteger.TH);
this.grid = [];
for (let x = 0; x < this.Cols; ++x)
{
const col = [];
for (let y = 0; y < this.Rows; ++y)
{
const tile = new BitmapIntegerTile(this, x, y);
}
}
}
}
class BitmapIntegerTile
{
constructor(owner, tx, ty)
{
this.Owner = owner;
this.TX = tx;
this.TY = ty;
this.Value = this.ToInt();
}
ToInt()
{
let value = 0n;
let bitIndex = 0;
for (let j = 0; j < BitmapInteger.TW; ++j)
{
for (let i = 0; i < BitmapInteger.TH; ++i)
{
const x = this.TX * BitmapInteger.TW + i;
const y = this.TY * BitmapInteger.TH + j;
const p = 4 * (x + this.Owner.W * y);
const r = this.Owner.Image.pixels[p];
const bit = +(r > 0);
value |= bit << bitIndex;
++bitIndex;
}
}
}
}