This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Image.toByteData and Picture.toImage implementations (#3) #20750
Merged
Merged
Changes from all commits
Commits
Show all changes
87 commits
Select commit
Hold shift + click to select a range
93e3f0b
Update image.dart
deakjahn cc827d6
Update html_image_codec.dart
deakjahn 6b9fd73
rebase
deakjahn 352b31a
Update image.dart
deakjahn 4ea7ef2
Update picture.dart
deakjahn f99c8b2
Update picture.dart
deakjahn 1e7188f
Update picture.dart
deakjahn 4017e40
Update html_image_codec.dart
deakjahn ed811cf
Update image.dart
deakjahn d6dc410
Update image.dart
deakjahn c2c70e4
Revert
deakjahn 8b1ed1a
Tested by local engine
deakjahn bad4d45
Add files via upload
deakjahn 22dbcf7
Delete picture_to_image_test.dart
deakjahn 5eb7b8a
Test #1
deakjahn 1feae02
Test to read only
deakjahn 4c9001b
Finally
deakjahn a2ff894
Sorry, spaces
deakjahn 0c72496
Test, finally
deakjahn 91b12ca
@JS refactoring
deakjahn 9eeb7e0
@JS refactoring
deakjahn 6efd763
SkData and SkImageInfo
deakjahn 22d2f96
Unused items
deakjahn f1d49be
Test to write PNG
deakjahn 6675e13
Remove comments
deakjahn ced934c
Add comments
deakjahn 7b78b27
CK test
deakjahn 11c4073
Comment about copying
deakjahn 72ef505
Update image.dart
deakjahn 1afe140
Update html_image_codec.dart
deakjahn 18642e4
rebase
deakjahn a20d80d
Update image.dart
deakjahn e3147c5
Update picture.dart
deakjahn ae8ba90
Update picture.dart
deakjahn abf4f78
Update picture.dart
deakjahn 2abe68f
Update html_image_codec.dart
deakjahn 0b765d8
Update image.dart
deakjahn 1109004
Update image.dart
deakjahn 17a2ef5
Revert
deakjahn 0c2aac9
Tested by local engine
deakjahn 301ae90
Add files via upload
deakjahn fbfd675
Delete picture_to_image_test.dart
deakjahn b49583b
Test #1
deakjahn 26a49fb
Test to read only
deakjahn b23ca62
Test, finally
deakjahn 41d664a
@JS refactoring
deakjahn fcd1d2f
@JS refactoring
deakjahn a29069f
SkData and SkImageInfo
deakjahn 83a7399
Unused items
deakjahn 99eb64c
Test to write PNG
deakjahn 4b28ee1
Remove comments
deakjahn 10f4d4c
CK test
deakjahn 70d9884
Merge branch 'master' of https://github.com/deakjahn/engine
deakjahn a1346ea
Rebase manually
deakjahn 4e41dfc
Rebase manually
deakjahn fb02673
New test
deakjahn 8c2790c
Newline
deakjahn 6a31d41
Rebase dirt
deakjahn dc77edc
SkImageInfo
deakjahn 54e706c
New test
deakjahn d4a07a1
New test
deakjahn 6db0a3a
New test
deakjahn 6daead7
Missing annotation
deakjahn 75770e7
Rebase
deakjahn ad715e1
ColorSpace
deakjahn 69dd265
SkImageInfo correct names
deakjahn 078d6bc
SkImageInfo correct names
deakjahn 5dd02dd
SkImageInfo correct names
deakjahn 5f4d5e7
SkImageInfo properties
deakjahn 107ba3d
Inactive test
deakjahn 93cd91d
Merge remote-tracking branch 'upstream/master'
deakjahn 69ec1cc
Unused import
deakjahn 9d5a611
Merge remote-tracking branch 'upstream/master'
deakjahn 6e1d95d
Squash 2
deakjahn 7da3c86
Merge branch 'master' of https://github.com/deakjahn/engine
deakjahn 90d0b69
Squash 2.
deakjahn 4c39264
Merge branch 'master' of https://github.com/deakjahn/engine
deakjahn 9cf68f8
Merge remote-tracking branch 'upstream/master'
deakjahn 91ed8f4
Add files via upload
deakjahn 38cf1e1
Add files via upload
deakjahn faf4ba9
Add files via upload
deakjahn b895e66
Add files via upload
deakjahn a57c674
Update canvas_to_picture_test.dart
deakjahn ba82ef9
Merge remote-tracking branch 'upstream/master'
deakjahn a36894b
Merge branch 'deakjahn-patch-1' of https://github.com/deakjahn/engine…
deakjahn ae9605a
Update canvas_to_picture_test.dart
deakjahn 21feeae
Update canvas_to_picture_test.dart
deakjahn 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 |
---|---|---|
|
@@ -129,13 +129,13 @@ class HtmlImage implements ui.Image { | |
final int height; | ||
|
||
@override | ||
Future<ByteData?> toByteData( | ||
{ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba}) { | ||
return futurize((Callback<ByteData?> callback) { | ||
return _toByteData(format.index, (Uint8List? encoded) { | ||
callback(encoded?.buffer.asByteData()); | ||
}); | ||
}); | ||
Future<ByteData?> toByteData({ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba}) { | ||
if (imgElement.src?.startsWith('data:') == true) { | ||
final data = UriData.fromUri(Uri.parse(imgElement.src!)); | ||
return Future.value(data.contentAsBytes().buffer.asByteData()); | ||
} else { | ||
return Future.value(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should probably throw instead of returning null. This indicates we don't support the format. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't know what you normally do in a situation like that. If throw, than throw it is. |
||
} | ||
} | ||
|
||
// Returns absolutely positioned actual image element on first call and | ||
|
@@ -149,12 +149,4 @@ class HtmlImage implements ui.Image { | |
return imgElement; | ||
} | ||
} | ||
|
||
// TODO(het): Support this for asset images and images generated from | ||
// `Picture`s. | ||
/// Returns an error message on failure, null on success. | ||
String _toByteData(int format, Callback<Uint8List?> callback) { | ||
callback(null); | ||
return 'Image.toByteData is not supported in Flutter for Web'; | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
lib/web_ui/test/golden_tests/engine/canvas_to_picture_test.dart
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,55 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// @dart = 2.6 | ||
import 'dart:html' as html; | ||
|
||
import 'package:ui/ui.dart'; | ||
import 'package:ui/src/engine.dart'; | ||
|
||
import 'package:test/bootstrap/browser.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
internalBootstrapBrowserTest(() => testMain); | ||
} | ||
|
||
void testMain() async { | ||
final Rect region = Rect.fromLTWH(0, 0, 500, 500); | ||
|
||
setUp(() async { | ||
debugShowClipLayers = true; | ||
SurfaceSceneBuilder.debugForgetFrameScene(); | ||
for (html.Node scene in html.document.querySelectorAll('flt-scene')) { | ||
scene.remove(); | ||
} | ||
|
||
await webOnlyInitializePlatform(); | ||
webOnlyFontCollection.debugRegisterTestFonts(); | ||
await webOnlyFontCollection.ensureFontsLoaded(); | ||
}); | ||
|
||
test('Convert Canvas to Picture', () async { | ||
final SurfaceSceneBuilder builder = SurfaceSceneBuilder(); | ||
final Picture testPicture = await _drawTestPictureWithCircle(region); | ||
builder.addPicture(Offset.zero, testPicture); | ||
|
||
html.document.body.append(builder | ||
.build() | ||
.webOnlyRootElement); | ||
|
||
//await matchGoldenFile('canvas_to_picture.png', region: region, write: true); | ||
}); | ||
} | ||
|
||
Picture _drawTestPictureWithCircle(Rect region) { | ||
final EnginePictureRecorder recorder = PictureRecorder(); | ||
final RecordingCanvas canvas = recorder.beginRecording(region); | ||
canvas.drawOval( | ||
region, | ||
Paint() | ||
..style = PaintingStyle.fill | ||
..color = Color(0xFF00FF00)); | ||
return recorder.endRecording(); | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ignores the
format
parameter. It's not entirely clear to me what format thedata:
URI is in, I'm trying to test this and I'm only seeing regular URIs or blob URIs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, this was some time ago already, we spent some with finalizing the PR, so the code itself is even older. Let me think. I seem to remember PNG was the only format available in the data URL, so it simply couldn't support anything else. The possibilities are: