{"name":"bmp-ts","version":"1.0.6","description":"A pure typescript BMP encoder and decoder","license":"MIT","repository":{"type":"git","url":"git+https://github.com/hipstersmoothie/bmp-ts.git"},"author":{"name":"Andrew lisowski","email":"lisowski54@gmail.com"},"scripts":{"build":"tshy","test":"vitest","release":"auto shipit"},"devDependencies":{"@types/node":"^10.11.7","auto":"^11.1.2","prettier":"^3.2.5","tshy":"^1.12.0","typescript":"^5.4.3","vitest":"^1.4.0"},"prettier":{"singleQuote":true},"keywords":["bmp","1bit","4bit","8bit","16bit","24bit","32bit","encoder","decoder","image","javascript","js"],"tshy":{"exclude":["**/__test__/**"],"exports":{"./package.json":"./package.json",".":"./src/index.ts"}},"exports":{"./package.json":"./package.json",".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}}},"main":"./dist/commonjs/index.js","types":"./dist/commonjs/index.d.ts","type":"module","_id":"bmp-ts@1.0.6","gitHead":"d62c2be42c81373515ae47986a426cf90a5cdc69","bugs":{"url":"https://github.com/hipstersmoothie/bmp-ts/issues"},"homepage":"https://github.com/hipstersmoothie/bmp-ts#readme","_nodeVersion":"18.19.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-7rxKlSlMK7Dz0AcaVaDTD4YRYHwXEjK38EUuNKm0R5uguWRSGnZT54m1rjWERnrbN5nc/biygiD+bs1j6sssXw==","shasum":"4d5c7511923e6df897fcad9222fb3a342f480cb2","tarball":"http://registry-npm.ywwl.com/bmp-ts/download/bmp-ts-1.0.6.tgz","fileCount":41,"unpackedSize":130249,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDfoToHn417JCc6BF5VOKuUmJgbPBds7c0TJjamoLTRoAiAV9W5O2xDI/gYS7MXAG3xuYNQIOhbVLEGfywtJVP0LvQ=="}],"size":15497,"noattachment":false,"key":"/bmp-ts/-/bmp-ts-1.0.6.tgz"},"_npmUser":{"name":"alisowski","email":"lisowski54@gmail.com"},"directories":{},"maintainers":[{"name":"alisowski","email":"lisowski54@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bmp-ts_1.0.6_1711223159918_0.5253232173030384"},"_hasShrinkwrap":false,"readme":"<div align=\"center\">\n  <img width=\"200\" height=\"200\"\n    src=\"./logo.png\">\n  <h1>bmp-ts</h1>\n  <p>A pure typescript <code>bmp</code> encoder and decoder.</p>\n</div\n\n[![Codecov](https://img.shields.io/codecov/c/github/hipstersmoothie/bmp-ts.svg?style=for-the-badge)](https://codecov.io/gh/hipstersmoothie/bmp-ts)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=for-the-badge)](https://github.com/prettier/prettier)\n\nSupports decoding and encoding in all bit depths (1, 4, 8, 16, 24, 32).\n\n## Install\n\n```sh\nnpm install bmp-ts\n```\n\n## Usage\n\n### Decoding\n\n`decode` will return an object that includes all the header properties of the `bmp` image file and the data. See header definition [below](#header).\n\n```js\nconst bmp = require('bmp-ts').default;\nconst bmpBuffer = fs.readFileSync('bit24.bmp');\nconst bmpData = bmp.decode(bmpBuffer);\n```\n\n#### Options\n\n- toRGBA - switch the output to big endian RGBA, making it compatible with other libraries like `pngjs`\n\n```js\nconst bmp = require('bmp-ts').default;\nconst bmpBuffer = fs.readFileSync('bit24.bmp');\nconst bmpData = bmp.decode(bmpBuffer, { toRGBA: true });\n```\n\n#### Supported Compression Methods\n\nCurrently compression is only supported during decoding. The following methods are implemented:\n\n- NONE - Most common\n- BI_RLE8 - Can be used only with 8-bit/pixel bitmap\n- BI_RLE4 - Can be used only with 4-bit/pixel bitmaps\n- BI_BIT_FIELDS - Huffman 1D - BITMAPV2INFOHEADER: RGB bit field masks, BITMAPV3INFOHEADER+: RGBA\n- BI_ALPHA_BIT_FIELDS - RGBA bit field masks - only Windows CE 5.0 with .NET 4.0 or later\n\n### Encoding\n\nTo encode an image all you need is a buffer with the image data, the height and the width. You can specify the bit depth of the output image by modifying `bitPP`. If you do not provide a value, the output image defaults to 24-bit.\n\nAll header fields are valid options to `encode` and will be encoded into the header.\n\n```js\nconst bmp = require('bmp-ts').default;\nconst fs = require('fs');\nconst bmpData = {\n  data, // Buffer\n  bitPP: 1 | 2 | 4 | 16 | 24 | 32, // The number of bits per pixel\n  width, // Number\n  height, // Number\n};\n\n// Compression is not supported\nconst rawData = bmp.encode(bmpData);\nfs.writeFileSync('./image.bmp', rawData.data);\n```\n\n## Header\n\n| Property        | Type    | Purpose                                                                                                |\n| --------------- | ------- | ------------------------------------------------------------------------------------------------------ |\n| fileSize        | number  | The size of the BMP file in bytes                                                                      |\n| reserve1        | number  | Reserved; actual value depends on the application that creates the image                               |\n| reserve2        | number  | Reserved; actual value depends on the application that creates the image                               |\n| offset          | number  | The offset, i.e. starting address, of the byte where the bitmap image data (pixel array) can be found. |\n| headerSize      | number  | The size of this header (12 bytes)                                                                     |\n| width           | number  | The bitmap width in pixels (unsigned 16-bit)                                                           |\n| height          | number  | The bitmap height in pixels (unsigned 16-bit)                                                          |\n| planes          | number  | The number of color planes, must be 1                                                                  |\n| bitPP           | number  | The number of bits per pixel                                                                           |\n| compress        | number  | The compression method being used. See the supported compression methods                               |\n| rawSize         | number  | The image size. This is the size of the raw bitmap data; a dummy 0 can be given for BI_RGB bitmaps.    |\n| hr              | number  | The horizontal resolution of the image. (pixel per metre, signed integer)                              |\n| vr              | number  | The vertical resolution of the image. (pixel per metre, signed integer)                                |\n| colors          | number  | The number of colors in the color palette, or 0 to default to 2n                                       |\n| importantColors | number  | The number of important colors used, or 0 when every color is important; generally ignored             |\n| palette         | Color[] | The colors used to render the image. only used for 1, 4, and 8 bitPP images                            |\n| data            | Byte[]  | The data in ABGR                                                                                       |\n\n### Color\n\nThe color palette is returned when decoding a 1, 4, or 8 bit image.\n\nColor Format:\n\n```json\n{\n  \"red\": 255,\n  \"green\": 255,\n  \"blue\": 255,\n  \"quad\": 255\n}\n```\n\nTo encode to 4 or 8 bit a color palette must be provided. 1 bit defaults to black and white but you can override this via palette.\n\n```js\nconst rawData = bmp.encode({\n  data,\n  bitPP: 8,\n  width,\n  height,\n  palette: [\n    { red: 255, green: 255, blue: 255, quad: 0 },\n    { red: 255, green: 255, blue: 0, quad: 0 },\n    { red: 255, green: 0, blue: 255, quad: 0 },\n    { red: 255, green: 0, blue: 0, quad: 0 },\n    { red: 0, green: 255, blue: 255, quad: 0 },\n    { red: 0, green: 255, blue: 0, quad: 0 },\n    { red: 0, green: 0, blue: 255, quad: 0 },\n    { red: 0, green: 0, blue: 0, quad: 0 },\n  ],\n});\n\nfs.writeFileSync('./image.bmp', rawData.data);\n```\n","publish_time":1711223160064,"_cnpm_publish_time":1711223160064,"dist-tags":{"canary":"1.0.4-canary.f6048cc","latest":"1.0.9"}}