mirror of
https://github.com/billsonnn/nitro-converter.git
synced 2024-11-26 17:30:52 +01:00
Fix some ESLint errors
This commit is contained in:
parent
bfe731d286
commit
15d99a58fa
39
error.log
39
error.log
@ -0,0 +1,39 @@
|
|||||||
|
TypeError: NitroBundle_1.default is not a constructor
|
||||||
|
TypeError: NitroBundle_1.default is not a constructor
|
||||||
|
TypeError: NitroBundle_1.default is not a constructor
|
||||||
|
TypeError: NitroBundle_1.default is not a constructor
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
||||||
|
TypeError: zlib_1.gzip.__promisify__ is not a function
|
@ -10,7 +10,7 @@ import { AssetMapper, IndexMapper, LogicMapper, VisualizationMapper } from '../.
|
|||||||
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
||||||
import File from '../../utils/File';
|
import File from '../../utils/File';
|
||||||
import Logger from '../../utils/Logger';
|
import Logger from '../../utils/Logger';
|
||||||
import NitroBundle from '../../utils/NitroBundle';
|
import { NitroBundle } from '../../utils/NitroBundle';
|
||||||
import { FurnitureDownloader } from './FurnitureDownloader';
|
import { FurnitureDownloader } from './FurnitureDownloader';
|
||||||
|
|
||||||
@singleton()
|
@singleton()
|
||||||
|
@ -10,7 +10,7 @@ import { AssetMapper, IndexMapper, LogicMapper, VisualizationMapper } from '../.
|
|||||||
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
import { HabboAssetSWF } from '../../swf/HabboAssetSWF';
|
||||||
import File from '../../utils/File';
|
import File from '../../utils/File';
|
||||||
import Logger from '../../utils/Logger';
|
import Logger from '../../utils/Logger';
|
||||||
import NitroBundle from '../../utils/NitroBundle';
|
import { NitroBundle } from '../../utils/NitroBundle';
|
||||||
import { PetDownloader } from './PetDownloader';
|
import { PetDownloader } from './PetDownloader';
|
||||||
|
|
||||||
@singleton()
|
@singleton()
|
||||||
|
@ -313,7 +313,7 @@ export class VisualizationMapper extends Mapper
|
|||||||
{
|
{
|
||||||
if(!xml || !xml.length) return;
|
if(!xml || !xml.length) return;
|
||||||
|
|
||||||
let i = 0;
|
const i = 0;
|
||||||
|
|
||||||
for(const offsetXML of xml)
|
for(const offsetXML of xml)
|
||||||
{
|
{
|
||||||
|
@ -49,13 +49,13 @@ export class FurnitureTypeXML
|
|||||||
|
|
||||||
if(xml.partcolors)
|
if(xml.partcolors)
|
||||||
{
|
{
|
||||||
for(let key in xml.partcolors)
|
for(const key in xml.partcolors)
|
||||||
{
|
{
|
||||||
const colorData = xml.partcolors[key].color;
|
const colorData = xml.partcolors[key].color;
|
||||||
|
|
||||||
if(colorData)
|
if(colorData)
|
||||||
{
|
{
|
||||||
for(let color of colorData)
|
for(const color of colorData)
|
||||||
{
|
{
|
||||||
let code = color;
|
let code = color;
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ export class HabboAssetSWF
|
|||||||
console.log(tag);
|
console.log(tag);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 35:
|
case 35: {
|
||||||
const jpegTag: any = await readImagesJPEG(35, tag);
|
const jpegTag = await readImagesJPEG(35, tag);
|
||||||
this._tags.push(new ImageTag({
|
this._tags.push(new ImageTag({
|
||||||
code: jpegTag.code,
|
code: jpegTag.code,
|
||||||
characterID: jpegTag.characterId,
|
characterID: jpegTag.characterId,
|
||||||
@ -52,8 +52,9 @@ export class HabboAssetSWF
|
|||||||
bitmapHeight: jpegTag.bitmapHeight
|
bitmapHeight: jpegTag.bitmapHeight
|
||||||
}));
|
}));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 36:
|
case 36: {
|
||||||
const pngTag: any = await readImagesDefineBitsLossless(tag);
|
const pngTag: any = await readImagesDefineBitsLossless(tag);
|
||||||
this._tags.push(new ImageTag({
|
this._tags.push(new ImageTag({
|
||||||
code: pngTag.code,
|
code: pngTag.code,
|
||||||
@ -64,6 +65,7 @@ export class HabboAssetSWF
|
|||||||
bitmapHeight: pngTag.bitmapHeight
|
bitmapHeight: pngTag.bitmapHeight
|
||||||
}));
|
}));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 20:
|
case 20:
|
||||||
console.log(tag);
|
console.log(tag);
|
||||||
@ -103,9 +105,11 @@ export class HabboAssetSWF
|
|||||||
|
|
||||||
let iterator: CustomIterator<ITag> = new CustomIterator(this._tags);
|
let iterator: CustomIterator<ITag> = new CustomIterator(this._tags);
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-constant-condition
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
let t: ITag;
|
let t: ITag;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(!iterator.hasNext())
|
if(!iterator.hasNext())
|
||||||
@ -184,6 +188,7 @@ export class HabboAssetSWF
|
|||||||
|
|
||||||
const iterator: CustomIterator<ITag> = new CustomIterator(this._tags);
|
const iterator: CustomIterator<ITag> = new CustomIterator(this._tags);
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-constant-condition
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
let t: ITag;
|
let t: ITag;
|
||||||
|
@ -39,6 +39,7 @@ export default class CustomIterator<TType>
|
|||||||
typeof candidate === 'object' &&
|
typeof candidate === 'object' &&
|
||||||
typeof candidate.length === 'number' &&
|
typeof candidate.length === 'number' &&
|
||||||
typeof candidate.splice === 'function' &&
|
typeof candidate.splice === 'function' &&
|
||||||
|
// eslint-disable-next-line no-prototype-builtins
|
||||||
!(candidate.propertyIsEnumerable('length'));
|
!(candidate.propertyIsEnumerable('length'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import { RmOptions } from 'fs';
|
import { existsSync, lstatSync, mkdirSync, readdirSync, RmOptions, rmSync } from 'fs';
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
export default class File
|
export default class File
|
||||||
{
|
{
|
||||||
@ -14,24 +12,24 @@ export default class File
|
|||||||
|
|
||||||
public exists(): boolean
|
public exists(): boolean
|
||||||
{
|
{
|
||||||
return fs.existsSync(this._path);
|
return existsSync(this._path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public mkdirs(): void
|
public mkdirs(): void
|
||||||
{
|
{
|
||||||
return fs.mkdirSync(this._path);
|
return mkdirSync(this._path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public list(): string[]
|
public list(): string[]
|
||||||
{
|
{
|
||||||
const test = fs.readdirSync(this._path);
|
const test = readdirSync(this._path);
|
||||||
|
|
||||||
return test;
|
return test;
|
||||||
}
|
}
|
||||||
|
|
||||||
public isDirectory(): boolean
|
public isDirectory(): boolean
|
||||||
{
|
{
|
||||||
return this.exists() && fs.lstatSync(this._path).isDirectory();
|
return this.exists() && lstatSync(this._path).isDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
get path(): string
|
get path(): string
|
||||||
@ -41,6 +39,6 @@ export default class File
|
|||||||
|
|
||||||
public rmdir(options: RmOptions): void
|
public rmdir(options: RmOptions): void
|
||||||
{
|
{
|
||||||
return fs.rmSync(this._path, options);
|
return rmSync(this._path, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,22 @@
|
|||||||
|
import { createWriteStream, existsSync } from 'fs';
|
||||||
|
import { appendFile } from 'fs/promises';
|
||||||
import { singleton } from 'tsyringe';
|
import { singleton } from 'tsyringe';
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const fsAsync = require('fs/promises');
|
|
||||||
|
|
||||||
@singleton()
|
@singleton()
|
||||||
export default class Logger
|
export default class Logger
|
||||||
{
|
{
|
||||||
|
|
||||||
constructor()
|
constructor()
|
||||||
{
|
{
|
||||||
if(!fs.existsSync('error.log'))
|
if(!existsSync('error.log'))
|
||||||
{
|
{
|
||||||
const createStream = fs.createWriteStream('error.log');
|
const createStream = createWriteStream('error.log');
|
||||||
createStream.end();
|
createStream.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public logErrorAsync(message: string): Promise<void>
|
public logErrorAsync(message: string): Promise<void>
|
||||||
{
|
{
|
||||||
return fsAsync.appendFile('error.log', message + '\n');
|
return appendFile('error.log', message + '\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
const ByteBuffer = require('bytebuffer');
|
import * as ByteBuffer from 'bytebuffer';
|
||||||
const { gzip } = require('node-gzip');
|
import { gzip } from 'zlib';
|
||||||
|
|
||||||
export default class NitroBundle
|
export class NitroBundle
|
||||||
{
|
{
|
||||||
private readonly _files: Map<string, Buffer>;
|
private readonly _files: Map<string, Buffer>;
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ export default class NitroBundle
|
|||||||
{
|
{
|
||||||
const buffer = new ByteBuffer();
|
const buffer = new ByteBuffer();
|
||||||
|
|
||||||
buffer.writeUInt16(this._files.size);
|
buffer.writeUint16(this._files.size);
|
||||||
|
|
||||||
const iterator = this._files.entries();
|
const iterator = this._files.entries();
|
||||||
let result: IteratorResult<[string, Buffer]> = iterator.next();
|
let result: IteratorResult<[string, Buffer]> = iterator.next();
|
||||||
@ -31,7 +31,7 @@ export default class NitroBundle
|
|||||||
buffer.writeUint16(fileName.length);
|
buffer.writeUint16(fileName.length);
|
||||||
buffer.writeString(fileName);
|
buffer.writeString(fileName);
|
||||||
|
|
||||||
const compressed = await gzip(file);
|
const compressed = await gzip.__promisify__(file);
|
||||||
buffer.writeUint32(compressed.length);
|
buffer.writeUint32(compressed.length);
|
||||||
buffer.append(compressed);
|
buffer.append(compressed);
|
||||||
|
|
||||||
|
@ -20,7 +20,8 @@ const _decoder = require('jpg-stream/decoder');
|
|||||||
|
|
||||||
const _decoder2 = _interopRequireDefault(_decoder);
|
const _decoder2 = _interopRequireDefault(_decoder);
|
||||||
|
|
||||||
function _interopRequireDefault(obj: any) {
|
function _interopRequireDefault(obj: any)
|
||||||
|
{
|
||||||
return obj && obj.__esModule ? obj : { default: obj };
|
return obj && obj.__esModule ? obj : { default: obj };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,45 +29,66 @@ const _concatFrames = require('concat-frames');
|
|||||||
|
|
||||||
const _concatFrames2 = _interopRequireDefault(_concatFrames);
|
const _concatFrames2 = _interopRequireDefault(_concatFrames);
|
||||||
|
|
||||||
const _slicedToArray = function () {
|
const _slicedToArray = function ()
|
||||||
function sliceIterator(arr: any, i: any) {
|
{
|
||||||
var _arr = [];
|
function sliceIterator(arr: any, i: any)
|
||||||
var _n = true;
|
{
|
||||||
var _d = false;
|
const _arr = [];
|
||||||
var _e = undefined;
|
let _n = true;
|
||||||
try {
|
let _d = false;
|
||||||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
let _e = undefined;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for(var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true)
|
||||||
|
{
|
||||||
_arr.push(_s.value);
|
_arr.push(_s.value);
|
||||||
if(i && _arr.length === i) break;
|
if(i && _arr.length === i) break;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
}
|
||||||
|
catch (err)
|
||||||
|
{
|
||||||
_d = true;
|
_d = true;
|
||||||
_e = err;
|
_e = err;
|
||||||
} finally {
|
}
|
||||||
try {
|
finally
|
||||||
if (!_n && _i["return"]) _i["return"]();
|
{
|
||||||
} finally {
|
try
|
||||||
|
{
|
||||||
|
if(!_n && _i['return']) _i['return']();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
if(_d) throw _e;
|
if(_d) throw _e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _arr;
|
return _arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return function (arr: any, i: any) {
|
return function (arr: any, i: any)
|
||||||
if (Array.isArray(arr)) {
|
{
|
||||||
|
if(Array.isArray(arr))
|
||||||
|
{
|
||||||
return arr;
|
return arr;
|
||||||
} else if (Symbol.iterator in Object(arr)) {
|
}
|
||||||
|
else if(Symbol.iterator in Object(arr))
|
||||||
|
{
|
||||||
return sliceIterator(arr, i);
|
return sliceIterator(arr, i);
|
||||||
} else {
|
}
|
||||||
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
else
|
||||||
|
{
|
||||||
|
throw new TypeError('Invalid attempt to destructure non-iterable instance');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}();
|
}();
|
||||||
|
|
||||||
export function readSwfAsync(data: string | Buffer): Promise<any> {
|
export function readSwfAsync(data: string | Buffer): Promise<any>
|
||||||
return new Promise<any>(((resolve, reject) => {
|
{
|
||||||
SWFReader.read(data, function (err: Error, swf: any) {
|
return new Promise<any>(((resolve, reject) =>
|
||||||
if (err) {
|
{
|
||||||
|
SWFReader.read(data, function (err: Error, swf: any)
|
||||||
|
{
|
||||||
|
if(err)
|
||||||
|
{
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
resolve(swf);
|
resolve(swf);
|
||||||
@ -76,18 +98,21 @@ export function readSwfAsync(data: string | Buffer): Promise<any> {
|
|||||||
|
|
||||||
const pngMagic = Buffer.from('0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A'.split(' ').map(Number));
|
const pngMagic = Buffer.from('0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A'.split(' ').map(Number));
|
||||||
const gifMagic = Buffer.from('0x47 0x49 0x46 0x38 0x39 0x61'.split(' ').map(Number));
|
const gifMagic = Buffer.from('0x47 0x49 0x46 0x38 0x39 0x61'.split(' ').map(Number));
|
||||||
const recognizeHeader = function recognizeHeader(buffer: Buffer) {
|
const recognizeHeader = function recognizeHeader(buffer: Buffer)
|
||||||
|
{
|
||||||
if(pngMagic.equals(buffer.slice(0, pngMagic.length))) return 'png';
|
if(pngMagic.equals(buffer.slice(0, pngMagic.length))) return 'png';
|
||||||
if(gifMagic.equals(buffer.slice(0, gifMagic.length))) return 'gif';
|
if(gifMagic.equals(buffer.slice(0, gifMagic.length))) return 'gif';
|
||||||
return 'jpeg';
|
return 'jpeg';
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function readImagesJPEG(code: number, tagData: any): Promise<any> {
|
export async function readImagesJPEG(code: number, tagData: any): Promise<any>
|
||||||
var characterId = tagData.characterId,
|
{
|
||||||
|
const characterId = tagData.characterId,
|
||||||
imageData = tagData.imageData;
|
imageData = tagData.imageData;
|
||||||
|
|
||||||
var imgType = recognizeHeader(imageData);
|
const imgType = recognizeHeader(imageData);
|
||||||
if (imgType !== 'jpeg') {
|
if(imgType !== 'jpeg')
|
||||||
|
{
|
||||||
return {
|
return {
|
||||||
code: code,
|
code: code,
|
||||||
characterId: characterId,
|
characterId: characterId,
|
||||||
@ -96,14 +121,17 @@ export async function readImagesJPEG(code: number, tagData: any): Promise<any> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var bitmapAlphaData = tagData.bitmapAlphaData;
|
const bitmapAlphaData = tagData.bitmapAlphaData;
|
||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject)
|
||||||
var enc = new _encoder2.default(undefined, undefined, {colorSpace: 'rgba'});
|
{
|
||||||
_zlib2.default.unzip(bitmapAlphaData, function (err: any, alphaBufPre: any) {
|
const enc = new _encoder2.default(undefined, undefined, { colorSpace: 'rgba' });
|
||||||
|
_zlib2.default.unzip(bitmapAlphaData, function (err: any, alphaBufPre: any)
|
||||||
|
{
|
||||||
// INVARIANT: alphaBuf is either null or a non-empty buffer
|
// INVARIANT: alphaBuf is either null or a non-empty buffer
|
||||||
let alphaBuf: any = null;
|
let alphaBuf: any = null;
|
||||||
if (err) {
|
if(err)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
Due to a bug present in node zlib (https://github.com/nodejs/node/issues/17041)
|
Due to a bug present in node zlib (https://github.com/nodejs/node/issues/17041)
|
||||||
unzipping an empty buffer can raise "unexpected end of file" error.
|
unzipping an empty buffer can raise "unexpected end of file" error.
|
||||||
@ -113,33 +141,41 @@ export async function readImagesJPEG(code: number, tagData: any): Promise<any> {
|
|||||||
other two zlib.unzip call happens at sites that an empty uncompressed Buffer
|
other two zlib.unzip call happens at sites that an empty uncompressed Buffer
|
||||||
does not make sense. So I think the current fix is good enough.
|
does not make sense. So I think the current fix is good enough.
|
||||||
*/
|
*/
|
||||||
if (bitmapAlphaData.length > 0) {
|
if(bitmapAlphaData.length > 0)
|
||||||
|
{
|
||||||
return reject(new Error(err));
|
return reject(new Error(err));
|
||||||
}
|
}
|
||||||
// leaving alphaBuf as null
|
// leaving alphaBuf as null
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// ensure alphaBuf is only assigned an non-empty Buffer
|
// ensure alphaBuf is only assigned an non-empty Buffer
|
||||||
if(alphaBufPre.length > 0) alphaBuf = alphaBufPre;
|
if(alphaBufPre.length > 0) alphaBuf = alphaBufPre;
|
||||||
}
|
}
|
||||||
var bufferStream = new _stream2.default.PassThrough();
|
const bufferStream = new _stream2.default.PassThrough();
|
||||||
bufferStream.end(imageData);
|
bufferStream.end(imageData);
|
||||||
bufferStream.pipe(new _decoder2.default()).pipe((_concatFrames2.default)(function (_ref: any) {
|
bufferStream.pipe(new _decoder2.default()).pipe((_concatFrames2.default)(function (_ref: any)
|
||||||
var _ref2 = _slicedToArray(_ref, 1),
|
{
|
||||||
|
const _ref2 = _slicedToArray(_ref, 1),
|
||||||
frame = _ref2[0];
|
frame = _ref2[0];
|
||||||
|
|
||||||
var input = frame.pixels;
|
const input = frame.pixels;
|
||||||
var pCount = frame.width * frame.height;
|
const pCount = frame.width * frame.height;
|
||||||
var output = Buffer.alloc(pCount * 4);
|
const output = Buffer.alloc(pCount * 4);
|
||||||
if (alphaBuf !== null && alphaBuf.length !== pCount) {
|
if(alphaBuf !== null && alphaBuf.length !== pCount)
|
||||||
|
{
|
||||||
console.error('expect alphaBuf to have size ' + pCount + ' while getting ' + alphaBuf.length);
|
console.error('expect alphaBuf to have size ' + pCount + ' while getting ' + alphaBuf.length);
|
||||||
}
|
}
|
||||||
var getAlphaBuf = alphaBuf === null ? function (_ignored: any) {
|
const getAlphaBuf = alphaBuf === null ? function (_ignored: any)
|
||||||
|
{
|
||||||
return 0xff;
|
return 0xff;
|
||||||
} : function (i: any) {
|
} : function (i: any)
|
||||||
|
{
|
||||||
return alphaBuf[i];
|
return alphaBuf[i];
|
||||||
};
|
};
|
||||||
|
|
||||||
for (var i = 0; i < pCount; ++i) {
|
for(let i = 0; i < pCount; ++i)
|
||||||
|
{
|
||||||
output[4 * i] = input[3 * i];
|
output[4 * i] = input[3 * i];
|
||||||
output[4 * i + 1] = input[3 * i + 1];
|
output[4 * i + 1] = input[3 * i + 1];
|
||||||
output[4 * i + 2] = input[3 * i + 2];
|
output[4 * i + 2] = input[3 * i + 2];
|
||||||
@ -150,8 +186,10 @@ export async function readImagesJPEG(code: number, tagData: any): Promise<any> {
|
|||||||
enc.end(output);
|
enc.end(output);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
(_streamToArray2.default)(enc).then(function (parts: any) {
|
(_streamToArray2.default)(enc).then(function (parts: any)
|
||||||
var buffers = parts.map(function (part: any) {
|
{
|
||||||
|
const buffers = parts.map(function (part: any)
|
||||||
|
{
|
||||||
return Buffer.isBuffer(part) ? part : Buffer.from(part);
|
return Buffer.isBuffer(part) ? part : Buffer.from(part);
|
||||||
});
|
});
|
||||||
resolve({
|
resolve({
|
||||||
@ -173,7 +211,8 @@ export interface ImageTagData {
|
|||||||
bitmapHeight: number
|
bitmapHeight: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export function readImagesDefineBitsLossless(tag: any) {
|
export function readImagesDefineBitsLossless(tag: any)
|
||||||
|
{
|
||||||
const characterId = tag.characterId,
|
const characterId = tag.characterId,
|
||||||
bitmapFormat = tag.bitmapFormat,
|
bitmapFormat = tag.bitmapFormat,
|
||||||
bitmapWidth = tag.bitmapWidth,
|
bitmapWidth = tag.bitmapWidth,
|
||||||
@ -182,21 +221,27 @@ export function readImagesDefineBitsLossless(tag: any) {
|
|||||||
zlibBitmapData = tag.zlibBitmapData;
|
zlibBitmapData = tag.zlibBitmapData;
|
||||||
|
|
||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject)
|
||||||
|
{
|
||||||
const enc = new _encoder2.default(bitmapWidth, bitmapHeight, { colorSpace: 'rgba' });
|
const enc = new _encoder2.default(bitmapWidth, bitmapHeight, { colorSpace: 'rgba' });
|
||||||
|
|
||||||
_zlib2.default.unzip(zlibBitmapData, function (err: any, dataBuf: any) {
|
_zlib2.default.unzip(zlibBitmapData, function (err: any, dataBuf: any)
|
||||||
if (err) {
|
{
|
||||||
|
if(err)
|
||||||
|
{
|
||||||
return reject(new Error(err));
|
return reject(new Error(err));
|
||||||
}
|
}
|
||||||
var output = Buffer.alloc(bitmapWidth * bitmapHeight * 4);
|
const output = Buffer.alloc(bitmapWidth * bitmapHeight * 4);
|
||||||
var index = 0;
|
let index = 0;
|
||||||
var ptr = 0;
|
let ptr = 0;
|
||||||
if (bitmapFormat === 5) {
|
if(bitmapFormat === 5)
|
||||||
|
{
|
||||||
// 32-bit ARGB image
|
// 32-bit ARGB image
|
||||||
for (var y = 0; y < bitmapHeight; ++y) {
|
for(let y = 0; y < bitmapHeight; ++y)
|
||||||
for (var x = 0; x < bitmapWidth; ++x) {
|
{
|
||||||
var alpha = dataBuf[ptr];
|
for(let x = 0; x < bitmapWidth; ++x)
|
||||||
|
{
|
||||||
|
const alpha = dataBuf[ptr];
|
||||||
output[index] = dataBuf[ptr + 1] * (255 / alpha);
|
output[index] = dataBuf[ptr + 1] * (255 / alpha);
|
||||||
output[index + 1] = dataBuf[ptr + 2] * (255 / alpha);
|
output[index + 1] = dataBuf[ptr + 2] * (255 / alpha);
|
||||||
output[index + 2] = dataBuf[ptr + 3] * (255 / alpha);
|
output[index + 2] = dataBuf[ptr + 3] * (255 / alpha);
|
||||||
@ -205,17 +250,22 @@ export function readImagesDefineBitsLossless(tag: any) {
|
|||||||
ptr += 4;
|
ptr += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (bitmapFormat === 3) {
|
}
|
||||||
|
else if(bitmapFormat === 3)
|
||||||
|
{
|
||||||
// 8-bit colormapped image
|
// 8-bit colormapped image
|
||||||
var colorMap = [];
|
const colorMap = [];
|
||||||
for (var i = 0; i < bitmapColorTableSize + 1; ++i) {
|
for(let i = 0; i < bitmapColorTableSize + 1; ++i)
|
||||||
|
{
|
||||||
colorMap.push([dataBuf[ptr], dataBuf[ptr + 1], dataBuf[ptr + 2], dataBuf[ptr + 3]]);
|
colorMap.push([dataBuf[ptr], dataBuf[ptr + 1], dataBuf[ptr + 2], dataBuf[ptr + 3]]);
|
||||||
ptr += 4;
|
ptr += 4;
|
||||||
}
|
}
|
||||||
for (var _y2 = 0; _y2 < bitmapHeight; ++_y2) {
|
for(let _y2 = 0; _y2 < bitmapHeight; ++_y2)
|
||||||
for (var _x2 = 0; _x2 < bitmapWidth; ++_x2) {
|
{
|
||||||
var idx = dataBuf[ptr];
|
for(let _x2 = 0; _x2 < bitmapWidth; ++_x2)
|
||||||
var color = idx < colorMap.length ? colorMap[idx] : [0, 0, 0, 0];
|
{
|
||||||
|
const idx = dataBuf[ptr];
|
||||||
|
const color = idx < colorMap.length ? colorMap[idx] : [0, 0, 0, 0];
|
||||||
output[index] = color[0];
|
output[index] = color[0];
|
||||||
output[index + 1] = color[1];
|
output[index + 1] = color[1];
|
||||||
output[index + 2] = color[2];
|
output[index + 2] = color[2];
|
||||||
@ -226,14 +276,18 @@ export function readImagesDefineBitsLossless(tag: any) {
|
|||||||
// skip padding
|
// skip padding
|
||||||
ptr += (4 - bitmapWidth % 4) % 4;
|
ptr += (4 - bitmapWidth % 4) % 4;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return reject(new Error('unhandled bitmapFormat: ' + bitmapFormat));
|
return reject(new Error('unhandled bitmapFormat: ' + bitmapFormat));
|
||||||
}
|
}
|
||||||
enc.end(output);
|
enc.end(output);
|
||||||
});
|
});
|
||||||
|
|
||||||
(_streamToArray2.default)(enc).then(function (parts: any) {
|
(_streamToArray2.default)(enc).then(function (parts: any)
|
||||||
var buffers = parts.map(function (part: any) {
|
{
|
||||||
|
const buffers = parts.map(function (part: any)
|
||||||
|
{
|
||||||
return Buffer.isBuffer(part) ? part : Buffer.from(part);
|
return Buffer.isBuffer(part) ? part : Buffer.from(part);
|
||||||
});
|
});
|
||||||
resolve({
|
resolve({
|
||||||
@ -245,7 +299,8 @@ export function readImagesDefineBitsLossless(tag: any) {
|
|||||||
bitmapHeight: bitmapHeight
|
bitmapHeight: bitmapHeight
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).catch(function (e) {
|
}).catch(function (e)
|
||||||
|
{
|
||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user