CHDK_DE Vorschauversion  Trunk Rev. 5842
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
histogram.c-Dateireferenz
#include "camera_info.h"
#include "conf.h"
#include "math.h"
#include "modes.h"
#include "viewport.h"
#include "gui.h"
#include "gui_draw.h"
#include "gui_osd.h"
#include "shooting.h"
#include "histogram.h"
+ Include-Abhängigkeitsdiagramm für histogram.c:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define HISTOGRAM_IDLE_STAGE   6
 
#define HISTO_R   0
 
#define HISTO_G   1
 
#define HISTO_B   2
 
#define HISTO_RGB   3
 
#define HISTO_Y   4
 
#define HISTO_MODE_LINEAR   0
 
#define HISTO_MODE_LOG   1
 
#define OSD_HISTO_LAYOUT_A   0
 
#define OSD_HISTO_LAYOUT_Y   1
 
#define OSD_HISTO_LAYOUT_A_Y   2
 
#define OSD_HISTO_LAYOUT_R_G_B   3
 
#define OSD_HISTO_LAYOUT_A_yrgb   4
 
#define OSD_HISTO_LAYOUT_Y_argb   5
 
#define OSD_HISTO_LAYOUT_BLEND   6
 
#define OSD_HISTO_LAYOUT_BLEND_Y   7
 
#define HISTO_STEP_SIZE   6
 

Funktionen

static int clip (int v)
 
static float identity (float x)
 
static float logarithmic (float x)
 
static void histogram_alloc ()
 
void histogram_process ()
 
static void gui_osd_draw_single_histo (int hist, coord x, coord y, int small)
 
static void gui_osd_draw_blended_histo (coord x, coord y)
 
void gui_osd_draw_histo (int is_osd_edit)
 
int _module_unloader ()
 
int _module_can_unload ()
 

Variablen

static unsigned char histogram [5][HISTO_WIDTH]
 
static unsigned short * histogram_proc [5] = { 0,0,0,0,0 }
 
unsigned int histo_max [5]
 
unsigned int histo_max_center [5]
 
static float histo_max_center_invw [5]
 
static long histo_magnification
 
static long under_exposed
 
static long over_exposed
 
static long histogram_stage =0
 
libhisto_sym _libhisto
 
ModuleInfo _module_info
 

Makro-Dokumentation

#define HISTO_B   2

Definiert in Zeile 23 der Datei histogram.c.

#define HISTO_G   1

Definiert in Zeile 22 der Datei histogram.c.

#define HISTO_MODE_LINEAR   0

Definiert in Zeile 28 der Datei histogram.c.

#define HISTO_MODE_LOG   1

Definiert in Zeile 29 der Datei histogram.c.

#define HISTO_R   0

Definiert in Zeile 21 der Datei histogram.c.

#define HISTO_RGB   3

Definiert in Zeile 24 der Datei histogram.c.

#define HISTO_STEP_SIZE   6

Definiert in Zeile 42 der Datei histogram.c.

#define HISTO_Y   4

Definiert in Zeile 25 der Datei histogram.c.

#define HISTOGRAM_IDLE_STAGE   6

Definiert in Zeile 18 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_A   0

Definiert in Zeile 32 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_A_Y   2

Definiert in Zeile 34 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_A_yrgb   4

Definiert in Zeile 36 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_BLEND   6

Definiert in Zeile 38 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_BLEND_Y   7

Definiert in Zeile 39 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_R_G_B   3

Definiert in Zeile 35 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_Y   1

Definiert in Zeile 33 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_Y_argb   5

Definiert in Zeile 37 der Datei histogram.c.

Dokumentation der Funktionen

int _module_can_unload ( )

Definiert in Zeile 477 der Datei histogram.c.

478 {
479  return conf.show_histo == 0;
480 }
int _module_unloader ( )

Definiert in Zeile 472 der Datei histogram.c.

473 {
474  return 0;
475 }
static int clip ( int  v)
static

Definiert in Zeile 63 der Datei histogram.c.

64 {
65  if (v<0) v=0;
66  else if (v>255) v=255;
67  return v;
68 }
static void gui_osd_draw_blended_histo ( coord  x,
coord  y 
)
static

Definiert in Zeile 338 der Datei histogram.c.

339 {
342 
343  register unsigned int i, v, red, grn, blu, sel;
344  color cls[] = {
345  BG_COLOR(hc),
346  COLOR_BLUE,
347  COLOR_GREEN,
348  COLOR_CYAN,
349  COLOR_RED,
351  COLOR_YELLOW,
353  };
354 
355  for (i=0; i<HISTO_WIDTH; ++i) {
356  red = histogram[HISTO_R][i];
357  grn = histogram[HISTO_G][i];
358  blu = histogram[HISTO_B][i];
359 
360  for (v=1; v<HISTO_HEIGHT; ++v) {
361  sel = 0;
362 
363  if (v < red) sel = 4;
364  if (v < grn) sel |= 2;
365  if (v < blu) sel |= 1;
366 
367  draw_pixel(x+1+i, y+HISTO_HEIGHT-v, cls[sel]);
368  }
369  }
370 
371  draw_rectangle(x, y, x+1+HISTO_WIDTH, y+HISTO_HEIGHT, hc2, RECT_BORDER1);
372  //Vertical lines
373  if (conf.histo_show_ev_grid) for (i=1;i<=4;i++) draw_line(x+(1+HISTO_WIDTH)*i/5, y, x+(1+HISTO_WIDTH)*i/5, y+HISTO_HEIGHT, FG_COLOR(hc2));
374 
375 }
void gui_osd_draw_histo ( int  is_osd_edit)

Definiert in Zeile 378 der Datei histogram.c.

379 {
380  if (is_osd_edit ||
382  (
384  ((conf.show_histo==SHOW_HISTO_REC) && camera_info.state.mode_rec && (recreview_hold==0)) ||
385  ((conf.show_histo==SHOW_HISTO_ALWAYS) && (recreview_hold==0))
386  )
387  )
388  )
389  {
392 
393  switch (conf.histo_layout)
394  {
395  case OSD_HISTO_LAYOUT_Y:
397  break;
401  break;
406  break;
413  break;
420  break;
423  break;
427  break;
428  case OSD_HISTO_LAYOUT_A:
429  default:
431  break;
432  }
433 
435  {
437  {
439  }
441  {
443  }
444  }
447  if (conf.histo_auto_ajust){
448  if (histo_magnification) {
449  char osd_buf[64];
450  sprintf(osd_buf, " %d.%02dx ", histo_magnification/100, histo_magnification%100);
452  } else if (is_osd_edit){
454  } else {
456  }
457  }
458  }
459 }
static void gui_osd_draw_single_histo ( int  hist,
coord  x,
coord  y,
int  small 
)
static

Definiert in Zeile 282 der Datei histogram.c.

283 {
286 
287  register int i, v, threshold;
288  register color cl, cl_over, cl_bg = BG_COLOR(hc);
290 
291  switch (hist)
292  {
293  case HISTO_R:
294  cl=COLOR_RED;
295  break;
296  case HISTO_G:
297  cl=COLOR_GREEN;
298  break;
299  case HISTO_B:
300  cl=COLOR_BLUE;
301  break;
302  case HISTO_RGB:
303  case HISTO_Y:
304  default:
305  cl=FG_COLOR(hc);
306  break;
307  }
308 
309  if (small) {
310  h>>=1; w>>=1;
311  for (i=0; i<w; ++i) {
312  threshold = (histogram[hist][i<<1]+histogram[hist][(i<<1)+1])>>2;
313 
314  for (v=1; v<h-1; ++v)
315  draw_pixel(x+1+i, y+h-v, (v<=threshold)?cl:cl_bg);
316  cl_over = (threshold==h && conf.show_overexp)?BG_COLOR(hc2):cl;
317  for (; v<h; ++v)
318  draw_pixel(x+1+i, y+h-v, (v<=threshold)?cl_over:cl_bg);
319  }
320  } else {
321  for (i=0; i<w; ++i) {
322  threshold = histogram[hist][i];
323 
324  for (v=1; v<h-3; ++v)
325  draw_pixel(x+1+i, y+h-v, (v<=threshold)?cl:cl_bg);
326  cl_over = (threshold==h && conf.show_overexp)?BG_COLOR(hc2):cl;
327  for (; v<h; ++v)
328  draw_pixel(x+1+i, y+h-v, (v<=threshold)?cl_over:cl_bg);
329  }
330  }
331 
332  draw_rectangle(x, y, x+1+w, y+h, hc2, RECT_BORDER1);
333  //Vertical Lines
334  if (conf.histo_show_ev_grid) for (i=1;i<=4;i++) draw_line(x+(1+w)*i/5, y, x+(1+w)*i/5, y+h, FG_COLOR(hc2));
335 }
static void histogram_alloc ( )
static

Definiert in Zeile 74 der Datei histogram.c.

75 {
76  // Allocate arrays to store counts during processing
77  // Each possible value is counted so the array sizes are set to 256, then these are summed to
78  // convert down to desired width of 128.
79  // This is faster than scaling each value as it is counted
80  if (histogram_proc[0] == 0)
81  {
82  histogram_proc[0] = malloc(5 * 256 * sizeof(unsigned short));
83  histogram_proc[1] = histogram_proc[0] + 256;
84  histogram_proc[2] = histogram_proc[1] + 256;
85  histogram_proc[3] = histogram_proc[2] + 256;
86  histogram_proc[4] = histogram_proc[3] + 256;
87  }
88 }
void histogram_process ( )

Definiert in Zeile 90 der Datei histogram.c.

91 {
92  static unsigned char *img;
93  static int viewport_size, viewport_width, viewport_row_offset, viewport_height, viewport_step_size;
94 
95  register int x, i, hi;
96  int y, v, u, c;
97  float (*histogram_transform)(float);
98  unsigned int histo_fill[5];
99  int histo_main;
100 
101  long exposition_thresh = camera_screen.size / 500;
102 
103  // Select transform function
104  switch (conf.histo_mode)
105  {
106  case HISTO_MODE_LOG:
107  histogram_transform = logarithmic;
108  break;
109  case HISTO_MODE_LINEAR:
110  default:
111  histogram_transform = identity;
112  break;
113  }
114 
115  // Select which calculated histogram channel determines magnification / scaling
117  histo_main = HISTO_Y;
118  else
119  histo_main = HISTO_RGB;
120 
121  histogram_alloc();
122 
123  // This function is called in the main spytask loop roughly every 20msec
124  // To avoid hogging all the CPU it performs it's work in stages controlled by histogram-stage
125  // Stage Function
126  // 0 Initialize global variables used in next stages
127  // 1,2,3 Count number of values for a third of the viewport image at each stage
128  // 4 Calculate max values, over and under exposure setting
129  // 5 Calculate the histogram display values
130  switch (histogram_stage)
131  {
132  case 0:
134  if (!img) return;
135 
136  img += vid_get_viewport_image_offset(); // offset into viewport for when image size != viewport size (e.g. 16:9 image on 4:3 LCD)
137 
138  viewport_height = vid_get_viewport_height_proper();
139  viewport_size = viewport_height * vid_get_viewport_byte_width();
140  // Viewport visible width in bytes
141 #ifndef THUMB_FW
142  viewport_width = vid_get_viewport_width_proper() * 6 / 4;
143 #else
144  viewport_width = vid_get_viewport_width_proper() * 4 / 2;
145 #endif
146  // Number of columns to scan - 30 for 720 pixel wide viewport, 40 for widescreen (960 wide).
147  // This give 24 pixel increments between columns.
148  // For pre Digic6 24 pixels = 24 * 6 / 4 bytes = 36 bytes (6 bytes = 4 pixels). Each 'stage' does a column @1/3rd of this width = 12 bytes = 8 pixels.
149  // For Digic6 24 pixels = 24 * 4 / 2 bytes = 48 bytes (4 bytes = 2 pixels). Each 'stage' does a column @1/3rd of this width = 16 bytes = 8 pixels.
150  // We offset all columns by 4 pixels so the first column is not hard against the left edge
151  viewport_step_size = viewport_width / (vid_get_viewport_width_proper() / 24);
152  // Increment to adjust for each row if physical width > visible width
153  viewport_row_offset = vid_get_viewport_row_offset();
154 
155  for (c=0; c<5; ++c) {
156  memset(histogram_proc[c],0,256*sizeof(unsigned short));
157  histo_max[c] = histo_max_center[c] = 0;
158  }
159 
160  histogram_stage=1;
161  break;
162 
163  case 1:
164  case 2:
165  case 3:
166  x = 0; // count how many bytes we have done on the current row (to skip unused buffer space at end of each row)
167 
168  for (i=(histogram_stage-1)*(viewport_step_size/3)+(viewport_step_size/6); i<viewport_size; i+=viewport_step_size) {
169 
170  y = img[i+1];
171 #ifndef THUMB_FW
172  u = (signed char)img[i];
173  v = (signed char)img[i+2];
174 #else
175  u = (int)img[i] - 128;
176  v = (int)img[i+2] - 128;
177 #endif
178 // img[i+1] = img[i+3] = 255; // Draw columns on screen for debugging
179 
180  ++histogram_proc[HISTO_Y][y]; // Y
181  hi = clip(((y<<12) + v*5743 + 2048)>>12); // R
182  ++histogram_proc[HISTO_R][hi];
183  hi = clip(((y<<12) - u*1411 - v*2925 + 2048)>>12); // G
184  ++histogram_proc[HISTO_G][hi];
185  hi = clip(((y<<12) + u*7258 + 2048)>>12); // B
186  ++histogram_proc[HISTO_B][hi];
187 
188  // Handle case where viewport memory buffer is wider than the actual buffer.
189  x += viewport_step_size;
190  if (x == viewport_width)
191  {
192  i += viewport_row_offset;
193  x = 0;
194  }
195  } //loop i
196 
197  ++histogram_stage;
198  break;
199 
200  case 4:
201  for (i=0, c=0; i<HISTO_WIDTH; ++i, c+=2) { // G
202  // Merge each pair of values into a single value (for width = 128)
203  // Warning: this is optimised for HISTO_WIDTH = 128, don't change the width unless you re-write this code as well.
204 #ifndef THUMB_FW
206  histogram_proc[HISTO_R][i] = histogram_proc[HISTO_R][c] + histogram_proc[HISTO_R][c+1];
207  histogram_proc[HISTO_G][i] = histogram_proc[HISTO_G][c] + histogram_proc[HISTO_G][c+1];
208  histogram_proc[HISTO_B][i] = histogram_proc[HISTO_B][c] + histogram_proc[HISTO_B][c+1];
209 #endif
210  // Calc combined RGB totals
211  histogram_proc[HISTO_RGB][i] = histogram_proc[HISTO_R][i] + histogram_proc[HISTO_G][i] + histogram_proc[HISTO_B][i];
212  }
213 
214  // calculate maximums
215  for (c=0; c<5; ++c) {
216  for (i=0; i<HISTO_WIDTH; ++i) {
217  if (histo_max[c]<histogram_proc[c][i])
218  histo_max[c]=histogram_proc[c][i];
221  }
222 
223  if (histo_max_center[c] > 0) {
224  histo_max_center_invw[c] = ((float)HISTO_HEIGHT)/histogram_transform((float)histo_max_center[c]);
225  } else if (histo_max[c] > 0) {
226  histo_max_center_invw[c] = ((float)HISTO_HEIGHT)/histogram_transform((float)histo_max[c]);
227  } else {
228  histo_max_center_invw[c] = 0.0f;
229  }
230  }
231 
232  if (histo_max[HISTO_RGB] > 0) { // over- / under- expos
235  +histogram_proc[HISTO_RGB][2]) > exposition_thresh;
236 
237  over_exposed = (histogram_proc[HISTO_RGB][HISTO_WIDTH-3]
238  +histogram_proc[HISTO_RGB][HISTO_WIDTH-2]*4
239  +histogram_proc[HISTO_RGB][HISTO_WIDTH-1]*8) > exposition_thresh;
240  } else {
241  over_exposed = 0;
242  under_exposed = 1;
243  }
244 
245  histogram_stage=5;
246  break;
247 
248  case 5:
249  for (c=0; c<5; ++c) {
250  histo_fill[c]=0;
251  for (i=0; i<HISTO_WIDTH; ++i) {
252  histogram[c][i] = (histogram_transform((float)histogram_proc[c][i]))*histo_max_center_invw[c];
253  if (histogram[c][i] > HISTO_HEIGHT)
254  histogram[c][i] = HISTO_HEIGHT;
255  histo_fill[c]+=histogram[c][i];
256  }
257  }
258 
260  if (conf.histo_auto_ajust) {
261  if (histo_fill[histo_main] < (HISTO_HEIGHT*HISTO_WIDTH)/5) { // try to ajust if average level is less than 20%
262  histo_magnification = (20*HISTO_HEIGHT*HISTO_WIDTH) / histo_fill[histo_main];
263  for (c=0; c<5; ++c) {
264  for (i=0;i<HISTO_WIDTH;i++) {
265  histogram[c][i] = histogram[c][i] * histo_magnification / 100;
266  if (histogram[c][i] > HISTO_HEIGHT)
267  histogram[c][i] = HISTO_HEIGHT;
268  }
269  }
270  }
271  }
272 
273  histogram_stage=0;
274  break;
275  }
276 
277 }
static float identity ( float  x)
static

Definiert in Zeile 71 der Datei histogram.c.

71 { return x; }
static float logarithmic ( float  x)
static

Definiert in Zeile 72 der Datei histogram.c.

72 { return log(x); }

Variablen-Dokumentation

libhisto_sym _libhisto
Initialisierung:

Definiert in Zeile 484 der Datei histogram.c.

ModuleInfo _module_info
Initialisierung:

Definiert in Zeile 494 der Datei histogram.c.

long histo_magnification
static

Definiert in Zeile 53 der Datei histogram.c.

unsigned int histo_max[5]

Definiert in Zeile 50 der Datei histogram.c.

unsigned int histo_max_center[5]

Definiert in Zeile 50 der Datei histogram.c.

float histo_max_center_invw[5]
static

Definiert in Zeile 51 der Datei histogram.c.

unsigned char histogram[5][HISTO_WIDTH]
static

Definiert in Zeile 48 der Datei histogram.c.

unsigned short* histogram_proc[5] = { 0,0,0,0,0 }
static

Definiert in Zeile 49 der Datei histogram.c.

long histogram_stage =0
static

Definiert in Zeile 57 der Datei histogram.c.

long over_exposed
static

Definiert in Zeile 55 der Datei histogram.c.

long under_exposed
static

Definiert in Zeile 54 der Datei histogram.c.