The Forum is up for sale: XeNTaX Forum looking for new owner

What's wrong with this bitmap export code

Coders and would-be coders alike, this is the place to talk about programming.
Post Reply
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 307 times

What's wrong with this bitmap export code

Post by finale00 »

I'm writing a simple bitmap export in python to get an idea of how to write such an exporter.
It is the uncompressed 24-bit bmp.

I have the header down, and here's how I'm doing the pixel array

Code: Select all

pix = bytes()
for x in range(pic.width):
   for y in range(pic.height - 1, 0, -1):
      pixel = pic.get_pixel(x, y)
      pix += pixel.red()
      pix += pixel.green()
      pix += pixel.blue()
f.write(struct.pack("%dB" %pic.width*pic.height*3, pix))
But the picture's all messed up lol

Image

It's like the pixels are not drawn in the right spots (everything shifted over by a bunch of pixels)

Following the specs on wiki, it should be 4-byte aligned.

My image is 544x416. Shouldn't have an issue with byte-alignment right?
howfie
double-veteran
double-veteran
Posts: 929
Joined: Fri Jul 08, 2011 12:06 pm
Location: Torrance, CA
Has thanked: 10 times
Been thanked: 274 times

Re: What's wrong with this bitmap export code

Post by howfie »

Try it with y in the outer loop.
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 307 times

Re: What's wrong with this bitmap export code

Post by finale00 »

Oh hey it worked.
Except now it's flipped o.O

EDIT: oh, now that I look at the array more carefully, (0,0) is at the bottom-left and not the upper-left -_-
Now I loop down to 0 for the rows and it's right-side up lol
howfie
double-veteran
double-veteran
Posts: 929
Joined: Fri Jul 08, 2011 12:06 pm
Location: Torrance, CA
Has thanked: 10 times
Been thanked: 274 times

Re: What's wrong with this bitmap export code

Post by howfie »

Correct. Bitmaps are stored upside down.
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 307 times

Re: What's wrong with this bitmap export code

Post by finale00 »

lol is there some reason to store it that way? Optimization?
Especially the 4-byte alignment padding stuff...
howfie
double-veteran
double-veteran
Posts: 929
Joined: Fri Jul 08, 2011 12:06 pm
Location: Torrance, CA
Has thanked: 10 times
Been thanked: 274 times

Re: What's wrong with this bitmap export code

Post by howfie »

Yeah, that kind of alignment nowadays probably doesn't help much, but back in the old days, say windows 3.1 days, it made a hell of a difference. I don't remember if bmp predates windows 3.1, but I remember looking at porn (look, back in 1993 all there was were porn sites lol) on dos 3. The picture would load pixel by pixel on the screen. You could literally count the pixels as they loaded lol. The hard drive was only 25 mb too and images were in 16-bit color. Ever see tits in 16-bits? Hahaha.
MichaelDarkAngel
mega-veteran
mega-veteran
Posts: 267
Joined: Thu Nov 04, 2010 11:25 pm
Location: Somewhere, out there... But, not quite here...
Has thanked: 133 times
Been thanked: 165 times
Contact:

Re: What's wrong with this bitmap export code

Post by MichaelDarkAngel »

howfie wrote:(look, back in 1993 all there was were porn sites lol)
You're dating yourself 8D
howfie wrote:Ever see tits in 16-bits? Hahaha.
How about ascii tits on a BBS with a Commodore 64? :ninja:
Image
MDA

Like TBotR on Facebook
ARchive_neXt v4.03.27.0 Now Available!

"I intend to leave a memory of myself in the minds of others."
Leonardo da Vinci,
disciple of experience
howfie
double-veteran
double-veteran
Posts: 929
Joined: Fri Jul 08, 2011 12:06 pm
Location: Torrance, CA
Has thanked: 10 times
Been thanked: 274 times

Re: What's wrong with this bitmap export code

Post by howfie »

Lol,bigger question is now, did you masturbate to ASCII tits :)?
Post Reply