Skip to content

Commit 3b56919

Browse files
authored
New output voltage control
new option : -VmaxR -VmaxG -VmaxB (try to scale data to match the specified output levels) -MaxValueR -MaxValueG -MaxValueB (specify the maximum value of the input signal) (everything higher is clipped)
1 parent 56a2126 commit 3b56919

File tree

1 file changed

+112
-5
lines changed

1 file changed

+112
-5
lines changed

src/fl2k_file.c

Lines changed: 112 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ double signal_gain_r = 1;
113113
double signal_gain_g = 1;
114114
double signal_gain_b = 1;
115115

116+
//Voltage control
117+
double v_max_r = -1;
118+
double v_max_g = -1;
119+
double v_max_b = -1;
120+
121+
int max_value_r = 255;
122+
int max_value_g = 255;
123+
int max_value_b = 255;
124+
125+
int min_value_r = 0;
126+
int min_value_g = 0;
127+
int min_value_b = 0;
128+
116129
//combine mode
117130
int cmb_mode_r = 0;
118131
int cmb_mode_g = 0;
@@ -191,6 +204,15 @@ void usage(void)
191204
"\t[-SgainR signal gain for output R (0.5 to 2.0) (clipping white)\n"
192205
"\t[-SgainG signal gain for output G (0.5 to 2.0) (clipping white)\n"
193206
"\t[-SgainB signal gain for output B (0.5 to 2.0) (clipping white)\n"
207+
"\t[-VmaxR maximum output voltage for channel R (0.003 to 0.7) (scale value) (disable Cgain and Sgain)\n"
208+
"\t[-VmaxG maximum output voltage for channel G (0.003 to 0.7) (scale value) (disable Cgain and Sgain)\n"
209+
"\t[-VmaxB maximum output voltage for channel B (0.003 to 0.7) (scale value) (disable Cgain and Sgain)\n"
210+
"\t[-MaxValueR max value for channel R (1 to 255) (reference level) (used for Vmax)\n"
211+
"\t[-MaxValueG max value for channel G (1 to 255) (reference level) (used for Vmax)\n"
212+
"\t[-MaxValueB max value for channel B (1 to 255) (reference level) (used for Vmax)\n"
213+
//"\t[-MinValueR min value for channel R (0 to 254) (reference level) (used for Vmax)\n"
214+
//"\t[-MinValueG min value for channel G (0 to 254) (reference level) (used for Vmax)\n"
215+
//"\t[-MinValueB min value for channel B (0 to 254) (reference level) (used for Vmax)\n"
194216
"\t[-ireR IRE level for input R (-50.0 to +50.0)\n"
195217
"\t[-ireG IRE level for input G (-50.0 to +50.0)\n"
196218
"\t[-ireB IRE level for input B (-50.0 to +50.0)\n"
@@ -271,6 +293,8 @@ int read_sample_file(void *inpt_color)
271293
double *chroma_gain = NULL;
272294
double *ire_level = NULL;
273295
double signal_gain = 1;
296+
double v_max = -1;
297+
int max_value = 255;
274298

