Resizing images - slow performance on device

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

m1BUSwIgg
Posts: 9
Joined: Wed Jun 20, 2012 4:41 am

Resizing images - slow performance on device

Post by m1BUSwIgg » Wed Oct 31, 2012 6:43 pm

I've been looking into various ways to resize images captured with mobilePickPhoto. Here's what I am trying to achieve:
1) resize images to a preferred size with acceptable on-device processing times
2) cross platform solution (mainly compatibility with android)

Using an iPhone 4 (running iOS6) as a minimum required device, I started with:

mobilePickPhoto "camera",1000,1000

After snapping a picture in iOS camera overlay, time was measured from the moment the "Use" button was pressed to returning to the card from which mobilePickPhoto was initiated. The above method resulted in times of approximately 4 seconds, which is acceptable.

Since setting the maximum image dimensions of mobilePickPhoto is not supported by Android, I began investigating alternatives. The first method was to resize the photo after the image was obtained by mobilePickPhoto using the following:

Code: Select all

--For resizing images
function mk_makeratio tW,tH,w,h
     put min (tW/w,tH/h) into tscaleFactor
     return round(w * tscaleFactor) & "," & round(h * tscaleFactor)
end mk_makeratio

on mouseUp
   
   --   Pick photo from phone
   mobilePickPhoto "camera"
   if it is "cancel" then 
      exit mouseUp
   end if
   
   --   Resizing
   put the formattedwidth of last image into w
   put the formattedheight of last image into h
   put 1000 into tW
   put 1000 into tH
   put mk_makeratio(tW,tH,w,h) into new_imagesize
   put item 1 of new_imagesize into newW
   put item 2 of new_imagesize into newH
   lock screen
   set the width of last image to newW
   set the height of last image to newH
   set the imagedata of last image to the imagedata of last image
   unlock screen
   
end mouseUp
Times for the above were approximately 15 seconds, which is too long (particularly if you are taking multiple photos). To make matters worse, if you include:

set the resizeQuality of the templateImage to "best"

before the mobilePickPhoto statement (in order to optimize image quality of the resized image), processing times skyrocket to 1 min 13 secs. Adding this line when setting maximum image size of mobilePickPhoto has little to no effect on processing time.

My next option was to not resize after the fact and set the size properties of templateImage. For testing purposes I chose 747x1000 which is proportional to the native full size portrait image captured by the camera. Here's what I used:

Code: Select all

on mouseUp
   
--Set templateImage properties that mobilePickPhoto is base on
   set the width of the templateImage to 747
   set the height of the templateImage to 1000
   set the lockloc of the templateImage to true
   
   --   Pick photo from phone
   mobilePickPhoto "camera"
   if it is "cancel" then 
      exit mouseUp
   end if
   
   lock screen
   set the imagedata of last image to the imagedata of last image
   unlock screen
   
end mouseUp
Again, processing times were in the 15 second range, and 1 min 13 sec range when setting resizeQuality to "Best".

Since it is obvious that the hardware can handle reasonable processing times when setting the maximum image size property of mobilePickPhoto, I'm at a loss as to why alternate methods take so much longer. If there are no other alternatives, it will severely compromise the ability of the intended app to provide a cross-platform solution.

Can anyone confirm these observations?
Can someone suggest an alternate resizing method I can try?

Thanks in advance.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Resizing images - slow performance on device

Post by jacque » Thu Nov 01, 2012 8:18 pm

I copied your first script to a button in a new stack and inserted this line at the top of the mouseup handler:

set the imagequality of the templateimage to "normal"

Then I made two more copies of the button and changed them to use an imagequality of "best" or "good". I compiled for Android and ran it on my Galaxy Tab 7 Plus. Results were:

Normal quality: instantaneous image, under 1 second
Good quality: instantaneouos image, under 1 second
Best quality: considerable lag, about 30 seconds

This is pretty consistent with results reported for geometry scripts that do resizing for screen display, and consensus seems to be that "good" is good enough, particularly on an Android screen. The "best" algorithm is time-consuming.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

m1BUSwIgg
Posts: 9
Joined: Wed Jun 20, 2012 4:41 am

Re: Resizing images - slow performance on device

Post by m1BUSwIgg » Thu Nov 01, 2012 8:45 pm

Thanks Jacque for testing it out.

I had yet to try the scripts on Android myself as I was concerned about the poor performance under iOS to start off. But at least this now gives me hope for a cross-platform solution. I can always set the maxWidth and maxHeight of mobilePickPhoto to get optimal performance under iOS, and given your results, then use the resizing script for Android.

As for image quality, I have to confess that my background as a graphic designer and photographer leads me to pay particular attention to these details. Since the resulting photos will eventually be accessible via the web, they will be viewed by both mobile devices and desktop. So optimal image quality can be a factor. But given the performance hit to achieve optimal image quality may not be worth it.

Thanks for your help.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Resizing images - slow performance on device

Post by jacque » Thu Nov 01, 2012 11:33 pm

