New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@blazediff/core

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blazediff/core

Blazing-fast pixel-by-pixel image comparison with block-based optimization. 1.5x times faster than pixelmatch

Source
npmnpm
Version
1.5.0
Version published
Weekly downloads
8.7M
-26.27%
Maintainers
1
Weekly downloads
 
Created
Source

@blazediff/core

npm bundle size NPM Downloads

High-performance pixel-by-pixel image comparison with block-based optimization. 20% faster than pixelmatch with zero memory allocation.

Features:

  • YIQ color space for perceptual color difference
  • Anti-aliasing detection and filtering
  • Block-based optimization with 32-bit integer comparison
  • Zero memory allocation during comparison
  • Support for alpha channel and transparency

For detailed algorithm explanation and mathematical formulas, see FORMULA.md.

Installation

npm install @blazediff/core

API

blazediff(image1, image2, output, width, height, options)

Compare two images and return the number of different pixels.

ParameterTypeDescription
image1Uint8Array | Uint8ClampedArrayFirst image data
image2Uint8Array | Uint8ClampedArraySecond image data
outputUint8Array | Uint8ClampedArrayOptional output buffer for diff visualization
widthnumberImage width in pixels
heightnumberImage height in pixels
optionsobjectComparison options (optional)

Returns: Number of different pixels

OptionTypeDefaultDescriptionHint
thresholdnumber0.1Color difference threshold (0-1)Lower values = more sensitive. 0.05 for strict comparison, 0.2+ for loose comparison
alphanumber0.1Background image opacityControls how faded unchanged pixels appear in diff output
aaColor[number, number, number][255,255,0]Anti-aliasing pixel colorYellow by default. Set to red [255,0,0] to highlight anti-aliasing
diffColor[number, number, number][255,0,0]Different pixel colorRed by default. Use contrasting colors for better visibility
diffColorAlt[number, number, number]-Alternative color for dark differencesHelps distinguish light vs dark pixel changes
includeAAbooleanfalseInclude anti-aliasing in diff countSet true to count anti-aliasing pixels as actual differences
diffMaskbooleanfalseOutput only differences (transparent background)Useful for creating overlay masks or highlighting changes only
fastBufferCheckbooleantrueUse fast buffer check using Buffer.compareSet to false if images are processed differently, but look similiar

Usage

import blazediff from '@blazediff/core';

const diffCount = blazediff(
  image1.data,
  image2.data,
  outputData,
  width,
  height,
  {
    threshold: 0.1,
    alpha: 0.1,
    aaColor: [255, 255, 0],
    diffColor: [255, 0, 0],
    includeAA: false,
    diffMask: false,
    fastBufferCheck: true,
  }
);

Algorithm

BlazeDiff uses a sophisticated multi-stage approach for high-performance image comparison:

  • Block-Based Pre-filtering: Divides images into adaptive blocks and uses 32-bit integer comparison to quickly identify unchanged regions
  • YIQ Color Space: Converts RGB to YIQ color space for perceptually accurate color difference measurement
  • Anti-Aliasing Detection: Implements the Vysniauskas (2009) algorithm to distinguish anti-aliasing artifacts from real differences
  • Optimized Memory Access: Zero-allocation design with cache-friendly memory patterns

See FORMULA.md for detailed mathematical formulas and algorithm explanation.

Performance

Compared to pixelmatch on a 1920×1080 image with 10% differences:

MetricBlazeDiffpixelmatchImprovement
Speed~25ms~30ms20% faster
Memory0 allocationsMultiple allocationsZero allocation
AccuracyYIQ perceptualYIQ perceptualSame

The block-based optimization provides the most benefit on images with large unchanged regions.

When to Use BlazeDiff vs Other Metrics

Use @blazediff/core when:

  • You need pixel-perfect diff visualization
  • You want to filter out anti-aliasing artifacts
  • You need precise control over difference colors
  • Performance is critical for CI/CD pipelines

Use @blazediff/gmsd when:

  • You need a perceptual similarity score (0-1)
  • You want to detect structural/gradient changes
  • You're comparing images with different compression or slight shifts
  • You need a single quality metric for regression testing

Limitations

  • Format: Requires RGBA format (4 bytes per pixel). Use transformers to convert other formats.
  • Memory: Images must fit in memory. For very large images (>100MP), consider tiling.
  • Precision: Uses floating-point arithmetic for color conversion. Expect ~0.01% variance in edge cases.
  • Anti-aliasing: Detection works best on standard rendering. May not detect exotic AA techniques.

References

  • Algorithm Documentation: FORMULA.md - Complete mathematical foundation and formulas
  • YIQ Color Space: Kotsarenko & Ramos (2009) - "Measuring perceived color difference using YIQ NTSC transmission color space"
  • Anti-Aliasing Detection: Vysniauskas (2009) - "Anti-aliased Pixel and Intensity Slope Detector"
  • Inspiration: pixelmatch - Original pixel-by-pixel diff algorithm

Keywords

image

FAQs

Package last updated on 17 Oct 2025

Related posts