Saturday, December 03, 2011

Reason for homogeneous (4D) coordinates in computer graphics

Homogeneous coordinates are used computer graphics - you can read this statement in every 3D computer graphics related book or article. If you ever asked yourself why this is the case, then you are at the right place...
The reason for this is to handle rotation, scaling and translation in a common way. While you can handle rotation and scaling using 3x3 matrices and vectors with 3 components, translation cannot be processed - unfortunately this is normally not further explained although it is quite easy to see:
Suppose we have a point p with coordinate (x, y, z) and we want to translate it by a distance defined by the translation vector t=(tx, ty, tz).
Of course, what you need to do to get new position p' of point p after translation is to add t to p:
p' = p + t, which means
p'.x = p.x + tx
p'.y = p.y + ty
p'.z = p.z + tz
If you try to create a 3x3 matrix M to perform this operation by p' = M * p, you get into trouble. What we require is:

x'   x + tx   |a b c|   |x|
y' = y + ty = |d e f| * |y|
z'   z + tz   |g h i|   |z|

x + tx = ax + by + cz (1)
y + ty = dx + ey + fz
z + tz = gx + hy + iz

Looking at equation (1) we directly see that a = 1 and we are left with tx = by + cz. But the translation in x-direction must be indepent of y and z coordinates, so b and c must be zero.

x + tx = 1*x + 0*y + c*z = x   => tx = 0
So only the primitive translation by zero is possible. The same applies for the equations for y and z.

Using homogeneous coordinates, that is to add a forth component w = 1 to each point, we can derive a 4x4 matrix for translation without any problems.


x + tx   |a b c d|   |x|
y + ty = |e f g h| * |y|
z + tz   |i j k l|   |z|
1        |m n o p|   |1|

we get e.g. for x-coordinate:

x + tx = ax + by + cz + d, 
so a = 1 and d = tx which leads us to the final translation matrix:

    |1 0 0 tx|
M = |0 1 0 ty|
    |0 0 1 tz|
    |0 0 0 1 |

That's it :-)




Sunday, January 09, 2011

Browsing old reversing sites - the good old times

I just browsed through an old backup folder called "Reversing favourites" ... man this contains really OLD urls of reversing sites: groups, tutorials and so on!
Of course, I clicked several of them, full of hope, just to get disappointed that ca. 90% of the urls do not exist anymore. But some of the linked site still exist, but of course not updated for several years - just lying dead on some server.
I engrossed the thoughts what really cool sites existed at that time, now approximately 10 years ago. Here are some that are still online but out-of-date - maybe some of you want also fall in some nostalgy.
So here are my three top sites that are still online available:

  • Immortal Descendants - this is one of my all-time favourite reversing sites. The tutorials and the code snippets were outstanding at that time, at least for me. I linked a working archived version of the site, the original URL was http://www.immortaldescendants.org.
  • BIW Reversing - not that old but still no update in the last two years
  • Crackstore - one of the first reversing sites I have ever visited
Let's see, next time I post the URLS of the top site of nowadays... stay tuned!

Friday, September 24, 2010

Injecting a dll to explorer.exe under windows 7 - FAILED

Today I tried to get an old self-coded tool to work under windows 7 64bit... I'm talking about my Desktop Symbol Utility I coded for and under windows XP.
In fact, I really do not require it because I managed to deactivate the dropshadow of the icon texts on the desktop while keeping the transpareny under windows 7 - without the help of an external tool! :-) Wow, finally Microsoft got it working... after how many years?

Howsoever, I found this tool accidentally again on my harddrive while searching for something else and tried to run it under my windows 7. As I had already expected, injecting the dll into explorer process did not work. So I extracted the code and had a look into it. I expected some typical error as it was programmed under a 32bit system and maybe the is some incompatible/wrong use of data types? Well, unfortunately not. It turned out that the CreateRemoteThread() call failed. My first assumption that the way the process ID is obtained is no longer valid under win7 was wrong - a simple compare with the PID in Process Explorer showed it. Also the other functions (VirtualAlloc etc.) succeeded.
Maybe it something to do with protected processes? (-> Link to article from Microsoft).
Well, I don't know... so if there is someone out there who got this tool working under Win7-64, please drop me some lines how you managed it - would be really great!

