mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-25 06:52:35 +01:00
Merge branch 'krille/readd-native-imgaging' into 'main'
feat: Use native imaging for much faster thumbnail calc on mobile See merge request famedly/fluffychat!806
This commit is contained in:
commit
d15259b8c1
@ -7,6 +7,7 @@ import 'package:matrix/encryption/utils/key_verification.dart';
|
|||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/utils/custom_image_resizer.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'famedlysdk_store.dart';
|
import 'famedlysdk_store.dart';
|
||||||
import 'matrix_sdk_extensions.dart/fluffybox_database.dart';
|
import 'matrix_sdk_extensions.dart/fluffybox_database.dart';
|
||||||
@ -99,5 +100,6 @@ abstract class ClientManager {
|
|||||||
AuthenticationTypes.sso
|
AuthenticationTypes.sso
|
||||||
},
|
},
|
||||||
compute: compute,
|
compute: compute,
|
||||||
|
customImageResizer: PlatformInfos.isMobile ? customImageResizer : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
32
lib/utils/custom_image_resizer.dart
Normal file
32
lib/utils/custom_image_resizer.dart
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
import 'package:native_imaging/native_imaging.dart' as native;
|
||||||
|
|
||||||
|
Future<MatrixImageFileResizedResponse?> customImageResizer(
|
||||||
|
MatrixImageFileResizeArguments arguments) async {
|
||||||
|
await native.init();
|
||||||
|
var nativeImg = await native.Image.loadEncoded(arguments.bytes);
|
||||||
|
|
||||||
|
final width = nativeImg.width;
|
||||||
|
final height = nativeImg.height;
|
||||||
|
final max = arguments.maxDimension;
|
||||||
|
if (width > max || height > max) {
|
||||||
|
var w = max, h = max;
|
||||||
|
if (width > height) {
|
||||||
|
h = max * height ~/ width;
|
||||||
|
} else {
|
||||||
|
w = max * width ~/ height;
|
||||||
|
}
|
||||||
|
|
||||||
|
final scaledImg = nativeImg.resample(w, h, native.Transform.lanczos);
|
||||||
|
nativeImg.free();
|
||||||
|
nativeImg = scaledImg;
|
||||||
|
}
|
||||||
|
final jpegBytes = await nativeImg.toJpeg(75);
|
||||||
|
|
||||||
|
return MatrixImageFileResizedResponse(
|
||||||
|
bytes: jpegBytes,
|
||||||
|
width: nativeImg.width,
|
||||||
|
height: nativeImg.height,
|
||||||
|
blurhash: arguments.calcBlurhash ? nativeImg.toBlurhash(3, 3) : null,
|
||||||
|
);
|
||||||
|
}
|
11
pubspec.lock
11
pubspec.lock
@ -983,7 +983,7 @@ packages:
|
|||||||
name: matrix
|
name: matrix
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.8.16"
|
version: "0.8.17"
|
||||||
matrix_api_lite:
|
matrix_api_lite:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1026,6 +1026,15 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.2"
|
version: "1.0.2"
|
||||||
|
native_imaging:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
path: "."
|
||||||
|
ref: HEAD
|
||||||
|
resolved-ref: "8c6a5afe2c965b79b5959bb4b49c4aad020cb980"
|
||||||
|
url: "https://gitlab.com/famedly/libraries/native_imaging.git"
|
||||||
|
source: git
|
||||||
|
version: "0.1.0"
|
||||||
nested:
|
nested:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -58,8 +58,10 @@ dependencies:
|
|||||||
keyboard_shortcuts: ^0.1.4
|
keyboard_shortcuts: ^0.1.4
|
||||||
localstorage: ^4.0.0+1
|
localstorage: ^4.0.0+1
|
||||||
lottie: ^1.2.2
|
lottie: ^1.2.2
|
||||||
matrix: ^0.8.16
|
matrix: ^0.8.17
|
||||||
matrix_link_text: ^1.0.2
|
matrix_link_text: ^1.0.2
|
||||||
|
native_imaging:
|
||||||
|
git: https://gitlab.com/famedly/libraries/native_imaging.git
|
||||||
open_noti_settings: ^0.4.0
|
open_noti_settings: ^0.4.0
|
||||||
package_info_plus: ^1.3.0
|
package_info_plus: ^1.3.0
|
||||||
path_provider: ^2.0.9
|
path_provider: ^2.0.9
|
||||||
|
Loading…
Reference in New Issue
Block a user