Skip to content

Commit 60791cc

Browse files
authored
Add createImageDataWith (#81)
* Add createImageDataWith * Add the change to the changelog
1 parent 6f1518e commit 60791cc

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88

99
New features:
10+
- Added `createImageDataWith` (#81)
1011

1112
Bugfixes:
1213

src/Graphics/Canvas.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,14 @@ exports.createImageDataCopy = function(ctx) {
469469
};
470470
};
471471

472+
exports.createImageDataWith = function(arr) {
473+
return function(sw) {
474+
return function() {
475+
return new ImageData(arr, sw);
476+
};
477+
};
478+
};
479+
472480
exports.drawImage = function(ctx) {
473481
return function(image_source) {
474482
return function(dx) {

src/Graphics/Canvas.purs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ module Graphics.Canvas
9494
, putImageDataFull
9595
, createImageData
9696
, createImageDataCopy
97+
, createImageDataWith
9798
, imageDataWidth
9899
, imageDataHeight
99100
, imageDataBuffer
@@ -634,6 +635,10 @@ foreign import createImageData :: Context2D -> Number -> Number -> Effect ImageD
634635
-- | Create a copy of an image data object.
635636
foreign import createImageDataCopy :: Context2D -> ImageData -> Effect ImageData
636637

638+
-- | Create an image data object given a `Uint8ClampedArray` containing the underlying pixel representation of the image.
639+
-- | The height is inferred from the array's size and the given width.
640+
foreign import createImageDataWith :: Uint8ClampedArray -> Int -> Effect ImageData
641+
637642
-- | Get the width of an `ImageData` object.
638643
foreign import imageDataWidth :: ImageData -> Int
639644

0 commit comments

Comments
 (0)