CHDK_DE Vorschauversion  Trunk Rev. 5232
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
curves.c-Dateireferenz
#include "camera_info.h"
#include "conf.h"
#include "stdlib.h"
#include "shooting.h"
#include "raw.h"
#include "gui_lang.h"
#include "curves.h"
#include "module_def.h"
+ Include-Abhängigkeitsdiagramm für curves.c:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define CURVE_SIZE   1024
 
#define CURVE_BYTES   (CURVE_SIZE*sizeof(unsigned short))
 
#define BLACK   32
 
#define LIM(a)   (((a)>1023) ? 1023: a )
 
#define RBLACK(a)   (((a)>BLACK) ? ((a)-BLACK) : 0)
 
#define CURVE0(a, b)   (((a) * curve0[b]) >> 12)
 
#define CURVE1(a, b)   (((a) * curve1[b]) >> 12)
 
#define CURVE2(a, b)   (((a) * curve2[b]) >> 12)
 
#define CURVE3(a, b)   (((a) * curve3[b]) >> 12)
 

Aufzählungen

enum  CURVE_TYPE { CURVE_NONE, CURVE_CUSTOM, CURVE_SYSTEM }
 

Funktionen

static void curve_free_data ()
 
static int curve_load_data (const char *name, CURVE_TYPE curve_type)
 
void curve_init_mode ()
 
void curve_set_mode (int value)
 
void curve_set_file (const char *s)
 
void curveRGB_apply ()
 
void curveL_apply (unsigned sys_index)
 
void curve_apply ()
 
int _module_can_unload ()
 

Variablen

unsigned short * curve_data = NULL
 
CURVE_TYPE current_curve_type = CURVE_NONE
 
libcurves_sym _libcurves
 
ModuleInfo _module_info
 

Makro-Dokumentation

#define BLACK   32

Definiert in Zeile 38 der Datei curves.c.

#define CURVE0 (   a,
 
)    (((a) * curve0[b]) >> 12)

Definiert in Zeile 42 der Datei curves.c.

#define CURVE1 (   a,
 
)    (((a) * curve1[b]) >> 12)

Definiert in Zeile 43 der Datei curves.c.

#define CURVE2 (   a,
 
)    (((a) * curve2[b]) >> 12)

Definiert in Zeile 44 der Datei curves.c.

#define CURVE3 (   a,
 
)    (((a) * curve3[b]) >> 12)

Definiert in Zeile 45 der Datei curves.c.

#define CURVE_BYTES   (CURVE_SIZE*sizeof(unsigned short))

Definiert in Zeile 36 der Datei curves.c.

#define CURVE_SIZE   1024

Definiert in Zeile 35 der Datei curves.c.

#define LIM (   a)    (((a)>1023) ? 1023: a )

Definiert in Zeile 39 der Datei curves.c.

#define RBLACK (   a)    (((a)>BLACK) ? ((a)-BLACK) : 0)

Definiert in Zeile 40 der Datei curves.c.

Dokumentation der Aufzählungstypen

enum CURVE_TYPE
Aufzählungswerte
CURVE_NONE 
CURVE_CUSTOM 
CURVE_SYSTEM 

Definiert in Zeile 47 der Datei curves.c.

47  {
48  CURVE_NONE,
51 }CURVE_TYPE;

Dokumentation der Funktionen

int _module_can_unload ( )

Definiert in Zeile 426 der Datei curves.c.

427 {
428  return conf.curve_enable == 0;
429 }
void curve_apply ( )

Definiert in Zeile 386 der Datei curves.c.

386  {
387  short EVbias = shooting_get_ev_correction1();
388 
389  switch(conf.curve_enable) {
390  case 0:
391  break;
392  case 1: // Custom
394  if(curve_data[0] > 1023){ // L curve contains multiplicator factors (0 Luminance has factor 1)
395  curveL_apply(0);
396  } else {
397  curveRGB_apply();
398  }
399  };
400  break;
401  case 2:
402  case 3: // +1EV, +2EV
404  break;
405  case 4: // Auto DR
406 
408  if (EVbias <-128) { // x4 for Bias from "-1 2/3" and below
409  curveL_apply(1);
410  } else if(EVbias<-32){ // x2 for Bias from "-1 1/3" to "-2/3"
411  curveL_apply(0);
412  }
413  }
414  break;
415  }
416 
417 }
static void curve_free_data ( )
static

Definiert in Zeile 55 der Datei curves.c.

55  {
57  curve_data = NULL;
59 }
void curve_init_mode ( )

Definiert in Zeile 103 der Datei curves.c.

103  {
104  switch(conf.curve_enable) {
105  case 1: // custom - ensure alloc and load conf.curve_file
107  break;
108  case 2: // system - ensure alloc and load syscurve
109  case 3:
110  case 4:
111  curve_load_data("A/CHDK/SYSCURVES.CVF",CURVE_SYSTEM);
112  break;
113  default:
114  conf.curve_enable = 0;
115  case 0: // disabled - free
116  curve_free_data();
117  }
118 }
static int curve_load_data ( const char *  name,
CURVE_TYPE  curve_type 
)
static

Definiert in Zeile 62 der Datei curves.c.

62  {
63  unsigned size;
64  FILE *fd;
65  if (current_curve_type != curve_type) {
67  }
68 
69  if (curve_type == CURVE_NONE) {
70  return 1;
71  }
72 
73  if(!name || !*name) {
75  return 0;
76  }
77 
78  if( curve_type == CURVE_CUSTOM ) {
79  size = CURVE_BYTES*4;
80  }
81  else {
82  size = CURVE_BYTES*2;
83  }
84 
85  if (!curve_data)
86  curve_data=malloc(size);
87 
88  if(!curve_data) {
90  return 0;
91  }
92  fd = fopen(name, "r+b");
93  if (!fd) {
95  return 0;
96  }
97  fread(curve_data, 1, size, fd);
98  fclose(fd);
99  current_curve_type = curve_type;
100  return 1;
101 }
void curve_set_file ( const char *  s)

Definiert in Zeile 125 der Datei curves.c.

125  {
126  int l;
127  if(s) {
128  if(strncmp(s,"A/",2)==0) strncpy(conf.curve_file,s,99);
129  else {
130  l=strlen(CURVE_DIR);
132  conf.curve_file[l]='/';
133  strncpy(&conf.curve_file[l+1],s,99-l-1);
134  }
135  conf.curve_file[99]=0x0;
136  curve_init_mode();
137  }
138 }
void curve_set_mode ( int  value)

Definiert in Zeile 120 der Datei curves.c.

120  {
121  if((value>=0) && (value<=4)) conf.curve_enable=value;
122  curve_init_mode();
123 }
void curveL_apply ( unsigned  sys_index)

Definiert in Zeile 227 der Datei curves.c.

