Batchfile: simple slideshow with custom image order

Last week a friend of mine wanted to have a image slideshow for a presentation TV screen for an exhibition. Besides of a large number of images that should be displayed in order he wanted to display his company logo image every second image, like:

  1. image 1
  2. company image
  3. image 2
  4. company image
  5. image 3
  6. company image

I wanted to do this without writing a program or installing Perl (his laptop is a Windows box) so I did this with a tiny Windows batch file:

@ECHO OFF
setLocal EnableDelayedExpansion

SET count=1
SET IMAGEDIR=%1
SET FILLIMAGE=%2

cd %IMAGEDIR%
FOR %%a IN (*.*) DO ( call :do "%%a" )
GOTO :EOF

:do
SET UQ1=%1
ren %UQ1% "%count%_!UQ1:"=!"
set /a count+=1
copy %FILLIMAGE% "%count%.jpg"
set /a count+=1
GOTO :eof

Given the batchfile slideshow.bat, the directory with a copy of all the source images in C:images and the company logo image in C:companyimage.jpg the call simply is:

slideshow.bat "C:images" "C:companyimage.jpg"

This will rename all the pictures found in C:images with a number in front of the original file name – with one number left out; like 1,3,5,7,etc. The company image is copied in between all these images as 2.jpg, 4.jpg, 6.jpg, etc. Now simply viewing the first image with Windows Picture Viewer and hitting the slideshow button will display the files by name which is exactly the desired display order.

Regarding the batchfile: it would be possible to execute multiple statements within the DO ( … ) but that way the counter variable did not work. I had to do a call to a method which then changes the counter. Another issue was the unquoting of the file name. The “%%a” supplies the image file name with double quotes to the %1 inside the :do function. As the final name should be counter + image-name without unquoting it would look like 1_”my image.jpg” which will do an error. The magick is the !VAR:”=! which unquotes the string in VAR.

Bookmarklet for QR Codes from Android market links

Since the beginning of this month Google has been allowing access to its android app market for non-Android devices via http://market.android.com. Unfortunately when accessing the app pages with a non-android device there’re no QR codes for the apps, so getting the app to the device is pretty cumbersome. I wrote a little bookmarklet to convert the http://market URL into a market:// one and generate a QR code image for that link.

javascript:(function(){var exp = /details?id=([w.]*)/; exp.exec(location.href); window.open('http://qrcode.kaywa.com/img.php?s=8&d=' + encodeURIComponent('market://details?id='+RegExp.$1), '_blank');})()

Just Drag&Drop this linked image:

AndroidScanner1

to your bookmarks bar and click on it when you’re on a android app page:

draganddropbookmarklet2[1]

Favorite Android Apps

For half a year my job has been getting me in “touch” 🙂 with Apple devices: an iPad 3G+WLAN and a new iPod touch. Most of the time we use these devices for testing our mobile websites and to find out how the rest of the mobile world does it. As I’m not that in favour of spending so much money for an Apple phone I ordered a startup Android 2.1 phone some time ago. The actual Huawei-manufactured Vodafone 845 comes with a pretty small resistive 320×240 pixel display – but: hey, it came only 100€!

After trying many many apps the following list is an overview of my favorite ones. I might add a list pretty useful iOS apps in another article together with Benjamin in the next days.


Games

123 Maze Lite

Maze game which get’s quite tricky in the later levels.

http://market.android.com/details?id=maze.game

Scumm VM (alpha)

The scumm VM is a virtual machine for the best adventure games ever – created some years ago by Lucas Arts. Till now I could only find a very early ported version for android but following the instructions in the website at: http://sites.google.com/site/scummvmandroid/ I got the manually installed apk running. You’ll need some files from the scumm VM project (datafiles) – just stick to their FAQ and it should work.

You can get some of the old games from abandonware games website on the web or just copy the data from your 3.5″ floopy disks :-). I successfully played Monkey Island 1 + 2, Zak McKraken, Sam & Max and Day Of the Tentacle (though the sound is sometimes cracking).

X Construction Lite

Like the bridge builder and Pontifex games in X Construction you have to compose stable bridges for a train using metal segments.

http://market.android.com/details?id=de.hms.xconstruction

Traffic Jam Free

Rushhour is a puzzle game where you have to move cars out of the way so a yellow can drive to the exit. Thousands of levels and you can set the difficulty in various steps.

http://market.android.com/details?id=com.jiuzhangtech.rushhour

Labyrinth Lite

The kids just love it, though the lite version does not come with many levels.

http://market.android.com/details?id=se.illusionlabs.labyrinth.lite

Andoku

Yet another Sudoku game with many variations and thousands of levels.

http://market.android.com/details?id=com.googlecode.andoku

Android Invasion

Space invaders clone.

http://market.android.com/details?id=com.invadersgame

Chess for Android

