0

I'm having an issue where the code below runs properly and generates the correct number of files, however it only produces the tops of images for all files (i.e. I can see sunglasses but not the person under them). I think it has to do with the while loop that checks to see if it's the beginning of another JPEG but I can't discern why it wouldn't produce the full image. Any help is appreciated.

uint8_t buffer[512];
int counter = 0;


//repeat until end of card
while (fread(buffer, 512, 1, file) == 1)
{
    //check if first 4 bytes are JPEG header

    if (buffer[0] == 0xff &&
        buffer[1] == 0xd8 &&
        buffer[2] == 0xff &&
        (buffer[3] & 0xf0) == 0xe0)
    {
        //pseudocode for writing header to file


        //checks to see if it is the beginning of another JPEG
        while (buffer[0] != 0xff &&
               buffer[1] != 0xd8 &&
               buffer[2] != 0xff &&
               (buffer[3] & 0xf0) != 0xe0)
        {
            //pseudocode for writing the buffer to file
        }

        //increment img file name

    }


}       

Modified to pseudocode since I thought my post might be giving too much away

1 Answer 1

0

After extensively traversing this forum I found that it was indeed an issue with my logic for checking to see if the condition fread had reached another header.

Here is the link to the comment I found: Developing JPEGS for pset4's recover troubleshooting

The issue relates to De Morgan's laws which I don't think were covered in the class. See here: https://en.wikipedia.org/wiki/De_Morgan%27s_laws

You must log in to answer this question.

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