Thursday, April 22, 2010

Fading windows in and out

Well, finally a new (though short) post :-)

For personal needs, I coded the functionality to fade in a window when my application starts and fade it smoothly out when the user quits the application. So below you can download the result - just add the fade.h and fade.cpp to your project, call InitFadeEngine() to initialize the fade engine with your window and then simply use FadeIn() or FadeOut() function. Have a look in the header file to get information about the required parameters and I also suggest to look at the source of the demo application that is also in the archive below - there you see how to use it. It's coded in plain C using the WinAPI function SetLayeredWindowAttributes() that is called repeatedly in its own thread. Have fun!

Friday, September 18, 2009

So what kind of interesting things happened the last weeks?
So first of all, I am very proud to announce to I received the FZI (Forschungszentrum für Informatik) Prize for the best diploma thesis in computer science at the University of Karlsruhe in the Year 08/09 for my diploma thesis "Development of a Power-Aware Rate Controller for the H.264 Video Encoder". There were more than 160 graduates in this year- so I think my work is really not that bad ;-) And it was endowed with 1000€ *g*.
Here a (unfortunately bad-quality) picture of this day:


Apart from that, life runs its normal way. I have just too less time for private coding - or I'm just too lazy. But I pulled myself together and I dived into JavaFX.

What the hell is JavaFx you aks yourself? Answer: It's a product family (let's say some kind of enhancement of Java) made by Sun Microsystems. Its main purpose is to help developers to produce easier and faster Rich Internet Applications (RIAs) with media and content across a wide variety of platforms and devices.

There some tutorials in the net but I suggest a book like "Essential JavaFx" or "Pro JavaFX Platform". If you are a Java coder (maybe just as hobby like me) and you wish an better way to design cooler Java applets, then go for JavaFX. Download the newest (really cool but god-damn sluggish) NetBeans Environment including the JavaFX plugins/SDK and have a look.
But don't be shocked - it differs heavily from plain Java - it's some kind of mixture of Java and a script language. You specify the layout hierarchical as a tree of nodes, but you can have also classes and even access classes written in plain Java. But is has some really cool featurs like binding, Animations and Effects.
For my personal learning purposes, I am (still) coding a little applet for calculting the resistance of a physical resistor which I will release soon on my homepage with sources - so stay tuned!
Here a screenshot:

Saturday, August 01, 2009

Am I a stupid user?

Sometimes I wonder if I am to stupid to use some tools or if the GUI is not like that as it should be. I am using Visual Studio 2005 now for several years and some weeks ago I tried to change the height of the client area of a normal combobox inside resourse editor. The reason was that I added around 20 text items from code and wanted them to be visible all at the same time in the dropdown list. Well in the Properties Window there is no such attribute to set and when I clicked the combobox it looks like this:

But it was only possible to change the width of the combox (blue spots) and not the height (white spots)! I just thought "Oh man what's going on... this cannot be true - I am going nuts!".
My first idea was to change the height from source code using MoveWindow etc. - but in total this required more than 5 lines of code (with variable declaration and nice layout) just to change the height of a dropdown list of a combobox...?! This is not that developer-friendly as I expected it...

Or was I just too stupid to use resourse editor - of course this was the case. But I found the solution only accidently. Instead of clicking directly on the combobox item, I clicked directly on the small button with the arrow downwards at the right side of the textbox, and suddenly it looked like that:

Now it was possible... that easy!
Although I feel some kind ashamed to waste so much time for such a trivial problem, I thought posting my lousy problem may help also some other 'stupid user' facing the same 'challenge' ;-)

Thursday, May 21, 2009

Hi, my name is Felix...

One day when I came home from work, I heard a cat crying miserably. It sound to be very near when I went on the balcony, but the cat's location was not detectable. So we started searching on the attic, in the garden, we even replaced tiles from the roof as we thought the cat is maybe stucked under the roof. Finally we found him - stucked in the drainpipe of the cullis! Most probably he went over the cullis and fell into the hole where the drainpipe starts towards the ground and as the pipe is quite thin the cat pinned inside the pipe. So we dismantled the drainpipe in order to rescue the undercooled, wet, afraid cat. I suggest he was only 4 weeks old and no mother or brothers/sisters were in sight, so we decided to keep him :-) Say hello to my new lodger:

