| 1 | #include "platform.h" |
|---|
| 2 | #include "core.h" |
|---|
| 3 | #include "conf.h" |
|---|
| 4 | #include "keyboard.h" |
|---|
| 5 | #include "stdlib.h" |
|---|
| 6 | #include "gui.h" |
|---|
| 7 | #include "histogram.h" |
|---|
| 8 | #include "raw.h" |
|---|
| 9 | #ifdef OPT_EDGEOVERLAY |
|---|
| 10 | #include "modules.h" |
|---|
| 11 | #endif |
|---|
| 12 | |
|---|
| 13 | #include "module_load.h" |
|---|
| 14 | #include "gui_draw.h" |
|---|
| 15 | |
|---|
| 16 | //========================================================== |
|---|
| 17 | // Data Structure to store camera specific information |
|---|
| 18 | // Used by modules to ensure module code is platform independent |
|---|
| 19 | |
|---|
| 20 | _cam_sensor camera_sensor = { |
|---|
| 21 | MAKE_API_VERSION(1,0), |
|---|
| 22 | |
|---|
| 23 | CAM_SENSOR_BITS_PER_PIXEL, |
|---|
| 24 | CAM_BLACK_LEVEL, CAM_WHITE_LEVEL, |
|---|
| 25 | CAM_RAW_ROWS, CAM_RAW_ROWPIX, (CAM_RAW_ROWPIX*CAM_SENSOR_BITS_PER_PIXEL)/8, CAM_RAW_ROWS * ((CAM_RAW_ROWPIX*CAM_SENSOR_BITS_PER_PIXEL)/8), |
|---|
| 26 | #if defined(CAM_ACTIVE_AREA_X1) && defined(CAM_JPEG_WIDTH) |
|---|
| 27 | {{ |
|---|
| 28 | (CAM_ACTIVE_AREA_X2-CAM_ACTIVE_AREA_X1-CAM_JPEG_WIDTH)/2, (CAM_ACTIVE_AREA_Y2-CAM_ACTIVE_AREA_Y1-CAM_JPEG_HEIGHT)/2, |
|---|
| 29 | CAM_JPEG_WIDTH, CAM_JPEG_HEIGHT |
|---|
| 30 | }}, |
|---|
| 31 | { { CAM_ACTIVE_AREA_Y1, CAM_ACTIVE_AREA_X1, CAM_ACTIVE_AREA_Y2, CAM_ACTIVE_AREA_X2 } }, |
|---|
| 32 | #else |
|---|
| 33 | {{ |
|---|
| 34 | 0, 0, |
|---|
| 35 | 0, 0 |
|---|
| 36 | }}, |
|---|
| 37 | { { 0, 0, 0, 0 } }, |
|---|
| 38 | #endif |
|---|
| 39 | #if defined(CAM_DNG_LENS_INFO) |
|---|
| 40 | CAM_DNG_LENS_INFO, |
|---|
| 41 | #else |
|---|
| 42 | { 0, 0, 0, 0, 0, 0, 0, 0 }, |
|---|
| 43 | #endif |
|---|
| 44 | #if defined(CAM_DNG_EXPOSURE_BIAS) |
|---|
| 45 | { CAM_DNG_EXPOSURE_BIAS }, |
|---|
| 46 | #else |
|---|
| 47 | { -1 , 2 }, |
|---|
| 48 | #endif |
|---|
| 49 | #if defined(CAM_COLORMATRIX1) |
|---|
| 50 | { CAM_COLORMATRIX1 }, |
|---|
| 51 | cam_CFAPattern, cam_CalibrationIlluminant1, |
|---|
| 52 | #else |
|---|
| 53 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
|---|
| 54 | 0, 0, |
|---|
| 55 | #endif |
|---|
| 56 | }; |
|---|
| 57 | |
|---|
| 58 | _cam_screen camera_screen = |
|---|
| 59 | { |
|---|
| 60 | CAM_SCREEN_WIDTH, CAM_SCREEN_HEIGHT, CAM_SCREEN_WIDTH * CAM_SCREEN_HEIGHT, |
|---|
| 61 | CAM_BITMAP_WIDTH, CAM_BITMAP_HEIGHT, CAM_BITMAP_WIDTH * CAM_BITMAP_HEIGHT, |
|---|
| 62 | EDGE_HMARGIN, CAM_TS_BUTTON_BORDER, |
|---|
| 63 | #if defined(CAM_ZEBRA_NOBUF) |
|---|
| 64 | 1, |
|---|
| 65 | #else |
|---|
| 66 | 0, |
|---|
| 67 | #endif |
|---|
| 68 | #if defined(CAM_ZEBRA_ASPECT_ADJUST) |
|---|
| 69 | 1, |
|---|
| 70 | #else |
|---|
| 71 | 0, |
|---|
| 72 | #endif |
|---|
| 73 | #if defined(CAM_HAS_VARIABLE_ASPECT) |
|---|
| 74 | 1, |
|---|
| 75 | #else |
|---|
| 76 | 0, |
|---|
| 77 | #endif |
|---|
| 78 | }; |
|---|
| 79 | |
|---|
| 80 | _cam_info camera_info = |
|---|
| 81 | { |
|---|
| 82 | MAKE_API_VERSION(1,0), |
|---|
| 83 | |
|---|
| 84 | { |
|---|
| 85 | #if defined(PARAM_CAMERA_NAME) |
|---|
| 86 | PARAM_CAMERA_NAME, |
|---|
| 87 | #else |
|---|
| 88 | 0, |
|---|
| 89 | #endif |
|---|
| 90 | }, |
|---|
| 91 | { |
|---|
| 92 | #if defined(CAM_HAS_GPS) |
|---|
| 93 | PROPCASE_GPS, |
|---|
| 94 | #else |
|---|
| 95 | 0, |
|---|
| 96 | #endif |
|---|
| 97 | PROPCASE_ORIENTATION_SENSOR, |
|---|
| 98 | PROPCASE_TV, PROPCASE_AV, PROPCASE_MIN_AV, |
|---|
| 99 | PROPCASE_EV_CORRECTION_2, |
|---|
| 100 | PROPCASE_FLASH_MODE, PROPCASE_FLASH_FIRE, |
|---|
| 101 | PROPCASE_METERING_MODE, PROPCASE_WB_ADJ, |
|---|
| 102 | #if defined(PROPCASE_ASPECT_RATIO) |
|---|
| 103 | PROPCASE_ASPECT_RATIO, |
|---|
| 104 | #else |
|---|
| 105 | 0, |
|---|
| 106 | #endif |
|---|
| 107 | PROPCASE_SHOOTING, |
|---|
| 108 | }, |
|---|
| 109 | ROMBASEADDR, MAXRAMADDR, |
|---|
| 110 | }; |
|---|
| 111 | |
|---|
| 112 | //========================================================== |
|---|
| 113 | |
|---|
| 114 | volatile int chdk_started_flag=0; |
|---|
| 115 | |
|---|
| 116 | static int raw_need_postprocess; |
|---|
| 117 | static volatile int spytask_can_start; |
|---|
| 118 | #ifdef CAM_HAS_GPS |
|---|
| 119 | extern void wegpunkt(); |
|---|
| 120 | #endif |
|---|
| 121 | |
|---|
| 122 | void core_hook_task_create(void *tcb) |
|---|
| 123 | { |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | void core_hook_task_delete(void *tcb) |
|---|
| 127 | { |
|---|
| 128 | char *name = (char*)(*(long*)((char*)tcb+0x34)); |
|---|
| 129 | if (strcmp(name,"tInitFileM")==0) core_spytask_can_start(); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | long core_get_noise_reduction_value() |
|---|
| 134 | { |
|---|
| 135 | return conf.raw_nr; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | void dump_memory() |
|---|
| 140 | { |
|---|
| 141 | int fd; |
|---|
| 142 | static int cnt=1; |
|---|
| 143 | static char fn[32]; |
|---|
| 144 | |
|---|
| 145 | started(); |
|---|
| 146 | mkdir("A/DCIM"); |
|---|
| 147 | mkdir("A/DCIM/100CANON"); |
|---|
| 148 | sprintf(fn, "A/DCIM/100CANON/CRW_%04d.JPG", cnt++); |
|---|
| 149 | fd = open(fn, O_WRONLY|O_CREAT, 0777); |
|---|
| 150 | if (fd) { |
|---|
| 151 | long val0 = *((long*)(0|CAM_UNCACHED_BIT)); |
|---|
| 152 | write(fd, &val0, 4); |
|---|
| 153 | write(fd, (void*)4, MAXRAMADDR-3); // MAXRAMADDR is last valid RAM location |
|---|
| 154 | close(fd); |
|---|
| 155 | } |
|---|
| 156 | vid_bitmap_refresh(); |
|---|
| 157 | finished(); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | int core_get_free_memory() |
|---|
| 161 | { |
|---|
| 162 | cam_meminfo camera_meminfo; |
|---|
| 163 | |
|---|
| 164 | #if defined(OPT_EXMEM_MALLOC) && !defined(OPT_EXMEM_TESTING) |
|---|
| 165 | // If using the exmem / suba memory allocation system then don't need |
|---|
| 166 | // to try allocating memory to find out how much is available |
|---|
| 167 | // Call function to scan free list for the largest free block available. |
|---|
| 168 | GetExMemInfo(&camera_meminfo); |
|---|
| 169 | #else |
|---|
| 170 | // Call function to fill memory info structure and return size of largest free block |
|---|
| 171 | // If implemented this will use firmware function, otherwise it will calculate largest |
|---|
| 172 | // free block |
|---|
| 173 | GetMemInfo(&camera_meminfo); |
|---|
| 174 | #endif |
|---|
| 175 | |
|---|
| 176 | return camera_meminfo.free_block_max_size; |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | static volatile long raw_data_available; |
|---|
| 180 | |
|---|
| 181 | /* called from another process */ |
|---|
| 182 | void core_rawdata_available() |
|---|
| 183 | { |
|---|
| 184 | raw_data_available = 1; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | void core_spytask_can_start() { |
|---|
| 188 | spytask_can_start = 1; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | void core_spytask() |
|---|
| 192 | { |
|---|
| 193 | int cnt = 1; |
|---|
| 194 | int i=0; |
|---|
| 195 | |
|---|
| 196 | raw_need_postprocess = 0; |
|---|
| 197 | |
|---|
| 198 | spytask_can_start=0; |
|---|
| 199 | |
|---|
| 200 | #ifdef OPT_EXMEM_MALLOC |
|---|
| 201 | exmem_malloc_init(); |
|---|
| 202 | #endif |
|---|
| 203 | |
|---|
| 204 | #ifdef CAM_CHDK_PTP |
|---|
| 205 | init_chdk_ptp_task(); |
|---|
| 206 | #endif |
|---|
| 207 | |
|---|
| 208 | while((i++<400) && !spytask_can_start) msleep(10); |
|---|
| 209 | |
|---|
| 210 | started(); |
|---|
| 211 | msleep(50); |
|---|
| 212 | finished(); |
|---|
| 213 | drv_self_unhide(); |
|---|
| 214 | |
|---|
| 215 | conf_restore(); |
|---|
| 216 | gui_init(); |
|---|
| 217 | |
|---|
| 218 | #if CAM_CONSOLE_LOG_ENABLED |
|---|
| 219 | extern void cam_console_init(); |
|---|
| 220 | cam_console_init(); |
|---|
| 221 | #endif |
|---|
| 222 | |
|---|
| 223 | mkdir("A/CHDK"); |
|---|
| 224 | mkdir("A/CHDK/FONTS"); |
|---|
| 225 | mkdir("A/CHDK/SYMBOLS"); |
|---|
| 226 | mkdir("A/CHDK/SCRIPTS"); |
|---|
| 227 | mkdir("A/CHDK/LANG"); |
|---|
| 228 | mkdir("A/CHDK/BOOKS"); |
|---|
| 229 | mkdir("A/CHDK/MODULES"); |
|---|
| 230 | mkdir("A/CHDK/MODULES/CFG"); |
|---|
| 231 | mkdir("A/CHDK/GRIDS"); |
|---|
| 232 | #ifdef OPT_CURVES |
|---|
| 233 | mkdir("A/CHDK/CURVES"); |
|---|
| 234 | #endif |
|---|
| 235 | mkdir("A/CHDK/DATA"); |
|---|
| 236 | mkdir("A/CHDK/LOGS"); |
|---|
| 237 | #ifdef OPT_EDGEOVERLAY |
|---|
| 238 | mkdir("A/CHDK/EDGE"); |
|---|
| 239 | #endif |
|---|
| 240 | auto_started = 0; |
|---|
| 241 | |
|---|
| 242 | #ifdef OPT_SCRIPTING |
|---|
| 243 | if (conf.script_startup==1) script_autostart(); // remote autostart |
|---|
| 244 | if (conf.script_startup==2) { |
|---|
| 245 | conf.script_startup=0; |
|---|
| 246 | conf_save(); |
|---|
| 247 | script_autostart(); |
|---|
| 248 | } |
|---|
| 249 | #endif |
|---|
| 250 | |
|---|
| 251 | while (1){ |
|---|
| 252 | |
|---|
| 253 | #ifdef CAM_LOAD_CUSTOM_COLORS |
|---|
| 254 | load_chdk_palette(); |
|---|
| 255 | #endif |
|---|
| 256 | |
|---|
| 257 | if (raw_data_available) { |
|---|
| 258 | raw_need_postprocess = raw_savefile(); |
|---|
| 259 | hook_raw_save_complete(); |
|---|
| 260 | raw_data_available = 0; |
|---|
| 261 | #ifdef CAM_HAS_GPS |
|---|
| 262 | if( (int)conf.gps_waypoint_save == 1 ) wegpunkt(); |
|---|
| 263 | #endif |
|---|
| 264 | continue; |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | if ((state_shooting_progress != SHOOTING_PROGRESS_PROCESSING) || recreview_hold) |
|---|
| 268 | { |
|---|
| 269 | if (((cnt++) & 3) == 0) |
|---|
| 270 | gui_redraw(); |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | if (state_shooting_progress != SHOOTING_PROGRESS_PROCESSING) |
|---|
| 274 | { |
|---|
| 275 | if (conf.show_histo) |
|---|
| 276 | histogram_process(); |
|---|
| 277 | |
|---|
| 278 | #ifdef OPT_EDGEOVERLAY |
|---|
| 279 | if(((gui_get_mode()==GUI_MODE_NONE) || (gui_get_mode()==GUI_MODE_ALT)) && conf.edge_overlay_thresh && conf.edge_overlay_enable) { |
|---|
| 280 | |
|---|
| 281 | // We need to skip first tick because stability |
|---|
| 282 | static int skip_counter=1; |
|---|
| 283 | |
|---|
| 284 | if (skip_counter>0) { |
|---|
| 285 | skip_counter--; |
|---|
| 286 | } |
|---|
| 287 | else if (module_edgeovr_load()) { |
|---|
| 288 | libedgeovr->edge_overlay(); |
|---|
| 289 | } |
|---|
| 290 | } |
|---|
| 291 | #endif |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | if ((state_shooting_progress == SHOOTING_PROGRESS_PROCESSING) && (!shooting_in_progress())) { |
|---|
| 295 | state_shooting_progress = SHOOTING_PROGRESS_DONE; |
|---|
| 296 | if (raw_need_postprocess) raw_postprocess(); |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | #ifdef DEBUG_PRINT_TO_LCD |
|---|
| 300 | char osd_buf[30]; |
|---|
| 301 | sprintf(osd_buf, "%d", cnt ); // modify cnt to what you want to display |
|---|
| 302 | draw_txt_string(2, 2, osd_buf, conf.osd_color); |
|---|
| 303 | #endif |
|---|
| 304 | |
|---|
| 305 | // Process async module unload requests |
|---|
| 306 | module_tick_unloader(); |
|---|
| 307 | |
|---|
| 308 | msleep(20); |
|---|
| 309 | chdk_started_flag=1; |
|---|
| 310 | } |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | long ftell(FILE *file) { |
|---|
| 314 | if(!file) return -1; |
|---|
| 315 | return file->pos; |
|---|
| 316 | } |
|---|