CHDK_DE Vorschauversion  Trunk Rev. 5209
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
histogram.c-Dateireferenz
#include "camera_info.h"
#include "stdlib.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 24 der Datei histogram.c.

#define HISTO_G   1

Definiert in Zeile 23 der Datei histogram.c.

#define HISTO_MODE_LINEAR   0

Definiert in Zeile 29 der Datei histogram.c.

#define HISTO_MODE_LOG   1

Definiert in Zeile 30 der Datei histogram.c.

#define HISTO_R   0

Definiert in Zeile 22 der Datei histogram.c.

#define HISTO_RGB   3

Definiert in Zeile 25 der Datei histogram.c.

#define HISTO_STEP_SIZE   6

Definiert in Zeile 43 der Datei histogram.c.

#define HISTO_Y   4

Definiert in Zeile 26 der Datei histogram.c.

#define HISTOGRAM_IDLE_STAGE   6

Definiert in Zeile 19 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_A   0

Definiert in Zeile 33 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_A_Y   2

Definiert in Zeile 35 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_A_yrgb   4

Definiert in Zeile 37 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_BLEND   6

Definiert in Zeile 39 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_BLEND_Y   7

Definiert in Zeile 40 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_R_G_B   3

Definiert in Zeile 36 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_Y   1

Definiert in Zeile 34 der Datei histogram.c.

#define OSD_HISTO_LAYOUT_Y_argb   5

Definiert in Zeile 38 der Datei histogram.c.

Dokumentation der Funktionen

int _module_can_unload ( )

Definiert in Zeile 492 der Datei histogram.c.

493 {
494  return conf.show_histo == 0;
495 }
int _module_unloader ( )

Definiert in Zeile 487 der Datei histogram.c.

488 {
489  return 0;
490 }
static int clip ( int  v)
static

Definiert in Zeile 64 der Datei histogram.c.

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

Definiert in Zeile 353 der Datei histogram.c.

354 {
357 
358  register unsigned int i, v, red, grn, blu, sel;
359  color cls[] = {
360  BG_COLOR(hc),
361  COLOR_BLUE,
362  COLOR_GREEN,
363  COLOR_CYAN,
364  COLOR_RED,
366  COLOR_YELLOW,
368  };
369 
370  for (i=0; i<HISTO_WIDTH; ++i) {
371  red = histogram[HISTO_R][i];
372  grn = histogram[HISTO_G][i];
373  blu = histogram[HISTO_B][i];
374 
375  for (v=1; v<HISTO_HEIGHT; ++v) {
376  sel = 0;
377 
378  if (v < red) sel = 4;
379  if (v < grn) sel |= 2;
380  if (v < blu) sel |= 1;
381 
382  draw_pixel(x+1+i, y+HISTO_HEIGHT-v, cls[sel]);
383  }
384  }
385 
386  draw_rectangle(x, y, x+1+HISTO_WIDTH, y+HISTO_HEIGHT, hc2, RECT_BORDER1);
387  //Vertical lines
388  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));
389 
390 }
void gui_osd_draw_histo ( int  is_osd_edit)

Definiert in Zeile 393 der Datei histogram.c.

394 {
395  if (is_osd_edit ||
397  (
399  ((conf.show_histo==SHOW_HISTO_REC) && camera_info.state.mode_rec && (recreview_hold==0)) ||
400  ((conf.show_histo==SHOW_HISTO_ALWAYS) && (recreview_hold==0))
401  )
402  )
403  )
404  {
407 
408  switch (conf.histo_layout)
409  {
410  case OSD_HISTO_LAYOUT_Y:
412  break;
416  break;
421  break;
428  break;
435  break;
438  break;
442  break;
443  case OSD_HISTO_LAYOUT_A:
444  default:
446  break;
447  }
448 
450  {
452  {
454  }
456  {
458  }
459  }
462  if (conf.histo_auto_ajust){
463  if (histo_magnification) {
464  char osd_buf[64];
465  sprintf(osd_buf, " %d.%02dx ", histo_magnification/100, histo_magnification%100);
467  } else if (is_osd_edit){
469  } else {
471  }
472  }
473  }
474 }
static void gui_osd_draw_single_histo ( int  hist,
coord  x,
coord  y,
int  small 
)
static