Tuesday, April 28, 2009

Modifying the S100

Hey out there,

I just bought a T-Online Vision S100. That's a media settop box for streaming movies over the internet directly to the TV. As the service was discontinued here in Germany, many of them are sold @ ebay for around 40€. Here are two pictures:
As you can see, it's quite stylish and gives enough possibilities to 'pimp' it. Some technical facts: Intel Celeron 733Mhz, 128MB Ram, Intel 830M for Graphics, USB, LAN, WLAN, Audio Analog/Digital, SVideo, Scart and also an infrared remote control. As there is no fan, it's runs completely silent.
So it's a perfect target to modify it to a personal mediabox, for watching movies, listen to music, surfing in the net or playing old games, all via TV. There are many fansites and tutorials about modding the S100, just use google.

The first thing I did is to tinker a custom cable for enabling the VGA output on the motherboard, similar to this one (picture is from here):


Attaching a monitor enables you to enter the Bios and disable booting Windows CE from the flash memory. You can either boot from usb or embed a harddisk (preferably a 2,5" notebook harddisk as they are more silent and require less power). I am going to choose the second option but therefore I have to modify the power supply and braze additional connectors. After that, an OS and some cool tools are installed, an LED for harddisk usage will be inserted and maybe the LED frontpanel will be removed, but let's see...

Here is picture of my home activity area:

Sunday, April 19, 2009

What's currently going on..

So folks,

I had last week off as my company has closed for four days due to the financial/economical situation. I used this 'forced spare time' to go on holiday - I went with my girlfriend to Vienna, Austria for some days. This was really nice - it's a really cool city with many, many places worth to visit, so we were the whole day on the move. Additionally we had awesome weather - look at this:

What else I have done in my spare time? Well, I must admit I began to play a video game which I came across in the net. It's a quite old one (dos game) which I own for about ten years but never fetched again from my rack because of lack of time and motivation. Then I saw the screenshots on the net and read that is has been drastically improved by hobby programmers which reversed the whole game and made it open source. Moreover it's now running under Windows (also under linux and mac, just for information!), I tried it again and nearly became addicted again. I'm talking about Transport Tycoon, more precisely Open Transport Tycoon - go and check it out (but you need the game data files from the original game). Here a screenshot:

What's about coding, reversing and your homepage you ask? Damn, a good question. Of course, it's not dead. I have just only little time... But I read about many topics I am interested in and some really cool ideas for projects in my head but everything is taking much time so new coding activities just progress slowly.
But I do my best :-) Let's see...

Thursday, February 26, 2009

Some personal news

So folks,

finally a new post :-) Just to tell that I'm still there and some things have changed in my life...
I have successfully completed my study at University of Karlsruhe and received my diploma in computer science. My diploma thesis about H.264 video coding finished very well and I'm quite proud of it, likewise my mentor and professor so I expect a very good grade :-)
After this, I moved away from Karlsruhe and now live together with my girlfriend in our own flat. That's why I had no internet access for more than one month and was not able to update my blog. Since beginning of February, I am working as a software engineer at Robert Bosch Gmbh in the sector of automotive control units, more precisely called DCU (Domain Control Unit). Everything is quite new so I am excited how things will go on - hopefully fine and successfully.
But yeah, only less time is available for spare time compared to be a student, so I have nearly no time for my personal coding and my website ;-( But no fear, this will change and I will somewhen resume to please the world with my code snippets ;-)
So then, stay tuned!

Thursday, October 30, 2008

Accessing Webcam & pre-process frame

One evening I asked myself how to access my laptop webcam (a noname 1.3MP cam integrated into my HP Pavillon dv6XXX) by code. As I faced a little problem with this, I want to share my experience with you.

A look at msdn/internet revealed the Windows Capture Functions, all starting with the prefix cap. Creating the capture window, connecting to the driver, scaling, enabling preview - all very easy as these are just simple function calls. Cause I wanted to preprocess the frame (in order to implement some algorithms to make nice effects - which is not done yet and will take some more time...) I engaged a frame callback function without problem.

But then a little obstacle occured: how is the frame data stored? Using capGetVideoFormat, I accessed the bitmapinfoheader structure and checked the biBitCount member - 16 Bits. Ok - nice - and started coding immediuately which turned out to be a mistake!
The color members were not stored as specified in the msdn library: least significant five bits blue, followed by five bits each for green and red and the most significant bit is unused.

At first I thought I introduced a bug on my bit operations to extract these bits - but no, works perfectly.

Ok, no big deal - as I wished the data to be 24bit RGB, I wanted to use capSetVideoFormat to change the captued video data to this format. But of course this solution would have been too easy - this function always returned FALSE meaning my webcam driver does not like another format :-(

So what was the problem?
While tracing the program I saw the bitmapheader structure values in the debugging window inside visual studio and the biCompression member caught my eyes: 844715353. Hm such a value is not predefined as e.g. BI_RGB etc. I converted this number to hex = 0x32595559 and searched the internet to find out that this is the fourcc of YUY2! Another search brought my to the great website FourCC.org where this format (and many others) is explained:
a simple 4:2:2 YUV format with byte order Y1 U Y2 V. With this info it's of course easy to preprocess each frame of my webcam as I want.
Of course a better BitmapInfoHeader Page at msdn would have saved me a lot of time... Although interestingly a few days later I found this page at msdn where I found exactly my required information - but just too late.

I hope this will help someone facing the same problem while accessing a webcam!

Wednesday, September 17, 2008

A bug hard to find...

During the last evenings, I have been coding a little tool to convert Avi files to 4:2:0 Yuv files. I just wanted it to have more videos to test with my H.264 encoder I work with in my diploma thesis. Well, it was no big deal programming it, just diving into the Video for Windows Api on MSDN to get familar with its interface so it didn't take long till I finished it. It's a console application and I always tested inside Visual Studio, passing the commandline parameters in the project settings. So everything worked fine till I tested it inside a cmd window outside Visual Studio. The converting loop was successful but it freezed after printing "Done!". Looking at the code I was surprised cause that printf("Done!\n") is the very last command!
That's the pseudocode:

for all frames
   pData = (BYTE*)AVIStreamGetFrame(pFrame, i-1);
   CreateYuvfromFrame(pData);
CloseAviFunctions();
printf("Done\n");
return;

Inside Visual Studio, I found at first no hint what was wrong, even tracing it showed no problem. Than I noticed that it does not freeze when the for-loop is not entered. Again reading in msdn, more specific AviStreamGetFrame, I read following:

Remarks:

The returned frame is valid only until the next call to this function or the AVIStreamGetFrameClose function.

Then I suddenly noticed, I called every necessary Avi-release and Avi-close function except the AviStreamGetFrameClose one. Inserting it just before my program ends and the bug was gone... and I was happy!

So what we learn from this: when using the Video for Windows Api, make sure to call the corresponding close-function for every Avifunction you use, although MSDN does not explicitly state that you have to before your program finishes!

But the open question remains: how to find this bug in a structured straightforward way? Normal debugging did not help and I was not willing the spend all my time to debug internal system calls within Ollydbg.
So if you know a way or you have just a suggestion, feel free to tell it me!


Friday, September 05, 2008

Still there

Hi,
currently I'm very busy with my diploma thesis - I just finished a big part concerning mode decision inside the encoder, now I have to implement some algortihms in VHDL and after that I will start with the actual Rate Controller. Things are getting more complicated and I also have to read some papers and books to build a mathematical theoretical background for my model. Well, nearly half of the time is already gone, so only 3 months left = stress.
That's why there is also no real update on my website. Ok I improved my layout as you can see which took already some time - did I ever mentioned that I'm no friend of html/css/all other web scripting languages - they just look ugly compared to a real programming language!
But I have already two cool tools coded concerning planar 4:2:0 yuv-files which just need some commenting and bugfixing before going to be available on my site - so stay tuned.

(Caution: Advertisment) I came across two cool free downloads - maybe you are also interested:
First of all, google published their own browser chrome for free download. My first impression is pretty positive - it's fast, small and easy to use - most of the screen is used for the displayed website, there is no over-blown gui with thousands of menus and statusbars. I like it but I stick to my lovely firefox - I am used to it and the bookmark bar is better and more comfortable to use in my opinion. But you should give chrome a try!
Second, after releasing Command & Conquer 1 as freeware, C&C - Red Alert is now also freely available as download. It's even better than part 1, in fact it is my all-time favourite realtime strategy game ever. I loved it. So go and download the iso images and start playing. For playing it under Windows XP/Vista, choose compatibility mode 'Windows 95' for both, the setup exe file and game exe file, and install also the provided patch - then you have no trouble.

Thursday, July 03, 2008

Online Calculator and Autocompletion

Finally my online calculator is published here: Online Calculator.
I was tired of using Windows Calculator for evaluating terms when I forget my hand calculator at home. And using other numeric bases like hexadecimal were not possible but I needed this functionality quite often. So I decided to code my own expression evaluator as a java applet and to put it on my homepage. Not bad, isn't it? Perhaps you find it also useful ;-)
It took quite some time at the beginning to get a working little parser engine. At first I wanted to do it the 'right way' -to build a complete parser tree in memory but very soon I noticed that this is too much for this little applet and also too time-consuming/complex to code. So I came up with a really simple but good working recursive parser. Then most of the work was already finished - just my ownerdraw resultlist took me some research on the internet to paint the listitems myself.
Originally I wanted also to implement an 'intellisense-like' autocompletion functionality for the textfield where you enter the term. But it turned out to be more difficult that I expect so I delayed it cause my online calculator has till now less than 15 commands so it's more fun than really necessary. But today I continued the fight and got it working - my main idea was not to extend a frame but just a JPopupMenu with some nice 'keylistener-action'. Till now it's not ownerdrawn and I don't know if I should really insert it into my online calculator. Let's see... but first here a little animation that it really works :-)

