63 lines
2.2 KiB
Dart
63 lines
2.2 KiB
Dart
import 'dart:convert';
|
|
import 'dart:typed_data';
|
|
|
|
class MosaicProjectData {
|
|
final bool useCapSize;
|
|
final String gridWidth;
|
|
final String gridHeight;
|
|
final String capSize;
|
|
final double fidelityStructure;
|
|
final double ditheringStrength;
|
|
final double edgeEmphasis;
|
|
final double colorVariation;
|
|
final String selectedPreset;
|
|
final Uint8List? sourceImageBytes;
|
|
final DateTime savedAt;
|
|
|
|
const MosaicProjectData({
|
|
required this.useCapSize,
|
|
required this.gridWidth,
|
|
required this.gridHeight,
|
|
required this.capSize,
|
|
required this.fidelityStructure,
|
|
required this.ditheringStrength,
|
|
required this.edgeEmphasis,
|
|
required this.colorVariation,
|
|
required this.selectedPreset,
|
|
required this.sourceImageBytes,
|
|
required this.savedAt,
|
|
});
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'useCapSize': useCapSize,
|
|
'gridWidth': gridWidth,
|
|
'gridHeight': gridHeight,
|
|
'capSize': capSize,
|
|
'fidelityStructure': fidelityStructure,
|
|
'ditheringStrength': ditheringStrength,
|
|
'edgeEmphasis': edgeEmphasis,
|
|
'colorVariation': colorVariation,
|
|
'selectedPreset': selectedPreset,
|
|
'sourceImageBase64':
|
|
sourceImageBytes == null ? null : base64Encode(sourceImageBytes!),
|
|
'savedAt': savedAt.toIso8601String(),
|
|
};
|
|
|
|
factory MosaicProjectData.fromJson(Map<String, dynamic> json) {
|
|
final sourceB64 = json['sourceImageBase64'] as String?;
|
|
return MosaicProjectData(
|
|
useCapSize: json['useCapSize'] as bool? ?? false,
|
|
gridWidth: json['gridWidth'] as String? ?? '40',
|
|
gridHeight: json['gridHeight'] as String? ?? '30',
|
|
capSize: json['capSize'] as String? ?? '12',
|
|
fidelityStructure: (json['fidelityStructure'] as num?)?.toDouble() ?? 0.5,
|
|
ditheringStrength: (json['ditheringStrength'] as num?)?.toDouble() ?? 0.35,
|
|
edgeEmphasis: (json['edgeEmphasis'] as num?)?.toDouble() ?? 0.4,
|
|
colorVariation: (json['colorVariation'] as num?)?.toDouble() ?? 0.3,
|
|
selectedPreset: json['selectedPreset'] as String? ?? 'ausgewogen',
|
|
sourceImageBytes: sourceB64 == null ? null : base64Decode(sourceB64),
|
|
savedAt: DateTime.tryParse(json['savedAt'] as String? ?? '') ?? DateTime.now(),
|
|
);
|
|
}
|
|
}
|