pixmap copying pixels from loaded to static
BlitzMax Forums/BlitzMax Beginners Area/pixmap copying pixels from loaded to static
| ||
I have a function where I make a static pixmap and I am trying to make a function where I can change pixels in that from a loaded pixmap.Function zgPixmapCreate:TPixmap( width, height ) Local pmap:TPixmap = New TPixmap pmap.pixels = MemAlloc( width * height * 4 ) pmap.width = width pmap.height = height pmap.pitch = width * 4 pmap.format = 6 pmap.capacity = -1 Return pmap End Function Function zgCopyRect( source:TPixmap, target:TPixmap, x, y, width, height, tx, ty ) For Local yy = 0 To height-1 For Local xx = 0 To width-1 Local src = source.pitch * ( yy + y ) + ( xx + x ) * 4 Local des = target.pitch * ( yy + ty ) + ( xx + tx ) * 4 target.pixels[des] = source.pixels[src] target.pixels[des+1] = source.pixels[src+1] target.pixels[des+2] = source.pixels[src+2] target.pixels[des+3] = source.pixels[src+3] Next Next End Function The above makes a pixmap which is set up using RGBA8888 format with 4 bytes per pixel. It works just fine when using two pixmaps that I have made with the first function, but when using a loaded pixmap as the source it copy over garbage pixel data. I have tried to figure out how the format of the pixmap that gets loaded with loadpixmap command is set up. But even if I do a convert to RGBA8888 it doesn't work. How would you copy pixels from a loaded pixmap to a static ? |
| ||
Brain spasm...Move along... |
| ||
I got it working using readpixel and writepixel, but it would be nice to know how the pixel data is stored within a pixmap that is loaded. |
| ||
I don't assume you checked out brl.pixmap (especially TPixmap.paste) |
| ||
I dont know why you are reserving memory for the pixmap. Doesn't New TPixmap create its own memory area? Also, I'm not sure but maybe the pixmap is upside down ... it needs to be upside down because OpenGL renders from the bottom upwards. If you look at the DrawPixmap() code, I think it converts it and flips it vertically first. In OpenGL you specify the lower left corner of the image first, you see, so the texture has to be read upside down. I think. ;-D So if you aren't taking that into account you might be reading the wrong memory area. |
| ||
Why don't you just use CreatePixmap() to create the empty pixmap? Or use CopyPixmap()? You might also try CreateStaticBank() mapped onto the memory of the pixmap, then use some kind of memcopy thing. |
| ||
I got things working using read/write pixel, but I will take another look at the functions in the pixmap module as perhaps I am working on things that is already there. Thanks for the pointers. |