Skip to content

Commit

Permalink
minor(examples): update pixel-basics
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 28, 2019
1 parent 969d6b8 commit 6d2414e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions examples/pixel-basics/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
ARGB4444,
canvas2d,
GRAY_ALPHA88,
GRAY8,
imagePromise,
PackedBuffer,
Expand All @@ -13,11 +13,16 @@ import LOGO from "../assets/logo-64.png";
Promise.all([IMG, LOGO].map(imagePromise)).then(([img, logo]) => {
// init 16bit packed RGB pixel buffer from image (resized to 256x256)
const buf = PackedBuffer.fromImage(img, RGB565, 256, 256);
// use Porter-Duff operator to blend logo into main image
PackedBuffer.fromImage(logo, ARGB4444).blend(SRC_OVER_I, buf, {
dx: 10,
dy: 10
});

// create grayscale buffer for logo and use Porter-Duff operator to
// composite with main image. Since the logo has transparency, we
// need to premultiply alpha first...
PackedBuffer.fromImage(logo, GRAY_ALPHA88)
.premultiply()
.blend(SRC_OVER_I, buf, {
dx: 10,
dy: 10
});

// extract sub-image
const region = buf.getRegion(32, 96, 128, 64);
Expand Down

0 comments on commit 6d2414e

Please sign in to comment.