Page 3 of 3

Re: put pixel to get pixel and gui scroll

Posted: Thu Aug 25, 2016 2:17 pm
by shmx
octacone wrote:No hope. This is just impossible to solve.
I do not see your attempts to do so.

Re: put pixel to get pixel and gui scroll

Posted: Thu Aug 25, 2016 2:23 pm
by shmx
octacone wrote:How do I capture 1600x900x32 area of pixels, save those pixels to a buffer and shift their y coordinate by wanted amount?
Why do you want intermediate buffer? Is not it easier to copy to the right place at once?

Code: Select all

void CopyMem(const DWORD* InBuf, DWORD* OutBuf, size_t Len, int Dir)
{
    size_t i;
    if(Dir == 0)
    {
        for(i = 0; i < Len; i++, OutBuf++, InBuf++)
             *OutBuf = *InBuf;
    }
    else
    {
        for(i = 0; i < Len; i++, OutBuf--, InBuf--)
            *OutBuf = *InBuf;
    }
}

void CopyRectangle(const DWORD *InVideoBuffer, DWORD *OutVideoBuffer,
    int X1, int Y1, int X2, int Y2, int Width, int Height,
    int Buffer1_Pitch, int Buffer2_Pitch)
{
	const DWORD* vbuf1;
    DWORD* vbuf2;
    int y = Height;

	if(Y2 <= Y1)
	{
		if(X2 <= X1)
		{
			vbuf1 = InVideoBuffer + X1 + Y1 * Buffer1_Pitch;
			vbuf2 = OutVideoBuffer + X2 + Y2 * Buffer2_Pitch;
			while(y-- > 0)
			{
                CopyMem(vbuf1, vbuf2, Width, 0);
				vbuf1 += Buffer1_Pitch;
				vbuf2 += Buffer2_Pitch;
			}
			
		}
		else
		{
			vbuf1 = InVideoBuffer + X1 + Width - 1 + Y1 * Buffer1_Pitch;
			vbuf2 = OutVideoBuffer + X2 + Width - 1 + Y2 * Buffer2_Pitch;
			while(y--)
			{
				CopyMem(vbuf1, vbuf2, Width, 1);
				vbuf1 += Buffer1_Pitch;
				vbuf2 += Buffer2_Pitch;
			}
		}
	}
	else
	{
		if(X2 <= X1)
		{
			vbuf1 = InVideoBuffer + X1 + (Y1 + Height - 1) * Buffer1_Pitch;
			vbuf2 = OutVideoBuffer + X2 + (Y2 + Height - 1) * Buffer2_Pitch;
			while(y--)
			{
			    CopyMem(vbuf1, vbuf2, Width, 0);
				vbuf1 -= Buffer1_Pitch;
				vbuf2 -= Buffer2_Pitch;
			}
		}
		else
		{
			vbuf1 = InVideoBuffer + X1 + Width - 1 + (Y1 + Height - 1) * Buffer1_Pitch;
			vbuf2 = OutVideoBuffer + X2 + Width - 1 + (Y2 + Height - 1) * Buffer2_Pitch;
			while(y--)
			{
				CopyMem(vbuf1, vbuf2, Width, 1);
				vbuf1 -= Buffer1_Pitch;
				vbuf2 -= Buffer2_Pitch;
			}
		}
	}
}
Something like this. InVideoBuffer can be equal OutVideoBuffer.
Pitch - logical buffer width (may be more than simply width).

Re: put pixel to get pixel and gui scroll

Posted: Fri Aug 26, 2016 2:50 am
by BrightLight
Just as a note, you should NEVER read from the VESA framebuffer. Writing is slow enough. Reading is even slower. Allocate a back buffer in normal RAM, and read from there and operate how you like on it. When all drawing is done, you memcpy() the back buffer to the hardware framebuffer.
Double Buffering

Re: put pixel to get pixel and gui scroll

