0

After looking at several similar questions, I still cannot figure out why my code is not working! here is my vertical (this is in the beginning of the outer loop):

        if(a <= n)
    {
        fseek(inptr, -(biWidth2 * (sizeof(RGBTRIPLE) + padding2)), SEEK_CUR);
        a++;
    }
    else
    {
        a = 0;
        b++;
        printf("line %i\n", b);
        printf("%li\n", ftell(inptr));
    }

EDIT:

I have changed the code to the following, but the program still cannot seem to run correctly:

long fgetpos(outptr, pos);
    // iterate over pixels in scanline
    for (int j = 0; j < n; j++)
    {
        long pos1 = ftell(outptr);
        if(pos != pos1)
        {
            fsetpos(inptr, pos);
        }
        ...
5

You're code is not quite clear to me. here is some pseudocode:

Approach #1:

for each scanline in original BMP
{
    // resize vertically
    repeat n times
    {
        ensure file position indicator is at the beginning of current scanline

        // resize horizontally
        for each RGBTRIPLE in current scanline
        {
            read an RGBTRIPLE
            write current RGBTRIPLE n times to new BMP
        }

        write new padding to new BMP
    }

    skip over old padding
}

Approach #2:

for each scanline in the original BMP
{
    create big enough array of RGBTRIPLEs named triples

    for each RGBTRIPLE in current scanline
    {
        read an RGBTRIPLE

        // resize horizontally
        append current RGBTRIPLE n times contiguously to triples 
    }

    // resize vertically
    repeat n times
    {
        write triples (whole array) to new BMP
        write new padding to new BMP
    }      

    skip the old padding
}

Hope that helps!

14
  • how would you know if you are not at the beginning of the current scanline? – user1475 Aug 10 '14 at 4:52
  • @user1475 what I meant by this is to check whether this is the very first iteration of the loop. You could have seeked back to the beginning of the current scanline directly anyway. It's just that in the first iteration of this loop, we don't really need to seek back and that's why I wrote this condition. If everything works according to the plan, at the end of this loop, you should be at the end of the current scanline. Also, no need for these ftell() calls, you may directly get and store the file position indicator at the beginning of the current scanline using fgetpos() and set it as – kzidane Aug 10 '14 at 10:26
  • you seek back to the beginning of the current scanline. Lastly, the code in the comment is quite hard to read. Please update your question with it if you want me to have a look at it. Thank you! – kzidane Aug 10 '14 at 10:27
  • sorry about that, I put it in as an edit – user1475 Aug 10 '14 at 21:37
  • what do you think is the problem? – user1475 Aug 12 '14 at 0:33

You must log in to answer this question.

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