mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-06 05:49:03 +08:00
feat: Add support for WebP image format in clipboard and thumbnail handling
This commit is contained in:
@@ -12,6 +12,7 @@ import '../api/file.dart';
|
||||
import '../api/gallery.dart';
|
||||
import '../globals.dart';
|
||||
import '../utils.dart';
|
||||
import '../utils/clipboard.dart';
|
||||
import '../viewer/single.dart';
|
||||
import 'image.dart';
|
||||
|
||||
@@ -84,6 +85,7 @@ class _Thumbnail extends State<Thumbnail> {
|
||||
double? _iconSize;
|
||||
bool _disposed = false;
|
||||
String? _originalUrl;
|
||||
ImageFmt _fmt = ImageFmt.jpg;
|
||||
void _onNsfwChanged(dynamic args) {
|
||||
final arguments = args as (String, bool)?;
|
||||
if (arguments == null) return;
|
||||
@@ -146,6 +148,9 @@ class _Thumbnail extends State<Thumbnail> {
|
||||
if (cache != null) {
|
||||
setState(() {
|
||||
_data = cache!.$1;
|
||||
var headers = Headers.fromMap(cache!.$2);
|
||||
_fmt = ImageFmt.fromMimeType(headers.value("content-type")) ??
|
||||
ImageFmt.jpg;
|
||||
_uri = cache!.$3 ?? _originalUrl;
|
||||
_isLoading = false;
|
||||
_cancel = null;
|
||||
@@ -168,6 +173,8 @@ class _Thumbnail extends State<Thumbnail> {
|
||||
'Failed to get thumbnail: ${re.response.statusCode} ${re.response.statusMessage}');
|
||||
}
|
||||
_uri = re.response.realUri.toString();
|
||||
_fmt = ImageFmt.fromMimeType(re.response.headers.value("content-type")) ??
|
||||
ImageFmt.jpg;
|
||||
final data = Uint8List.fromList(re.data);
|
||||
if (!_cancel!.isCancelled) {
|
||||
if (isImageCacheEnabled) {
|
||||
@@ -273,6 +280,7 @@ class _Thumbnail extends State<Thumbnail> {
|
||||
uri: _uri,
|
||||
originalUri: oUri,
|
||||
fileName: _fileName,
|
||||
fmt: _fmt,
|
||||
dir: _dir,
|
||||
isNsfw:
|
||||
auth.canEditGallery == true ? () => widget._pMeta.isNsfw : null,
|
||||
|
||||
@@ -5,3 +5,7 @@ import 'package:image/image.dart';
|
||||
Future<Uint8List> jpgToPng(Uint8List data) async {
|
||||
return encodePng(decodeJpg(data)!);
|
||||
}
|
||||
|
||||
Future<Uint8List> webpToPng(Uint8List data) async {
|
||||
return encodePng(decodeWebP(data)!);
|
||||
}
|
||||
|
||||
@@ -3,3 +3,7 @@ import 'dart:typed_data';
|
||||
Future<Uint8List> jpgToPng(Uint8List data) async {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
Future<Uint8List> webpToPng(Uint8List data) async {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ import '../utils.dart';
|
||||
enum ImageFmt {
|
||||
jpg,
|
||||
png,
|
||||
gif;
|
||||
gif,
|
||||
webp;
|
||||
|
||||
String toMimeType() {
|
||||
switch (this) {
|
||||
@@ -18,6 +19,8 @@ enum ImageFmt {
|
||||
return "image/png";
|
||||
case ImageFmt.gif:
|
||||
return "image/gif";
|
||||
case ImageFmt.webp:
|
||||
return "image/webp";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +29,8 @@ enum ImageFmt {
|
||||
switch (mime) {
|
||||
case "image/jpeg":
|
||||
return ImageFmt.jpg;
|
||||
case "image/webp":
|
||||
return ImageFmt.webp;
|
||||
case "image/png":
|
||||
return ImageFmt.png;
|
||||
case "image/gif":
|
||||
@@ -46,11 +51,17 @@ Future<void> copyImageToClipboard(Uint8List data, ImageFmt fmt) async {
|
||||
? Formats.jpeg(data)
|
||||
: fmt == ImageFmt.gif
|
||||
? Formats.gif(data)
|
||||
: Formats.png(data));
|
||||
: fmt == ImageFmt.png
|
||||
? Formats.png(data)
|
||||
: Formats.webp(data));
|
||||
} else {
|
||||
item.add(fmt == ImageFmt.gif
|
||||
? Formats.gif(data)
|
||||
: Formats.png(fmt == ImageFmt.jpg ? await jpgToPng(data) : data));
|
||||
: Formats.png(fmt == ImageFmt.jpg
|
||||
? await jpgToPng(data)
|
||||
: fmt == ImageFmt.webp
|
||||
? await webpToPng(data)
|
||||
: data));
|
||||
}
|
||||
await SystemClipboard.instance!.write([item]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user