PocketMatrix forums

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

scaling

Hi, I'm trying to implement a scaling algorithm which works by inserting an extra blended pixel between each pixel and 80% brightness 'scan-lines' between each horizontal line:
Code:

// E2DSurface dest is twice as big as E2DSurface src
for (unsigned char y = 0; y < src.GetHeight(); y++) {
// Row 1: Alternate between source pixel and blended pixel
for (unsigned char x = 0; x < src.GetWidth(); x++) {
dest.PutPixel(x*2, y*2, src.GetPixel(x, y));
COLORREF temp1 = src.GetPixel(x, y);
COLORREF temp2 = src.GetPixel(x+1, y);
dest.PutPixel(x*2+1, y*2, E_RGBX((E_GETR(temp1)+E_GETR(temp2))/2, (E_GETG(temp1)+E_GETG(temp2))/2, (E_GETB(temp1)+E_GETB(temp2))/2);
}
// Row 2: blit line y scaled 2x at 80% brightness
RECT rc;
SetRect(&rc, 0, y, src.GetWidth(), y);
Blt(dest.GetWidth()/2, (y*2)+1, src, &rc, 0, 131072, EFLIP_NONE, EFX_OPACITY, 200);
}

I have two issues here. First, it is extremely slow! Is there any faster alternative reading/writing to E2DSurface than using Get/PutPixel? Or any other obvious way to optimize this code? Second, SetRect() doesn't allow me to set a 1 row tall Rect. Is there any other way I can grab a single row from my source image to blit to my destination buffer?
Hi,

The best alternative for get/put pixel is to lock the surface to receive its memory buffer. You can fetch one row of pixel data by changing your code. In the SetRect call, use y + 1 as the fifth parameter instead of y.
Thanks for the quick reply. I'm trying to look at some of the Lock() examples on the forum, but I'm not clear as to how to define the E2DSURFACEINFO parameter. What exactly do the pitch (xpitch, ypitch, realpitch) values refer to? Also, where can I find the bufferoffset value? Last, could you please clarify the difference between regular and real variables (such as width vs. realwidth)?
Hi, figured it out after rereading through old posts. Thanks!