Showing
2 changed files
with
14 additions
and
20 deletions
@@ -60,7 +60,7 @@ abstract class ProcessingCameraImage { | @@ -60,7 +60,7 @@ abstract class ProcessingCameraImage { | ||
60 | }); | 60 | }); |
61 | 61 | ||
62 | /// [processCameraImageToGray8Bit]. for Android with YUV420. | 62 | /// [processCameraImageToGray8Bit]. for Android with YUV420. |
63 | - Uint8List? processCameraImageToGray8Bit({ | 63 | + Image8bit? processCameraImageToGray8Bit({ |
64 | int? width, | 64 | int? width, |
65 | int? height, | 65 | int? height, |
66 | Uint8List? plane0, | 66 | Uint8List? plane0, |
@@ -70,3 +70,10 @@ abstract class ProcessingCameraImage { | @@ -70,3 +70,10 @@ abstract class ProcessingCameraImage { | ||
70 | bool isFlipVectical = false, | 70 | bool isFlipVectical = false, |
71 | }); | 71 | }); |
72 | } | 72 | } |
73 | + | ||
74 | +class Image8bit { | ||
75 | + final int width; | ||
76 | + final int heigh; | ||
77 | + final Uint8List data; | ||
78 | + Image8bit({required this.data, required this.heigh, required this.width}); | ||
79 | +} |
@@ -83,12 +83,10 @@ class IProcessingCameraImage implements ProcessingCameraImage { | @@ -83,12 +83,10 @@ class IProcessingCameraImage implements ProcessingCameraImage { | ||
83 | int newImgWidth = (sinVal * height + cosVal * bytesPerRowPlane0).toInt(); | 83 | int newImgWidth = (sinVal * height + cosVal * bytesPerRowPlane0).toInt(); |
84 | int newImgHeight = (sinVal * bytesPerRowPlane0 + cosVal * height).toInt(); | 84 | int newImgHeight = (sinVal * bytesPerRowPlane0 + cosVal * height).toInt(); |
85 | 85 | ||
86 | - // Allocate memory for the 3 planes of the image | ||
87 | Pointer<Uint8> p = ffi.malloc.allocate(plane0.length); | 86 | Pointer<Uint8> p = ffi.malloc.allocate(plane0.length); |
88 | Pointer<Uint8> p1 = ffi.malloc.allocate(plane1.length); | 87 | Pointer<Uint8> p1 = ffi.malloc.allocate(plane1.length); |
89 | Pointer<Uint8> p2 = ffi.malloc.allocate(plane2.length); | 88 | Pointer<Uint8> p2 = ffi.malloc.allocate(plane2.length); |
90 | 89 | ||
91 | - // Assign the planes data to the pointers of the image | ||
92 | Uint8List pointerList = p.asTypedList(plane0.length); | 90 | Uint8List pointerList = p.asTypedList(plane0.length); |
93 | Uint8List pointerList1 = p1.asTypedList(plane1.length); | 91 | Uint8List pointerList1 = p1.asTypedList(plane1.length); |
94 | Uint8List pointerList2 = p2.asTypedList(plane2.length); | 92 | Uint8List pointerList2 = p2.asTypedList(plane2.length); |
@@ -96,7 +94,6 @@ class IProcessingCameraImage implements ProcessingCameraImage { | @@ -96,7 +94,6 @@ class IProcessingCameraImage implements ProcessingCameraImage { | ||
96 | pointerList1.setRange(0, plane1.length, plane1); | 94 | pointerList1.setRange(0, plane1.length, plane1); |
97 | pointerList2.setRange(0, plane2.length, plane2); | 95 | pointerList2.setRange(0, plane2.length, plane2); |
98 | 96 | ||
99 | - // Call the convertImage function and convert the YUV to RGB | ||
100 | Pointer<Uint32> imgP = _convertImageYuv420pToRGB( | 97 | Pointer<Uint32> imgP = _convertImageYuv420pToRGB( |
101 | p, | 98 | p, |
102 | p1, | 99 | p1, |
@@ -111,14 +108,10 @@ class IProcessingCameraImage implements ProcessingCameraImage { | @@ -111,14 +108,10 @@ class IProcessingCameraImage implements ProcessingCameraImage { | ||
111 | isFlipHoriozntal, | 108 | isFlipHoriozntal, |
112 | ); | 109 | ); |
113 | 110 | ||
114 | - // Get the pointer of the data returned from the function to a List | ||
115 | List<int> imgData = imgP.asTypedList(((newImgWidth) * (newImgHeight))); | 111 | List<int> imgData = imgP.asTypedList(((newImgWidth) * (newImgHeight))); |
116 | - // Generate image from the converted data | ||
117 | imglib.Image img = | 112 | imglib.Image img = |
118 | imglib.Image.fromBytes(newImgWidth, newImgHeight, imgData); | 113 | imglib.Image.fromBytes(newImgWidth, newImgHeight, imgData); |
119 | 114 | ||
120 | - // Free the memory space allocated | ||
121 | - // from the planes and the converted data | ||
122 | ffi.malloc.free(p); | 115 | ffi.malloc.free(p); |
123 | ffi.malloc.free(p1); | 116 | ffi.malloc.free(p1); |
124 | ffi.malloc.free(p2); | 117 | ffi.malloc.free(p2); |
@@ -176,7 +169,7 @@ class IProcessingCameraImage implements ProcessingCameraImage { | @@ -176,7 +169,7 @@ class IProcessingCameraImage implements ProcessingCameraImage { | ||
176 | 169 | ||
177 | /// [processCameraImageToGray8Bit]. | 170 | /// [processCameraImageToGray8Bit]. |
178 | @override | 171 | @override |
179 | - Uint8List? processCameraImageToGray8Bit({ | 172 | + Image8bit? processCameraImageToGray8Bit({ |
180 | int? width, | 173 | int? width, |
181 | int? height, | 174 | int? height, |
182 | Uint8List? plane0, | 175 | Uint8List? plane0, |
@@ -216,13 +209,14 @@ class IProcessingCameraImage implements ProcessingCameraImage { | @@ -216,13 +209,14 @@ class IProcessingCameraImage implements ProcessingCameraImage { | ||
216 | imglib.Image img = | 209 | imglib.Image img = |
217 | imglib.Image.fromBytes(newImgWidth, newImgHeight, imgData); | 210 | imglib.Image.fromBytes(newImgWidth, newImgHeight, imgData); |
218 | 211 | ||
219 | - // retData.addAll(imgData); | ||
220 | - | ||
221 | ffi.malloc.free(p); | 212 | ffi.malloc.free(p); |
222 | ffi.malloc.free(imgP); | 213 | ffi.malloc.free(imgP); |
223 | 214 | ||
224 | - // print(newImgHeight * newImgWidth); | ||
225 | - return img.getBytes(); | 215 | + return Image8bit( |
216 | + data: img.getBytes(), | ||
217 | + heigh: newImgHeight, | ||
218 | + width: newImgWidth, | ||
219 | + ); | ||
226 | } | 220 | } |
227 | 221 | ||
228 | /// [processCameraImageToRGBIOS]. for IOS with YUV420. | 222 | /// [processCameraImageToRGBIOS]. for IOS with YUV420. |
@@ -259,17 +253,14 @@ class IProcessingCameraImage implements ProcessingCameraImage { | @@ -259,17 +253,14 @@ class IProcessingCameraImage implements ProcessingCameraImage { | ||
259 | int newImgWidth = (sinVal * height + cosVal * bytesPerRowPlane0).toInt(); | 253 | int newImgWidth = (sinVal * height + cosVal * bytesPerRowPlane0).toInt(); |
260 | int newImgHeight = (sinVal * bytesPerRowPlane0 + cosVal * height).toInt(); | 254 | int newImgHeight = (sinVal * bytesPerRowPlane0 + cosVal * height).toInt(); |
261 | 255 | ||
262 | - // Allocate memory for the 3 planes of the image | ||
263 | Pointer<Uint8> p = ffi.malloc.allocate(plane0.length); | 256 | Pointer<Uint8> p = ffi.malloc.allocate(plane0.length); |
264 | Pointer<Uint8> p1 = ffi.malloc.allocate(plane1.length); | 257 | Pointer<Uint8> p1 = ffi.malloc.allocate(plane1.length); |
265 | 258 | ||
266 | - // Assign the planes data to the pointers of the image | ||
267 | Uint8List pointerList = p.asTypedList(plane0.length); | 259 | Uint8List pointerList = p.asTypedList(plane0.length); |
268 | Uint8List pointerList1 = p1.asTypedList(plane1.length); | 260 | Uint8List pointerList1 = p1.asTypedList(plane1.length); |
269 | pointerList.setRange(0, plane0.length, plane0); | 261 | pointerList.setRange(0, plane0.length, plane0); |
270 | pointerList1.setRange(0, plane1.length, plane1); | 262 | pointerList1.setRange(0, plane1.length, plane1); |
271 | 263 | ||
272 | - // Call the convertImage function and convert the YUV to RGB | ||
273 | Pointer<Uint32> imgP = _convertImageNV12ToRGB( | 264 | Pointer<Uint32> imgP = _convertImageNV12ToRGB( |
274 | p, | 265 | p, |
275 | p1, | 266 | p1, |
@@ -283,15 +274,11 @@ class IProcessingCameraImage implements ProcessingCameraImage { | @@ -283,15 +274,11 @@ class IProcessingCameraImage implements ProcessingCameraImage { | ||
283 | isFlipHoriozntal, | 274 | isFlipHoriozntal, |
284 | ); | 275 | ); |
285 | 276 | ||
286 | - // Get the pointer of the data returned from the function to a List | ||
287 | final imgData = imgP.asTypedList(((newImgWidth) * (newImgHeight))); | 277 | final imgData = imgP.asTypedList(((newImgWidth) * (newImgHeight))); |
288 | 278 | ||
289 | - // // Generate image from the converted data | ||
290 | imglib.Image img = | 279 | imglib.Image img = |
291 | imglib.Image.fromBytes(newImgWidth, newImgHeight, imgData); | 280 | imglib.Image.fromBytes(newImgWidth, newImgHeight, imgData); |
292 | 281 | ||
293 | - // Free the memory space allocated | ||
294 | - // from the planes and the converted data | ||
295 | ffi.malloc.free(p); | 282 | ffi.malloc.free(p); |
296 | ffi.malloc.free(p1); | 283 | ffi.malloc.free(p1); |
297 | ffi.malloc.free(imgP); | 284 | ffi.malloc.free(imgP); |
-
Please register or login to post a comment