folksable / blurhash_ffi

a port of blurhash to flutter written in c via dart:ffi
https://pub.dev/packages/blurhash_ffi
BSD 3-Clause "New" or "Revised" License
41 stars 6 forks source link

Windows Decoding White Image #13

Closed dhikshithrm closed 10 months ago

dhikshithrm commented 11 months ago

thanks to @wh201906 for the vla fix with #10 pr, there seems to be a dart side issue while constructing an image sent from the native side.

windows decoding

dhikshithrm commented 11 months ago

https://github.com/folksable/blurhash_ffi/pull/10#issuecomment-1840703640

I just tested them and I also got the blank image view when decoding. However, it looks like the decoding result from the native C code is good. I added some code to print the decoding result and tested them on both Windows and Linux, then I got the same result.

Patch to show the head and the end of the decoding result ``` diff --git a/lib/blurhash.dart b/lib/blurhash.dart index 63d8de9..29f719b 100644 --- a/lib/blurhash.dart +++ b/lib/blurhash.dart @@ -341,6 +341,38 @@ class BlurhashFFI { return completer.future; } + void printUint8ListInHex(Uint8List list) { + print("data length: " + list.length.toString()); + print("head:"); + int printLength = list.length > 256 ? 256 : list.length; + String hexString = ""; + int i = 0; + for (i = 0; i < printLength; i++) { + hexString += list[i].toRadixString(16).padLeft(2, '0'); + if (i % 16 == 15) { + print(hexString); + hexString = ""; + } + } + if (i % 16 == 15) { + print(hexString); + } + + print("end:"); + int startLength = list.length > 256 ? list.length - 256 : 0; + Uint8List lastBytes = list.sublist(startLength); + for (i = 0; i < printLength; i++) { + hexString += lastBytes[i].toRadixString(16).padLeft(2, '0'); + if (i % 16 == 15) { + print(hexString); + hexString = ""; + } + } + if (i % 16 == 15) { + print(hexString); + } + } + void isolateEntryPoint(SendPort sendPort) async { void onSend(dynamic data) { try { @@ -366,6 +398,7 @@ class BlurhashFFI { data.free(); final Uint8List resultImage = result.asTypedList(data.width * data.height * data.channels); + printUint8ListInHex(resultImage); _bindings.freePixelArray(result); final _DecodeResponse response = _DecodeResponse(data.id, resultImage); ```

Test result for the 3 images in the example

Result on linux ``` linux flutter: data length: 57600 flutter: head: flutter: 004346ff004346ff004346ff004346ff flutter: 004346ff004346ff004346ff004346ff flutter: 004246ff004246ff004245ff004245ff flutter: 004245ff004245ff004144ff004144ff flutter: 004144ff004043ff034043ff0e4042ff flutter: 163f42ff1c3f42ff223f41ff263e41ff flutter: 2b3e40ff2f3d3fff333d3fff363c3eff flutter: 393c3eff3d3b3dff403b3cff433a3bff flutter: 463a3bff48393aff4b3939ff4e3838ff flutter: 503737ff523736ff553635ff573534ff flutter: 593534ff5b3433ff5d3331ff5f3330ff flutter: 61322fff63312eff64312dff66302cff flutter: 682f2bff692f2aff6a2e29ff6c2d28ff flutter: 6d2d26ff6e2c25ff6f2c24ff712b23ff flutter: 722b22ff722a21ff732a20ff74291fff flutter: 75291eff75281dff76281cff77281bff flutter: end: flutter: b64536ffb64536ffb74536ffb74636ff flutter: b84636ffb84637ffb84737ffb84737ff flutter: b84737ffb84737ffb84838ffb74838ff flutter: b74838ffb64838ffb64839ffb54839ff flutter: b44939ffb34939ffb24939ffb1493aff flutter: af493affae493affac493affab493bff flutter: a9493bffa7493bffa5493bffa3493cff flutter: a1493cff9f493cff9c493cff9a493cff flutter: 97493dff95493dff92493dff8f493dff flutter: 8c493eff89493eff86493eff83483eff flutter: 7f483eff7c483eff78483fff75483fff flutter: 71483fff6e483fff6a473fff66473fff flutter: 624740ff5f4740ff5b4740ff574740ff flutter: 534740ff504740ff4c4640ff494640ff flutter: 454640ff424640ff3f4640ff3d4640ff flutter: 3b4641ff394641ff384641ff374641ff flutter: data length: 57600 flutter: head: flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff060000ff120000ff flutter: 1a0000ff210000ff270000ff2c0c0cff flutter: 311818ff352121ff3a2828ff3e2e2eff flutter: 413333ff453838ff493c3cff4c4040ff flutter: 4f4444ff524848ff554b4bff584f4fff flutter: 5b5252ff5d5555ff605757ff625a5aff flutter: 655c5cff675f5fff696161ff6b6363ff flutter: 6d6565ff6f6767ff716868ff736a6aff flutter: 746c6cff766d6dff776e6eff786f6fff flutter: 7a7070ff7b7171ff7c7272ff7d7373ff flutter: 7e7474ff7f7474ff7f7575ff807575ff flutter: 807575ff817575ff817575ff817575ff flutter: 817575ff827575ff817575ff817474ff flutter: end: flutter: 4c4a4aff4a4949ff494848ff474747ff flutter: 454545ff434444ff414242ff3e4040ff flutter: 3b3e3eff383c3cff353939ff313636ff flutter: 2c3434ff273030ff222d2dff1b2929ff flutter: 122525ff042020ff001a1aff001313ff flutter: 000808ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: data length: 57600 flutter: head: flutter: 3d4d43ff3d4d43ff3e4d44ff3f4d44ff flutter: 404d44ff414e45ff434f45ff454f46ff flutter: 475047ff4a5147ff4c5248ff4f5349ff flutter: 52544aff54554bff57564cff5a574dff flutter: 5d584eff605a4fff635b50ff655c51ff flutter: 685d52ff6b5e53ff6d5f54ff706055ff flutter: 736156ff756257ff776357ff7a6458ff flutter: 7c6559ff7e6659ff80675aff82675aff flutter: 84685aff85685aff87695bff88695bff flutter: 8a6a5bff8b6a5bff8c6a5aff8d6a5aff flutter: 8e6a5aff8f6a59ff906a59ff906a58ff flutter: 916a58ff916957ff926956ff926955ff flutter: 926855ff926854ff926753ff926652ff flutter: 926651ff926550ff91644fff91634eff flutter: 90634dff90624bff8f614bff8f604aff flutter: 8e6049ff8d5f48ff8c5e47ff8c5e47ff flutter: end: flutter: b18a73ffb38d74ffb59076ffb79278ff flutter: b9957affbb987cffbd9b7effbf9e80ff flutter: c1a182ffc3a484ffc5a686ffc7a988ff flutter: c9ac8affcbae8cffccb18effceb390ff flutter: d0b592ffd2b893ffd3ba95ffd5bc97ff flutter: d6be98ffd7c09affd9c19bffdac39cff flutter: dbc49effdcc69fffddc7a0ffdec8a1ff flutter: dec9a2ffdfcaa3ffdfcba3ffe0cca4ff flutter: e0cca5ffe1cda5ffe1cda6ffe1cda6ff flutter: e1cea7ffe1cea7ffe1cea7ffe1cea7ff flutter: e1cea7ffe1cea7ffe1cda8ffe0cda8ff flutter: e0cda7ffe0cda7ffdfcca7ffdfcca7ff flutter: dfcba7ffdecba7ffdecaa7ffddcaa6ff flutter: ddcaa6ffddc9a6ffdcc9a6ffdcc8a6ff flutter: dcc8a6ffdbc8a5ffdbc7a5ffdbc7a5ff flutter: dbc7a5ffdbc7a5ffdac7a5ffdac7a5ff ```
Result on Windows ``` windows flutter: data length: 57600 flutter: head: flutter: 004346ff004346ff004346ff004346ff flutter: 004346ff004346ff004346ff004346ff flutter: 004246ff004246ff004245ff004245ff flutter: 004245ff004245ff004144ff004144ff flutter: 004144ff004043ff034043ff0e4042ff flutter: 163f42ff1c3f42ff223f41ff263e41ff flutter: 2b3e40ff2f3d3fff333d3fff363c3eff flutter: 393c3eff3d3b3dff403b3cff433a3bff flutter: 463a3bff48393aff4b3939ff4e3838ff flutter: 503737ff523736ff553635ff573534ff flutter: 593534ff5b3433ff5d3331ff5f3330ff flutter: 61322fff63312eff64312dff66302cff flutter: 682f2bff692f2aff6a2e29ff6c2d28ff flutter: 6d2d26ff6e2c25ff6f2c24ff712b23ff flutter: 722b22ff722a21ff732a20ff74291fff flutter: 75291eff75281dff76281cff77281bff flutter: end: flutter: b64536ffb64536ffb74536ffb74636ff flutter: b84636ffb84637ffb84737ffb84737ff flutter: b84737ffb84737ffb84838ffb74838ff flutter: b74838ffb64838ffb64839ffb54839ff flutter: b44939ffb34939ffb24939ffb1493aff flutter: af493affae493affac493affab493bff flutter: a9493bffa7493bffa5493bffa3493cff flutter: a1493cff9f493cff9c493cff9a493cff flutter: 97493dff95493dff92493dff8f493dff flutter: 8c493eff89493eff86493eff83483eff flutter: 7f483eff7c483eff78483fff75483fff flutter: 71483fff6e483fff6a473fff66473fff flutter: 624740ff5f4740ff5b4740ff574740ff flutter: 534740ff504740ff4c4640ff494640ff flutter: 454640ff424640ff3f4640ff3d4640ff flutter: 3b4641ff394641ff384641ff374641ff flutter: data length: 57600 flutter: head: flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff060000ff120000ff flutter: 1a0000ff210000ff270000ff2c0c0cff flutter: 311818ff352121ff3a2828ff3e2e2eff flutter: 413333ff453838ff493c3cff4c4040ff flutter: 4f4444ff524848ff554b4bff584f4fff flutter: 5b5252ff5d5555ff605757ff625a5aff flutter: 655c5cff675f5fff696161ff6b6363ff flutter: 6d6565ff6f6767ff716868ff736a6aff flutter: 746c6cff766d6dff776e6eff786f6fff flutter: 7a7070ff7b7171ff7c7272ff7d7373ff flutter: 7e7474ff7f7474ff7f7575ff807575ff flutter: 807575ff817575ff817575ff817575ff flutter: 817575ff827575ff817575ff817474ff flutter: end: flutter: 4c4a4aff4a4949ff494848ff474747ff flutter: 454545ff434444ff414242ff3e4040ff flutter: 3b3e3eff383c3cff353939ff313636ff flutter: 2c3434ff273030ff222d2dff1b2929ff flutter: 122525ff042020ff001a1aff001313ff flutter: 000808ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: 000000ff000000ff000000ff000000ff flutter: data length: 57600 flutter: head: flutter: 3d4d43ff3d4d43ff3e4d44ff3f4d44ff flutter: 404d44ff414e45ff434f45ff454f46ff flutter: 475047ff4a5147ff4c5248ff4f5349ff flutter: 52544aff54554bff57564cff5a574dff flutter: 5d584eff605a4fff635b50ff655c51ff flutter: 685d52ff6b5e53ff6d5f54ff706055ff flutter: 736156ff756257ff776357ff7a6458ff flutter: 7c6559ff7e6659ff80675aff82675aff flutter: 84685aff85685aff87695bff88695bff flutter: 8a6a5bff8b6a5bff8c6a5aff8d6a5aff flutter: 8e6a5aff8f6a59ff906a59ff906a58ff flutter: 916a58ff916957ff926956ff926955ff flutter: 926855ff926854ff926753ff926652ff flutter: 926651ff926550ff91644fff91634eff flutter: 90634dff90624bff8f614bff8f604aff flutter: 8e6049ff8d5f48ff8c5e47ff8c5e47ff flutter: end: flutter: b18a73ffb38d74ffb59076ffb79278ff flutter: b9957affbb987cffbd9b7effbf9e80ff flutter: c1a182ffc3a484ffc5a686ffc7a988ff flutter: c9ac8affcbae8cffccb18effceb390ff flutter: d0b592ffd2b893ffd3ba95ffd5bc97ff flutter: d6be98ffd7c09affd9c19bffdac39cff flutter: dbc49effdcc69fffddc7a0ffdec8a1ff flutter: dec9a2ffdfcaa3ffdfcba3ffe0cca4ff flutter: e0cca5ffe1cda5ffe1cda6ffe1cda6ff flutter: e1cea7ffe1cea7ffe1cea7ffe1cea7ff flutter: e1cea7ffe1cea7ffe1cda8ffe0cda8ff flutter: e0cda7ffe0cda7ffdfcca7ffdfcca7ff flutter: dfcba7ffdecba7ffdecaa7ffddcaa6ff flutter: ddcaa6ffddc9a6ffdcc9a6ffdcc8a6ff flutter: dcc8a6ffdbc8a5ffdbc7a5ffdbc7a5ff flutter: dbc7a5ffdbc7a5ffdac7a5ffdac7a5ff ```

(They are identical)

So I guess it's something wrong in the Dart side.

iliser commented 10 months ago

Same problem exists on linux/android too. On this os image in most cases fine, in rare cases first pixels get corrupted and contains garbage values. I found some memory problems and fix it. After that on linux/android image always correct. Not tested on windows.

wh201906 commented 10 months ago

@iliser I just tested your fork on Windows and it is fixed. Thanks! 图片 图片

(Ah how could I forget to deallocate the memory in #10)

dhikshithrm commented 10 months ago

Thank you @iliser for the fix and memory leak observation and thank you @wh201906 for confirming this fixed #13