CHDK_DE Vorschauversion  Trunk Rev. 5779
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
zebra.c-Dateireferenz
#include "camera_info.h"
#include "conf.h"
#include "keyboard.h"
#include "modes.h"
#include "viewport.h"
#include "properties.h"
#include "gui.h"
#include "gui_draw.h"
#include "gui_lang.h"
#include "gui_osd.h"
#include "gui_mbox.h"
#include "gui_batt.h"
#include "gui_space.h"
#include "histogram.h"
#include "zebra.h"
#include "gui_grid.h"
#include "module_def.h"
+ Include-Abhängigkeitsdiagramm für zebra.c:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define ZFIX_TOP   29
 
#define ZFIX_BOTTOM   30
 

Funktionen

unsigned char clip8 (signed short x)
 
static void gui_osd_zebra_free ()
 
static int gui_osd_zebra_init (int show)
 
static void draw_pixel_buffered (unsigned int offset, color cl)
 
int draw_guard_pixel ()
 
static void gui_osd_draw_zebra_osd ()
 
static void disp_zebra ()
 
static int draw_zebra_aspect_adjust (int mrec, unsigned int f, color *cls)
 
static unsigned char get_cur_buf (unsigned int idx)
 
static int draw_zebra_no_aspect_adjust (int mrec, unsigned int f, color *cls)
 
int gui_osd_draw_zebra (int show)
 
int _module_unloader ()
 
int _module_can_unload ()
 

Variablen

static unsigned char * img_buf
 
static unsigned char * scr_buf
 
static unsigned char * cur_buf_top
 
static unsigned char * cur_buf_bot
 
static int timer = 0
 
static unsigned char * buf = NULL
 
static int buffer_size
 
static color cl_under
 
static color cl_over
 
libzebra_sym _libzebra
 
ModuleInfo _module_info
 

Makro-Dokumentation

#define ZFIX_BOTTOM   30

Definiert in Zeile 103 der Datei zebra.c.

#define ZFIX_TOP   29

Definiert in Zeile 102 der Datei zebra.c.

Dokumentation der Funktionen

int _module_can_unload ( )

Definiert in Zeile 816 der Datei zebra.c.

817 {
818  return conf.zebra_draw == 0;
819 }
int _module_unloader ( )

Definiert in Zeile 810 der Datei zebra.c.

811 {
813  return 0;
814 }
unsigned char clip8 ( signed short  x)

Definiert in Zeile 114 der Datei zebra.c.

114 { if (x<0) x=0; else if (x>255) x=255; return x; }
static void disp_zebra ( )
static

Definiert in Zeile 224 der Datei zebra.c.

225 {
226  // draw CHDK osd and histogram to buf[] (if enabled in config)
228 
229  // copy buf[] to both display buffers
230  if (buf != scr_buf)
233 }
int draw_guard_pixel ( )

Definiert in Zeile 191 der Datei zebra.c.

191  {
192  unsigned char* buffer1 = vid_get_bitmap_fb()+camera_screen.buffer_size/2;
193  unsigned char* buffer2 = buffer1+camera_screen.buffer_size;
194  int has_disappeared=0;
195 
196  if(*buffer1!=COLOR_GREEN) has_disappeared=1;
197  if(*buffer2!=COLOR_GREEN) has_disappeared=2;
198  *buffer1 = *buffer2 = COLOR_GREEN;
199  return has_disappeared;
200 }
static void draw_pixel_buffered ( unsigned int  offset,
color  cl 
)
static

Definiert in Zeile 185 der Datei zebra.c.

186 {
187  buf[offset] = cl;
188 }
static int draw_zebra_aspect_adjust ( int  mrec,
unsigned int  f,
color cls 
)
static

Definiert in Zeile 240 der Datei zebra.c.

