nc-photos/lib/entity/exif.dart
Ming Ming bb71dcc22b Remove MakerNote from Exif
It's too large for nothing
2021-04-24 00:46:32 +08:00

108 lines
3 KiB
Dart

import 'package:equatable/equatable.dart';
import 'package:exifdart/exifdart.dart';
import 'package:intl/intl.dart';
class Exif with EquatableMixin {
Exif(this.data);
dynamic operator [](String key) => data[key];
bool containsKey(String key) => data.containsKey(key);
Map<String, dynamic> toJson() {
return Map.fromIterable(
data.entries.where((e) => e.key != "MakerNote").map((e) {
var jsonValue;
if (e.value is Rational) {
jsonValue = e.value.toJson();
} else if (e.value is List) {
jsonValue = e.value.map((e) {
if (e is Rational) {
return e.toJson();
} else {
return e;
}
}).toList();
} else {
jsonValue = e.value;
}
return MapEntry(e.key, jsonValue);
}),
key: (e) => e.key,
value: (e) => e.value,
);
}
factory Exif.fromJson(Map<String, dynamic> json) {
return Exif(Map.fromIterable(
// we are filtering out MakerNote here because it's generally very large
// and could exceed the 1MB cursor size limit on Android. Second, the
// content is proprietary and thus useless to us anyway
json.entries.where((e) => e.key != "MakerNote").map((e) {
var exifValue;
if (e.value is Map) {
exifValue = Rational.fromJson(e.value.cast<String, dynamic>());
} else if (e.value is List) {
exifValue = e.value.map((e) {
if (e is Map) {
return Rational.fromJson(e.cast<String, dynamic>());
} else {
return e;
}
}).toList();
} else {
exifValue = e.value;
}
return MapEntry(e.key, exifValue);
}),
key: (e) => e.key,
value: (e) => e.value,
));
}
@override
toString() {
final dataStr = data.entries.map((e) {
return "${e.key}: '${e.value}'";
}).join(", ");
return "$runtimeType {$dataStr}";
}
/// 0x010f Make
String get make => data["Make"];
/// 0x0110 Model
String get model => data["Model"];
/// 0x9003 DateTimeOriginal
DateTime get dateTimeOriginal => data.containsKey("DateTimeOriginal")
? dateTimeFormat.parse(data["DateTimeOriginal"])
: null;
/// 0x829a ExposureTime
Rational get exposureTime => data["ExposureTime"];
/// 0x829d FNumber
Rational get fNumber => data["FNumber"];
/// 0x8827 ISO/ISOSpeedRatings/PhotographicSensitivity
int get isoSpeedRatings => data["ISOSpeedRatings"];
/// 0x920a FocalLength
Rational get focalLength => data["FocalLength"];
/// 0x8825 GPS tags
String get gpsLatitudeRef => data["GPSLatitudeRef"];
List<Rational> get gpsLatitude => data["GPSLatitude"].cast<Rational>();
String get gpsLongitudeRef => data["GPSLongitudeRef"];
List<Rational> get gpsLongitude => data["GPSLongitude"].cast<Rational>();
@override
get props => [
data,
];
final Map<String, dynamic> data;
static final dateTimeFormat = DateFormat("yyyy:MM:dd HH:mm:ss");
}