CHDK_DE Vorschauversion  Trunk Rev. 5779
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
edgeoverlay.c-Dateireferenz
#include "camera_info.h"
#include "conf.h"
#include "keyboard.h"
#include "modes.h"
#include "viewport.h"
#include "shooting.h"
#include "gui.h"
#include "gui_draw.h"
#include "gui_lang.h"
#include "bitvector.h"
#include "time.h"
#include "dirent.h"
#include "ctype.h"
#include "edgeoverlay.h"
#include "module_def.h"
+ Include-Abhängigkeitsdiagramm für edgeoverlay.c:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define EDGE_FILE_PREFIX   "EDG_"
 
#define EDGE_FILE_FORMAT   EDGE_FILE_PREFIX "%04d.edg"
 
#define EDGE_SLICES   2
 
#define XINC   6
 
#define YINC   2
 

Typdefinitionen

typedef enum _edge_fsm_state edge_fsm_state_t
 

Aufzählungen

enum  _edge_fsm_state { EDGE_LIVE = 0, EDGE_FROZEN }
 

Funktionen

static void get_viewport_size ()
 
static void ensure_allocate_imagebuffer ()
 
static void reset_edge_overlay ()
 
static int is_buffer_ready ()
 
static int get_edge_file_num (const char *fn)
 
void save_edge_overlay (void)
 
void load_edge_overlay (const char *fn)
 
static void average_filter_row (const unsigned char *ptrh1, unsigned char *smptr, int x, int x_max)
 
static int calc_edge_overlay ()
 
static int draw_edge_overlay ()
 
static void set_offset_from_overlap ()
 
void edge_overlay ()
 
int _module_loader (__attribute__((unused)) unsigned int *chdk_export_list)
 
int _module_unloader ()
 
int _module_can_unload ()
 

Variablen

static edge_fsm_state_t fsm_state = EDGE_LIVE
 
static bit_vector_tedgebuf = NULL
 
static int xoffset = 0
 
static int yoffset = 0
 
static unsigned char * smbuf = NULL
 
static int slice = 0
 
static int slice_height
 
static int viewport_byte_width
 
static int viewport_yscale
 
static int viewport_height
 
static int viewport_width
 
static int viewport_xoffset
 
static int viewport_yoffset
 
libedgeovr_sym _libedgeovr
 
ModuleInfo _module_info
 

Makro-Dokumentation

#define EDGE_FILE_FORMAT   EDGE_FILE_PREFIX "%04d.edg"

Definiert in Zeile 22 der Datei edgeoverlay.c.

#define EDGE_FILE_PREFIX   "EDG_"

Definiert in Zeile 21 der Datei edgeoverlay.c.

#define EDGE_SLICES   2

Definiert in Zeile 23 der Datei edgeoverlay.c.

#define XINC   6

Definiert in Zeile 26 der Datei edgeoverlay.c.

#define YINC   2

Definiert in Zeile 27 der Datei edgeoverlay.c.

Dokumentation der benutzerdefinierten Typen

Dokumentation der Aufzählungstypen

Aufzählungswerte
EDGE_LIVE 
EDGE_FROZEN 

Definiert in Zeile 29 der Datei edgeoverlay.c.

