PocketMatrix forums

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

duplicating images

hi there,

my case is :
i need to duplicate an E2DSurfaceRGBA because i wanted to do real time scaling without messing the actual E2DSurfaceRGBA. i'm thinking about duplicating the actual E2DSurfaceRGBA every time i need to do scaling. i'm doing this on PC platform btw.

so my questions are:
- how can i duplicate a surface?
- will it hurt the performance?
- are there going to be memory leaking?

will be waiting for response. thanks.
Hi Nic-Gun,

When duplicating surfaces you need to store 2 (or more) surface objects. One for the original and another for the copy. Make sure the whole object is duplicated, not just the pointer.

To duplicate the surface we recommend looking at the following sample:
Code:

E2DSurface original, duplicate;
//This sample assumes original is already created and contains an image
display->CreateSurface(&duplicate;, original.GetWidth(), original.GetHeight());
E2DSURFACEINFO info;
unsigned char *dst = duplicate.Lock(&info;), *src = original.Lock();
if (dst && src)
ClassEMemory::Copy(dst, src, info.realheight * info.realpitch);
if (src)
original.Unlock();
if (dst)
duplicate.Unlock();


If you follow the sample, there will be no memory leaks. Performance depends on how often you duplicate a surface and which functions you'll use on it afterwards.
i tried the sample but i got an error at line :
ClassEMemory::Copy(dst, src, info.realheight * info.realpitch * info.realwidth * (info.bitwidth / 8));

where it lead to MEMCPY.asm at line :
;
; Copy down to avoid propogation in overlapping buffers.
;
align @WordSize
CopyDown:
lea esi,[esi+ecx-4] ;U - point to 4 bytes before src buffer end
lea edi,[edi+ecx-4] ;V - point to 4 bytes before dest buffer end
;
; See if the destination start is dword aligned
;

test edi,11b ;U - test if dword aligned
jnz short CopyLeadDown ;V - if not, jump

shr ecx,2 ;U - shift down to dword count
and edx,11b ;V - trailing byte count

cmp ecx,8 ;U - test if small enough for unwind copy
jb short CopyUnwindDown ;V - if so, then jump

std ;N - set direction flag
rep movsd ;N - move all of our dwords
cld ;N - clear direction flag back

jmp dword ptr TrailDownVec[edx*4] ;N - process trailing bytes

align @WordSize


any suggestion?
Hi Nic-Gun,

Sorry, I was lazy :p

I've modified the sample in the original post. It was copying too many bytes.
hi there,

it's fine really :D and the most important thing is that it worked nicely. thanks for the insight.