| 1 | /* |
|---|
| 2 | * CHDK-FLAT Module System. |
|---|
| 3 | * |
|---|
| 4 | * (c)2011 Sergey Taranenko aka tsvstar |
|---|
| 5 | * |
|---|
| 6 | * Specific "shortcuts", dynamic libraries binding |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | #include "modules.h" |
|---|
| 10 | #include "module_load.h" |
|---|
| 11 | #include "camera.h" |
|---|
| 12 | #include "stdlib.h" |
|---|
| 13 | #include "conf.h" |
|---|
| 14 | #include "gui_draw.h" |
|---|
| 15 | #include "dng.h" |
|---|
| 16 | |
|---|
| 17 | /************* DYNAMIC LIBRARY RAWOPERATION ******/ |
|---|
| 18 | |
|---|
| 19 | #if CAM_SENSOR_BITS_PER_PIXEL==10 |
|---|
| 20 | #define MODULE_NAME_RAWOP "_rawop10.flt" |
|---|
| 21 | #elif CAM_SENSOR_BITS_PER_PIXEL==12 |
|---|
| 22 | #define MODULE_NAME_RAWOP "_rawop12.flt" |
|---|
| 23 | #else |
|---|
| 24 | #error define set_raw_pixel for sensor bit depth |
|---|
| 25 | #endif |
|---|
| 26 | |
|---|
| 27 | // This is to minimize sharing sym to use this lib in other modules |
|---|
| 28 | struct librawop_sym* librawop; |
|---|
| 29 | |
|---|
| 30 | static int bind_module_rawop( void** export_list ) |
|---|
| 31 | { |
|---|
| 32 | // Unbind |
|---|
| 33 | if ( !export_list ) { |
|---|
| 34 | librawop=0; |
|---|
| 35 | return 0; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | // Bind |
|---|
| 39 | if ( (unsigned int)export_list[0] != EXPORTLIST_MAGIC_NUMBER ) |
|---|
| 40 | return 1; |
|---|
| 41 | if ( (unsigned int)export_list[1] <3 ) |
|---|
| 42 | return 1; |
|---|
| 43 | |
|---|
| 44 | librawop = export_list[2]; |
|---|
| 45 | |
|---|
| 46 | if ( !librawop ) |
|---|
| 47 | return 1; |
|---|
| 48 | |
|---|
| 49 | /* NO API VERSION CHECK HERE - EACH MODULE CHECK THIS AGAINST ITS REQUIREMENT |
|---|
| 50 | if ( !API_VERSION_MATCH_REQUIREMENT( librawop->version, 1, 0 ) ) { |
|---|
| 51 | librawop=0; |
|---|
| 52 | return 1; |
|---|
| 53 | } |
|---|
| 54 | */ |
|---|
| 55 | |
|---|
| 56 | return 0; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | void module_rawop_unload() |
|---|
| 60 | { |
|---|
| 61 | if (librawop==0) |
|---|
| 62 | return; |
|---|
| 63 | |
|---|
| 64 | module_unload(MODULE_NAME_RAWOP); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | // Return: 0-fail, otherwise - bind list |
|---|
| 69 | struct librawop_sym* module_rawop_load() |
|---|
| 70 | { |
|---|
| 71 | static int module_idx=-1; |
|---|
| 72 | |
|---|
| 73 | if (librawop) |
|---|
| 74 | return librawop; |
|---|
| 75 | |
|---|
| 76 | module_idx=module_load(MODULE_NAME_RAWOP, bind_module_rawop ); |
|---|
| 77 | if ( module_idx<0 ) |
|---|
| 78 | module_unload(MODULE_NAME_RAWOP); |
|---|
| 79 | |
|---|
| 80 | return librawop; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | /************* DYNAMIC LIBRARY EDGE OVERLAY ******/ |
|---|
| 86 | |
|---|
| 87 | #define MODULE_NAME_EDGEOVR "edgeovr.flt" |
|---|
| 88 | |
|---|
| 89 | struct libedgeovr_sym* libedgeovr; |
|---|
| 90 | |
|---|
| 91 | static int bind_module_edgeovr( void** export_list ) |
|---|
| 92 | { |
|---|
| 93 | // Unbind |
|---|
| 94 | if ( !export_list ) { |
|---|
| 95 | libedgeovr =0; |
|---|
| 96 | return 0; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | // Bind |
|---|
| 100 | if ( (unsigned int)export_list[0] != EXPORTLIST_MAGIC_NUMBER ) |
|---|
| 101 | return 1; |
|---|
| 102 | if ( (unsigned int)export_list[1] <3 ) |
|---|
| 103 | return 1; |
|---|
| 104 | |
|---|
| 105 | libedgeovr = export_list[2]; |
|---|
| 106 | if ( !libedgeovr ) |
|---|
| 107 | return 1; |
|---|
| 108 | if ( !API_VERSION_MATCH_REQUIREMENT( libedgeovr->version, 1, 0 ) ) { |
|---|
| 109 | libedgeovr=0; |
|---|
| 110 | return 1; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | return 0; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | // Return: 0-fail, 1-ok |
|---|
| 117 | struct libedgeovr_sym* module_edgeovr_load() |
|---|
| 118 | { |
|---|
| 119 | if (libedgeovr) |
|---|
| 120 | return libedgeovr; |
|---|
| 121 | |
|---|
| 122 | // This flag is because edgeovr called each tick |
|---|
| 123 | // If module loading failed, then do not try to load it until reboot |
|---|
| 124 | // (otherwise we will try to load module each tick) |
|---|
| 125 | static int flag_load_fail = 0; |
|---|
| 126 | static int module_idx=-1; |
|---|
| 127 | |
|---|
| 128 | if ( flag_load_fail==0 ) |
|---|
| 129 | { |
|---|
| 130 | module_idx=module_load(MODULE_NAME_EDGEOVR, bind_module_edgeovr ); |
|---|
| 131 | if ( module_idx<0 ) { |
|---|
| 132 | flag_load_fail = 1; |
|---|
| 133 | module_unload(MODULE_NAME_EDGEOVR); |
|---|
| 134 | } |
|---|
| 135 | else { |
|---|
| 136 | // This library never unloaded once it is loaded |
|---|
| 137 | // Reason - it should keep its data during whole session |
|---|
| 138 | module_set_flags(module_idx, MODULE_FLAG_DISABLE_AUTOUNLOAD); |
|---|
| 139 | } |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | return libedgeovr; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | // edgeovr module will never unload to keep its picture |
|---|
| 147 | // void module_edgeovr_unload() {} |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | /************* DYNAMIC LIBRARY CURVES ******/ |
|---|
| 151 | |
|---|
| 152 | #define MODULE_NAME_CURVES "curves.flt" |
|---|
| 153 | |
|---|
| 154 | struct libcurves_sym* libcurves; |
|---|
| 155 | |
|---|
| 156 | static int bind_module_curves( void** export_list ) |
|---|
| 157 | { |
|---|
| 158 | // Unbind |
|---|
| 159 | if ( !export_list ) { |
|---|
| 160 | libcurves=0; |
|---|
| 161 | return 0; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | // Bind |
|---|
| 165 | if ( (unsigned int)export_list[0] != EXPORTLIST_MAGIC_NUMBER ) |
|---|
| 166 | return 1; |
|---|
| 167 | if ( (unsigned int)export_list[1] <3 ) |
|---|
| 168 | return 1; |
|---|
| 169 | |
|---|
| 170 | libcurves = export_list[2]; |
|---|
| 171 | |
|---|
| 172 | if ( !libcurves ) |
|---|
| 173 | return 1; |
|---|
| 174 | if ( !API_VERSION_MATCH_REQUIREMENT( libcurves->version, 1, 0 ) ) { |
|---|
| 175 | librawop=0; |
|---|
| 176 | return 1; |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | return 0; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | // Return: 0-fail, addr-ok |
|---|
| 183 | struct libcurves_sym* module_curves_load() |
|---|
| 184 | { |
|---|
| 185 | if (libcurves) |
|---|
| 186 | return libcurves; |
|---|
| 187 | |
|---|
| 188 | static int module_idx=-1; |
|---|
| 189 | |
|---|
| 190 | module_idx=module_load(MODULE_NAME_CURVES, bind_module_curves ); |
|---|
| 191 | if ( module_idx<0 ) |
|---|
| 192 | module_unload(MODULE_NAME_CURVES); |
|---|
| 193 | else { |
|---|
| 194 | // This library never unloaded once it is loaded |
|---|
| 195 | // Reason - changing mode mode from LUA stored inside module only |
|---|
| 196 | module_set_flags(module_idx, MODULE_FLAG_DISABLE_AUTOUNLOAD); |
|---|
| 197 | |
|---|
| 198 | // Initialize - in module |
|---|
| 199 | // curve_init_mode(); |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | return libcurves; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | /************* MODULE PALETTE ******/ |
|---|
| 207 | |
|---|
| 208 | void module_palette_run(int mode, color st_color, void (*on_select)(color clr)) |
|---|
| 209 | { |
|---|
| 210 | unsigned int argv[] = { mode, |
|---|
| 211 | (unsigned int)st_color, |
|---|
| 212 | (unsigned int)on_select }; |
|---|
| 213 | module_run("palette.flt", 0, sizeof(argv)/sizeof(argv[0]), argv, UNLOAD_IF_ERR); |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | /************* MODULE MPOPUP ******/ |
|---|
| 218 | |
|---|
| 219 | void module_mpopup_init(struct mpopup_item* popup_actions, const unsigned int flags, void (*on_select)(unsigned int actn), int mode) |
|---|
| 220 | { |
|---|
| 221 | unsigned int argv[] = { (unsigned int)popup_actions, |
|---|
| 222 | (unsigned int)flags, |
|---|
| 223 | (unsigned int)on_select, |
|---|
| 224 | (unsigned int)mode, |
|---|
| 225 | }; |
|---|
| 226 | module_run("mpopup.flt", 0, sizeof(argv)/sizeof(argv[0]), argv, UNLOAD_IF_ERR); |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | /************* MODULE FSELECT ******/ |
|---|
| 231 | |
|---|
| 232 | void module_fselect_init_w_mode(int title, const char* prev_dir, const char* default_dir, void (*on_select)(const char *fn), unsigned int key_redraw_mode) |
|---|
| 233 | { |
|---|
| 234 | unsigned int argv[] = { title, |
|---|
| 235 | (unsigned int)prev_dir, |
|---|
| 236 | (unsigned int)default_dir, |
|---|
| 237 | (unsigned int)on_select, |
|---|
| 238 | (unsigned int)key_redraw_mode, |
|---|
| 239 | }; |
|---|
| 240 | module_run("fselect.flt", 0, sizeof(argv)/sizeof(argv[0]), argv, UNLOAD_IF_ERR); |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | void module_fselect_init(int title, const char* prev_dir, const char* default_dir, void (*on_select)(const char *fn)) |
|---|
| 244 | { |
|---|
| 245 | module_fselect_init_w_mode(title, prev_dir, default_dir, on_select, 0/*key_redraw_mode*/); |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | /************* MODULE DNG ******/ |
|---|
| 251 | |
|---|
| 252 | #define MODULE_NAME_DNG "_dng.flt" |
|---|
| 253 | |
|---|
| 254 | // This is to keep module in memory while it required by anyone |
|---|
| 255 | static int module_dng_semaphore; |
|---|
| 256 | |
|---|
| 257 | struct libdng_sym* libdng; |
|---|
| 258 | |
|---|
| 259 | #if DNG_SUPPORT |
|---|
| 260 | static int bind_module_dng( void** export_list ) |
|---|
| 261 | { |
|---|
| 262 | // Unbind |
|---|
| 263 | if ( !export_list ) { |
|---|
| 264 | libdng=0; |
|---|
| 265 | return 0; |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | // Bind |
|---|
| 269 | if ( (unsigned int)export_list[0] != EXPORTLIST_MAGIC_NUMBER ) |
|---|
| 270 | return 1; |
|---|
| 271 | if ( (unsigned int)export_list[1] < 3 ) |
|---|
| 272 | return 1; |
|---|
| 273 | |
|---|
| 274 | libdng = export_list[2]; |
|---|
| 275 | if ( libdng==0 ) |
|---|
| 276 | return 1; |
|---|
| 277 | |
|---|
| 278 | if ( !API_VERSION_MATCH_REQUIREMENT( libdng->version, 1, 0 ) ) { |
|---|
| 279 | libdng=0; |
|---|
| 280 | return 1; |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | return 0; |
|---|
| 284 | } |
|---|
| 285 | #endif |
|---|
| 286 | |
|---|
| 287 | void module_dng_unload(int owner) |
|---|
| 288 | { |
|---|
| 289 | #if DNG_SUPPORT |
|---|
| 290 | if (libdng==0) |
|---|
| 291 | return; |
|---|
| 292 | |
|---|
| 293 | module_dng_semaphore&=~owner; |
|---|
| 294 | if (module_dng_semaphore) |
|---|
| 295 | return; |
|---|
| 296 | |
|---|
| 297 | module_unload(MODULE_NAME_DNG); |
|---|
| 298 | #endif |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | // Return: 0-fail, otherwise - bind list |
|---|
| 303 | struct libdng_sym* module_dng_load(int owner) |
|---|
| 304 | { |
|---|
| 305 | #if DNG_SUPPORT |
|---|
| 306 | static int module_idx=-1; |
|---|
| 307 | |
|---|
| 308 | module_dng_semaphore|=owner; |
|---|
| 309 | if (libdng) |
|---|
| 310 | return libdng; |
|---|
| 311 | |
|---|
| 312 | module_idx=module_load(MODULE_NAME_DNG, bind_module_dng ); |
|---|
| 313 | if ( module_idx<0 ) { |
|---|
| 314 | module_unload(MODULE_NAME_DNG); |
|---|
| 315 | module_dng_semaphore=0; |
|---|
| 316 | } |
|---|
| 317 | else { |
|---|
| 318 | // This module could be unloaded only manualy (because store badpixel) |
|---|
| 319 | module_set_flags(module_idx, MODULE_FLAG_DISABLE_AUTOUNLOAD); |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | return libdng; |
|---|
| 323 | #else |
|---|
| 324 | return 0; |
|---|
| 325 | #endif |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | // Make convertion or check operation exsitsing |
|---|
| 329 | // Parameter: fn = filename or 0 to just check is operation possible |
|---|
| 330 | // Return: 0-fail, 1-ok |
|---|
| 331 | //-------------------------------------------------------- |
|---|
| 332 | int module_convert_dng_to_chdk_raw(char* fn) |
|---|
| 333 | { |
|---|
| 334 | #if DNG_SUPPORT |
|---|
| 335 | if ( fn==0 ) |
|---|
| 336 | return module_check_is_exist(MODULE_NAME_DNG); |
|---|
| 337 | if ( !module_dng_load(LIBDNG_OWNED_BY_CONVERT) ) |
|---|
| 338 | return 0; |
|---|
| 339 | libdng->convert_dng_to_chdk_raw(fn); |
|---|
| 340 | module_dng_unload(LIBDNG_OWNED_BY_CONVERT); |
|---|
| 341 | return 1; |
|---|
| 342 | #else |
|---|
| 343 | return 0; |
|---|
| 344 | #endif |
|---|
| 345 | } |
|---|