Highlighter screen saver

As an experiment on GDI performance I created the Highlighter screen saver. The application model is simple: one thread, one window procedure and a timer.
Final executable is only 9 kilobytes long and the application takes about 20% CPU load on average on my 2GHz Pentium M.

The screen saver generally runs in 32 bit color quality mode and I also successfully launched it in 16 bit color mode.

Still my concern is the code, which draws the entire frame.
I still have a feeling that brightening code could be more optimized.

There are four memory blocks each for its own purpose:

  • ptrPixels contains an image of all window pixels.
  • pOffset contains offset values for the next processing pixels (light shape).
  • pIntensity contains light intensity values for each pixel pointed by pOffset value (light intensity mask).
  • pDifferenceMask contains an image of color differences between most highlighted pixel and most shadowed.

Highlighter screen saver structure

First a pointer to the next processing pixel is calculated.
Then pixel color data is increased appropriately to the light intensity level and a difference mask.
This process is repeated until all pixels pointed by light shape array are processed.

	while(*pOffset){
		iCursor += *pOffset;
		ptrPixels[iCursor] += pDifferenceMask[iCursor] * (*pIntensity);
		pOffset++;
		pIntensity++;
	}

This structure allows me to have the light of different shapes.
Basically the CreateLigthShape routine can set any light shape with any intensity.

GDI seems great at least if I don’t set refresh rate higher than 10 fps.
Otherwise some flickering can occur but I believe that’s all only by BitBlt.

Here is the screen shot of this application:

Highlighter v 1.0 screen shot

I am going to experiment a little further with this code.

Leave a Reply