Thursday, June 26, 2008

Command & Conquer 1 for free!

Hi folks,

in a phase of nostalgia I viewed some videos on youtube of old pc-games I played when I was younger - and the first Command & Conquer part Tiberian Dawn was one of my favourite. Of course the dos version with just 320x200 pixels ;-) But it was the perfect real-time strategy game in those days. But I think everybody knows it so why talking much about it - you can play it now for free. In 2006 it was re-released in the 'The first decade' compilation pack - even the SVGA windows version including a patch to work under XP/Vista. Then in September 2007, EA released these iso images for free downloading on their servers. So what are you waiting for - go and get it!

Wednesday, June 18, 2008

Firefox 3 is out!

The final reason of Firefox 3 is out and waiting to be downloaded. I have just installed it and I'm fully happy with it. Looks better, seems to be even more stable than version 2 and alone the new "AwesomeBar" makes it worth to get it. Since Firefox 0.8 it's the only browser I use and I'm really a fan of this (in my opinion) best existing browser. It has also broken a world record by being downloaded more than 7 million times in the first 24 hours!

Download Firefox
Firefox Worldrecord

Wednesday, June 11, 2008

Diploma Thesis

That's just a quick post to tell what I'm doing now. I found finally an interesting diploma thesis at which I have been working for the last two weeks already. It's official title is "Development of a Power-Aware Rate Controller for H.264 Video Encoder" and it's located at the Chair for Embedded Systems at University Karlsruhe. My mentor seems to be really nice and to be motivated to help me completing my work successfully. I have 6 months to finish it and hopefully this length of time is enough. I was surprised how complex this H.264 Encoding Standard is and how many complicated steps needs to be accomplished to encode a video with good quality and less need for memory. I have read two complete books and several papers during the last weeks and also dived in the C Code of the standard implementation of this encoder but understanding the rate controller process/steps seems to be really hard. I think this will last but let's see...
The good thing is that when I come home I can watch football the whole evening :-) Or I go to a place with public viewing when the German football team plays. The European Soccer Championship is really exciting and I'm curious what will happen... :-)

Saturday, April 26, 2008

Last oral exam done!

