Socket
Book a DemoInstallSign in
Socket

q-floodfill-hsl

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

q-floodfill-hsl

Optimized, non-recursive flood fill using a scan line search

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
4
100%
Maintainers
1
Weekly downloads
 
Created
Source

q-floodfill

Optimized, non-recursive flood fill algorithm using a scan line search.

Implemented in TypeScript. Zero dependencies and bundle size around 1.8k (gzipped and minified).

Demo - https://pavelkukov.github.io/q-floodfill/

🙌 Acknowledgments

The work here is heavily inspired from QuickFill algorithm by John R. Shaw. https://www.codeproject.com/Articles/6017/QuickFill-An-Efficient-Flood-Fill-Algorithm

📈 Performance

Needs ~30-40ms to fill 800x660 canvas. For comparison, wasm-flood-fill needs ~50-60ms for the same operation.

🧩 Installing

npm install --save q-floodfill

✔ Usage

// import default from module
import FloodFill from 'q-floodfill'
// get 2d context
const context = canvas.getContext('2d')
// get image data
const imgData = context.getImageData(0, 0, canvas.width, canvas.height)
// Construct flood fill instance
const floodFill = new FloodFill(imgData)
// Modify image data
floodFill.fill(fillColor, x, y, 0)
// put the modified data back in context
context.putImageData(floodFill.imageData, 0, 0)

Options

  • Get modified pixels count
// Construct flood fill instance
const floodFill = new FloodFill(imgData)
// Modify image data
floodFill.fill(fillColor, x, y, 0)
// Read property modifiedPixelsCount
const count = floodFill.modifiedPixelsCount
  • Collect modified pixels. This option is having a significant impact on performance.
const floodFill = new FloodFill(imgData)
// Set collectModifiedPixels to true
floodFill.collectModifiedPixels = true
// Modify image data
floodFill.fill(fillColor, x, y, 0)
// Read property modifiedPixels
const pixels = floodFill.modifiedPixels
// The type of modifiedPixels is Set<string>
// Each point is stored in the format `${x}|${y}`

Useful exports

{
    isSameColor, // Compare two colors for equality with optional tolerance
    setColorAtPixel, // Set pixel color by x, y coordinates in ImageData array
    getColorAtPixel, // Get pixel color from ImageData array by x, y coordinates
    colorToRGBA, // Convert CSS rgba, rgb or HEX color to RGBA color
    hex2RGBA, // convert CSS hex to RGBA color. Alpha is 255 by default
    ColorRGBA, // Type definition {r: number, g: number, b: number, a: number}
}

🧾 Notes

👋 Author

Pavel Kukov pavelkukov@gmail.com

© LICENSE (MIT)

See LICENSE.txt in the root directory

Similar packages

Keywords

flood-fill

FAQs

Package last updated on 13 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.