Urgent, JPG quality / compression

Hi,

I’m making an image with the camera. Here I have two choices:

  1. Save the display object
  2. Save the original file taken

I need to send the image to a server, so option 2 isn’t my preferred solution, as the images are about 3-4MB each.

Number 1 gives somewhat reasonable results, but still the image is way too big for my needs (it’s 400kb for 640x960).
I need a way to specify the quality level for the display.save() method.

Now, as that’s probably not likely to be in corona any time soon, I am in deep need of an alternative.

Is there any pure-lua JPG library (or any other method so I can compress the image to around 50-150kb?)
Or is it possible to use libjpeg from within corona? [import]uid: 5942 topic_id: 32185 reply_id: 332185[/import]

I don’t know about a pure-lua solution, but I am using the same thing for my app. What I do is I save the image to the device, send it to my server, compress and process it with PHP and save it to the server and once this is all done, the app deletes the old image and downloads the new one.

It looks like a long process but it really doesn’t take longer than 3-4 seconds with WiFi and a little longer on 3G.

Edit: Forgot to say that the final image is of the dimensions of 640x424 and takes about 100-150kb [import]uid: 14018 topic_id: 32185 reply_id: 128141[/import]

Yeah, that’s what I’m doing too… But 150kb per upload is still a lot, when the image can easily be about 25% that [import]uid: 5942 topic_id: 32185 reply_id: 128260[/import]

I don’t know about a pure-lua solution, but I am using the same thing for my app. What I do is I save the image to the device, send it to my server, compress and process it with PHP and save it to the server and once this is all done, the app deletes the old image and downloads the new one.

It looks like a long process but it really doesn’t take longer than 3-4 seconds with WiFi and a little longer on 3G.

Edit: Forgot to say that the final image is of the dimensions of 640x424 and takes about 100-150kb [import]uid: 14018 topic_id: 32185 reply_id: 128141[/import]

You can choose the compression amount in PHP and make the end images take up less space [import]uid: 14018 topic_id: 32185 reply_id: 128288[/import]

Yes I understand, but I’m more concerned with the upload speed from the iphone -> server.
When I have the image on the server, we can optimize and do anything with it [import]uid: 5942 topic_id: 32185 reply_id: 128289[/import]

Yeah, that’s what I’m doing too… But 150kb per upload is still a lot, when the image can easily be about 25% that [import]uid: 5942 topic_id: 32185 reply_id: 128260[/import]

You can choose the compression amount in PHP and make the end images take up less space [import]uid: 14018 topic_id: 32185 reply_id: 128288[/import]

Yes I understand, but I’m more concerned with the upload speed from the iphone -> server.
When I have the image on the server, we can optimize and do anything with it [import]uid: 5942 topic_id: 32185 reply_id: 128289[/import]

Ouch. I just installed build 1003. My app takes pictures and saves them as png files using display.save() at 640x960 resolution.

In build 996 images were in the 600-800k ballpark. Now they appear to be in the 1.5MB ballpark.

We could really use something to control the compression… either for jpgs (which are too low quality in corona), or for the pngs (which compress GIGANTIC, perhaps done for the changes in build 999). [import]uid: 79933 topic_id: 32185 reply_id: 138756[/import]

@mpappas how can you compress some image with 1003 build? [import]uid: 172733 topic_id: 32185 reply_id: 138776[/import]

Ouch. I just installed build 1003. My app takes pictures and saves them as png files using display.save() at 640x960 resolution.

In build 996 images were in the 600-800k ballpark. Now they appear to be in the 1.5MB ballpark.

We could really use something to control the compression… either for jpgs (which are too low quality in corona), or for the pngs (which compress GIGANTIC, perhaps done for the changes in build 999). [import]uid: 79933 topic_id: 32185 reply_id: 138756[/import]

@mpappas how can you compress some image with 1003 build? [import]uid: 172733 topic_id: 32185 reply_id: 138776[/import]

I am taking a picture with the camera, showing it onscreen and then using display.save()

Corona will save in jpg format if you give it a filename with .jpg, and it will save in png format if you use ,png in the filename.

Now, with build 1074, the png files are still pretty huge (apparently lossless or close to it, with alpha as well). So, I’ve switched back to jpgs…

The good news is that the jpg quality on iOS went way up (filesize increased pretty good too, to about the old png size). It’s ok by me - the images look great!

However, the saved jpg quality on android is not nearly as good. And the file sizes are 1/10 the size of the iOS saved jpg images – I am saving a 480x720 image on android, and the file size is only 24kb. That’s like a thumbnail filesize – but it’s almost a fullscreen image on my droid… Not the best quality…

So, when users take images on droids, and my app tries to scale them and save them using display.save… The result is not so pretty…

The final result: It looks like they vastly increased the quality of the jpg compression on iOS… Kudos on that. Maybe the Android jpg compression will get a little quality adjustment next :slight_smile:

I just had a look at the code and iOS saves JPEGs at 100% compression (which is still a bit lossy) and Android saves them at 90% compression.  My memory is a bit fuzzy about this, but I think our iOS team upped the JPEG compression to 100% because they didn’t have PNG support at the time so this was the next best thing.  If you’re all happy with the 100% JPEG compression file size, then we can change Android to do the same.

Also note that when taking screenshots, PNGs are best used for things that have a lot of solid colors, such as UI screenshots.  JPEGs are best used for images that have a large mix of colors such as photos where it lossy format isn’t really noticeable.

Wow, it’s just 10% difference on the setting, but it makes a factor of 10 difference on the size saved! (And a pretty big quality difference too - It is photos as you implied/recommended)

I wouldn’t be too sure that the compressor setting on iOS and android is identical though… The compressors may be implemented differently(?)

Overall, if you want to throw it to 100% on the Android side too, that would be fine by me! If you’ve got a lot of spare time, you could throw it to 95% and I could test it out for you (on either / both iOS and Droid)

:slight_smile:

Oh wait… you said its about 10x file size difference between iOS and Android.  That kind of bothers me.  So are you saying that the PNG’s file size on iOS is even bigger than the JPEG file size?

I’m thinking we should either attempt to find that magic compression rate sweet spot (perhaps 95%?) or we should just make it settable.  Ideally, making it settable is the best choice, but API changes are team decisions on my end because multiple people are involved (update code on iOS/Android, updating documentation, updating sample code, involving QA, etc.).  I’m just trying to find the path of least resistance to help you guys out.

Joshua, I’ll chime in here with… there is no “magic” compression sweet spot.  It is going to be different depending on the image being compressed, and different for the different use cases for all the different apps Corona devs make.  Somebody is going to want best quality, someone is going to have an equally pressing need for smallest file size.  Everyone in between will have their own sweet spot/quality trade off.  So, I vote for settable compression.  

Now, it sounds like there might actually be a problem on the Android side if it is already set at 90% and there is a huge, noticeable quality difference between that and 100% on iOS.  So maybe what’s needed now is a short term fix for the Android issue, and then a mid-term solution would be Corona-settable compression. 

-Stephen

Oh bugger… I’ve discovered deep down in the bowels of our Android code where we save a JPEG at 50% compression.  It’s some old legacy code that I’ll bet is responsible for this issue that you guys are facing.  I’ll bump it up to 90% like the rest of our Android code expects.  Thanks for following up on this.  It forced me to take a deeper look at what was going on.

Note that this change won’t be made available in a daily build until hopefully next week.  We’re currently preparing a new release version of the Corona SDK which takes priority at the moment.

That’s the best news I had so far this week, thanks Joshua! Woohoo!