1.1.0 • Published 2 years ago

normal-filter v1.1.0

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

normal-filter

Install

npm install normal-filter

Usage (Typescript)

Require

import { normal_map } from "normal-filter";

Types

let myImage = normal_map(bytes: Uint8Array): MyImage;

Real usage

const str2arrBuff = (str: string) => {
  var buf = new ArrayBuffer(str.length);
  var bufView = new Uint8Array(buf);
  for (var i = 0, strLen = str.length; i < strLen; i++) {
    bufView[i] = str.charCodeAt(i);
  }
  return bufView;
}

const createNormalTexture = (base64: string) => {
  let myImage = normal_map(str2arrBuff(atob(base64)));

  let imageData = new ImageData(
    new Uint8ClampedArray(myImage.raw_image()),
    myImage.width(),
    myImage.height()
  );

  let canvas = document.createElement('canvas');
  canvas.width = myImage.width();
  canvas.height = myImage.height();

  let ctx = canvas.getContext('2d')!;
  ctx.putImageData(imageData, 0, 0);
  myImage = null;
  imageData = null;

  return canvas;
};