mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Add types for bmp-js (#41199)
This commit is contained in:
committed by
Andrew Branch
parent
a8fb783542
commit
62e76348ae
8
types/bmp-js/bmp-js-tests.ts
Normal file
8
types/bmp-js/bmp-js-tests.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { decode, encode } from "bmp-js";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
|
||||
const bmpBuffer = readFileSync('grayscale.bmp');
|
||||
const decoded = decode(bmpBuffer);
|
||||
const { width, height, data } = decoded;
|
||||
console.log("got bmp with %s x %s (%s bytes)", width, height, data.byteLength);
|
||||
writeFileSync("testoutput.bmp", encode(decoded).data);
|
||||
76
types/bmp-js/index.d.ts
vendored
Executable file
76
types/bmp-js/index.d.ts
vendored
Executable file
@@ -0,0 +1,76 @@
|
||||
// Type definitions for bmp-js 0.1
|
||||
// Project: https://github.com/shaozilee/bmp-js
|
||||
// Definitions by: Robert Krahn <https://github.com/rksm>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
export interface ImageData {
|
||||
readonly data: Buffer;
|
||||
readonly height: number;
|
||||
readonly width: number;
|
||||
}
|
||||
|
||||
export type Encode = (imgData: ImageData, quality?: number) => ImageData;
|
||||
|
||||
/**
|
||||
* Bmp format decoder, support 1bit 4bit 8bit 24bit bmp
|
||||
*/
|
||||
export class BmpDecoder implements ImageData {
|
||||
private pos: number;
|
||||
data: Buffer;
|
||||
fileSize: number;
|
||||
reserved: number;
|
||||
offset: number;
|
||||
headerSize: number;
|
||||
width: number;
|
||||
height: number;
|
||||
planes: number;
|
||||
bitPP: number;
|
||||
compress: number;
|
||||
rawSize: number;
|
||||
hr: number;
|
||||
vr: number;
|
||||
colors: number;
|
||||
importantColors: number;
|
||||
bottom_up: boolean;
|
||||
|
||||
palette: Array<{
|
||||
red: number;
|
||||
green: number;
|
||||
blue: number;
|
||||
quad: number;
|
||||
}>;
|
||||
|
||||
constructor(buffer: Buffer, is_with_alpha?: boolean);
|
||||
|
||||
/**
|
||||
* Returns the data buffer - byte array order by ABGR ABGR ABGR,4 bytes per pixel
|
||||
*/
|
||||
getData(): Buffer;
|
||||
|
||||
private parseHeader(): void;
|
||||
private parseRGBA(): void;
|
||||
private bit1(): void;
|
||||
private bit4(): void;
|
||||
private bit8(): void;
|
||||
private bit15(): void;
|
||||
private bit16(): void;
|
||||
private bit24(): void;
|
||||
private bit32(): void;
|
||||
}
|
||||
|
||||
export type Decode = (bmpData: Buffer) => BmpDecoder;
|
||||
|
||||
/**
|
||||
* var bmp = require("bmp-js");
|
||||
* var bmpBuffer = fs.readFileSync('bit24.bmp');
|
||||
* var bmpData = bmp.decode(bmpBuffer);
|
||||
*/
|
||||
export const decode: Decode;
|
||||
|
||||
/**
|
||||
* var bmp = require("bmp-js");
|
||||
* var rawData = bmp.encode(bmpData); //default no compression,write rawData to .bmp file
|
||||
*/
|
||||
export const encode: Encode;
|
||||
23
types/bmp-js/tsconfig.json
Executable file
23
types/bmp-js/tsconfig.json
Executable file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"bmp-js-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/bmp-js/tslint.json
Normal file
3
types/bmp-js/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user