-
Notifications
You must be signed in to change notification settings - Fork 77
PAINTROID_457: Add .ora support for save/load #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Amit-Matth
wants to merge
2
commits into
Catrobat:develop
Choose a base branch
from
Amit-Matth:PAINTROID-457
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'dart:convert'; | ||
import 'dart:typed_data'; | ||
import 'package:image/image.dart' as img; | ||
import 'package:archive/archive.dart'; | ||
|
||
class OraImage { | ||
final int width; | ||
final int height; | ||
final List<img.Image> layers; | ||
final String xmlMetadata; | ||
|
||
OraImage({ | ||
required this.width, | ||
required this.height, | ||
required this.layers, | ||
required this.xmlMetadata, | ||
}); | ||
|
||
Uint8List toBytes() { | ||
final archive = Archive(); | ||
|
||
for (int i = 0; i < layers.length; i++) { | ||
final layer = layers[i]; | ||
final encoder = img.PngEncoder(); | ||
final layerData = encoder.encodeImage(layer); | ||
archive.addFile(ArchiveFile('layer_$i.png', layerData.length, layerData)); | ||
} | ||
|
||
final encodedXml = utf8.encode(xmlMetadata); | ||
archive.addFile(ArchiveFile('stack.xml', encodedXml.length, encodedXml)); | ||
|
||
final zipEncoder = ZipEncoder(); | ||
return Uint8List.fromList(zipEncoder.encode(archive)!); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'dart:typed_data'; | ||
import 'dart:ui' as ui; | ||
import 'package:archive/archive.dart'; | ||
import 'package:image/image.dart' as img; | ||
|
||
class ProcessOra { | ||
Future<List<ui.Image>> processOraFile(Archive archive) async { | ||
List<ui.Image> layers = []; | ||
|
||
for (var file in archive) { | ||
if (file.isFile && | ||
(file.name.endsWith('.png') || file.name.endsWith('.jpg')) || | ||
file.name.endsWith('.ora')) { | ||
Amit-Matth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
img.Image? decodedImage = img.decodeImage(file.content as List<int>); | ||
Amit-Matth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
if (decodedImage != null) { | ||
ui.Image layer = await convertImgImageToUiImage(decodedImage); | ||
layers.add(layer); | ||
} | ||
} | ||
} | ||
|
||
return layers; | ||
} | ||
|
||
Future<ui.Image> convertImgImageToUiImage(img.Image image) async { | ||
List<int> pngBytes = img.encodePng(image); | ||
|
||
final codec = await ui.instantiateImageCodec(Uint8List.fromList(pngBytes)); | ||
final frame = await codec.getNextFrame(); | ||
return frame.image; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'dart:io'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:oxidized/oxidized.dart'; | ||
import 'package:paintroid/core/models/ora_image.dart'; | ||
import 'package:paintroid/core/providers/object/file_service.dart'; | ||
import 'package:paintroid/core/providers/object/permission_service.dart'; | ||
import 'package:paintroid/core/utils/failure.dart'; | ||
import 'package:paintroid/core/utils/save_image_failure.dart'; | ||
|
||
class SaveAsOraImage { | ||
final IFileService _fileService; | ||
final IPermissionService _permissionService; | ||
|
||
SaveAsOraImage(this._fileService, this._permissionService); | ||
|
||
static final provider = Provider((ref) { | ||
final fileService = ref.watch(IFileService.provider); | ||
final permissionService = ref.watch(IPermissionService.provider); | ||
return SaveAsOraImage(fileService, permissionService); | ||
}); | ||
|
||
Future<Result<File, Failure>> call(OraImage image, String fileName) async { | ||
if (!(await _permissionService.requestAccessToSharedFileStorage())) { | ||
return const Result.err(SaveImageFailure.permissionDenied); | ||
} | ||
|
||
final bytes = image.toBytes(); | ||
return _fileService.save(fileName, bytes); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.