Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
fix: LEAP-439: Add maskData exporting into new MIG serialization appr…
Browse files Browse the repository at this point in the history
…oach (#1659)

* fix: LEAP-439: Add maskData exporting into new MIG serialization approach

* Update version of @heartexlabs/ls-test dependency

* Add serialization/deserialization test for Magic Wand tool

* fix import path

* Configure timeouts

* Update @heartexlabs/ls-test dependency version

* Update @heartexlabs/ls-test dependency

* Update "@heartexlabs/ls-test" dependency
  • Loading branch information
Gondragos authored Jan 9, 2024
1 parent d4182be commit a3e4f43
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 16 deletions.
26 changes: 16 additions & 10 deletions src/regions/BrushRegion.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,24 @@ const Model = types
let pathPoints,
cachedPoints,
lastPointX = -1,
lastPointY = -1;
lastPointY = -1,
maskImage;

return {
afterCreate() {
// if ()
// const newdata = ctx.createImageData(750, 937);
// newdata.data.set(decode(item._rle));
// const dec = decode(self._rle);
// self._rle_image =
// item._cached_mask = decode(item._rle);
// const newdata = ctx.createImageData(750, 937);
// newdata.data.set(item._cached_mask);
// var img = imagedata_to_image(newdata);
self.updateMaskImage();
},

updateMaskImage() {
if (self.maskDataURL) {
if (!maskImage) maskImage = new window.Image();

maskImage.src = self.maskDataURL;
}
},

getMaskImage() {
return maskImage;
},

setLayerRef(ref) {
Expand Down Expand Up @@ -349,6 +354,7 @@ const Model = types
annotation.startAutosave();

self.maskDataURL = maskDataURL;
self.updateMaskImage();

self.notifyDrawingFinished();

Expand Down
7 changes: 7 additions & 0 deletions src/utils/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ function exportRLE(region) {
ctx.putImageData(imageData, 0, 0);
}

const maskImage = region.getMaskImage?.();

if (maskImage) {
// Apply maskDataURL to existing image data
ctx.drawImage(maskImage, 0, 0);
}

// If the region was changed manually, we'll have access to user tuoches
// Render those on the canvas after RLE
if (region.touches.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"cvg:summary": "nyc report --temp-dir=.nyc_output --reporter=text-summary --cwd=. --exclude-after-remap false"
},
"dependencies": {
"@heartexlabs/ls-test": "heartexlabs/ls-frontend-test#fa441d3d82b9aa238bf68a9bdcc33f7d8f6ec361"
"@heartexlabs/ls-test": "heartexlabs/ls-frontend-test#9ff949fc19abaf124477dfd41c6f230b00665ab3"
},
"devDependencies": {
"ts-loader": "^9.4.2",
Expand Down
40 changes: 39 additions & 1 deletion tests/functional/specs/image_segmentation/tools/magic-wand.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ImageView, LabelStudio, Sidebar } from '@heartexlabs/ls-test/helpers/LSF';
import { magicWandConfig, magicWandImageData } from '../../../data/image_segmentation/tools/magic-wand';
import { FF_DEV_4081 } from '../../../../../src/utils/feature-flags';
import { FF_DEV_4081, FF_LSDV_4583 } from '../../../../../src/utils/feature-flags';
import { Generator } from '@heartexlabs/ls-test/helpers/common/Generator';

describe('Magic Wand tool', () => {
beforeEach(() => {
Expand Down Expand Up @@ -40,4 +41,41 @@ describe('Magic Wand tool', () => {

Sidebar.hasRegions(1);
});

it.only('Should be able to serialize and deserialize the same region', () => {
LabelStudio.addFeatureFlagsOnPageLoad({
[FF_LSDV_4583]: true,
});
Generator.generateImageUrl({ width: 10, height: 10 })
.then((imageUrl) => {
LabelStudio.params()
.config(magicWandConfig)
.data({ image: imageUrl })
.withResult([])
.init();

ImageView.waitForImage();

ImageView.clickAtRelative(.15, .15);
ImageView.waitForPixelRelative(.15, .15, '#a1a1a1', { timeout: 10000 });

Sidebar.hasRegions(1);
ImageView.capture('RegionOnCanvas');

LabelStudio.serialize().then((data) => {
LabelStudio.params()
.config(magicWandConfig)
.data({ image: imageUrl })
.withResult(data)
.init();

ImageView.waitForImage();

Sidebar.hasRegions(1);
ImageView.waitForPixelRelative(.15, .15, '#a1a1a1', { timeout: 10000 });
ImageView.canvasShouldNotChange('RegionOnCanvas');
});
});

});
});
8 changes: 4 additions & 4 deletions tests/functional/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==

"@heartexlabs/ls-test@heartexlabs/ls-frontend-test#e760e117af39c187065ec8c704ce174e5d001eff":
"@heartexlabs/ls-test@heartexlabs/ls-frontend-test#9ff949fc19abaf124477dfd41c6f230b00665ab3":
version "1.0.8"
resolved "https://codeload.github.com/heartexlabs/ls-frontend-test/tar.gz/e760e117af39c187065ec8c704ce174e5d001eff"
resolved "https://codeload.github.com/heartexlabs/ls-frontend-test/tar.gz/9ff949fc19abaf124477dfd41c6f230b00665ab3"
dependencies:
"@cypress/code-coverage" "^3.10.0"
"@cypress/webpack-preprocessor" "^5.17.0"
Expand All @@ -288,9 +288,9 @@
webpack-cli "^5.0.1"
yargs "^17.7.1"

"@heartexlabs/ls-test@heartexlabs/ls-frontend-test#fa441d3d82b9aa238bf68a9bdcc33f7d8f6ec361":
"@heartexlabs/ls-test@heartexlabs/ls-frontend-test#df8e7ea65179f5d143a4a299428116646f2236c4":
version "1.0.8"
resolved "https://codeload.github.com/heartexlabs/ls-frontend-test/tar.gz/fa441d3d82b9aa238bf68a9bdcc33f7d8f6ec361"
resolved "https://codeload.github.com/heartexlabs/ls-frontend-test/tar.gz/df8e7ea65179f5d143a4a299428116646f2236c4"
dependencies:
"@cypress/code-coverage" "^3.10.0"
"@cypress/webpack-preprocessor" "^5.17.0"
Expand Down

0 comments on commit a3e4f43

Please sign in to comment.