chore: Follow up fix image resizer
This commit is contained in:
parent
da2c53edfc
commit
62b8f16128
4 changed files with 15 additions and 69 deletions
|
|
@ -7,7 +7,6 @@ import 'package:matrix/encryption/utils/key_verification.dart';
|
|||
import 'package:matrix/matrix.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'package:fluffychat/utils/custom_image_resizer.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'famedlysdk_store.dart';
|
||||
import 'matrix_sdk_extensions.dart/fluffybox_database.dart';
|
||||
|
|
@ -100,6 +99,5 @@ abstract class ClientManager {
|
|||
AuthenticationTypes.sso
|
||||
},
|
||||
compute: compute,
|
||||
customImageResizer: PlatformInfos.isMobile ? customImageResizer : null,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,55 +0,0 @@
|
|||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
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);
|
||||
|
||||
try {
|
||||
nativeImg = await native.Image.loadEncoded(arguments.bytes); // load on web
|
||||
} on UnsupportedError {
|
||||
// for the other platforms
|
||||
final dartCodec = await instantiateImageCodec(arguments.bytes);
|
||||
final dartFrame = await dartCodec.getNextFrame();
|
||||
final rgbaData = await dartFrame.image.toByteData();
|
||||
if (rgbaData == null) {
|
||||
return null;
|
||||
}
|
||||
final rgba = Uint8List.view(
|
||||
rgbaData.buffer, rgbaData.offsetInBytes, rgbaData.lengthInBytes);
|
||||
dartFrame.image.dispose();
|
||||
dartCodec.dispose();
|
||||
|
||||
nativeImg = native.Image.fromRGBA(
|
||||
dartFrame.image.width, dartFrame.image.height, rgba);
|
||||
}
|
||||
|
||||
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,
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue