├── .editorconfig
├── .eslintrc.js
├── .gitattributes
├── .gitignore
├── .npmignore
├── .travis.yml
├── LICENSE
├── README.md
├── check.js
├── e2e-test.js
├── executables
├── gitter-chatlog.md
└── win32
│ ├── api-ms-win-core-file-l1-2-0.dll
│ ├── api-ms-win-core-file-l2-1-0.dll
│ ├── api-ms-win-core-localization-l1-2-0.dll
│ ├── api-ms-win-core-processthreads-l1-1-1.dll
│ ├── api-ms-win-core-synch-l1-2-0.dll
│ ├── api-ms-win-core-timezone-l1-1-0.dll
│ ├── api-ms-win-crt-convert-l1-1-0.dll
│ ├── api-ms-win-crt-environment-l1-1-0.dll
│ ├── api-ms-win-crt-filesystem-l1-1-0.dll
│ ├── api-ms-win-crt-heap-l1-1-0.dll
│ ├── api-ms-win-crt-locale-l1-1-0.dll
│ ├── api-ms-win-crt-math-l1-1-0.dll
│ ├── api-ms-win-crt-multibyte-l1-1-0.dll
│ ├── api-ms-win-crt-runtime-l1-1-0.dll
│ ├── api-ms-win-crt-stdio-l1-1-0.dll
│ ├── api-ms-win-crt-string-l1-1-0.dll
│ ├── api-ms-win-crt-time-l1-1-0.dll
│ ├── api-ms-win-crt-utility-l1-1-0.dll
│ ├── encode.bat
│ ├── flif.exe
│ ├── msvcp140.dll
│ ├── ucrtbase.dll
│ ├── vcruntime140.dll
│ └── vcruntime140_app.dll
├── index.js
├── package-lock.json
├── package.json
├── sample
├── cat.flif
├── cat.png
├── catrun01.png
├── catrun02.png
├── catrun03.png
├── catrun04.png
├── catrun05.png
├── catrun06.png
├── kodim01.png
├── output.flif
└── sal.png
├── src
├── conversion
│ ├── argumentGroups
│ │ ├── advancedEncode.js
│ │ ├── advancedEncode.test.js
│ │ ├── commonDecode.js
│ │ ├── commonDecode.test.js
│ │ ├── commonEncode.js
│ │ ├── commonEncode.test.js
│ │ ├── commonEncodeDecode.js
│ │ └── commonEncodeDecode.test.js
│ ├── cli-api.txt
│ ├── decode.js
│ ├── decode.test.js
│ ├── encode.js
│ ├── encode.test.js
│ ├── transcode.js
│ └── transcode.test.js
├── helpers
│ ├── executablePath.js
│ ├── executablePath.test.js
│ ├── guesses.js
│ ├── runCommand.js
│ ├── runCommand.test.js
│ ├── runCommandSync.js
│ ├── runCommandSync.test.js
│ ├── verifyParams.js
│ ├── verifyParams.test.js
│ ├── verifyParams
│ │ ├── disallowQuality.js
│ │ ├── disallowQuality.test.js
│ │ ├── ensureInputOutputExist.js
│ │ ├── ensureInputOutputExist.test.js
│ │ ├── ensureParamsExist.js
│ │ ├── ensureParamsExist.test.js
│ │ ├── verifyAdaptive.js
│ │ ├── verifyAdaptive.test.js
│ │ ├── verifyAlphaGuess.js
│ │ ├── verifyAlphaGuess.test.js
│ │ ├── verifyAsync.js
│ │ ├── verifyAsync.test.js
│ │ ├── verifyCRC.js
│ │ ├── verifyCRC.test.js
│ │ ├── verifyChanceAlpha.js
│ │ ├── verifyChanceAlpha.test.js
│ │ ├── verifyChanceCutoff.js
│ │ ├── verifyChanceCutoff.test.js
│ │ ├── verifyChannelCompact.js
│ │ ├── verifyChannelCompact.test.js
│ │ ├── verifyChromaSubsample.js
│ │ ├── verifyChromaSubsample.test.js
│ │ ├── verifyColorBuckets.js
│ │ ├── verifyColorBuckets.test.js
│ │ ├── verifyDecodeQuality.js
│ │ ├── verifyDecodeQuality.test.js
│ │ ├── verifyEffort.js
│ │ ├── verifyEffort.test.js
│ │ ├── verifyEncodeQuality.js
│ │ ├── verifyEncodeQuality.test.js
│ │ ├── verifyFit.js
│ │ ├── verifyFit.test.js
│ │ ├── verifyFrameDelay.js
│ │ ├── verifyFrameDelay.test.js
│ │ ├── verifyFrameShape.js
│ │ ├── verifyFrameShape.test.js
│ │ ├── verifyGuess.js
│ │ ├── verifyGuess.test.js
│ │ ├── verifyInterlace.js
│ │ ├── verifyInterlace.test.js
│ │ ├── verifyKeepAlpha.js
│ │ ├── verifyKeepAlpha.test.js
│ │ ├── verifyKeepColorProfile.js
│ │ ├── verifyKeepColorProfile.test.js
│ │ ├── verifyKeepMetaData.js
│ │ ├── verifyKeepMetaData.test.js
│ │ ├── verifyKeepPalette.js
│ │ ├── verifyKeepPalette.test.js
│ │ ├── verifyManiacDivisor.js
│ │ ├── verifyManiacDivisor.test.js
│ │ ├── verifyManiacMinSize.js
│ │ ├── verifyManiacMinSize.test.js
│ │ ├── verifyManiacRepeats.js
│ │ ├── verifyManiacRepeats.test.js
│ │ ├── verifyManiacThreshold.js
│ │ ├── verifyManiacThreshold.test.js
│ │ ├── verifyMaxFrameLookBack.js
│ │ ├── verifyMaxFrameLookBack.test.js
│ │ ├── verifyMaxPaletteSize.js
│ │ ├── verifyMaxPaletteSize.test.js
│ │ ├── verifyOverwrite.js
│ │ ├── verifyOverwrite.test.js
│ │ ├── verifyResize.js
│ │ ├── verifyResize.test.js
│ │ ├── verifyScale.js
│ │ ├── verifyScale.test.js
│ │ ├── verifySubtractGreen.js
│ │ ├── verifySubtractGreen.test.js
│ │ ├── verifyYcocg.js
│ │ └── verifyYcocg.test.js
│ ├── warnUser.js
│ └── warnUser.test.js
├── information
│ ├── breakpoints.js
│ ├── breakpoints.test.js
│ ├── identify.js
│ ├── identify.test.js
│ ├── version.js
│ └── version.test.js
└── testers
│ ├── errorMessage.js
│ └── loopOverAllTestSets.js
├── test.js
└── try.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome: http://EditorConfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # Newline ending every file
7 | [*]
8 | end_of_line = lf
9 | insert_final_newline = true
10 |
11 | # Matches multiple files with brace expansion notation
12 | # Set default charset
13 | [*.{js,css,html}]
14 | charset = utf-8
15 |
16 | # 4 space indentation
17 | [*.{js,css,sass,scss}]
18 | indent_style = space
19 | indent_size = 4
20 |
21 | [*.{json}]
22 | indent_style = space
23 |
24 | [*.{html}]
25 | indent_style = space
26 | indent_size = 2
27 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | 'env': {
3 | 'browser': true,
4 | 'node': true
5 | },
6 | 'extends': 'eslint:recommended',
7 | 'rules': {
8 | 'brace-style': ['error', '1tbs', { 'allowSingleLine': true }],
9 | 'comma-dangle': ['error', 'never'],
10 | 'comma-spacing': ['error', { 'before': false, 'after': true }],
11 | 'comma-style': ['error', 'last'],
12 | 'curly': ['error'],
13 | 'indent': ['error', 4, { 'SwitchCase': 1 }],
14 | 'keyword-spacing': ['error', { 'before': true, 'after': true }],
15 | 'no-multi-spaces': ['error'],
16 | 'no-ternary': ['error'],
17 | 'no-unused-vars': ['error', { 'args': 'all' }],
18 | 'one-var': ['error', 'never'],
19 | 'quotes': ['error', 'single'],
20 | 'semi': ['error', 'always'],
21 | 'space-before-blocks': ['error', 'always'],
22 | 'space-before-function-paren': ['error', 'always'],
23 | 'space-in-parens': ['error', 'never'],
24 | 'space-infix-ops': ['error'],
25 | 'spaced-comment': ['error', 'always']
26 | }
27 | };
28 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=LF
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 |
11 | # Directory for instrumented libs generated by jscoverage/JSCover
12 | lib-cov
13 |
14 | # Coverage directory used by tools like istanbul
15 | coverage
16 |
17 | # nyc test coverage
18 | .nyc_output
19 |
20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21 | .grunt
22 |
23 | # node-waf configuration
24 | .lock-wscript
25 |
26 | # Compiled binary addons (http://nodejs.org/api/addons.html)
27 | build/Release
28 |
29 | # Dependency directories
30 | node_modules
31 | jspm_packages
32 |
33 | # Optional npm cache directory
34 | .npm
35 |
36 | # Optional REPL history
37 | .node_repl_history
38 |
39 | # Manually added
40 | .DS_Store
41 | thumbs.db
42 | sample/decode-test.png
43 | sample/encode-test.flif
44 | sample/encode-anim-test.flif
45 | sample/viewflif.exe
46 | sample/decode-encode-test.png
47 | sample/try-a.png
48 | sample/try-b.flif
49 | sample/try-c.png
50 | sample/check.flif
51 | sample/check.png
52 | sample/flif.exe
53 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .git/
2 | node_modules/
3 | sample/
4 | src/conversion/cli-api.txt
5 | src/**/*.test.js
6 | .editorconfig
7 | .eslintrc.js
8 | .gitattributes
9 | .gitignore
10 | .npmignore
11 | .travis.yml
12 | check.js
13 | e2e-test.js
14 | README.md
15 | test.js
16 | try.js
17 | sample/flif.exe
18 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: required
2 | language: node_js
3 | node_js:
4 | - "8"
5 | install:
6 | - npm install
7 | script:
8 | - npm run lint
9 | - npm run test
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 FLIF
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/check.js:
--------------------------------------------------------------------------------
1 | // This file exists to check the limits of arguments
2 |
3 | var fs = require('fs');
4 | var nodeFLIF = require('./index.js');
5 |
6 | function runCommandSync (args) {
7 | var exec = require('child_process').execSync;
8 | var wasmPath = require.resolve('flif-wasm');
9 | var executable = 'node "' + wasmPath + '"';
10 |
11 | if (process.platform === 'win32') {
12 | executable = nodeFLIF.executablePath();
13 | }
14 |
15 | var executableAndArgs = executable + ' ' + args;
16 | var child = exec(executableAndArgs);
17 |
18 | return child.toString().trim();
19 | }
20 |
21 | function openImage (args) {
22 | var exec = require('child_process').execSync;
23 | exec(args);
24 | }
25 |
26 | try { fs.unlinkSync('./sample/check.flif'); } catch (err) {}
27 | try { fs.unlinkSync('./sample/check.png'); } catch (err) {}
28 |
29 | // Should return flif.exe version
30 | var version = runCommandSync('-v');
31 | console.log(version);
32 |
33 | // Should convert cat.png to check.flif
34 | // var encode = runCommandSync('-e ./sample/catrun01.png ./sample/catrun02.png ./sample/catrun03.png ./sample/catrun04.png ./sample/catrun05.png ./sample/catrun06.png ./sample/check.flif');
35 | var encode = runCommandSync('-e -HX ./sample/catrun01.png ./sample/check.flif');
36 | console.log(encode);
37 |
38 | // runCommandSync('-t ./sample/catrun01.flif ./sample/cat.flif potato.flif');
39 |
40 | // good
41 | // P-32000 P32000
42 | // bad
43 | // P-32001 P32001
44 | // https://github.com/FLIF-hub/FLIF/blob/v0.3/src/flif.cpp#L580
45 |
46 | // Log out true/false if file exists
47 | console.log('Does ./sample/check.flif exist?', fs.existsSync('./sample/check.flif'));
48 |
49 |
50 | // Should convert cat.flif to check.png
51 | var decode = runCommandSync('-d ./sample/check.flif ./sample/check.png');
52 | console.log(decode);
53 |
54 | // Log out true/false if file exists
55 | console.log('Does ./sample/check.png exist?', fs.existsSync('./sample/check.png'));
56 |
57 | openImage('sample\\check.png');
58 |
59 |
60 |
--------------------------------------------------------------------------------
/e2e-test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-console */
2 |
3 | var nodeFLIF = require('./index.js');
4 |
5 | function runCommandSync (executable, args) {
6 | var exec = require('child_process').execSync;
7 | var executableAndArgs = executable + ' ' + args;
8 | var child = exec(executableAndArgs);
9 | return child.toString().trim();
10 | }
11 |
12 |
13 | // Test converting 1 flif to 1 png
14 |
15 | var decodeParams = {
16 | input: './sample/cat.flif',
17 | output: './sample/decode-test.png',
18 | overwrite: true
19 | };
20 |
21 | nodeFLIF.decode(decodeParams, function (data) {
22 | console.log('Decode cat.flif -> decode-test.png finished');
23 | if (data) {
24 | console.log(data);
25 | }
26 | });
27 |
28 |
29 | // Test converting 1 png to 1 flif
30 |
31 | var encodeParams = {
32 | input: './sample/cat.png',
33 | output: './sample/encode-test.flif',
34 | overwrite: true,
35 | async: false,
36 | // Pixel predictor for each plane: 'average', 'median gradient', 'median number', 'mixed', default is 'heuristically'
37 | guess: {
38 | y: 'heuristically',
39 | co: 'heuristically',
40 | cg: 'heuristically',
41 | alpha: 'heuristically',
42 | lookback: 'heuristically'
43 | }
44 | };
45 |
46 | console.log(nodeFLIF.encode(encodeParams));
47 | console.log('Encode cat.png -> encode-test.flif finished.');
48 |
49 |
50 | // Verify the above flif was created properly by decoding to png
51 |
52 | var decodeParams2 = {
53 | input: './sample/encode-test.flif',
54 | output: './sample/decode-encode-test.png',
55 | overwrite: true
56 | };
57 |
58 | nodeFLIF.decode(decodeParams2, function (data) {
59 | console.log('Decode encode-test.flif -> decode-encode-test.png finished');
60 | if (data) {
61 | console.log(data);
62 | }
63 | });
64 |
65 |
66 | // Identify data in a flif
67 |
68 | var catData = nodeFLIF.identify('./sample/cat.flif');
69 | console.log(catData);
70 | console.log('Identified cat.flif');
71 |
72 |
73 | // Create an animated flif
74 |
75 | var encodeAnimParams = {
76 | input: [
77 | './sample/catrun01.png',
78 | './sample/catrun02.png',
79 | './sample/catrun03.png',
80 | './sample/catrun04.png',
81 | './sample/catrun05.png',
82 | './sample/catrun06.png'
83 | ],
84 | output: './sample/encode-anim-test.flif',
85 | overwrite: true,
86 | frameDelay: [0]
87 | };
88 |
89 | nodeFLIF.encode(encodeAnimParams, function (data) {
90 | console.log('Encode catrun01-06.png -> encode-anim-test.flif finished.');
91 | if (data) {
92 | console.log(data);
93 | }
94 | });
95 |
96 | // Run Libflif
97 | var open = require('open');
98 | open('http://localhost:8000/node_modules/libflif.js/index.html');
99 | runCommandSync('node', './node_modules/npm-free-server/dist/server.js');
100 |
--------------------------------------------------------------------------------
/executables/gitter-chatlog.md:
--------------------------------------------------------------------------------
1 | **fherzog2 @fherzog2 May 14 14:03**
2 | > If you're on Windows, you just need to edit these lines:
3 | >
4 | > * https://github.com/FLIF-hub/FLIF/blob/master/build/MSVC/Makefile#L11
5 | > * https://github.com/FLIF-hub/FLIF/blob/master/build/MSVC/dl_make_vs.bat#L54
6 | >
7 | > Set `Rt = MT` and it will be compiled with static runtime.
8 |
9 | **The Jared Wilcurt @TheJaredWilcurt May 14 14:04**
10 | > Cool, but what about for Linux and OSX builds
11 |
12 | **fherzog2 @fherzog2 May 14 14:15**
13 | > Don't know for sure about Linux and OSX
14 | > But on Linux, shouldn't the user already have installed all requirements. They are pretty basic.
15 |
16 | **Leo Izen @thebombzen May 14 14:19**
17 | > the question is relevant to `C++`
18 | > the way you'd do it is by compiling each `.cpp` file to an object file (`.o`) without linking by using `g++ -c`
19 | > then once you have serveral .so files, you put them in an ARchive with "ar" and ranlib it
20 | > which gives you a static library
21 | > then you can run `g++ -shared -o libflif.so libflif.a` to link it into a shared library or you can run `g++ -o flif flif.cpp -L. -lflif` to create the flif binary from the static library
22 |
23 | **The Jared Wilcurt @TheJaredWilcurt 01:06**
24 | > @thebombzen I have no idea how to do that or what most of that even means. Would you be able to create a script file that automates that. Then I can do the builds on each new release.
25 |
26 | **Leo Izen @thebombzen 01:09**
27 | > this is why I thought it was relevant to ask the `C++` people
28 | > If you have a program composed of several JavaScript source files, functions in one can be referenced from another. This is basically what "linking" is with `C++`, the compilation process is a 2-step process. first, `g++` (or whatever you're using) turns the source into an object file by compiling `C++` code to machine code. But an object file isn't actually something you can do anything with. It contains the machine code for everything in the source file, and basically nothing else.
29 | > Linking is the process of taking several object files or libraries and putting them together to get a useful executable.
30 | >
31 | > By default the compiler uses a shortcut and doesn't actually dump the object files to disk. But in order to do what you want, you'd need to tell it not to do that.
32 | > If compile all the `.cpp` files to objects, and then from there you can do lot of things with them. You could create a shared library like libflif, you could create a flif executable, etc.
33 | >
34 | > Currently the makefile creates a shared library, and then has flif reference that library. You said you don't want that. So you'd need to have compile the `C++` sources directly to the flif executable without passing GO.
35 | > A long-term solution is to compile the `C++` sources to object files so you don't have to compile them twice, but if you really want to, then well
36 | >
37 | > **TLDR:** Go to the Makefile and change this line:
38 | > ```
39 | > $(CXX) -std=gnu++11 $(CXXFLAGS) $(OPTIMIZATIONS) -g0 -Wall flif.cpp $(LDFLAGS) -L. -lflif -o flif
40 | > ```
41 | > to this one:
42 | > ```
43 | > $(CXX) -std=gnu++11 $(CXXFLAGS) $(OPTIMIZATIONS) -g0 -Wall $(FILES_CPP) flif.cpp $(LDFLAGS) -o flif
44 | > ```
45 | > although on Linux I recommend something else
46 |
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-core-file-l1-2-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-core-file-l1-2-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-core-file-l2-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-core-file-l2-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-core-localization-l1-2-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-core-localization-l1-2-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-core-processthreads-l1-1-1.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-core-processthreads-l1-1-1.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-core-synch-l1-2-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-core-synch-l1-2-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-core-timezone-l1-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-core-timezone-l1-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-crt-convert-l1-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-crt-convert-l1-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-crt-environment-l1-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-crt-environment-l1-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-crt-filesystem-l1-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-crt-filesystem-l1-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-crt-heap-l1-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-crt-heap-l1-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-crt-locale-l1-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-crt-locale-l1-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-crt-math-l1-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-crt-math-l1-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-crt-multibyte-l1-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-crt-multibyte-l1-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-crt-runtime-l1-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-crt-runtime-l1-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-crt-stdio-l1-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-crt-stdio-l1-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-crt-string-l1-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-crt-string-l1-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-crt-time-l1-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-crt-time-l1-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/api-ms-win-crt-utility-l1-1-0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/api-ms-win-crt-utility-l1-1-0.dll
--------------------------------------------------------------------------------
/executables/win32/encode.bat:
--------------------------------------------------------------------------------
1 | :: You can drag/drop an image onto this file to have it encode to flif
2 | SET a=%~1
3 | SET b=.flif
4 | SET c=%a%%b%
5 | flif.exe -e %a% %c%
6 |
--------------------------------------------------------------------------------
/executables/win32/flif.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/flif.exe
--------------------------------------------------------------------------------
/executables/win32/msvcp140.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/msvcp140.dll
--------------------------------------------------------------------------------
/executables/win32/ucrtbase.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/ucrtbase.dll
--------------------------------------------------------------------------------
/executables/win32/vcruntime140.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/vcruntime140.dll
--------------------------------------------------------------------------------
/executables/win32/vcruntime140_app.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/executables/win32/vcruntime140_app.dll
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * This file acts as the API for node-flif. It decides what
3 | * is publically accessible to users.
4 | */
5 | var nodeFLIF = {
6 |
7 | // //////////////////////////// //
8 | // HELPER METHODS //
9 | // //////////////////////////// //
10 |
11 | /**
12 | * Detect the user's OS and architecture to
13 | * generate the correct path to the flif
14 | * executable that will work for them.
15 | *
16 | * @return {string} Path to the correct flif.exe
17 | */
18 | 'executablePath': require('./src/helpers/executablePath.js'),
19 |
20 |
21 | // //////////////////////////// //
22 | // FILE CONVERSION //
23 | // //////////////////////////// //
24 |
25 | 'convert': function (params, src, callback) {
26 | if (!src || typeof(src) !== 'string' || (src !== 'encode' && src !== 'decode' && src !== 'transcode')) {
27 | throw 'The src argument must be encode, decode, or transcode.';
28 | }
29 | if (callback && typeof(callback) !== 'function') {
30 | // Although this is actually the 3rd arg in this function, the user will only be passing in 2 when running en/de/trans
31 | throw 'The second argument in node-flif.' + src + ' is optional. However if used, it must be a function.';
32 | }
33 |
34 | var buildArgs = require('./src/conversion/' + src + '.js');
35 | var args = buildArgs(params);
36 |
37 | if (args === false) {
38 | throw 'ERROR: node-flif was unable to complete.';
39 | }
40 |
41 | if (params.async === false) {
42 | var runCommandSync = require('./src/helpers/runCommandSync.js');
43 | return runCommandSync(args);
44 | } else {
45 | var runCommand = require('./src/helpers/runCommand.js');
46 | if (callback && typeof(callback) === 'function') {
47 | runCommand(args, callback);
48 | } else {
49 | runCommand(args);
50 | }
51 | }
52 | },
53 |
54 | /**
55 | * Encodes a PNG, PNM, PPM, PGM, PBM, or PAM to a FLIF.
56 | * @param {object} params Parameters for the encoding passed in by the user.
57 | * @param {function} callback Optional callback function, ignored if async param is false
58 | */
59 | 'encode': function (params, callback) {
60 | this.convert(params, 'encode', callback);
61 | },
62 | /**
63 | * Decodes a FLIF to a PNG, PNM, PPM, PGM, PBM, or PAM.
64 | * @param {object} params Parameters for the decoding passed in by the user.
65 | * @param {function} callback Optional callback function, ignored if async param is false
66 | */
67 | 'decode': function (params, callback) {
68 | this.convert(params, 'decode', callback);
69 | },
70 | /**
71 | * Transcodes a FLIF to a new FLIF.
72 | * @param {object} params Parameters for the transcoding passed in by the user.
73 | * @param {function} callback Optional callback function, ignored if async param is false
74 | */
75 | 'transcode': function (params, callback) {
76 | this.convert(params, 'transcode', callback);
77 | },
78 |
79 |
80 | // //////////////////////////// //
81 | // INFORMATION //
82 | // //////////////////////////// //
83 |
84 | /**
85 | * Does not decode, just returns metadata about the breakpoints
86 | * of interlaced flifs. This data can be used to truncate a file
87 | * at different points. The breakpoints, or "truncation offsets",
88 | * are for truncations at scales 1:8, 1:4, 1:2.
89 | * This function runs synchronously.
90 | * Non-interlaced flifs will return an empty object.
91 | *
92 | * @param {string} file Filepath to the flif image.
93 | * @return {object} An object like the example below:
94 | * {
95 | offsetStart: 11,
96 | eighth: 8080,
97 | fourth: 24900,
98 | half: 90422
99 | }
100 | */
101 | 'breakpoints': require('./src/information/breakpoints.js'),
102 |
103 | /**
104 | * Does not decode, just identifies the input flif file.
105 | *
106 | * @param {string} file The path to the flif file to inspect
107 | * @return {object} Data about the provided flif, including:
108 | * name, dimensions, color, interlace, size
109 | */
110 | 'identify': require('./src/information/identify.js'),
111 |
112 | /**
113 | * Returns the versions of node-flif and the flif executable.
114 | * @return {object} Contains keys for nodeFLIF and flif that contain a string of the versions.
115 | */
116 | 'version': require('./src/information/version.js')
117 | };
118 |
119 | module.exports = nodeFLIF;
120 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "node-flif",
3 | "version": "1.0.1",
4 | "flifVersion": "0.3.0",
5 | "description": "A Node.js wrapper for the FLIF executable.",
6 | "main": "index.js",
7 | "engines": {
8 | "node": ">=1.0.0"
9 | },
10 | "scripts": {
11 | "start": "node index.js",
12 | "installer": "npm install --loglevel=error",
13 | "lint": "eslint --config=.eslintrc.js index.js e2e-test.js test.js src/**/*.js",
14 | "fix": "eslint --fix --config=.eslintrc.js index.js e2e-test.js test.js src/**/*.js",
15 | "debug": "node --inspect-brk test.js",
16 | "test": "node test.js"
17 | },
18 | "repository": {
19 | "type": "git",
20 | "url": "git+https://github.com/FLIF-hub/node-flif.git"
21 | },
22 | "keywords": [
23 | "flif",
24 | "node",
25 | "lossless",
26 | "image-compression",
27 | "image-conversion",
28 | "encode",
29 | "decode",
30 | "convert"
31 | ],
32 | "dependencies": {
33 | "flif-wasm": "^1.0.7",
34 | "root-require": "^0.3.1"
35 | },
36 | "devDependencies": {
37 | "eslint": "^4.17.0",
38 | "libflif.js": "github:SaschaNaz/libflif.js#master",
39 | "npm-free-server": "^1.1.0",
40 | "open": "0.0.5",
41 | "pre-commit": "^1.2.2"
42 | },
43 | "author": "The Jared Wilcurt",
44 | "license": "MIT",
45 | "licenses": [
46 | {
47 | "type": "MIT",
48 | "url": "https://github.com/FLIF-hub/node-flif/blob/master/LICENSE"
49 | }
50 | ],
51 | "bugs": {
52 | "url": "https://github.com/FLIF-hub/node-flif/issues"
53 | },
54 | "homepage": "https://github.com/FLIF-hub/node-flif#readme",
55 | "pre-commit": [
56 | "test",
57 | "lint"
58 | ]
59 | }
60 |
--------------------------------------------------------------------------------
/sample/cat.flif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/sample/cat.flif
--------------------------------------------------------------------------------
/sample/cat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/sample/cat.png
--------------------------------------------------------------------------------
/sample/catrun01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/sample/catrun01.png
--------------------------------------------------------------------------------
/sample/catrun02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/sample/catrun02.png
--------------------------------------------------------------------------------
/sample/catrun03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/sample/catrun03.png
--------------------------------------------------------------------------------
/sample/catrun04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/sample/catrun04.png
--------------------------------------------------------------------------------
/sample/catrun05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/sample/catrun05.png
--------------------------------------------------------------------------------
/sample/catrun06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/sample/catrun06.png
--------------------------------------------------------------------------------
/sample/kodim01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/sample/kodim01.png
--------------------------------------------------------------------------------
/sample/output.flif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/sample/output.flif
--------------------------------------------------------------------------------
/sample/sal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FLIF-hub/node-flif/94ab62a3c0554d070ef35bc8022d750d6be7135c/sample/sal.png
--------------------------------------------------------------------------------
/src/conversion/argumentGroups/advancedEncode.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-regex-spaces */
2 |
3 | /**
4 | * Advanced arguments used during Encodes.
5 | * @param {object} params Parameters for the encoding passed in by the user.
6 | * @return {string} The arguments to be passed into the CLI
7 | */
8 | function advancedEncode (params) {
9 | var maxPaletteSize = '';
10 | var colorBuckets = '';
11 | var channelCompact = '';
12 | var ycocg = '';
13 | var subtractGreen = '';
14 | var frameShape = '';
15 | var maxFrameLookBack = '';
16 | var maniacRepeats = '';
17 | var maniacThreshold = '';
18 | var maniacDivisor = '';
19 | var maniacMinSize = '';
20 | var chanceCutoff = '';
21 | var chanceAlpha = '';
22 | var adaptive = '';
23 | var guess = '';
24 | var alphaGuess = '';
25 | var chromaSubsample = '';
26 |
27 | if (params.maxPaletteSize) {
28 | maxPaletteSize = '-P' + parseInt(params.maxPaletteSize);
29 | }
30 | if (params.colorBuckets === false) {
31 | colorBuckets = '-B';
32 | }
33 | if (params.colorBuckets === true) {
34 | colorBuckets = '-A';
35 | }
36 | if (params.colorBuckets === 'auto') {
37 | colorBuckets = '';
38 | }
39 | if (params.channelCompact === false) {
40 | channelCompact = '-C';
41 | }
42 | if (params.ycocg === false) {
43 | ycocg = '-Y';
44 | }
45 | if (params.subtractGreen === false) {
46 | subtractGreen = '-W';
47 | }
48 | if (params.frameShape === false) {
49 | frameShape = '-S';
50 | }
51 | if (params.maxFrameLookBack) {
52 | maxFrameLookBack = '-L' + parseInt(params.maxFrameLookBack);
53 | }
54 | if (params.maniacRepeats) {
55 | maniacRepeats = '-R' + parseInt(params.maniacRepeats);
56 | }
57 | if (parseInt(params.maniacThreshold) > -1) {
58 | maniacThreshold = '-T' + parseInt(params.maniacThreshold);
59 | }
60 | if (params.maniacDivisor) {
61 | maniacDivisor = '-D' + parseInt(params.maniacDivisor);
62 | }
63 | if (params.maniacMinSize) {
64 | maniacMinSize = '-M' + parseInt(params.maniacMinSize);
65 | }
66 | if (params.chanceCutoff) {
67 | chanceCutoff = '-X' + parseInt(params.chanceCutoff);
68 | }
69 | if (params.chanceAlpha) {
70 | chanceAlpha = '-Z' + parseInt(params.chanceAlpha);
71 | }
72 | if (params.adaptive) {
73 | adaptive = '-U';
74 | if (Array.isArray(params.input)) {
75 | params.input.push(params.adaptive);
76 | } else {
77 | var newInput = [];
78 | newInput.push(params.input);
79 | newInput.push(params.adaptive);
80 | params.input = newInput;
81 | }
82 | }
83 | if (params.guess) {
84 | var guessDefault = 'heuristically';
85 |
86 | var y = params.guess.y || guessDefault;
87 | var co = params.guess.co || guessDefault;
88 | var cg = params.guess.cg || guessDefault;
89 | var alpha = params.guess.alpha || guessDefault;
90 | var lookback = params.guess.lookback || guessDefault;
91 |
92 | var planes = [y, co, cg, alpha, lookback];
93 |
94 | guess = '-G';
95 |
96 | var planeMap = {
97 | 'heuristically': '?',
98 | 'average': '0',
99 | 'median gradient': '1',
100 | 'median number': '2',
101 | 'mixed': 'X'
102 | };
103 |
104 | // -G => -G?012X || -G????? || -G11111 || etc.
105 | for (var i = 0; i < planes.length; i++) {
106 | var plane = planes[i];
107 | guess = guess + planeMap[plane];
108 | }
109 | }
110 | if (!params.keepAlpha) {
111 | if (params.alphaGuess === 'average') {
112 | alphaGuess = '-H0';
113 | } else if (params.alphaGuess === 'median gradient') {
114 | alphaGuess = '-H1';
115 | } else if (params.alphaGuess === 'median neighbors') {
116 | alphaGuess = '-H2';
117 | }
118 | }
119 | if (params.chromaSubsample === true) {
120 | chromaSubsample = '-J';
121 | }
122 |
123 | var args = [
124 | maxPaletteSize,
125 | colorBuckets,
126 | channelCompact,
127 | ycocg,
128 | subtractGreen,
129 | frameShape,
130 | maxFrameLookBack,
131 | maniacRepeats,
132 | maniacThreshold,
133 | maniacDivisor,
134 | maniacMinSize,
135 | chanceCutoff,
136 | chanceAlpha,
137 | adaptive,
138 | guess,
139 | alphaGuess,
140 | chromaSubsample
141 | ].join(' ');
142 |
143 | args = args.replace(/ +/g, ' ');
144 | args = args.trim();
145 |
146 | return args;
147 | }
148 |
149 | module.exports = advancedEncode;
150 |
--------------------------------------------------------------------------------
/src/conversion/argumentGroups/commonDecode.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-regex-spaces */
2 |
3 | /**
4 | * Commonly used arguments used during Decodes.
5 | * @param {object} params Parameters for the decoding passed in by the user.
6 | * @return {string} The arguments to be passed into the CLI
7 | */
8 | function commonDecode (params) {
9 | var decodeQuality = '';
10 | var scale = '';
11 | var resize = '';
12 | var fit = '';
13 |
14 | if (parseInt(params.decodeQuality) < 101) {
15 | decodeQuality = '-q=' + parseInt(params.decodeQuality);
16 | }
17 | if (params.scale) {
18 | scale = '-s=' + parseInt(params.scale);
19 | }
20 | if (params.resize) {
21 | resize = '-r=' + parseInt(params.resize.width) + 'x' + parseInt(params.resize.height);
22 | }
23 | if (params.fit) {
24 | fit = '-f=' + parseInt(params.fit.width) + 'x' + parseInt(params.fit.height);
25 | }
26 |
27 | var args = [
28 | decodeQuality,
29 | scale,
30 | resize,
31 | fit
32 | ].join(' ');
33 |
34 | args = args.replace(/ +/g, ' ');
35 | args = args.trim();
36 |
37 | return args;
38 | }
39 |
40 | module.exports = commonDecode;
41 |
--------------------------------------------------------------------------------
/src/conversion/argumentGroups/commonDecode.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'commonDecode';
6 | var testData = [
7 | { expected: '-q=0', arguments: [{decodeQuality: 0 }] },
8 | { expected: '-q=1', arguments: [{decodeQuality: 1 }] },
9 | { expected: '-q=50', arguments: [{decodeQuality: 50 }] },
10 | { expected: '-q=100', arguments: [{decodeQuality: 100 }] },
11 | { expected: '-s=1', arguments: [{scale: 1 }] },
12 | { expected: '-s=2', arguments: [{scale: 2 }] },
13 | { expected: '-s=4', arguments: [{scale: 4 }] },
14 | { expected: '-s=8', arguments: [{scale: 8 }] },
15 | { expected: '-s=16', arguments: [{scale: 16 }] },
16 | { expected: '-s=32', arguments: [{scale: 32 }] },
17 | { expected: '-r=1x1', arguments: [{resize: {width:1, height:1} }] },
18 | { expected: '-f=1x1', arguments: [{fit: {width:1, height:1} }] }
19 | ];
20 |
21 | runAllTests(testName, 'conversion/argumentGroups', testData);
22 |
23 | return [testName, testData.length];
24 | }
25 |
26 | module.exports = test;
27 |
--------------------------------------------------------------------------------
/src/conversion/argumentGroups/commonEncode.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-regex-spaces */
2 |
3 | /**
4 | * Commonly used arguments used for Encodes.
5 | * @param {object} params Parameters for the encoding passed in by the user.
6 | * @return {string} The arguments to be passed into the CLI
7 | */
8 | function commonEncode (params) {
9 | var encodeQuality = '';
10 | var effort = '';
11 | var interlace = '';
12 | var keepAlpha = '';
13 | var frameDelay = '';
14 |
15 | if (parseInt(params.encodeQuality, 10) < 101) {
16 | encodeQuality = '-Q' + parseInt(params.encodeQuality, 10);
17 | }
18 | if (parseInt(params.effort) < 101) {
19 | effort = '-E' + parseInt(params.effort);
20 | }
21 | if (params.interlace === false) {
22 | interlace = '-N';
23 | }
24 | if (params.interlace === true) {
25 | interlace = '-I';
26 | }
27 | if (params.interlace === 'auto') {
28 | interlace = '';
29 | }
30 | if (params.keepAlpha === true) {
31 | keepAlpha = '-K';
32 | }
33 | if (params.frameDelay) {
34 | frameDelay = '-F' + params.frameDelay.join(',');
35 | }
36 |
37 | var args = [
38 | effort,
39 | interlace,
40 | encodeQuality,
41 | keepAlpha,
42 | frameDelay
43 | ].join(' ');
44 |
45 | args = args.replace(/ +/g, ' ');
46 | args = args.trim();
47 |
48 | return args;
49 | }
50 |
51 | module.exports = commonEncode;
52 |
--------------------------------------------------------------------------------
/src/conversion/argumentGroups/commonEncode.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'commonEncode';
6 | var testData = [
7 | { expected: '-E0', arguments: [{ effort: 0 }] },
8 | { expected: '-E1', arguments: [{ effort: 1 }] },
9 | { expected: '-E50', arguments: [{ effort: 50 }] },
10 | { expected: '-E100', arguments: [{ effort: 100 }] },
11 | { expected: '-I', arguments: [{ interlace: true }] },
12 | { expected: '-N', arguments: [{ interlace: false }] },
13 | { expected: '', arguments: [{ interlace: 'auto' }] },
14 | { expected: '-Q0', arguments: [{ encodeQuality: 0 }] },
15 | { expected: '-Q1', arguments: [{ encodeQuality: 1 }] },
16 | { expected: '-Q50', arguments: [{ encodeQuality: 50 }] },
17 | { expected: '-Q100', arguments: [{ encodeQuality: 100 }] },
18 | { expected: '-K', arguments: [{ keepAlpha: true }] },
19 | { expected: '', arguments: [{ keepAlpha: false }] },
20 | { expected: '-F100', arguments: [{ frameDelay: [100] }] },
21 | { expected: '-F1,2', arguments: [{ frameDelay: [1, 2] }] }
22 | ];
23 |
24 | runAllTests(testName, 'conversion/argumentGroups', testData);
25 |
26 | return [testName, testData.length];
27 | }
28 |
29 | module.exports = test;
30 |
--------------------------------------------------------------------------------
/src/conversion/argumentGroups/commonEncodeDecode.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-regex-spaces */
2 |
3 | /**
4 | * Commonly used arguments used by both Encodes and Decodes.
5 | * @param {object} params Parameters for the **coding passed in by the user.
6 | * @return {string} The arguments to be passed into the CLI
7 | */
8 | function commonEncodeDecode (params) {
9 | var crc = '';
10 | var keepMetaData = '';
11 | var keepColorProfile = '';
12 | var overwrite = '';
13 | var keepPalette = '';
14 |
15 | // Common (Encode/Decode)
16 | if (params.crc === false) {
17 | crc = '-c';
18 | }
19 | if (params.keepMetaData === false) {
20 | keepMetaData = '-m';
21 | }
22 | if (params.keepColorProfile === false) {
23 | keepColorProfile = '-p';
24 | }
25 | if (params.overwrite === true) {
26 | overwrite = '-o';
27 | }
28 | if (params.keepPalette === true) {
29 | keepPalette = '-k';
30 | }
31 |
32 | var args = [
33 | crc,
34 | keepMetaData,
35 | keepColorProfile,
36 | overwrite,
37 | keepPalette
38 | ].join(' ');
39 |
40 | args = args.replace(/ +/g, ' ');
41 | args = args.trim();
42 |
43 | return args;
44 | }
45 |
46 | module.exports = commonEncodeDecode;
47 |
--------------------------------------------------------------------------------
/src/conversion/argumentGroups/commonEncodeDecode.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'commonEncodeDecode';
6 | var testData = [
7 | { expected: '', arguments: [{crc: true }] },
8 | { expected: '-c', arguments: [{crc: false }] },
9 | { expected: '', arguments: [{keepMetaData: true }] },
10 | { expected: '-m', arguments: [{keepMetaData: false }] },
11 | { expected: '', arguments: [{keepColorProfile: true }] },
12 | { expected: '-p', arguments: [{keepColorProfile: false }] },
13 | { expected: '-o', arguments: [{overwrite: true }] },
14 | { expected: '', arguments: [{overwrite: false }] },
15 | { expected: '-k', arguments: [{keepPalette: true }] },
16 | { expected: '', arguments: [{keepPalette: false }] },
17 |
18 | // Multi param tests
19 | {
20 | expected: '-m -p -o',
21 | arguments: [
22 | {
23 | overwrite: true,
24 | keepMetaData: false,
25 | keepColorProfile: false
26 | }
27 | ]
28 | },
29 | {
30 | expected: '-c -k',
31 | arguments: [
32 | {
33 | keepPalette: true,
34 | crc: false,
35 | overwrite: false
36 | }
37 | ]
38 | },
39 | {
40 | expected: '-c -m -p -o -k',
41 | arguments: [
42 | {
43 | crc: false,
44 | keepMetaData: false,
45 | keepColorProfile: false,
46 | overwrite: true,
47 | keepPalette: true
48 | }
49 | ]
50 | },
51 | {
52 | expected: '',
53 | arguments: [
54 | {
55 | crc: true,
56 | keepMetaData: true,
57 | keepColorProfile: true,
58 | overwrite: false,
59 | keepPalette: false
60 | }
61 | ]
62 | }
63 | ];
64 |
65 | runAllTests(testName, 'conversion/argumentGroups', testData);
66 |
67 | return [testName, testData.length];
68 | }
69 |
70 | module.exports = test;
71 |
--------------------------------------------------------------------------------
/src/conversion/cli-api.txt:
--------------------------------------------------------------------------------
1 | ____ _(_)____
2 | (___ | | | ___) FLIF (Free Lossless Image Format) 0.3 [28 April 2017]
3 | (__ | |_| __) Copyright (C) 2017 Jon Sneyers and Pieter Wuille
4 | (_|___|_) License LGPLv3+: GNU LGPL version 3 or later
5 |
6 | Usage:
7 | flif [-e] [encode options]
8 | flif [-d] [decode options]
9 | flif [-t] [decode options] [encode options]
10 | Supported input/output image formats: PNG, PNM (PPM,PGM,PBM), PAM
11 | General Options:
12 | -h, --help show help (use -hvv for advanced options)
13 | -v, --verbose increase verbosity (multiple -v for more output)
14 | -c, --no-crc don't verify the CRC (or don't add a CRC)
15 | -m, --no-metadata strip Exif/XMP metadata (default is to keep it)
16 | -p, --no-color-profile strip ICC color profile (default is to keep it)
17 | -o, --overwrite overwrite existing files
18 | -k, --keep-palette use input PNG palette / write palette PNG if possible
19 | Encode options: (-e, --encode)
20 | -E, --effort=N 0=fast/poor compression, 100=slowest/best? (default: -E60)
21 | -I, --interlace interlacing (default, except for tiny images)
22 | -N, --no-interlace force no interlacing
23 | -Q, --lossy=N lossy compression; default: -Q100 (lossless)
24 | -K, --keep-invisible-rgb store original RGB values behind A=0
25 | -F, --frame-delay=N[,N,..] delay between animation frames in ms; default: -F100
26 | Advanced encode options: (mostly useful for flifcrushing)
27 | -P, --max-palette-size=N max size for Palette(_Alpha); default: -P512
28 | -A, --force-color-buckets force Color_Buckets transform
29 | -B, --no-color-buckets disable Color_Buckets transform
30 | -C, --no-channel-compact disable Channel_Compact transform
31 | -Y, --no-ycocg disable YCoCg transform; use G(R-G)(B-G)
32 | -W, --no-subtract-green disable YCoCg and SubtractGreen transform; use GRB
33 | -S, --no-frame-shape disable Frame_Shape transform
34 | -L, --max-frame-lookback=N max nb of frames for Frame_Lookback; default: -L1
35 | -R, --maniac-repeats=N MANIAC learning iterations; default: -R2
36 | -T, --maniac-threshold=N MANIAC tree growth split threshold, in bits saved; default: -T64
37 | -D, --maniac-divisor=N MANIAC inner node count divisor; default: -D30
38 | -M, --maniac-min-size=N MANIAC post-pruning threshold; default: -M50
39 | -X, --chance-cutoff=N minimum chance (N/4096); default: -X2
40 | -Z, --chance-alpha=N chance decay factor; default: -Z19
41 | -U, --adaptive adaptive lossy, second input image is saliency map
42 | -G, --guess=N[N..] pixel predictor for each plane (Y,Co,Cg,Alpha,Lookback)
43 | ?=pick heuristically, 0=avg, 1=median_grad, 2=median_nb, X=mixed
44 | -H, --invisible-guess=N predictor for invisible pixels (only if -K is not used)
45 | -J, --chroma-subsample write an incomplete 4:2:0 chroma subsampled FLIF file (lossy!)
46 | Decode options: (-d, --decode)
47 | -i, --identify do not decode, just identify the input FLIF file
48 | -q, --quality=N lossy decode quality percentage; default -q100
49 | -s, --scale=N lossy downscaled image at scale 1:N (2,4,8,16,32); default -s1
50 | -r, --resize=WxH lossy downscaled image to fit inside WxH (but typically smaller)
51 | -f, --fit=WxH lossy downscaled image to exactly WxH
52 | -b, --breakpoints report breakpoints (truncation offsets) for truncations at scales 1:8, 1:4, 1:2
53 |
--------------------------------------------------------------------------------
/src/conversion/decode.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-console */
2 | /* eslint-disable no-regex-spaces */
3 |
4 | /**
5 | * Converts JSON params for decoding into CLI arguments
6 | * @param {object} params Parameters for the decoding passed in by the user.
7 | * @param {boolean} skipWarnings If true, then helpful warning messages will not be displayed.
8 | * @return {string} The built args to be sent to the command line.
9 | */
10 | function buildDecodeArgs (params, skipWarnings) {
11 | var commonEncodeDecode = require('./argumentGroups/commonEncodeDecode.js');
12 | var commonDecode = require('./argumentGroups/commonDecode.js');
13 | var verifyParams = require('../helpers/verifyParams.js');
14 |
15 | var paramsWereVerified = verifyParams(params, 'decode', skipWarnings);
16 | if (!paramsWereVerified) {
17 | return false;
18 | }
19 |
20 | var input = params.input;
21 | var output = params.output;
22 | var options = [
23 | commonEncodeDecode(params),
24 | commonDecode(params)
25 | ].join(' ');
26 |
27 | // -d -c -m -p -o -k -q=100 -s=2 -r=100x100 -f=100x100 "input file.flif" "output file.png"
28 | var args = '-d ' + options + ' "' + input + '" "' + output + '"';
29 | // -d -c -m -s=2 -f=100x100 "a.flif" "b.flif" ==> -d -c -m -s=2 -f=100x100 "a.flif" "b.flif"
30 | args = args.replace(/ +/g, ' ');
31 | args = args.trim();
32 |
33 | return args;
34 | }
35 |
36 | module.exports = buildDecodeArgs;
37 |
--------------------------------------------------------------------------------
/src/conversion/decode.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../testers/loopOverAllTestSets.js');
5 | var testName = 'decode';
6 | var testData = [
7 | // Individual params
8 | { expected: false, arguments: [{input:'a.flif', output:'b.flif' }] },
9 | { expected: false, arguments: [{input:'a.png', output:'b.flif' }] },
10 | { expected: '-d "a.flif" "b.png"', arguments: [{input:'a.flif', output:'b.png' }] },
11 | { expected: '-d "a.flif" "b.png"', arguments: [{input:'a.flif', output:'b.png', async: true }] },
12 | { expected: '-d "a.flif" "b.png"', arguments: [{input:'a.flif', output:'b.png', async: false }] },
13 |
14 | // Multi param tests
15 | {
16 | expected: '-d -f=640x480 "a.flif" "b.png"',
17 | arguments: [
18 | {
19 | input: 'a.flif',
20 | output: 'b.png',
21 | fit: {
22 | width: 640,
23 | height: 480
24 | }
25 | }
26 | ]
27 | },
28 | {
29 | expected: '-d -s=8 -f=640x480 "a.flif" "b.png"',
30 | arguments: [
31 | {
32 | input: 'a.flif',
33 | output: 'b.png',
34 | scale: 8,
35 | fit: {
36 | width: 640,
37 | height: 480
38 | }
39 | }
40 | ]
41 | },
42 | {
43 | expected: '-d -q=81 -s=1 -r=200x400 -f=200x400 "a.flif" "b.png"',
44 | arguments: [
45 | {
46 | input: 'a.flif',
47 | output: 'b.png',
48 | async: false,
49 | decodeQuality: 81,
50 | scale: 1,
51 | resize: {
52 | width: 200,
53 | height: 400
54 | },
55 | fit: {
56 | width: 200,
57 | height: 400
58 | }
59 | }
60 | ]
61 | }
62 | ];
63 |
64 | runAllTests(testName, 'conversion', testData);
65 |
66 | return [testName, testData.length];
67 | }
68 |
69 | module.exports = test;
70 |
--------------------------------------------------------------------------------
/src/conversion/transcode.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../testers/loopOverAllTestSets.js');
5 | var testName = 'transcode';
6 | var testData = [
7 | // Individual Params
8 | { expected: false, arguments: [{input:'a.png', output:'b.flif' }] },
9 | { expected: false, arguments: [{input:'a.flif', output:'b.png' }] },
10 | { expected: '-t "a.flif" "b.flif"', arguments: [{input:'a.flif', output:'b.flif' }] },
11 | { expected: '-t "a.flif" "b.flif"', arguments: [{input:'a.flif', output:'b.flif', async: true }] },
12 | { expected: '-t "a.flif" "b.flif"', arguments: [{input:'a.flif', output:'b.flif', async: false }] },
13 | {
14 | expected: '-t ' +
15 | '-c -m -p -o -k -E100 -I -Q100 -K -F100 ' +
16 | '-q=81 -s=1 -r=200x400 -f=200x400 ' +
17 | '-P512 -B -C -Y -W -S -L1 -R2 -T64 -D30 -M50 -X2 -Z19 -G????? -J ' +
18 | '"a.flif" "b.flif"',
19 | arguments: [
20 | {
21 | input: 'a.flif',
22 | output: 'b.flif',
23 | async: true,
24 | overwrite: true, // -o for true
25 | effort: 100, // -E100
26 | interlace: true, // -I for true | -N for false | empty string for auto
27 | encodeQuality: 100, // -Q100
28 | keepAlpha: true, // -K when true
29 | crc: false, // -c when false
30 | keepMetaData: false, // -m when false
31 | keepColorProfile: false, // -p when false
32 | keepPalette: true, // -k when true
33 | maxPaletteSize: 512, // -P512
34 | colorBuckets: false, // -B when false | -A when true | empty string when 'auto'
35 | channelCompact: false, // -C
36 | ycocg: false, // -Y when false
37 | subtractGreen: false, // -W when false
38 | frameShape: false, // -S when false
39 | maxFrameLookBack: 1, // -L1
40 | maniacRepeats: 2, // -R2
41 | maniacThreshold: 64, // -T64
42 | maniacDivisor: 30, // -D30
43 | maniacMinSize: 50, // -M50
44 | chanceCutoff: 2, // -X2
45 | chanceAlpha: 19, // -Z19
46 | guess: { // -G????? | -G012X? | etc.
47 | y: 'heuristically', // -G? heuristically | -G0 avg | -G1 median_grad | -G2 median_nb | -GX mixed
48 | co: 'heuristically',
49 | cg: 'heuristically',
50 | alpha: 'heuristically',
51 | lookback: 'heuristically'
52 | },
53 | alphaGuess: 'average', // -H0 | -H1 | -H2 | (only if keepAlpha is false)
54 | chromaSubsample: true, // -J
55 | frameDelay: [100], // -F100
56 |
57 | // Decode
58 | decodeQuality: 81, // -q81
59 | scale: 1,
60 | resize: {
61 | width: 200,
62 | height: 400
63 | },
64 | fit: {
65 | width: 200,
66 | height: 400
67 | }
68 | }
69 | ]
70 | }
71 | ];
72 |
73 | runAllTests(testName, 'conversion', testData);
74 |
75 | return [testName, testData.length];
76 | }
77 |
78 | module.exports = test;
79 |
--------------------------------------------------------------------------------
/src/helpers/executablePath.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Return the correct path to the flif-wasm bin module.
3 | *
4 | * @return {string} Path to the correct flif binary
5 | */
6 | function executablePath () {
7 | var executionPath = '';
8 |
9 | if (process.platform === 'win32') {
10 | var path = require('path');
11 | var rootPath = '';
12 | try {
13 | rootPath = require.resolve('node-flif');
14 | } catch (err) {
15 | // eslint-disable-line no-empty
16 | }
17 |
18 | executionPath = path.join('.', 'executables', 'win32', 'flif.exe');
19 | if (rootPath) {
20 | executionPath = path.join(path.dirname(rootPath), executionPath);
21 | }
22 | } else {
23 | var wasmPath = require.resolve('flif-wasm');
24 | executionPath = 'node "' + wasmPath + '"';
25 | }
26 |
27 | return executionPath;
28 | }
29 |
30 | module.exports = executablePath;
31 |
--------------------------------------------------------------------------------
/src/helpers/executablePath.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../testers/loopOverAllTestSets.js');
5 | var testName = 'executablePath';
6 | var path = require('path');
7 | var testData = [
8 | { expected: 'node "' + path.resolve(process.cwd(), 'node_modules', 'flif-wasm', 'lib', 'flif-wasm.js') + '"', arguments: [] }
9 | ];
10 | if (process.platform === 'win32') {
11 | testData = [
12 | { expected: 'executables\\win32\\flif.exe', arguments: [] }
13 | ];
14 | }
15 | runAllTests(testName, 'helpers', testData);
16 |
17 | return [testName, testData.length];
18 | }
19 |
20 | module.exports = test;
21 |
--------------------------------------------------------------------------------
/src/helpers/guesses.js:
--------------------------------------------------------------------------------
1 | var guesses = {
2 | allHeuristically: {
3 | y: 'heuristically',
4 | co: 'heuristically',
5 | cg: 'heuristically',
6 | alpha: 'heuristically',
7 | lookback: 'heuristically'
8 | },
9 | allAverage: {
10 | y: 'average',
11 | co: 'average',
12 | cg: 'average',
13 | alpha: 'average',
14 | lookback: 'average'
15 | },
16 | allMedianGradient: {
17 | y: 'median gradient',
18 | co: 'median gradient',
19 | cg: 'median gradient',
20 | alpha: 'median gradient',
21 | lookback: 'median gradient'
22 | },
23 | allMedianNumber: {
24 | y: 'median number',
25 | co: 'median number',
26 | cg: 'median number',
27 | alpha: 'median number',
28 | lookback: 'median number'
29 | },
30 | allMixed: {
31 | y: 'mixed',
32 | co: 'mixed',
33 | cg: 'mixed',
34 | alpha: 'mixed',
35 | lookback: 'mixed'
36 | },
37 | rainbow1: {
38 | y: 'heuristically',
39 | co: 'average',
40 | cg: 'median gradient',
41 | alpha: 'median number',
42 | lookback: 'mixed'
43 | },
44 | rainbow2: {
45 | y: 'average',
46 | co: 'median gradient',
47 | cg: 'median number',
48 | alpha: 'mixed',
49 | lookback: 'heuristically'
50 | },
51 | rainbow3: {
52 | y: 'median gradient',
53 | co: 'median number',
54 | cg: 'mixed',
55 | alpha: 'heuristically',
56 | lookback: 'average'
57 | },
58 | rainbow4: {
59 | y: 'median number',
60 | co: 'mixed',
61 | cg: 'heuristically',
62 | alpha: 'average',
63 | lookback: 'median gradient'
64 | },
65 | rainbow5: {
66 | y: 'mixed',
67 | co: 'heuristically',
68 | cg: 'average',
69 | alpha: 'median gradient',
70 | lookback: 'median number'
71 | },
72 | missingY: {
73 | co: 'heuristically',
74 | cg: 'heuristically',
75 | alpha: 'heuristically',
76 | lookback: 'heuristically'
77 | },
78 | missingCo: {
79 | y: 'heuristically',
80 | cg: 'heuristically',
81 | alpha: 'heuristically',
82 | lookback: 'heuristically'
83 | },
84 | missingCg: {
85 | y: 'heuristically',
86 | co: 'heuristically',
87 | alpha: 'heuristically',
88 | lookback: 'heuristically'
89 | },
90 | missingAlpha: {
91 | y: 'heuristically',
92 | co: 'heuristically',
93 | cg: 'heuristically',
94 | lookback: 'heuristically'
95 | },
96 | missingLookback: {
97 | y: 'heuristically',
98 | co: 'heuristically',
99 | cg: 'heuristically',
100 | alpha: 'heuristically'
101 | },
102 | allTrue: {
103 | y: true,
104 | co: true,
105 | cg: true,
106 | alpha: true,
107 | lookback: true
108 | },
109 | allFalse: {
110 | y: false,
111 | co: false,
112 | cg: false,
113 | alpha: false,
114 | lookback: false
115 | },
116 | allNumber: {
117 | y: 5,
118 | co: 5,
119 | cg: 5,
120 | alpha: 5,
121 | lookback: 5
122 | },
123 | allString: {
124 | y: 'a',
125 | co: 'a',
126 | cg: 'a',
127 | alpha: 'a',
128 | lookback: 'a'
129 | },
130 | allArray: {
131 | y: ['a'],
132 | co: ['a'],
133 | cg: ['a'],
134 | alpha: ['a'],
135 | lookback: ['a']
136 | },
137 | allObject: {
138 | y: { a: 'b' },
139 | co: { a: 'b' },
140 | cg: { a: 'b' },
141 | alpha: { a: 'b' },
142 | lookback: { a: 'b' }
143 | },
144 | empty: {}
145 | };
146 |
147 | module.exports = guesses;
148 |
--------------------------------------------------------------------------------
/src/helpers/runCommand.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Spawns a child process using the arguments that were passed in.
3 | * This is done asynchronously. It will run the callback function
4 | * upon completion.
5 | * @param {string} args List of arguments to pass in
6 | * @param {function} callback Optional callback function
7 | */
8 | function runCommand (args, callback) {
9 | if (!args || typeof(args) !== 'string') {
10 | throw '\nERROR: Command line arguments where not supplied to the FLIF executable. See above warning for details.';
11 | } else if (callback && typeof(callback) !== 'function') {
12 | throw 'The second argument to the runCommand method is meant to be a callback function.';
13 | }
14 |
15 | var executablePath = require('./executablePath.js');
16 | var exec = require('child_process').exec;
17 | var flif = executablePath();
18 | var executableAndArgs = flif + ' ' + args;
19 |
20 | exec(executableAndArgs, function (error, stdout) {
21 | if (error !== null) {
22 | throw 'Executable Error: ' + error;
23 | }
24 | if (stdout && callback) {
25 | callback(stdout);
26 | } else if (callback) {
27 | callback();
28 | }
29 | });
30 | }
31 |
32 | module.exports = runCommand;
33 |
--------------------------------------------------------------------------------
/src/helpers/runCommand.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../testers/loopOverAllTestSets.js');
5 | var testName = 'runCommand';
6 | var testData = [
7 | { expected: 'FLIF (Free Lossless Image Format) 0.3 [28 April 2017]', arguments: ['-v'] }
8 | ];
9 |
10 | runAllTests(testName, 'helpers', testData, true);
11 |
12 | return [testName, testData.length];
13 | }
14 |
15 | module.exports = test;
16 |
--------------------------------------------------------------------------------
/src/helpers/runCommandSync.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Spawns a child process using the arguments that were passed in.
3 | * This is done synchronously.
4 | *
5 | * @param {string} args List of arguments to pass in.
6 | * @return {string} The data that is returned from the finished executable.
7 | */
8 | function runCommandSync (args) {
9 | if (!args || typeof(args) !== 'string') {
10 | throw '\nERROR: Command line arguments where not supplied to the FLIF executable. See above warning for details.';
11 | }
12 |
13 | var executablePath = require('./executablePath.js');
14 | var exec = require('child_process').execSync;
15 | var flif = executablePath();
16 | var executableAndArgs = flif + ' ' + args;
17 |
18 | var child = exec(executableAndArgs);
19 |
20 | return child.toString().trim();
21 | }
22 |
23 | module.exports = runCommandSync;
24 |
--------------------------------------------------------------------------------
/src/helpers/runCommandSync.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../testers/loopOverAllTestSets.js');
5 | var testName = 'runCommandSync';
6 | var testData = [
7 | { expected: 'FLIF (Free Lossless Image Format) 0.3 [28 April 2017]', arguments: ['-v'] }
8 | ];
9 |
10 | runAllTests(testName, 'helpers', testData);
11 |
12 | return [testName, testData.length];
13 | }
14 |
15 | module.exports = test;
16 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyParams';
6 | var testData = [];
7 |
8 | runAllTests(testName, 'helpers', testData);
9 |
10 | return [testName, testData.length];
11 | }
12 |
13 | module.exports = test;
14 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/disallowQuality.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function disallowQuality (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (params && typeof(params) === 'object' && params.quality && src) {
14 | warnUser('The quality parameter in node-flif has been changed to be encode and decode specific', skipWarnings);
15 | return false;
16 | }
17 |
18 | return true;
19 | }
20 |
21 | module.exports = disallowQuality;
22 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/disallowQuality.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'disallowQuality';
6 | var testData = [
7 | // Throw error if quality is used instead of encodeQuality or decodeQuality
8 | { expected: false, arguments: [ { input: 'a.png', output: 'a.flif', quality: 100 }, 'encode', true]},
9 | { expected: false, arguments: [ { input: 'a.flif', output: 'a.png', quality: 100 }, 'decode', true]},
10 | { expected: false, arguments: [ { input: 'a.flif', output: 'a.flif', quality: 100 }, 'transcode', true]}
11 | ];
12 |
13 | runAllTests(testName, 'helpers/verifyParams', testData);
14 |
15 | return [testName, testData.length];
16 | }
17 |
18 | module.exports = test;
19 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/ensureInputOutputExist.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters for input and output files exists, are the
3 | * correct types, and match their conversion method (encode/decode/transcode).
4 | * Return helpful error messages to users.
5 | *
6 | * @param {object} params The object the user passed in.
7 | * @param {string} src The method that called verifyParams, used in error messages.
8 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
9 | * @return {boolean} True if params pass, false if there was a problem.
10 | */
11 | function ensureInputOutputExist (params, src, skipWarnings) {
12 | var warnUser = require('../warnUser.js');
13 |
14 | if (src === 'encode') {
15 | if (
16 | !params.input ||
17 | typeof(params.input) !== 'string' &&
18 | !Array.isArray(params.input)
19 | ) {
20 | warnUser('Encode input must be either a string or an array of strings', skipWarnings);
21 | return false;
22 | }
23 | if (!params.output || typeof(params.output) !== 'string') {
24 | warnUser('You must pass in a path to your input and output files as a string.', skipWarnings);
25 | return false;
26 | }
27 | } else if (
28 | !params.input ||
29 | !params.output ||
30 | typeof(params.input) !== 'string' ||
31 | typeof(params.output) !== 'string'
32 | ) {
33 | warnUser('You must pass in a path to your input and output files as a string.', skipWarnings);
34 | return false;
35 | }
36 |
37 | var input = params.input;
38 | var output = params.output.toLowerCase();
39 |
40 | if (typeof(input) === 'string') {
41 | input = input.toLowerCase();
42 |
43 | if (
44 | src === 'encode' &&
45 | !input.endsWith('.png') &&
46 | !input.endsWith('.pnm') &&
47 | !input.endsWith('.ppm') &&
48 | !input.endsWith('.pgm') &&
49 | !input.endsWith('.pbm') &&
50 | !input.endsWith('.pam')
51 | ) {
52 | warnUser('Encode input only accepts .png, .pnm, .ppm, .pgm, .pbm, and .pam files.', skipWarnings);
53 | return false;
54 | }
55 |
56 | if (src === 'decode' && !input.endsWith('.flif')) {
57 | warnUser('Decode input must be a .flif file.', skipWarnings);
58 | return false;
59 | }
60 |
61 | if (src === 'transcode' && (!input.endsWith('.flif') || !output.endsWith('.flif'))) {
62 | warnUser('Transcode input and output must be .flif files.', skipWarnings);
63 | return false;
64 | }
65 | } else if (src === 'encode' && Array.isArray(params.input)) {
66 | if (input.length < 1) {
67 | warnUser('Encode input must be either a string or an array of strings', skipWarnings);
68 | return false;
69 | }
70 | for (var i = 0; i < input.length; i++) {
71 | var file = input[i];
72 | if (typeof(file) !== 'string') {
73 | warnUser('Encode input must be either a string or an array of strings', skipWarnings);
74 | return false;
75 | }
76 | file = file.toLowerCase();
77 | if (
78 | !file.endsWith('.png') &&
79 | !file.endsWith('.pnm') &&
80 | !file.endsWith('.ppm') &&
81 | !file.endsWith('.pgm') &&
82 | !file.endsWith('.pbm') &&
83 | !file.endsWith('.pam')
84 | ) {
85 | warnUser('Encode input only accepts .png, .pnm, .ppm, .pgm, .pbm, and .pam files.', skipWarnings);
86 | return false;
87 | }
88 | }
89 | }
90 |
91 | if (src === 'encode' && !output.endsWith('.flif')) {
92 | warnUser('Encode output must be a .flif file.', skipWarnings);
93 | return false;
94 | }
95 | if (
96 | src === 'decode' &&
97 | !output.endsWith('.png') &&
98 | !output.endsWith('.pnm') &&
99 | !output.endsWith('.ppm') &&
100 | !output.endsWith('.pgm') &&
101 | !output.endsWith('.pbm') &&
102 | !output.endsWith('.pam')
103 | ) {
104 | warnUser('Decode output only accepts .png, .pnm, .ppm, .pgm, .pbm, and .pam file.', skipWarnings);
105 | return false;
106 | }
107 |
108 | return true;
109 | }
110 |
111 | module.exports = ensureInputOutputExist;
112 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/ensureParamsExist.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function ensureParamsExist (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (!params || typeof(params) !== 'object' || Object.keys(params).length < 2) {
14 | warnUser('You must pass an object into nodeFLIF.' + src + ' containing input/output paths.', skipWarnings);
15 | return false;
16 | }
17 |
18 | if (!src || typeof(src) !== 'string' || src.length < 2) {
19 | warnUser('The conversion method (encode, decode, transcode) is unknown.', skipWarnings);
20 | return false;
21 | }
22 |
23 | return true;
24 | }
25 |
26 | module.exports = ensureParamsExist;
27 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/ensureParamsExist.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'ensureParamsExist';
6 | var testData = [
7 | // Test if params exist
8 | { expected: false, arguments: [ undefined, 'encode', true]},
9 | { expected: false, arguments: [ null, 'encode', true]},
10 | { expected: false, arguments: [ true, 'encode', true]},
11 | { expected: false, arguments: [ false, 'encode', true]},
12 | { expected: false, arguments: [ 8, 'encode', true]},
13 | { expected: false, arguments: [ '', 'encode', true]},
14 | { expected: false, arguments: [ [], 'encode', true]},
15 | { expected: false, arguments: [ {}, 'encode', true]},
16 |
17 | // Test if src exists
18 | { expected: false, arguments: [ { input: 'a.png', output: 'a.flif' }, undefined, true]},
19 | { expected: false, arguments: [ { input: 'a.png', output: 'a.flif' }, null, true]},
20 | { expected: false, arguments: [ { input: 'a.png', output: 'a.flif' }, true, true]},
21 | { expected: false, arguments: [ { input: 'a.png', output: 'a.flif' }, false, true]},
22 | { expected: false, arguments: [ { input: 'a.png', output: 'a.flif' }, 8, true]},
23 | { expected: false, arguments: [ { input: 'a.png', output: 'a.flif' }, '', true]},
24 | { expected: false, arguments: [ { input: 'a.png', output: 'a.flif' }, [], true]},
25 | { expected: false, arguments: [ { input: 'a.png', output: 'a.flif' }, {}, true]},
26 |
27 | // Known good
28 | { expected: true, arguments: [ { input: 'a.png', output: 'a.flif' }, 'encode', true]},
29 | { expected: true, arguments: [ { input: 'a.flif', output: 'a.png' }, 'decode', true]},
30 | { expected: true, arguments: [ { input: 'a.flif', output: 'a.flif' }, 'transcode', true]}
31 | ];
32 |
33 | runAllTests(testName, 'helpers/verifyParams', testData);
34 |
35 | return [testName, testData.length];
36 | }
37 |
38 | module.exports = test;
39 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyAdaptive.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyAdaptive (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | function hasFileExtension () {
14 | var hasExtension = false;
15 | var file = params.adaptive;
16 | if (typeof(file) === 'string') {
17 | file = file.toLowerCase();
18 | if (file.endsWith('.png') ||
19 | file.endsWith('.pnm') ||
20 | file.endsWith('.ppm') ||
21 | file.endsWith('.pgm') ||
22 | file.endsWith('.pbm') ||
23 | file.endsWith('.pam')
24 | ) {
25 | hasExtension = true;
26 | }
27 | }
28 | return hasExtension;
29 | }
30 |
31 | if (
32 | params.adaptive === null ||
33 | params.adaptive === false ||
34 | params.adaptive === true ||
35 | params.adaptive && typeof(params.input) !== 'string' && params.input.length !== 1 ||
36 | params.adaptive && !hasFileExtension()
37 | ) {
38 | warnUser(
39 | 'The adaptive parameter must be a string file path.\n' +
40 | 'The adaptive file path should point to a saliency map for lossy\n' +
41 | 'encoding that ends in .png, .pnm, .ppm, .pgm, .pbm, or .pam.\n' +
42 | 'Adaptive encoding only accepts one input (no animations).',
43 | skipWarnings
44 | );
45 | return false;
46 | }
47 |
48 | if (
49 | params.adaptive && hasFileExtension() && src === 'decode' ||
50 | params.adaptive && hasFileExtension() && src === 'transcode'
51 | ) {
52 | warnUser('The adaptive parameter only works on encodes.', skipWarnings);
53 | return false;
54 | }
55 |
56 | if (
57 | params.adaptive && hasFileExtension() && typeof(params.encodeQuality) !== 'number' ||
58 | params.adaptive && hasFileExtension() && params.encodeQuality && params.encodeQuality > 99
59 | ) {
60 | warnUser(
61 | 'The adaptive parameter can only be applied when the encodeQuality\n' +
62 | 'parameter is set to 99 or below (lossy).',
63 | skipWarnings
64 | );
65 | return false;
66 | }
67 |
68 | return true;
69 | }
70 |
71 | module.exports = verifyAdaptive;
72 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyAlphaGuess.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyAlphaGuess (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (
14 | params.alphaGuess === false ||
15 | params.alphaGuess === true ||
16 | params.alphaGuess === null ||
17 | params.alphaGuess && typeof(params.alphaGuess) !== 'string' ||
18 | params.alphaGuess && src === 'decode' ||
19 | params.alphaGuess && (
20 | params.alphaGuess !== 'average' &&
21 | params.alphaGuess !== 'median gradient' &&
22 | params.alphaGuess !== 'median neighbors'
23 | )
24 | ) {
25 | warnUser('The alphaGuess parameter must be one of the following: "average", "median gradient", "median neighbors".', skipWarnings);
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | module.exports = verifyAlphaGuess;
33 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyAlphaGuess.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyAlphaGuess';
6 | var testData = [
7 | // Test known good for alphaGuess
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', alphaGuess: 'average' }, 'encode', true]},
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', alphaGuess: 'average' }, 'transcode', true]},
10 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', alphaGuess: 'median gradient' }, 'encode', true]},
11 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', alphaGuess: 'median gradient' }, 'transcode', true]},
12 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', alphaGuess: 'median neighbors' }, 'encode', true]},
13 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', alphaGuess: 'median neighbors' }, 'transcode', true]},
14 |
15 | // Test known bad for alphaGuess
16 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', alphaGuess: 'average' }, 'decode', true]},
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', alphaGuess: 'median gradient' }, 'decode', true]},
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', alphaGuess: 'median neighbors' }, 'decode', true]},
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', alphaGuess: 'heuristically' }, 'encode', true]},
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', alphaGuess: 'heuristically' }, 'decode', true]},
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', alphaGuess: 'heuristically' }, 'transcode', true]},
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', alphaGuess: 'median number' }, 'encode', true]},
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', alphaGuess: 'median number' }, 'decode', true]},
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', alphaGuess: 'median number' }, 'transcode', true]},
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', alphaGuess: 'mixed' }, 'encode', true]},
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', alphaGuess: 'mixed' }, 'decode', true]},
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', alphaGuess: 'mixed' }, 'transcode', true]},
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', alphaGuess: true }, 'encode', true]},
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', alphaGuess: true }, 'decode', true]},
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', alphaGuess: true }, 'transcode', true]},
31 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', alphaGuess: false }, 'encode', true]},
32 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', alphaGuess: false }, 'decode', true]},
33 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', alphaGuess: false }, 'transcode', true]},
34 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', alphaGuess: 'a' }, 'encode', true]},
35 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', alphaGuess: 'a' }, 'decode', true]},
36 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', alphaGuess: 'a' }, 'transcode', true]},
37 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', alphaGuess: [0, 1, 2] }, 'encode', true]},
38 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', alphaGuess: [0, 1, 2] }, 'decode', true]},
39 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', alphaGuess: [0, 1, 2] }, 'transcode', true]},
40 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', alphaGuess: {'a': 1} }, 'encode', true]},
41 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', alphaGuess: {'a': 1} }, 'decode', true]},
42 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', alphaGuess: {'a': 1} }, 'transcode', true]},
43 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', alphaGuess: null }, 'encode', true]},
44 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', alphaGuess: null }, 'decode', true]},
45 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', alphaGuess: null }, 'transcode', true]},
46 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', alphaGuess: 8 }, 'encode', true]},
47 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', alphaGuess: 8 }, 'decode', true]},
48 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', alphaGuess: 8 }, 'transcode', true]}
49 | ];
50 |
51 | runAllTests(testName, 'helpers/verifyParams', testData);
52 |
53 | return [testName, testData.length];
54 | }
55 |
56 | module.exports = test;
57 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyAsync.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | // eslint-disable-next-line no-unused-vars
11 | function verifyAsync (params, src, skipWarnings) {
12 | var warnUser = require('../warnUser.js');
13 |
14 | if (
15 | params.async === null ||
16 | params.async &&
17 | typeof(params.async) !== 'boolean'
18 | ) {
19 | warnUser('The async parameter must be a boolean value.', skipWarnings);
20 | return false;
21 | }
22 |
23 | return true;
24 | }
25 |
26 | module.exports = verifyAsync;
27 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyAsync.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyAsync';
6 | var testData = [
7 | // Test known good for async
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', async: true }, 'encode', true] },
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', async: true }, 'decode', true] },
10 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', async: true }, 'transcode', true] },
11 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', async: false }, 'encode', true] },
12 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', async: false }, 'decode', true] },
13 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', async: false }, 'transcode', true] },
14 |
15 | // Test known bad for async
16 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', async: 'a' }, 'encode', true] },
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', async: 'a' }, 'decode', true] },
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', async: 'a' }, 'transcode', true] },
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', async: [0, 1, 2] }, 'encode', true] },
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', async: [0, 1, 2] }, 'decode', true] },
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', async: [0, 1, 2] }, 'transcode', true] },
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', async: {'a': 1} }, 'encode', true] },
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', async: {'a': 1} }, 'decode', true] },
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', async: {'a': 1} }, 'transcode', true] },
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', async: null }, 'encode', true] },
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', async: null }, 'decode', true] },
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', async: null }, 'transcode', true] },
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', async: 8 }, 'encode', true] },
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', async: 8 }, 'decode', true] },
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', async: 8 }, 'transcode', true] }
31 | ];
32 |
33 | runAllTests(testName, 'helpers/verifyParams', testData);
34 |
35 | return [testName, testData.length];
36 | }
37 |
38 | module.exports = test;
39 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyCRC.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | // eslint-disable-next-line no-unused-vars
11 | function verifyCRC (params, src, skipWarnings) {
12 | var warnUser = require('../warnUser.js');
13 |
14 | if (
15 | params.crc === null ||
16 | params.crc &&
17 | typeof(params.crc) !== 'boolean'
18 | ) {
19 | warnUser('The crc parameter must be a boolean value.', skipWarnings);
20 | return false;
21 | }
22 |
23 | return true;
24 | }
25 |
26 | module.exports = verifyCRC;
27 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyCRC.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyCRC';
6 | var testData = [
7 | // Test known good for crc
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', crc: true }, 'encode', true] },
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', crc: true }, 'decode', true] },
10 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', crc: true }, 'transcode', true] },
11 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', crc: false }, 'encode', true] },
12 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', crc: false }, 'decode', true] },
13 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', crc: false }, 'transcode', true] },
14 |
15 | // Test known bad for crc
16 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', crc: 'a' }, 'encode', true] },
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', crc: 'a' }, 'decode', true] },
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', crc: 'a' }, 'transcode', true] },
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', crc: [0, 1, 2] }, 'encode', true] },
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', crc: [0, 1, 2] }, 'decode', true] },
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', crc: [0, 1, 2] }, 'transcode', true] },
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', crc: {'a': 1} }, 'encode', true] },
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', crc: {'a': 1} }, 'decode', true] },
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', crc: {'a': 1} }, 'transcode', true] },
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', crc: null }, 'encode', true] },
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', crc: null }, 'decode', true] },
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', crc: null }, 'transcode', true] },
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', crc: 8 }, 'encode', true] },
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', crc: 8 }, 'decode', true] },
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', crc: 8 }, 'transcode', true] }
31 | ];
32 |
33 | runAllTests(testName, 'helpers/verifyParams', testData);
34 |
35 | return [testName, testData.length];
36 | }
37 |
38 | module.exports = test;
39 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyChanceAlpha.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyChanceAlpha (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 | var lowerBounds = 2;
13 | var upperBounds = 128;
14 |
15 | if (
16 | params.chanceAlpha === false ||
17 | params.chanceAlpha === true ||
18 | params.chanceAlpha === null ||
19 | params.chanceAlpha && typeof(params.chanceAlpha) !== 'number' ||
20 | typeof(params.chanceAlpha) === 'number' && params.chanceAlpha < lowerBounds ||
21 | typeof(params.chanceAlpha) === 'number' && params.chanceAlpha > upperBounds ||
22 | typeof(params.chanceAlpha) === 'number' && params.chanceAlpha % 1 !== 0 ||
23 | typeof(params.chanceAlpha) === 'number' && src === 'decode'
24 | ) {
25 | warnUser('The chanceAlpha parameter must be a whole number between ' + lowerBounds + ' and ' + upperBounds + '.', skipWarnings);
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | module.exports = verifyChanceAlpha;
33 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyChanceCutoff.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyChanceCutoff (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 | var lowerBounds = 1;
13 | var upperBounds = 128;
14 |
15 | if (
16 | params.chanceCutoff === false ||
17 | params.chanceCutoff === true ||
18 | params.chanceCutoff === null ||
19 | params.chanceCutoff && typeof(params.chanceCutoff) !== 'number' ||
20 | typeof(params.chanceCutoff) === 'number' && params.chanceCutoff < lowerBounds ||
21 | typeof(params.chanceCutoff) === 'number' && params.chanceCutoff > upperBounds ||
22 | typeof(params.chanceCutoff) === 'number' && params.chanceCutoff % 1 !== 0 ||
23 | typeof(params.chanceCutoff) === 'number' && src === 'decode'
24 | ) {
25 | warnUser('The chanceCutoff parameter must be a whole number between ' + lowerBounds + ' and ' + upperBounds + '.', skipWarnings);
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | module.exports = verifyChanceCutoff;
33 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyChanceCutoff.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyChanceCutoff';
6 | function rand (num) {
7 | return Math.round(Math.random() * num);
8 | }
9 | var testData = [
10 | // Test known good for chanceCutoff
11 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: 1 }, 'encode', true]},
12 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: 1 }, 'transcode', true]},
13 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: 2 }, 'encode', true]},
14 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: 2 }, 'transcode', true]},
15 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: 128 }, 'encode', true]},
16 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: 128 }, 'transcode', true]},
17 |
18 | // Test random number from 1-128 on chanceCutoff
19 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: rand(127) + 1 }, 'encode', true]},
20 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: rand(127) + 1 }, 'transcode', true]},
21 |
22 | // Test known bad for chanceCutoff
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chanceCutoff: 1 }, 'decode', true]},
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chanceCutoff: 2 }, 'decode', true]},
25 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chanceCutoff: rand(127) + 1 }, 'decode', true]},
26 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: 0 }, 'encode', true]},
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chanceCutoff: 0 }, 'decode', true]},
28 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: 0 }, 'transcode', true]},
29 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: 129 }, 'encode', true]},
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chanceCutoff: 129 }, 'decode', true]},
31 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: 129 }, 'transcode', true]},
32 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: -10 }, 'encode', true]},
33 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chanceCutoff: -10 }, 'decode', true]},
34 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: -10 }, 'transcode', true]},
35 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: 22.2 }, 'encode', true]},
36 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chanceCutoff: 22.2 }, 'decode', true]},
37 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: 22.2 }, 'transcode', true]},
38 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: 'a' }, 'encode', true]},
39 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chanceCutoff: 'a' }, 'decode', true]},
40 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: 'a' }, 'transcode', true]},
41 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: [0, 1, 2] }, 'encode', true]},
42 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chanceCutoff: [0, 1, 2] }, 'decode', true]},
43 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: [0, 1, 2] }, 'transcode', true]},
44 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: {'a': 1} }, 'encode', true]},
45 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chanceCutoff: {'a': 1} }, 'decode', true]},
46 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: {'a': 1} }, 'transcode', true]},
47 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: null }, 'encode', true]},
48 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chanceCutoff: null }, 'decode', true]},
49 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: null }, 'transcode', true]},
50 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: true }, 'encode', true]},
51 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chanceCutoff: true }, 'decode', true]},
52 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: true }, 'transcode', true]},
53 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chanceCutoff: false }, 'encode', true]},
54 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chanceCutoff: false }, 'decode', true]},
55 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chanceCutoff: false }, 'transcode', true]}
56 | ];
57 |
58 | runAllTests(testName, 'helpers/verifyParams', testData);
59 |
60 | return [testName, testData.length];
61 | }
62 |
63 | module.exports = test;
64 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyChannelCompact.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyChannelCompact (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (
14 | params.channelCompact === null ||
15 | params.channelCompact &&
16 | typeof(params.channelCompact) !== 'boolean' ||
17 | src === 'decode' && params.channelCompact === false ||
18 | src === 'decode' && params.channelCompact === true
19 | ) {
20 | warnUser('The channelCompact parameter must be a boolean value.', skipWarnings);
21 | return false;
22 | }
23 |
24 | return true;
25 | }
26 |
27 | module.exports = verifyChannelCompact;
28 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyChannelCompact.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyChannelCompact';
6 | var testData = [
7 | // Test known good for channelCompact
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', channelCompact: true }, 'encode', true]},
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', channelCompact: true }, 'transcode', true]},
10 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', channelCompact: false }, 'encode', true]},
11 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', channelCompact: false }, 'transcode', true]},
12 |
13 | // Test known bad for channelCompact
14 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', channelCompact: true }, 'decode', true]},
15 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', channelCompact: false }, 'decode', true]},
16 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', channelCompact: 'a' }, 'encode', true]},
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', channelCompact: 'a' }, 'decode', true]},
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', channelCompact: 'a' }, 'transcode', true]},
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', channelCompact: [0, 1, 2] }, 'encode', true]},
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', channelCompact: [0, 1, 2] }, 'decode', true]},
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', channelCompact: [0, 1, 2] }, 'transcode', true]},
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', channelCompact: {'a': 1} }, 'encode', true]},
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', channelCompact: {'a': 1} }, 'decode', true]},
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', channelCompact: {'a': 1} }, 'transcode', true]},
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', channelCompact: null }, 'encode', true]},
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', channelCompact: null }, 'decode', true]},
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', channelCompact: null }, 'transcode', true]},
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', channelCompact: 8 }, 'encode', true]},
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', channelCompact: 8 }, 'decode', true]},
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', channelCompact: 8 }, 'transcode', true]}
31 | ];
32 |
33 | runAllTests(testName, 'helpers/verifyParams', testData);
34 |
35 | return [testName, testData.length];
36 | }
37 |
38 | module.exports = test;
39 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyChromaSubsample.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyChromaSubsample (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (
14 | params.chromaSubsample === null ||
15 | params.chromaSubsample &&
16 | typeof(params.chromaSubsample) !== 'boolean' ||
17 | src === 'decode' && params.chromaSubsample === false ||
18 | src === 'decode' && params.chromaSubsample === true
19 | ) {
20 | warnUser('The chromaSubsample parameter must be a boolean value.', skipWarnings);
21 | return false;
22 | }
23 |
24 | return true;
25 | }
26 |
27 | module.exports = verifyChromaSubsample;
28 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyChromaSubsample.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyChromaSubsample';
6 | var testData = [
7 | // Test known good for chromaSubsample
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', chromaSubsample: true }, 'encode', true] },
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', chromaSubsample: true }, 'transcode', true] },
10 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', chromaSubsample: false }, 'encode', true] },
11 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', chromaSubsample: false }, 'transcode', true] },
12 |
13 | // Test known bad for chromaSubsample
14 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chromaSubsample: true }, 'decode', true] },
15 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chromaSubsample: false }, 'decode', true] },
16 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chromaSubsample: 'a' }, 'encode', true] },
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chromaSubsample: 'a' }, 'decode', true] },
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chromaSubsample: 'a' }, 'transcode', true] },
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chromaSubsample: [0, 1, 2] }, 'encode', true] },
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chromaSubsample: [0, 1, 2] }, 'decode', true] },
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chromaSubsample: [0, 1, 2] }, 'transcode', true] },
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chromaSubsample: {'a': 1} }, 'encode', true] },
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chromaSubsample: {'a': 1} }, 'decode', true] },
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chromaSubsample: {'a': 1} }, 'transcode', true] },
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chromaSubsample: null }, 'encode', true] },
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chromaSubsample: null }, 'decode', true] },
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chromaSubsample: null }, 'transcode', true] },
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', chromaSubsample: 8 }, 'encode', true] },
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', chromaSubsample: 8 }, 'decode', true] },
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', chromaSubsample: 8 }, 'transcode', true] }
31 | ];
32 |
33 | runAllTests(testName, 'helpers/verifyParams', testData);
34 |
35 | return [testName, testData.length];
36 | }
37 |
38 | module.exports = test;
39 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyColorBuckets.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyColorBuckets (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (
14 | params.colorBuckets === null ||
15 | typeof(params.colorBuckets) === 'object' ||
16 | typeof(params.colorBuckets) === 'number' ||
17 | (
18 | typeof(params.colorBuckets) === 'boolean' &&
19 | params.colorBuckets !== false &&
20 | params.colorBuckets !== true
21 | ) ||
22 | (
23 | typeof(params.colorBuckets) === 'string' &&
24 | params.colorBuckets !== 'auto'
25 | ) ||
26 | src === 'decode' && params.colorBuckets === false ||
27 | src === 'decode' && params.colorBuckets === true ||
28 | src === 'decode' && params.colorBuckets === 'auto'
29 | ) {
30 | warnUser('The colorBuckets parameter must be set to true, false, or "auto".', skipWarnings);
31 | return false;
32 | }
33 |
34 | return true;
35 | }
36 |
37 | module.exports = verifyColorBuckets;
38 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyColorBuckets.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyColorBuckets';
6 | var testData = [
7 | // Test known good for colorBuckets
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', colorBuckets: true }, 'encode', true]},
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', colorBuckets: true }, 'transcode', true]},
10 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', colorBuckets: false }, 'encode', true]},
11 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', colorBuckets: false }, 'transcode', true]},
12 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', colorBuckets: 'auto' }, 'encode', true]},
13 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', colorBuckets: 'auto' }, 'transcode', true]},
14 |
15 | // Test known bad for colorBuckets
16 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', colorBuckets: true }, 'decode', true]},
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', colorBuckets: false }, 'decode', true]},
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', colorBuckets: 'auto' }, 'decode', true]},
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', colorBuckets: 'a' }, 'encode', true]},
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', colorBuckets: 'a' }, 'decode', true]},
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', colorBuckets: 'a' }, 'transcode', true]},
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', colorBuckets: [0, 1, 2] }, 'encode', true]},
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', colorBuckets: [0, 1, 2] }, 'decode', true]},
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', colorBuckets: [0, 1, 2] }, 'transcode', true]},
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', colorBuckets: {'a': 1} }, 'encode', true]},
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', colorBuckets: {'a': 1} }, 'decode', true]},
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', colorBuckets: {'a': 1} }, 'transcode', true]},
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', colorBuckets: null }, 'encode', true]},
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', colorBuckets: null }, 'decode', true]},
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', colorBuckets: null }, 'transcode', true]},
31 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', colorBuckets: 8 }, 'encode', true]},
32 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', colorBuckets: 8 }, 'decode', true]},
33 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', colorBuckets: 8 }, 'transcode', true]}
34 | ];
35 |
36 | runAllTests(testName, 'helpers/verifyParams', testData);
37 |
38 | return [testName, testData.length];
39 | }
40 |
41 | module.exports = test;
42 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyDecodeQuality.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyDecodeQuality (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 | var lowerBounds = 0;
13 | var upperBounds = 100;
14 |
15 | if (
16 | params.decodeQuality === false ||
17 | params.decodeQuality === true ||
18 | params.decodeQuality === null ||
19 | params.decodeQuality && typeof(params.decodeQuality) !== 'number' ||
20 | typeof(params.decodeQuality) === 'number' && params.decodeQuality < lowerBounds ||
21 | typeof(params.decodeQuality) === 'number' && params.decodeQuality > upperBounds ||
22 | typeof(params.decodeQuality) === 'number' && params.decodeQuality % 1 !== 0 ||
23 | typeof(params.decodeQuality) === 'number' && src === 'encode'
24 | ) {
25 | warnUser('The decodeQuality parameter must be a whole number between ' + lowerBounds + ' and ' + upperBounds + '.', skipWarnings);
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | module.exports = verifyDecodeQuality;
33 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyDecodeQuality.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyDecodeQuality';
6 | function rand (num) {
7 | return Math.round(Math.random() * num);
8 | }
9 | var testData = [
10 | // Test known good for decodeQuality
11 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: 0 }, 'decode', true] },
12 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: 0 }, 'transcode', true] },
13 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: 1 }, 'decode', true] },
14 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: 1 }, 'transcode', true] },
15 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: 50 }, 'decode', true] },
16 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: 50 }, 'transcode', true] },
17 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: 100 }, 'decode', true] },
18 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: 100 }, 'transcode', true] },
19 |
20 | // Test random number from 0-100 on decodeQuality
21 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: rand(100) }, 'decode', true] },
22 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: rand(100) }, 'transcode', true] },
23 |
24 | // Test known bad for decodeQuality
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: 0 }, 'encode', true] },
26 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: 1 }, 'encode', true] },
27 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: 50 }, 'encode', true] },
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: 100 }, 'encode', true] },
29 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: rand(100) }, 'encode', true] },
30 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: 101 }, 'encode', true] },
31 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: 101 }, 'decode', true] },
32 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: 101 }, 'transcode', true] },
33 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: -10 }, 'encode', true] },
34 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: -10 }, 'decode', true] },
35 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: -10 }, 'transcode', true] },
36 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: 22.2 }, 'encode', true] },
37 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: 22.2 }, 'decode', true] },
38 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: 22.2 }, 'transcode', true] },
39 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: 'a' }, 'encode', true] },
40 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: 'a' }, 'decode', true] },
41 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: 'a' }, 'transcode', true] },
42 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: [0, 1, 2] }, 'encode', true] },
43 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: [0, 1, 2] }, 'decode', true] },
44 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: [0, 1, 2] }, 'transcode', true] },
45 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: {'a': 1} }, 'encode', true] },
46 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: {'a': 1} }, 'decode', true] },
47 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: {'a': 1} }, 'transcode', true] },
48 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: null }, 'encode', true] },
49 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: null }, 'decode', true] },
50 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: null }, 'transcode', true] },
51 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: true }, 'encode', true] },
52 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: true }, 'decode', true] },
53 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: true }, 'transcode', true] },
54 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', decodeQuality: false }, 'encode', true] },
55 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', decodeQuality: false }, 'decode', true] },
56 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', decodeQuality: false }, 'transcode', true] }
57 | ];
58 |
59 | runAllTests(testName, 'helpers/verifyParams', testData);
60 |
61 | return [testName, testData.length];
62 | }
63 |
64 | module.exports = test;
65 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyEffort.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyEffort (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 | var lowerBounds = 0;
13 | var upperBounds = 100;
14 |
15 | if (
16 | params.effort === null ||
17 | params.effort === false ||
18 | params.effort &&
19 | typeof(params.effort) !== 'number' ||
20 | typeof(params.effort) === 'number' && params.effort < lowerBounds ||
21 | typeof(params.effort) === 'number' && params.effort > upperBounds ||
22 | typeof(params.effort) === 'number' && params.effort % 1 !== 0 ||
23 | typeof(params.effort) === 'number' && src === 'decode'
24 | ) {
25 | warnUser('The effort parameter must be a whole number between ' + lowerBounds + ' and ' + upperBounds + '.', skipWarnings);
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | module.exports = verifyEffort;
33 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyEncodeQuality.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyEncodeQuality (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 | var lowerBounds = 0;
13 | var upperBounds = 100;
14 |
15 | if (
16 | params.encodeQuality === false ||
17 | params.encodeQuality === true ||
18 | params.encodeQuality === null ||
19 | params.encodeQuality && typeof(params.encodeQuality) !== 'number' ||
20 | typeof(params.encodeQuality) === 'number' && params.encodeQuality < lowerBounds ||
21 | typeof(params.encodeQuality) === 'number' && params.encodeQuality > upperBounds ||
22 | typeof(params.encodeQuality) === 'number' && params.encodeQuality % 1 !== 0 ||
23 | typeof(params.encodeQuality) === 'number' && src === 'decode'
24 | ) {
25 | warnUser('The encodeQuality parameter must be a whole number between ' + lowerBounds + ' and ' + upperBounds + '.', skipWarnings);
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | module.exports = verifyEncodeQuality;
33 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyEncodeQuality.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyEncodeQuality';
6 | function rand (num) {
7 | return Math.round(Math.random() * num);
8 | }
9 | var testData = [
10 | // Test known good for encodeQuality
11 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: 0 }, 'encode', true] },
12 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: 0 }, 'transcode', true] },
13 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: 1 }, 'encode', true] },
14 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: 1 }, 'transcode', true] },
15 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: 50 }, 'encode', true] },
16 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: 50 }, 'transcode', true] },
17 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: 100 }, 'encode', true] },
18 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: 100 }, 'transcode', true] },
19 |
20 | // Test random number from 0-100 on encodeQuality
21 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: rand(100) }, 'encode', true] },
22 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: rand(100) }, 'transcode', true] },
23 |
24 | // Test known bad for encodeQuality
25 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: 0 }, 'decode', true] },
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: 1 }, 'decode', true] },
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: 50 }, 'decode', true] },
28 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: 100 }, 'decode', true] },
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: rand(100) }, 'decode', true] },
30 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: 101 }, 'encode', true] },
31 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: 101 }, 'decode', true] },
32 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: 101 }, 'transcode', true] },
33 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: -10 }, 'encode', true] },
34 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: -10 }, 'decode', true] },
35 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: -10 }, 'transcode', true] },
36 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: 22.2 }, 'encode', true] },
37 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: 22.2 }, 'decode', true] },
38 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: 22.2 }, 'transcode', true] },
39 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: 'a' }, 'encode', true] },
40 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: 'a' }, 'decode', true] },
41 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: 'a' }, 'transcode', true] },
42 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: [0, 1, 2] }, 'encode', true] },
43 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: [0, 1, 2] }, 'decode', true] },
44 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: [0, 1, 2] }, 'transcode', true] },
45 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: {'a': 1} }, 'encode', true] },
46 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: {'a': 1} }, 'decode', true] },
47 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: {'a': 1} }, 'transcode', true] },
48 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: null }, 'encode', true] },
49 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: null }, 'decode', true] },
50 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: null }, 'transcode', true] },
51 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: true }, 'encode', true] },
52 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: true }, 'decode', true] },
53 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: true }, 'transcode', true] },
54 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', encodeQuality: false }, 'encode', true] },
55 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', encodeQuality: false }, 'decode', true] },
56 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', encodeQuality: false }, 'transcode', true] }
57 | ];
58 |
59 | runAllTests(testName, 'helpers/verifyParams', testData);
60 |
61 | return [testName, testData.length];
62 | }
63 |
64 | module.exports = test;
65 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyFit.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyFit (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (params.fit && typeof(params.fit) !== 'object') {
14 | warnUser('The fit parameter must be a object.', skipWarnings);
15 | return false;
16 | }
17 |
18 | if (
19 | params.fit === null ||
20 | params.fit === false ||
21 | params.fit &&
22 | (
23 | Object.keys(params.fit).length !== 2 ||
24 | params.fit.width === false ||
25 | params.fit.height === false ||
26 | params.fit.width === true ||
27 | params.fit.height === true ||
28 | isNaN(parseInt(params.fit.width)) ||
29 | isNaN(parseInt(params.fit.height)) ||
30 | params.fit.width < 0 ||
31 | params.fit.height < 0 ||
32 | src === 'encode'
33 | )
34 | ) {
35 | warnUser('The fit parameter should be an object. Example: { width: 320, height: 240 }.', skipWarnings);
36 | return false;
37 | }
38 |
39 | return true;
40 | }
41 |
42 | module.exports = verifyFit;
43 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyFrameDelay.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyFrameDelay (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 | var lowerBounds = 0;
13 | var upperBounds = 60000;
14 |
15 | if (
16 | params.frameDelay === null ||
17 | params.frameDelay === false ||
18 | params.frameDelay === true ||
19 | params.frameDelay && typeof(params.frameDelay) !== 'object' ||
20 | params.frameDelay && !Array.isArray(params.frameDelay) ||
21 | params.frameDelay && src === 'decode'
22 | ) {
23 | warnUser('The frameDelay parameter must be an array of numbers like [100] or [100, 250].', skipWarnings);
24 | return false;
25 | }
26 |
27 | if (params.frameDelay && params.frameDelay.length > 0) {
28 | for (var i = 0; i < params.frameDelay.length; i++) {
29 | var item = params.frameDelay[i];
30 | if (
31 | typeof(item) !== 'number' ||
32 | item === undefined
33 | ) {
34 | warnUser('The frameDelay parameter must be an array of numbers like [100] or [100, 250].', skipWarnings);
35 | return false;
36 | }
37 | if (
38 | typeof(item) === 'number' && item < lowerBounds ||
39 | typeof(item) === 'number' && item > upperBounds
40 | ) {
41 | warnUser('Numbers in the frameDelay parameter array must be a whole number between ' + lowerBounds + ' and ' + upperBounds + '.', skipWarnings);
42 | return false;
43 | }
44 | }
45 | }
46 |
47 | return true;
48 | }
49 |
50 | module.exports = verifyFrameDelay;
51 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyFrameShape.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyFrameShape (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (
14 | params.frameShape === null ||
15 | params.frameShape &&
16 | typeof(params.frameShape) !== 'boolean' ||
17 | src === 'decode' && params.frameShape === false ||
18 | src === 'decode' && params.frameShape === true
19 | ) {
20 | warnUser('The frameShape parameter must be a boolean value.', skipWarnings);
21 | return false;
22 | }
23 |
24 | return true;
25 | }
26 |
27 | module.exports = verifyFrameShape;
28 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyFrameShape.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyFrameShape';
6 | var testData = [
7 | // Test known good for frameShape
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', frameShape: true }, 'encode', true]},
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', frameShape: true }, 'transcode', true]},
10 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', frameShape: false }, 'encode', true]},
11 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', frameShape: false }, 'transcode', true]},
12 |
13 | // Test known bad for frameShape
14 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', frameShape: true }, 'decode', true]},
15 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', frameShape: false }, 'decode', true]},
16 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', frameShape: 'a' }, 'encode', true]},
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', frameShape: 'a' }, 'decode', true]},
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', frameShape: 'a' }, 'transcode', true]},
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', frameShape: [0, 1, 2] }, 'encode', true]},
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', frameShape: [0, 1, 2] }, 'decode', true]},
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', frameShape: [0, 1, 2] }, 'transcode', true]},
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', frameShape: {'a': 1} }, 'encode', true]},
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', frameShape: {'a': 1} }, 'decode', true]},
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', frameShape: {'a': 1} }, 'transcode', true]},
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', frameShape: null }, 'encode', true]},
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', frameShape: null }, 'decode', true]},
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', frameShape: null }, 'transcode', true]},
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', frameShape: 8 }, 'encode', true]},
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', frameShape: 8 }, 'decode', true]},
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', frameShape: 8 }, 'transcode', true]}
31 | ];
32 |
33 | runAllTests(testName, 'helpers/verifyParams', testData);
34 |
35 | return [testName, testData.length];
36 | }
37 |
38 | module.exports = test;
39 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyGuess.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyGuess (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | // Throw error if params.guess is used but isn't an object
14 | if (
15 | params.guess === false ||
16 | params.guess === true ||
17 | params.guess === null ||
18 | params.guess && Array.isArray(params.guess) ||
19 | params.guess && typeof(params.guess) !== 'object' ||
20 | params.guess && src === 'decode'
21 | ) {
22 | warnUser('The guess parameter must be an object.', skipWarnings);
23 | return false;
24 | }
25 |
26 | if (params.guess && typeof(params.guess) === 'object') {
27 | // Describe all planes
28 | var y = params.guess.y;
29 | var co = params.guess.co;
30 | var cg = params.guess.cg;
31 | var alpha = params.guess.alpha;
32 | var lookback = params.guess.lookback;
33 |
34 | var planes = [y, co, cg, alpha, lookback];
35 |
36 | for (var i = 0; i < planes.length; i++) {
37 | var plane = planes[i];
38 |
39 | if (
40 | plane === false ||
41 | plane && typeof(plane) !== 'string' ||
42 | plane && typeof(plane) === 'string' &&
43 | (
44 | plane !== 'heuristically' &&
45 | plane !== 'average' &&
46 | plane !== 'median gradient' &&
47 | plane !== 'median number' &&
48 | plane !== 'mixed'
49 | )
50 | ) {
51 | warnUser('The guess.' + plane + ' parameter must be one of the following: "heuristically", "average", "median gradient", "median number", "mixed".', skipWarnings);
52 | return false;
53 | }
54 | }
55 |
56 | var expectedKeys = ['y', 'co', 'cg', 'alpha', 'lookback'];
57 | for (var key in params.guess) {
58 | var keyMatched = false;
59 | for (var j = 0; j < expectedKeys.length; j++) {
60 | var expectedKey = expectedKeys[j];
61 | if (key === expectedKey) {
62 | keyMatched = true;
63 | }
64 | }
65 | if (!keyMatched) {
66 | warnUser('Unexpected parameter: guess.' + key + '. Use one or more of the following instead: y, co, cg, alpha, lookback.', skipWarnings);
67 | return false;
68 | }
69 | }
70 | }
71 |
72 | return true;
73 | }
74 |
75 | module.exports = verifyGuess;
76 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyInterlace.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyInterlace (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (
14 | params.interlace === null ||
15 | typeof(params.interlace) === 'object' ||
16 | typeof(params.interlace) === 'number' ||
17 | (
18 | typeof(params.interlace) === 'boolean' &&
19 | params.interlace !== false &&
20 | params.interlace !== true
21 | ) ||
22 | (
23 | typeof(params.interlace) === 'string' &&
24 | params.interlace !== 'auto'
25 | ) ||
26 | src === 'decode' && params.interlace === false ||
27 | src === 'decode' && params.interlace === true ||
28 | src === 'decode' && params.interlace === 'auto'
29 | ) {
30 | warnUser('The interlace parameter must be set to true, false, or "auto".', skipWarnings);
31 | return false;
32 | }
33 |
34 | return true;
35 | }
36 |
37 | module.exports = verifyInterlace;
38 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyInterlace.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyInterlace';
6 | var testData = [
7 | // Test known good for interlace
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', interlace: true }, 'encode', true]},
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', interlace: true }, 'transcode', true]},
10 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', interlace: false }, 'encode', true]},
11 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', interlace: false }, 'transcode', true]},
12 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', interlace: 'auto' }, 'encode', true]},
13 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', interlace: 'auto' }, 'transcode', true]},
14 |
15 | // Test known bad for interlace
16 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', interlace: true }, 'decode', true]},
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', interlace: false }, 'decode', true]},
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', interlace: 'auto' }, 'decode', true]},
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', interlace: 'a' }, 'encode', true]},
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', interlace: 'a' }, 'decode', true]},
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', interlace: 'a' }, 'transcode', true]},
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', interlace: [0, 1, 2] }, 'encode', true]},
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', interlace: [0, 1, 2] }, 'decode', true]},
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', interlace: [0, 1, 2] }, 'transcode', true]},
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', interlace: {'a': 1} }, 'encode', true]},
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', interlace: {'a': 1} }, 'decode', true]},
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', interlace: {'a': 1} }, 'transcode', true]},
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', interlace: null }, 'encode', true]},
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', interlace: null }, 'decode', true]},
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', interlace: null }, 'transcode', true]},
31 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', interlace: 8 }, 'encode', true]},
32 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', interlace: 8 }, 'decode', true]},
33 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', interlace: 8 }, 'transcode', true]}
34 | ];
35 |
36 | runAllTests(testName, 'helpers/verifyParams', testData);
37 |
38 | return [testName, testData.length];
39 | }
40 |
41 | module.exports = test;
42 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyKeepAlpha.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyKeepAlpha (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (
14 | params.keepAlpha === null ||
15 | params.keepAlpha &&
16 | typeof(params.keepAlpha) !== 'boolean' ||
17 | src === 'decode' && params.keepAlpha === false ||
18 | src === 'decode' && params.keepAlpha === true
19 | ) {
20 | warnUser('The keepAlpha parameter must be a boolean value.', skipWarnings);
21 | return false;
22 | }
23 |
24 | return true;
25 | }
26 |
27 | module.exports = verifyKeepAlpha;
28 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyKeepAlpha.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyKeepAlpha';
6 | var testData = [
7 | // Test known good for keepAlpha
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', keepAlpha: true }, 'encode', true]},
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', keepAlpha: true }, 'transcode', true]},
10 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', keepAlpha: false }, 'encode', true]},
11 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', keepAlpha: false }, 'transcode', true]},
12 |
13 | // Test known bad for keepAlpha
14 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepAlpha: true }, 'decode', true]},
15 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepAlpha: false }, 'decode', true]},
16 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepAlpha: 'a' }, 'encode', true]},
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepAlpha: 'a' }, 'decode', true]},
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepAlpha: 'a' }, 'transcode', true]},
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepAlpha: [0, 1, 2] }, 'encode', true]},
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepAlpha: [0, 1, 2] }, 'decode', true]},
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepAlpha: [0, 1, 2] }, 'transcode', true]},
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepAlpha: {'a': 1} }, 'encode', true]},
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepAlpha: {'a': 1} }, 'decode', true]},
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepAlpha: {'a': 1} }, 'transcode', true]},
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepAlpha: null }, 'encode', true]},
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepAlpha: null }, 'decode', true]},
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepAlpha: null }, 'transcode', true]},
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepAlpha: 8 }, 'encode', true]},
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepAlpha: 8 }, 'decode', true]},
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepAlpha: 8 }, 'transcode', true]}
31 | ];
32 |
33 | runAllTests(testName, 'helpers/verifyParams', testData);
34 |
35 | return [testName, testData.length];
36 | }
37 |
38 | module.exports = test;
39 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyKeepColorProfile.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | // eslint-disable-next-line no-unused-vars
11 | function verifyKeepColorProfile (params, src, skipWarnings) {
12 | var warnUser = require('../warnUser.js');
13 |
14 | if (
15 | params.keepColorProfile === null ||
16 | params.keepColorProfile &&
17 | typeof(params.keepColorProfile) !== 'boolean'
18 | ) {
19 | warnUser('The keepColorProfile parameter must be a boolean value.', skipWarnings);
20 | return false;
21 | }
22 |
23 | return true;
24 | }
25 |
26 | module.exports = verifyKeepColorProfile;
27 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyKeepColorProfile.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyKeepColorProfile';
6 | var testData = [
7 | // Test known good for keepColorProfile
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', keepColorProfile: true }, 'encode', true] },
9 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', keepColorProfile: false }, 'encode', true] },
10 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', keepColorProfile: true }, 'transcode', true] },
11 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', keepColorProfile: false }, 'transcode', true] },
12 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', keepColorProfile: true }, 'decode', true] },
13 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', keepColorProfile: false }, 'decode', true] },
14 |
15 | // Test known bad for keepColorProfile
16 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepColorProfile: 'a' }, 'encode', true] },
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepColorProfile: 'a' }, 'decode', true] },
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepColorProfile: 'a' }, 'transcode', true] },
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepColorProfile: [0, 1, 2] }, 'encode', true] },
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepColorProfile: [0, 1, 2] }, 'decode', true] },
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepColorProfile: [0, 1, 2] }, 'transcode', true] },
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepColorProfile: {'a': 1} }, 'encode', true] },
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepColorProfile: {'a': 1} }, 'decode', true] },
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepColorProfile: {'a': 1} }, 'transcode', true] },
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepColorProfile: null }, 'encode', true] },
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepColorProfile: null }, 'decode', true] },
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepColorProfile: null }, 'transcode', true] },
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepColorProfile: 8 }, 'encode', true] },
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepColorProfile: 8 }, 'decode', true] },
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepColorProfile: 8 }, 'transcode', true] }
31 | ];
32 |
33 | runAllTests(testName, 'helpers/verifyParams', testData);
34 |
35 | return [testName, testData.length];
36 | }
37 |
38 | module.exports = test;
39 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyKeepMetaData.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | // eslint-disable-next-line no-unused-vars
11 | function verifyKeepMetaData (params, src, skipWarnings) {
12 | var warnUser = require('../warnUser.js');
13 |
14 | if (
15 | params.keepMetaData === null ||
16 | params.keepMetaData &&
17 | typeof(params.keepMetaData) !== 'boolean'
18 | ) {
19 | warnUser('The keepMetaData parameter must be a boolean value.', skipWarnings);
20 | return false;
21 | }
22 |
23 | return true;
24 | }
25 |
26 | module.exports = verifyKeepMetaData;
27 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyKeepMetaData.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyKeepMetaData';
6 | var testData = [
7 | // Test known good for keepMetaData
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', keepMetaData: true }, 'encode', true] },
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', keepMetaData: true }, 'decode', true] },
10 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', keepMetaData: true }, 'transcode', true] },
11 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', keepMetaData: false }, 'encode', true] },
12 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', keepMetaData: false }, 'decode', true] },
13 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', keepMetaData: false }, 'transcode', true] },
14 |
15 | // Test known bad for keepMetaData
16 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepMetaData: 'a' }, 'encode', true] },
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepMetaData: 'a' }, 'decode', true] },
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepMetaData: 'a' }, 'transcode', true] },
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepMetaData: [0, 1, 2] }, 'encode', true] },
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepMetaData: [0, 1, 2] }, 'decode', true] },
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepMetaData: [0, 1, 2] }, 'transcode', true] },
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepMetaData: {'a': 1} }, 'encode', true] },
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepMetaData: {'a': 1} }, 'decode', true] },
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepMetaData: {'a': 1} }, 'transcode', true] },
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepMetaData: null }, 'encode', true] },
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepMetaData: null }, 'decode', true] },
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepMetaData: null }, 'transcode', true] },
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepMetaData: 8 }, 'encode', true] },
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepMetaData: 8 }, 'decode', true] },
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepMetaData: 8 }, 'transcode', true] }
31 | ];
32 |
33 | runAllTests(testName, 'helpers/verifyParams', testData);
34 |
35 | return [testName, testData.length];
36 | }
37 |
38 | module.exports = test;
39 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyKeepPalette.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | // eslint-disable-next-line no-unused-vars
11 | function verifyKeepPalette (params, src, skipWarnings) {
12 | var warnUser = require('../warnUser.js');
13 |
14 | if (
15 | params.keepPalette === null ||
16 | params.keepPalette &&
17 | typeof(params.keepPalette) !== 'boolean'
18 | ) {
19 | warnUser('The keepPalette parameter must be a boolean value.', skipWarnings);
20 | return false;
21 | }
22 |
23 | return true;
24 | }
25 |
26 | module.exports = verifyKeepPalette;
27 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyKeepPalette.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyKeepPalette';
6 | var testData = [
7 | // Test known good for keepPalette
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', keepPalette: true }, 'encode', true] },
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', keepPalette: true }, 'decode', true] },
10 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', keepPalette: true }, 'transcode', true] },
11 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', keepPalette: false }, 'encode', true] },
12 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', keepPalette: false }, 'decode', true] },
13 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', keepPalette: false }, 'transcode', true] },
14 |
15 | // Test known bad for keepPalette
16 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepPalette: 'a' }, 'encode', true] },
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepPalette: 'a' }, 'decode', true] },
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepPalette: 'a' }, 'transcode', true] },
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepPalette: [0, 1, 2] }, 'encode', true] },
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepPalette: [0, 1, 2] }, 'decode', true] },
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepPalette: [0, 1, 2] }, 'transcode', true] },
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepPalette: {'a': 1} }, 'encode', true] },
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepPalette: {'a': 1} }, 'decode', true] },
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepPalette: {'a': 1} }, 'transcode', true] },
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepPalette: null }, 'encode', true] },
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepPalette: null }, 'decode', true] },
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepPalette: null }, 'transcode', true] },
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', keepPalette: 8 }, 'encode', true] },
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', keepPalette: 8 }, 'decode', true] },
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', keepPalette: 8 }, 'transcode', true] }
31 | ];
32 |
33 | runAllTests(testName, 'helpers/verifyParams', testData);
34 |
35 | return [testName, testData.length];
36 | }
37 |
38 | module.exports = test;
39 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyManiacDivisor.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyManiacDivisor (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 | var lowerBounds = 1;
13 | var upperBounds = 268435455;
14 |
15 | if (
16 | params.maniacDivisor === false ||
17 | params.maniacDivisor === true ||
18 | params.maniacDivisor === null ||
19 | params.maniacDivisor && typeof(params.maniacDivisor) !== 'number' ||
20 | typeof(params.maniacDivisor) === 'number' && params.maniacDivisor < lowerBounds ||
21 | typeof(params.maniacDivisor) === 'number' && params.maniacDivisor > upperBounds ||
22 | typeof(params.maniacDivisor) === 'number' && params.maniacDivisor % 1 !== 0 ||
23 | typeof(params.maniacDivisor) === 'number' && src === 'decode'
24 | ) {
25 | warnUser('The maniacDivisor parameter must be a number between ' + lowerBounds + ' and ' + upperBounds + '.', skipWarnings);
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | module.exports = verifyManiacDivisor;
33 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyManiacMinSize.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyManiacMinSize (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 | var lowerBounds = 0;
13 | // The upperBounds are not defined in the FLIF source code. It only checks for if (x < 0) { throw error }
14 |
15 | if (
16 | params.maniacMinSize === false ||
17 | params.maniacMinSize === true ||
18 | params.maniacMinSize === null ||
19 | params.maniacMinSize && typeof(params.maniacMinSize) !== 'number' ||
20 | typeof(params.maniacMinSize) === 'number' && params.maniacMinSize < lowerBounds ||
21 | typeof(params.maniacMinSize) === 'number' && params.maniacMinSize % 1 !== 0 ||
22 | typeof(params.maniacMinSize) === 'number' && src === 'decode'
23 | ) {
24 | warnUser('The maniacMinSize parameter must be a whole number greater than or equal to ' + lowerBounds + '.', skipWarnings);
25 | return false;
26 | }
27 |
28 | return true;
29 | }
30 |
31 | module.exports = verifyManiacMinSize;
32 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyManiacMinSize.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyManiacMinSize';
6 | function rand (num) {
7 | return Math.round(Math.random() * num);
8 | }
9 | var testData = [
10 | // Test known good for maniacMinSize
11 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', maniacMinSize: 50 }, 'encode', true]},
12 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', maniacMinSize: 50 }, 'transcode', true]},
13 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', maniacMinSize: 0 }, 'encode', true]},
14 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', maniacMinSize: 0 }, 'transcode', true]},
15 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', maniacMinSize: 1 }, 'encode', true]},
16 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', maniacMinSize: 1 }, 'transcode', true]},
17 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', maniacMinSize: 2 }, 'encode', true]},
18 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', maniacMinSize: 2 }, 'transcode', true]},
19 |
20 | // Test random number from 0-1000 on maniacMinSize
21 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', maniacMinSize: rand(1000) }, 'encode', true]},
22 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', maniacMinSize: rand(1000) }, 'transcode', true]},
23 |
24 | // Test known bad for maniacMinSize
25 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maniacMinSize: 50 }, 'decode', true]},
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maniacMinSize: 1 }, 'decode', true]},
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maniacMinSize: 2 }, 'decode', true]},
28 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maniacMinSize: rand(1000) }, 'decode', true]},
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maniacMinSize: 0 }, 'decode', true]},
30 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maniacMinSize: -10 }, 'encode', true]},
31 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maniacMinSize: -10 }, 'decode', true]},
32 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maniacMinSize: -10 }, 'transcode', true]},
33 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maniacMinSize: 22.2 }, 'encode', true]},
34 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maniacMinSize: 22.2 }, 'decode', true]},
35 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maniacMinSize: 22.2 }, 'transcode', true]},
36 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maniacMinSize: 'a' }, 'encode', true]},
37 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maniacMinSize: 'a' }, 'decode', true]},
38 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maniacMinSize: 'a' }, 'transcode', true]},
39 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maniacMinSize: [0, 1, 2] }, 'encode', true]},
40 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maniacMinSize: [0, 1, 2] }, 'decode', true]},
41 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maniacMinSize: [0, 1, 2] }, 'transcode', true]},
42 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maniacMinSize: {'a': 1} }, 'encode', true]},
43 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maniacMinSize: {'a': 1} }, 'decode', true]},
44 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maniacMinSize: {'a': 1} }, 'transcode', true]},
45 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maniacMinSize: null }, 'encode', true]},
46 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maniacMinSize: null }, 'decode', true]},
47 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maniacMinSize: null }, 'transcode', true]},
48 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maniacMinSize: true }, 'encode', true]},
49 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maniacMinSize: true }, 'decode', true]},
50 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maniacMinSize: true }, 'transcode', true]},
51 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maniacMinSize: false }, 'encode', true]},
52 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maniacMinSize: false }, 'decode', true]},
53 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maniacMinSize: false }, 'transcode', true]}
54 | ];
55 |
56 | runAllTests(testName, 'helpers/verifyParams', testData);
57 |
58 | return [testName, testData.length];
59 | }
60 |
61 | module.exports = test;
62 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyManiacRepeats.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyManiacRepeats (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 | var lowerBounds = 0;
13 | var upperBounds = 20;
14 |
15 | if (
16 | params.maniacRepeats === false ||
17 | params.maniacRepeats === true ||
18 | params.maniacRepeats === null ||
19 | params.maniacRepeats && typeof(params.maniacRepeats) !== 'number' ||
20 | typeof(params.maniacRepeats) === 'number' && params.maniacRepeats < lowerBounds ||
21 | typeof(params.maniacRepeats) === 'number' && params.maniacRepeats > upperBounds ||
22 | typeof(params.maniacRepeats) === 'number' && params.maniacRepeats % 1 !== 0 ||
23 | typeof(params.maniacRepeats) === 'number' && src === 'decode'
24 | ) {
25 | warnUser('The maniacRepeats parameter must be a whole number between ' + lowerBounds + ' and ' + upperBounds + '.', skipWarnings);
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | module.exports = verifyManiacRepeats;
33 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyManiacThreshold.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyManiacThreshold (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 | var lowerBounds = 4;
13 | var upperBounds = 100000;
14 |
15 | if (
16 | params.maniacThreshold === false ||
17 | params.maniacThreshold === true ||
18 | params.maniacThreshold === null ||
19 | params.maniacThreshold && typeof(params.maniacThreshold) !== 'number' ||
20 | typeof(params.maniacThreshold) === 'number' && params.maniacThreshold < lowerBounds ||
21 | typeof(params.maniacThreshold) === 'number' && params.maniacThreshold > upperBounds ||
22 | typeof(params.maniacThreshold) === 'number' && params.maniacThreshold % 1 !== 0 ||
23 | typeof(params.maniacThreshold) === 'number' && src === 'decode'
24 | ) {
25 | warnUser('The maniacThreshold parameter must be a whole number between ' + lowerBounds + ' and ' + upperBounds + '.', skipWarnings);
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | module.exports = verifyManiacThreshold;
33 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyMaxFrameLookBack.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyMaxFrameLookBack (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 | var lowerBounds = -1;
13 | var upperBounds = 256;
14 |
15 | if (
16 | params.maxFrameLookBack === false ||
17 | params.maxFrameLookBack === true ||
18 | params.maxFrameLookBack === null ||
19 | params.maxFrameLookBack && typeof(params.maxFrameLookBack) !== 'number' ||
20 | typeof(params.maxFrameLookBack) === 'number' && params.maxFrameLookBack < lowerBounds ||
21 | typeof(params.maxFrameLookBack) === 'number' && params.maxFrameLookBack > upperBounds ||
22 | typeof(params.maxFrameLookBack) === 'number' && params.maxFrameLookBack % 1 !== 0 ||
23 | typeof(params.maxFrameLookBack) === 'number' && src === 'decode'
24 | ) {
25 | warnUser('The maxFrameLookBack parameter must be a whole number between ' + lowerBounds + ' and ' + upperBounds + '.', skipWarnings);
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | module.exports = verifyMaxFrameLookBack;
33 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyMaxFrameLookBack.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyMaxFrameLookBack';
6 | function rand (num) {
7 | return Math.round(Math.random() * num);
8 | }
9 | var testData = [
10 | // Test known good for maxFrameLookBack
11 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: -1 }, 'encode', true]},
12 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: -1 }, 'transcode', true]},
13 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: 0 }, 'encode', true]},
14 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: 0 }, 'transcode', true]},
15 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: 1 }, 'encode', true]},
16 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: 1 }, 'transcode', true]},
17 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: 256 }, 'encode', true]},
18 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: 256 }, 'transcode', true]},
19 |
20 | // Test random number from -1 and 256 on maxFrameLookBack
21 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: rand(257) - 1 }, 'encode', true]},
22 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: rand(257) - 1 }, 'transcode', true]},
23 |
24 | // Test known bad for maxFrameLookBack
25 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maxFrameLookBack: 1 }, 'decode', true]},
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maxFrameLookBack: rand(257) - 1 }, 'decode', true]},
27 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: -2 }, 'encode', true]},
28 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maxFrameLookBack: -2 }, 'decode', true]},
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: -2 }, 'transcode', true]},
30 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: 22.2 }, 'encode', true]},
31 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maxFrameLookBack: 22.2 }, 'decode', true]},
32 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: 22.2 }, 'transcode', true]},
33 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: 257 }, 'encode', true]},
34 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maxFrameLookBack: 257 }, 'decode', true]},
35 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: 257 }, 'transcode', true]},
36 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: 'a' }, 'encode', true]},
37 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maxFrameLookBack: 'a' }, 'decode', true]},
38 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: 'a' }, 'transcode', true]},
39 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: [0, 1, 2] }, 'encode', true]},
40 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maxFrameLookBack: [0, 1, 2] }, 'decode', true]},
41 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: [0, 1, 2] }, 'transcode', true]},
42 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: {'a': 1} }, 'encode', true]},
43 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maxFrameLookBack: {'a': 1} }, 'decode', true]},
44 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: {'a': 1} }, 'transcode', true]},
45 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: null }, 'encode', true]},
46 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maxFrameLookBack: null }, 'decode', true]},
47 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: null }, 'transcode', true]},
48 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: true }, 'encode', true]},
49 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maxFrameLookBack: true }, 'decode', true]},
50 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: true }, 'transcode', true]},
51 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', maxFrameLookBack: false }, 'encode', true]},
52 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', maxFrameLookBack: false }, 'decode', true]},
53 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', maxFrameLookBack: false }, 'transcode', true]}
54 | ];
55 |
56 | runAllTests(testName, 'helpers/verifyParams', testData);
57 |
58 | return [testName, testData.length];
59 | }
60 |
61 | module.exports = test;
62 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyMaxPaletteSize.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyMaxPaletteSize (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 | var lowerBounds = -32000;
13 | var upperBounds = 32000;
14 |
15 | if (
16 | params.maxPaletteSize === false ||
17 | params.maxPaletteSize === true ||
18 | params.maxPaletteSize === null ||
19 | params.maxPaletteSize && typeof(params.maxPaletteSize) !== 'number' ||
20 | typeof(params.maxPaletteSize) === 'number' && params.maxPaletteSize < lowerBounds ||
21 | typeof(params.maxPaletteSize) === 'number' && params.maxPaletteSize > upperBounds ||
22 | typeof(params.maxPaletteSize) === 'number' && params.maxPaletteSize % 1 !== 0 ||
23 | typeof(params.maxPaletteSize) === 'number' && src === 'decode'
24 | ) {
25 | warnUser('The maxPaletteSize parameter must be a whole number between ' + lowerBounds + ' and ' + upperBounds + '.', skipWarnings);
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | module.exports = verifyMaxPaletteSize;
33 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyOverwrite.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | // eslint-disable-next-line no-unused-vars
11 | function verifyOverwrite (params, src, skipWarnings) {
12 | var warnUser = require('../warnUser.js');
13 |
14 | if (
15 | params.overwrite === null ||
16 | params.overwrite &&
17 | typeof(params.overwrite) !== 'boolean'
18 | ) {
19 | warnUser('The overwrite parameter must be a boolean value.', skipWarnings);
20 | return false;
21 | }
22 |
23 | return true;
24 | }
25 |
26 | module.exports = verifyOverwrite;
27 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyOverwrite.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyOverwrite';
6 | var testData = [
7 | // Test known good for overwrite
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', overwrite: true }, 'encode', true] },
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', overwrite: true }, 'decode', true] },
10 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', overwrite: true }, 'transcode', true] },
11 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', overwrite: false }, 'encode', true] },
12 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.png', overwrite: false }, 'decode', true] },
13 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', overwrite: false }, 'transcode', true] },
14 |
15 | // Test known bad for overwrite
16 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', overwrite: 'a' }, 'encode', true] },
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', overwrite: 'a' }, 'decode', true] },
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', overwrite: 'a' }, 'transcode', true] },
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', overwrite: [0, 1, 2] }, 'encode', true] },
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', overwrite: [0, 1, 2] }, 'decode', true] },
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', overwrite: [0, 1, 2] }, 'transcode', true] },
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', overwrite: {'a': 1} }, 'encode', true] },
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', overwrite: {'a': 1} }, 'decode', true] },
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', overwrite: {'a': 1} }, 'transcode', true] },
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', overwrite: null }, 'encode', true] },
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', overwrite: null }, 'decode', true] },
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', overwrite: null }, 'transcode', true] },
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', overwrite: 8 }, 'encode', true] },
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', overwrite: 8 }, 'decode', true] },
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', overwrite: 8 }, 'transcode', true] }
31 | ];
32 |
33 | runAllTests(testName, 'helpers/verifyParams', testData);
34 |
35 | return [testName, testData.length];
36 | }
37 |
38 | module.exports = test;
39 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyResize.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyResize (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (params.resize && typeof(params.resize) !== 'object') {
14 | warnUser('The resize parameter must be a object.', skipWarnings);
15 | return false;
16 | }
17 |
18 | if (
19 | params.resize === null ||
20 | params.resize === false ||
21 | params.resize &&
22 | (
23 | Object.keys(params.resize).length !== 2 ||
24 | params.resize.width === false ||
25 | params.resize.height === false ||
26 | params.resize.width === true ||
27 | params.resize.height === true ||
28 | isNaN(parseInt(params.resize.width)) ||
29 | isNaN(parseInt(params.resize.height)) ||
30 | params.resize.width < 1 ||
31 | params.resize.height < 1 ||
32 | src === 'encode'
33 | )
34 | ) {
35 | warnUser('The resize parameter should be an object. Example: { width: 320, height: 240 }.', skipWarnings);
36 | return false;
37 | }
38 |
39 | return true;
40 | }
41 |
42 | module.exports = verifyResize;
43 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyScale.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyScale (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (
14 | params.scale === null ||
15 | params.scale === false ||
16 | params.scale &&
17 | typeof(params.scale) !== 'number' ||
18 | params.scale &&
19 | (
20 | params.scale !== 1 &&
21 | params.scale !== 2 &&
22 | params.scale !== 4 &&
23 | params.scale !== 8 &&
24 | params.scale !== 16 &&
25 | params.scale !== 32 ||
26 | src === 'encode'
27 | )
28 | ) {
29 | warnUser('The scale parameter must be one of the following numbers: 1, 2, 4, 8, 16, 32.', skipWarnings);
30 | return false;
31 | }
32 |
33 | return true;
34 | }
35 |
36 | module.exports = verifyScale;
37 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifySubtractGreen.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifySubtractGreen (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (
14 | params.subtractGreen === null ||
15 | params.subtractGreen &&
16 | typeof(params.subtractGreen) !== 'boolean' ||
17 | src === 'decode' && params.subtractGreen === false ||
18 | src === 'decode' && params.subtractGreen === true
19 | ) {
20 | warnUser('The subtractGreen parameter must be a boolean value.', skipWarnings);
21 | return false;
22 | }
23 |
24 | return true;
25 | }
26 |
27 | module.exports = verifySubtractGreen;
28 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifySubtractGreen.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifySubtractGreen';
6 | var testData = [
7 | // Test known good for subtractGreen
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', subtractGreen: true }, 'encode', true]},
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', subtractGreen: true }, 'transcode', true]},
10 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', subtractGreen: false }, 'encode', true]},
11 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', subtractGreen: false }, 'transcode', true]},
12 |
13 | // Test known bad for subtractGreen
14 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', subtractGreen: true }, 'decode', true]},
15 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', subtractGreen: false }, 'decode', true]},
16 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', subtractGreen: 'a' }, 'encode', true]},
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', subtractGreen: 'a' }, 'decode', true]},
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', subtractGreen: 'a' }, 'transcode', true]},
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', subtractGreen: [0, 1, 2] }, 'encode', true]},
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', subtractGreen: [0, 1, 2] }, 'decode', true]},
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', subtractGreen: [0, 1, 2] }, 'transcode', true]},
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', subtractGreen: {'a': 1} }, 'encode', true]},
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', subtractGreen: {'a': 1} }, 'decode', true]},
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', subtractGreen: {'a': 1} }, 'transcode', true]},
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', subtractGreen: null }, 'encode', true]},
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', subtractGreen: null }, 'decode', true]},
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', subtractGreen: null }, 'transcode', true]},
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', subtractGreen: 8 }, 'encode', true]},
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', subtractGreen: 8 }, 'decode', true]},
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', subtractGreen: 8 }, 'transcode', true]}
31 | ];
32 |
33 | runAllTests(testName, 'helpers/verifyParams', testData);
34 |
35 | return [testName, testData.length];
36 | }
37 |
38 | module.exports = test;
39 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyYcocg.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Verify that the passed in parameters exists are the correct types.
3 | * Return helpful error messages to users.
4 | *
5 | * @param {object} params The object the user passed in.
6 | * @param {string} src The method that called verifyParams, used in error messages.
7 | * @param {boolean} skipWarnings This is used in our tests to not flag false positives.
8 | * @return {boolean} True if params pass, false if there was a problem.
9 | */
10 | function verifyYcocg (params, src, skipWarnings) {
11 | var warnUser = require('../warnUser.js');
12 |
13 | if (
14 | params.ycocg === null ||
15 | params.ycocg &&
16 | typeof(params.ycocg) !== 'boolean' ||
17 | src === 'decode' && params.ycocg === false ||
18 | src === 'decode' && params.ycocg === true
19 | ) {
20 | warnUser('The ycocg parameter must be a boolean value.', skipWarnings);
21 | return false;
22 | }
23 |
24 | return true;
25 | }
26 |
27 | module.exports = verifyYcocg;
28 |
--------------------------------------------------------------------------------
/src/helpers/verifyParams/verifyYcocg.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../../testers/loopOverAllTestSets.js');
5 | var testName = 'verifyYcocg';
6 | var testData = [
7 | // Test known good for ycocg
8 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', ycocg: true }, 'encode', true]},
9 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', ycocg: true }, 'transcode', true]},
10 | { expected: true, arguments: [{ input: 'a.png', output: 'a.flif', ycocg: false }, 'encode', true]},
11 | { expected: true, arguments: [{ input: 'a.flif', output: 'a.flif', ycocg: false }, 'transcode', true]},
12 |
13 | // Test known bad for ycocg
14 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', ycocg: true }, 'decode', true]},
15 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', ycocg: false }, 'decode', true]},
16 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', ycocg: 'a' }, 'encode', true]},
17 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', ycocg: 'a' }, 'decode', true]},
18 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', ycocg: 'a' }, 'transcode', true]},
19 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', ycocg: [0, 1, 2] }, 'encode', true]},
20 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', ycocg: [0, 1, 2] }, 'decode', true]},
21 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', ycocg: [0, 1, 2] }, 'transcode', true]},
22 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', ycocg: {'a': 1} }, 'encode', true]},
23 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', ycocg: {'a': 1} }, 'decode', true]},
24 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', ycocg: {'a': 1} }, 'transcode', true]},
25 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', ycocg: null }, 'encode', true]},
26 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', ycocg: null }, 'decode', true]},
27 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', ycocg: null }, 'transcode', true]},
28 | { expected: false, arguments: [{ input: 'a.png', output: 'a.flif', ycocg: 8 }, 'encode', true]},
29 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.png', ycocg: 8 }, 'decode', true]},
30 | { expected: false, arguments: [{ input: 'a.flif', output: 'a.flif', ycocg: 8 }, 'transcode', true]}
31 | ];
32 |
33 | runAllTests(testName, 'helpers/verifyParams', testData);
34 |
35 | return [testName, testData.length];
36 | }
37 |
38 | module.exports = test;
39 |
--------------------------------------------------------------------------------
/src/helpers/warnUser.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Logs out a stack trace and helpful human readable message.
3 | * @param {string} message The helpful message to be logged out.
4 | * @param {boolean} skipWarnings If true, skip logging console errors.
5 | */
6 | function warnUser (message, skipWarnings) {
7 | skipWarnings = skipWarnings || false;
8 |
9 | if (typeof(skipWarnings) !== 'boolean') {
10 | skipWarnings = false;
11 | }
12 |
13 | if (!skipWarnings) {
14 | var stack = (new Error()).stack.trim().split('\n');
15 | var stackTrace = [
16 | stack[3].trim().replace('at ', ''),
17 | stack[4].trim().replace('at ', ''),
18 | stack[5].trim().replace('at ', ''),
19 | stack[6].trim().replace('at ', '')
20 | ].join('\n');
21 | console.log('\nWARNING: ' + message + '\n\n' + stackTrace + '\n'); // eslint-disable-line no-console
22 | }
23 | }
24 |
25 | module.exports = warnUser;
26 |
--------------------------------------------------------------------------------
/src/helpers/warnUser.test.js:
--------------------------------------------------------------------------------
1 | function test () {
2 | var testName = 'warnUser';
3 |
4 | // The function is used to console log out errors to the user.
5 | // Nothing is returned, so nothing can be tested.
6 |
7 | return [testName, 0];
8 | }
9 |
10 | module.exports = test;
11 |
--------------------------------------------------------------------------------
/src/information/breakpoints.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Does not decode, just returns metadata about the breakpoints
3 | * in the flif. This data can be used to truncate a file at
4 | * different points. The breakpoints, or "truncation offsets",
5 | * are for truncations at scales 1:8, 1:4, 1:2.
6 | * This function runs synchronously.
7 | *
8 | * @param {string} file Filepath to the flif image.
9 | * @return {object} An object like the example below:
10 | * {
11 | offsetStart: 11,
12 | eighth: 8080,
13 | fourth: 24900,
14 | half: 90422
15 | }
16 | */
17 | function breakpoints (file) {
18 | var identify = require('./identify.js');
19 | var runCommandSync = require('../helpers/runCommandSync.js');
20 |
21 | if (!file || typeof(file) !== 'string') {
22 | throw 'You must pass in a string to the breakpoints method.';
23 | } else if (!file.endsWith('.flif')) {
24 | throw 'The breakpoints method only works on FLIF files.';
25 | }
26 |
27 | if (identify(file).interlace === 'non-interlaced') {
28 | return {};
29 | } else {
30 | var rawData = runCommandSync('--decode --breakpoints ' + file);
31 | rawData = rawData.split('\n');
32 |
33 | var offsetStart = parseInt(rawData[0].split('offset ')[1]);
34 | var eighth = parseInt(rawData[1].split(' ')[2]);
35 | var fourth = parseInt(rawData[2].split(' ')[2]);
36 | var half = parseInt(rawData[3].split(' ')[2]);
37 |
38 | var data = {
39 | 'offsetStart': offsetStart,
40 | 'eighth': eighth,
41 | 'fourth': fourth,
42 | 'half': half
43 | };
44 |
45 | return data;
46 | }
47 | }
48 |
49 | module.exports = breakpoints;
50 |
--------------------------------------------------------------------------------
/src/information/breakpoints.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../testers/loopOverAllTestSets.js');
5 | var testName = 'breakpoints';
6 | var path = require('path');
7 | var testData = [
8 | { expected: {}, arguments: [path.join('.', 'sample', 'cat.flif')] },
9 | { expected: {
10 | offsetStart: 11,
11 | eighth: 8080,
12 | fourth: 24900,
13 | half: 90422
14 | }, arguments: [path.join('.', 'sample', 'output.flif')] }
15 | ];
16 |
17 | runAllTests(testName, 'information', testData);
18 |
19 | return [testName, testData.length];
20 | }
21 |
22 | module.exports = test;
23 |
--------------------------------------------------------------------------------
/src/information/identify.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Does not decode, just identifies the input flif file.
3 | *
4 | * @param {string} file The path to the flif file to inspect
5 | * @return {object} Data about the provided flif, including:
6 | * name, dimensions, color, interlace, size
7 | */
8 | function identify (file) {
9 | var fs = require('fs');
10 | var runCommandSync = require('../helpers/runCommandSync.js');
11 |
12 | if (!file || typeof(file) !== 'string') {
13 | throw 'You must pass in a string to the identify method.';
14 | } else if (!(file.endsWith('.flif') || file.endsWith('.flif"') || file.endsWith('.flif\''))) {
15 | throw 'The identify method only works on FLIF files.';
16 | }
17 |
18 | // Remove first char if it is a quote
19 | if (file.substring(0, 1) === '"' || file.substring(0, 1) === '\'') {
20 | file = file.substring(1);
21 | }
22 | // Remove last char if it is a quote
23 | if (file.split('').pop() === '"' || file.split('').pop() === '\'') {
24 | file = file.slice(0, -1);
25 | }
26 |
27 | var stats = fs.statSync(file);
28 |
29 | // 'sample\cat.flif: FLIF image, 80x64, 8-bit RGBA, non-interlaced'
30 | var rawData = runCommandSync('-d -i "' + file + '"').trim();
31 |
32 | // 'sample\cat.flif'
33 | var fileName = rawData.split(': ')[0];
34 |
35 | // 'FLIF image, 80x64, 8-bit RGBA, non-interlaced'
36 | var info = rawData.split(': ')[1];
37 |
38 | // ["FLIF image", "80x64", "8-bit RGBA", "non-interlaced"]
39 | info = info.split(', ');
40 |
41 | var data = {
42 | 'file': fileName,
43 | 'dimensions': info[1],
44 | 'color': info[2],
45 | 'interlace': info[3],
46 | 'size': stats.size
47 | };
48 |
49 | return data;
50 | }
51 |
52 | module.exports = identify;
53 |
--------------------------------------------------------------------------------
/src/information/identify.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../testers/loopOverAllTestSets.js');
5 | var testName = 'identify';
6 | var path = require('path');
7 | var testData = [
8 | { expected: { file: path.join(process.cwd(), 'sample', 'cat.flif'), dimensions: '80x64', color: '8-bit RGBA', interlace: 'non-interlaced', size: 103 }, arguments: ['"' + path.resolve('.', 'sample', 'cat.flif') + '"'] },
9 | { expected: { file: path.join(process.cwd(), 'sample', 'output.flif'), dimensions: '768x512', color: '8-bit RGB', interlace: 'interlaced', size: 475578 }, arguments: ['"' + path.resolve('.', 'sample', 'output.flif') + '"'] }
10 | ];
11 |
12 | runAllTests(testName, 'information', testData);
13 |
14 | var amountOfTests = testData.length * Object.keys(testData[0].expected).length;
15 | return [testName, amountOfTests];
16 | }
17 |
18 | module.exports = test;
19 |
--------------------------------------------------------------------------------
/src/information/version.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Returns the versions of node-flif and the flif executable.
3 | * @return {object} Contains keys for nodeFLIF and flif that contain a string of the versions.
4 | */
5 | function version () {
6 | var manifest = require('root-require')('package.json');
7 | var versionInfo = {
8 | 'nodeFLIF': manifest.version,
9 | 'flif': manifest.flifVersion
10 | };
11 |
12 | return versionInfo;
13 | }
14 |
15 | module.exports = version;
16 |
--------------------------------------------------------------------------------
/src/information/version.test.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-multi-spaces */
2 |
3 | function test () {
4 | var runAllTests = require('../testers/loopOverAllTestSets.js');
5 | var testName = 'version';
6 | var testData = [
7 | { expected: { nodeFLIF: '1.0.1', flif: '0.3.0' }, arguments: [''] }
8 | ];
9 |
10 | runAllTests(testName, 'information', testData);
11 |
12 | return [testName, testData.length];
13 | }
14 |
15 | module.exports = test;
16 |
--------------------------------------------------------------------------------
/src/testers/errorMessage.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-regex-spaces*/
2 |
3 | /**
4 | * Generate a detailed error message to display if a test fails.
5 | *
6 | * @param {object} details All details required to generate a helpful error message
7 | * @param {array} details.stack Stack trace
8 | * @param {string} details.testName Name of the failed test
9 | * @param {number} details.i Iteration of test loop
10 | * @param {array} details.arguments Array of what will be passed into the test subject
11 | * @param {unknown} details.expectation Expectated outcome
12 | * @param {unknown} details.actual Actual outcome
13 | *
14 | * @return {string} The error message for the failed test.
15 | */
16 | function errorMessage (details) {
17 | // Get the name of the project from package.json
18 | var manifest = require('root-require')('package.json');
19 | var project = manifest.name;
20 | var projectName = project + '/';
21 | // Escape any dashes that could be in the package name
22 | project = project.replace(/-/g, '\\-');
23 | if (process.platform === 'win32') {
24 | projectName = new RegExp('(?:\\()(?:.*)(?:' + project + ')(?:\\/)?(?:\\\\)?', 'gm');
25 | }
26 |
27 | var stackTrace = [];
28 | for (var i = 2; i < (details.stack.length - 1); i++) {
29 | var item = details.stack[i].trim().replace('at ', ' ').replace(projectName, '(.\\');
30 | stackTrace.push(item);
31 | }
32 | stackTrace = stackTrace.join('\n');
33 |
34 | var errMsg = '\n' +
35 | 'TEST: ' + details.testName + '\n' +
36 | 'ERROR:\n' +
37 | ' Iterator: ' + details.i + '\n' +
38 | ' Expected: ' + JSON.stringify(details.expectation, null, 2).replace(/\n /g, '\n ').replace('}', ' }') + '\n' +
39 | ' Actual: ' + JSON.stringify(details.actual, null, 2).replace(/\n /g, '\n ').replace('}', ' }') + '\n' +
40 | ' Arguments: ' + JSON.stringify(details.arguments, null, 2).replace(/\n /g, '\n ').replace(']', ' ]') + '\n' +
41 | ' Stack Trace:\n' +
42 | stackTrace.split('\n\n').join('\n');
43 |
44 | return errMsg;
45 | }
46 |
47 | module.exports = errorMessage;
48 |
--------------------------------------------------------------------------------
/src/testers/loopOverAllTestSets.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Loop ever a set of test data to check if expectations match actual results
3 | *
4 | * @param {string} testName Name of the logic file we are testing
5 | * @param {string} folder Relative path to the file
6 | * @param {array} testSet Array of objects, each object contains an expectation and an arr
7 | */
8 | function loopOverAllTestSets (testName, folder, testSet, async) {
9 | async = async || false;
10 | var path = require('path');
11 | var assert = require('assert');
12 |
13 | var testFile = path.join('..', folder, testName + '.js');
14 | var subject = require(testFile);
15 |
16 | for (var i = 0; i < testSet.length; i++) {
17 | var args = testSet[i].arguments;
18 | var skipWarnings = true;
19 | if (!Array.isArray(args)) {
20 | throw 'Argument is not an array.';
21 | }
22 | var expected = testSet[i].expected;
23 |
24 | if (async) {
25 | // eslint-disable-next-line
26 | function cb (actual) {
27 | actual = actual.toString().trim();
28 |
29 | var isEqual = true;
30 | try {
31 | assert.deepStrictEqual(expected, actual);
32 | } catch (err) {
33 | isEqual = false;
34 | }
35 |
36 | if (!isEqual) {
37 | var stack = (new Error()).stack.trim().split('\n');
38 | var errorMessageGenerator = require('./errorMessage.js');
39 | var errorDetails = {
40 | stack: stack,
41 | testName: testName,
42 | i: i,
43 | arguments: args,
44 | expectation: expected,
45 | actual: actual
46 | };
47 | var errorMessage = errorMessageGenerator(errorDetails);
48 |
49 | throw errorMessage;
50 | }
51 | }
52 | args.push(cb);
53 | args.push(skipWarnings);
54 | subject.apply(null, args);
55 | } else {
56 | args.push(skipWarnings);
57 | var actual = subject.apply(null, args);
58 |
59 | var isEqual = true;
60 | try {
61 | assert.deepStrictEqual(expected, actual);
62 | } catch (err) {
63 | isEqual = false;
64 | }
65 |
66 | if (!isEqual) {
67 | var stack = (new Error()).stack.trim().split('\n');
68 | var errorMessageGenerator = require('./errorMessage.js');
69 | var errorDetails = {
70 | stack: stack,
71 | testName: testName,
72 | i: i,
73 | arguments: args,
74 | expectation: expected,
75 | actual: actual
76 | };
77 | var errorMessage = errorMessageGenerator(errorDetails);
78 |
79 | throw errorMessage;
80 | }
81 | }
82 | }
83 | }
84 |
85 | module.exports = loopOverAllTestSets;
86 |
--------------------------------------------------------------------------------
/try.js:
--------------------------------------------------------------------------------
1 | // This file exists to test if flif-wasm works in Windows
2 |
3 | var fs = require('fs');
4 |
5 | // Delete old files from previous attempts
6 | try { fs.unlinkSync('./sample/try-a.png'); } catch (err) {}
7 | try { fs.unlinkSync('./sample/try-b.flif'); } catch (err) {}
8 | try { fs.unlinkSync('./sample/try-c.png'); } catch (err) {}
9 |
10 | function runCommandSync (args) {
11 | var exec = require('child_process').execSync;
12 | var wasmPath = require.resolve('flif-wasm');
13 | var executable = 'node "' + wasmPath + '"';
14 |
15 | var executableAndArgs = executable + ' ' + args;
16 | var child = exec(executableAndArgs);
17 |
18 | return child.toString().trim();
19 | }
20 |
21 |
22 |
23 | // Should return flif.exe version
24 | var version = runCommandSync('-v');
25 | console.log(version);
26 |
27 |
28 |
29 | // Should convert cat.flif to try-a.png
30 | var decode = runCommandSync('-d ./sample/cat.flif ./sample/try-a.png');
31 | console.log(decode);
32 |
33 | // Log out true/false if file exists
34 | console.log(fs.existsSync('./sample/try-a.png'));
35 |
36 |
37 |
38 | // Should convert cat.png to try-b.flif
39 | var encode = runCommandSync('-e ./sample/cat.png ./sample/try-b.flif');
40 | console.log(encode);
41 |
42 | // Log out true/false if file exists
43 | console.log(fs.existsSync('./sample/try-b.flif'));
44 |
45 |
46 |
47 | // Should convert try-b.flif to try-c.png
48 | var decodeEncodedTry = runCommandSync('-d ./sample/try-b.flif ./sample/try-c.png');
49 | console.log(decodeEncodedTry);
50 |
51 | // Log out true/false if file exists
52 | console.log(fs.existsSync('./sample/try-c.png'));
53 |
--------------------------------------------------------------------------------