Definiert in Zeile 297 der Datei histogram.c.

298 {
301 
302  register unsigned int i, v, threshold;
303  register color cl, cl_over, cl_bg = BG_COLOR(hc);
305 
306  switch (hist)
307  {
308  case HISTO_R:
309  cl=COLOR_RED;
310  break;
311  case HISTO_G:
312  cl=COLOR_GREEN;
313  break;
314  case HISTO_B:
315  cl=COLOR_BLUE;
316  break;
317  case HISTO_RGB:
318  case HISTO_Y:
319  default:
320  cl=FG_COLOR(hc);
321  break;
322  }
323 
324  if (small) {
325  h>>=1; w>>=1;
326  for (i=0; i<w; ++i) {
327  threshold = (histogram[hist][i<<1]+histogram[hist][(i<<1)+1])>>2;
328 
329  for (v=1; v<h-1; ++v)
330  draw_pixel(x+1+i, y+h-v, (v<=threshold)?cl:cl_bg);
331  cl_over = (threshold==h && conf.show_overexp)?BG_COLOR(hc2):cl;
332  for (; v<h; ++v)
333  draw_pixel(x+1+i, y+h-v, (v<=threshold)?cl_over:cl_bg);
334  }
335  } else {
336  for (i=0; i<w; ++i) {
337  threshold = histogram[hist][i];
338 
339  for (v=1; v<h-3; ++v)
340  draw_pixel(x+1+i, y+h-v, (v<=threshold)?cl:cl_bg);
341  cl_over = (threshold==h && conf.show_overexp)?BG_COLOR(hc2):cl;
342  for (; v<h; ++v)
343  draw_pixel(x+1+i, y+h-v, (v<=threshold)?cl_over:cl_bg);
344  }
345  }
346 
347  draw_rectangle(x, y, x+1+w, y+h, hc2, RECT_BORDER1);
348  //Vertical Lines
349  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));
350 }
static void histogram_alloc ( )
static

Definiert in Zeile 75 der Datei histogram.c.

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

Definiert in Zeile 91 der Datei histogram.c.

92 {
93  static unsigned char *img;
94  static int viewport_size, viewport_width, viewport_row_offset, viewport_height, viewport_byte_width;
95 
96  register int x, i, hi;
97  int y, v, u, c;
98  float (*histogram_transform)(float);
99  unsigned int histo_fill[5];
100  int histo_main;
101 
102  long exposition_thresh = camera_screen.size / 500;
103 
104  // Select transform function
105  switch (conf.histo_mode)
106  {
107  case HISTO_MODE_LOG:
108  histogram_transform = logarithmic;
109  break;
110  case HISTO_MODE_LINEAR:
111  default:
112  histogram_transform = identity;
113  break;
114  }
115 
116  // Select which calculated histogram channel determines magnification / scaling
118  histo_main = HISTO_Y;
119  else
120  histo_main = HISTO_RGB;
121 
122  histogram_alloc();
123 
124  // This function is called in the main spytask loop roughly every 20msec
125  // To avoid hogging all the CPU it performs it's work in stages controlled by histogram-stage
126  // Stage Function
127  // 0 Initialize global variables used in next stages
128  // 1,2,3 Count number of values for a third of the viewport image at each stage
129  // 4 Calculate max values, over and under exposure setting
130  // 5 Calculate the histogram display values
131  switch (histogram_stage)
132  {
133  case 0:
135  if (!img) return;
136 
137  img += vid_get_viewport_image_offset(); // offset into viewport for when image size != viewport size (e.g. 16:9 image on 4:3 LCD)
138  viewport_height = vid_get_viewport_height();
139  viewport_byte_width = vid_get_viewport_byte_width();
140  viewport_size = viewport_height * viewport_byte_width * vid_get_viewport_yscale();
141  viewport_width = vid_get_viewport_width();
142  viewport_row_offset = vid_get_viewport_row_offset();
143  for (c=0; c<5; ++c) {
144  memset(histogram_proc[c],0,256*sizeof(unsigned short));
145  histo_max[c] = histo_max_center[c] = 0;
146  }
147 
148  histogram_stage=1;
149  break;
150 
151  case 1:
152  case 2:
153  case 3:
154  x = 0; // count how many blocks we have done on the current row (to skip unused buffer space at end of each row)
155 #ifndef THUMB_FW
156 
157  for (i=(histogram_stage-1)*6; i<viewport_size; i+=HISTO_STEP_SIZE*6) {
158 #else
159 
160 //digic 6
161 // 16:9 f:8 vh:360 vw:640 vbw:1280 vxo:0 vyo:60
162 //1x1 f:8 vh:480 vw:480 vbw:1280 vxo:80 vyo:0
163  int yp;
164 //for yp=0,3,6...
165 //then yp=1,4,7...
166 //then yp=2,5,8....
167 
168  for (yp=(histogram_stage - 1); yp< viewport_height;yp+=3) {
169  for (x=0;x<viewport_width*2 ;x+=HISTO_STEP_SIZE*4) {
170  i = x + yp * viewport_byte_width;
171 #endif
172 
173 #ifndef THUMB_FW
174  y = img[i+1];
175  u = *(signed char*)(&img[i]);
176  //if (u&0x00000080) u|=0xFFFFFF00; // Compiler should handle the unsigned -> signed conversion
177  v = *(signed char*)(&img[i+2]);
178 #else
179  unsigned int ibuf = *(unsigned int*)(&img[i&0xfffffffc]);
180  u =(signed char)((ibuf&0xff)-128);
181  v =(signed char)(((ibuf>>16)&0xff)-128);
182  y = (unsigned char)((ibuf>>8)&0xff);
183 
184 #endif
185  //if (v&0x00000080) v|=0xFFFFFF00; // Compiler should handle the unsigned -> signed conversion
186 
187  ++histogram_proc[HISTO_Y][y]; // Y
188  hi = clip(((y<<12) + v*5743 + 2048)>>12); // R
189  ++histogram_proc[HISTO_R][hi];
190  hi = clip(((y<<12) - u*1411 - v*2925 + 2048)>>12); // G
191  ++histogram_proc[HISTO_G][hi];
192  hi = clip(((y<<12) + u*7258 + 2048)>>12); // B
193  ++histogram_proc[HISTO_B][hi];
194 
195 
196 #ifndef THUMB_FW
197  // Handle case where viewport memory buffer is wider than the actual buffer.
198  x += HISTO_STEP_SIZE * 2; // viewport width is measured in blocks of three bytes each even though the data is stored in six byte chunks !
199  if (x == viewport_width)
200  {
201  i += viewport_row_offset;
202  x = 0;
203  }
204  } //loop i
205 #else
206  }
207  }
208 #endif
209 
210 
211 
212  ++histogram_stage;
213  break;
214 
215  case 4:
216  for (i=0, c=0; i<HISTO_WIDTH; ++i, c+=2) { // G
217  // Merge each pair of values into a single value (for width = 128)
218  // Warning: this is optimised for HISTO_WIDTH = 128, don't change the width unless you re-write this code as well.
219 #ifndef THUMB_FW
221  histogram_proc[HISTO_R][i] = histogram_proc[HISTO_R][c] + histogram_proc[HISTO_R][c+1];
222  histogram_proc[HISTO_G][i] = histogram_proc[HISTO_G][c] + histogram_proc[HISTO_G][c+1];
223  histogram_proc[HISTO_B][i] = histogram_proc[HISTO_B][c] + histogram_proc[HISTO_B][c+1];
224 #endif
225  // Calc combined RGB totals
226  histogram_proc[HISTO_RGB][i] = histogram_proc[HISTO_R][i] + histogram_proc[HISTO_G][i] + histogram_proc[HISTO_B][i];
227  }
228 
229  // calculate maximums
230  for (c=0; c<5; ++c) {
231  for (i=0; i<HISTO_WIDTH; ++i) {
232  if (histo_max[c]<histogram_proc[c][i])
233  histo_max[c]=histogram_proc[c][i];
236  }
237 
238  if (histo_max_center[c] > 0) {
239  histo_max_center_invw[c] = ((float)HISTO_HEIGHT)/histogram_transform((float)histo_max_center[c]);
240  } else if (histo_max[c] > 0) {
241  histo_max_center_invw[c] = ((float)HISTO_HEIGHT)/histogram_transform((float)histo_max[c]);
242  } else {
243  histo_max_center_invw[c] = 0.0f;
244  }
245  }
246 
247  if (histo_max[HISTO_RGB] > 0) { // over- / under- expos
250  +histogram_proc[HISTO_RGB][2]) > exposition_thresh;
251 
252  over_exposed = (histogram_proc[HISTO_RGB][HISTO_WIDTH-3]
253  +histogram_proc[HISTO_RGB][HISTO_WIDTH-2]*4
254  +histogram_proc[HISTO_RGB][HISTO_WIDTH-1]*8) > exposition_thresh;
255  } else {
256  over_exposed = 0;
257  under_exposed = 1;
258  }
259 
260  histogram_stage=5;
261  break;
262 
263  case 5:
264  for (c=0; c<5; ++c) {
265  histo_fill[c]=0;
266  for (i=0; i<HISTO_WIDTH; ++i) {
267  histogram[c][i] = (histogram_transform((float)histogram_proc[c][i]))*histo_max_center_invw[c];
268  if (histogram[c][i] > HISTO_HEIGHT)
269  histogram[c][i] = HISTO_HEIGHT;
270  histo_fill[c]+=histogram[c][i];
271  }
272  }
273 
275  if (conf.histo_auto_ajust) {
276  if (histo_fill[histo_main] < (HISTO_HEIGHT*HISTO_WIDTH)/5) { // try to ajust if average level is less than 20%
277  histo_magnification = (20*HISTO_HEIGHT*HISTO_WIDTH) / histo_fill[histo_main];
278  for (c=0; c<5; ++c) {
279  for (i=0;i<HISTO_WIDTH;i++) {
280  histogram[c][i] = histogram[c][i] * histo_magnification / 100;
281  if (histogram[c][i] > HISTO_HEIGHT)
282  histogram[c][i] = HISTO_HEIGHT;
283  }
284  }
285  }
286  }
287 
288  histogram_stage=0;
289  break;
290  }
291 
292 }
static float identity ( float  x)
static

Definiert in Zeile 72 der Datei histogram.c.

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

Definiert in Zeile 73 der Datei histogram.c.

73 { return log(x); }

Variablen-Dokumentation

libhisto_sym _libhisto
Initialisierung:

Definiert in Zeile 499 der Datei histogram.c.

ModuleInfo _module_info
Initialisierung:

Definiert in Zeile 509 der Datei histogram.c.

long histo_magnification
static

Definiert in Zeile 54 der Datei histogram.c.

unsigned int histo_max[5]

Definiert in Zeile 51 der Datei histogram.c.

unsigned int histo_max_center[5]

Definiert in Zeile 51 der Datei histogram.c.

float histo_max_center_invw[5]
static

Definiert in Zeile 52 der Datei histogram.c.

unsigned char histogram[5][HISTO_WIDTH]
static

Definiert in Zeile 49 der Datei histogram.c.

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

Definiert in Zeile 50 der Datei histogram.c.

long histogram_stage =0
static

Definiert in Zeile 58 der Datei histogram.c.

long over_exposed
static

Definiert in Zeile 56 der Datei histogram.c.

long under_exposed
static

Definiert in Zeile 55 der Datei histogram.c.