Changeset 1799 for trunk/core/dng.c
- Timestamp:
- 04/11/12 23:18:35 (14 months ago)
- File:
-
- 1 edited
-
trunk/core/dng.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/dng.c
r1796 r1799 49 49 const int cam_Resolution[] = {180,1}; 50 50 int cam_AsShotNeutral[] = {1000,1000,1000,1000,1000,1000}; 51 static char cam_datetime[20] = ""; // DateTimeOriginal 51 52 52 53 struct t_data_for_exif{ … … 150 151 {0x11C, T_SHORT, 1, 1}, // PlanarConfiguration: 1 151 152 {0x131, T_ASCII, sizeof(cam_chdk_ver), (int)cam_chdk_ver},//Software 152 {0x132, T_ASCII, 20, 0},// DateTime153 {0x132, T_ASCII, 20, (int)cam_datetime}, // DateTime 153 154 {0x14A, T_LONG, 1, 0}, //SubIFDs offset 154 155 {0x8298, T_ASCII, 1, 0}, // Copyright … … 200 201 static int cam_shutter[2] = { 0, 1000000 }; // Shutter speed 201 202 static int cam_aperture[2] = { 0, 10 }; // Aperture 202 static char cam_datetime[20] = ""; // DateTimeOriginal203 203 static int cam_apex_shutter[2] = { 0, 96 }; // Shutter speed in APEX units 204 204 static int cam_apex_aperture[2] = { 0, 96 }; // Aperture in APEX units … … 229 229 struct dir_entry GPS_IFD[]={ 230 230 {0x0000, T_BYTE, 4, 0x00000302}, //GPSVersionID: 2 3 0 0 231 {0x0001, T_ASCII ,2, (int)gps_data.latitudeRef}, //North or South Latitude "N\0" or "S\0"231 {0x0001, T_ASCII|T_PTR, 2, (int)gps_data.latitudeRef}, //North or South Latitude "N\0" or "S\0" 232 232 {0x0002, T_RATIONAL, 3, (int)gps_data.latitude}, //Latitude 233 {0x0003, T_ASCII ,2, (int)gps_data.longitudeRef}, //East or West Latitude "E\0" or "W\0"233 {0x0003, T_ASCII|T_PTR, 2, (int)gps_data.longitudeRef}, //East or West Latitude "E\0" or "W\0" 234 234 {0x0004, T_RATIONAL, 3, (int)gps_data.longitude}, //Longitude 235 {0x0005, T_BYTE , 1, (int)gps_data.heightRef},//AltitudeRef235 {0x0005, T_BYTE|T_PTR, 1, (int)&gps_data.heightRef}, //AltitudeRef 236 236 {0x0006, T_RATIONAL, 1, (int)gps_data.height}, //Altitude 237 237 {0x0007, T_RATIONAL, 3, (int)gps_data.timeStamp}, //TimeStamp 238 {0x0009, T_ASCII ,2, (int)gps_data.status}, //Status238 {0x0009, T_ASCII|T_PTR, 2, (int)gps_data.status}, //Status 239 239 //{0x000A, T_ASCII, 1, 0}, //MeasureMode 240 240 {0x0012, T_ASCII, 7, (int)gps_data.mapDatum}, //MapDatum 7 + 1 pad byte … … 295 295 case 0x110 : // CameraName 296 296 case 0xC614: IFD_LIST[j].entry[i].count = strlen((char*)IFD_LIST[j].entry[i].offset) + 1; break; // UniqueCameraModel 297 case 0x132 :298 297 case 0x8822: IFD_LIST[j].entry[i].offset=get_exp_program_for_exif(exif_data.exp_program); break;//ExposureProgram 299 298 case 0x0112: IFD_LIST[j].entry[i].offset=get_orientation_for_exif(exif_data.orientation); break; //Orientation … … 603 602 // removal from images. 604 603 605 //#define INIT_BADPIXEL_COUNT -1606 //#define INIT_BADPIXEL_FILE -2607 // 608 //#define PATH_BADPIXEL_BIN "A/CHDK/badpixel.bin"609 //#define PATH_BAD_TMP_BIN "A/CHDK/bad_tmp.bin"610 // 611 //int init_badpixel_bin_flag; // contants above to count/create file, > 0 num bad pixel612 // 604 #define INIT_BADPIXEL_COUNT -1 605 #define INIT_BADPIXEL_FILE -2 606 607 #define PATH_BADPIXEL_BIN "A/CHDK/badpixel.bin" 608 #define PATH_BAD_TMP_BIN "A/CHDK/bad_tmp.bin" 609 610 int init_badpixel_bin_flag; // contants above to count/create file, > 0 num bad pixel 611 613 612 int raw_init_badpixel_bin() { 614 //int count;615 //unsigned short c[2];616 //FILE*f;617 //if(init_badpixel_bin_flag == INIT_BADPIXEL_FILE) {618 //f=fopen(PATH_BAD_TMP_BIN,"w+b");619 //} else if (init_badpixel_bin_flag == INIT_BADPIXEL_COUNT) {620 //f=NULL;621 //} else {622 //return 0;623 //}624 //count = 0;625 //for (c[0]=camera_sensor.active_area.x1; c[0]<camera_sensor.active_area.x2; c[0]++)626 //{627 //for (c[1]=camera_sensor.active_area.y1; c[1]<camera_sensor.active_area.y2; c[1]++)628 //{629 //if (get_raw_pixel(c[0],c[1]) <= DNG_BADPIXEL_VALUE_LIMIT)630 //{631 //unsigned short l;632 //for (l=0; l<7 && (c[1]+l+1)<camera_sensor.active_area.y2; l++)633 //if (get_raw_pixel(c[0],c[1]+l+1) > DNG_BADPIXEL_VALUE_LIMIT)634 //break;635 //c[1] = c[1] | (l << 13);636 //if (f) fwrite(c, 1, 4, f);637 //c[1] = (c[1] & 0x1FFF) + l;638 //count = count + l + 1;639 //}640 //}641 //}642 //if (f) fclose(f);643 //init_badpixel_bin_flag = count;644 //state_shooting_progress = SHOOTING_PROGRESS_PROCESSING;613 int count; 614 unsigned short c[2]; 615 FILE*f; 616 if(init_badpixel_bin_flag == INIT_BADPIXEL_FILE) { 617 f=fopen(PATH_BAD_TMP_BIN,"w+b"); 618 } else if (init_badpixel_bin_flag == INIT_BADPIXEL_COUNT) { 619 f=NULL; 620 } else { 621 return 0; 622 } 623 count = 0; 624 for (c[0]=camera_sensor.active_area.x1; c[0]<camera_sensor.active_area.x2; c[0]++) 625 { 626 for (c[1]=camera_sensor.active_area.y1; c[1]<camera_sensor.active_area.y2; c[1]++) 627 { 628 if (get_raw_pixel(c[0],c[1]) <= DNG_BADPIXEL_VALUE_LIMIT) 629 { 630 unsigned short l; 631 for (l=0; l<7 && (c[1]+l+1)<camera_sensor.active_area.y2; l++) 632 if (get_raw_pixel(c[0],c[1]+l+1) > DNG_BADPIXEL_VALUE_LIMIT) 633 break; 634 c[1] = c[1] | (l << 13); 635 if (f) fwrite(c, 1, 4, f); 636 c[1] = (c[1] & 0x1FFF) + l; 637 count = count + l + 1; 638 } 639 } 640 } 641 if (f) fclose(f); 642 init_badpixel_bin_flag = count; 643 state_shooting_progress = SHOOTING_PROGRESS_PROCESSING; 645 644 return 1; 646 645 } 647 646 648 //short* binary_list=NULL;649 //int binary_count=-1;647 short* binary_list=NULL; 648 int binary_count=-1; 650 649 651 650 void load_bad_pixels_list_b(char* filename) { 652 //struct STD_stat st;653 //long filesize;654 //void* ptr;655 //FILE *fd;656 657 //if ( filename==0 )658 //{ unload_bad_pixels_list_b(); return; }659 660 //binary_count=-1;661 //if (safe_stat(filename,&st)!=0) return;662 //filesize=st.st_size;663 //if (filesize%(2*sizeof(short)) != 0) return;664 //if (filesize == 0) { binary_count = 0; return; } // Allow empty badpixel.bin file665 //ptr=malloc(filesize);666 //if (!ptr) return;667 //fd=fopen(filename, "rb");668 //if (fd) {669 //fread(ptr,1, filesize,fd);670 //fclose(fd);671 //binary_list=ptr;672 //binary_count=filesize/(2*sizeof(short));673 //}674 //else free(ptr);651 struct STD_stat st; 652 long filesize; 653 void* ptr; 654 FILE *fd; 655 656 if ( filename==0 ) 657 { unload_bad_pixels_list_b(); return; } 658 659 binary_count=-1; 660 if (safe_stat(filename,&st)!=0) return; 661 filesize=st.st_size; 662 if (filesize%(2*sizeof(short)) != 0) return; 663 if (filesize == 0) { binary_count = 0; return; } // Allow empty badpixel.bin file 664 ptr=malloc(filesize); 665 if (!ptr) return; 666 fd=fopen(filename, "rb"); 667 if (fd) { 668 fread(ptr,1, filesize,fd); 669 fclose(fd); 670 binary_list=ptr; 671 binary_count=filesize/(2*sizeof(short)); 672 } 673 else free(ptr); 675 674 } 676 675 677 676 void unload_bad_pixels_list_b(void) { 678 //if (binary_list) free(binary_list);679 //binary_list=NULL;680 //binary_count=-1;677 if (binary_list) free(binary_list); 678 binary_list=NULL; 679 binary_count=-1; 681 680 } 682 681 683 682 void patch_bad_pixels_b(void) { 684 //int i;685 //short* ptr=binary_list;686 //short y, cnt;687 //for (i=0; i<binary_count; i++, ptr+=2)688 //{689 //y = ptr[1] & 0x1FFF;690 //cnt = (ptr[1] >> 13) & 7;691 //for (; cnt>=0; cnt--, y++)692 //if (get_raw_pixel(ptr[0], y) <= DNG_BADPIXEL_VALUE_LIMIT)693 //patch_bad_pixel(ptr[0], y);694 //}683 int i; 684 short* ptr=binary_list; 685 short y, cnt; 686 for (i=0; i<binary_count; i++, ptr+=2) 687 { 688 y = ptr[1] & 0x1FFF; 689 cnt = (ptr[1] >> 13) & 7; 690 for (; cnt>=0; cnt--, y++) 691 if (get_raw_pixel(ptr[0], y) <= DNG_BADPIXEL_VALUE_LIMIT) 692 patch_bad_pixel(ptr[0], y); 693 } 695 694 } 696 695 697 696 int badpixel_list_loaded_b(void) { 698 // return (binary_count >= 0) ? 1 : 0; 697 return (binary_count >= 0) ? 1 : 0; 698 } 699 700 // ----------------------------------------------- 701 702 enum BadpixelFSM { 703 BADPIX_START, 704 BADPIX_S1, 705 BADPIX_S2 706 }; 707 708 int badpixel_task_stack(long p) { 709 static unsigned int badpix_cnt1; 710 711 switch(p) { 712 case BADPIX_START: 713 action_pop(); 714 715 console_clear(); 716 console_add_line("Wait please... "); 717 console_add_line("This takes a few seconds,"); 718 console_add_line("don't panic!"); 719 720 init_badpixel_bin_flag = INIT_BADPIXEL_COUNT; 721 722 shooting_set_tv96_direct(96, SET_LATER); 723 action_push(BADPIX_S1); 724 action_push(AS_SHOOT); 725 action_push_delay(3000); 726 break; 727 case BADPIX_S1: 728 action_pop(); 729 730 badpix_cnt1 = init_badpixel_bin_flag; 731 init_badpixel_bin_flag = INIT_BADPIXEL_FILE; 732 shooting_set_tv96_direct(96, SET_LATER); 733 734 action_push(BADPIX_S2); 735 action_push(AS_SHOOT); 736 break; 737 case BADPIX_S2: 738 action_pop(); 739 740 console_clear(); 741 if (badpix_cnt1 == init_badpixel_bin_flag) { 742 // TODO script asked confirmation first 743 // should sanity check bad pixel count at least, 744 // wrong buffer address could make badpixel bigger than available mem 745 char msg[32]; 746 console_add_line("badpixel.bin created."); 747 sprintf(msg, "Bad pixel count: %d", badpix_cnt1); 748 console_add_line(msg); 749 remove(PATH_BADPIXEL_BIN); 750 rename(PATH_BAD_TMP_BIN,PATH_BADPIXEL_BIN); 751 } else { 752 console_add_line("badpixel.bin failed."); 753 console_add_line("Please try again."); 754 } 755 init_badpixel_bin_flag = 0; 756 remove(PATH_BAD_TMP_BIN); 757 758 action_push_delay(3000); 759 break; 760 default: 761 action_stack_standard(p); 762 break; 763 } 764 699 765 return 1; 700 766 } 701 767 702 // -----------------------------------------------703 704 //enum BadpixelFSM {705 // BADPIX_START,706 // BADPIX_S1,707 // BADPIX_S2708 //};709 //710 //int badpixel_task_stack(long p) {711 // static unsigned int badpix_cnt1;712 //713 // switch(p) {714 // case BADPIX_START:715 // action_pop();716 //717 // console_clear();718 // console_add_line("Wait please... ");719 // console_add_line("This takes a few seconds,");720 // console_add_line("don't panic!");721 //722 // init_badpixel_bin_flag = INIT_BADPIXEL_COUNT;723 //724 // shooting_set_tv96_direct(96, SET_LATER);725 // action_push(BADPIX_S1);726 // action_push(AS_SHOOT);727 // action_push_delay(3000);728 // break;729 // case BADPIX_S1:730 // action_pop();731 //732 // badpix_cnt1 = init_badpixel_bin_flag;733 // init_badpixel_bin_flag = INIT_BADPIXEL_FILE;734 // shooting_set_tv96_direct(96, SET_LATER);735 //736 // action_push(BADPIX_S2);737 // action_push(AS_SHOOT);738 // break;739 // case BADPIX_S2:740 // action_pop();741 //742 // console_clear();743 // if (badpix_cnt1 == init_badpixel_bin_flag) {744 // // TODO script asked confirmation first745 // // should sanity check bad pixel count at least,746 // // wrong buffer address could make badpixel bigger than available mem747 // char msg[32];748 // console_add_line("badpixel.bin created.");749 // sprintf(msg, "Bad pixel count: %d", badpix_cnt1);750 // console_add_line(msg);751 // remove(PATH_BADPIXEL_BIN);752 // rename(PATH_BAD_TMP_BIN,PATH_BADPIXEL_BIN);753 // } else {754 // console_add_line("badpixel.bin failed.");755 // console_add_line("Please try again.");756 // }757 // init_badpixel_bin_flag = 0;758 // remove(PATH_BAD_TMP_BIN);759 //760 // action_push_delay(3000);761 // break;762 // default:763 // action_stack_standard(p);764 // break;765 // }766 //767 // return 1;768 //}769 770 768 771 769 void create_badpixel_bin() { 772 //if (!(mode_get() & MODE_REC)) {773 //gui_mbox_init(LANG_ERROR, LANG_MSG_RECMODE_REQUIRED, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL);774 //return;775 //}776 777 //gui_set_mode(&altGuiHandler);778 //action_stack_create(&badpixel_task_stack, BADPIX_START);770 if (!(mode_get() & MODE_REC)) { 771 gui_mbox_init(LANG_ERROR, LANG_MSG_RECMODE_REQUIRED, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL); 772 return; 773 } 774 775 gui_set_mode(&altGuiHandler); 776 action_stack_create(&badpixel_task_stack, BADPIX_START); 779 777 } 780 778 … … 789 787 { 790 788 fill_gamma_buf(); 791 //patch_bad_pixels_b(); 789 if (conf.dng_badpix_removal) 790 patch_bad_pixels_b(); 792 791 create_thumbnail(); 793 792 write(fd, dng_header_buf, dng_header_buf_size); … … 854 853 int _module_unloader() 855 854 { 856 857 855 unload_bad_pixels_list_b(); 858 856 free_dng_header();
Note: See TracChangeset
for help on using the changeset viewer.