You can set the CPU strength which gives even my bad chess skills a chance to win.

http://market.android.com/details?id=com.google.android.chess

Droid Balance Lite

Fun with the position sensor of the phone. By turning the phone left and right you have to get rid of red shapes while preventing the blue ones from falling down.

http://market.android.com/details?id=com.DroidBalanceLite

Gensoid Lite

Gensoid is an emulator for good old SEGA games, such as Sonic the Hedgehog or Street Figther.

http://market.android.com/details?id=com.androidemu.genslite

Math Attack & Math Workout

Two “brain-train” math games.

http://market.android.com/details?id=com.chilisapps.android.mathAttack

http://market.android.com/details?id=com.akbur.mathsworkout

National Flags Quiz

Either you have to chose the correct country name according to a shown flag or the other way around. I knew suprisingly few of them …

http://market.android.com/details?id=net.fractalgate.android.nationalflags

Save Newton Lite

Using arrows shot by a bow you have to save Newton from apples falling from the tree.

http://market.android.com/details?id=ml.game.android.SaveNewton.lite

Sea Fight

Classic sea fight game. Just place your ships wise and try to nuke the CPU one’s.

http://market.android.com/details?id=com.ztech.seafight


Tools & spare time

c:geo

All-you-need for geocaching. Just connected my geocaching.com account and turned on GPS and it worked like a charm. Comes with Google maps overlay, GPS compass, detailed cache information with riddles, coordinates and user hints. You can store geocache information for later use – e.g. if there’s no network in the woods.

http://market.android.com/details?id=carnero.cgeo

IMDb

Accesses movie information from the internet movie database. Very handy for quicky looking up a movie or what actor did which movie and such.

http://market.android.com/details?id=com.imdb.mobile

Google Sky Map

Ever looked to the night sky and wondered: what’s the name of that bright star? Google sky map can tell you, just point your phone into the direction of the target.Can also guide you to find a specific galaxy or star.

http://market.android.com/details?id=com.google.android.stardroid

DailyStrip

Displays comic strips which you can chose from a large list. I’m much in favour of XKCD, Dilbert and Peanuts.

http://market.android.com/details?id=com.fusetree.android.dailyStrip

fring

Instant message client for Gtalk, msn, icq or yahoo. Can also do video calls. I’ve been using it for ICQ chatting sometimes.

http://market.android.com/details?id=com.fring

barcoo

Given a scanned barcode of a grocery item you can look up it’s caloric values or where to get it with best price.

http://market.android.com/details?id=de.barcoo.android

Mileage

Small app for tracking fuel consumption and gas station prices.

http://market.android.com/details?id=com.evancharlton.mileage


By the way: I used the QR Code generator by Jason Delport of Paxmodept to create the QR codes. You can get market links and package names of android apps using androlib.com and – as of today, I believe – you can visit the market links using any browser as google opened the market for the web.

JavaScript Timer and Stack Trace Debugging

Today I had to work on a webpage with a large amount of JavaScript timers running and I had to find a bug which one of them caused. Unfortunatly the timeline in the Google Chrome developer tools only showed the order of the timer execution together with the timer ID. That IDs are created by each JavaScript setInterval() and setTimeout call. But just the ID doesn’t help much. So I rewrote the prototype of both the setTimeout and setInterval functions:


window._oldTimeOut = window.setTimeout;
window.setTimeout = function(execute, timeout) {
	var id = window._oldTimeOut(execute, timeout);
	console.debug("created timer with id:", id, arguments.callee.caller.toString());
	console.debug('execute',execute.toString());
	return id;
};

window._oldInterval = window.setInterval;
window.setInterval = function(execute, timeout) {
	var id = window._oldInterval(execute, timeout);
	console.debug("created interval with id:", id, arguments.callee.caller.toString());
	console.debug('execute',execute.toString());
	return id;
};

This gave me at least a hint where the sourcecode lines of the timer-executed code can be found. Also very helpful is a stack trace (aka call stack) at the current code position to find out which other function was calling the current one. I found a pretty old but still working code snippet on http://helephant.com/2007/05/diy-javascript-stack-trace/ and added it to my timer debugging:


Function.prototype.trace = function() {
	var trace = [];
	var current = this;
	while(current) {
		trace.push(current.signature());
		current = current.caller;
	}
	return trace;
};

Function.prototype.signature = function() {
	var signature = {
		name: this.getName(),
		params: [],
		toString: function() {
			var params = this.params.length > 0 ? "'" + this.params.join("', '") + "'" : "";
			return this.name + "(" + params + ")";
		}
	};
	if(this.arguments) {
		for(var x=0; x<this.arguments.length; x++)
			signature.params.push(this.arguments[x]);
	}
	return signature;
};

