Changeset 1796 for trunk/core/dng.c
- Timestamp:
- 04/11/12 03:12:35 (14 months ago)
- File:
-
- 1 edited
-
trunk/core/dng.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/dng.c
r1754 r1796 61 61 62 62 static struct t_data_for_exif exif_data; 63 64 #define BE(v) ((v&0x000000FF)<<24)|((v&0x0000FF00)<<8)|((v&0x00FF0000)>>8)|((v&0xFF000000)>>24) // Convert to big_endian 65 66 static unsigned int badpixel_opcode[] = 67 { 68 // *** all values must be in big endian order 69 70 BE(4), // Count = 4 71 72 BE(4), // FixBadPixelsConstant = 4 73 BE(0x01030000), // DNG version = 1.3.0.0 74 BE(1), // Flags = 1 75 BE(8), // Opcode length = 8 bytes 76 BE(0), // Constant = 0 77 #if cam_CFAPattern == 0x02010100 78 BE(0), // BayerPhase = 0 (top left pixel is red) 79 #elif cam_CFAPattern == 0x01020001 80 BE(1), // BayerPhase = 1 (top left pixel is green in a green/red row) 81 #elif cam_CFAPattern == 0x01000201 82 BE(2), // BayerPhase = 2 (top left pixel is green in a green/blue row) 83 #elif cam_CFAPattern == 0x00010102 84 BE(3), // BayerPhase = 3 (top left pixel is blue) 85 #endif 86 87 BE(4), // FixBadPixelsConstant = 4 88 BE(0x01030000), // DNG version = 1.3.0.0 89 BE(1), // Flags = 1 90 BE(8), // Opcode length = 8 bytes 91 BE(1), // Constant = 1 92 #if cam_CFAPattern == 0x02010100 93 BE(0), // BayerPhase = 0 (top left pixel is red) 94 #elif cam_CFAPattern == 0x01020001 95 BE(1), // BayerPhase = 1 (top left pixel is green in a green/red row) 96 #elif cam_CFAPattern == 0x01000201 97 BE(2), // BayerPhase = 2 (top left pixel is green in a green/blue row) 98 #elif cam_CFAPattern == 0x00010102 99 BE(3), // BayerPhase = 3 (top left pixel is blue) 100 #endif 101 102 BE(4), // FixBadPixelsConstant = 4 103 BE(0x01030000), // DNG version = 1.3.0.0 104 BE(1), // Flags = 1 105 BE(8), // Opcode length = 8 bytes 106 BE(2), // Constant = 2 107 #if cam_CFAPattern == 0x02010100 108 BE(0), // BayerPhase = 0 (top left pixel is red) 109 #elif cam_CFAPattern == 0x01020001 110 BE(1), // BayerPhase = 1 (top left pixel is green in a green/red row) 111 #elif cam_CFAPattern == 0x01000201 112 BE(2), // BayerPhase = 2 (top left pixel is green in a green/blue row) 113 #elif cam_CFAPattern == 0x00010102 114 BE(3), // BayerPhase = 3 (top left pixel is blue) 115 #endif 116 117 BE(4), // FixBadPixelsConstant = 4 118 BE(0x01030000), // DNG version = 1.3.0.0 119 BE(1), // Flags = 1 120 BE(8), // Opcode length = 8 bytes 121 BE(3), // Constant = 3 122 #if cam_CFAPattern == 0x02010100 123 BE(0), // BayerPhase = 0 (top left pixel is red) 124 #elif cam_CFAPattern == 0x01020001 125 BE(1), // BayerPhase = 1 (top left pixel is green in a green/red row) 126 #elif cam_CFAPattern == 0x01000201 127 BE(2), // BayerPhase = 2 (top left pixel is green in a green/blue row) 128 #elif cam_CFAPattern == 0x00010102 129 BE(3), // BayerPhase = 3 (top left pixel is blue) 130 #endif 131 }; 63 132 64 133 // warning: according to TIFF format specification, elements must be sorted by tag value in ascending order! … … 87 156 {0x8825, T_LONG, 1, 0}, //GPS_IFD offset 88 157 {0x9216, T_BYTE, 4, 0x00000001}, // TIFF/EPStandardID: 1.0.0.0 89 {0xC612, T_BYTE, 4, 0x00000 101}, //DNGVersion: 1.1.0.0158 {0xC612, T_BYTE, 4, 0x00000301}, //DNGVersion: 1.3.0.0 90 159 {0xC614, T_ASCII, 32, (int)cam_name}, //UniqueCameraModel. Filled at header generation. 91 160 {0xC621, T_SRATIONAL, 9, (int)&camera_sensor.color_matrix1}, … … 124 193 {0xC620, T_LONG, 2, (int)&camera_sensor.crop.size}, 125 194 {0xC68D, T_LONG, 4, (int)&camera_sensor.dng_active_area}, 195 {0xC740, T_UNDEFINED|T_PTR, sizeof(badpixel_opcode), (int)&badpixel_opcode}, 126 196 {0, T_END} 127 197 }; … … 533 603 // removal from images. 534 604 535 #define INIT_BADPIXEL_COUNT -1536 #define INIT_BADPIXEL_FILE -2537 538 #define PATH_BADPIXEL_BIN "A/CHDK/badpixel.bin"539 #define PATH_BAD_TMP_BIN "A/CHDK/bad_tmp.bin"540 541 int init_badpixel_bin_flag; // contants above to count/create file, > 0 num bad pixel542 605 //#define INIT_BADPIXEL_COUNT -1 606 //#define INIT_BADPIXEL_FILE -2 607 // 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 pixel 612 // 543 613 int raw_init_badpixel_bin() { 544 int count;545 unsigned short c[2];546 FILE*f;547 if(init_badpixel_bin_flag == INIT_BADPIXEL_FILE) {548 f=fopen(PATH_BAD_TMP_BIN,"w+b");549 } else if (init_badpixel_bin_flag == INIT_BADPIXEL_COUNT) {550 f=NULL;551 } else {552 return 0;553 }554 count = 0;555 for (c[0]=camera_sensor.active_area.x1; c[0]<camera_sensor.active_area.x2; c[0]++)556 {557 for (c[1]=camera_sensor.active_area.y1; c[1]<camera_sensor.active_area.y2; c[1]++)558 {559 if (get_raw_pixel(c[0],c[1]) <= DNG_BADPIXEL_VALUE_LIMIT)560 {561 unsigned short l;562 for (l=0; l<7 && (c[1]+l+1)<camera_sensor.active_area.y2; l++)563 if (get_raw_pixel(c[0],c[1]+l+1) > DNG_BADPIXEL_VALUE_LIMIT)564 break;565 c[1] = c[1] | (l << 13);566 if (f) fwrite(c, 1, 4, f);567 c[1] = (c[1] & 0x1FFF) + l;568 count = count + l + 1;569 }570 }571 }572 if (f) fclose(f);573 init_badpixel_bin_flag = count;574 state_shooting_progress = SHOOTING_PROGRESS_PROCESSING;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; 575 645 return 1; 576 646 } 577 647 578 short* binary_list=NULL;579 int binary_count=-1;648 //short* binary_list=NULL; 649 //int binary_count=-1; 580 650 581 651 void load_bad_pixels_list_b(char* filename) { 582 struct STD_stat st;583 long filesize;584 void* ptr;585 FILE *fd;586 587 if ( filename==0 )588 { unload_bad_pixels_list_b(); return; }589 590 binary_count=-1;591 if (safe_stat(filename,&st)!=0) return;592 filesize=st.st_size;593 if (filesize%(2*sizeof(short)) != 0) return;594 if (filesize == 0) { binary_count = 0; return; } // Allow empty badpixel.bin file595 ptr=malloc(filesize);596 if (!ptr) return;597 fd=fopen(filename, "rb");598 if (fd) {599 fread(ptr,1, filesize,fd);600 fclose(fd);601 binary_list=ptr;602 binary_count=filesize/(2*sizeof(short));603 }604 else free(ptr);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 file 665 // 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); 605 675 } 606 676 607 677 void unload_bad_pixels_list_b(void) { 608 if (binary_list) free(binary_list);609 binary_list=NULL;610 binary_count=-1;678 //if (binary_list) free(binary_list); 679 //binary_list=NULL; 680 //binary_count=-1; 611 681 } 612 682 613 683 void patch_bad_pixels_b(void) { 614 int i;615 short* ptr=binary_list;616 short y, cnt;617 for (i=0; i<binary_count; i++, ptr+=2)618 {619 y = ptr[1] & 0x1FFF;620 cnt = (ptr[1] >> 13) & 7;621 for (; cnt>=0; cnt--, y++)622 if (get_raw_pixel(ptr[0], y) <= DNG_BADPIXEL_VALUE_LIMIT)623 patch_bad_pixel(ptr[0], y);624 }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 //} 625 695 } 626 696 627 697 int badpixel_list_loaded_b(void) { 628 return (binary_count >= 0) ? 1 : 0; 698 // return (binary_count >= 0) ? 1 : 0; 699 return 1; 629 700 } 630 701 631 702 // ----------------------------------------------- 632 703 633 enum BadpixelFSM {634 BADPIX_START,635 BADPIX_S1,636 BADPIX_S2637 };638 639 int badpixel_task_stack(long p) {640 static unsigned int badpix_cnt1;641 642 switch(p) {643 case BADPIX_START:644 action_pop();645 646 console_clear();647 console_add_line("Wait please... ");648 console_add_line("This takes a few seconds,");649 console_add_line("don't panic!");650 651 init_badpixel_bin_flag = INIT_BADPIXEL_COUNT;652 653 shooting_set_tv96_direct(96, SET_LATER);654 action_push(BADPIX_S1);655 action_push(AS_SHOOT);656 action_push_delay(3000);657 break;658 case BADPIX_S1:659 action_pop();660 661 badpix_cnt1 = init_badpixel_bin_flag;662 init_badpixel_bin_flag = INIT_BADPIXEL_FILE;663 shooting_set_tv96_direct(96, SET_LATER);664 665 action_push(BADPIX_S2);666 action_push(AS_SHOOT);667 break;668 case BADPIX_S2:669 action_pop();670 671 console_clear();672 if (badpix_cnt1 == init_badpixel_bin_flag) {673 // TODO script asked confirmation first674 // should sanity check bad pixel count at least,675 // wrong buffer address could make badpixel bigger than available mem676 char msg[32];677 console_add_line("badpixel.bin created.");678 sprintf(msg, "Bad pixel count: %d", badpix_cnt1);679 console_add_line(msg);680 remove(PATH_BADPIXEL_BIN);681 rename(PATH_BAD_TMP_BIN,PATH_BADPIXEL_BIN);682 } else {683 console_add_line("badpixel.bin failed.");684 console_add_line("Please try again.");685 }686 init_badpixel_bin_flag = 0;687 remove(PATH_BAD_TMP_BIN);688 689 action_push_delay(3000);690 break;691 default:692 action_stack_standard(p);693 break;694 }695 696 return 1;697 }704 //enum BadpixelFSM { 705 // BADPIX_START, 706 // BADPIX_S1, 707 // BADPIX_S2 708 //}; 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 first 745 // // should sanity check bad pixel count at least, 746 // // wrong buffer address could make badpixel bigger than available mem 747 // 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 //} 698 769 699 770 700 771 void create_badpixel_bin() { 701 if (!(mode_get() & MODE_REC)) {702 gui_mbox_init(LANG_ERROR, LANG_MSG_RECMODE_REQUIRED, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL);703 return;704 }705 706 gui_set_mode(&altGuiHandler);707 action_stack_create(&badpixel_task_stack, BADPIX_START);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); 708 779 } 709 780 … … 718 789 { 719 790 fill_gamma_buf(); 720 patch_bad_pixels_b();791 //patch_bad_pixels_b(); 721 792 create_thumbnail(); 722 793 write(fd, dng_header_buf, dng_header_buf_size);
Note: See TracChangeset
for help on using the changeset viewer.