Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Kevin Brough
- //kmb180
- #include <stdio.h>
- #include <string.h>
- struct header{
- char start[2];
- char app1[2];
- char len_app_1[2];
- char exif_data_string[4];
- char NULL_zero[2];
- char endian[2];
- char v_num[2];
- int offset;
- };
- struct tiff_header{
- short tag_identifier;
- char data_type[2];
- int num_bytes;
- int data_offset;
- };
- int main(int argc, char *argv[]){
- FILE *f;
- struct tiff_header tiff_hdr;
- struct header hdr;
- unsigned short count = 0;
- int index = 0;
- int E0 = 224;
- int file_tracker = 12;//to keep track of where we last had the file pointer; begins at 12 because that's where the tags start
- char data_string[256];
- unsigned int u_int1; // for displaying ratios for type 5 data
- unsigned int u_int2;
- f = fopen(argv[1], "rb");
- fread(&hdr, sizeof(hdr), 1, f);
- if(hdr.app1[1] == E0){
- printf("Error: Expected APP1");
- return 1;
- }
- if(strcmp(hdr.endian, "MM") == 0){ // If what we got was MM is indeed MM then end program with error
- printf("Error: Endianess not supported");
- return 1;
- }
- fread(&count, sizeof(unsigned short), 1, f);
- for(index; index<count; index++){
- fread(&tiff_hdr, sizeof(tiff_hdr), 1, f);
- if(tiff_hdr.tag_identifier == 0x010F){
- file_tracker = ftell(f);
- fseek(f, tiff_hdr.data_offset+12, SEEK_SET);
- fread(data_string, tiff_hdr.num_bytes, 1, f);
- printf("Manufacturer:\t%s\n", data_string);
- fseek(f, file_tracker, SEEK_SET);
- }
- if(tiff_hdr.tag_identifier == 0x0110){
- file_tracker = ftell(f);
- fseek(f, tiff_hdr.data_offset+12, SEEK_SET);
- fread(data_string, tiff_hdr.num_bytes, 1, f);
- printf("Model:\t\t%s\n", data_string);
- fseek(f, file_tracker, SEEK_SET);
- }
- if(tiff_hdr.tag_identifier == 0xffff8769){
- index = 0;//restarting the loop
- fseek(f, tiff_hdr.data_offset+12, SEEK_SET);//getting to the new tags
- fread(&count, sizeof(unsigned short), 1, f); //and reading in that new count right after
- }
- if(tiff_hdr.tag_identifier == 0xffffA002){//type 4
- file_tracker = ftell(f);
- printf("Width:\t\t%u pixels\n", tiff_hdr.data_offset);
- }
- if(tiff_hdr.tag_identifier == 0xffffA003){//type 4
- file_tracker = ftell(f);
- printf("Height:\t\t%u pixels\n", tiff_hdr.data_offset);
- }
- if(tiff_hdr.tag_identifier == 0xffff8827){ //type 4
- file_tracker = ftell(f);
- printf("ISO:\t\tISO %u\n", tiff_hdr.data_offset);
- }
- if(tiff_hdr.tag_identifier == 0xffff829a){//type 5
- file_tracker = ftell(f);
- fseek(f, tiff_hdr.data_offset+12, SEEK_SET);
- fread(&u_int1, sizeof(unsigned int), 1, f);//like with the rest of these type 5's we're reading in to unsigned ints
- fread(&u_int2, sizeof(unsigned int), 1, f);
- printf("Exposure Time:\t%u/%u second\n", u_int1, u_int2);
- fseek(f, file_tracker, SEEK_SET);
- }
- if(tiff_hdr.tag_identifier == 0xffff829d){//type 5
- file_tracker = ftell(f);
- fseek(f, tiff_hdr.data_offset+12, SEEK_SET);
- fread(&u_int1, sizeof(unsigned int), 1, f);
- fread(&u_int2, sizeof(unsigned int), 1, f);
- printf("F-stop:\t\tf/%.1f\n", (double)u_int1/u_int2);
- fseek(f, file_tracker, SEEK_SET);
- }
- if(tiff_hdr.tag_identifier == 0xffff920A){//type 5
- file_tracker = ftell(f);
- fseek(f, tiff_hdr.data_offset+12, SEEK_SET);
- fread(&u_int1, sizeof(unsigned int), 1, f);
- fread(&u_int2, sizeof(unsigned int), 1, f);
- printf("Focal Length:\t%u mm\n", u_int1/u_int2);
- fseek(f, file_tracker, SEEK_SET);
- }
- if(tiff_hdr.tag_identifier == 0xffff9003){
- file_tracker = ftell(f);
- fseek(f, tiff_hdr.data_offset+12, SEEK_SET);
- fread(data_string, tiff_hdr.num_bytes, 1, f);
- printf("Date Taken:\t%s\n", data_string);
- fseek(f, file_tracker, SEEK_SET);
- }
- file_tracker += 12;
- }
- fclose(f);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement