| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 | import { Jimp, mkJGD } from '@jimp/test-utils';import configure from '@jimp/custom';import mask from '../src';const jimp = configure({ plugins: [mask] }, Jimp);describe('Mask', () => {  let imgSrcOpaq;  let imgSrcAlpa;  let maskGrayBig;  let maskGraySmall;  let maskColor;  before(done => {    Promise.all([      jimp.read(mkJGD('▴□▾□■□', '■▴■▾■□', '■□▴□▾□', '■□■▴■▾')),      jimp.read(mkJGD('▴▵▾▿', '▴▵▾▿', '▴▵▾▿')),      jimp.read(mkJGD('048840', '8CFFC8', '8CFFC8', '048840')),      jimp.read(mkJGD('0369', '369C', '69CF')),      jimp.read(mkJGD('▴▴▾▾', '▪▪▰▰', '□□□□'))    ])      .then(imgs => {        imgSrcOpaq = imgs[0];        imgSrcAlpa = imgs[1];        maskGrayBig = imgs[2];        maskGraySmall = imgs[3];        maskColor = imgs[4];        done();      })      .catch(done);  });  it('Affect opaque image with a gray mask with the same size', () => {    imgSrcOpaq      .clone()      .mask(maskGrayBig)      .getJGDSync()      .should.be.sameJGD({        width: 6,        height: 4,        data: [          0xff000000,          0xffffff44,          0x0000ff88,          0xffffff88,          0x00000044,          0xffffff00,          0x00000088,          0xff0000cc,          0x000000ff,          0x0000ffff,          0x000000cc,          0xffffff88,          0x00000088,          0xffffffcc,          0xff0000ff,          0xffffffff,          0x0000ffcc,          0xffffff88,          0x00000000,          0xffffff44,          0x00000088,          0xff000088,          0x00000044,          0x0000ff00        ]      });  });  it('Affect opaque image with a gray mask with the same size, blited', () => {    imgSrcOpaq      .clone()      .mask(maskGrayBig, 1, 1)      .getJGDSync()      .should.be.sameJGD({        width: 6,        height: 4,        data: [          0xff0000ff,          0xffffffff,          0x0000ffff,          0xffffffff,          0x000000ff,          0xffffffff,          0x000000ff,          0xff000000,          0x00000044,          0x0000ff88,          0x00000088,          0xffffff44,          0x000000ff,          0xffffff88,          0xff0000cc,          0xffffffff,          0x0000ffff,          0xffffffcc,          0x000000ff,          0xffffff88,          0x000000cc,          0xff0000ff,          0x000000ff,          0x0000ffcc        ]      });  });  it('Affect opaque image with a gray mask with the same size, blited negative', () => {    imgSrcOpaq      .clone()      .mask(maskGrayBig, -1, -1)      .getJGDSync()      .should.be.sameJGD({        width: 6,        height: 4,        data: [          0xff0000cc,          0xffffffff,          0x0000ffff,          0xffffffcc,          0x00000088,          0xffffffff,          0x000000cc,          0xff0000ff,          0x000000ff,          0x0000ffcc,          0x00000088,          0xffffffff,          0x00000044,          0xffffff88,          0xff000088,          0xffffff44,          0x0000ff00,          0xffffffff,          0x000000ff,          0xffffffff,          0x000000ff,          0xff0000ff,          0x000000ff,          0x0000ffff        ]      });  });  it('Affect opaque image with a smaller gray mask', () => {    imgSrcOpaq      .clone()      .mask(maskGraySmall)      .getJGDSync()      .should.be.sameJGD({        width: 6,        height: 4,        data: [          0xff000000,          0xffffff33,          0x0000ff66,          0xffffff99,          0x000000ff,          0xffffffff,          0x00000033,          0xff000066,          0x00000099,          0x0000ffcc,          0x000000ff,          0xffffffff,          0x00000066,          0xffffff99,          0xff0000cc,          0xffffffff,          0x0000ffff,          0xffffffff,          0x000000ff,          0xffffffff,          0x000000ff,          0xff0000ff,          0x000000ff,          0x0000ffff        ]      });  });  it('Affect opaque image with a smaller gray mask, blited', () => {    imgSrcOpaq      .clone()      .mask(maskGraySmall, 1, 1)      .getJGDSync()      .should.be.sameJGD({        width: 6,        height: 4,        data: [          0xff0000ff,          0xffffffff,          0x0000ffff,          0xffffffff,          0x000000ff,          0xffffffff,          0x000000ff,          0xff000000,          0x00000033,          0x0000ff66,          0x00000099,          0xffffffff,          0x000000ff,          0xffffff33,          0xff000066,          0xffffff99,          0x0000ffcc,          0xffffffff,          0x000000ff,          0xffffff66,          0x00000099,          0xff0000cc,          0x000000ff,          0x0000ffff        ]      });  });  it('Affect alpha image with a bigger gray mask', () => {    imgSrcAlpa      .clone()      .mask(maskGrayBig)      .getJGDSync()      .should.be.sameJGD({        width: 4,        height: 3,        data: [          0xff000000,          0xff000021,          0x0000ff88,          0x0000ff43,          0xff000088,          0xff000065,          0x0000ffff,          0x0000ff7f,          0xff000088,          0xff000065,          0x0000ffff,          0x0000ff7f        ]      });  });  it('Affect alpha image with a bigger gray mask, blited', () => {    imgSrcAlpa      .clone()      .mask(maskGrayBig, -1, -1)      .getJGDSync()      .should.be.sameJGD({        width: 4,        height: 3,        data: [          0xff0000cc,          0xff00007f,          0x0000ffff,          0x0000ff65,          0xff0000cc,          0xff00007f,          0x0000ffff,          0x0000ff65,          0xff000044,          0xff000043,          0x0000ff88,          0x0000ff21        ]      });  });  it('Affect opaque image with a colored mask', () => {    imgSrcOpaq      .clone()      .mask(maskColor, 1, 1)      .getJGDSync()      .should.be.sameJGD({        width: 6,        height: 4,        data: [          0xff0000ff,          0xffffffff,          0x0000ffff,          0xffffffff,          0x000000ff,          0xffffffff,          0x000000ff,          0xff000055,          0x00000055,          0x0000ff55,          0x00000055,          0xffffffff,          0x000000ff,          0xffffffaa,          0xff0000aa,          0xffffffaa,          0x0000ffaa,          0xffffffff,          0x000000ff,          0xffffffff,          0x000000ff,          0xff0000ff,          0x000000ff,          0x0000ffff        ]      });  });});
 |