source: trunk/core/main.c @ 1352

Revision 1352, 4.5 KB checked in by philmoz, 21 months ago (diff)

Add colored icons from CHDK-DE (thx waterwingz).
Modified from CHDK-DE version to define the icon colors in gui_draw.h instead of gui_batt.c and gui_space.c.
Enabled for G10, G12, SX30 & IXUS310 - define CAM_USE_COLORED_ICONS in platform_camera.h to activate (may also need to fix icon color definitions in gui_draw.h for your camera as well).
Also adds custom color palette handling for G12, SX30 & IXUS310.

  • Property svn:eol-style set to native
Line 
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 "edgeoverlay.h"
11#endif
12static int raw_need_postprocess;
13static volatile int spytask_can_start;
14
15void core_hook_task_create(void *tcb) {
16}
17
18void core_hook_task_delete(void *tcb) {
19    char *name = (char*)(*(long*)((char*)tcb+0x34));
20    if (strcmp(name,"tInitFileM")==0) core_spytask_can_start();
21}
22
23long core_get_noise_reduction_value() {
24    return conf.raw_nr;
25}
26
27void dump_memory() {
28    int fd;
29    static int cnt=1;
30    static char fn[32];
31
32    started();
33    mkdir("A/DCIM");
34    mkdir("A/DCIM/100CANON");
35    sprintf(fn, "A/DCIM/100CANON/CRW_%04d.JPG", cnt++);
36    fd = open(fn, O_WRONLY|O_CREAT, 0777);
37    if (fd) {
38#ifdef CAMERA_ixus65_sd630    // Zero is not readable on ixus65!
39        write(fd, (int*)0xFFFF0000, 4);
40        write(fd, (int*)4, 0x1900-4);
41#else
42        write(fd, (void*)0, 0x1900);
43#endif
44        // TODO actual memory size is larger than 32 MB on many cameras!
45        write(fd, (void*)0x1900, 32*1024*1024-0x1900);
46        close(fd);
47    }
48    vid_bitmap_refresh();
49    finished();
50}
51
52int core_get_free_memory() {
53#if defined(OPT_EXMEM_MALLOC) && !defined(OPT_EXMEM_TESTING)
54        // If using the exmem / suba memory allocation system then don't need
55        // to try allocating memory to find out how much is available
56        // Call function to scan free list for the largest free block available.
57    cam_meminfo camera_meminfo;
58    GetExMemInfo(&camera_meminfo);
59    return camera_meminfo.free_block_max_size;
60#elif defined(CAM_FIRMWARE_MEMINFO)
61    // Call firmware function to fill memory info structure and return size of largest free block
62    cam_meminfo camera_meminfo;
63    GetMemInfo(&camera_meminfo);
64    return camera_meminfo.free_block_max_size;
65#else
66        int size, l_size, d;
67    char* ptr;
68
69    size = 16;
70    while (1) {
71        ptr= malloc(size);
72        if (ptr) {
73            free(ptr);
74            size <<= 1;
75        } else
76            break;
77    }
78
79    l_size = size;
80    size >>= 1;
81    d=1024;
82    while (d) {
83        ptr = malloc(size);
84        if (ptr) {
85            free(ptr);
86            d = l_size-size;
87            if (d<0) d=-d;
88            l_size = size;
89            size += d>>1;
90        } else {
91            d = size-l_size;
92            if (d<0) d=-d;
93            l_size = size;
94            size -= d>>1;
95        }
96       
97    }
98    return size-1;
99#endif
100}
101
102static volatile long raw_data_available;
103
104// called from another process
105void core_rawdata_available() {
106    raw_data_available = 1;
107}
108
109void core_spytask_can_start() {
110    spytask_can_start = 1;
111}
112
113void core_spytask() {
114    int cnt = 1;
115    int i=0;
116
117    raw_need_postprocess = 0;
118
119    spytask_can_start=0;
120
121#ifdef OPT_EXMEM_MALLOC
122        exmem_malloc_init();
123#endif
124
125#ifdef CAM_CHDK_PTP
126    init_chdk_ptp_task();
127#endif
128
129    while((i++<400) && !spytask_can_start) msleep(10);
130
131    started();
132    msleep(50);
133    finished();
134    drv_self_unhide();
135
136    conf_restore();
137    gui_init();
138
139#if CAM_CONSOLE_LOG_ENABLED
140    cam_console_init();
141#endif
142
143    mkdir("A/CHDK");
144    mkdir("A/CHDK/FONTS");
145    mkdir("A/CHDK/SYMBOLS");
146    mkdir("A/CHDK/SCRIPTS");
147    mkdir("A/CHDK/LANG");
148    mkdir("A/CHDK/BOOKS");
149    mkdir("A/CHDK/GRIDS");
150#ifdef OPT_CURVES
151    mkdir("A/CHDK/CURVES");
152#endif
153    mkdir("A/CHDK/DATA");
154    mkdir("A/CHDK/LOGS");
155#ifdef OPT_EDGEOVERLAY
156    mkdir("A/CHDK/EDGE");
157#endif
158    auto_started = 0;
159
160#ifdef OPT_SCRIPTING
161    if (conf.script_startup==1) script_autostart();    // remote autostart
162    if (conf.script_startup==2) {
163        conf.script_startup=0;
164        conf_save();
165        script_autostart();
166    }
167#endif
168
169    while (1) {
170
171#ifdef  CAM_LOAD_CUSTOM_COLORS
172        load_chdk_palette();
173#endif
174
175        if (raw_data_available) {
176            raw_need_postprocess = raw_savefile();
177            hook_raw_save_complete();
178            raw_data_available = 0;
179            continue;
180        }
181
182        if (state_shooting_progress != SHOOTING_PROGRESS_PROCESSING) {
183            if (((cnt++) & 3) == 0)
184                gui_redraw();
185
186            histogram_process();
187#ifdef OPT_EDGEOVERLAY
188            if(conf.edge_overlay_thresh && conf.edge_overlay_enable) edge_overlay();
189#endif
190        }
191
192        if ((state_shooting_progress == SHOOTING_PROGRESS_PROCESSING) && (!shooting_in_progress())) {
193            state_shooting_progress = SHOOTING_PROGRESS_DONE;
194            if (raw_need_postprocess) raw_postprocess();
195        }
196
197        msleep(20);
198    }
199}
200
201long ftell(FILE *file) {
202    if(!file) return -1;
203    return file->pos;
204}
Note: See TracBrowser for help on using the repository browser.