227  {
228  int i,j;
229  unsigned short pixVal0, pixVal1, pixVal2;
230  unsigned char *src;
231 
232  unsigned short *curve0;
233  unsigned short *curve1;
234  unsigned short *curve2;
235  unsigned short *curve3;
237  if (sys_index > 1)
238  return;
239  curve0 = curve1 = curve2 = curve3 = curve_data + sys_index*CURVE_SIZE;
240  }
241  else if(current_curve_type == CURVE_CUSTOM) {
242  curve0 = curve_data;
243  curve1 = curve0 + CURVE_SIZE;
244  curve2 = curve1 + CURVE_SIZE;
245  curve3 = curve2 + CURVE_SIZE;
246  } else {
247  return;
248  }
249 
250 
251  // Set pointer to picture raw data in memory
252  src = (unsigned char *) get_raw_image_addr();
253 
254  // Loop through picture rows
255  for (i=camera_sensor.raw_rows; i;i-=2){
256  // Loop through picture columns
257  for (j=camera_sensor.raw_rowpix; j; j-=8, src+=10){
258  pixVal0=((0x3fc&(((unsigned short)(src[1]))<<2)) | (src[0] >> 6));
259  pixVal1=((0x3f0&(((unsigned short)(src[0]))<<4)) | (src[3] >> 4));
260  if (pixVal1) {
261  pixVal1 = RBLACK( pixVal1 );
262  if (pixVal0) {
263  pixVal0 = RBLACK( pixVal0 );
264  pixVal0 = CURVE0( pixVal0, pixVal1 ) + BLACK;
265  pixVal0 = LIM( pixVal0 );
266  }
267  pixVal1 = CURVE1( pixVal1, pixVal1 ) + BLACK;
268  pixVal1 = LIM( pixVal1 );
269  }
270  *(src+1) = (unsigned char) ((pixVal0>>2)); // 0
271  *src = (unsigned char) ((pixVal0<<6)|(pixVal1>>4)); //0, 1
272 
273  pixVal2=((0x3c0&(((unsigned short)(src[3]))<<6)) | (src[2] >> 2));
274  pixVal0=((0x300&(((unsigned short)(src[2]))<<8)) | (src[5]));
275  if (pixVal0) {
276  pixVal0 = RBLACK( pixVal0 );
277  if (pixVal2) {
278  pixVal2 = RBLACK( pixVal2 );
279  pixVal2 = CURVE0( pixVal2, pixVal0 ) + BLACK;
280  pixVal2 = LIM( pixVal2 );
281  }
282  pixVal0 = CURVE1( pixVal0, pixVal0 ) + BLACK;
283  pixVal0 = LIM( pixVal0 );
284  }
285  *(src+3) = (unsigned char) ((pixVal1<<4)|(pixVal2>>6)); //1,2
286  *(src+2) = (unsigned char) ((pixVal2<<2)|(pixVal0>>8)); //2,3 =>(2,0)
287  *(src+5) = (unsigned char) ((pixVal0)); //3 (=>0)
288 
289  pixVal0=((0x3fc&(((unsigned short)(src[4]))<<2)) | (src[7] >> 6));
290  pixVal1=((0x3f0&(((unsigned short)(src[7]))<<4)) | (src[6] >> 4));
291  if (pixVal1) {
292  pixVal1 = RBLACK( pixVal1 );
293  if (pixVal0) {
294  pixVal0 = RBLACK( pixVal0 );
295  pixVal0 = CURVE0( pixVal0, pixVal1 ) + BLACK;
296  pixVal0 = LIM( pixVal0 );
297  }
298  pixVal1 = CURVE1( pixVal1, pixVal1 ) + BLACK;
299  pixVal1 = LIM( pixVal1 );
300  }
301  *(src+4) = (unsigned char) ((pixVal0>>2)); // 4 => 0
302  *(src+7) = (unsigned char) ((pixVal0<<6)|(pixVal1>>4)); // 4,5 => (0,1)
303 
304  pixVal2=((0x3c0&(((unsigned short)(src[6]))<<6)) | (src[9] >> 2));
305  pixVal0=((0x300&(((unsigned short)(src[9]))<<8)) | (src[8]));
306  if (pixVal0) {
307  pixVal0 = RBLACK( pixVal0 );
308  if (pixVal2) {
309  pixVal2 = RBLACK( pixVal2 );
310  pixVal2 = CURVE0( pixVal2, pixVal0 ) + BLACK;
311  pixVal2 = LIM( pixVal2 );
312  }
313  pixVal0 = CURVE1( pixVal0, pixVal0 ) + BLACK;
314  pixVal0 = LIM( pixVal0 );
315  }
316  *(src+6) = (unsigned char) ((pixVal1<<4)|(pixVal2>>6)); // 5,6 => (1,2)
317  *(src+9) = (unsigned char) ((pixVal2<<2)|(pixVal0>>8)); // 6,7 =>(2,0)
318  *(src+8) = (unsigned char) ((pixVal0)); //7 (=>0)
319  }
320  for (j=camera_sensor.raw_rowpix; j; j-=8, src+=10){
321  pixVal0=((0x3fc&(((unsigned short)(src[1]))<<2)) | (src[0] >> 6));
322  pixVal1=((0x3f0&(((unsigned short)(src[0]))<<4)) | (src[3] >> 4));
323  if (pixVal0) {
324  pixVal0 = RBLACK( pixVal0 );
325  if (pixVal1) {
326  pixVal1 = RBLACK( pixVal1 );
327  pixVal1 = CURVE3( pixVal1, pixVal0 ) + BLACK;
328  pixVal1 = LIM( pixVal1 );
329  }
330  pixVal0 = CURVE2( pixVal0, pixVal0 ) + BLACK;
331  pixVal0 = LIM( pixVal0 );
332  }
333  *(src+1) = (unsigned char) ((pixVal0>>2)); // 0
334  *src = (unsigned char) ((pixVal0<<6)|(pixVal1>>4)); //0, 1
335 
336  pixVal2=((0x3c0&(((unsigned short)(src[3]))<<6)) | (src[2] >> 2));
337  pixVal0=((0x300&(((unsigned short)(src[2]))<<8)) | (src[5]));
338  if (pixVal2) {
339  pixVal2 = RBLACK( pixVal2 );
340  if (pixVal0) {
341  pixVal0 = RBLACK( pixVal0 );
342  pixVal0 = CURVE3( pixVal0, pixVal2 ) + BLACK;
343  pixVal0 = LIM( pixVal0 );
344  }
345  pixVal2 = CURVE2( pixVal2, pixVal2 ) + BLACK;
346  pixVal2 = LIM( pixVal2 );
347  }
348  *(src+3) = (unsigned char) ((pixVal1<<4)|(pixVal2>>6)); //1,2
349  *(src+2) = (unsigned char) ((pixVal2<<2)|(pixVal0>>8)); //2,3 =>(2,0)
350  *(src+5) = (unsigned char) ((pixVal0)); //3 (=>0)
351 
352  pixVal0=((0x3fc&(((unsigned short)(src[4]))<<2)) | (src[7] >> 6));
353  pixVal1=((0x3f0&(((unsigned short)(src[7]))<<4)) | (src[6] >> 4));
354  if (pixVal0) {
355  pixVal0 = RBLACK( pixVal0 );
356  if (pixVal1) {
357  pixVal1 = RBLACK( pixVal1 );
358  pixVal1 = CURVE3( pixVal1, pixVal0 ) + BLACK;
359  pixVal1 = LIM( pixVal1 );
360  }
361  pixVal0 = CURVE2( pixVal0, pixVal0 ) + BLACK;
362  pixVal0 = LIM( pixVal0 );
363  }
364  *(src+4) = (unsigned char) ((pixVal0>>2)); // 4 => 0
365  *(src+7) = (unsigned char) ((pixVal0<<6)|(pixVal1>>4)); // 4,5 => (0,1)
366 
367  pixVal2=((0x3c0&(((unsigned short)(src[6]))<<6)) | (src[9] >> 2));
368  pixVal0=((0x300&(((unsigned short)(src[9]))<<8)) | (src[8]));
369  if (pixVal2) {
370  pixVal2 = RBLACK( pixVal2 );
371  if (pixVal0) {
372  pixVal0 = RBLACK( pixVal0 );
373  pixVal0 = CURVE3( pixVal0, pixVal2 ) + BLACK;
374  pixVal0 = LIM( pixVal0 );
375  }
376  pixVal2 = CURVE2( pixVal2, pixVal2 ) + BLACK;
377  pixVal2 = LIM( pixVal2 );
378  }
379  *(src+6) = (unsigned char) ((pixVal1<<4)|(pixVal2>>6)); // 5,6 => (1,2)
380  *(src+9) = (unsigned char) ((pixVal2<<2)|(pixVal0>>8)); // 6,7 =>(2,0)
381  *(src+8) = (unsigned char) ((pixVal0)); //7 (=>0)
382  }
383  }
384 }
void curveRGB_apply ( )

