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