30 {
31  EDGE_LIVE = 0,

Dokumentation der Funktionen

int _module_can_unload ( )

Definiert in Zeile 928 der Datei edgeoverlay.c.

929 {
930  return conf.edge_overlay_enable == 0;
931 }
int _module_loader ( __attribute__((unused)) unsigned int *  chdk_export_list)

Definiert in Zeile 901 der Datei edgeoverlay.c.

902 {
904  return 0;
905 }
int _module_unloader ( )

Definiert in Zeile 912 der Datei edgeoverlay.c.

913 {
914  // Save state info
916 
917  // Module can be unloaded when menu exits
918  // Free filter buffer
919  if (smbuf != NULL)
920  {
921  free(smbuf);
922  smbuf = NULL;
923  }
924 
925  return 0;
926 }
static void average_filter_row ( const unsigned char *  ptrh1,
unsigned char *  smptr,
int  x,
int  x_max 
)
static

Definiert in Zeile 218 der Datei edgeoverlay.c.

221 {
222  const unsigned char* ptrh2 = ptrh1 + viewport_byte_width*viewport_yscale; // current row
223  const unsigned char* ptrh3 = ptrh2 + viewport_byte_width*viewport_yscale; // next row
224 #ifndef THUMB_FW
225  for (; x<x_max; x+=6)
226  {
227  *(smptr + x + 1) = (*(ptrh1 + x - 1) +
228  *(ptrh1 + x + 1) +
229  *(ptrh1 + x + 3) +
230 
231  *(ptrh2 + x - 1) +
232  *(ptrh2 + x + 1) +
233  *(ptrh2 + x + 3) +
234 
235  *(ptrh3 + x - 1) +
236  *(ptrh3 + x + 1) +
237  *(ptrh3 + x + 3)) / 9u;
238 
239  *(smptr + x + 3) = (*(ptrh1 + x + 1) +
240  *(ptrh1 + x + 3) +
241  *(ptrh1 + x + 4) +
242 
243  *(ptrh2 + x + 1) +
244  *(ptrh2 + x + 3) +
245  *(ptrh2 + x + 4) +
246 
247  *(ptrh3 + x + 1) +
248  *(ptrh3 + x + 3) +
249  *(ptrh3 + x + 4)) / 9u;
250 
251  *(smptr + x + 4) = (*(ptrh1 + x + 3) +
252  *(ptrh1 + x + 4) +
253  *(ptrh1 + x + 5) +
254 
255  *(ptrh2 + x + 3) +
256  *(ptrh2 + x + 4) +
257  *(ptrh2 + x + 5) +
258 
259  *(ptrh3 + x + 3) +
260  *(ptrh3 + x + 4) +
261  *(ptrh3 + x + 5)) / 9u;
262 
263  *(smptr + x + 5) = (*(ptrh1 + x + 4) +
264  *(ptrh1 + x + 5) +
265  *(ptrh1 + x + 7) +
266 
267  *(ptrh2 + x + 4) +
268  *(ptrh2 + x + 5) +
269  *(ptrh2 + x + 7) +
270 
271  *(ptrh3 + x + 4) +
272  *(ptrh3 + x + 5) +
273  *(ptrh3 + x + 7)) / 9u;
274  }
275 
276  // copy 2nd last column to last column to prevent vertical stripe artifact.
277  smptr[x+1] = smptr[x-5];
278  smptr[x+3] = smptr[x-3];
279  smptr[x+4] = smptr[x-2];
280  smptr[x+5] = smptr[x-1];
281 }
static int calc_edge_overlay ( )
static

Definiert in Zeile 343 der Datei edgeoverlay.c.

344 {
345  int shutter_fullpress = kbd_is_key_pressed(KEY_SHOOT_FULL);
346 
347  const unsigned char* img = vid_get_viewport_active_buffer();
348  if (!img) return shutter_fullpress;
349 
350  const unsigned char* ptrh1 = NULL; // previous pixel line
351  const unsigned char* ptrh2 = NULL; // current pixel line
352  const unsigned char* ptrh3 = NULL; // next pixel line
353  unsigned char* smptr = NULL; // pointer to line in smbuf
354  int x, y, xdiv3;
355  int conv1, conv2;
356 
357  const int y_min = camera_screen.edge_hmargin+ slice *slice_height;
358  const int y_max = camera_screen.edge_hmargin+(slice+1)*slice_height;
359 #ifndef THUMB_FW
360  const int x_min = 6;
361  const int x_max = (viewport_width - 2) * 3;
362 #else
363  const int x_min = 8;
364  const int x_max = (viewport_width - 4) * 2;
365 #endif
366  img += vid_get_viewport_image_offset(); // offset into viewport for when image size != viewport size (e.g. 16:9 image on 4:3 LCD)
367 
368  xoffset = 0;
369  yoffset = 0;
370 
371  // Reserve buffers
373  if( !is_buffer_ready() ) return 0;
374 
375  // In every 6 bytes the Y of four pixels are described in the
376  // viewport (UYVYYY format). For edge detection we only
377  // consider the second in the current and the first
378  // in the next pixel.
379 
380  // Clear all edges in the current slice
381  int compressed_slice = edgebuf->ptrLen / EDGE_SLICES;
382  memset(edgebuf->ptr + slice*compressed_slice, 0, compressed_slice);
383 
385  {
386  // Prefill smbuf with three lines of avergae-filtered data.
387  // This looks much more complex then it actually is.
388  // We really are just summing up nine pixels in a 3x3 box
389  // and averaging the current pixel based on them. And
390  // we do it 4 bytes at a time because of the UYVYYY format.
391  for (y = -1; y <= 1; ++y)
392  {
393  shutter_fullpress |= kbd_is_key_pressed(KEY_SHOOT_FULL);
394 
395  ptrh1 = img + (y_min+y-1) * viewport_byte_width*viewport_yscale;
396  smptr = smbuf + (y+1) * viewport_byte_width;
397 
398  average_filter_row(ptrh1, smptr, x_min, x_max);
399  }
400  }
401 
402  for (y = y_min; y < y_max; ++y)
403  {
404  shutter_fullpress |= kbd_is_key_pressed(KEY_SHOOT_FULL);
405 
407  {
408  // We need to shift up our smbuf one line,
409  // and fill in the last line (which now empty)
410  // with average-filtered data from img.
411  // By storing only three lines of smoothed picture
412  // in memory, we save memory.
413 
414  // Shift
416 
417  // Filter new line
418  ptrh1 = img + y * viewport_byte_width*viewport_yscale;
419  smptr = smbuf + 2 * viewport_byte_width;
420  average_filter_row(ptrh1, smptr, x_min, x_max);
421 
422  ptrh1 = smbuf;
423  }
424  else
425  {
426  ptrh1 = img + (y-1) * viewport_byte_width*viewport_yscale;
427  }
428  ptrh2 = ptrh1 + viewport_byte_width*viewport_yscale;
429  ptrh3 = ptrh2 + viewport_byte_width*viewport_yscale;
430 
431  // Now we do sobel on the current line
432 #ifndef THUMB_FW
433  for (x = x_min, xdiv3 = x_min/3; x < x_max; x += 6, xdiv3 += 2)
434  {
435  // convolve vert (second Y)
436  conv1 = *(ptrh1 + x + 1) * ( 1) +
437  *(ptrh1 + x + 4) * (-1) +
438 
439  *(ptrh2 + x + 1) * ( 2) +
440  *(ptrh2 + x + 4) * (-2) +
441 
442  *(ptrh3 + x + 1) * ( 1) +
443  *(ptrh3 + x + 4) * (-1);
444  if (conv1 < 0) // abs()
445  conv1 = -conv1;
446 
447  // convolve vert (first Y of next pixel)
448  conv2 = *(ptrh1 + x + 1) * ( 1) +
449  *(ptrh1 + x + 3) * ( 2) +
450  *(ptrh1 + x + 4) * ( 1) +
451 
452  *(ptrh3 + x + 1) * (-1) +
453  *(ptrh3 + x + 3) * (-2) +
454  *(ptrh3 + x + 4) * (-1);
455  if (conv2 < 0) // abs()
456  conv2 = -conv2;
457 
458  if (conv1 + conv2 > conf.edge_overlay_thresh)
459  {
461  }
462 
463  // Do it once again for the next 'pixel'
464 
465  // convolve vert (second Y)
466  conv1 = *(ptrh1 + x + 5) * ( 1) +
467  *(ptrh1 + x + 9) * (-1) +
468 
469  *(ptrh2 + x + 5) * ( 2) +
470  *(ptrh2 + x + 9) * (-2) +
471 
472  *(ptrh3 + x + 5) * ( 1) +
473  *(ptrh3 + x + 9) * (-1);
474  if (conv1 < 0) // abs()
475  conv1 = -conv1;
476 
477  // convolve vert (first Y of next pixel)
478  conv2 = *(ptrh1 + x + 5) * ( 1) +
479  *(ptrh1 + x + 7) * ( 2) +
480  *(ptrh1 + x + 9) * ( 1) +
481 
482  *(ptrh3 + x + 5) * (-1) +
483  *(ptrh3 + x + 7) * (-2) +
484  *(ptrh3 + x + 9) * (-1);
485  if (conv2 < 0) // abs()
486  conv2 = -conv2;
487 
488  if (conv1 + conv2 > conf.edge_overlay_thresh)
489  {
491  }
492  } // for x
493  } // for y
494 
495 #else
496  for (x = x_min, xdiv3 = x_min/2; x < x_max; x += 4, xdiv3 += 2)
497  { // 1 231 2 3
498  // convolve vert (second Y) // 1 234 5 678 >> 1 2 3 4 5 6
499  conv1 = *(ptrh1 + x + 1) * ( 1) + // UYVYYY UYVYYY >> UYVY UYVY UYVY
500  *(ptrh1 + x + 5) * (-1) + // 012345 678901 >> 0123 4567 8901
501 
502  *(ptrh2 + x + 1) * ( 2) +
503  *(ptrh2 + x + 5) * (-2) +
504 
505  *(ptrh3 + x + 1) * ( 1) +
506  *(ptrh3 + x + 5) * (-1);
507  if (conv1 < 0) // abs()
508  conv1 = -conv1;
509 
510  // convolve vert (first Y of next pixel)
511  conv2 = *(ptrh1 + x + 1) * ( 1) +
512  *(ptrh1 + x + 3) * ( 2) +
513  *(ptrh1 + x + 5) * ( 1) +
514 
515  *(ptrh3 + x + 1) * (-1) +
516  *(ptrh3 + x + 3) * (-2) +
517  *(ptrh3 + x + 5) * (-1);
518  if (conv2 < 0) // abs()
519  conv2 = -conv2;
520 
521  if (conv1 + conv2 > conf.edge_overlay_thresh)
522  {
524  }
525 
526  // Do it once again for the next 'pixel'
527 
528  // convolve vert (second Y)
529  conv1 = *(ptrh1 + x + 7) * ( 1) +
530  *(ptrh1 + x + 11) * (-1) +
531 
532  *(ptrh2 + x + 7) * ( 2) +
533  *(ptrh2 + x + 11) * (-2) +
534 
535  *(ptrh3 + x + 7) * ( 1) +
536  *(ptrh3 + x + 11) * (-1);
537  if (conv1 < 0) // abs()
538  conv1 = -conv1;
539 
540  // convolve vert (first Y of next pixel)
541  conv2 = *(ptrh1 + x + 7) * ( 1) +
542  *(ptrh1 + x + 9) * ( 2) +
543  *(ptrh1 + x + 11) * ( 1) +
544 
545  *(ptrh3 + x + 7) * (-1) +
546  *(ptrh3 + x + 9) * (-2) +
547  *(ptrh3 + x + 11) * (-1);
548  if (conv2 < 0) // abs()
549  conv2 = -conv2;
550 
551  if (conv1 + conv2 > conf.edge_overlay_thresh)
552  {
554  }
555  } // for x
556  } // for y
557 #endif
558 
559 // For an even more improved edge overlay, enabling the following lines will
560 // post-filter the results of the edge detection, removing false edge 'dots'
561 // from the display. However, the speed hit is large. In the developer's opinion
562 // this code is not needed, but if you want that additional quality and do not
563 // care so much about performance, you can enable it.
564 //
565 // if (conf.edge_overlay_filter)
566 // {
567 // // Here we do basic filtering on the detected edges.
568 // // If a pixel is marked as edge but just a few of its
569 // // neighbors are also edges, then we assume that the
570 // // current pixel is just noise and delete the mark.
571 //
572 // bit_vector_t* bv_tmp = bv_create(edgebuf->nElem, edgebuf->nBits);
573 // if (bv_tmp != NULL)
574 // {
575 // memset(bv_tmp->ptr, 0, bv_tmp->ptrLen);
576 //
577 // for (y = 1; y < viewport_height-1; ++y)
578 // {
579 // shutter_fullpress |= kbd_is_key_pressed(KEY_SHOOT_FULL);
580 //
581 // for (x=12; x<(viewport_width - 4); ++x)
582 // {
583 // int bEdge = bv_get(edgebuf, y*viewport_width + x);
584 // if (bEdge)
585 // {
586 // // Count the number of neighbor edges
587 // int sum =
588 // bv_get(edgebuf, (y-1)*viewport_width + (x-1)) +
589 // bv_get(edgebuf, (y-1)*viewport_width + (x)) +
590 // bv_get(edgebuf, (y-1)*viewport_width + (x+1)) +
591 //
592 // bv_get(edgebuf, (y)*viewport_width + (x-1)) +
594 // bv_get(edgebuf, (y)*viewport_width + (x+1)) +
595 //
596 // bv_get(edgebuf, (y+1)*viewport_width + (x-1)) +
597 // bv_get(edgebuf, (y+1)*viewport_width + (x)) +
598 // bv_get(edgebuf, (y+1)*viewport_width + (x+1));
599 //
600 // if (!conf.edge_overlay_show)
601 // {
602 // if (sum >= 5) // if we have at least 5 neighboring edges
603 // bv_set(bv_tmp, y*viewport_width + x, 1); // keep the edge
604 // // else
605 // // there is no need to delete because the buffer is already zeroed
606 // }
607 // }
608 // } // for x
609 // } // for y
610 //
611 // // Swap the filtered edge buffer for the real one
612 // bit_vector_t* swap_tmp = edgebuf;
613 // edgebuf = bv_tmp;
614 // bv_free(swap_tmp);
615 // } // NULL-check
616 // } // if filtering
617 
618  return shutter_fullpress;
619 }
static int draw_edge_overlay ( )
static

Definiert in Zeile 621 der Datei edgeoverlay.c.

622 {
623  int shutter_fullpress = kbd_is_key_pressed(KEY_SHOOT_FULL);
624 
625  int x, y;
626  int x_off, y_off;
627 
629  const int y_slice_min = camera_screen.edge_hmargin+ slice *slice_height;
630  const int y_slice_max = camera_screen.edge_hmargin+(slice+1)*slice_height;
631  const int y_min = camera_screen.edge_hmargin;
632  const int y_max = camera_screen.edge_hmargin+viewport_height;
633  const int x_min = 2;
634  const int x_max = (viewport_width - 2);
635 
636  if( !is_buffer_ready() ) return 0;
637 
638  for (y = y_slice_min; y < y_slice_max; ++y)
639  {
640  y_off = y + yoffset;
641 
642  shutter_fullpress |= kbd_is_key_pressed(KEY_SHOOT_FULL);
643 
644  if ((y_off > y_min) && (y_off < y_max)) // do not draw outside of allowed area
645  {
646  const int y_edgebuf = (y-y_min) * viewport_width;
647 
648  for (x = x_min; x < x_max; ++x)
649  {
650  x_off = x + xoffset;
651 
652  if ((x_off > x_min) && (x_off < x_max)) // do not draw outside of allowed area
653  {
654  // Draw a pixel to the screen wherever we detected an edge.
655  // If there is no edge based on the newest data, but there is one painted on the screen
656  // from previous calls, delete it from the screen.
657  const int bEdge = bv_get(edgebuf, y_edgebuf + x);
658  // TODO draw_get_pixel_unrotated not implemented for digic 6
659  const int bDraw = bEdge || (draw_get_pixel_unrotated(x_off+viewport_xoffset, y_off+viewport_yoffset) == cl);
660  if (bEdge || bDraw)
661  draw_pixel_unrotated(x_off+viewport_xoffset, y_off+viewport_yoffset, bEdge ? cl : 0);
662 
663  }
664  } // for x
665  }
666  } // for y
667 
668 
669  // Drawing the overlay is over.
670  // But as a finishing touch we clear up garbage on the screen
671  // by clearing those parts that the overlay has left.
672 
673  if (xoffset != 0)
674  {
675  // Cleans up leftover from horizontal motion
676 
677  const int x_min_c = (xoffset < 0) ? x_max + xoffset : x_min;
678  const int x_max_c = (xoffset > 0) ? x_min + xoffset : x_max;
679 
680  for (y = y_min; y < y_max; ++y)
681  {
682  for (x = x_min_c; x < x_max_c; ++x)
683  {
684  // if there is an edge drawn on the screen but there is no edge there based on the newest data, delete it from the screen
687  }
688  }
689  }
690 
691  if (yoffset != 0)
692  {
693  // Cleans up leftover from vertical motion
694 
695  const int y_min_c = (yoffset < 0) ? y_max + yoffset : y_min;
696  const int y_max_c = (yoffset > 0) ? y_min + yoffset : y_max;
697 
698  for (y = y_min_c; y < y_max_c; ++y)
699  {
700  for (x = x_min; x < x_max; ++x)
701  {
702  // if there is an edge drawn on the screen but there is no edge there based on the newest data, delete it from the screen
705  }
706  }
707  }
708 
709  return shutter_fullpress;
710 }
void edge_overlay ( )

