Repository navigation
refactor: use typeutils for nativeImage serialization - #23693
Conversation
9d44647 to
b53f7f0
Compare
| const { size, scaleFactor, dataURL } = rep; | ||
|
|
||
| // Use Buffer when there's only one representation for better perf. | ||
| // This avoids compressing to/from PNG where it's not necessary to |
There was a problem hiding this comment.
Interesting in knowing more about this, why can't multiple representations use the bitmap buffer?
There was a problem hiding this comment.
If one uses a buffer to construct an image with multiple representation from multiple dataURLs, the dataURLs themselves are not preserved. If you test:
const image = nativeImage.createEmpty();
const dataURL1 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYlWNgAAIAAAUAAdafFs0AAAAASUVORK5CYII=';
image.addRepresentation({ scaleFactor: 1.0, dataURL: dataURL1 });
const dataURL2 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVQYlWP8//8/AwMDEwMDAwMDAwAkBgMBBMzldwAAAABJRU5ErkJggg==';
image.addRepresentation({ scaleFactor: 2.0, dataURL: dataURL2 });
const serializedImage = serialize(image);
const nonEmpty = deserialize(serializedImage);
expect(nonEmpty.toDataURL({ scaleFactor: 1.0 })).to.equal(dataURL1);
expect(nonEmpty.toDataURL({ scaleFactor: 2.0 })).to.equal(dataURL2);
expect(nonEmpty.toDataURL({ scaleFactor: 2.0 })).to.equal(dataURL2); will fail, as the only dataURL associated with the image will be dataURL1. However, there's a perf boost with buffer serialization (see: #23549) so we want to allow it where possible.
45cb617 to
14121d1
Compare
14121d1 to
defa10d
Compare
|
No Release Notes |
|
@codebytere has manually backported this PR to "10-x-y", please check out #23794 |
|
@codebytere has manually backported this PR to "9-x-y", please check out #23796 |
|
@codebytere has manually backported this PR to "8-x-y", please check out #23797 |
* refactor: use typeutils for nativeImage serialization (#23693) * fix: ensure nativeImage serialization main->renderer
Description of Change
Follow-up to #23666, as stated in PR body. Uses existing
typeUtilsto serializenativeImagesand improves perf by using a buffer to construct thenativeImageif there is only one representation.cc @miniak @MarshallOfSound
Checklist
npm testpassesRelease Notes
Notes: none