0

enter image description here

enter image description here

i am kind of stuck right now.. any suggestion?

i made this for loop to repeat pixel n times. for (int n = 0; n < scale; n++)

But if i do this, padding also gets repeated "scale" times. Is putting for loop here right approach?

0

Make sure you understand how your input and output differ, in pixels per line and where how much padding is added.

I guess bi_n is your new header, and bi is the old one.

You are reading bi_n.biWidth "pixels", while an input line is only bi.biWidth pixels wide, so you are treating the padding as pixels. As the padding here is same size as pixels, it just appears as black pixels.

Similarly, the input file contains only abs(bi.biHeight) lines, so you would either have to copy the read line into an array, and write multiple times from there, or fseek to the beginning of the input line and re-read it.

For both, horizontal and vertical scaling, I'd use nested loops, an outer with the dimension of the input image, and an inner with scale iterations (similar to what you tried for horizontal resize). That way, the code in the outer loop corresponds to input image, the code in the inner loop corresponds to output image. And horizontal scaling code into vertical scaling code, just as you do. Make sure to do all the fseek and output padding writing on the right level.

6
  • Thanks for the reply! I forgot that I was reading original image not the new image in the for loop. I think I solved few more steps after that. I put one more for loop that would write same scanline "scale" times and fseek to put cursor to the beginning. But I don't know how to write copied scanline to the next line.. can you help me out.
    – sksch1663
    Aug 16 '18 at 14:30
  • Other code looks mostly right, but remember you need to progress at some point. Currently it looks like you are always jumping back to the beginning of the line. Also, SEEK_SET wants an absolute position, you meant SEEK_CUR.
    – Blauelf
    Aug 16 '18 at 14:37
  • thanks its seek_cur because it has to move from the current position to the beginning. How would I move to the next scanline? I tried to use fseek(outptr) but seems like its not working :(
    – sksch1663
    Aug 17 '18 at 11:12
  • Either don't jump back on the last repeat, or jump forward by the same number of bytes.
    – Blauelf
    Aug 17 '18 at 11:24
  • I got it working thanks..One last question though.. just want to make sure
    – sksch1663
    Aug 21 '18 at 1:24
0

I got the code to work but I don't understand one thing. I understand that after it writes first scanline "scale" times, use fseek to move cursor back to the beginning to read same scanline and write that "scale" times again for vertical copy. But I don't understand why it moves to the 2nd vertical line. So basically if pixel is like x o x,

why would scaling it 4 times make it

x x x x o o o o x x x x

x x x x o o o o x x x x

x x x x o o o o x x x x

x x x x o o o o x x x x

instead of

x^4 x^4 x^4 x^4 o^4 o^4 o^4 o^4 x^4 x^4 x^4 x^4

here ^4 shows how it would write pixels on the same spot thus making it

x x x x o o o o x x x x

Or am I just confused because of separate lines? is

x x x x o o o o x x x x

x x x x o o o o x x x x

x x x x o o o o x x x x

x x x x o o o o x x x x

same as

x x x x o o o o x x x x x x x x o o o o x x x x x x x x o o o o x x x x x x x x o o o o x x x x ?

so after cursor moves back to read same scanline and write it scale times, outptr cursor automatically just moves to the next spot to write that scanline?

1
  • I created new question but no one answered it lol
    – sksch1663
    Aug 21 '18 at 1:26

You must log in to answer this question.

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