Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

ReadFile.readBitmap alters image colors #87

Closed
rmtheis opened this issue Jun 1, 2015 · 10 comments
Closed

ReadFile.readBitmap alters image colors #87

rmtheis opened this issue Jun 1, 2015 · 10 comments
Labels

Comments

@rmtheis
Copy link
Owner

rmtheis commented Jun 1, 2015

ReadFile.readFile and ReadFile.readMem seem to be changing white to gray.

@rmtheis rmtheis added the bug label Jun 1, 2015
@rmtheis
Copy link
Owner Author

rmtheis commented Jun 1, 2015

On some devices, this is causing the following tests to fail in ReadFileTest:

testReadFile_jpg
testReadMem_jpg

@rmtheis
Copy link
Owner Author

rmtheis commented Jun 2, 2015

device-2015-06-02-072547

@rmtheis
Copy link
Owner Author

rmtheis commented Jun 14, 2015

The tests have been fixed but the ReadFile problems remain. The following tests are now failing:

testReadBitmap (the alpha value is apparently read incorrectly for the 1x1 bitmap)
testReadFile_jpg
testReadMem_jpg

@rmtheis rmtheis changed the title ReadFile.readFile and ReadFile.readMem methods alter image colors ReadFile.readBitmap alters image colors Jun 14, 2015
@megabytefisher
Copy link
Contributor

From my minor testing on this, I am wondering if these tests are failing because of "Java_com_googlecode_leptonica_android_ReadFile_nativeReadBitmap" converting the 32-bit bitmap image to a 8-bit grayscale image? The alpha data of the image is discarded, so I'm guessing the internal RGBA representation has an alpha value that is not equal to the full opaque value? I'm not totally sure.

I can do more testing on this issue, but in any case, would you be opposed to me modifying the aforementioned function so that it creates a Pix with the full 32-bit data, instead of grayscale?

The code I mentioned is here:
https://github.com/rmtheis/tess-two/blob/master/tess-two/jni/com_googlecode_leptonica_android/readfile.cpp#L113

@rmtheis
Copy link
Owner Author

rmtheis commented Jul 4, 2016

I think changing the function to return a Pix with the full 32-bit data would be fine, and worth doing.

Yes it does look like the alpha data is currently discarded.

Hmm, it looks like there's a version in renard314's version of the repo that may be worth testing and using: https://github.com/renard314/tess-two/blob/master/tess-two/jni/com_googlecode_leptonica_android/readfile.cpp#L141

I see there's a function called pixEndianByteSwap in renard314's version. I seem to remember some endianness-related changes in the pre-release Leptonica code that may possibly perform a related function. I haven't taken a close look at either Renard's version or the Leptonica code at this point though.

@megabytefisher
Copy link
Contributor

This did end up fixing all those failing tests- I used renard314's version. I hope that's okay.

@megabytefisher
Copy link
Contributor

megabytefisher commented Jul 12, 2016

Actually, upon second look, this might have introduced another issue- I'm now getting:

com.googlecode.leptonica.android.test.JpegIOTest > testCompressToJpeg[XT907 - 4.4.2] FAILED
Test failed to run to completion. Reason: 'Instrumentation run failed due to 'Native crash''. Check device logcat for details
Tests on XT907 - 4.4.2 failed: Instrumentation run failed due to 'Native crash'
:tess-two-test:connectedDebugAndroidTest FAILED

Let me test this some more. Sorry for the confusion- that'll teach me to think I've won too early.

Edit: this was just caused by me forgetting to change Pix's depth from 8 to 32. So that's fixed, but other tests now fail because of alpha issues. I'll work on getting all fixed.

@alexcohn
Copy link
Contributor

alexcohn commented Jul 3, 2019

I have fixed this and similar WriteFile tests in my fork, which uses Tesseract 4.0. Should I create a special Pull Request for these changes, or maybe it would be wise to move the whole project to Tesseract 4.0 ?

@rmtheis
Copy link
Owner Author

rmtheis commented Jul 3, 2019

My preference would be to first have pull requests or a single PR to fix this issue and the other similar issues, so that I could tag a release and publish a version on Bintray with those fixes for users who want to have the bug fixes but don't want to upgrade to Tesseract 4.0 yet.

@alexcohn
Copy link
Contributor

alexcohn commented Jul 3, 2019

Feel free to cherry-pick the relevant commits. Note that no changes to tesseract or leptronica sources were not involved.

I will be away from computers for about a week, but if you need my help I will do my best on return from this short vacation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants