27 Nov

Viewer2 Build 3982

  • Updated to the latest version of libiptc, this fixes IPTC compatibility problems with Picasa and other software with faulty IPTC support (Picasa would sometimes skip IPTC data completely even if it was valid). Yes, you heard that Google fanboys.
  • IPTC data editing. Select images and press F9 (I didn’t have the time to draw an icon). Contact me if you need more fields in the editing dialog, I have no idea which fields are used the most.
  • You can enable IPTC keyword synchronizing in the configuration. This will modify the IPTC keywords every time you add or remove a tag for an image. This is experimental but seems to work OK.
22 Nov

Viewer2 Build 3900

  • Now includes a configuration tweaking tool. Some options are not as exposed as the more common ones, changing them is somewhat similar to using regedit. See the shortcut in Start menu.
  • You can now tell Viewer2 not to stretch or shrink images to fit on screen.
  • When viewing images, the next and previous images are preloaded for instant switch.
  • Browsing directories is now quite usable, directories are shown with a yellow border around a preview of the first image in that directory (or a directory icon if no images are found). Use the config tool to enable this.
17 Nov

Viewer2 Build 3782

Here’s the new Viewer2 version:

  • More information in the hover info box.
  • Zooming in now also moves towards the mouse cursor. Set the option NavigateWhileZooming to zero if you don’t like this.
  • You can enlarge the areas that open the menu and the tag and file lists with HotSpotSize. A value of 16 would make the zone extend 16 pixels. This is useful if you have multiple screens that makes the mouse not stop on the edge of the screen. The default is 1 which means the zone effectively is just the edge of the screen.
  • When the mouse hovers over the two hot zones for the lists, an arrow clue appears to indicate the user can click there.
  • Made the toolbar icons a bit more visible with darker shadows.
  • The toolbar menu now has an icon for moving up to the parent directory.

Also in the news: German online magazine Netzwelt has a nice Viewer2 review up. Viewer2 was previously featured as the freeware application of the week and seems they still like it.

The review says only JPEG files are supported, it doesn’t mean the PNG support from the last version has been removed. :) Also, since the review mentioned they liked the spiral type ordering of images, I reiterate it is still there. See the FAQ for info how to enable the spiral.

11 Nov

Compare text files in SQL

Here’s a quick hack that allows loading text files as tables in a sqlite database. Why? It’s pretty nice to compare files in SQL.

txtsql can be run as follows: txtsql.exe file.txt file2.txt ...

Every text file is loaded as a table with two columns: row (line number) and data (the actual text). When saved with save and the first column is named row, it will be skipped. Thus, every loaded table and ever table created with new will be saved as a normal text file. Any other table will be saved with tab characters separating the cells.

The program is just a test to see if this is a viable concept (post a comment if you think it is). If it seems to be something to develop further, I’ll add something like transparent loading and saving of text files as tables when they are invoked (now you have to load them with the load command), common text operations (fuzzy searching etc.) and such.

Examples

Count lines:

load `file.txt`
select count(*) from `file.txt`

Save unique lines in a new file:

load `file.txt`
new `uniq.txt`
insert into `uniq.txt` (data) select distinct data from `file.txt`
save `uniq.txt`

Find similar lines:

load `1.txt`
load `2.txt`
select data from `1.txt` where data in (select data from `2.txt`)

txtsql.zip – Binaries (Win32) and source code

07 Nov

What exactly does GCC optimize?

All compilers optimize code to some extent, some better than others. However, at least to me a great amount of the nature of the optimizations is unclear, outside the explicitly stated loop unrolling and like. Let’s find out which kind of programmer laziness and/or stupidity gets eliminated.

Setup

I used GCC 4.2.2 (MinGW) to compile the test program. The following options produce an assembly source of the compiled binary juxtaposed to the C source:

gcc -c -Wa,-a,-ad opt.c > opt.lst

The tests mostly check if the compiler realizes a function always returns a certain value (opt1(), opt2()), if a function call can be completely eliminated by looking at the input parameter (opt5()) and so on. While compilers do a good job at saving CPU cycles by using registers to pass parameters instead of the stack and so on, the question here is how they manage with lazy code and if you can trust the compiler to take care of some obvious optimizations and shortcuts.

Tests

Each of the following test case is called by the following line (to ensure the optimizer doesn’t just skip execution etc.):

printf("%d %d %d %d %d %d\n",opt1(),opt2(),opt3(),opt4(),opt5(0),opt5(1));

opt1()
int opt1() {
	return 6+7;	
}

The following of course always returns 13. We assume the compiler should always substitute function calls with the result.

opt2()
int opt2() {
	int x=rand();
	int y=rand();
	return x*y-x*y;   // 1-1=0
}

Always returns a zero. The function call can’t be eliminated because even if we know the result, two calls to rand() are needed. The two substitutions and multiplications can still be omitted.

opt3()
int opt3() {
	int x=rand();
	int y=rand();
	return ((x*y)<10000)?(x):(x*y);	
}

Will the compiler see it doesn’t have to calculate x*y twice?

opt4()
int opt4() {
	if (opt3()) {
		rand();	
	} else {
		rand();	
	}
	
	if (opt2()) {
                // should never get here!
		return opt3(); 
	} else {
		return 5+opt3();	
	}
}

Tests if the compiler leaves out blocks that will never be on the code path (opt2() always returns zero) and if the else-clause yields to same code as the if-clause.

opt5()
int opt5(int x) {
	return x*opt1();	
}

Does the compiler substitute the function call with the result? If x equals to zero, the result will always be zero.

Results

GCC 4.2.2 -O2 GCC 4.2.2 -O3
opt1() Call Result substituted, no call
opt2() Call, no calc, returns zero Result substituted, no call
opt3() Call, remembers x*y Inlined
opt4() Call, forgets opt2() always returns zero, although

if (opt3()) {
  rand();
} else {
  rand();
}

correctly becomes

opt3();
rand();
Inlined, all excess code eliminated
opt5() Call, calls opt1(). No optimizations Inlined, substituted

Analysis

As you can see from the results, -O2 isn’t too smart. Many clear cases such as the one with opt1() go unnoticed. I would assume a typical method that returns the value of a private member also has to be called instead of just accessed directly, so beware (note: I didn’t test g++ but as you know, it simply produces wrapper code for GCC).

-O3 on the other hand is a much better companion to a lazy coder, you can trust it eliminates downright crap code you don’t feel like cleaning manually. With -O3 you pretty much can use inlined functions instead of macros with no penalty (as long as you set the inline limits et cetera).