Merge branch 'krille/fix-resize-with-compute' into 'main'
fix: Resize image with compute by using const class arguments See merge request famedly/company/frontend/famedlysdk!951
This commit is contained in:
		
						commit
						7d3d838d51
					
				|  | @ -86,9 +86,14 @@ class MatrixImageFile extends MatrixFile { | ||||||
|       Future<T> Function<T, U>(FutureOr<T> Function(U arg) function, U arg)? |       Future<T> Function<T, U>(FutureOr<T> Function(U arg) function, U arg)? | ||||||
|           compute}) async { |           compute}) async { | ||||||
|     Image? image; |     Image? image; | ||||||
|  |     final arguments = _ResizeArguments( | ||||||
|  |       bytes: bytes, | ||||||
|  |       maxDimension: maxDimension, | ||||||
|  |       fileName: name, | ||||||
|  |     ); | ||||||
|     final resizedData = compute != null |     final resizedData = compute != null | ||||||
|         ? await compute(_resize, [bytes, maxDimension]) |         ? await compute(_resize, arguments) | ||||||
|         : _resize([bytes, maxDimension, name]); |         : _resize(arguments); | ||||||
| 
 | 
 | ||||||
|     if (resizedData == null) { |     if (resizedData == null) { | ||||||
|       return MatrixImageFile(bytes: bytes, name: name, mimeType: mimeType); |       return MatrixImageFile(bytes: bytes, name: name, mimeType: mimeType); | ||||||
|  | @ -166,22 +171,31 @@ class MatrixImageFile extends MatrixFile { | ||||||
|     return thumbnailFile; |     return thumbnailFile; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   static Uint8List? _resize(List<dynamic> arguments) { |   static Uint8List? _resize(_ResizeArguments arguments) { | ||||||
|     final bytes = arguments[0] as Uint8List; |     final image = decodeImage(arguments.bytes); | ||||||
|     final maxDimension = arguments[1] as int; |  | ||||||
|     final fileName = arguments[2] as String; |  | ||||||
|     final image = decodeImage(bytes); |  | ||||||
| 
 | 
 | ||||||
|     final resized = copyResize(image!, |     final resized = copyResize(image!, | ||||||
|         height: image.height > image.width ? maxDimension : null, |         height: image.height > image.width ? arguments.maxDimension : null, | ||||||
|         width: image.width >= image.height ? maxDimension : null); |         width: image.width >= image.height ? arguments.maxDimension : null); | ||||||
| 
 | 
 | ||||||
|     final encoded = encodeNamedImage(resized, fileName); |     final encoded = encodeNamedImage(resized, arguments.fileName); | ||||||
|     if (encoded == null) return null; |     if (encoded == null) return null; | ||||||
|     return Uint8List.fromList(encoded); |     return Uint8List.fromList(encoded); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | class _ResizeArguments { | ||||||
|  |   final Uint8List bytes; | ||||||
|  |   final int maxDimension; | ||||||
|  |   final String fileName; | ||||||
|  | 
 | ||||||
|  |   const _ResizeArguments({ | ||||||
|  |     required this.bytes, | ||||||
|  |     required this.maxDimension, | ||||||
|  |     required this.fileName, | ||||||
|  |   }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| class MatrixVideoFile extends MatrixFile { | class MatrixVideoFile extends MatrixFile { | ||||||
|   int? width; |   int? width; | ||||||
|   int? height; |   int? height; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue