image icon indicating copy to clipboard operation
image copied to clipboard

Adding EOI FLAG to unfinished JPEG buffer

Open truonghoangduy opened this issue 4 years ago • 1 comments

Hi ! I was sending a picture via Bluetooth from small IoT devices the image buffer some time missing few end package ( frame buffer ) so I just add 0xFF 0xD9 at the end of the buffer to closing the JPEG format sacrifice missing frame buffer. And then I push it into decodeImage() the lib throw me error ( with add EOI FLAG )

unexpected marker: ffda

When the exception was thrown, this was the stack #0 JpegScan._readBit package:image/…/jpeg/jpeg_scan.dart:135 #1 JpegScan._decodeHuffman package:image/…/jpeg/jpeg_scan.dart:147 #2 JpegScan._decodeBaseline package:image/…/jpeg/jpeg_scan.dart:189 #3 JpegScan._decodeMcu package:image/…/jpeg/jpeg_scan.dart:324 #4 JpegScan.decode

Without EOI FLAG The method '>' was called on null. Receiver: null Tried calling: >(0) When the exception was thrown, this was the stack #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5) #1 JpegScan._receive package:image/…/jpeg/jpeg_scan.dart:159 #2 JpegScan._receiveAndExtend package:image/…/jpeg/jpeg_scan.dart:174 #3 JpegScan._decodeBaseline package:image/…/jpeg/jpeg_scan.dart:183 #4 JpegScan._decodeMcu

It work when i using widget/Image Image.memory adding my buffer without EOI flag work fine Here is txt byte format for debugging added 0xFF 0xD9 as EOI data.txt

Python script write them to the picture format work with or without EOI flag https://github.com/truonghoangduy/Valerian/blob/master/IoT-Devices/Valarien-Sight/main.py

To sum up can I add EOI FLAG to unfinished JPEG Buffer and then the lib could parse it to package:image/image.dart Image class . I really sorry for the misunderstanding JPEG markers and it supposed to be working.

truonghoangduy avatar Jun 15 '20 05:06 truonghoangduy

I'm really sorry for the long delay in response. My understanding of Jpeg, flags are associated with blocks, where the flag is followed by a block size; the next flag is expected to be after the block. So if the flag turns up in the middle of a block, as in your case, it's simply interpreted as part of the blocks data, and in this case bad data in the huffman encoding data. I'm not sure that Widget/Image.memory is doing. I suspect it's just aborting the decode when the error in decoding occurred and giving you whatever it had finished until the error. The decoder will have to be re-arranged a bit to be able to try and finish decoding the image if an error occurs along the way.

brendan-duncan avatar Sep 14 '20 06:09 brendan-duncan