Skip to content

Commit 1dbb5fd

Browse files
Add tests for images with icc profile
1 parent 3d07200 commit 1dbb5fd

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

tests/images/image.raw

2 MB
Binary file not shown.

tests/unit/image.spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import PDFDocument from '../../lib/document';
22
import fs from 'fs';
33
import JPEG from '../../lib/image/jpeg';
4+
import { logData } from './helpers';
45

56
describe('Image', function () {
67
/**
@@ -28,4 +29,49 @@ describe('Image', function () {
2829
expect(jpeg.height).toBe(500);
2930
expect(jpeg.orientation).toBe(1);
3031
});
32+
33+
test('support raw images with custom properties', () => {
34+
const data = new Uint8Array(fs.readFileSync('./tests/images/image.raw'));
35+
const profileData = fs.readFileSync('tests/profiles/eciCMYK_v2.icc');
36+
const docData = logData(document);
37+
document.iccProfile('KittlCMYK', profileData, 4, 'DeviceCMYK');
38+
const image = document.openImage(data, {
39+
isBitmap: true,
40+
width: 651,
41+
height: 643,
42+
channels: 5,
43+
hasAlphaChannel: true,
44+
colorSpace: 'KittlCMYK',
45+
});
46+
document.image(image, 0, 0);
47+
document.end();
48+
49+
expect(docData).toContainChunk([
50+
'<<\n' +
51+
'/Type /XObject\n' +
52+
'/Subtype /Image\n' +
53+
'/Height 643\n' +
54+
'/Width 651\n' +
55+
'/BitsPerComponent 8\n' +
56+
'/ColorSpace /DeviceGray\n' +
57+
'/Decode [0 1]\n' +
58+
'/Length 432\n' +
59+
'/Filter /FlateDecode\n' +
60+
'>>',
61+
]);
62+
63+
expect(docData).toContainChunk([
64+
'<<\n' +
65+
'/Type /XObject\n' +
66+
'/Subtype /Image\n' +
67+
'/Height 643\n' +
68+
'/Width 651\n' +
69+
'/BitsPerComponent 8\n' +
70+
'/ColorSpace /DeviceGray\n' +
71+
'/Decode [0 1]\n' +
72+
'/Length 432\n' +
73+
'/Filter /FlateDecode\n' +
74+
'>>',
75+
]);
76+
});
3177
});
37.5 KB
Loading

tests/visual/images.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'fs';
12
import { runDocTest } from './helpers';
23

34
describe('images', function () {
@@ -669,4 +670,21 @@ describe('images', function () {
669670
});
670671
});
671672
});
673+
674+
test('bitmap with icc profile', () => {
675+
return runDocTest({}, function (doc) {
676+
const data = new Uint8Array(fs.readFileSync('./tests/images/image.raw'));
677+
const profileData = fs.readFileSync('tests/profiles/eciCMYK_v2.icc');
678+
doc.iccProfile('KittlCMYK', profileData, 4, 'DeviceCMYK');
679+
const image = doc.openImage(data, {
680+
isBitmap: true,
681+
width: 651,
682+
height: 643,
683+
channels: 5,
684+
hasAlphaChannel: true,
685+
colorSpace: 'KittlCMYK',
686+
});
687+
doc.image(image, 0, 0);
688+
});
689+
});
672690
});

0 commit comments

Comments
 (0)