{"library":"pixel-utils","title":"Pixel Utility Functions","description":"pixel-utils is a JavaScript/TypeScript library providing minimalist utility functions for pixel manipulation. As of version 0.9.0, it offers conversions between raw, RGB, and RGBA pixel formats, functions for handling 'no data' values, pixel iteration, selection, and transparency adjustments. The library is optimized for speed and supports optional mutability for memory-preserving operations. A key differentiator is its ability to handle raw image data (not limited to 8-bit 0-255 RGBA) and arbitrary image layouts, thanks to integration with the xdim library. While actively developed with frequent minor updates, the project maintains a 'beta' status, indicating that function signatures are subject to change without strict adherence to semantic versioning for breaking changes. Core assumptions involve pixel formats as arrays of numbers (0-255 for RGB/RGBA, arbitrary for raw) and specific conventions for alpha and 'no data' values.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install pixel-utils"],"cli":null},"imports":["import { rawToRgba } from 'pixel-utils';","import { eachPixel } from 'pixel-utils';","import { rgbToRgba } from 'pixel-utils';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { rawToRgba, eachPixel } from 'pixel-utils';\n\n// Example raw pixel data (e.g., from a sensor, could be any number)\nconst rawImageBuffer = [\n  1000, 2000, 3000, // Pixel 1 data\n  4000, 5000, 6000, // Pixel 2 data\n  7000, 8000, 9000  // Pixel 3 data\n];\n\n// Define image dimensions and no-data value for raw conversion\nconst width = 3;\nconst height = 1;\nconst bands = 3;\nconst noDataValue = 0; // Assuming 0 for simplicity, actual would depend on sensor\n\n// Convert raw data to RGBA (0-255 range)\n// This example assumes a simple scaling for demonstration.\n// In a real scenario, you'd likely map sensor values to a visual range.\nconst rgbaPixels = rawToRgba({\n  data: rawImageBuffer,\n  width,\n  height,\n  bands,\n  noData: noDataValue,\n  scale: (value: number) => Math.min(255, Math.max(0, value / 40))\n});\n\nconsole.log('Converted RGBA Pixels (first 4 values):', rgbaPixels.data.slice(0, 4));\n\n// Iterate over the RGBA pixels\nlet pixelCount = 0;\neachPixel({\n  data: rgbaPixels.data,\n  width: rgbaPixels.width,\n  height: rgbaPixels.height,\n  bands: 4 // RGBA has 4 bands\n}, (pixel: number[], x: number, y: number) => {\n  console.log(`Pixel at (${x}, ${y}): [${pixel.join(', ')}]`);\n  pixelCount++;\n});\n\nconsole.log(`Processed ${pixelCount} pixels.`);","lang":"typescript","description":"Demonstrates converting raw, unscaled pixel data into RGBA format and then iterating through the resulting RGBA pixel array.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}