| 1 | #include "edgeoverlay.h" |
|---|
| 2 | #include "platform.h" |
|---|
| 3 | #include "conf.h" |
|---|
| 4 | #include "keyboard.h" |
|---|
| 5 | #include "stdlib.h" |
|---|
| 6 | #include "gui_draw.h" |
|---|
| 7 | |
|---|
| 8 | // until the edge thresh is put into conf structure I have hardcoded the threshold see "thresh" below |
|---|
| 9 | static char * imgbuf = 0; |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | void edge_overlay(){ |
|---|
| 13 | |
|---|
| 14 | //if(!(conf.edge_overlay_thresh) || !(conf.edge_overlay_enable)) return; |
|---|
| 15 | |
|---|
| 16 | static int inmem=0; |
|---|
| 17 | static int viewport_height; |
|---|
| 18 | static int viewport_width;// screenwidth * 3 |
|---|
| 19 | static int viewport_size; |
|---|
| 20 | static int shotTaken = 0; |
|---|
| 21 | static int imgmem = 0; |
|---|
| 22 | static int ymin = 0; |
|---|
| 23 | static int thresh; |
|---|
| 24 | thresh = conf.edge_overlay_thresh; //40 |
|---|
| 25 | static int xoffset = 0; |
|---|
| 26 | static int yoffset = 0; |
|---|
| 27 | static int full_press = 0;//cure for flaky behavior. due to multiple returns to the scrip during one full press |
|---|
| 28 | static char strbuf[7] = "Frozen"; |
|---|
| 29 | static unsigned char *img; |
|---|
| 30 | int i, hi, c; |
|---|
| 31 | int x, y, h, v, ymax, y1, x1, y2; |
|---|
| 32 | char * ptrh1; |
|---|
| 33 | char * ptrh2; |
|---|
| 34 | char * ptrv1; |
|---|
| 35 | char * ptrv2; |
|---|
| 36 | char * optr; |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | img = vid_get_viewport_fb(); |
|---|
| 40 | viewport_height = vid_get_viewport_height(); |
|---|
| 41 | viewport_width = screen_width * 3; |
|---|
| 42 | viewport_size = viewport_height * screen_width; |
|---|
| 43 | if(imgbuf == 0) imgbuf = malloc(viewport_size * 3); |
|---|
| 44 | |
|---|
| 45 | if((mode_get()&MODE_MASK) != MODE_PLAY) { |
|---|
| 46 | if (kbd_is_key_pressed(KEY_RIGHT)) { |
|---|
| 47 | xoffset -=XINC; |
|---|
| 48 | } |
|---|
| 49 | if (kbd_is_key_pressed(KEY_LEFT)) { |
|---|
| 50 | xoffset +=XINC; |
|---|
| 51 | } |
|---|
| 52 | if (kbd_is_key_pressed(KEY_DOWN)) { |
|---|
| 53 | yoffset -=YINC; |
|---|
| 54 | } |
|---|
| 55 | if (kbd_is_key_pressed(KEY_UP)) { |
|---|
| 56 | yoffset +=YINC; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | if (kbd_is_key_pressed(KEY_SHOOT_HALF)||kbd_is_key_pressed(KEY_SHOOT_FULL)) { |
|---|
| 60 | if (kbd_is_key_pressed(KEY_SHOOT_FULL) && !full_press) { |
|---|
| 61 | shotTaken = 1 - shotTaken; |
|---|
| 62 | memcpy(imgbuf,img,viewport_size * 3); |
|---|
| 63 | ymin = CALCYMARGIN; |
|---|
| 64 | inmem = 1; |
|---|
| 65 | full_press = 1; |
|---|
| 66 | xoffset = 0; |
|---|
| 67 | yoffset = 0; |
|---|
| 68 | return; |
|---|
| 69 | } |
|---|
| 70 | if(shotTaken) { |
|---|
| 71 | return; |
|---|
| 72 | } |
|---|
| 73 | memcpy(imgbuf,img,viewport_size * 3); |
|---|
| 74 | ymin = CALCYMARGIN; |
|---|
| 75 | inmem = 1; |
|---|
| 76 | xoffset = 0; |
|---|
| 77 | yoffset = 0; |
|---|
| 78 | return; |
|---|
| 79 | } |
|---|
| 80 | else full_press = 0; |
|---|
| 81 | if (inmem && (ymin < screen_height-CALCYMARGIN)) { |
|---|
| 82 | ymax = ymin + (screen_height - 2 * CALCYMARGIN) / NSTAGES; |
|---|
| 83 | if(ymax > screen_height - CALCYMARGIN) ymax = screen_height - CALCYMARGIN; |
|---|
| 84 | for (y=ymin; y<ymax; y++) { |
|---|
| 85 | ptrh1 = imgbuf + y * viewport_width + 7; |
|---|
| 86 | ptrh2 = imgbuf + y * viewport_width - 5; |
|---|
| 87 | ptrv1 = imgbuf + (y + 1) * viewport_width + 1; |
|---|
| 88 | ptrv2 = imgbuf + (y - 1) * viewport_width + 1; |
|---|
| 89 | optr = imgbuf + y * viewport_width + 3; |
|---|
| 90 | for (x=12; x<(screen_width- 4) * 3; x+=6) { |
|---|
| 91 | h = ptrh1[x] - ptrh2[x]; |
|---|
| 92 | if(h < 0) h = -h; |
|---|
| 93 | v = ptrv1[x] - ptrv2[x]; |
|---|
| 94 | if(v < 0) v = -v; |
|---|
| 95 | optr[x] = h + v; |
|---|
| 96 | h = ptrh1[x + 3] - ptrh2[x + 3]; |
|---|
| 97 | if(h < 0) h = -h; |
|---|
| 98 | v = ptrv1[x + 3] - ptrv2[x + 3]; |
|---|
| 99 | if(v < 0) v = -v; |
|---|
| 100 | optr[x + 2] = h + v; |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | ymin += (screen_height - 2 * CALCYMARGIN) / NSTAGES; |
|---|
| 104 | return; |
|---|
| 105 | } |
|---|
| 106 | if(inmem &&(ymin >= screen_height-CALCYMARGIN) && |
|---|
| 107 | ((gui_get_mode() == GUI_MODE_NONE) || (gui_get_mode() == GUI_MODE_ALT))){ |
|---|
| 108 | //thresh = (conf.edge_overlay_thresh - 1) * 12; |
|---|
| 109 | for (y=MARGIN; y<screen_height-MARGIN; y++) { |
|---|
| 110 | y1 = y + yoffset; |
|---|
| 111 | if((y1 < CALCYMARGIN) || (y1 >= screen_height - CALCYMARGIN)) { |
|---|
| 112 | for (x=MARGIN; x < screen_width - MARGIN; x+=2) { |
|---|
| 113 | draw_pixel(x, y, 0); |
|---|
| 114 | draw_pixel(x+1, y, 0); |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | else { |
|---|
| 118 | for (x=MARGIN; x < screen_width - MARGIN; x+=2) { |
|---|
| 119 | x1 = x + xoffset; |
|---|
| 120 | if((x1 < 12) || (x1 >= screen_width-13)) { |
|---|
| 121 | draw_pixel(x, y, 0); |
|---|
| 122 | draw_pixel(x+1, y, 0); |
|---|
| 123 | } |
|---|
| 124 | else { |
|---|
| 125 | c = 0; |
|---|
| 126 | if(imgbuf[y1 * viewport_width + x1 * 3 + 3] > thresh) |
|---|
| 127 | c = conf.edge_overlay_color; |
|---|
| 128 | draw_pixel(x, y, c); |
|---|
| 129 | c = 0; |
|---|
| 130 | if(imgbuf[y1 * viewport_width + x1 * 3 + 5] > thresh) |
|---|
| 131 | c = conf.edge_overlay_color; |
|---|
| 132 | draw_pixel(x+1, y, c); |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | for (y2=MARGIN; y2<screen_height-MARGIN; y2++) { |
|---|
| 137 | draw_pixel(XGRID1,y2,0xff); |
|---|
| 138 | draw_pixel(XGRID2,y2,0xff); |
|---|
| 139 | if(y2 == YGRID1) for (x=MARGIN; x < screen_width - MARGIN; x++) draw_pixel(x,y2,0xff); |
|---|
| 140 | if(y2 == YGRID2) for (x=MARGIN; x < screen_width - MARGIN; x++) draw_pixel(x,y2,0xff); |
|---|
| 141 | } |
|---|
| 142 | if(shotTaken) draw_string(30, 10, strbuf, conf.osd_color); |
|---|
| 143 | } |
|---|
| 144 | return; |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | else { |
|---|
| 148 | full_press = 0; |
|---|
| 149 | inmem = 0; |
|---|
| 150 | shotTaken = 0; |
|---|
| 151 | ymin = 0; |
|---|
| 152 | xoffset = 0; |
|---|
| 153 | yoffset = 0; |
|---|
| 154 | } |
|---|
| 155 | return; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | /*// Code to test the idea of an edge overlay |
|---|
| 160 | // Put edge_overlay(); after the line histogram_process(); |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | // Put the following after the line #include "motion_detector.h" in main.c |
|---|
| 164 | #include "gui_draw.h" |
|---|
| 165 | |
|---|
| 166 | // until the edge thresh is put into conf structure I have hardcoded the threshold see "thresh" below |
|---|
| 167 | static char * imgbuf = 0; |
|---|
| 168 | |
|---|
| 169 | #define MARGIN 30 |
|---|
| 170 | #define CALCYMARGIN 3 |
|---|
| 171 | #define EDGECOLOR 0x66 |
|---|
| 172 | #define NSTAGES 4 |
|---|
| 173 | #define XINC 6 |
|---|
| 174 | #define YINC 2 |
|---|
| 175 | #define XGRID1 120 |
|---|
| 176 | #define XGRID2 240 |
|---|
| 177 | #define YGRID1 80 |
|---|
| 178 | #define YGRID2 160 |
|---|
| 179 | |
|---|
| 180 | void edge_overlay(){ |
|---|
| 181 | static int inmem=0; |
|---|
| 182 | static int viewport_height; |
|---|
| 183 | static int viewport_width;// screenwidth * 3 |
|---|
| 184 | static int viewport_size; |
|---|
| 185 | static int shotTaken = 0; |
|---|
| 186 | static int imgmem = 0; |
|---|
| 187 | static int ymin = 0; |
|---|
| 188 | static int thresh = 40; |
|---|
| 189 | static int xoffset = 0; |
|---|
| 190 | static int yoffset = 0; |
|---|
| 191 | static int full_press = 0;//cure for flaky behavior. due to multiple returns to the scrip during one full press |
|---|
| 192 | static char strbuf[7] = "Frozen"; |
|---|
| 193 | static unsigned char *img; |
|---|
| 194 | int i, hi, c; |
|---|
| 195 | int x, y, h, v, ymax, y1, x1, y2; |
|---|
| 196 | char * ptrh1; |
|---|
| 197 | char * ptrh2; |
|---|
| 198 | char * ptrv1; |
|---|
| 199 | char * ptrv2; |
|---|
| 200 | char * optr; |
|---|
| 201 | |
|---|
| 202 | // if(!conf.edge_thresh) return; |
|---|
| 203 | |
|---|
| 204 | img = vid_get_viewport_fb(); |
|---|
| 205 | viewport_height = vid_get_viewport_height(); |
|---|
| 206 | viewport_width = screen_width * 3; |
|---|
| 207 | viewport_size = viewport_height * screen_width; |
|---|
| 208 | if(imgbuf == 0) imgbuf = malloc(viewport_size * 3); |
|---|
| 209 | |
|---|
| 210 | if((mode_get()&MODE_MASK) != MODE_PLAY) { |
|---|
| 211 | if (kbd_is_key_pressed(KEY_RIGHT)) { |
|---|
| 212 | xoffset -=XINC; |
|---|
| 213 | } |
|---|
| 214 | if (kbd_is_key_pressed(KEY_LEFT)) { |
|---|
| 215 | xoffset +=XINC; |
|---|
| 216 | } |
|---|
| 217 | if (kbd_is_key_pressed(KEY_DOWN)) { |
|---|
| 218 | yoffset -=YINC; |
|---|
| 219 | } |
|---|
| 220 | if (kbd_is_key_pressed(KEY_UP)) { |
|---|
| 221 | yoffset +=YINC; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | if (kbd_is_key_pressed(KEY_SHOOT_HALF)||kbd_is_key_pressed(KEY_SHOOT_FULL)) { |
|---|
| 225 | if (kbd_is_key_pressed(KEY_SHOOT_FULL) && !full_press) { |
|---|
| 226 | shotTaken = 1 - shotTaken; |
|---|
| 227 | memcpy(imgbuf,img,viewport_size * 3); |
|---|
| 228 | ymin = CALCYMARGIN; |
|---|
| 229 | inmem = 1; |
|---|
| 230 | full_press = 1; |
|---|
| 231 | xoffset = 0; |
|---|
| 232 | yoffset = 0; |
|---|
| 233 | return; |
|---|
| 234 | } |
|---|
| 235 | if(shotTaken) { |
|---|
| 236 | return; |
|---|
| 237 | } |
|---|
| 238 | memcpy(imgbuf,img,viewport_size * 3); |
|---|
| 239 | ymin = CALCYMARGIN; |
|---|
| 240 | inmem = 1; |
|---|
| 241 | xoffset = 0; |
|---|
| 242 | yoffset = 0; |
|---|
| 243 | return; |
|---|
| 244 | } |
|---|
| 245 | else full_press = 0; |
|---|
| 246 | if (inmem && (ymin < screen_height-CALCYMARGIN)) { |
|---|
| 247 | ymax = ymin + (screen_height - 2 * CALCYMARGIN) / NSTAGES; |
|---|
| 248 | if(ymax > screen_height - CALCYMARGIN) ymax = screen_height - CALCYMARGIN; |
|---|
| 249 | for (y=ymin; y<ymax; y++) { |
|---|
| 250 | ptrh1 = imgbuf + y * viewport_width + 7; |
|---|
| 251 | ptrh2 = imgbuf + y * viewport_width - 5; |
|---|
| 252 | ptrv1 = imgbuf + (y + 1) * viewport_width + 1; |
|---|
| 253 | ptrv2 = imgbuf + (y - 1) * viewport_width + 1; |
|---|
| 254 | optr = imgbuf + y * viewport_width + 3; |
|---|
| 255 | for (x=12; x<(screen_width- 4) * 3; x+=6) { |
|---|
| 256 | h = ptrh1[x] - ptrh2[x]; |
|---|
| 257 | if(h < 0) h = -h; |
|---|
| 258 | v = ptrv1[x] - ptrv2[x]; |
|---|
| 259 | if(v < 0) v = -v; |
|---|
| 260 | optr[x] = h + v; |
|---|
| 261 | h = ptrh1[x + 3] - ptrh2[x + 3]; |
|---|
| 262 | if(h < 0) h = -h; |
|---|
| 263 | v = ptrv1[x + 3] - ptrv2[x + 3]; |
|---|
| 264 | if(v < 0) v = -v; |
|---|
| 265 | optr[x + 2] = h + v; |
|---|
| 266 | } |
|---|
| 267 | } |
|---|
| 268 | ymin += (screen_height - 2 * CALCYMARGIN) / NSTAGES; |
|---|
| 269 | return; |
|---|
| 270 | } |
|---|
| 271 | if(inmem &&(ymin >= screen_height-CALCYMARGIN) && |
|---|
| 272 | ((gui_get_mode() == GUI_MODE_NONE) || (gui_get_mode() == GUI_MODE_ALT))){ |
|---|
| 273 | // thresh = (conf.edge_thresh - 1) * 12; |
|---|
| 274 | for (y=MARGIN; y<screen_height-MARGIN; y++) { |
|---|
| 275 | y1 = y + yoffset; |
|---|
| 276 | if((y1 < CALCYMARGIN) || (y1 >= screen_height - CALCYMARGIN)) { |
|---|
| 277 | for (x=MARGIN; x < screen_width - MARGIN; x+=2) { |
|---|
| 278 | draw_pixel(x, y, 0); |
|---|
| 279 | draw_pixel(x+1, y, 0); |
|---|
| 280 | } |
|---|
| 281 | } |
|---|
| 282 | else { |
|---|
| 283 | for (x=MARGIN; x < screen_width - MARGIN; x+=2) { |
|---|
| 284 | x1 = x + xoffset; |
|---|
| 285 | if((x1 < 12) || (x1 >= screen_width-13)) { |
|---|
| 286 | draw_pixel(x, y, 0); |
|---|
| 287 | draw_pixel(x+1, y, 0); |
|---|
| 288 | } |
|---|
| 289 | else { |
|---|
| 290 | c = 0; |
|---|
| 291 | if(imgbuf[y1 * viewport_width + x1 * 3 + 3] > thresh) |
|---|
| 292 | c = EDGECOLOR; |
|---|
| 293 | draw_pixel(x, y, c); |
|---|
| 294 | c = 0; |
|---|
| 295 | if(imgbuf[y1 * viewport_width + x1 * 3 + 5] > thresh) |
|---|
| 296 | c = EDGECOLOR; |
|---|
| 297 | draw_pixel(x+1, y, c); |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | for (y2=MARGIN; y2<screen_height-MARGIN; y2++) { |
|---|
| 302 | draw_pixel(XGRID1,y2,0xff); |
|---|
| 303 | draw_pixel(XGRID2,y2,0xff); |
|---|
| 304 | if(y2 == YGRID1) for (x=MARGIN; x < screen_width - MARGIN; x++) draw_pixel(x,y2,0xff); |
|---|
| 305 | if(y2 == YGRID2) for (x=MARGIN; x < screen_width - MARGIN; x++) draw_pixel(x,y2,0xff); |
|---|
| 306 | } |
|---|
| 307 | if(shotTaken) draw_string(30, 10, strbuf, conf.osd_color); |
|---|
| 308 | } |
|---|
| 309 | return; |
|---|
| 310 | } |
|---|
| 311 | } |
|---|
| 312 | else { |
|---|
| 313 | full_press = 0; |
|---|
| 314 | inmem = 0; |
|---|
| 315 | shotTaken = 0; |
|---|
| 316 | ymin = 0; |
|---|
| 317 | xoffset = 0; |
|---|
| 318 | yoffset = 0; |
|---|
| 319 | } |
|---|
| 320 | return; |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | //End of edge detector code. next put edge_overlay(); after the line histogram_process(); |
|---|
| 324 | */ |
|---|