Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
processing_camera_image
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
thuanpm
2022-05-11 23:26:36 +0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
44ad88688be37a1bf1f1153ff1f06eab2ee5972f
44ad8868
1 parent
90ee79f8
fix channel 8bit
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
20 deletions
lib/processing_camera_image.dart
lib/processing_camera_image_i.dart
lib/processing_camera_image.dart
View file @
44ad886
...
...
@@ -60,7 +60,7 @@ abstract class ProcessingCameraImage {
});
/// [processCameraImageToGray8Bit]. for Android with YUV420.
Uint8Lis
t
?
processCameraImageToGray8Bit
({
Image8bi
t
?
processCameraImageToGray8Bit
({
int
?
width
,
int
?
height
,
Uint8List
?
plane0
,
...
...
@@ -70,3 +70,10 @@ abstract class ProcessingCameraImage {
bool
isFlipVectical
=
false
,
});
}
class
Image8bit
{
final
int
width
;
final
int
heigh
;
final
Uint8List
data
;
Image8bit
({
required
this
.
data
,
required
this
.
heigh
,
required
this
.
width
});
}
...
...
lib/processing_camera_image_i.dart
View file @
44ad886
...
...
@@ -83,12 +83,10 @@ class IProcessingCameraImage implements ProcessingCameraImage {
int
newImgWidth
=
(
sinVal
*
height
+
cosVal
*
bytesPerRowPlane0
).
toInt
();
int
newImgHeight
=
(
sinVal
*
bytesPerRowPlane0
+
cosVal
*
height
).
toInt
();
// Allocate memory for the 3 planes of the image
Pointer
<
Uint8
>
p
=
ffi
.
malloc
.
allocate
(
plane0
.
length
);
Pointer
<
Uint8
>
p1
=
ffi
.
malloc
.
allocate
(
plane1
.
length
);
Pointer
<
Uint8
>
p2
=
ffi
.
malloc
.
allocate
(
plane2
.
length
);
// Assign the planes data to the pointers of the image
Uint8List
pointerList
=
p
.
asTypedList
(
plane0
.
length
);
Uint8List
pointerList1
=
p1
.
asTypedList
(
plane1
.
length
);
Uint8List
pointerList2
=
p2
.
asTypedList
(
plane2
.
length
);
...
...
@@ -96,7 +94,6 @@ class IProcessingCameraImage implements ProcessingCameraImage {
pointerList1
.
setRange
(
0
,
plane1
.
length
,
plane1
);
pointerList2
.
setRange
(
0
,
plane2
.
length
,
plane2
);
// Call the convertImage function and convert the YUV to RGB
Pointer
<
Uint32
>
imgP
=
_convertImageYuv420pToRGB
(
p
,
p1
,
...
...
@@ -111,14 +108,10 @@ class IProcessingCameraImage implements ProcessingCameraImage {
isFlipHoriozntal
,
);
// Get the pointer of the data returned from the function to a List
List
<
int
>
imgData
=
imgP
.
asTypedList
(((
newImgWidth
)
*
(
newImgHeight
)));
// Generate image from the converted data
imglib
.
Image
img
=
imglib
.
Image
.
fromBytes
(
newImgWidth
,
newImgHeight
,
imgData
);
// Free the memory space allocated
// from the planes and the converted data
ffi
.
malloc
.
free
(
p
);
ffi
.
malloc
.
free
(
p1
);
ffi
.
malloc
.
free
(
p2
);
...
...
@@ -176,7 +169,7 @@ class IProcessingCameraImage implements ProcessingCameraImage {
/// [processCameraImageToGray8Bit].
@override
Uint8Lis
t
?
processCameraImageToGray8Bit
({
Image8bi
t
?
processCameraImageToGray8Bit
({
int
?
width
,
int
?
height
,
Uint8List
?
plane0
,
...
...
@@ -216,13 +209,14 @@ class IProcessingCameraImage implements ProcessingCameraImage {
imglib
.
Image
img
=
imglib
.
Image
.
fromBytes
(
newImgWidth
,
newImgHeight
,
imgData
);
// retData.addAll(imgData);
ffi
.
malloc
.
free
(
p
);
ffi
.
malloc
.
free
(
imgP
);
// print(newImgHeight * newImgWidth);
return
img
.
getBytes
();
return
Image8bit
(
data:
img
.
getBytes
(),
heigh:
newImgHeight
,
width:
newImgWidth
,
);
}
/// [processCameraImageToRGBIOS]. for IOS with YUV420.
...
...
@@ -259,17 +253,14 @@ class IProcessingCameraImage implements ProcessingCameraImage {
int
newImgWidth
=
(
sinVal
*
height
+
cosVal
*
bytesPerRowPlane0
).
toInt
();
int
newImgHeight
=
(
sinVal
*
bytesPerRowPlane0
+
cosVal
*
height
).
toInt
();
// Allocate memory for the 3 planes of the image
Pointer
<
Uint8
>
p
=
ffi
.
malloc
.
allocate
(
plane0
.
length
);
Pointer
<
Uint8
>
p1
=
ffi
.
malloc
.
allocate
(
plane1
.
length
);
// Assign the planes data to the pointers of the image
Uint8List
pointerList
=
p
.
asTypedList
(
plane0
.
length
);
Uint8List
pointerList1
=
p1
.
asTypedList
(
plane1
.
length
);
pointerList
.
setRange
(
0
,
plane0
.
length
,
plane0
);
pointerList1
.
setRange
(
0
,
plane1
.
length
,
plane1
);
// Call the convertImage function and convert the YUV to RGB
Pointer
<
Uint32
>
imgP
=
_convertImageNV12ToRGB
(
p
,
p1
,
...
...
@@ -283,15 +274,11 @@ class IProcessingCameraImage implements ProcessingCameraImage {
isFlipHoriozntal
,
);
// Get the pointer of the data returned from the function to a List
final
imgData
=
imgP
.
asTypedList
(((
newImgWidth
)
*
(
newImgHeight
)));
// // Generate image from the converted data
imglib
.
Image
img
=
imglib
.
Image
.
fromBytes
(
newImgWidth
,
newImgHeight
,
imgData
);
// Free the memory space allocated
// from the planes and the converted data
ffi
.
malloc
.
free
(
p
);
ffi
.
malloc
.
free
(
p1
);
ffi
.
malloc
.
free
(
imgP
);
...
...
Please
register
or
login
to post a comment