I probably misunderstood, it sounded like you were looking at an Android fix. But the results should be pretty similar on iOS, I think the lag is in the engine resizing, not the hardware display. I do understand your concerns about quality, I'm working with a client right now who is an audio expert and he feels the same way about sound files. But most people can't tell the difference, to be honest, and usually performance means more to the masses than exact reproductions. You may have to bite the bullet and keep repeating to yourself, "no one else will notice, no one else will notice..." :)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

m1BUSwIgg
Posts: 9
Joined: Wed Jun 20, 2012 4:41 am

Re: Resizing images - slow performance on device

Post by m1BUSwIgg » Fri Nov 02, 2012 10:21 pm

I'm very familiar with that phrase :D

Yes, the performance issues were running either of those 2 resizing script on an iphone 4. It ran them at 15 seconds vs. 1 sec. on your Galaxy Tab. Granted the iphone 4 is not the latest hardware. But it's a baseline I am trying to stick to. As I mentioned, the hardware is perfectly capable of resizing the images in 3.5 - 4 seconds by setting the max size property of mobilePickPhoto. But it can't handle it well using the resizing scripts above.

Since I am looking to also run it on android, I was initially looking for one common script that would work on both. Looks like that won't work and I will have to use different methods for each platform. My minimum specs for Android are much higher, so the results should be comparable to your Galaxy Tab.

Thanks again.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Resizing images - slow performance on device

Post by jacque » Sat Nov 03, 2012 5:19 am

Choosing your first script to test was just arbitrary. I have an iPad 2 here, I can try both methods on that over the weekend if you want. I'll let you know what I find out.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

m1BUSwIgg
Posts: 9
Joined: Wed Jun 20, 2012 4:41 am

Re: Resizing images - slow performance on device

Post by m1BUSwIgg » Sat Nov 03, 2012 6:20 am

Sure. The more beta testing the better. :D

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Resizing images - slow performance on device

Post by jacque » Sun Nov 04, 2012 6:29 pm

Okay, I built the test stack for iPad and did the tests again. iOS is much slower on my iPad 2 than on my Galaxy Tab, but it's still pretty quick. I also did all the tests again on my Android tablet using both your scripts. Results using either method were identical on both devices, so it seems that setting the templateImage size first or resizing the image afterward doesn't matter.

On the iPad 2, "normal" and "good" quality both took about 4-5 seconds. Using "best" quality took about 10 seconds.

I was counting in my head, I didn't use a timer, so it may actually have been a second or two longer. But it didn't seem excessive to me, and for sure wasn't the times you are getting. You want my test stack?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Resizing images - slow performance on device

Post by jacque » Sun Nov 04, 2012 6:36 pm

Actually, here's the stack whether you want it or not. :)
https://dl.dropbox.com/u/23431607/photo ... vecode.zip

I built this with LiveCode 5.5.2 because I haven't downloaded the new XCode yet. I don't know if you are using 5.5.3 or if that matters. You'll need to change the standalone settings to use your own certificates.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

m1BUSwIgg
Posts: 9
Joined: Wed Jun 20, 2012 4:41 am

Re: Resizing images - slow performance on device

Post by m1BUSwIgg » Mon Nov 05, 2012 4:44 pm

That's great. Your results fall pretty much in line with what I was expecting given the hardware difference between the iphone 4 and ipad 2. And I've no doubt that when I test on the iphone 5 it should be pretty similar to your galaxy tab results. I was initially testing with 5.5.2, but then updated to 5.5.3 with no variance in results.

Appreciate you taking the time.

p.s. nice little testing stack :wink:

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Resizing images - slow performance on device

Post by jacque » Mon Nov 05, 2012 7:28 pm

Thanks, glad it was useful. I'm still not sure why you'd get results over a minute, that's awfully long.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Resizing images - slow performance on device

Post by jmburnod » Sun Nov 25, 2012 2:29 pm

Thank for share it.
I tested it in my iPad and it work fast and well for me (I downgraded it to 5.0.2)
I suggest to add a condition to the mk_makeratio function for smaller images

Code: Select all

--For resizing images
function mk_makeratio tW,tH,w,h
   if w < tW and h < tH then
      return w,h
      exit mk_makeratio -- useful or not ?
   end if
   put min (tW/w,tH/h) into tscaleFactor
   return round(w * tscaleFactor) & "," & round(h * tscaleFactor)
end mk_makeratio
https://alternatic.ch

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Resizing images - slow performance on device

Post by Klaus » Sun Nov 25, 2012 2:46 pm

Hi,

yes, a very cool function of mine :D
But no need to "exit whatever", a "return tReturnValue" will immediately leave a function anyway!


Bewt

Klaus

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Resizing images - slow performance on device

Post by jmburnod » Sun Nov 25, 2012 3:47 pm

Hi Klaus,
no need to "exit whatever"
Thanks for this confirmation
Best
Jean-Marc
https://alternatic.ch

abhinav7979
Posts: 5
Joined: Mon Jan 04, 2016 1:10 pm

Re: Resizing images - slow performance on device

Post by abhinav7979 » Wed Jan 06, 2016 2:05 pm

jacque wrote:
https ://dl. dropbox. com/u/23431607/phototest/photoTest. livecode.zip
Hey Jacque,

I'm wondering if you have the code stored somewhere. I'm having the same problem, and it will be very helpful if you could give me the test code.

Post Reply