Merge pull request #24 from koji-1009/refactor/futureor
feat: Update convert method to return FutureOr
This commit is contained in:
commit
b63e14b46d
|
|
@ -85,7 +85,7 @@ class ImageConverter {
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
// The original implementation for those who opt-out.
|
// The original implementation for those who opt-out.
|
||||||
return _platform.convert(
|
return await _platform.convert(
|
||||||
inputData: inputData,
|
inputData: inputData,
|
||||||
format: format,
|
format: format,
|
||||||
quality: quality,
|
quality: quality,
|
||||||
|
|
@ -110,7 +110,7 @@ ImageConverterPlatform _getPlatformForTarget(TargetPlatform platform) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Top-level function for `compute`.
|
/// Top-level function for `compute`.
|
||||||
Future<Uint8List> _convertInIsolate(
|
FutureOr<Uint8List> _convertInIsolate(
|
||||||
({
|
({
|
||||||
Uint8List inputData,
|
Uint8List inputData,
|
||||||
OutputFormat format,
|
OutputFormat format,
|
||||||
|
|
@ -119,12 +119,9 @@ Future<Uint8List> _convertInIsolate(
|
||||||
TargetPlatform platform,
|
TargetPlatform platform,
|
||||||
})
|
})
|
||||||
request,
|
request,
|
||||||
) {
|
) => _getPlatformForTarget(request.platform).convert(
|
||||||
final platform = _getPlatformForTarget(request.platform);
|
inputData: request.inputData,
|
||||||
return platform.convert(
|
format: request.format,
|
||||||
inputData: request.inputData,
|
quality: request.quality,
|
||||||
format: request.format,
|
resizeMode: request.resizeMode,
|
||||||
quality: request.quality,
|
);
|
||||||
resizeMode: request.resizeMode,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,12 @@ final class ImageConverterAndroid implements ImageConverterPlatform {
|
||||||
const ImageConverterAndroid();
|
const ImageConverterAndroid();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Uint8List> convert({
|
Uint8List convert({
|
||||||
required Uint8List inputData,
|
required Uint8List inputData,
|
||||||
OutputFormat format = OutputFormat.jpeg,
|
OutputFormat format = OutputFormat.jpeg,
|
||||||
int quality = 100,
|
int quality = 100,
|
||||||
ResizeMode resizeMode = const OriginalResizeMode(),
|
ResizeMode resizeMode = const OriginalResizeMode(),
|
||||||
}) async {
|
}) {
|
||||||
return using((arena) {
|
return using((arena) {
|
||||||
final inputJBytes = JByteArray.from(inputData)..releasedBy(arena);
|
final inputJBytes = JByteArray.from(inputData)..releasedBy(arena);
|
||||||
final originalBitmap = BitmapFactory.decodeByteArray(
|
final originalBitmap = BitmapFactory.decodeByteArray(
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@ final class ImageConverterAndroid implements ImageConverterPlatform {
|
||||||
const ImageConverterAndroid();
|
const ImageConverterAndroid();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Uint8List> convert({
|
Uint8List convert({
|
||||||
required Uint8List inputData,
|
required Uint8List inputData,
|
||||||
OutputFormat format = OutputFormat.jpeg,
|
OutputFormat format = OutputFormat.jpeg,
|
||||||
int quality = 100,
|
int quality = 100,
|
||||||
ResizeMode resizeMode = const OriginalResizeMode(),
|
ResizeMode resizeMode = const OriginalResizeMode(),
|
||||||
}) async => throw UnimplementedError();
|
}) => throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,12 @@ final class ImageConverterDarwin implements ImageConverterPlatform {
|
||||||
const ImageConverterDarwin();
|
const ImageConverterDarwin();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Uint8List> convert({
|
Uint8List convert({
|
||||||
required Uint8List inputData,
|
required Uint8List inputData,
|
||||||
OutputFormat format = OutputFormat.jpeg,
|
OutputFormat format = OutputFormat.jpeg,
|
||||||
int quality = 100,
|
int quality = 100,
|
||||||
ResizeMode resizeMode = const OriginalResizeMode(),
|
ResizeMode resizeMode = const OriginalResizeMode(),
|
||||||
}) async {
|
}) {
|
||||||
Pointer<Uint8>? inputPtr;
|
Pointer<Uint8>? inputPtr;
|
||||||
CFDataRef? cfData;
|
CFDataRef? cfData;
|
||||||
CGImageSourceRef? imageSource;
|
CGImageSourceRef? imageSource;
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ final class ImageConverterDarwin implements ImageConverterPlatform {
|
||||||
const ImageConverterDarwin();
|
const ImageConverterDarwin();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Uint8List> convert({
|
Uint8List convert({
|
||||||
required Uint8List inputData,
|
required Uint8List inputData,
|
||||||
OutputFormat format = OutputFormat.jpeg,
|
OutputFormat format = OutputFormat.jpeg,
|
||||||
int quality = 100,
|
int quality = 100,
|
||||||
ResizeMode resizeMode = const OriginalResizeMode(),
|
ResizeMode resizeMode = const OriginalResizeMode(),
|
||||||
}) async => throw UnimplementedError();
|
}) => throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'dart:async';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:platform_image_converter/src/output_format.dart';
|
import 'package:platform_image_converter/src/output_format.dart';
|
||||||
|
|
@ -31,7 +32,7 @@ abstract interface class ImageConverterPlatform {
|
||||||
/// - [ImageDecodingException]: If the input image data cannot be decoded.
|
/// - [ImageDecodingException]: If the input image data cannot be decoded.
|
||||||
/// - [ImageEncodingException]: If the image cannot be encoded to the target format.
|
/// - [ImageEncodingException]: If the image cannot be encoded to the target format.
|
||||||
/// - [ImageConversionException]: For other general errors during the conversion process.
|
/// - [ImageConversionException]: For other general errors during the conversion process.
|
||||||
Future<Uint8List> convert({
|
FutureOr<Uint8List> convert({
|
||||||
required Uint8List inputData,
|
required Uint8List inputData,
|
||||||
OutputFormat format = OutputFormat.jpeg,
|
OutputFormat format = OutputFormat.jpeg,
|
||||||
int quality = 100,
|
int quality = 100,
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ final class ImageConverterWeb implements ImageConverterPlatform {
|
||||||
const ImageConverterWeb();
|
const ImageConverterWeb();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Uint8List> convert({
|
Uint8List convert({
|
||||||
required Uint8List inputData,
|
required Uint8List inputData,
|
||||||
OutputFormat format = OutputFormat.jpeg,
|
OutputFormat format = OutputFormat.jpeg,
|
||||||
int quality = 100,
|
int quality = 100,
|
||||||
ResizeMode resizeMode = const OriginalResizeMode(),
|
ResizeMode resizeMode = const OriginalResizeMode(),
|
||||||
}) async => throw UnimplementedError();
|
}) => throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue