CHDK_DE Vorschauversion  Trunk Rev. 5163
 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 820 der Datei zebra.c.

821 {
822  return conf.zebra_draw == 0;
823 }
int _module_unloader ( )

Definiert in Zeile 814 der Datei zebra.c.

815 {
817  return 0;
818 }
unsigned char clip8 ( signed short  x)

Definiert in Zeile 112 der Datei zebra.c.

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

Definiert in Zeile 222 der Datei zebra.c.

223 {
224  // draw CHDK osd and histogram to buf[] (if enabled in config)
226 
227  // copy buf[] to both display buffers
228  if (buf != scr_buf)
231 }
int draw_guard_pixel ( )

Definiert in Zeile 189 der Datei zebra.c.

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

Definiert in Zeile 183 der Datei zebra.c.

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

Definiert in Zeile 238 der Datei zebra.c.

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

Definiert in Zeile 347 der Datei zebra.c.

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

Definiert in Zeile 333 der Datei zebra.c.

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

Definiert in Zeile 444 der Datei zebra.c.

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

Definiert in Zeile 201 der Datei zebra.c.

201  {
202  switch (conf.zebra_draw_osd) {
203  case ZEBRA_DRAW_NONE:
204  break;
205  case ZEBRA_DRAW_OSD:
206  if (conf.show_osd) {
210  }
211  /* no break here */
212  case ZEBRA_DRAW_HISTO:
213  default:
217  break;
218  }
219 }
static void gui_osd_zebra_free ( )
static

Definiert in Zeile 117 der Datei zebra.c.

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

Definiert in Zeile 130 der Datei zebra.c.

131 {
134 
135  if (show)
136  {
137  if (!buf)
138  {
139  timer = 0;
140  // Determine bitmap buffer size. If physical buffer is taller than displayed height then ignore bottom strip - (used to be ZEBRA_HMARGIN0).
143  if (camera_screen.zebra_nobuf == 0)
144  {
146  //gui_mbox_init(LANG_WARNING, (int)"No space to allocate zebra buffer: restart camera", MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL);
147  }
148  if (!buf)
149  {
150  buf = scr_buf; //without new buffer: directly into screen buffer: we got some flickering in OSD and histogram but it's usable
151  }
153  {
154  cur_buf_top = cur_buf_bot = 0;
155  }
156  else
157  {
160  // cleanup and disable zebra if any mallocs failed
161  if (!cur_buf_top || !cur_buf_bot)
165  }
166  // in variable aspect, the borders would never be cleared
169  }
170  }
171  else {
172  if (buf) // if zebra was previously on, restore
174 
176  }
177  return (buf != NULL);
178 }

Variablen-Dokumentation

libzebra_sym _libzebra
Initialisierung:

Definiert in Zeile 827 der Datei zebra.c.

ModuleInfo _module_info
Initialisierung:

Definiert in Zeile 836 der Datei zebra.c.

unsigned char* buf = NULL
static

Definiert in Zeile 108 der Datei zebra.c.

int buffer_size
static

Definiert in Zeile 109 der Datei zebra.c.

color cl_over
static

Definiert in Zeile 110 der Datei zebra.c.

color cl_under
static

Definiert in Zeile 110 der Datei zebra.c.

unsigned char * cur_buf_bot
static

Definiert in Zeile 106 der Datei zebra.c.

unsigned char* cur_buf_top
static

Definiert in Zeile 106 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 107 der Datei zebra.c.