What is BMPFILE structure? Where do you get it? Are you sure it is 3 bytes per pixel? Are you sure rows are tightly packed (next row starts where previous one ends) without any padding?
I was thinking the same thing..I checked if it was compressed and it wasn't compressed like the body parts of our hero.
Yes, It's 24bits, so I get a byte from the image and then OR and SHIFT it leaving the alpha 0.
| I'm so excited that i can finally answer a question in this forum rather than ask it, because i ran into the very same thing.
the problem you have is that although the picture is 3 byte per pixel, the row must start on a offset that is dividable by 4, and the format just inserts some 0 bytes into the end of the row to make the offset dividable. if you don't account for those 0 bytes, you get a wrong number of bytes per row (pitch). wrong pitch makes straight vertical lines into diagonal lines, and that's what you see in the picture.
if you want to check for yourself, search for the BMP format or look at the memory tab in visual studio, or both.
i solved it by just not dealing with it, and converting the image into 4 bytes AARRGGBB format, the other solution was to make bitmaps width dividable by 4. making something special for each row would make my one copy loop from one for loop into two, and i didn't want that, but i see you can edit your code to handle it.
i hope i was clear about that,
the mage.
|
I haven't even done putting it on an X and Y cords yet. Right now it's at 0,0, and I will keep that mind when I do add X and Y cords, thanks! and Also, yes you are right, I forgot to add the pitch.
This problem is asking for some structured art.
Thanks I did review the video again and found the problem and a solution.
While for simple bitmaps the first code fragment could work, once you get into optimization and especially SIMD stuff, you want to use second code fragment. That way you can make pitch bigger than Width * BytesPerPixel, so every row actually begins on 16-byte aligned address (or 32-byte for AVX).
If you look carefully what code Casey writes on stream you'll see that he always uses Pitch to advance to next row.
yes, the pitch was exactly what I needed! And I think I will try to optimize, because it's the only way I can learn, then just watching.
Thanks to all, Handmade hero community is awesome. Now I just need to figure out how to flip the image. I already watch how Casey did it but it didn't quite work out. I prob just need to think it out more. Thanks Again.