Skip to content

Commit

Permalink
Merge branch 'fix/heic_issue' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
4ster1sk committed Nov 8, 2024
2 parents b01d753 + f9fb2e1 commit 8869e13
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ android {
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand All @@ -71,4 +71,4 @@ flutter {
source '../..'
}

dependencies {}
dependencies {}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "dart:io";
import "dart:typed_data";

import "package:dio/dio.dart";
Expand All @@ -6,7 +7,9 @@ import "package:flutter/material.dart";
import "package:flutter_gen/gen_l10n/app_localizations.dart";
import "package:flutter_image_compress/flutter_image_compress.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:image/image.dart";
import "package:mfm_parser/mfm_parser.dart";
import "package:mime/mime.dart";
import "package:miria/extensions/note_visibility_extension.dart";
import "package:miria/log.dart";
import "package:miria/model/image_file.dart";
Expand Down Expand Up @@ -158,17 +161,16 @@ class NoteCreateNotifier extends _$NoteCreateNotifier {
files: await Future.wait(
initialMediaFiles.map((media) async {
final file = _fileSystem.file(media);
final contents = await file.readAsBytes();
final fileName = file.basename;
final extension = fileName.split(".").last.toLowerCase();
if (["jpg", "png", "gif", "webp"].contains(extension)) {
if (["jpg", "png", "gif", "webp", "heic"].contains(extension)) {
return ImageFile(
data: contents,
data: await loadImage(file),
fileName: fileName,
);
} else {
return UnknownFile(
data: contents,
data: await file.readAsBytes(),
fileName: fileName,
);
}
Expand Down Expand Up @@ -592,8 +594,8 @@ class NoteCreateNotifier extends _$NoteCreateNotifier {
final result = await FilePicker.platform.pickFiles(
type: FileType.image,
allowMultiple: true,
allowCompression: false,
compressionQuality: 0,
allowCompression: Platform.isIOS, // v8.1.3ではiOS以外でこの値を使用していない
compressionQuality: 0, // Androidでは0にすることで圧縮パススルー
);
if (result == null || result.files.isEmpty) return;

Expand All @@ -607,16 +609,45 @@ class NoteCreateNotifier extends _$NoteCreateNotifier {
final files = await Future.wait(
fsFiles.map(
(file) async => ImageFile(
data: await file.readAsBytes(),
data: await loadImage(file),
fileName: file.basename,
),
),
);

state = state.copyWith(files: [...state.files, ...files]);
state = state.copyWith(files: [
...state.files,
...files.where((file) => file.data.isNotEmpty)
]);
}
}

Future<Uint8List> loadImage(File file) async {
final imageBytes = await file.readAsBytes();
final mime = lookupMimeType(file.path, headerBytes: imageBytes);
if (mime == "image/jpeg") {
final origExif = decodeJpgExif(imageBytes);
final exif = ExifData();

if (origExif != null) {
final orientation = origExif.imageIfd["Orientation"];
if (orientation != null) {
exif.imageIfd["Orientation"] = orientation;
}
}

final img = injectJpgExif(imageBytes, exif);
if (img == null) {
return Uint8List(0);
}

return img;
} else if (mime == "image/heic") {
return Uint8List(0);
}
return imageBytes;
}

/// メディアの内容を変更する
void setFileContent(MisskeyPostFile file, Uint8List? content) {
if (content == null) return;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ packages:
source: hosted
version: "1.0.5"
mime:
dependency: transitive
dependency: "direct main"
description:
name: mime
sha256: "801fd0b26f14a4a58ccb09d5892c3fbdeff209594300a542492cf13fba9d247a"
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: miria
description: Miria is Misskey Client for Mobile App.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 2.0.0+112
version: 2.0.0+114

environment:
sdk: '>=3.0.0 <4.0.0'
Expand Down Expand Up @@ -77,6 +77,7 @@ dependencies:
flutter_hooks: ^0.20.5
punycode: ^1.0.0
image: ^4.3.0
mime: ^1.0.6

dependency_overrides:
image_editor:
Expand Down

0 comments on commit 8869e13

Please sign in to comment.