-
Notifications
You must be signed in to change notification settings - Fork 605
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 #5265 from voxel51/merge/release/v1.2.0
Merge `release/v1.2.0` to `develop`
- Loading branch information
Showing
13 changed files
with
450 additions
and
128 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import type { Buffers } from "../state"; | ||
import { hasFrame } from "./utils"; | ||
|
||
describe("looker utilities", () => { | ||
it("determines frame availability given a buffer list", () => { | ||
const BUFFERS: Buffers = [ | ||
[1, 3], | ||
[5, 25], | ||
]; | ||
for (const frameNumber of [1, 10, 25]) { | ||
expect(hasFrame(BUFFERS, frameNumber)).toBe(true); | ||
} | ||
|
||
for (const frameNumber of [0, 4, 26]) { | ||
expect(hasFrame(BUFFERS, frameNumber)).toBe(false); | ||
} | ||
}); | ||
}); |
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,7 @@ | ||
import type { Buffers } from "../state"; | ||
|
||
export const hasFrame = (buffers: Buffers, frameNumber: number) => { | ||
return buffers.some( | ||
([start, end]) => start <= frameNumber && frameNumber <= end | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { isGrayscale } from "./canvas-decoder"; | ||
|
||
const createData = ( | ||
pixels: Array<[number, number, number, number]> | ||
): Uint8ClampedArray => { | ||
return new Uint8ClampedArray(pixels.flat()); | ||
}; | ||
|
||
describe("isGrayscale", () => { | ||
it("should return true for a perfectly grayscale image", () => { | ||
const data = createData(Array(100).fill([100, 100, 100, 255])); | ||
expect(isGrayscale(data)).toBe(true); | ||
}); | ||
|
||
it("should return false if alpha is not 255", () => { | ||
const data = createData([ | ||
[100, 100, 100, 255], | ||
[100, 100, 100, 254], | ||
...Array(98).fill([100, 100, 100, 255]), | ||
]); | ||
expect(isGrayscale(data)).toBe(false); | ||
}); | ||
|
||
it("should return false if any pixel is not grayscale", () => { | ||
const data = createData([ | ||
[100, 100, 100, 255], | ||
[100, 101, 100, 255], | ||
...Array(98).fill([100, 100, 100, 255]), | ||
]); | ||
expect(isGrayscale(data)).toBe(false); | ||
}); | ||
|
||
it("should detect a non-grayscale pixel placed deep enough to ensure at least 1% of pixels are checked", () => { | ||
// large image: 100,000 pixels. 1% of 100,000 is 1,000. | ||
// the function will check at least 1,000 pixels. | ||
// place a non-grayscale pixel after 800 pixels. | ||
const pixels = Array(100000).fill([50, 50, 50, 255]); | ||
pixels[800] = [50, 51, 50, 255]; // this is within the first 1% of pixels | ||
const data = createData(pixels); | ||
expect(isGrayscale(data)).toBe(false); | ||
}); | ||
}); |
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
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.