Function.prototype.getName = function() {
	if(this.name)
		return this.name;
	var definition = this.toString().split("n")[0];
	var exp = /^function ([^s(]+).+/;
		if(exp.test(definition))
			return definition.split("n")[0].replace(exp, "$1") || "anonymous";
		return "anonymous";
	};

	window._oldTimeOut = window.setTimeout;
	window.setTimeout = function(execute, timeout) {
		var id = window._oldTimeOut(execute, timeout);
		console.debug("created timer with id:", id);
		console.debug('execute',execute.toString());
		console.debug("stacktrace", arguments.callee.trace());
		return id;
	};

	window._oldInterval = window.setInterval;
	window.setInterval = function(execute, timeout) {
		var id = window._oldInterval(execute, timeout);
		console.debug("created interval with id:", id);
		console.debug('execute',execute.toString());
		console.debug("stacktrace", arguments.callee.trace());
		return id;
	};
};

Be sure to add that script tag at the very top of your JavaScript execution (as the first element of your <head> tag for example).

Find UTF-8 byte order marks

In a templating application I just ran into ugly “” characters a the beginning of the text. This is caused by the byte order mark with the hex characters 0xEFBBBF. As it was not the only one file that contained the BOM I ran a search:

find . -iname '*.css' -o -iname '*.html' -o -iname '*.js' -o -iname '*.pm' -o -iname '*.pl' -o -iname '*.xml' | xargs grep -rl $'xEFxBBxBF'

To remove the BOM I followed the suggested way by http://stackoverflow.com/questions/204765/elegant-way-to-search-for-utf-8-files-with-bom using sed:

find . -iname '*.css' -o -iname '*.html' -o -iname '*.js' -o -iname '*.pm' -o -iname '*.pl' -o -iname '*.xml' -exec sed 's/^xEFxBBxBF//' -i.bak {} ; -exec rm {}.bak ;

Tada, no more ugly BOMs!

Optimize all PNG images recursively

Windows batch file syntax sometimes is a pain compared to UNIX bash/sh. Using optipng I wanted to shrink all the PNG images in a directory and inside its subdirectories as well. Notice that I had to write the command into a .bat batch file, it did not work directly from the command line:

FOR /F "tokens=*" %%G IN ('dir /s /b *.png') DO optipng -nc -nb -o7 -full %%G

The optipng params -nc and -nb prevent any color and color depth changes of the png files. Those may change the appearance, for example in the evil Internet Explorer. -o7 means the best and slowest optimization and -full does a full scan of the IDAT part. Using UNIX the same job may look like:

find . -name *.png | xargs optipng -nc -nb -o7 -full

HDR Panorama Tutorial

Stitching panorama pictures from a series of taken photos is simple, besides of buyable software like Panorama Studio or Autopano there’re even free alternatives like Microsoft ICE. But what if you have three series of pictures for the panorama – each serial taken with a different exposure time? With single images it’s easy to merge the images into an HDR image by using Photoshop or Photomatix for example. But combining both techniques into a HDR panorama is a little tricky, hence I wrote this tutorial with a solution that worked for me.

Autopano Giga and HDRs

The “Giga” version of Autopano supports working with multiple exposure series. So my first idea is to just apply the Autopano workflow to all the pictures that will belong to the panorama. There’re 12 pictures in my case and Autopano automatically sorts them into 4 panorama parts (4 views á 3 different exposure times).

Now I just apply the detection and change to the editing mode of the resulting panorama. There I choose not to apply any color correction (I want to tone map the HDR later anyway) plus I crop the borders. Notice the layer setting to output only one blended layer.

Now I just render the panorama with one target .hdr file.

So far so good. Next I open the hdr file I just created in Photomatix to do some tone mapping, but what’s this?

Seems like this does not work the way I want to. There’re many ugly blending errors and the light spots are all overspilled!

The workaround

Ok, back to Autopano’s edit panorama mode. In the layer section I now chose “Group by speed” as I want to get a separate panorama image for each exposure serial, but with exactly the same panorama stitching (the three panoramas have to match each other exactly, otherwise the later HDR generation in Photomatix would screw up the .hdr entirely).

Now again I render the panorama but not targeting one .hdr file. Instead I choose the 8Bits TIFF format. To get one TIFF per exposure serial I have to add a “%L” to the file name for the layer name.

Great, after exporting I get three TIFF images with the stitched panorama for each exposure serial.

HDR generation & tone mapping

The next step is as simple as I is with non-panoramic pictures. I just create a new panorama in Photomatix and deactivate the alignment tool (the panorama, taken using a tripod, is already aligned) and activate the ghost reduction for objects and people (this happens quite often with exposures lower than 5 seconds). Really important is to activate the noise reduction – otherwise the hdr will look like a Christmas tree. Finally, after applying the tone mapping and doing some little fixes in GIMP (sharpen, denoise, contrast), it’s a nice HDR panorama.

markt_tonemapped