Skip to content

Commit

Permalink
quality as optional parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
arrrrny committed May 9, 2022
1 parent 1fd29dd commit 7aa4332
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
22 changes: 21 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
TODO: Add your license here.
MIT License

Copyright (c) 2022 ZUZU YAZILIM A.S.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
int[] strides = call.argument("strides");
int width = call.argument("width");
int height = call.argument("height");
int quality = call.argument("quality");

try {
byte[] data = YuvConverter.NV21toJPEG(YuvConverter.YUVtoNV21(bytesList, strides, width, height), width, height, 100);
Expand All @@ -46,7 +47,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
matrix.postRotate(90);
Bitmap finalbitmap = Bitmap.createBitmap(bitmapRaw, 0, 0, bitmapRaw.getWidth(), bitmapRaw.getHeight(), matrix, true);
ByteArrayOutputStream outputStreamCompressed = new ByteArrayOutputStream();
finalbitmap.compress(Bitmap.CompressFormat.JPEG, 60, outputStreamCompressed);
finalbitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStreamCompressed);

result.success(outputStreamCompressed.toByteArray());
outputStreamCompressed.close();
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.1+1"
version: "0.0.2"
sdks:
dart: ">=2.16.1 <3.0.0"
flutter: ">=2.8.0"
6 changes: 4 additions & 2 deletions lib/yuvtransform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import 'package:flutter/services.dart';
class Yuvtransform {
static const MethodChannel _channel = MethodChannel('yuvtransform');

static Future<Uint8List> yuvTransform(CameraImage image) async {
static Future<Uint8List> yuvTransform(CameraImage image,
{int? quality = 60}) async {
List<int> strides = Int32List(image.planes.length * 2);
int index = 0;
// We need to transform the image to Uint8List so that the native code could
Expand All @@ -23,7 +24,8 @@ class Yuvtransform {
'platforms': data,
'height': image.height,
'width': image.width,
'strides': strides
'strides': strides,
'quality': quality
});

return imageJpeg;
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: yuvtransform
description: A new flutter plugin project.
version: 0.0.1
description: Transform Android CameraImage Stream YUV420 to RBG Format
version: 0.0.2
homepage: https://github.com/zuzu-dev/yuvtransform

environment:
Expand All @@ -10,7 +10,7 @@ environment:
dependencies:
flutter:
sdk: flutter
camera: ^0.8.1+4
camera: ^0.9.4

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 7aa4332

Please sign in to comment.