davidbyttow / govips

A lightning fast image processing and resizing library for Go
MIT License
1.25k stars 196 forks source link

Adds `Recomb` for `ImageRef` #377

Closed n0vad3v closed 10 months ago

n0vad3v commented 1 year ago

This PR will add support for vips_recomb on ImageRef, will provide similar functionality as sharp does(https://sharp.pixelplumbing.com/api-operation#recomb)

Sharp example:

sharp(input)
  .recomb([
   [0.3588, 0.7044, 0.1368],
   [0.2990, 0.5870, 0.1140],
   [0.2392, 0.4696, 0.0912],
  ])
  .raw()
  .toBuffer(function(err, data, info) {
    // data contains the raw pixel data after applying the matrix
    // With this example input, a sepia filter has been applied
  });

Go example after this PR merged:

package main

import (
    "fmt"
    "os"

    "github.com/davidbyttow/govips/v2/vips"
)

func main() {
    vips.Startup(nil)
    defer vips.Shutdown()

    img, _ := vips.NewImageFromFile("test.png")
    matrix := [][]float64{
        {0.3588, 0.7044, 0.1368},
        {0.2990, 0.5870, 0.1140},
        {0.2392, 0.4696, 0.0912},
    }

    err := img.Recomb(matrix)
    if err != nil {
        fmt.Println(err)
    }
    image1bytes, _, _ := img.ExportPng(vips.NewPngExportParams())
    _ = os.WriteFile("experiment.png", image1bytes, 0644)

}

test.png test

experiment.png experiment