275299
int is16 = 0;
276300
int is_signed = 0;
@@ -322,6 +346,8 @@ int read_sample_file(void *inpt_color)
322346
is16 = r16;
323347
is_signed = r_sign;
324348
signal_gain = signal_gain_r;
349+
v_max = v_max_r;
350+
max_value = max_value_r;
325351
if(sync_a == 'R' && pipe_mode == 'A')
326352
{
327353
is_sync_a = 1;
@@ -349,6 +375,8 @@ int read_sample_file(void *inpt_color)
349375
is16 = g16;
350376
is_signed = g_sign;
351377
signal_gain = signal_gain_g;
378+
v_max = v_max_g;
379+
max_value = max_value_g;
352380
if(sync_a == 'G' && pipe_mode == 'A')
353381
{
354382
is_sync_a = 1;
@@ -376,6 +404,8 @@ int read_sample_file(void *inpt_color)
376404
is16 = b16;
377405
is_signed = b_sign;
378406
signal_gain = signal_gain_b;
407+
v_max = v_max_b;
408+
max_value = max_value_b;
379409
if(sync_a == 'B' && pipe_mode == 'A')
380410
{
381411
is_sync_a = 1;
@@ -582,7 +612,7 @@ int read_sample_file(void *inpt_color)
582612
tmp_buf[i] = value8;
583613
}
584614

585-
if(*chroma_gain != 0)
615+
if(*chroma_gain != 1)
586616
{
587617
//color burst reading
588618
if(((*line_sample_cnt >= cbust_start) && (*line_sample_cnt <= cbust_end)) && (*line_cnt == (21 + ((unsigned long)*field_cnt % 2))))
@@ -617,15 +647,32 @@ int read_sample_file(void *inpt_color)
617647
}
618648
}
619649

620-
if(tmp_buf[i] > 5)
650+
//signal gain
651+
if(signal_gain != 1)
652+
{
653+
if(tmp_buf[i] > 5)
654+
{
655+
if((tmp_buf[i] * signal_gain) > 255)
656+
{
657+
tmp_buf[i] = 255;
658+
}
659+
else
660+
{
661+
tmp_buf[i] = round(tmp_buf[i] * signal_gain);
662+
}
663+
}
664+
}
665+
666+
//scale to max voltage
667+
if(v_max > 0.0)
621668
{
622-
if((tmp_buf[i] * signal_gain) > 255)
669+
if(round(tmp_buf[i]*(255/max_value)) > 255)
623670
{
624671
tmp_buf[i] = 255;
625672
}
626673
else
627674
{
628-
tmp_buf[i] = round(tmp_buf[i] * signal_gain);
675+
tmp_buf[i] = round((tmp_buf[i]*(255/max_value))/(0.7/v_max));
629676
}
630677
}
631678

@@ -930,7 +977,13 @@ int main(int argc, char **argv)
930977
{"signR", 1, 0, 35},
931978
{"signG", 1, 0, 36},
932979
{"signB", 1, 0, 37},
933-
{0, 0, 0, 0}
980+
{"VmaxR", 1, 0, 38},
981+
{"VmaxG", 1, 0, 39},
982+
{"VmaxB", 1, 0, 40},
983+
{"MaxValueR", 1, 0, 41},
984+
{"MaxValueG", 1, 0, 42},
985+
{"MaxValueB", 1, 0, 43},
986+
{0, 0, 0, 0}//reminder : letter value are from 65 to 122
934987
};
935988

936989
while ((opt = getopt_long_only(argc, argv, "d:r:s:uR:G:B:A:",long_options, &option_index)) != -1) {
@@ -1101,6 +1154,24 @@ int main(int argc, char **argv)
11011154
else if(*optarg == 's' || *optarg == 'S'){override_b_sign = 1;}
11021155
else{override_b_sign = atoi(optarg);}
11031156
break;
1157+
case 38:
1158+
v_max_r = atof(optarg);
1159+
break;
1160+
case 39:
1161+
v_max_g = atof(optarg);
1162+
break;
1163+
case 40:
1164+
v_max_b = atof(optarg);
1165+
break;
1166+
case 41:
1167+
max_value_r = atoi(optarg);
1168+
break;
1169+
case 42:
1170+
max_value_g = atoi(optarg);
1171+
break;
1172+
case 43:
1173+
max_value_b = atoi(optarg);
1174+
break;
11041175
default:
11051176
usage();
11061177
break;
@@ -1180,6 +1251,42 @@ int main(int argc, char **argv)
11801251
usage();
11811252
}
11821253

1254+
if(((v_max_r < 0.003 || v_max_r > 0.7) && v_max_r != -1)|| ((v_max_g < 0.003 || v_max_g > 0.7) && v_max_g != -1) || ((v_max_b < 0.003 || v_max_b > 0.7) && v_max_b != -1))
1255+
{
1256+
fprintf(stderr, "\n maximum voltage (%f) is invalid / range : (0.003 , 0.7)\n\n",v_max_g);
1257+
usage();
1258+
}
1259+
1260+
if((max_value_r < 1 || max_value_r > 255) || (max_value_g < 1 || max_value_g > 255) || (max_value_b < 1 || max_value_b > 255))
1261+
{
1262+
fprintf(stderr, "\n max value is invalid / range : (1 , 255)\n\n");
1263+
usage();
1264+
}
1265+
1266+
if(v_max_r > 0.0)
1267+
{
1268+
fprintf(stderr, "\nGain and ire control disabled for output R\n\n");
1269+
c_gain_r = 1;
1270+
signal_gain_r = 1;
1271+
ire_r = 0;
1272+
}
1273+
1274+
if(v_max_g > 0.0)
1275+
{
1276+
fprintf(stderr, "\nGain and ire control disabled for output G\n\n");
1277+
c_gain_g = 1;
1278+
signal_gain_g = 1;
1279+
ire_g = 0;
1280+
}
1281+
1282+
if(v_max_b > 0.0)
1283+
{
1284+
fprintf(stderr, "\nGain and ire control disabled for output B\n\n");
1285+
c_gain_b = 1;
1286+
signal_gain_b = 1;
1287+
ire_b = 0;
1288+
}
1289+
11831290
if(samp_rate == 17734475 || samp_rate == 17735845)//PAL
11841291
{
11851292
start_r = start_r * ((709375 + (1135 * tbcR)) * (1 + r16));// set first frame

0 commit comments

Comments
 (0)