[Solved] put pixel to get pixel and gui scroll

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
shmx
Member
Member
Posts: 68
Joined: Sat Jan 16, 2016 10:43 am

Re: put pixel to get pixel and gui scroll

Post by shmx »

octacone wrote:No hope. This is just impossible to solve.
I do not see your attempts to do so.
shmx
Member
Member
Posts: 68
Joined: Sat Jan 16, 2016 10:43 am

Re: put pixel to get pixel and gui scroll

Post 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).
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: put pixel to get pixel and gui scroll

Post 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
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: put pixel to get pixel and gui scroll

Post 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.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: put pixel to get pixel and gui scroll

Post 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
Attachments
doublebuffer.png
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: put pixel to get pixel and gui scroll

Post 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
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: put pixel to get pixel and gui scroll

Post 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);
}
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: put pixel to get pixel and gui scroll

Post 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
azblue
Member
Member
Posts: 147
Joined: Sat Feb 27, 2010 8:55 pm

Re: put pixel to get pixel and gui scroll

Post 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.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: put pixel to get pixel and gui scroll

Post 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
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

[Solved] put pixel to get pixel and gui scroll

Post 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. :)
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Post Reply