Merge pull request #11 from koji-1009/fix/bugs

fix: fix bug
This commit is contained in:
Koji Wakamiya 2025-12-12 11:37:08 +09:00 committed by GitHub
commit 43d2003e6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 7 deletions

View File

@ -69,6 +69,10 @@ class ImageConverter {
ResizeMode resizeMode = const OriginalResizeMode(),
bool runInIsolate = true,
}) async {
assert(
quality >= 1 && quality <= 100,
'Quality must be between 1 and 100.',
);
if (runInIsolate) {
return await compute(_convertInIsolate, (
inputData: inputData,

View File

@ -228,10 +228,9 @@ final class ImageConverterDarwin implements ImageConverterPlatform {
}
CGImageRef _resizeImage(CGImageRef originalImage, int width, int height) {
CGColorSpaceRef? colorSpace;
CGContextRef? context;
try {
colorSpace = CGImageGetColorSpace(originalImage);
final colorSpace = CGImageGetColorSpace(originalImage);
if (colorSpace == nullptr) {
throw Exception('Failed to get color space from image.');
}
@ -271,7 +270,6 @@ final class ImageConverterDarwin implements ImageConverterPlatform {
}
return resizedImage;
} finally {
if (colorSpace != null) CFRelease(colorSpace.cast());
if (context != null) CFRelease(context.cast());
}
}

View File

@ -44,17 +44,17 @@ final class ImageConverterWeb implements ImageConverterPlatform {
ResizeMode resizeMode = const OriginalResizeMode(),
}) async {
final img = HTMLImageElement();
final decodeCompeleter = Completer<void>();
final decodeCompleter = Completer<void>();
final blob = Blob([inputData.toJS].toJS);
final url = URL.createObjectURL(blob);
img.onLoad.listen((_) => decodeCompeleter.complete());
img.onLoad.listen((_) => decodeCompleter.complete());
img.onError.listen((e) {
URL.revokeObjectURL(url);
decodeCompeleter.completeError('Failed to load image: $e');
decodeCompleter.completeError('Failed to load image: $e');
});
img.src = url;
await decodeCompeleter.future;
await decodeCompleter.future;
URL.revokeObjectURL(url);
final canvas = HTMLCanvasElement();