Register
Site Login
Site Search
Forums
Advertisement
Welcome to PocketMatrix. PocketMatrix is dedicated to providing the best online community for mobile device developers and enthusiests. What's new?

putpixel fast...


putpixel fast...

Postby relo » Feb 14, 2008 @ 12:52pm

the display->buffer.PutPixel(i,t,E_RGBX(250,250,250)); so slow.
Code: Select all









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();
9 lines; 6 keywds; 7 nums; 43 ops; 0 strs; 1 coms    Syntactic Coloring v0.4 - Dan East  

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.
relo
pm Member
 
Posts: 22
Joined: Nov 2, 2006 @ 8:38am


Postby edge » Feb 14, 2008 @ 6:56pm

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: Select all

videobuffer[* xpitch + y * ypitch] = 0;
1 lines; 0 keywds; 1 nums; 7 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


When locking the backbuffer be sure to check the pixelformat of the surface, not all devices have the same colordepth.
EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Postby relo » Feb 15, 2008 @ 8:19am

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)?
relo
pm Member
 
Posts: 22
Joined: Nov 2, 2006 @ 8:38am


Postby edge » Feb 15, 2008 @ 11:56am

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: Select all









10 
11 
12 
switch(pixelformat)
{
    case EDSP_TRUE12:
        Video_Buffer[* xpitch + y * ypitch]=((red & 0xF0) << 4) | (green & 0xF0) | ((blue & 0xF0) >> 4);
        break;
    case EDSP_TRUE16:
        Video_Buffer[* xpitch + y * ypitch]=((red & 0xF8) << 8) | ((green & 0xFC) << 3) | ((blue & 0xF8) >> 3);
        break;
    case EDSP_TRUE32:
        Video_Buffer[* xpitch + y * ypitch]=(red << 16) | (green << 8) | blue;
        break;
}
12 lines; 7 keywds; 13 nums; 83 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


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).
EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Postby relo » Feb 15, 2008 @ 1:00pm

Strange works. Now draws always yellow points.
(I test on "Windows Desktop" - Video_Buffer[x * xpitch + y * ypitch]=(red << 16) | (green << 8) | blue; ) .....
relo
pm Member
 
Posts: 22
Joined: Nov 2, 2006 @ 8:38am


Postby edge » Feb 15, 2008 @ 2:59pm

Hi Relo,

Are you initializing your variables? For example:
Code: Select all



red = 255;
green = 0;
blue = 0;
3 lines; 0 keywds; 3 nums; 6 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  
EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Postby relo » Feb 15, 2008 @ 4:04pm

yes.
Code: Select all







unsigned long CC,red,green,blue;
      red=0;
    green=255;
    blue=0;
    CC=(red << 16 ) | (green << 8 ) | blue;
      ...............
      Video_Buffer[* sf_inf.xpitch + t * sf_inf.ypitch]=CC;
7 lines; 2 keywds; 5 nums; 46 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  

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 ?
relo
pm Member
 
Posts: 22
Joined: Nov 2, 2006 @ 8:38am


Postby edge » Feb 16, 2008 @ 2:02pm

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: Select all

unsigned long *videomem32 = (unsigned long *)Video_Buffer;
1 lines; 4 keywds; 0 nums; 6 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


For EDSP_TRUE12 and EDSP_TRUE16 use unsigned short.
EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Return to EDGELIB


Sort


Forum Description

Powerful and affordable C++ middleware solution covering true multi-platform 2D, 3D and network features for Apple iPhone, Windows Mobile, Symbian S60, UIQ, Linux and Windows desktop.

Moderator:

edge

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum