Thursday, July 30, 2009

Making ADB Work

Let's say you have a shiny new HTC Magic. Being keen to get a look under the hood, you install the android-sdk package on Debian, and try out the adb tool:
root@thorn 35> adb shell
* daemon not running. starting it now *
* daemon started successfully *
error: device not found
Woe! All the stupid pages on the internet talk about fixing this problem by using the right Windows driver (kuh), or by making sure you're root (you're ever not root???), or by putting in some udev file.

None, of those fixed my problem. For me, I had to enable USB debugging on the phone itself. I found this in Settings -> Applications -> Development -> USB debugging. Once I enabled that, I was able to get to the shell prompt on the phone:
root@thorn 57> adb shell
* daemon not running. starting it now *
* daemon started successfully *
$ id
uid=2000(shell) gid=2000(shell)

Tuesday, July 14, 2009

JPEG Rotation: mogrify versus jpegtran

Hello!

Sooo, perhaps you have a large number of jpegs. And perhaps these jpegs need to be rotated. Your initial instinct is to use ImageMagick: god bless mogrify! And indeed, that would work. But at what cost? Specifically, at what cost of time?

Let's say the list of files to be rotated are in files.txt. So, we can rotate them all with:
cat files.txt | while read i; do mogrify -rotate 90 $i ; done
How fast does it go? With about 650 files, I measure this to be:
root@thistle 36> time ( cat files.txt | while read i; do mogrify -rotate 90 $i ; done )

real 0m52.527s
user 1m10.104s
sys 0m6.620s
After some grovelling about, I found jpegtran. How does it perform? I had to modify the commands a bit, since mogrify modifies a file in place but jpegtran produces the output on stdout.

root@thistle 37> time ( cat files.txt | while read i; do jpegtran -rotate 90 $i > $i-rotate ; done )

real 0m12.634s
user 0m8.413s
sys 0m4.036s
So it does it in about 25% of the time. So that's that.

Yes, we could save some time by getting mogrify to modify multiple files at once, saving process start time. But it's not that much a saving:
root@thistle 43> time ( cat files.txt | xargs mogrify -rotate 90 )

real 0m48.517s
user 1m28.310s
sys 0m5.820s

Blog Archive