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: 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