241 {
242  int v, s, x, y, over;
243  static int need_restore=0;
244  int viewport_height;
245  int viewport_width;
246  int viewport_image_offset; // for when viewport memory buffer is wider than viewport
247  int viewport_row_offset; // for when viewport memory buffer is wider than viewport
248  int viewport_xoffset; // used when image size != viewport size
249  int viewport_yoffset; // used when image size != viewport size
250  int zebra_drawn=0;
251 
252  viewport_height = vid_get_viewport_height();
253  viewport_width = vid_get_viewport_width();
254  viewport_image_offset = vid_get_viewport_image_offset();
255  viewport_row_offset = vid_get_viewport_row_offset();
256  viewport_xoffset = vid_get_viewport_display_xoffset();
257  viewport_yoffset = vid_get_viewport_display_yoffset();
258 
259  // if not in no-zebra phase of blink mode zebra, draw zebra to buf[]
260  if (f) {
261  if (viewport_yoffset > 0) { // clear top & bottom areas of buffer if image height if smaller than viewport
263  memset(buf+(viewport_yoffset+viewport_height)*camera_screen.buffer_width, COLOR_TRANSPARENT, viewport_yoffset*camera_screen.buffer_width);
264  }
265  int step_x, step_v, sy, sx;
266  over = 255-conf.zebra_over;
267  if (conf.zebra_multichannel) {step_x=2; step_v=6;} else {step_x=1; step_v=3;}
268  for (y=viewport_yoffset, v=viewport_image_offset; y<viewport_yoffset+viewport_height; ++y) {
270  sx = viewport_xoffset;
271  if (viewport_xoffset > 0) { // clear left & right areas of buffer if image width if smaller than viewport
272  memset(buf+sy, COLOR_TRANSPARENT, sx*2);
273  memset(buf+sy+(sx+viewport_width)*2, COLOR_TRANSPARENT, sx*2);
274  }
275  for (x=viewport_xoffset; x<viewport_xoffset+viewport_width; x+=step_x, sx+=step_x, v+=step_v) {
276  register int yy;
277  yy = img_buf[v+1];
278  s = sy + sx*2;
279 
280  if (conf.zebra_multichannel) {
281  register int uu, vv;
282  int sel;
283  uu = (signed char)img_buf[v];
284  vv = (signed char)img_buf[v+2];
285  sel=0;
287  if (clip8(((yy<<12) + vv*5743 + 2048)>>12)>over) sel = 4; // R
288  if (clip8(((yy<<12) - uu*1411 - vv*2925 + 2048)>>12)>over) sel |= 2; // G
289  if (clip8(((yy<<12) + uu*7258 + 2048)>>12)>over) sel |= 1; // B
290  }
291  buf[s] = buf[s+1] = cls[sel];
292  buf[s+2] = buf[s+3] = cls[sel];
293  }
294  else if (((conf.zebra_mode == ZEBRA_MODE_ZEBRA_1 || conf.zebra_mode == ZEBRA_MODE_ZEBRA_2) && (y-x-timer)&f))
295  buf[s] = buf[s+1] = COLOR_TRANSPARENT;
296  else
297  buf[s] = buf[s+1] = (yy>over)?cl_over:(yy<conf.zebra_under)?cl_under:COLOR_TRANSPARENT;
298 
299  if (buf[s] != COLOR_TRANSPARENT && !zebra_drawn)
300  zebra_drawn = 1;
301  }
302  // adjust for cases where buffer is wider than viewport (e.g. on G12)
303  v += viewport_row_offset;
304  }
305  if (!zebra_drawn) f=0;
306  }
307  // if blink mode is in no-zebra phase OR if there was no over/underexposed pixels to draw zebra on
308  if (!f) {
309  // if zebra was drawn during previous call of this function
310  if (need_restore) {
313  } else { // clear buf[] of zebra, only leave Canon OSD
314  if (!mrec) { // Not REC mode
315  // No Canon OSD restore, fill buf[] with transparent color:
317  }
318  disp_zebra();
319  }
320  need_restore=0;
321  }
323  // if zebra was drawn
324  } else {
325  disp_zebra();
326 
327  need_restore=1;
328  return 1;
329  }
330  return 0;
331 }
static int draw_zebra_no_aspect_adjust ( int  mrec,
unsigned int  f,
color cls 
)
static

Definiert in Zeile 349 der Datei zebra.c.