Definiert in Zeile 751 der Datei edgeoverlay.c.

752 {
753  // Was the shutter fully pressed the last time we ran?
754  // We use this to make sure that the user has released
755  // the button before processing the next FullPress event.
756  // This prevents switching FSM states more than once
757  // per press.
758  static int bFullPress_prev = 0;
759 
760  // Have we already started taking pictures in panorama mode?
761  // We use this variable to be able to detect if panorama
762  // mode has been turned off.
763  static int bPanoInProgress = 0;
764 
765  // Precalculate some values to make the rest of the
766  // code easier to read.
767  int bFullPress = kbd_is_key_pressed(KEY_SHOOT_FULL);
768  const int bHalfPress = camera_info.state.is_shutter_half_press;
769  const int bPlayMode = camera_info.state.mode_play;
770  const int bPanoramaMode = (conf.edge_overlay_pano != 0);
771  const int bNeedHalfPress = (conf.edge_overlay_show != 1);
772  const int bDisplayInPlay = (conf.edge_overlay_play == 1);
773  const int bCanDisplay = (
774  (!bPlayMode && (bHalfPress || !bNeedHalfPress)) || // we have a HalfPress in rec-mode
775  ( bPlayMode && bDisplayInPlay) // or we are in play-mode with the right settings
776  );
777 
778  if (bPanoInProgress && !bPanoramaMode)
779  {
780  // This means panorama mode has been recently
781  // turned off in the menu. So let's release
782  // Frozen mode for the user.
784  bPanoInProgress = 0;
785  }
786 
788 
789  // For just two states a state machine is not actually needed.
790  // But it is scalable in the future in case anybody
791  // wants to extend the functionality of edge overlay.
792  switch (fsm_state)
793  {
794  case EDGE_LIVE:
795  {
797  // In this state we assume no edge overlay in memory,
798  // but we are ready to create one if the user presses wishes so.
799 
800  int bRealtimeUpdate = bCanDisplay && (camera_info.state.gui_mode_alt || camera_info.state.gui_mode_none);
801  if (bRealtimeUpdate)
802  {
803  // We try to detect button presses during the lengthy
804  // calculations.
805  bFullPress |= calc_edge_overlay();
806  bFullPress |= draw_edge_overlay();
807  }
808 
809  int bSwitch2Frozen = bFullPress && !bFullPress_prev && camera_info.state.gui_mode_none;
810  if (bSwitch2Frozen)
811  {
812  // Switch to Frozen mode
813 
814  // Make sure we have one whole consistent frame
815  for (slice = 0; slice < EDGE_SLICES; ++slice)
817 
820  bPanoInProgress = bPanoramaMode;
821  }
822 
823  if (!bRealtimeUpdate && !bSwitch2Frozen)
824  {
825  // Nothing happens. So do nothing.
826  // Or rather, we could clean up if we are that bored.
828  }
829  break;
830  }
831  case EDGE_FROZEN:
832  {
834  // We have a stored edge overlay in memory and we display
835  // it on screen in 'frozen' mode.
836 
837  // Move edge overlay around.
839  {
841  xoffset +=XINC;
843  xoffset -=XINC;
845  yoffset +=YINC;
847  yoffset -=YINC;
848  }
849 
851  {
852  // We try to detect button presses during the lengthy
853  // calculations.
854  bFullPress |= draw_edge_overlay();
855  //draw_string(0, 0, "Frozen", user_color(conf.osd_color));
856  }
857 
858  // In event of a FullPress, we either capture a new
859  // overlay and stay frozen, OR we go back to live mode.
860  if (bFullPress && !bFullPress_prev && camera_info.state.gui_mode_none)
861  {
862  // Possible mode switch
863  if (bPanoramaMode)
864  {
865  // Make sure we have one whole consistent frame
866  for (slice = 0; slice < EDGE_SLICES; ++slice)
868 
870  bPanoInProgress = 1;
871  }
872  else
874  }
875 
876  break;
877  } // case
878  } // switch
879 
880 
881  bFullPress_prev = bFullPress;
882 
883  if (++slice >= EDGE_SLICES)
884  slice = 0;
885 
886 } // function
static void ensure_allocate_imagebuffer ( )
static

Definiert in Zeile 63 der Datei edgeoverlay.c.

64 {
65  if (edgebuf == NULL)
66  {
68  if (edgebuf != NULL)
70  }
71  if (conf.edge_overlay_filter && (smbuf == NULL))
72  {
73  smbuf = (unsigned char*)malloc(viewport_byte_width*3);
74  if (smbuf != NULL)
76  else
77  {
78  // Disable filtering if we do not have enough memory for it
80  }
81  }
82 }
static int get_edge_file_num ( const char *  fn)
static

Definiert in Zeile 114 der Datei edgeoverlay.c.

115 {
116  int num = 0;
117  if( strncmp(fn,EDGE_FILE_PREFIX,sizeof(EDGE_FILE_PREFIX)-1) == 0 )
118  {
119  // has the correct beginning at least, now try to read as a number...
120  fn += sizeof(EDGE_FILE_PREFIX);
121  while( *fn == '0' ) // skip leading 0s
122  {
123  ++fn;
124  }
125  while( isdigit(*fn) )
126  {
127  num *= 10;
128  num += *fn - '0';
129  ++fn;
130  }
131  // ignore anything else after it, that is like the ending etc.
132  }
133  return num;
134 }
static int is_buffer_ready ( )
static

Definiert in Zeile 106 der Datei edgeoverlay.c.

107 {
108  if (edgebuf == NULL) return 0;
109  if (edgebuf->ptr == NULL) return 0; // this should never happen, but it does not hurt to check
110  return 1;
111 }
void load_edge_overlay ( const char *  fn)

Definiert in Zeile 194 der Datei edgeoverlay.c.

195 {
196  FILE *fd;
197  int zoom;
198 
201  fd = fopen(fn,"rb");
202  if( fd != NULL )
203  {
204  int ret = fread(edgebuf->ptr,edgebuf->ptrLen,1,fd);
205  int ret2 = fread (&zoom,sizeof(zoom),1,fd);
206  fclose(fd);
207  if( (ret == 1) && (ret2 == 1) )
208  {
209  fsm_state = EDGE_FROZEN; // switch to "edge overlay frozen"-mode
211  {
212  shooting_set_zoom(zoom);
213  }
214  }
215  }
216 }
static void reset_edge_overlay ( )
static

Definiert in Zeile 84 der Datei edgeoverlay.c.

85 {
86  if (smbuf != NULL)
87  {
88  free(smbuf);
89  smbuf = NULL;
90  }
91 
92  if (edgebuf != NULL)
93  {
94  gui_set_need_restore(); // Refresh display to restore Canon OSD
96  edgebuf = NULL;
97  }
98 
100  slice = 0;
101 
102  // Clean up state saved in core CHDK
104 }
void save_edge_overlay ( void  )

Definiert in Zeile 137 der Datei edgeoverlay.c.

138 {
139 
140  char fn[64];
141  char msg[64];
142  FILE *fd;
143  DIR* d;
144  int fnum = 0;
145  int fr = 0;
146  int zoom = 0;
147  struct dirent* de;
148  static struct utimbuf t;
149  // nothing to save? then dont save
150 
151  if( !is_buffer_ready() )
152  {
153  draw_string(0, 0, "No overlay to save.", user_color(conf.osd_color));
154  return;
155  }
156 
157  zoom = shooting_get_zoom();
158 
159  // first figure out the most appropriate filename to use
160  d = opendir(EDGE_SAVE_DIR);
161  if( ! d )
162  {
163  return;
164  }
165 
166  while( (de = readdir(d)) )
167  {
168  fr = get_edge_file_num(de->d_name);
169  if( fr > fnum )
170  {
171  fnum = fr;
172  }
173  }
174  ++fnum; // the highest is set, we use the next one
176  // open the right file
177  sprintf(fn, EDGE_SAVE_DIR "/" EDGE_FILE_FORMAT, fnum );
178  fd = fopen(fn, "wb");
179  if(fd !=NULL)
180  {
181  // write the data
182  fwrite(edgebuf->ptr,edgebuf->ptrLen,1,fd);
183  fwrite(&zoom,sizeof(zoom),1,fd);
184  fclose(fd);
185  t.actime = t.modtime = time(NULL);
186  utime(fn, &t);
187  sprintf(msg, "Saved as %s",fn);
188  draw_string(0, 0, msg, user_color(conf.osd_color));
189  }
190  closedir(d);
191 }
static void set_offset_from_overlap ( )
static

