CHDK_DE Vorschauversion  Trunk Rev. 5232
 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 478 der Datei histogram.c.

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

Definiert in Zeile 473 der Datei histogram.c.

474 {
475  return 0;
476 }
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 339 der Datei histogram.c.

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

Definiert in Zeile 379 der Datei histogram.c.

380 {
381  if (is_osd_edit ||
383  (
385  ((conf.show_histo==SHOW_HISTO_REC) && camera_info.state.mode_rec && (recreview_hold==0)) ||
386  ((conf.show_histo==SHOW_HISTO_ALWAYS) && (recreview_hold==0))
387  )
388  )
389  )
390  {
393 
394  switch (conf.histo_layout)
395  {
396  case OSD_HISTO_LAYOUT_Y:
398  break;
402  break;
407  break;
414  break;
421  break;
424  break;
428  break;
429  case OSD_HISTO_LAYOUT_A:
430  default:
432  break;
433  }
434 
436  {
438  {
440  }
442  {
444  }
445  }
448  if (conf.histo_auto_ajust){
449  if (histo_magnification) {
450  char osd_buf[64];
451  sprintf(osd_buf, " %d.%02dx ", histo_magnification/100, histo_magnification%100);
453  } else if (is_osd_edit){
455  } else {
457  }
458  }
459  }
460 }
static void gui_osd_draw_single_histo ( int  hist,
coord  x,
coord  y,
int  small 
)
static

Definiert in Zeile 283 der Datei histogram.c.

284 {
287 
288  register unsigned int i, v, threshold;
289  register color cl, cl_over, cl_bg = BG_COLOR(hc);
291 
292  switch (hist)
293  {
294  case HISTO_R:
295  cl=COLOR_RED;
296  break;
297  case HISTO_G:
298  cl=COLOR_GREEN;
299  break;
300  case HISTO_B:
301  cl=COLOR_BLUE;
302  break;
303  case HISTO_RGB:
304  case HISTO_Y:
305  default:
306  cl=FG_COLOR(hc);
307  break;
308  }
309 
310  if (small) {
311  h>>=1; w>>=1;
312  for (i=0; i<w; ++i) {
313  threshold = (histogram[hist][i<<1]+histogram[hist][(i<<1)+1])>>2;
314 
315  for (v=1; v<h-1; ++v)
316  draw_pixel(x+1+i, y+h-v, (v<=threshold)?cl:cl_bg);
317  cl_over = (threshold==h && conf.show_overexp)?BG_COLOR(hc2):cl;
318  for (; v<h; ++v)
319  draw_pixel(x+1+i, y+h-v, (v<=threshold)?cl_over:cl_bg);
320  }
321  } else {
322  for (i=0; i<w; ++i) {
323  threshold = histogram[hist][i];
324 
325  for (v=1; v<h-3; ++v)
326  draw_pixel(x+1+i, y+h-v, (v<=threshold)?cl:cl_bg);
327  cl_over = (threshold==h && conf.show_overexp)?BG_COLOR(hc2):cl;
328  for (; v<h; ++v)
329  draw_pixel(x+1+i, y+h-v, (v<=threshold)?cl_over:cl_bg);
330  }
331  }
332 
333  draw_rectangle(x, y, x+1+w, y+h, hc2, RECT_BORDER1);
334  //Vertical Lines
335  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));
336 }
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_step_size;
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 
139  viewport_height = vid_get_viewport_height_proper();
140  viewport_size = viewport_height * vid_get_viewport_byte_width();
141  // Viewport visible width in bytes
142 #ifndef THUMB_FW
143  viewport_width = vid_get_viewport_width_proper() * 6 / 4;
144 #else
145  viewport_width = vid_get_viewport_width_proper() * 4 / 2;
146 #endif
147  // Number of columns to scan - 30 for 720 pixel wide viewport, 40 for widescreen (960 wide).
148  // This give 24 pixel increments between columns.
149  // 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.
150  // 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.
151  // We offset all columns by 4 pixels so the first column is not hard against the left edge
152  viewport_step_size = viewport_width / (vid_get_viewport_width_proper() / 24);
153  // Increment to adjust for each row if physical width > visible width
154  viewport_row_offset = vid_get_viewport_row_offset();
155 
156  for (c=0; c<5; ++c) {
157  memset(histogram_proc[c],0,256*sizeof(unsigned short));
158  histo_max[c] = histo_max_center[c] = 0;
159  }
160 
161  histogram_stage=1;
162  break;
163 
164  case 1:
165  case 2:
166  case 3:
167  x = 0; // count how many bytes we have done on the current row (to skip unused buffer space at end of each row)
168 
169  for (i=(histogram_stage-1)*(viewport_step_size/3)+(viewport_step_size/6); i<viewport_size; i+=viewport_step_size) {
170 
171  y = img[i+1];
172 #ifndef THUMB_FW
173  u = (signed char)img[i];
174  v = (signed char)img[i+2];
175 #else
176  u = (int)img[i] - 128;
177  v = (int)img[i+2] - 128;
178 #endif
179 // img[i+1] = img[i+3] = 255; // Draw columns on screen for debugging
180 
181  ++histogram_proc[HISTO_Y][y]; // Y
182  hi = clip(((y<<12) + v*5743 + 2048)>>12); // R
183  ++histogram_proc[HISTO_R][hi];
184  hi = clip(((y<<12) - u*1411 - v*2925 + 2048)>>12); // G
185  ++histogram_proc[HISTO_G][hi];
186  hi = clip(((y<<12) + u*7258 + 2048)>>12); // B
187  ++histogram_proc[HISTO_B][hi];
188 
189  // Handle case where viewport memory buffer is wider than the actual buffer.
190  x += viewport_step_size;
191  if (x == viewport_width)
192  {
193  i += viewport_row_offset;
194  x = 0;
195  }
196  } //loop i
197 
198  ++histogram_stage;
199  break;
200 
201  case 4:
202  for (i=0, c=0; i<HISTO_WIDTH; ++i, c+=2) { // G
203  // Merge each pair of values into a single value (for width = 128)
204  // Warning: this is optimised for HISTO_WIDTH = 128, don't change the width unless you re-write this code as well.
205 #ifndef THUMB_FW
207  histogram_proc[HISTO_R][i] = histogram_proc[HISTO_R][c] + histogram_proc[HISTO_R][c+1];
208  histogram_proc[HISTO_G][i] = histogram_proc[HISTO_G][c] + histogram_proc[HISTO_G][c+1];
209  histogram_proc[HISTO_B][i] = histogram_proc[HISTO_B][c] + histogram_proc[HISTO_B][c+1];
210 #endif
211  // Calc combined RGB totals
212  histogram_proc[HISTO_RGB][i] = histogram_proc[HISTO_R][i] + histogram_proc[HISTO_G][i] + histogram_proc[HISTO_B][i];
213  }
214 
215  // calculate maximums
216  for (c=0; c<5; ++c) {
217  for (i=0; i<HISTO_WIDTH; ++i) {
218  if (histo_max[c]<histogram_proc[c][i])
219  histo_max[c]=histogram_proc[c][i];
222  }
223 
224  if (histo_max_center[c] > 0) {
225  histo_max_center_invw[c] = ((float)HISTO_HEIGHT)/histogram_transform((float)histo_max_center[c]);
226  } else if (histo_max[c] > 0) {
227  histo_max_center_invw[c] = ((float)HISTO_HEIGHT)/histogram_transform((float)histo_max[c]);
228  } else {
229  histo_max_center_invw[c] = 0.0f;
230  }
231  }
232 
233  if (histo_max[HISTO_RGB] > 0) { // over- / under- expos
236  +histogram_proc[HISTO_RGB][2]) > exposition_thresh;
237 
238  over_exposed = (histogram_proc[HISTO_RGB][HISTO_WIDTH-3]
239  +histogram_proc[HISTO_RGB][HISTO_WIDTH-2]*4
240  +histogram_proc[HISTO_RGB][HISTO_WIDTH-1]*8) > exposition_thresh;
241  } else {
242  over_exposed = 0;
243  under_exposed = 1;
244  }
245 
246  histogram_stage=5;
247  break;
248 
249  case 5:
250  for (c=0; c<5; ++c) {
251  histo_fill[c]=0;
252  for (i=0; i<HISTO_WIDTH; ++i) {
253  histogram[c][i] = (histogram_transform((float)histogram_proc[c][i]))*histo_max_center_invw[c];
254  if (histogram[c][i] > HISTO_HEIGHT)
255  histogram[c][i] = HISTO_HEIGHT;
256  histo_fill[c]+=histogram[c][i];
257  }
258  }
259 
261  if (conf.histo_auto_ajust) {
262  if (histo_fill[histo_main] < (HISTO_HEIGHT*HISTO_WIDTH)/5) { // try to ajust if average level is less than 20%
263  histo_magnification = (20*HISTO_HEIGHT*HISTO_WIDTH) / histo_fill[histo_main];
264  for (c=0; c<5; ++c) {
265  for (i=0;i<HISTO_WIDTH;i++) {
266  histogram[c][i] = histogram[c][i] * histo_magnification / 100;
267  if (histogram[c][i] > HISTO_HEIGHT)
268  histogram[c][i] = HISTO_HEIGHT;
269  }
270  }
271  }
272  }
273 
274  histogram_stage=0;
275  break;
276  }
277 
278 }
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 485 der Datei histogram.c.

ModuleInfo _module_info
Initialisierung:

Definiert in Zeile 495 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.