Skip to content

Commit

Permalink
fix(core): handle custom resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
marcincichocki authored Aug 26, 2021
1 parent cce0da1 commit d437366
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Binary file added src/core/bp-registry/custom/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/core/bp-registry/registry.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"custom": [
{
"fileName": "1.png",
"daemons": [
["55", "1C", "1C"],
["1C", "1C"],
["1C", "E9", "1C", "E9"]
],
"grid": [
"E9", "1C", "55", "1C", "55",
"1C", "1C", "55", "E9", "55",
"1C", "1C", "55", "E9", "1C",
"BD", "1C", "1C", "1C", "55",
"1C", "55", "1C", "55", "BD"
],
"bufferSize": 7
}
],
"1024x768": [
{
"fileName": "1.png",
Expand Down
8 changes: 4 additions & 4 deletions src/core/ocr/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ export abstract class BreachProtocolFragment<
const { width, height, left, top } = this.container.getCroppedBoundingBox();

return {
left: left + Math.round(p1.x * width),
top: top + Math.round(p1.y * height),
left: Math.round(p1.x * width + left),
top: Math.round(p1.y * height + top),
width: Math.round((p2.x - p1.x) * width),
height: Math.round((p2.y - p1.y) * height),
outerWidth: width + 2 * left,
outerHeight: height + 2 * top,
outerWidth: Math.round(2 * left + width),
outerHeight: Math.round(2 * top + height),
innerWidth: width,
innerHeight: height,
} as BreachProtocolFragmentBoundingBox;
Expand Down
8 changes: 8 additions & 0 deletions src/core/ocr/ocr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface RegistryEntry {
}

type Resolution =
| 'custom'
| '1024x768'
| '1920x1080'
| '2560x1440'
Expand Down Expand Up @@ -184,6 +185,13 @@ describe('ocr', () => {
await BreachProtocolOCRFragment.terminateScheduler();
});

it.each(getRegistryFor('custom'))(
'should correctly ocr custom resolution/%s',
async (f: string, entry: RegistryEntry) => {
await compareOcrToJson(entry, 'custom');
}
);

it.each(getRegistryFor('1024x768'))(
'should correctly ocr 1024x768/%s',
async (f: string, entry: RegistryEntry) => {
Expand Down

0 comments on commit d437366

Please sign in to comment.