Monday, December 10, 2007

Missing text in GTK apps like XMMS, audacity and etc.

Today I was explaining how I solved the missing text issue in "World of Padman" installer to my colleagues and they said they are facing the same issue in XMMS. I asked them to change their locale language settings to en_US and it works. I googled for the problem and found lot of people(mostly Indians) suffers because of this locale(e.g. en_IN) problem.

Sunday, December 09, 2007

Problem with internationalized(gettext) application

I was trying to install "Word of Padman" on my laptop which runs Ubuntu Gutsy Gibbon. I downloaded 500+mb of file "worldofpadman.run" and ran it. It verified the package and shows the installation wizard but no text in any of controls in the dialog. I made a post in Ubuntu forum and also mailed World of Padman support people but didn't get any reply. So I started troubleshooting myself. First of all the ".run" is made by makeself and the installation wizard written in gtk and glade. I also found that the installer is using gettext for internationalization. Then I did a strace on the installer and found that its trying to open setup.mo(gettext binary file) for my locale which is "en_IN". Since there is no language file(setup.mo) for my locale it shows all gtk controls without any text.

So I changed my language temporarily(export LANG="en_US") and relaunched the installer. Now everything is fine, all controls shows proper text. I faced the same problem in Tremulous installer so now I am happy I can install Tremulous too.

Monday, November 19, 2007

Area of Circle - pi*r^2

I always wonder how people got the formula pi*r^2 as area of circle. So I launched firefox and started googling about area of circle, there are many pages which explains formula but none of them easy to understand. Finally I end-up with a page which explains the formula with real life example.

Original Source: The real story behind the "Area of a Circle"

My Interpretation:
A circle can be seen as collection of triangles. Unwrap the triangles and we get a strip of triangles. Now fold the triangle strip so that it will form a rectangle. In this rectangle the height is approximately the radius of circle and the length of rectangle is half of the circle's circumference. Now the area of the rectangle is = width x length = r * (pi*r) hence the are of circle is pi*r^2.

Tuesday, April 17, 2007

Image Transition - Fading

Today my friend asked how to do fading image transition effect. I suggested him an algorithm and thought of sharing it here.

The Algorithm:

#define MAX_ALPHA 255
for (int alpha = 0; alpha < (MAX_ALPHA + 1); alpha++)
{
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
P1Ratio = 1 - (alpha / MAX_ALPHA);
P2Ratio = (alpha / MAX_ALPHA);
PF[x][y][R] = (P1[x][y][R] * P1Ratio) + (P2[x][y][R] * P2Ratio)
PF[x][y][G] = (P1[x][y][G] * P1Ratio) + (P2[x][y][G] * P2Ratio)
PF[x][y][B] = (P1[x][y][B] * P1Ratio) + (P2[x][y][B] * P2Ratio)
}
}

DISPLAY PICTURE
}


The transition will be very smooth and also very slow since 'alpha++'. The speed can be achieve by 'alpha += 2' or 'alpha += 10'. The algorithm is limited to same resolution of images. I didn't test this code but hope it will work.

Wednesday, April 11, 2007

Mingw/Dev-C++ binary file operations

I encountered this problem when I was porting a Linux utility program to Windows. The job of the utility is to read a XML file and generate a equivalent binary file. I have written it in Linux few weeks before and it works without any issue. When I ported and run the program everything went fine except the reading part of the utility. The utility suppose to read the generated binary file for verification but it fails. The problem is 'read' function returns '0'(indication of EOF) though it has data to read. I have gone through the code many times and found nothing wrong. Then I goggled and found that any file opening in Windows will be in text mode if unspecified.

This can be solved if I use 'fopen' call("rb" mode) but I use 'open' system call. So I again googled and found that I can include the binmode.o(in Mingw lib directory) object along with my executable and which forces the binary mode file open as default. This can also be done by

#include ...
#undef _fmode
int _fmode = _O_BINARY;
...

Ref: http://www.mingw.org/MinGWiki/index.php/binary