diff --git a/test/_input/pnm/test.pbm b/test/_input/pnm/test.pbm new file mode 100644 index 0000000..73c7a5b --- /dev/null +++ b/test/_input/pnm/test.pbm @@ -0,0 +1,10 @@ +P1 +24 # PBM example +7 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 +0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 +0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0 +0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 +0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \ No newline at end of file diff --git a/test/_input/pnm/test.pgm b/test/_input/pnm/test.pgm new file mode 100644 index 0000000..ba47572 --- /dev/null +++ b/test/_input/pnm/test.pgm @@ -0,0 +1,10 @@ +P2 +24 7 +15 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0 +0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0 +0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0 +0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0 +0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \ No newline at end of file diff --git a/test/_input/pnm/test.ppm b/test/_input/pnm/test.ppm new file mode 100644 index 0000000..ecd1b91 --- /dev/null +++ b/test/_input/pnm/test.ppm @@ -0,0 +1,8 @@ +P3 +# example from the man page +4 4 +15 + 0 0 0 0 0 0 0 0 0 15 0 15 + 0 0 0 0 15 7 0 0 0 0 0 0 + 0 0 0 0 0 0 0 15 7 0 0 0 +15 0 15 0 0 0 0 0 0 0 0 0 \ No newline at end of file diff --git a/test/_input/pnm/z00n2c08.pnm b/test/_input/pnm/z00n2c08.pnm new file mode 100644 index 0000000..55da3c5 Binary files /dev/null and b/test/_input/pnm/z00n2c08.pnm differ diff --git a/test/_utils/test-section.ts b/test/_utils/test-section.ts index ff5960a..2b21cfc 100644 --- a/test/_utils/test-section.ts +++ b/test/_utils/test-section.ts @@ -12,6 +12,7 @@ export enum TestSection { ico, jpeg, png, + pnm, tiff, tga, transform, diff --git a/test/_utils/test-utils.ts b/test/_utils/test-utils.ts index ed708f1..dc3260d 100644 --- a/test/_utils/test-utils.ts +++ b/test/_utils/test-utils.ts @@ -47,6 +47,8 @@ export abstract class TestUtils { return 'jpg'; case TestSection.png: return 'png'; + case TestSection.pnm: + return 'pnm'; case TestSection.tiff: return 'tiff'; case TestSection.tga: diff --git a/test/format/format.pnm.test.ts b/test/format/format.pnm.test.ts new file mode 100644 index 0000000..f6bdc45 --- /dev/null +++ b/test/format/format.pnm.test.ts @@ -0,0 +1,38 @@ +/** @format */ + +import { encodePng, PnmDecoder } from '../../src'; +import { TestFolder } from '../_utils/test-folder'; +import { TestSection } from '../_utils/test-section'; +import { TestUtils } from '../_utils/test-utils'; + +describe('Format: PNM', () => { + const resFiles = TestUtils.listFiles(TestFolder.input, TestSection.pnm); + + for (const file of resFiles) { + test(`pnm ${file.fileName}`, () => { + const input = TestUtils.readFromFilePath(file.path); + const decoder = new PnmDecoder(); + + const isValidFile = decoder.isValidFile(input); + expect(isValidFile).toBeTruthy(); + + const image = decoder.decode({ + bytes: input, + }); + expect(image).toBeDefined(); + if (image === undefined) { + return; + } + + const output = encodePng({ + image: image, + }); + TestUtils.writeToFile( + TestFolder.output, + TestSection.pnm, + `${file.fileName}.png`, + output + ); + }); + } +});