Definiert in Zeile 141 der Datei curves.c.

141  {
142  int i,j;
143  unsigned short pixVal0, pixVal1, pixVal2;
144  unsigned char *src;
145 
146  unsigned short *curve0 = curve_data;
147  unsigned short *curve1 = curve0 + CURVE_SIZE;
148  unsigned short *curve2 = curve1 + CURVE_SIZE;
149  unsigned short *curve3 = curve2 + CURVE_SIZE;
150 
152  return;
153 
154  // Set pointer to picture raw data in memory
155  src = (unsigned char *) get_raw_image_addr();
156 
157 
158  // Loop through picture rows
159  for (i=camera_sensor.raw_rows; i;i-=2){
160  // Loop through picture columns
161  for (j=camera_sensor.raw_rowpix; j; j-=8, src+=10){
162  pixVal0=((0x3fc&(((unsigned short)(src[1]))<<2)) | (src[0] >> 6));
163  pixVal1=((0x3f0&(((unsigned short)(src[0]))<<4)) | (src[3] >> 4));
164  pixVal0 = curve0[pixVal0];
165  pixVal1 = curve1[pixVal1];
166  *(src+1) = (unsigned char) ((pixVal0>>2)); // 0
167  *src = (unsigned char) ((pixVal0<<6)|(pixVal1>>4)); //0, 1
168 
169  pixVal2=((0x3c0&(((unsigned short)(src[3]))<<6)) | (src[2] >> 2));
170  pixVal0=((0x300&(((unsigned short)(src[2]))<<8)) | (src[5]));
171  pixVal2 = curve0[pixVal2];
172  pixVal0 = curve1[pixVal0];
173  *(src+3) = (unsigned char) ((pixVal1<<4)|(pixVal2>>6)); //1,2
174  *(src+2) = (unsigned char) ((pixVal2<<2)|(pixVal0>>8)); //2,3 =>(2,0)
175  *(src+5) = (unsigned char) ((pixVal0)); //3 (=>0)
176 
177  pixVal0=((0x3fc&(((unsigned short)(src[4]))<<2)) | (src[7] >> 6));
178  pixVal1=((0x3f0&(((unsigned short)(src[7]))<<4)) | (src[6] >> 4));
179  pixVal0 = curve0[pixVal0];
180  pixVal1 = curve1[pixVal1];
181  *(src+4) = (unsigned char) ((pixVal0>>2)); // 4 => 0
182  *(src+7) = (unsigned char) ((pixVal0<<6)|(pixVal1>>4)); // 4,5 => (0,1)
183 
184  pixVal2=((0x3c0&(((unsigned short)(src[6]))<<6)) | (src[9] >> 2));
185  pixVal0=((0x300&(((unsigned short)(src[9]))<<8)) | (src[8]));
186  pixVal2 = curve0[pixVal2];
187  pixVal0 = curve1[pixVal0];
188  *(src+6) = (unsigned char) ((pixVal1<<4)|(pixVal2>>6)); // 5,6 => (1,2)
189  *(src+9) = (unsigned char) ((pixVal2<<2)|(pixVal0>>8)); // 6,7 =>(2,0)
190  *(src+8) = (unsigned char) ((pixVal0)); //7 (=>0) }
191  }
192  for (j=camera_sensor.raw_rowpix;j; j-=8, src+=10){
193  pixVal0=((0x3fc&(((unsigned short)(src[1]))<<2)) | (src[0] >> 6));
194  pixVal1=((0x3f0&(((unsigned short)(src[0]))<<4)) | (src[3] >> 4));
195  pixVal0 = curve2[pixVal0];
196  pixVal1 = curve3[pixVal1];
197  *(src+1) = (unsigned char) ((pixVal0>>2)); // 0
198  *src = (unsigned char) ((pixVal0<<6)|(pixVal1>>4)); //0, 1
199 
200  pixVal2=((0x3c0&(((unsigned short)(src[3]))<<6)) | (src[2] >> 2));
201  pixVal0=((0x300&(((unsigned short)(src[2]))<<8)) | (src[5]));
202  pixVal2 = curve2[pixVal2];
203  pixVal0 = curve3[pixVal0];
204  *(src+3) = (unsigned char) ((pixVal1<<4)|(pixVal2>>6)); //1,2
205  *(src+2) = (unsigned char) ((pixVal2<<2)|(pixVal0>>8)); //2,3 =>(2,0)
206  *(src+5) = (unsigned char) ((pixVal0)); //3 (=>0)
207 
208  pixVal0=((0x3fc&(((unsigned short)(src[4]))<<2)) | (src[7] >> 6));
209  pixVal1=((0x3f0&(((unsigned short)(src[7]))<<4)) | (src[6] >> 4));
210  pixVal0 = curve2[pixVal0];
211  pixVal1 = curve3[pixVal1];
212  *(src+4) = (unsigned char) ((pixVal0>>2)); // 4 => 0
213  *(src+7) = (unsigned char) ((pixVal0<<6)|(pixVal1>>4)); // 4,5 => (0,1)
214 
215  pixVal2=((0x3c0&(((unsigned short)(src[6]))<<6)) | (src[9] >> 2));
216  pixVal0=((0x300&(((unsigned short)(src[9]))<<8)) | (src[8]));
217  pixVal2 = curve2[pixVal2];
218  pixVal0 = curve3[pixVal0];
219  *(src+6) = (unsigned char) ((pixVal1<<4)|(pixVal2>>6)); // 5,6 => (1,2)
220  *(src+9) = (unsigned char) ((pixVal2<<2)|(pixVal0>>8)); // 6,7 =>(2,0)
221  *(src+8) = (unsigned char) ((pixVal0)); //7 (=>0)
222  }
223  }
224 }

Variablen-Dokumentation

libcurves_sym _libcurves
Initialisierung:

Definiert in Zeile 433 der Datei curves.c.

ModuleInfo _module_info
Initialisierung:

Definiert in Zeile 445 der Datei curves.c.

CURVE_TYPE current_curve_type = CURVE_NONE

Definiert in Zeile 53 der Datei curves.c.

unsigned short* curve_data = NULL

Definiert in Zeile 33 der Datei curves.c.