docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a tool that efficiently compares two image buffers and reports whether they are identical. The tool must be optimized for performance, especially when processing large images or performing many comparisons in sequence.
When comparing image data represented as byte arrays in RGBA format (4 bytes per pixel: red, green, blue, alpha), a naive byte-by-byte comparison can be slow. Your task is to implement an efficient comparison that minimizes memory allocations and maximizes throughput.
Your implementation must:
The implementation must be optimized for:
When a third output buffer is provided:
0.299 × red + 0.587 × green + 0.114 × blue[255, 0, 0, 255]grayscale × alpha / 255/**
* Compares two image buffers pixel by pixel and returns the number of mismatched pixels.
* Optionally generates a visual diff output.
*
* @param {Uint8Array|Uint8ClampedArray|Buffer} img1 - First image buffer in RGBA format
* @param {Uint8Array|Uint8ClampedArray|Buffer} img2 - Second image buffer in RGBA format
* @param {Uint8Array|Uint8ClampedArray|Buffer|null} output - Optional output buffer for diff visualization
* @param {number} width - Image width in pixels
* @param {number} height - Image height in pixels
* @returns {number} Number of pixels that differ between img1 and img2
*/
function compareImages(img1, img2, output, width, height) {
// Implementation here
}
module.exports = { compareImages };Provides pixel-level image comparison with performance optimizations.