@thi.ng/pixel-io-pfm
Version:
Portable FloatMap image format support for @thi.ng/pixel
125 lines (89 loc) • 4.03 kB
Markdown
<!-- This file is generated - DO NOT EDIT! -->
<!-- Please see: https://codeberg.org/thi.ng/umbrella/src/branch/develop/CONTRIBUTING.md#changes-to-readme-files -->
# 
[](https://www.npmjs.com/package/@thi.ng/pixel-io-pfm)

[](https://mastodon.thi.ng/@toxi)
> [!NOTE]
> This is one of 215 standalone projects. LLM-free, human-made and
> cared for software, maintained as part of the
> [.ng/umbrella](https://codeberg.org/thi.ng/umbrella/) ecosystem and
> anti-framework.
>
> 🚀 Please help me to work full-time on these projects by [sponsoring
> me](https://codeberg.org/thi.ng/umbrella/src/branch/develop/CONTRIBUTING.md#donations).
> Thank you! ❤️
- [About](#about)
- [Status](#status)
- [Installation](#installation)
- [Dependencies](#dependencies)
- [API](#api)
- [Authors](#authors)
- [License](#license)
## About
Portable FloatMap image format support for [.ng/pixel](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/pixel).
Similar to the [NetPBM
formats](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/pixel-io-netpbm),
the [Portable FloatMap image format](https://pauldebevec.com/Research/HDR/PFM/)
is extremely simple, uncompressed and mainly interesting for development
purposes & interchange (e.g. for use with Intel's [Open Image Denoise CLI
tools](https://github.com/OpenImageDenoise/oidn)).
## Status
**STABLE** - used in production
[Search or submit any issues for this package](https://codeberg.org/thi.ng/umbrella/issues?q=%5Bpixel-io-pfm%5D)
## Installation
```bash
yarn add .ng/pixel-io-pfm
```
ESM import:
```ts
import * as pfm from "@thi.ng/pixel-io-pfm";
```
Browser ESM import:
```html
<script type="module" src="https://esm.run/@thi.ng/pixel-io-pfm"></script>
```
[JSDelivr documentation](https://www.jsdelivr.com/)
For Node.js REPL:
```js
const pfm = await import("@thi.ng/pixel-io-pfm");
```
Package sizes (brotli'd, pre-treeshake): ESM: 694 bytes
## Dependencies
- [.ng/errors](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/errors)
- [.ng/pixel](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/pixel)
## API
[Generated API docs](https://docs.thi.ng/umbrella/pixel-io-pfm/)
The package only provides 2 functions:
- [`asPFM(img: IntBuffer | FloatBuffer, littleEndian?: boolean, linearRGB?: boolean):
Uint8Array`](https://docs.thi.ng/umbrella/pixel-io-pfm/functions/asPFM.html):
Serializes an image to PFM and returns result as byte array
- [`readPFM(buf: Uint8Array, linearRGB?: boolean):
FloatBuffer`](https://docs.thi.ng/umbrella/pixel-io-pfm/functions/readPFM.html):
Parses byte array as PFM image and returns it as
[`FloatBuffer`](https://docs.thi.ng/umbrella/pixel/classes/FloatBuffer.html)
```ts tangle:export/readme.ts
import { intBuffer, RGB888 } from "@thi.ng/pixel";
import { asPFM } from "@thi.ng/pixel-io-pfm";
import { writeFileSync } from "node:fs";
// create 2x2 image
const img = intBuffer(2, 2, RGB888);
// set all 4 pixels (in order: red, green, blue, yellow)
img.data.set([0xff0000, 0x00ff00, 0x0000ff, 0xffff00]);
// serialize image to PFM byte array and write to file
// (format conversion to FLOAT_RGB is done automatically & non-destructively)
writeFileSync("export/rgby.pfm", asPFM(img));
```
## Authors
- [Karsten Schmidt](https://thi.ng)
If this project contributes to an academic publication, please cite it as:
```bibtex
{thing-pixel-io-pfm,
title = "@thi.ng/pixel-io-pfm",
author = "Karsten Schmidt",
note = "https://thi.ng/pixel-io-pfm",
year = 2023
}
```
## License
© 2023 - 2026 Karsten Schmidt // Apache License 2.0