Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Show very high rest images in lower resolution on low ram devices

laurenspriem43a2dbc5b2d8
diff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
index 3c0c80d2d6..9ce0af642d 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
@@ -26,6 +26,7 @@ import 'package:photos/ui/common/loading_widget.dart';
import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
import 'package:photos/utils/file_util.dart';
import 'package:photos/utils/image_util.dart';
+import "package:photos/utils/ram_check_util.dart";
import 'package:photos/utils/thumbnail_util.dart';
class ZoomableImage extends StatefulWidget {
@@ -84,7 +85,13 @@ class _ZoomableImageState extends State<ZoomableImage> {
// This is to prevent the app from crashing when loading 200MP images
// https://github.com/flutter/flutter/issues/110331
- bool get isTooLargeImage => _photo.width * _photo.height > 100000000; //100MP
+ static const int _defaultMaxPixels = 100000000; // 100MP
+ static const int _lowRamMaxPixels = 24000000; // 24MP
+
+ int get _maxImagePixels =>
+ hasLessThan5GBRAM ? _lowRamMaxPixels : _defaultMaxPixels;
+
+ bool get isTooLargeImage => _photo.width * _photo.height > _maxImagePixels;
@override
void initState() {
@@ -466,11 +473,10 @@ class _ZoomableImageState extends State<ZoomableImage> {
ImageProvider imageProvider;
if (isTooLargeImage) {
_logger.info(
- "Handling very large image (${_photo.width}x${_photo.height}) by decreasing resolution to 50MP to prevent crash",
+ "Handling very large image (${_photo.width}x${_photo.height}) by decreasing resolution to ${_maxImagePixels ~/ 1000000}MP to prevent crash",
);
final aspectRatio = _photo.width / _photo.height;
- const maxPixels = 50000000;
- final targetHeight = sqrt(maxPixels / aspectRatio);
+ final targetHeight = sqrt(_maxImagePixels / aspectRatio);
final targetWidth = aspectRatio * targetHeight;
imageProvider = Image.file(
@@ -604,11 +610,10 @@ class _ZoomableImageState extends State<ZoomableImage> {
Uint8List? compressedFile;
if (isTooLargeImage) {
_logger.info(
- "Compressing very large image (${_photo.width}x${_photo.height}) more aggressively down to 50MP",
+ "Compressing very large image (${_photo.width}x${_photo.height}) more aggressively down to ${_maxImagePixels ~/ 1000000}MP",
);
final aspectRatio = _photo.width / _photo.height;
- const maxPixels = 50000000;
- final targetHeight = sqrt(maxPixels / aspectRatio);
+ final targetHeight = sqrt(_maxImagePixels / aspectRatio);
final targetWidth = aspectRatio * targetHeight;
compressedFile = await FlutterImageCompress.compressWithFile(
diff --git a/mobile/apps/photos/lib/utils/ram_check_util.dart b/mobile/apps/photos/lib/utils/ram_check_util.dart
index aff9caf12b..45bccc049e 100644
--- a/mobile/apps/photos/lib/utils/ram_check_util.dart
+++ b/mobile/apps/photos/lib/utils/ram_check_util.dart
@@ -6,6 +6,9 @@ int? deviceTotalRAM;
bool get enoughRamForLocalIndexing =>
deviceTotalRAM == null || deviceTotalRAM! >= 5 * 1024;
+bool get hasLessThan5GBRAM =>
+ deviceTotalRAM != null && deviceTotalRAM! < 5 * 1024;
+
bool get enoughRamForOfflineLocalIndexing =>
deviceTotalRAM == null || deviceTotalRAM! > 3 * 1024;