Hi everybody,
after 8 weeks of learning and diving into the secrets of nets, pointclouds, bezier and bspline curves, triangulations, many graphical algorithms and much more, I had yesterday my last oral exam - in computer graphics. It went perfectly :-) Fortunately I was very well prepared. My study thesis is also finished so I'm looking currently for an interesting diploma thesis. But now I make holidays for two weeks - very nice cause the summer slowly begins now here in Germany and the weather is great!
So perhaps I'll find some time for coding - have already two things in mind that I'm wanna code, but let's see.
Well, over the last years my interest in computer games constantly decreased. But when I played something (very seldom) then it was of course Trackmania Nations. I did already mentioned it on my site when this game was released two years ago - completely for free! It an really nice, good looking, challanging racing game which you can also play over the net against others. And now, finally, the next part was released - Trackmania Nations Forever - again for free! So if you like racing games, be sure to check it out! Best thing is to check out following very good site - there you find everything you need:
http://tmnforever.tm-exchange.com/

So have fun!
Sunshine

Thursday, March 06, 2008

Maximum subvector problem

So folks,
again a life sign from me. Again I'm busy... Currently I'm writing the paper of my study thesis. This needs more time than I thought but fortunately my monitoring unit works on the fpga. On the side I started to learn for my last oral exam - in computer graphics. That means hard-core diving into bézier and b-spline curves, also in point clouds. That's gonna be difficult and time-consuming.
Nevertheless while surfing, I came across a paper about the so-called maximum subvector problem. I even think that I really had this problem some years ago while coding. Although it's quite simple it's somehow cool to think about solving it. So what it is about?

given : an array[1...n] of (positive and negativ) numeric values
goal: to determine the maximum subvector a[i..j], 1 <= i <= j <= n whose sum of elements is maximum over all subvectors. Well, not that big thing at first - just calculate all possible subvectors and save the maximum one. The straightforward approach could be look like this: MaxSoFar := 0.0
for L := 1 to N do

  for U := L to N do

    Sum := 0.0

    for I := L to U do

      Sum : = Sum + X[I]
      /* Sum now contains the sum of X[L..U] */

      MaxSoFar := max(MaxSoFar, Sum)


This works of course but for even quite small array sizes (e.g. 1000 elements) this lasts quite long. The execution time is proportional to O(n^3)!
This just be motivation enough to search for some better algorithm. Well, after some thinking you might find a O(n^2) algorithm. There is even a divide-and-conquer approach which is in O(nlogn), but it's not that easy to code :-( Ok, nice, they are often hard to implement...
But in fact there is a simple algorithm that works in linear time! Yes, in O(n)! I must admit I had never expected it nor searched for it. And it is so simple!!!
Curious? Ok here it is:

MaxSoFar := 0.0
MaxEndingHere := 0.0
for I := 1 to N do
  MaxEndingHere := max(MaxEndingHere+X[I], 0.0)
  MaxSoFar := max(MaxSoFar, MaxEndingHere)

So if you found this blog entry interesting, then be sure to check out following article, it contains everything I've written here:


Bye

Tuesday, January 29, 2008

Hope dies last

So, January is nearly over and that's just my first post.
As always, much work to do :-( My study thesis does progress quite slowly unfortunately. The problems are pretty resistent against my tries to solve them ;-)
I managed it that my log entries can be sent from the htx-board to main memory. Therefore I use a linux device driver to allocate a buffer in main memory and send its physical (not virtual, that's why a driver is needed) address to the board. So when my associative memory on the board is full, they are written to this buffer and I can read them with my user-level test application. Of course, some little bugs are still there (not surprisingly, isn't it). Write requests are not correctly logged in contrast to read requests and I f***ing don't find the reason. But I still hope that I can finish it in near future.
I'm slightly sad that I have so little time for my website and coding. I had begun to code my own burrows-wheeler-transformation in the last week of december, but just one day wasn't enough to get it working. The reverse transformation is quite difficult to implement it efficiently - the way I learned to do it by hand is not a good way to implement it. Perhaps when this term is over, I have some spare time and enough motivation to complete it.
Till then, keep cool,
greetz Sunshine