Skip to content

Commit df31604

Browse files
committed
fix #42
1 parent 9b7f29e commit df31604

File tree

4 files changed

+43
-24
lines changed

4 files changed

+43
-24
lines changed

0x1.png

807 Bytes
Loading

CHANGELOG

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [unreleased]
4+
- Change DPLC limit to 255
5+
- Fix issue where image data would be cached incorrectly
6+
37
## [1.2.2]
48
- Added sprite rotation algorithm: 3 shears
59
- Fix Sonic 3 Object null sprites
@@ -11,9 +15,6 @@
1115
- Sprite Rotation
1216
- Add zoom slider in sprites tab
1317

14-
## [1.1.3]
15-
- Upgrade to electron 12
16-
1718
## [1.1.2]
1819
- Assume undefined labels are at address 0 [#33](/../../issues/33)
1920
- Made generated mapping labels random

app/components/import/state.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { observable, computed, action, autorun, toJS, makeObservable } from 'mobx';
1+
import { observable, computed, action, makeObservable } from 'mobx';
22
const { dialog } = require('@electron/remote');
33
import { errorMsg } from '#util/dialog';
44
import { removeBackground } from './remove-background';
55
import { colorMatch } from './color-match';
66
import { getSpriteBBoxes } from './get-sprite';
77
import { getMappings } from './generate-mappings';
88
import { importSprite } from './import-sprite';
9+
import { readFile } from 'fs';
910

1011
class ImportState {
1112
config = {
@@ -65,21 +66,27 @@ class ImportState {
6566
this.ctx = node.getContext('2d');
6667

6768
if (this.path) {
68-
const img = new Image();
69-
70-
img.onload = () => {
71-
node.width = img.width;
72-
node.height = img.height;
73-
this.ctx.drawImage(img, 0, 0);
74-
requestAnimationFrame(this.loaded);
75-
};
76-
77-
img.onerror = (e) => {
78-
errorMsg('Import Error', `Error loading ${this.path}`);
79-
this.cancel();
80-
};
81-
82-
img.src = this.path;
69+
readFile(this.path, (_err, data) => {
70+
if (data) {
71+
const blob = new Blob([data]);
72+
const url = URL.createObjectURL(blob);
73+
const img = new Image();
74+
img.onload = () => {
75+
node.width = img.width;
76+
node.height = img.height;
77+
this.ctx.drawImage(img, 0, 0);
78+
requestAnimationFrame(this.loaded);
79+
URL.revokeObjectURL(url);
80+
};
81+
img.onerror = (e) => {
82+
errorMsg('Import Error', `Error loading ${this.path}`);
83+
this.cancel();
84+
};
85+
img.src = url;
86+
} else {
87+
errorMsg('Import Error', `Error loading ${this.path}`);
88+
}
89+
});
8390

8491
} else if (this.rotCanvas) {
8592
this.ctx.drawImage(this.rotCanvas, 0, 0);

app/formats/image.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { environment } from '#store/environment';
22
const { dialog } = require('@electron/remote');
3-
import { writeFile } from 'fs';
3+
import { readFile, writeFile } from 'fs';
44
import { errorMsg } from '#util/dialog';
55
import { colorMatch } from '#components/import/color-match';
66

@@ -172,10 +172,21 @@ export async function importImg() {
172172
// load image
173173

174174
const img = await (new Promise((resolve) => {
175-
const img = new Image();
176-
img.onload = () => { resolve(img); };
177-
img.onerror = (e) => { resolve(null); };
178-
img.src = path;
175+
readFile(path, (_err, data) => {
176+
if (data) {
177+
const blob = new Blob([data]);
178+
const url = URL.createObjectURL(blob);
179+
const img = new Image();
180+
img.onload = () => {
181+
resolve(img);
182+
URL.revokeObjectURL(url);
183+
};
184+
img.onerror = (e) => { resolve(null); };
185+
img.src = url;
186+
} else {
187+
resolve(null);
188+
}
189+
});
179190
}));
180191

181192
if (!img) return errorMsg('Import Error', `Error loading ${path}`);

0 commit comments

Comments
 (0)