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.
I'm drawing some random shapes that I happened to have lying around in a BMP. I've attached the image that was actually drawn and the image that should've been drawn. The image that was actually drawn had junk pixels in it. Interestingly, the junk pixels are different when I run it in Bochs and when I run it on my laptop. Does anybody have any ideas why this could be happening? I think it might have something to do with the bit orders, but I'm not sure.
Now, I know NOTHING on this bitmap drawing stuff. But I can safely say you are probably not giving enough information. How is this function called? How is fs_read supposed to be called? What is your framebuffer structure like exactly?
"Procrastination is the art of keeping up with yesterday."
One of the obvious issues here is that you forgot bitmap coordinates are not screen coordinates - instead they follow the same direction as how you would plot a function in math classes.
The other issue is possibly caused by having a bitmap covering only a part of the screen (and you neglecting to clear the rest of it in advance).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Sorry for not being specific enough on my first try. framebuffer_t is a cross-platform structure I use for framebuffers in my graphics code that contains, among other things, the framebuffer's data region as a void*, and the framebuffer's width, height, bpp, and pitch. fs_read() takes an Inode, buffer, offset, and length. My bitmap drawing function, for now, just takes a framebuffer and a file name.
Right now the image is drawn upside-down. I'm going to fix that issue but I was first testing with this code that draws it upside-down. Finally, the image is the same size as the screen, for testing purposes. The screen has already been cleared.
1. I don't know how your fs_read works internally, but why would you make repeated calls to that per row? Unless you have filesystem caching, in which case ignore this point.
2. Combuster has already pointed out, as with OpenGL and math, the 0,0 on bitmaps is usually on the bottom left instead. However, there's some quirk or something, where if the row is negative it changes the direction of the bitmap. I don't know if it's negative makes it top-left or bottom-left, but either way you can't just abs() away the height.
3. Again, I don't know the internals of your system, but one of the possible causes of the junk could be your disk reading -- it might be returning junk in the buffer or something. Either way, your actual bitmap drawing looks correct (apart from the inverted thing), but we can't tell for sure.
EDIT: Another thing I would check is your bitmap file itself. It might be compressed. It might help if you provided the original bitmap image.
1) I know that the image is currently flipped and that I can't simply use abs() of the height. I just haven't implemented that feature yet (I was testing it with the simpler version first).
2) It seems a very real possibility that something is wrong with my filesystem drivers. I will do more testing on this. I can dump pixel values on the screen/in the framebuffer and in the image and compare them. Specifically, I want to see a hexdump of the junk pixel data. There are LBA out of range messages in Bochs.
3) I can't upload the original image because it's too big, however, I checked and the image data doesn't seem to be compressed. This is substantiated by the fact that it displays differently on my two different devices I've been testing it on.
If you're getting LBA out of range errors, then you definitely want to check your filesystem code.
EDIT: Well if you want to see the pixel data, just dump it? It should also be trivial to make a user space program to dump the data from the original image.