349  {
350  int v, s, x, y, over;
351  static int need_restore=0;
352  int viewport_height;
353  int zebra_drawn=0;
354 
355  unsigned bWide = 1; // if wide (16:9) or standard (4:3) aspect ratio (but 1 in cameras that only have 4:3)
356  unsigned aspOffset = 0; // offset to add to x-coord (or buffer address) when drawing zebra
357 
359  {
360  if (shooting_get_prop(camera_info.props.aspect_ratio) == 0) // standard requires x-shift to overlay drawing
361  {
362  bWide = 0;
363  //aspOffset = (camera_screen.width - (camera_screen.width * 12 / 16)) / 2; // = actual calculation, simplified below
364  aspOffset = camera_screen.width / 8; // half of the difference in width between equal height 16:9 and 4:3 screens, = black bar width
365  }
366  }
367 
368  viewport_height = vid_get_viewport_height();
369 
370  // if not in no-zebra phase of blink mode zebra, draw zebra to buf[]
371  if (f) {
372  int step_x, step_v;
373  over = 255-conf.zebra_over;
374  if (conf.zebra_multichannel) {step_x=2; step_v=6;} else {step_x=1; step_v=3;}
375  s = aspOffset;
376  for (y=1, v=0; y<=viewport_height; ++y) {
377  for (x=0; x<camera_screen.width; x+=step_x, s+=step_x, v+=step_v) {
378  register int yy, uu, vv;
379  int sel;
380 
381  if (!bWide && (x + aspOffset >= camera_screen.width - aspOffset)) continue; // do not draw "outside screen"
382 
383  yy = img_buf[v+1];
384  if (conf.zebra_multichannel) {
385  uu = (signed char)img_buf[v];
386  vv = (signed char)img_buf[v+2];
387  sel=0;
389  if (clip8(((yy<<12) + vv*5743 + 2048)>>12)>over) sel = 4; // R
390  if (clip8(((yy<<12) - uu*1411 - vv*2925 + 2048)>>12)>over) sel |= 2; // G
391  if (clip8(((yy<<12) + uu*7258 + 2048)>>12)>over) sel |= 1; // B
392  }
393  buf[s]=buf[s+1]=cls[sel];
394  }
396  else buf[s]=(yy>over)?cl_over:(yy<conf.zebra_under)?cl_under:COLOR_TRANSPARENT;
397  if (buf[s] != COLOR_TRANSPARENT && !zebra_drawn) zebra_drawn = 1;
398  if (mrec) {
399  // draw Canon OSD to buf[] if in REC mode
402  }
403  }
408  }
409  }
410  if (!zebra_drawn) f=0;
411  }
412  // if blink mode is in no-zebra phase OR if there was no over/underexposed pixels to draw zebra on
413  if (!f) {
414  // if zebra was drawn during previous call of this function
415  if (need_restore) {
418  } else { // clear buf[] of zebra, only leave Canon OSD
419  if (mrec) { // REC mode
420  // copy rescued Canon OSD to buf[] top/bottom parts and fill center with transparent color:
425  }
426  } else { // Not REC mode
427  // No Canon OSD restore, fill buf[] with transparent color:
429  }
430  disp_zebra();
431  }
432  need_restore=0;
433  }
435  // if zebra was drawn
436  } else {
437  disp_zebra();
438 
439  need_restore=1;
440  return 1;
441  }
442  return 0;
443 }
static unsigned char get_cur_buf ( unsigned int  idx)
static

Definiert in Zeile 335 der Datei zebra.c.

335  {
336  unsigned int a;
337 
339 
340  if (idx < (unsigned)camera_screen.buffer_width * ZFIX_TOP) return(cur_buf_top[idx]);
341  if (idx >= a && idx < (unsigned)camera_screen.buffer_size) return(cur_buf_bot[idx - a]);
342  return (COLOR_TRANSPARENT);
343 }
int gui_osd_draw_zebra ( int  show)

Definiert in Zeile 446 der Datei zebra.c.

