Skip to content

Commit

Permalink
Migrate image package
Browse files Browse the repository at this point in the history
  • Loading branch information
Roaa94 committed Mar 24, 2024
1 parent 22ee0dd commit 9ccf596
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 33 deletions.
8 changes: 4 additions & 4 deletions example/lib/_processing_demo_sketch_display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -364,26 +364,26 @@ class ProcessingDemoState extends State<ProcessingDemo> with SingleTickerProvide

// Retrieve the pixel data for the current sketch painting.
final frameBytes = await image.toByteData();
final rawImageData = frameBytes!.buffer.asUint8List();
final rawImageBuffer = frameBytes!.buffer;

// Convert the pixel data to the desired format.
late List<int> formattedImageData;
switch (imageFormat) {
case ImageFileFormat.png:
formattedImageData = imageFormats.encodePng(
imageFormats.Image.fromBytes(image.width, image.height, rawImageData),
imageFormats.Image.fromBytes(width: image.width, height: image.height, bytes: rawImageBuffer),
);
break;
case ImageFileFormat.jpeg:
formattedImageData = imageFormats.encodeJpg(
imageFormats.Image.fromBytes(image.width, image.height, rawImageData),
imageFormats.Image.fromBytes(width: image.width, height: image.height, bytes: rawImageBuffer),
);
break;
case ImageFileFormat.tiff:
throw UnimplementedError('Tiff images are not supported in save()');
case ImageFileFormat.targa:
formattedImageData = imageFormats.encodeTga(
imageFormats.Image.fromBytes(image.width, image.height, rawImageData),
imageFormats.Image.fromBytes(width: image.width, height: image.height, bytes: rawImageBuffer),
);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions example/lib/io/gif.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class GifGenerator {

await sketch.loadPixels();

final gifFrame = gif.Image.fromBytes(sketch.width, sketch.height, sketch.pixels!.buffer.asUint8List());
final gifFrame = gif.Image.fromBytes(width: sketch.width, height: sketch.height, bytes: sketch.pixels!.buffer);
final timeInHundredths = (_gifFrameRateFps.inMilliseconds / 10).round();
_gifEncoder.addFrame(gifFrame, duration: timeInHundredths);
_addedFrameCount += 1;
Expand Down Expand Up @@ -68,7 +68,7 @@ class GifGenerator {
}

final frameBytes = await frame.toByteData();
final gifFrame = gif.Image.fromBytes(frame.width, frame.height, frameBytes!.buffer.asUint8List());
final gifFrame = gif.Image.fromBytes(width: frame.width, height: frame.height, bytes: frameBytes!.buffer);
_frames.add(gifFrame);
// final timeInHundredths = (_gifFrameRateFps.inMilliseconds / 10).round();
// _gifEncoder.addFrame(gifFrame, duration: timeInHundredths);
Expand Down
46 changes: 35 additions & 11 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ packages:
dependency: transitive
description:
name: archive
sha256: ae3e2b5dcfd7262920f3a36df8f04a9f798bafe395d7dc6cf2a7178ae8aba792
sha256: "22600aa1e926be775fa5fe7e6894e7fb3df9efda8891c73f70fb3262399a432d"
url: "https://pub.dev"
source: hosted
version: "3.1.6"
version: "3.4.10"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -57,6 +57,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.18.0"
convert:
dependency: transitive
description:
name: convert
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
url: "https://pub.dev"
source: hosted
version: "3.1.1"
cross_file:
dependency: transitive
description:
Expand All @@ -69,10 +77,10 @@ packages:
dependency: transitive
description:
name: crypto
sha256: cf75650c66c0316274e21d7c43d3dea246273af5955bd94e8184837cd577575c
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "3.0.3"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -197,15 +205,23 @@ packages:
dependency: "direct main"
description:
name: image
sha256: "3e5c9ef82c0af7823be4cb5294a829a6e0548a6f6b4e261e6386509a9e03bcab"
sha256: "4c68bfd5ae83e700b5204c1e74451e7bf3cf750e6843c6e158289cf56bda018e"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
version: "4.1.7"
integration_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: js
sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
url: "https://pub.dev"
source: hosted
version: "0.7.1"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -266,10 +282,10 @@ packages:
dependency: transitive
description:
name: petitparser
sha256: "85e8f8b118afcccf948a9844d199e56260117400bd9b9982d87bf1d62ebc1690"
sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27
url: "https://pub.dev"
source: hosted
version: "4.1.0"
version: "6.0.2"
platform:
dependency: transitive
description:
Expand All @@ -286,6 +302,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
pointycastle:
dependency: transitive
description:
name: pointycastle
sha256: "43ac87de6e10afabc85c445745a7b799e04de84cebaa4fd7bf55a5e1e9604d29"
url: "https://pub.dev"
source: hosted
version: "3.7.4"
popover:
dependency: "direct main"
description:
Expand Down Expand Up @@ -407,10 +431,10 @@ packages:
dependency: transitive
description:
name: xml
sha256: "9d2cf96b38e3f523fb78f0102d1d4483f817f3c3a6d81f46bf1b7a430ae8d561"
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
url: "https://pub.dev"
source: hosted
version: "5.1.1"
version: "6.5.0"
sdks:
dart: ">=3.2.0-194.0.dev <4.0.0"
dart: ">=3.2.0 <4.0.0"
flutter: ">=2.0.0"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:

file_selector: ^0.8.2
file_selector_macos: ^0.0.4
image: ^3.0.2
image: ^4.1.7
path: ^1.8.0
patterns_canvas: ^0.3.5
popover: ^0.2.6+2
Expand Down
6 changes: 3 additions & 3 deletions lib/src/output/_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,19 @@ Future<void> saveBytesToFile({
switch (imageFormat) {
case ImageFileFormat.png:
formattedImageData = imageFormats.encodePng(
imageFormats.Image.fromBytes(width, height, imageData),
imageFormats.Image.fromBytes(width: width, height: height, bytes: imageData.buffer),
);
break;
case ImageFileFormat.jpeg:
formattedImageData = imageFormats.encodeJpg(
imageFormats.Image.fromBytes(width, height, imageData),
imageFormats.Image.fromBytes(width: width, height: height, bytes: imageData.buffer),
);
break;
case ImageFileFormat.tiff:
throw UnimplementedError('Tiff images are not supported in save()');
case ImageFileFormat.targa:
formattedImageData = imageFormats.encodeTga(
imageFormats.Image.fromBytes(width, height, imageData),
imageFormats.Image.fromBytes(width: width, height: height, bytes: imageData.buffer),
);
break;
}
Expand Down
46 changes: 35 additions & 11 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ packages:
dependency: transitive
description:
name: archive
sha256: a92e39b291073bb840a72cf43d96d2a63c74e9a485d227833e8ea0054d16ad16
sha256: "22600aa1e926be775fa5fe7e6894e7fb3df9efda8891c73f70fb3262399a432d"
url: "https://pub.dev"
source: hosted
version: "3.1.2"
version: "3.4.10"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -49,14 +49,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.18.0"
convert:
dependency: transitive
description:
name: convert
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
url: "https://pub.dev"
source: hosted
version: "3.1.1"
crypto:
dependency: transitive
description:
name: crypto
sha256: cf75650c66c0316274e21d7c43d3dea246273af5955bd94e8184837cd577575c
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "3.0.3"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -111,10 +119,18 @@ packages:
dependency: "direct main"
description:
name: image
sha256: "3e5c9ef82c0af7823be4cb5294a829a6e0548a6f6b4e261e6386509a9e03bcab"
sha256: "4c68bfd5ae83e700b5204c1e74451e7bf3cf750e6843c6e158289cf56bda018e"
url: "https://pub.dev"
source: hosted
version: "4.1.7"
js:
dependency: transitive
description:
name: js
sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
url: "https://pub.dev"
source: hosted
version: "3.0.2"
version: "0.7.1"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -159,10 +175,18 @@ packages:
dependency: transitive
description:
name: petitparser
sha256: "85e8f8b118afcccf948a9844d199e56260117400bd9b9982d87bf1d62ebc1690"
sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27
url: "https://pub.dev"
source: hosted
version: "6.0.2"
pointycastle:
dependency: transitive
description:
name: pointycastle
sha256: "43ac87de6e10afabc85c445745a7b799e04de84cebaa4fd7bf55a5e1e9604d29"
url: "https://pub.dev"
source: hosted
version: "4.1.0"
version: "3.7.4"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -244,10 +268,10 @@ packages:
dependency: transitive
description:
name: xml
sha256: "30498604ab00fc50286f8aaf7e077c496550b16ed2f325c14152244882314f03"
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
url: "https://pub.dev"
source: hosted
version: "5.1.2"
version: "6.5.0"
sdks:
dart: ">=3.2.0-194.0.dev <4.0.0"
dart: ">=3.2.0 <4.0.0"
flutter: ">=1.17.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
sdk: flutter

fast_noise: ^2.0.0
image: ^3.0.2
image: ^4.1.7
path: ^1.8.0

dev_dependencies:
Expand Down

0 comments on commit 9ccf596

Please sign in to comment.