0

I have a strange flaw in my program. Initially everything looks fine, it can resize any image correctly and the headers of the staff solutions and mine all match via "peek", so it seems that it makes an identical file. However, when I perform xxd on the copy I made, I notice my file is quite a bit longer!

For instance, when I resize small.bmp by 2, it looks fine on the image viewer and has a bfSize of (0xae) and biSizeImage of (0x78), which they should be.

However, xxd reveals this:

0000036: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 0000 ....................

000004a: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 0000 ....................

000005e: 00ff00 00ff00 ffffff ffffff 00ff00 00ff00 0000 ....................

0000072: 00ff00 00ff00 ffffff ffffff 00ff00 00ff00 0000 ....................

0000086: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 0000 ....................

000009a: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 0000 ....................

00000ae: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 0000 ....................

00000c2: 00ff00 00ff00 00ff00 00ff00 000000 000000 0000 ....................

00000d6: 000000 000000 000000 000000 000000 000000 0000 ....................

00000ea: 00ff00 00ff00 000000 000000 000000 000000 0000 ....................

00000fe: 000000 000000 000000 000000 000000 000000 0000 ....................

0000112: 00ff00 00ff00 000000 000000 000000 000000 0000 ....................

As you can see, it's written beyond the size of the file!! How is that even possible. It should have stopped at (0xae), but just keeps going.

When I try to see what is causing this in gdb, I can't figure out whats wrong! The program actually does stop writing there, but again when I open it up via xxd it looks like this. Please help me out, I don't know why it keeps writing these extra pixels and it is very frustrating!

1
  • You have twice more lines than you should have, so the problem likely lies in for loop responsible for iterating over scanlines. – Wiktor Czajkowski Jul 31 '15 at 8:32
0

As I answered over in your reddit post:

Remember, your header values have no bearing on the pixels that your write. That's entirely up to your loops, so I would suggest that your loops have the wrong incrementer. You are writing twice as many lines as you need, so perhaps you've got your reading loop using the new width rather than the old one?

1
  • Thank you, you were correct about me using the new width (or rather height in this case). Seems silly since I thought it was about the headers this whole time, it was a simple fix I just needed to know where I was going wrong :) – Thomas Jul 31 '15 at 14:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .