PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

putpixel fast...

the display->buffer.PutPixel(i,t,E_RGBX(250,250,250)); so slow.
Code:
E2DSURFACEINFO sf_inf;
unsigned char* Video_Buffer=display->buffer.Lock(&sf_inf);

for (int i=0;i<100;i++)
for (int t=0;t<100;t++)
//display->buffer.PutPixel(i,t,E_RGBX(250,250,250));
Video_Buffer[i+t*sf_inf.width]=E_RGBX(250,250,250);

display->buffer.Unlock();

The given code works not correctly (draws small 10х10 squares instead of one big 100х100).

How it is possible to draw points quickly?

Thanks.
Hi Relo,

Locking the backbuffer is the fastest way to plot pixels. Make sure to use the xpitch and ypitch members of the E2DSURFACEINFO structure.

For example:

Code:

videobuffer[x * xpitch + y * ypitch] = 0;


When locking the backbuffer be sure to check the pixelformat of the surface, not all devices have the same colordepth.
Thanks. So works. But it is not absolutely correct always plot pixels - blue color, and should be red.
Video_Buffer[х * xpitch + y * ypitch]=E_RGBX(255,0,0);

PixelFormat - 6 ??

How to me to deduce pixels of red color (for an example)?
Hi Relo,

The E_RGBX macro shouldn't be used when plotting pixels directly. Here is a piece of sample code to plot a pixel and handle the several colordepths (assuming the red, green and blue values go from 0 to 255):

Code:

switch(pixelformat)
{
case EDSP_TRUE12:
Video_Buffer[x * xpitch + y * ypitch]=((red & 0xF0) << 4) | (green & 0xF0) | ((blue & 0xF0) >> 4);
break;
case EDSP_TRUE16:
Video_Buffer[x * xpitch + y * ypitch]=((red & 0xF8) << 8) | ((green & 0xFC) << 3) | ((blue & 0xF8) >> 3);
break;
case EDSP_TRUE32:
Video_Buffer[x * xpitch + y * ypitch]=(red << 16) | (green << 8) | blue;
break;
}


More information about the pixel formats:
For Windows Desktop the most commonly used format is EDSP_TRUE32, unless it's set to 16-bit colors in the display configuration. On Windows Mobile EDSP_TRUE16 is used, but there is a big chance that EDSP_TRUE32 is used as well or will be used in the future. For Symbian it uses all three, although EDSP_TRUE12 is used in old devices (for example, Nokia N-Gage).
Strange works. Now draws always yellow points.
(I test on "Windows Desktop" - Video_Buffer[x * xpitch + y * ypitch]=(red << 16) | (green << 8) | blue; ) .....
Hi Relo,

Are you initializing your variables? For example:
Code:

red = 255;
green = 0;
blue = 0;
yes.
Code:
unsigned long CC,red,green,blue;
red=0;
green=255;
blue=0;
CC=(red << 16 ) | (green << 8 ) | blue;
...............
Video_Buffer[i * sf_inf.xpitch + t * sf_inf.ypitch]=CC;

And if to draw on a background, such sensation what to be put the color filter (all to become with a shade yellow)

Probably one byte of all changes in memory ?
Hi Relo,

It probably doesn't work because you're using an unsigned char * pointer for accessing the display memory. For EDSP_TRUE32 you need to cast it to unsigned long:

Code:

unsigned long *videomem32 = (unsigned long *)Video_Buffer;


For EDSP_TRUE12 and EDSP_TRUE16 use unsigned short.