Skip to content

Instantly share code, notes, and snippets.

Avatar

Endre Simó esimov

View GitHub Profile
View triangle.go
c.processor = &triangle.Processor{
BlurRadius: 2,
Noise: 0,
BlurFactor: 2,
EdgeFactor: 4,
PointRate: c.pointRate,
MaxPoints: c.trianglePoints,
PointsThreshold: c.pointsThreshold,
Wireframe: c.wireframe,
StrokeWidth: c.strokeWidth,
View uint8arr_to_uint8clamped.go
uint8Arr := js.Global().Get("Uint8Array").New(width * height * 4)
js.CopyBytesToJS(uint8Arr2, pixels.ImgToPix(blurred))
uint8Clamped := js.Global().Get("Uint8ClampedArray").New(uint8Arr2)
rawData := js.Global().Get("ImageData").New(uint8Clamped, width, height)
c.ctx.Call("putImageData", rawData, 0, 0)
View uint8clamped_2_uint8arr.go
rgba := c.ctx.Call("getImageData", 0, 0, width, height).Get("data")
// Convert the rgba value of type Uint8ClampedArray to Uint8Array in order to
// be able to transfer it from Javascript to Go via the js.CopyBytesToGo function.
uint8Arr := js.Global().Get("Uint8Array").New(rgba)
js.CopyBytesToGo(data, uint8Arr)
View img_conversion.go
// ImgToPix converts an image to an 1D uint8 pixel array.
// In order to preserve the color information per pixel we need to reconstruct the array to a specific format.
func ImgToPix(src *image.NRGBA) []uint8 {
size := src.Bounds().Size()
width, height := size.X, size.Y
pixels := make([][][3]uint8, height)
for y := 0; y < height; y++ {
row := make([][3]uint8, width)
for x := 0; x < width; x++ {
View ellipse.go
package draw
import (
"image"
"image/color"
)
// ellipse defines the struct components required to apply the ellipse's formula.
type ellipse struct {
cx int // center x
View draw_mask.go
draw.DrawMask(source.(*image.NRGBA), source.Bounds(), ellipse, image.Point{}, mask, image.Point{}, draw.Over)
View index.html
<html>
<head>
<meta charset="utf-8" />
<script src="js/wasm_exec.js"></script>
<script type="text/javascript">
function fetchAndInstantiate(url, importObject) {
return fetch(url).then(response =>
response.arrayBuffer()
).then(bytes =>
WebAssembly.instantiate(bytes, importObject)
View Makefile
ifeq ($(OS),Windows_NT)
BROWSER = start
else
UNAME := $(shell uname -s)
ifeq ($(UNAME), Linux)
BROWSER = xdg-open
endif
ifeq ($(UNAME), Darwin)
BROWSER = open
endif
View wasm_webcam.go
// +build js,wasm
package main
import (
"fmt"
"github.com/esimov/pigo/wasm/canvas"
)
@esimov
esimov / caire_batch.go
Created Jul 2, 2019
Resize multiple images with Caire.
View caire_batch.go
package main
import (
"fmt"
"log"
"math/rand"
"os"
"runtime"
"strconv"
"time"