diff --git a/README.md b/README.md index 0b9cc00..0679210 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,8 @@ const imageWithWarnings = await Image.decode(data, { ``` **Note:** When using `Image.decode()`, the library automatically tries runtime-optimized decoders +(ImageDecoder API) first, falling back to the pure JS decoder with tolerant mode for maximum +compatibility. ## CMYK Color Space Support @@ -378,9 +380,6 @@ const roundtrip = await Image.decode(parsed.bytes, "png"); console.log(roundtrip.width, roundtrip.height); ``` -(ImageDecoder API) first, falling back to the pure JS decoder with tolerant mode for maximum -compatibility. - ## Fault-Tolerant Decoding for Other Formats In addition to JPEG, @cross/image provides fault-tolerant decoding for several other formats that diff --git a/docs/src/examples/decoding-encoding.md b/docs/src/examples/decoding-encoding.md index 18bf2b8..52dedca 100644 --- a/docs/src/examples/decoding-encoding.md +++ b/docs/src/examples/decoding-encoding.md @@ -280,6 +280,51 @@ const pcx = await image.encode("pcx"); await Deno.writeFile("output.pcx", pcx); ``` +### QOI (Quite OK Image) + +Fast lossless format with simple encoding. + +```ts +import { Image } from "jsr:@cross/image"; + +const data = await Deno.readFile("input.png"); +const image = await Image.decode(data); + +// Encode as QOI +const qoi = await image.encode("qoi"); +await Deno.writeFile("output.qoi", qoi); +``` + +### PGM (Portable GrayMap) + +Netpbm grayscale format; RGB is converted to grayscale using luma weighting. + +```ts +import { Image } from "jsr:@cross/image"; + +const data = await Deno.readFile("input.png"); +const image = await Image.decode(data); + +// Encode as PGM (binary P5 format) +const pgm = await image.encode("pgm"); +await Deno.writeFile("output.pgm", pgm); +``` + +### PBM (Portable BitMap) + +Netpbm monochrome format; pixels at or above luma 128 become white. + +```ts +import { Image } from "jsr:@cross/image"; + +const data = await Deno.readFile("input.png"); +const image = await Image.decode(data); + +// Encode as PBM (binary P4 format) +const pbm = await image.encode("pbm"); +await Deno.writeFile("output.pbm", pbm); +``` + ## Format Conversion Examples ### PNG to JPEG diff --git a/docs/src/index.md b/docs/src/index.md index 93eeb5f..a1bc51b 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -136,12 +136,13 @@ await Image.decode(bytes, "png"); ## Supported Formats -@cross/image supports 15 image formats with varying levels of pure-JS implementation: +@cross/image supports 18 image formats with varying levels of pure-JS implementation: -- **PNG, APNG, BMP, ICO, GIF, DNG, PAM, PPM, PCX, ASCII** - Full pure-JS implementation +- **PNG, APNG, BMP, ICO, GIF, DNG, PAM, PPM, PGM, PBM, PCX, QOI, ASCII** - Full pure-JS + implementation - **JPEG** - Pure-JS baseline & progressive DCT - **WebP** - Pure-JS lossless, native API for lossy VP8 -- **TIFF** - Pure-JS uncompressed + LZW, native API for other compressions +- **TIFF** - Pure-JS uncompressed, LZW, PackBits & Deflate; native API for JPEG compression - **HEIC, AVIF** - Runtime-based implementation (requires ImageDecoder/OffscreenCanvas API) See the [Format Support](formats.md) page for detailed compatibility information.