Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- typedef uint8_t BYTE;
- #define BLOCKSIZE 512
- int main(void)
- {
- // define 512 byte block
- BYTE block[BLOCKSIZE];
- // open memory card
- FILE* fp = fopen("card.raw", "r");
- // check if file opened
- if (fp == NULL)
- {
- printf("Error opening file\n");
- return 1;
- }
- // open output file
- FILE* outfile;
- outfile = NULL;
- int num = 0;
- char filename[14];
- int x = 0;
- int y = 512;
- // main block till end of file
- while (y == 512)
- {
- if ( x == 0)
- {
- // read every 512 block
- fread(&block, sizeof(block), 1 , fp);
- }
- // if 4 first characters jpg
- if ((block[0] == 0xff && block[1] == 0xd8 && block[2] == 0xff && block[3] == 0xe0) || (block[0] == 0xff && block[1] == 0xd8 && block[2] == 0xff && block[3] == 0xe1))
- {
- sprintf(filename, "%03d_output.jpg", num);
- outfile = fopen(filename, "a");
- fwrite(&block, sizeof(block), 1, outfile);
- //fseek(fp, sizeof(block), SEEK_CUR);
- fread(&block, sizeof(block), 1 , fp);
- while (!((block[0] == 0xff && block[1] == 0xd8 && block[2] == 0xff && block[3] == 0xe0) || (block[0] == 0xff && block[1] == 0xd8 && block[2] == 0xff && block[3] == 0xe1)))
- {
- fwrite(&block, sizeof(block), 1, outfile);
- y = fread(&block, sizeof(block), 1, fp);
- }
- //fseek(fp, -(sizeof(block)), SEEK_CUR);
- fclose(outfile);
- num++;
- x = 1;
- //y = fread(&block, sizeof(block), 1, fp);
- }
- //printf("%s\n", block);
- }
- // close memory card
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement