bmp.test.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* eslint-disable no-control-regex */
  2. import { Jimp, getTestDir } from '@jimp/test-utils';
  3. import configure from '@jimp/custom';
  4. import bmp from '../src';
  5. const jimp = configure({ types: [bmp] }, Jimp);
  6. describe('BMP', () => {
  7. const imagesDir = getTestDir(__dirname) + '/images';
  8. it('load BMP', async () => {
  9. const image = await jimp.read(imagesDir + '/windows95.bmp');
  10. image.getPixelColor(10, 10).should.be.equal(0xeff7f7ff);
  11. image.getPixelColor(150, 80).should.be.equal(0x73add6ff);
  12. image.getPixelColor(190, 200).should.be.equal(0xf7c300ff);
  13. });
  14. it('export BMP', async () => {
  15. const image = await jimp.read({
  16. width: 3,
  17. height: 3,
  18. data: [
  19. 0xff0000ff,
  20. 0xff0080ff,
  21. 0xff00ffff,
  22. 0xff0080ff,
  23. 0xff00ffff,
  24. 0x8000ffff,
  25. 0xff00ffff,
  26. 0x8000ffff,
  27. 0x0000ffff
  28. ]
  29. });
  30. const buffer = await image.getBufferAsync('image/bmp');
  31. buffer.toString().should.match(/^BMZ\u0000/);
  32. });
  33. it('uses correct colors for BMP', async function() {
  34. this.timeout(4000);
  35. const expectedImg = await jimp.read(
  36. getTestDir(__dirname) + '/images/windows95.png'
  37. );
  38. const image = await jimp.read(
  39. getTestDir(__dirname) + '/images/windows95.bmp'
  40. );
  41. image.bitmap.data.should.be.deepEqual(expectedImg.bitmap.data);
  42. });
  43. });