From ea6a4953a0ebc940e80475bb5a224a4ca5933081 Mon Sep 17 00:00:00 2001 From: Berk Ozkutuk Date: Sat, 4 Sep 2021 20:34:54 +0300 Subject: [PATCH 1/2] Add createImageDataWith --- src/Graphics/Canvas.js | 8 ++++++++ src/Graphics/Canvas.purs | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/src/Graphics/Canvas.js b/src/Graphics/Canvas.js index 1cae278..c1dce61 100644 --- a/src/Graphics/Canvas.js +++ b/src/Graphics/Canvas.js @@ -469,6 +469,14 @@ exports.createImageDataCopy = function(ctx) { }; }; +exports.createImageDataWith = function(arr) { + return function(sw) { + return function() { + return new ImageData(arr, sw); + }; + }; +}; + exports.drawImage = function(ctx) { return function(image_source) { return function(dx) { diff --git a/src/Graphics/Canvas.purs b/src/Graphics/Canvas.purs index 8e31dd6..1d0d6a1 100644 --- a/src/Graphics/Canvas.purs +++ b/src/Graphics/Canvas.purs @@ -94,6 +94,7 @@ module Graphics.Canvas , putImageDataFull , createImageData , createImageDataCopy + , createImageDataWith , imageDataWidth , imageDataHeight , imageDataBuffer @@ -634,6 +635,10 @@ foreign import createImageData :: Context2D -> Number -> Number -> Effect ImageD -- | Create a copy of an image data object. foreign import createImageDataCopy :: Context2D -> ImageData -> Effect ImageData +-- | Create an image data object given a `Uint8ClampedArray` containing the underlying pixel representation of the image. +-- | The height is inferred from the array's size and the given width. +foreign import createImageDataWith :: Uint8ClampedArray -> Int -> Effect ImageData + -- | Get the width of an `ImageData` object. foreign import imageDataWidth :: ImageData -> Int From 63cf5529000fd43dbb79c3de7de9688d3c4b0bcf Mon Sep 17 00:00:00 2001 From: Berk Ozkutuk Date: Sun, 5 Sep 2021 14:52:07 +0300 Subject: [PATCH 2/2] Add the change to the changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13ef5f1..768daef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based Breaking changes: New features: +- Added `createImageDataWith` (#81) Bugfixes: