-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Not worth to use QOI decoding over PNG decoding on Android? #3
Comments
I don't know exactly, but most probably Android's PNG decoder is a native library, whereas qoi-java decoder is a Java library. To get expected performance boost from using QOI, it would make more sense to use original C library or one of its optimized implementations like in Rust. Note that I've compared qoi-java with Java AWT PNG parser, and it mostly does make sense, because AWT's PNG parser is mostly written in Java.
Java implementation of QOI is already optimized well (although I have some ideas, but implementing them will not give much performance boost). To decode even faster, as I've said above, you need to use native libraries. Most performant version of QOI decoder should be written in a native language (C/Rust/etc.) and output an int array, suitable to be passed into Bitmap#createBitmap.
You need to get RGB(A) values from a QOIImage and set pixels on a Bitmap: https://stackoverflow.com/a/59788350 |
Have you tested it using C library instead of Java (on Android) that you say it's faster? As I remember, on new Android versions, the ART makes Java/Kotlin as good as C/C++ in terms of performance, usually. Have you tested the conversion to Android's Bitmap object? |
No, I just guess -- I assume that C is faster than Java, but of course I can't argue for or against it because no becnhmarks were done.
No -- I'm not an Android developer and do not have Android development environment set up, so I can't do benchmarks/tests. But the conversion is so simple that I do not think anything needs to be tested here -- you can just try. |
I see. Can you please try to have a sample that runs on Java, but uses the C/C++ library you talked about? As for the conversion from QOIImage to Bitmap, this worked for me:
Now I calculated including the conversion to Bitmap. From inputStream of the resource (files are within the app) : From a file outside the app: Still slower than PNG, of course. Attached here: |
Probably I can, using JNI/JNR (although there will be overhead, it would be interesting to see). But I can not say for now when I will have time to do it. |
Can you please create a Java JNI wrapper and see if it performs better than what you did here? |
Yea, I can, it's just that I'm busy with my job and don't know when I will have time to work on QOI. |
OK thanks. I'm just curious. :) |
Whether I use
QOIUtil.readFile
vsBitmapFactory.decodeFile
of Android, or I useQOIUtil.readImage
vsBitmapFactory.decodeStream
, it seems that Android's implementation is faster to parse PNG files over QOI:From inputStream of the resource (files are within the app) :
QOI took 84 ms
PNG took 25 ms
From a file outside the app:
QOI took 36 ms
PNG took 30 ms
And that's before getting Bitmap instance out of the QOIImage instance, which I don't understand how to do.
Tested on Pixel 4 with Android API 32 on the "wikipedia_008" image files, from here (got from here) :
https://qoiformat.org/qoi_test_images.zip
See attached project:
My Application.zip
How could it be?
Is there anything that can be improved in the implementation?
And how do you convert the output of the function to a working Bitmap instance?
The text was updated successfully, but these errors were encountered: