Skip to content

Commit

Permalink
Merge pull request #460 from ericblade/dev
Browse files Browse the repository at this point in the history
switch from using rarely maintained gl-* packages to full gl-matrix package
  • Loading branch information
ericblade authored Oct 19, 2022
2 parents 95c523b + 1cdabea commit ef7511f
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 66 deletions.
40 changes: 9 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@
"dependencies": {
"@babel/polyfill": "^7.12.1",
"get-pixels": "^3.3.3",
"gl-mat2": "^1.0.1",
"gl-vec2": "^1.3.0",
"gl-vec3": "^1.1.3",
"gl-matrix": "^3.4.3",
"lodash": "^4.17.21",
"ndarray": "^1.0.19",
"ndarray-linear-interpolate": "^1.0.0"
Expand Down
5 changes: 2 additions & 3 deletions src/common/cluster.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// TODO: cluster.js and cv_utils.js are pretty tightly intertwined, making for a complex conversion
// into typescript. be warned. :-)

import { clone, dot } from 'gl-vec2';

const vec2 = { clone, dot };
import { glMatrix, vec2 } from 'gl-matrix';

glMatrix.setMatrixArrayType(Array);
/**
* Creates a cluster for grouping similar orientations of datapoints
*/
Expand Down
8 changes: 3 additions & 5 deletions src/common/cv_utils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/* eslint-disable no-mixed-operators */
/* eslint-disable no-bitwise */
import { clone as v2clone } from 'gl-vec2';
import { clone as v3clone } from 'gl-vec3';
import Cluster2 from './cluster';
import { glMatrix, vec2, vec3 } from 'gl-matrix';
import ArrayHelper from './array_helper';
import Cluster2 from './cluster';

const vec2 = { clone: v2clone };
const vec3 = { clone: v3clone };
glMatrix.setMatrixArrayType(Array);

/**
* @param x x-coordinate
Expand Down
4 changes: 2 additions & 2 deletions src/common/image_wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clone } from 'gl-vec2';
import { glMatrix, vec2 } from 'gl-matrix';
import {
XYSize,
TypedArrayConstructor,
Expand All @@ -10,7 +10,7 @@ import {
import ArrayHelper from './array_helper';
import { hsv2rgb } from './cv_utils';

const vec2 = { clone };
glMatrix.setMatrixArrayType(Array);

type PositiveNumber = number;
function assertNumberPositive(val: number): asserts val is PositiveNumber {
Expand Down
4 changes: 2 additions & 2 deletions src/locator/barcode_locator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as vec2 from 'gl-vec2';
import * as mat2 from 'gl-mat2';
import { glMatrix, vec2, mat2 } from 'gl-matrix';
import ImageWrapper from '../common/image_wrapper';
import {
calculatePatchSize,
Expand All @@ -17,6 +16,7 @@ import Rasterizer from './rasterizer';
import Tracer from './tracer';
import skeletonizer from './skeletonizer';

glMatrix.setMatrixArrayType(Array);

let _config;
let _currentImageWrapper;
Expand Down
18 changes: 7 additions & 11 deletions src/quagga/initBuffers.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { clone } from 'gl-vec2';
import { glMatrix, vec2 } from 'gl-matrix';
import ImageWrapper from '../common/image_wrapper';
import type { InputStream } from '../input/input_stream/input_stream.d';
import BarcodeLocator from '../locator/barcode_locator';

type BufferReturn = {
// boxSize should be like [[ number, number], ...] but clone's signature doesn't seem to allow that
boxSize: Array<Array<number>>;
inputImageWrapper: ImageWrapper;
};
glMatrix.setMatrixArrayType(Array);

// TODO: need typescript def for BarcodeLocator
export default function initBuffers(
inputStream: InputStream,
imageWrapper: ImageWrapper | undefined,
locator: any,
): BufferReturn {
) {
const inputImageWrapper = imageWrapper || new ImageWrapper({
x: inputStream.getWidth(),
y: inputStream.getHeight(),
Expand All @@ -25,10 +21,10 @@ export default function initBuffers(
console.log(`image wrapper size ${inputImageWrapper.size}`);
}
const boxSize = [
clone([0, 0]),
clone([0, inputImageWrapper.size.y]),
clone([inputImageWrapper.size.x, inputImageWrapper.size.y]),
clone([inputImageWrapper.size.x, 0]),
vec2.clone([0, 0]),
vec2.clone([0, inputImageWrapper.size.y]),
vec2.clone([inputImageWrapper.size.x, inputImageWrapper.size.y]),
vec2.clone([inputImageWrapper.size.x, 0]),
];
BarcodeLocator.init(inputImageWrapper, locator);
return { inputImageWrapper, boxSize };
Expand Down
12 changes: 7 additions & 5 deletions src/quagga/quagga.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clone } from 'gl-vec2';
import { glMatrix, vec2 } from 'gl-matrix';
import { QuaggaJSResultObject, QuaggaJSReaderConfig } from '../../type-definitions/quagga.d';
import Events from '../common/events';
import ImageWrapper from '../common/image_wrapper';
Expand All @@ -16,6 +16,8 @@ import * as QWorkers from './qworker';
import setupInputStream from './setupInputStream';
import { moveLine, moveBox } from './transform';

glMatrix.setMatrixArrayType(Array);

export default class Quagga {
context: QuaggaContext = new QuaggaContext();

Expand Down Expand Up @@ -118,10 +120,10 @@ export default class Quagga {
getBoundingBoxes(): Array<Array<number>> | null {
return this.context.config?.locate ? BarcodeLocator.locate()
: [[
clone(this.context.boxSize[0]),
clone(this.context.boxSize[1]),
clone(this.context.boxSize[2]),
clone(this.context.boxSize[3]),
vec2.clone(this.context.boxSize[0]),
vec2.clone(this.context.boxSize[1]),
vec2.clone(this.context.boxSize[2]),
vec2.clone(this.context.boxSize[3]),
]];
}

Expand Down
10 changes: 6 additions & 4 deletions type-definitions/quagga.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Project: http://serratus.github.io/quaggaJS/
// Definitions by: Cam Birch, Peter Horwood aka Madman Pierre, Dan Manastireanu <https://github.com/danmana>

import { vec2 } from 'gl-matrix';

// import SubImage from '../src/common/subImage';
// import ImageWrapper from '../src/common/image_wrapper';
// export { SubImage, ImageWrapper };
Expand All @@ -14,9 +16,9 @@ export default Quagga;
// contextual meaning. This allows us to create a type that is branded by name, and therefore these variables cannot be directly
// mixed up with each other, without explicitly forcing it to happen. Good.
export interface XYObject<T extends string> {
type: T;
x: number;
y: number;
type: T;
}

// TODO: fill this in from cv_utils#imageRef
Expand All @@ -40,13 +42,13 @@ export type WrapperIndexMapping = {
export type Moment = {
m00: number;
m01: number;
m02: number;
m10: number;
m11: number;
m02: number;
m20: number;
theta: number;
rad: number;
vec?: Array<number>;
theta: number;
vec?: vec2;
};

export class ImageWrapper {
Expand Down

0 comments on commit ef7511f

Please sign in to comment.