mirror of
https://github.com/immich-app/immich.git
synced 2026-03-05 16:33:46 -05:00
* feat(mobile): add support for encoded image requests in local and remote image APIs * fix(mobile): handle memory cleanup for cancelled image requests * refactor(mobile): simplify memory management and response handling for encoded image requests * fix(mobile): correct formatting in cancellation check for image requests * Apply suggestion from @mertalev Co-authored-by: Mert <101130780+mertalev@users.noreply.github.com> * refactor(mobile): rename 'encoded' parameter to 'preferEncoded' for clarity in image request APIs * fix(mobile): ensure proper resource cleanup for cancelled image requests * refactor(mobile): streamline codec handling by removing unnecessary descriptor disposal in loadCodec request --------- Co-authored-by: Mert <101130780+mertalev@users.noreply.github.com>
60 lines
1.5 KiB
Dart
60 lines
1.5 KiB
Dart
part of 'image_request.dart';
|
|
|
|
class LocalImageRequest extends ImageRequest {
|
|
final String localId;
|
|
final int width;
|
|
final int height;
|
|
final AssetType assetType;
|
|
|
|
LocalImageRequest({required this.localId, required ui.Size size, required this.assetType})
|
|
: width = size.width.toInt(),
|
|
height = size.height.toInt();
|
|
|
|
@override
|
|
Future<ImageInfo?> load(ImageDecoderCallback decode, {double scale = 1.0}) async {
|
|
if (_isCancelled) {
|
|
return null;
|
|
}
|
|
|
|
final info = await localImageApi.requestImage(
|
|
localId,
|
|
requestId: requestId,
|
|
width: width,
|
|
height: height,
|
|
isVideo: assetType == AssetType.video,
|
|
preferEncoded: false,
|
|
);
|
|
if (info == null) {
|
|
return null;
|
|
}
|
|
|
|
final frame = await _fromDecodedPlatformImage(info["pointer"]!, info["width"]!, info["height"]!, info["rowBytes"]!);
|
|
return frame == null ? null : ImageInfo(image: frame.image, scale: scale);
|
|
}
|
|
|
|
@override
|
|
Future<ui.Codec?> loadCodec() async {
|
|
if (_isCancelled) {
|
|
return null;
|
|
}
|
|
|
|
final info = await localImageApi.requestImage(
|
|
localId,
|
|
requestId: requestId,
|
|
width: width,
|
|
height: height,
|
|
isVideo: assetType == AssetType.video,
|
|
preferEncoded: true,
|
|
);
|
|
if (info == null) return null;
|
|
|
|
final (codec, _) = await _codecFromEncodedPlatformImage(info['pointer']!, info['length']!) ?? (null, null);
|
|
return codec;
|
|
}
|
|
|
|
@override
|
|
Future<void> _onCancelled() {
|
|
return localImageApi.cancelRequest(requestId);
|
|
}
|
|
}
|