https://github.com/xyproto/pf
Apply functions to each pixel in an image, concurrently
https://github.com/xyproto/pf
argb concurrent map pixels
Last synced: about 1 year ago
JSON representation
Apply functions to each pixel in an image, concurrently
- Host: GitHub
- URL: https://github.com/xyproto/pf
- Owner: xyproto
- License: bsd-3-clause
- Created: 2018-08-22T13:00:47.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2021-08-12T16:09:50.000Z (almost 5 years ago)
- Last Synced: 2025-03-29T03:03:56.276Z (about 1 year ago)
- Topics: argb, concurrent, map, pixels
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PixelFunctions
Apply functions to each pixel in an image, concurrently.
This module contains functions that fit well together with the [pixelpusher](https://github.com/xyproto/pixelpusher) module.
The `PixelFunction` type has this signature:
func(v uint32) uint32
If you have a pixel buffer of type `[]uint32`, with colors on the form `ARGB`, then this modules allows you to apply functions of the type `PixelFunction` to that slice, concurrently.
The goal is to avoid looping over all pixels more than once, while applying many different effects, concurrently.
## Combine and Map
* Several `PixelFunction` functions can be combined to a single `PixelFunction` by using the `Combine` function.
* A `PixelFuncion` can be applied to a pixel buffer by using the `Map` function.
Example:
```go
package main
import (
"fmt"
"github.com/xyproto/pf"
"runtime"
)
func main() {
// Resolution
const w, h = 320, 200
pixels := make([]uint32, w*h)
// Find the number of available CPUs
n := runtime.NumCPU()
// Combine two pixel functions
pfs := pf.Combine(pf.InvertEverything, pf.OnlyBlue)
// Run the combined pixel functions over all pixels using all available CPUs
pf.Map(n, pfs, pixels)
// Retrieve the red, green and blue components of the first pixel
red := (pixels[0] | 0x00ff0000) >> 0xffff
green := (pixels[0] | 0x0000ff00) >> 0xff
blue := (pixels[0] | 0x000000ff)
// Should output only blue: rgb(0, 0, 255)
fmt.Printf("rgb(%d, %d, %d)\n", red, green, blue)
}
```
# General info
* License: BSD
* Version: 0.1.0
* Author: Alexander F. Rødseth <xyproto@archlinux.org>