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