awxkee / jxl-coder

JPEG XL (JXL) Decoder/Encoder library for Android
Apache License 2.0
53 stars 5 forks source link

Quality doesn't affect encoded image #6

Closed T8RIN closed 1 year ago

T8RIN commented 1 year ago

I have no sense why this happens, it's l ooks like the only lossless/lossy type affects image and distance are ignored

awxkee commented 1 year ago

I have no sense why this happens, it's l ooks like the only lossless/lossy type affects image and distance are ignored

This is just one possible options currently to regulate quality. I had a look to source for well-known ImageMagick and it just do not provide any options to regulate quality except loosy/loseless. This may happen due to libjxl still in beta, and after some time ( possible few years ) if demand to JXL will increase it will start works as expected

T8RIN commented 1 year ago

I have no sense why this happens, it's l ooks like the only lossless/lossy type affects image and distance are ignored

This is just one possible options currently to regulate quality. I had a look to source for well-known ImageMagick and it just do not provide any options to regulate quality except loosy/loseless. This may happen due to libjxl still in beta, and after some time ( possible few years ) if demand to JXL will increase it will start works as expected

Hmmm, sounds not good, but maybe for the users there will be no sense , btw thanks for the library :)

I will use another product flavor to not increase my app size five/six times

T8RIN commented 1 year ago

@awxkee sorry for asking this, but do you now the way of writing exif metadata to files except of JPG/PNG/WEBP ? Because google don't want to add such functionality to ExifInterface yet

awxkee commented 1 year ago

@awxkee sorry for asking this, but do you now the way of writing exif metadata to files except of JPG/PNG/WEBP ? Because google don't want to add such functionality to ExifInterface yet

Yes, almost all libraries provides native interface to do this. Google just decided not implement this in android.

T8RIN commented 1 year ago

@awxkee sorry for asking this, but do you now the way of writing exif metadata to files except of JPG/PNG/WEBP ? Because google don't want to add such functionality to ExifInterface yet

Yes, almost all libraries provides native interface to do this. Google just decided not implement this in android.

Which libraries for example?

awxkee commented 1 year ago

@awxkee sorry for asking this, but do you now the way of writing exif metadata to files except of JPG/PNG/WEBP ? Because google don't want to add such functionality to ExifInterface yet

Yes, almost all libraries provides native interface to do this. Google just decided not implement this in android.

Which libraries for example?

Libavif, libavif definitely do

awxkee commented 1 year ago

Finally I had a look and a distance parameter works perfectly but this required quite complex computation for distance static inline float JXLGetDistance(int quality) { if (quality == 0) return (1.0f); if (quality >= 30) return std::clamp((0.1f + (float) (100 - std::min(100.0f, (float)quality)) * 0.09f), 0.0f, 15.0f); return std::clamp((6.24f + (float) pow(2.5f, (30.0 - (float) quality) / 5.0) / 6.25f), 0.0f, 15.0f); } So I did it and added just a quality parameter which works just in range 0...100 where 0 means default parameter equals to distance = 1.0f

awxkee commented 1 year ago

So finally there are two quality parameters in Jpeg XL quality and effort that works simultanesously

T8RIN commented 1 year ago

Finally I had a look and a distance parameter works perfectly but this required quite complex computation for distance static inline float JXLGetDistance(int quality) { if (quality == 0) return (1.0f); if (quality >= 30) return std::clamp((0.1f + (float) (100 - std::min(100.0f, (float)quality)) * 0.09f), 0.0f, 15.0f); return std::clamp((6.24f + (float) pow(2.5f, (30.0 - (float) quality) / 5.0) / 6.25f), 0.0f, 15.0f); } So I did it and added just a quality parameter which works just in range 0...100 where 0 means default parameter equals to distance = 1.0f

So it means i can use both effort and quality for lossless and lossy modes?

awxkee commented 1 year ago

I’m not really tested this one but I think you can. However I think setting a quality in lossless mode will be ignored by libjxl, but I didn’t check it

T8RIN commented 1 year ago

Okay 👀