447 {
448  unsigned int f;
449 
450  if (!gui_osd_zebra_init(show))
451  return 0;
452 
453  color cls[] = {
455  COLOR_BLUE,
456  COLOR_GREEN,
457  COLOR_CYAN,
458  COLOR_RED,
460  COLOR_YELLOW,
462  };
463 
465  if (!img_buf) return 0;
466 
467  if (timer==0)
468  {
470  timer = 1;
471  return 0;
472  }
473 
474  if (timer==1)
475  {
476  int ready;
477  static int n=0;
478  if (!camera_info.state.mode_rec) ready=1;
479  else get_property_case(camera_info.props.shooting, &ready, 4);
480  n=draw_guard_pixel(); // will be 0 in PLAY mode, should be 1 or 2 in REC mode.
481  if(!ready) return 0;
482  if (cur_buf_top)
483  {
484  // rescue Canon OSD from scr_buf to cur_buf_top and _bot:
485  if (n==1) {
488  }
489  else {
492  }
493  }
494  }
495  ++timer;
496 
497  switch (conf.zebra_mode)
498  {
499  case ZEBRA_MODE_ZEBRA_1: f = 4; break;
500  case ZEBRA_MODE_ZEBRA_2: f = 8; break;
501  case ZEBRA_MODE_SOLID: f = 1; break;
502  case ZEBRA_MODE_BLINKED_1: f = timer&1; break;
503  case ZEBRA_MODE_BLINKED_3: f = timer&4; break;
504  case ZEBRA_MODE_BLINKED_2:
505  default: f = timer&2; break;
506  }
507 
509  return draw_zebra_aspect_adjust(camera_info.state.mode_rec,f,cls); // For newer cameras with 720/960 pixel wide screen
510  else
511  return draw_zebra_no_aspect_adjust(camera_info.state.mode_rec,f,cls); // For older cameras with 360/480 pixel wide screen
512 }
static void gui_osd_draw_zebra_osd ( )
static

Definiert in Zeile 203 der Datei zebra.c.

203  {
204  switch (conf.zebra_draw_osd) {
205  case ZEBRA_DRAW_NONE:
206  break;
207  case ZEBRA_DRAW_OSD:
208  if (conf.show_osd) {
212  }
213  /* no break here */
214  case ZEBRA_DRAW_HISTO:
215  default:
219  break;
220  }
221 }
static void gui_osd_zebra_free ( )
static

Definiert in Zeile 119 der Datei zebra.c.

120 {
121  if (buf != scr_buf) free(buf);
122  buf = NULL;
123 
124  free(cur_buf_top);
125  cur_buf_top = NULL;
126 
127  free(cur_buf_bot);
128  cur_buf_bot = NULL;
129 }
static int gui_osd_zebra_init ( int  show)
static

Definiert in Zeile 132 der Datei zebra.c.

133 {
136 
137  if (show)
138  {
139  if (!buf)
140  {
141  timer = 0;
142  // Determine bitmap buffer size. If physical buffer is taller than displayed height then ignore bottom strip - (used to be ZEBRA_HMARGIN0).
145  if (camera_screen.zebra_nobuf == 0)
146  {
148  //gui_mbox_init(LANG_WARNING, (int)"No space to allocate zebra buffer: restart camera", MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL);
149  }
150  if (!buf)
151  {
152  buf = scr_buf; //without new buffer: directly into screen buffer: we got some flickering in OSD and histogram but it's usable
153  }
155  {
156  cur_buf_top = cur_buf_bot = 0;
157  }
158  else
159  {
162  // cleanup and disable zebra if any mallocs failed
163  if (!cur_buf_top || !cur_buf_bot)
167  }
168  // in variable aspect, the borders would never be cleared
171  }
172  }
173  else {
174  if (buf) // if zebra was previously on, restore
176 
178  }
179  return (buf != NULL);
180 }

Variablen-Dokumentation

libzebra_sym _libzebra
Initialisierung:

Definiert in Zeile 823 der Datei zebra.c.

ModuleInfo _module_info
Initialisierung:

Definiert in Zeile 832 der Datei zebra.c.

unsigned char* buf = NULL
static

Definiert in Zeile 110 der Datei zebra.c.

int buffer_size
static

Definiert in Zeile 111 der Datei zebra.c.

color cl_over
static

Definiert in Zeile 112 der Datei zebra.c.

color cl_under
static

Definiert in Zeile 112 der Datei zebra.c.

unsigned char * cur_buf_bot
static

Definiert in Zeile 107 der Datei zebra.c.

unsigned char* cur_buf_top
static

Definiert in Zeile 107 der Datei zebra.c.

unsigned char* img_buf
static

Definiert in Zeile 105 der Datei zebra.c.

unsigned char * scr_buf
static

Definiert in Zeile 105 der Datei zebra.c.

int timer = 0
static

Definiert in Zeile 109 der Datei zebra.c.