Forgotten Coder craziest idea

Pages: 123
that is not too advanced. you just flip the rows. row max and row zero exchange.
just draw it the way the tool wants it, and flip your iteration.

1
2
3
4
5
6
7
8
9
10
11
12
for(rows = maxrow; rows; rows--)  //if maxrow is the size, you need -1 here
  for(cols = 0; cols <= maxcol; cols++)  //if maxcol is the size, use < not <= here
   {
      img[rows][cols] = pixeldata; //its correct to think top down here, but its filling it bottom up
    }

what-if you had a top down and a bottom up then?  adding a top-down source to copy from:
for(rows = maxrow; rows; rows--)  //if maxrow is the size, you need -1 here
  for(cols = 0; cols <= maxcol; cols++)  //if maxcol is the size, use < not <= here
   {
      img[rows][cols] = topdown[maxrow-row][cols];
    }


it may be faster to have an extra iteration variable for maxrow-row that goes 0-maxrow.
but that is code tweaking, the logic is identical.
Last edited on
Hi jonnin

The problem is that memory_buffer uses has origin (0,0) the bottom left corner of screen. I want to pass (0,0) to top left corner of screen with a formula. No success so far. Memory buffer is continuos. Your go through with a pointer. Doesn't have rows or columns.

p - pointer to buffer memory
x,y - coords
*4 = 4 bytes per color in buffer memory


p += y * 4 * buffer_width;
p += x * 4;


This formula will start your pixels origin from bottom left corner. I want it to start on top left corner of screen.

Note: thanks for your code
Doesn't have rows or columns.

you can make a 1-d to 2-d.
the standard formula is:
oned[desired row* number_cols + desired_col];
that is C/C++ memory layout.

a different and more complex mapping for going over it your way is doable. But its inefficient: you will go much faster iterating it forward as it is in memory. And the subtraction costs a bit too.

what you do is take the above formula and do what I did in the code above to revere the rows.
so instead of desired_row you get (maxrow-desired_row) I think, or something like that.
Last edited on
My memory buffer starts putting pixels from bottom left corner, line by line, all the way up on screen. It's bottom top. I want to start on top left corner moving down. Struggling with a working formula for that.


Let GDI do this by creating a top-down bitmap.
https://docs.microsoft.com/en-us/windows/win32/directshow/top-down-vs--bottom-up-dibs
Essentially you have to negate the height of the bitmap in the bitmapinfo structure.

Also make sure to choose 32 bits-per-pixel so that exactly zero bytes of padding are required after the end of a scan line. Row stride (the offset from the start of one scan line to the next) must be a multiple of four. Moreover the start of each scan line must be aligned on a 4-byte boundary.
If you use the windows memory functions to get space for the bitmaps you are guaranteed a DWORD alignment, but honestly, the C and C++ memory managers should do that for you on Windows as well, unless you fiddle with some compiler flags to turn that off.
Hi jonin

Thanks for tip.
Hi mbozzi

Thanks for tip. Made some ajustments in my code. And now i have a superfast putpixel function. More fast than W32 SetPixel.

This line will change mode to top-down in bitmap (negative height)

buffer_bitmap_info.bmiHeader.biHeight= - buffer_height;


Hi Duthomhas

Thanks for tip. I am using VirtualAlloc to alocate memory.


buffer_memory = VirtualAlloc(0,buffer_size,MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
Hi guys

Finally i have a name for library. I call it TURBOSCREEN.

Trying to setup a forum for it with PHPBB. Another strugling BIG LOL.

Working on a color system like SFML for my pixels on screen. An idea i got from here.

My system will be like

ts::Color::RED



Note: ts = turboscreen :)
Last edited on
Topic archived. No new replies allowed.
Pages: 123