Posted: Fri Aug 26, 2016 8:26 am
by Octacone
omarrx024 wrote:Just as a note, you should NEVER read from the VESA framebuffer. Writing is slow enough. Reading is even slower. Allocate a back buffer in normal RAM, and read from there and operate how you like on it. When all drawing is done, you memcpy() the back buffer to the hardware framebuffer.
Double Buffering
I have to admit something... That was one of the easiest to understand tutorials I've ever seen. =D> for the author.
I did not know that it was that bad. I guess I will have to implement double buffering first and the get come in here.

Re: put pixel to get pixel and gui scroll

Posted: Fri Aug 26, 2016 10:45 am
by Octacone
Is this how double buffering is supposed to look like?

Code: Select all

backVideoBuffer = ((uint32_t*) (Malloc(5760000))); //When I do this my mode does not get set
backVideoBuffer = ((uint32_t*) (Malloc(576000))); //When I do is with one less zero I get those artifacts

Re: put pixel to get pixel and gui scroll

Posted: Fri Aug 26, 2016 11:05 am
by Ch4ozz
Looks like broken memory management if the usage of the buffer is right.
Anyways, you should clear the buffer before using it because memory is usually not 0

Re: put pixel to get pixel and gui scroll

Posted: Fri Aug 26, 2016 11:12 am
by Octacone
Ch4ozz wrote:Looks like broken memory management if the usage of the buffer is right.
Anyways, you should clear the buffer before using it because memory is usually not 0
Broken memory management. RIP!!!
What could it be: Malloc or MemoryCopy?

Here is my memory copy function:

Code: Select all

void MemoryCopy(string source, string destination, int bytes)
{
	for(int i = 0; i < bytes; ++i)
	*(destination + i) = *(source + i);
}

Re: put pixel to get pixel and gui scroll

Posted: Sat Aug 27, 2016 4:31 am
by Ch4ozz
octacone wrote:Broken memory management. RIP!!!
What could it be: Malloc or MemoryCopy?

Here is my memory copy function:

Code: Select all

void MemoryCopy(string source, string destination, int bytes)
{
	for(int i = 0; i < bytes; ++i)
	*(destination + i) = *(source + i);
}
The probem is usually a wrong implementation of malloc.
Your memcpy is the slowest possible method btw (moving windows will lag like hell with this thing) :D

Re: put pixel to get pixel and gui scroll

Posted: Sun Aug 28, 2016 8:07 am
by azblue
octacone wrote:
shmx wrote:
octacone wrote:The problem is: getting pixels from selected region.
It is simply copying memory. I do not understand what could be the problem.
I only know how to put pixels using:

Code: Select all

unsigned location = (position.Y * screenWidthBGA * 4) + (position.X * 4);
	linearFrameBufferBGA[location + 0] = 0;
	linearFrameBufferBGA[location + 2] = color.R;
	linearFrameBufferBGA[location + 1] = color.G;
	linearFrameBufferBGA[location + 0] = color.B;
I don't know how to get specific pixels from wanted location.
I don't understand how you can possibly know how to plot pixels but not get them. You read the locations you would otherwise write.

Re: put pixel to get pixel and gui scroll

Posted: Sun Aug 28, 2016 9:20 am
by Octacone
Ch4ozz wrote:
octacone wrote:Broken memory management. RIP!!!
What could it be: Malloc or MemoryCopy?

Here is my memory copy function:

Code: Select all

void MemoryCopy(string source, string destination, int bytes)
{
	for(int i = 0; i < bytes; ++i)
	*(destination + i) = *(source + i);
}
The probem is usually a wrong implementation of malloc.
Your memcpy is the slowest possible method btw (moving windows will lag like hell with this thing) :D
Yeah I know. I tweaked it up a bit. :P

[Solved] put pixel to get pixel and gui scroll

Posted: Sun Aug 28, 2016 9:21 am
by Octacone
azblue wrote: It is simply copying memory. I do not understand what could be the problem.
It is much more complex than that.
Does not matter any more, topic closed. :)