Definiert in Zeile 712 der Datei edgeoverlay.c.

713 {
714  const int y_max = viewport_height;
715  const int x_max = (viewport_width - 2);
716 
717  switch(conf.edge_overlay_pano)
718  {
719  case 0: // pano off
720  xoffset = 0;
721  yoffset = 0;
722  break;
723  case 1: // pano from left to right
724  xoffset = -x_max*(100-conf.edge_overlay_pano_overlap)/100;
725  break;
726  case 2: // pano from top to bottom
727  yoffset = -y_max*(100-conf.edge_overlay_pano_overlap)/100;
728  break;
729  case 3: // pano from right to left
730  xoffset = x_max*(100-conf.edge_overlay_pano_overlap)/100;
731  break;
732  case 4: // pano from bottom to top
733  yoffset = y_max*(100-conf.edge_overlay_pano_overlap)/100;
734  break;
735  case 5: // free mode
736  default:
737  // free mode: change position with "ALT" and cursor
738  // nothing to do here.
739  break;
740  }
741 }

Variablen-Dokumentation

libedgeovr_sym _libedgeovr
Initialisierung:

Definiert in Zeile 935 der Datei edgeoverlay.c.

ModuleInfo _module_info
Initialisierung:

Definiert in Zeile 946 der Datei edgeoverlay.c.

bit_vector_t* edgebuf = NULL
static

Definiert in Zeile 36 der Datei edgeoverlay.c.

edge_fsm_state_t fsm_state = EDGE_LIVE
static

Definiert in Zeile 35 der Datei edgeoverlay.c.

int slice = 0
static

Definiert in Zeile 40 der Datei edgeoverlay.c.

int slice_height
static

Definiert in Zeile 41 der Datei edgeoverlay.c.

unsigned char* smbuf = NULL
static

Definiert in Zeile 38 der Datei edgeoverlay.c.

int viewport_byte_width
static

Definiert in Zeile 43 der Datei edgeoverlay.c.

int viewport_height
static

Definiert in Zeile 45 der Datei edgeoverlay.c.

int viewport_width
static

Definiert in Zeile 46 der Datei edgeoverlay.c.

int viewport_xoffset
static

Definiert in Zeile 47 der Datei edgeoverlay.c.

int viewport_yoffset
static

Definiert in Zeile 48 der Datei edgeoverlay.c.

int viewport_yscale
static

Definiert in Zeile 44 der Datei edgeoverlay.c.

int xoffset = 0
static

Definiert in Zeile 37 der Datei edgeoverlay.c.

int yoffset = 0
static

Definiert in Zeile 37 der Datei edgeoverlay.c.