fix github issue #121 - correct bitmap stride in QR code generation#136
Open
munzzyy wants to merge 1 commit into
Open
fix github issue #121 - correct bitmap stride in QR code generation#136munzzyy wants to merge 1 commit into
munzzyy wants to merge 1 commit into
Conversation
…de generation setPixels() was passed width (the requested dimension) as the row stride instead of w (the actual BitMatrix width returned by zxing). Since the pixel array is filled using w as the row stride, any mismatch between width and w shifts every row after the first, corrupting the QR code so it can't be scanned.
Member
|
Thanks for the fix... I think #121 is actually something else (the image hadn't been uploaded yet to ipfs storage, and so there wasn't a proper URI in the QR code, jus as hash:foo value), but this is still a good bug find anyhow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #121.
encodeAsBitmap()inSocialImageUtil.ktbuilds the pixel array usingw/h, the actual dimensions zxing'sMultiFormatWriterhands back fromBitMatrix, and fills it withoffset = y * wper row. But the call tobitmap.setPixels()right after passeswidth(the size that was originally requested) as the stride argument instead ofw.Those two aren't guaranteed to match. QR codes only come in fixed module counts, so
MultiFormatWriter.encode()can return aBitMatrixsized slightly differently than what was asked for. Whenever that happens,setPixels()reads each row startingwidthentries apart in the array while the data is actually laid outwentries apart, so every row past the first is read from the wrong offset. The result is a bitmap where all but the first row of the QR code is shifted, which is exactly the "doesn't render any data" / unscannable symptom in the issue.Changed the stride argument to
wso it matches how the array was actually populated.Couldn't run this on-device (no Android SDK/emulator in this environment), but the bug is a plain array-indexing mismatch and the fix is checkable by inspection:
pixelsis written with row stridew, sosetPixelsneeds to be told the row stride iswtoo. There's no existing test target for this class inapp/src/main, so I didn't add one - happy to if there's a preferred place forapp-module unit tests here.