-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from grandchef/refactor/decoupling-image-and-q…
…rcode-libs refactor: decoupling image and qrcode libs
- Loading branch information
Showing
23 changed files
with
467 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,6 @@ node_modules/ | |
# Coverage | ||
coverage | ||
|
||
# VS Code | ||
.vscode | ||
!.vscode/tasks.js | ||
|
||
# JetBrains IDEs | ||
.idea/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Test and Watch", | ||
"type": "node", | ||
"request": "launch", | ||
"cwd": "${workspaceFolder}", | ||
"runtimeExecutable": "yarn", | ||
"runtimeArgs": [ | ||
"test:debug" | ||
], | ||
"port": 9229 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,29 @@ | ||
import { load } from '../helper'; | ||
import * as path from 'path'; | ||
import { ImageManager } from 'escpos-buffer-image'; | ||
|
||
import { Image } from '../../src'; | ||
import { PNG } from '../../src'; | ||
|
||
describe('proccess images to printing format', () => { | ||
it('load image from buffer', () => { | ||
const image = new Image(load('sample.png')); | ||
it('load image from buffer', async () => { | ||
const imageManager = new ImageManager(); | ||
const imageData = await imageManager.loadImage( | ||
path.join(__dirname, '../resources/sample.png'), | ||
); | ||
const image = new Image(imageData); | ||
expect(image.width).toBe(180); | ||
}); | ||
|
||
it('allow image cache', () => { | ||
const cache = new Image(load('sample.png')); | ||
const image = new Image(); | ||
it('allow image cache', async () => { | ||
const imageManager = new ImageManager(); | ||
const imageDataCache = await imageManager.loadImage( | ||
path.join(__dirname, '../resources/sample.png'), | ||
); | ||
const imageData = await imageManager.loadImage( | ||
path.join(__dirname, '../resources/transparent_sample.png'), | ||
); | ||
const cache = new Image(imageDataCache); | ||
const image = new Image(imageData); | ||
Object.assign(image, cache); | ||
expect(image.width).toBe(180); | ||
}); | ||
|
||
it('accepts a pre-loaded PNG instance', async () => { | ||
const imageBuffer = load('sample.png'); | ||
|
||
const png = await new Promise((resolve: Function, reject: Function) => { | ||
new PNG({ filterType: 4 }).parse( | ||
imageBuffer, | ||
(error: Error, data: PNG) => { | ||
if (error) { | ||
reject(error); | ||
return; | ||
} | ||
resolve(data); | ||
}, | ||
); | ||
}); | ||
|
||
const image = new Image(png as PNG); | ||
expect(image.width).toBe(180); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import * as path from 'path'; | ||
import { ImageManager } from 'escpos-buffer-image'; | ||
import { load } from '../../helper'; | ||
import { BayerOrdered, Image } from '../../../src'; | ||
|
||
describe('proccess images using Bayer ordered algorithm', () => { | ||
it('apply filter on image from buffer', () => { | ||
const image = new Image(load('sample.png'), new BayerOrdered()); | ||
it('apply filter on image from buffer', async () => { | ||
const imageManager = new ImageManager(); | ||
const imageData = await imageManager.loadImage( | ||
path.join(__dirname, '../../resources/sample.png'), | ||
); | ||
const image = new Image(imageData, new BayerOrdered()); | ||
expect(image.data).toStrictEqual(load('bayer_filter', image.data)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import * as path from 'path'; | ||
import { ImageManager } from 'escpos-buffer-image'; | ||
import { load } from '../../helper'; | ||
import { Threshold, Image } from '../../../src'; | ||
|
||
describe('proccess images using threshold algorithm', () => { | ||
it('apply filter on image from buffer', () => { | ||
const image = new Image(load('sample.png'), new Threshold()); | ||
it('apply filter on image from buffer', async () => { | ||
const imageManager = new ImageManager(); | ||
const imageData = await imageManager.loadImage( | ||
path.join(__dirname, '../../resources/sample.png'), | ||
); | ||
const image = new Image(imageData, new Threshold()); | ||
expect(image.data).toStrictEqual(load('threshold_filter', image.data)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.