From 229feb9a13ce1a0f3ee1f99ecbf05be5cb802d79 Mon Sep 17 00:00:00 2001 From: reyalP Date: Sun, 9 Jan 2011 03:15:50 +0000 Subject: [PATCH] scriptless badpixel.bin creation, from ultimA in http://chdk.setepontos.com/index.php?topic=5793.msg59376#msg59376 git-svn-id: http://tools.assembla.com/svn/chdk/trunk@1035 6794e30b-3f2a-0410-a806-a2bbca1c07ff --- CHDK/LANG/english.lng | 4 +- CHDK/LANG/german.lng | 2 + CHDK/LANG/hungarian.lng | 2 + core/gui.c | 6 +++ core/gui_lang.c | 2 + core/gui_lang.h | 4 +- core/raw.c | 95 ++++++++++++++++++++++++++++++++++++++++- core/raw.h | 4 ++ 8 files changed, 116 insertions(+), 3 deletions(-) diff --git a/CHDK/LANG/english.lng b/CHDK/LANG/english.lng index ccebecf7..38a25cec 100644 --- a/CHDK/LANG/english.lng +++ b/CHDK/LANG/english.lng @@ -563,7 +563,7 @@ 423 "Rear curtain flash sync" 424 "DNG format" 425 "RAW buffer cached" -426 "Cannot load CHDK/badpixel.bin\nPlease run \nCHDK/SCRIPTS/TEST/badpixel.lua" +426 "Cannot load CHDK/badpixel.bin\nUse Create badpixel.bin in raw menu" 427 "Show raw saving time" 428 "Connect 4" 429 "Opponent:" @@ -594,3 +594,5 @@ 456 "Filter edges" 457 "Always show" 458 " Pano overlap (%)" +459 "Create badpixel.bin" +460 "You need to be in REC-mode\nfor this operation." diff --git a/CHDK/LANG/german.lng b/CHDK/LANG/german.lng index 081ee587..bf6f9786 100644 --- a/CHDK/LANG/german.lng +++ b/CHDK/LANG/german.lng @@ -576,3 +576,5 @@ 456 "Konturenfilterung" 457 "Kontinuierlich anz." 458 " Pano-Überlappung (%)" +459 "badpixel.bin erstellen" +460 "REC-Modus erforderlich." diff --git a/CHDK/LANG/hungarian.lng b/CHDK/LANG/hungarian.lng index 911c8a52..1118e054 100644 --- a/CHDK/LANG/hungarian.lng +++ b/CHDK/LANG/hungarian.lng @@ -582,3 +582,5 @@ 456 "Élek szürése" 457 "Folyamatos megjel." 458 " Átfedés (%)" +459 "badpixel.bin mentése" +460 "Elöbb lépj REC-modba." diff --git a/core/gui.c b/core/gui.c index 9606322c..43560936 100644 --- a/core/gui.c +++ b/core/gui.c @@ -281,6 +281,7 @@ static void cb_zebra_restore_screen(); static void cb_zebra_restore_osd(); #if DNG_SUPPORT static void cb_change_dng(); +void gui_menuproc_badpixel_create(int arg); #endif #if defined (DNG_EXT_FROM) static void cb_change_dng_usb_ext(); @@ -821,6 +822,7 @@ static CMenuItem raw_submenu_items[] = { #if DNG_SUPPORT {0x5c,LANG_MENU_DNG_FORMAT, MENUITEM_BOOL | MENUITEM_ARG_CALLBACK, &conf.dng_raw , (int)cb_change_dng }, {0x5c,LANG_MENU_RAW_DNG_EXT, MENUITEM_BOOL, &conf.raw_dng_ext}, + {0x2a,LANG_MENU_BADPIXEL_CREATE, MENUITEM_PROC, (int*)gui_menuproc_badpixel_create }, #endif {0x5c,LANG_MENU_RAW_CACHED, MENUITEM_BOOL, &conf.raw_cache }, {0x51,LANG_MENU_BACK, MENUITEM_UP }, @@ -1008,6 +1010,10 @@ void cb_change_dng(){ conf_change_dng(); if ((old==1) && (conf.dng_raw==0)) gui_mbox_init(LANG_ERROR, LANG_CANNOT_OPEN_BADPIXEL_FILE, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL); } + +void gui_menuproc_badpixel_create(int arg) { + create_badpixel_bin(); +} #endif #if defined (DNG_EXT_FROM) diff --git a/core/gui_lang.c b/core/gui_lang.c index 1380bf4b..7046adc6 100644 --- a/core/gui_lang.c +++ b/core/gui_lang.c @@ -579,6 +579,8 @@ static char* gui_lang_default = \ "456 \"Filter edges\"\n" "457 \"Always show\"\n" "458 \" Pano overlap (%)\"\n" +"459 \"Create badpixel.bin\"\n" +"460 \"You need to be in REC-mode\\nfor this operation.\"\n" ; //------------------------------------------------------------------- diff --git a/core/gui_lang.h b/core/gui_lang.h index 1309c58d..55f208a3 100644 --- a/core/gui_lang.h +++ b/core/gui_lang.h @@ -568,9 +568,11 @@ #define LANG_MENU_EDGE_FILTER 456 #define LANG_MENU_EDGE_SHOW 457 #define LANG_MENU_EDGE_PANO_OVERLAP 458 +#define LANG_MENU_BADPIXEL_CREATE 459 +#define LANG_MSG_RECMODE_REQUIRED 460 //------------------------------------------------------------------- -#define GUI_LANG_ITEMS 458 +#define GUI_LANG_ITEMS 460 //------------------------------------------------------------------- extern void gui_lang_init(); diff --git a/core/raw.c b/core/raw.c index 4df82abd..1b72e527 100644 --- a/core/raw.c +++ b/core/raw.c @@ -6,6 +6,11 @@ #if DNG_SUPPORT #include "dng.h" #include "math.h" + #include "keyboard.h" + #include "action_stack.h" + #include "gui_draw.h" + #include "gui_mbox.h" + #include "gui_lang.h" #endif #ifdef OPT_CURVES #include "curves.h" @@ -49,7 +54,7 @@ char* get_alt_raw_image_addr(void){ // return inactive buffer for cameras with m //------------------------------------------------------------------- -unsigned int get_bad_count_and_write_file(char *fn){ +unsigned int get_bad_count_and_write_file(const char *fn){ int count=0; unsigned short c[2]; FILE*f; @@ -122,6 +127,8 @@ int raw_savefile() { char* altrawadr = get_alt_raw_image_addr(); // ! ! ! exclusively for special script which creates badpixel.bin ! ! ! + // NOTE: get_bad_count_and_write_file() must be called from here and cannot be called + // outside of this function. if (conf.save_raw==255) conf.save_raw=get_bad_count_and_write_file("A/CHDK/bad_tmp.bin"); // @@ -441,4 +448,90 @@ void unpatch_bad_pixels_b(void){ int badpixel_list_loaded_b(void){ return binary_count; } + +// ----------------------------------------------- + +enum BadpixelFSM +{ + BADPIX_START, + BADPIX_S1, + BADPIX_S2 +}; + +int badpixel_task_stack(long p) +{ + static unsigned int badpix_cnt1, badpix_cnt2; + static int raw_conf_bck; + + switch(p) + { + + case BADPIX_START: + action_pop(); + + console_clear(); + console_add_line("Wait please... "); + console_add_line("This takes a few seconds,"); + console_add_line("don't panic!"); + + raw_conf_bck = conf.save_raw; + conf.save_raw = 255; + + shooting_set_tv96_direct(96, SET_LATER); + action_push(BADPIX_S1); + action_push(AS_SHOOT); + action_push_delay(3000); + break; + case BADPIX_S1: + action_pop(); + + badpix_cnt1 = conf.save_raw; + shooting_set_tv96_direct(96, SET_LATER); + + action_push(BADPIX_S2); + action_push(AS_SHOOT); + break; + case BADPIX_S2: + action_pop(); + + badpix_cnt2 = conf.save_raw; + conf.save_raw = raw_conf_bck; + + console_clear(); + if (badpix_cnt1 == badpix_cnt2) + { + char msg[32]; + console_add_line("badpixel.bin created."); + sprintf(msg, "Bad pixel count: %d", badpix_cnt1); + console_add_line(msg); + } + else + { + console_add_line("badpixel.bin failed."); + console_add_line("Please try again."); + } + + action_push_delay(3000); + break; + default: + action_stack_standard(p); + break; + } + + return 1; +} + + +void create_badpixel_bin() +{ + if (!(mode_get() & MODE_REC)) + { + gui_mbox_init(LANG_ERROR, LANG_MSG_RECMODE_REQUIRED, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL); + return; + } + + gui_set_mode(GUI_MODE_ALT); + action_stack_create(&badpixel_task_stack, BADPIX_START); +} + #endif diff --git a/core/raw.h b/core/raw.h index b9f5c7e4..534a021b 100644 --- a/core/raw.h +++ b/core/raw.h @@ -24,12 +24,16 @@ extern void raw_postprocess(); extern void raw_prepare_develop(const char* filename); extern void load_bad_pixels_list(const char* filename); unsigned short get_raw_pixel(unsigned int x,unsigned int y); + +#if DNG_SUPPORT void load_bad_pixels_list_b(char* filename); void unload_bad_pixels_list_b(void); void patch_bad_pixels_b(void); void unpatch_bad_pixels_b(void); int badpixel_list_loaded_b(void); char* get_raw_image_addr(void); +void create_badpixel_bin(); +#endif //------------------------------------------------------------------- #endif