Skip to content

Commit 5e9cdc7

Browse files
committed
feat: added Matrix Coefficient and Color Primaries options
1 parent ca98e54 commit 5e9cdc7

File tree

1 file changed

+256
-0
lines changed

1 file changed

+256
-0
lines changed

src/main.rs

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct AV1Studio {
2424
height: String,
2525

2626
output_pixel_format: PixelFormat,
27+
color_primaries: ColorPrimaries,
28+
matrix_coefficients: MatrixCoefficients,
2729

2830
file_concatenation: String,
2931

@@ -66,6 +68,8 @@ impl Default for AV1Studio {
6668
width: String::new(),
6769
height: String::new(),
6870
output_pixel_format: PixelFormat::default(),
71+
color_primaries: ColorPrimaries::default(),
72+
matrix_coefficients: MatrixCoefficients::default(),
6973
file_concatenation: String::new(),
7074
preset: 4.0,
7175
crf: 27.0,
@@ -115,6 +119,92 @@ impl PixelFormat {
115119
}
116120
}
117121

122+
#[derive(PartialEq, Eq, Clone, Copy)]
123+
enum ColorPrimaries {
124+
Bt709, // [1] BT.709
125+
Unspecified, // [2] unspecified, default
126+
Bt470m, // [4] BT.470 System M (historical)
127+
Bt470bg, // [5] BT.470 System B, G (historical)
128+
Bt601, // [6] BT.601
129+
Smpte240, // [7] SMPTE 240
130+
Film, // [8] Generic film (color filters using illuminant C)
131+
Bt2020, // [9] SMPTE 428 (CIE 1921 XYZ)
132+
Xyz, // [10] SMPTE RP 431-2
133+
Smpte431, // [11] SMPTE EG 431-2
134+
Smpte432, // [12] SMPTE EG 432-1
135+
Ebu3213, // [22] EBU Tech. 3213-E
136+
}
137+
138+
impl Default for ColorPrimaries {
139+
fn default() -> Self {
140+
ColorPrimaries::Unspecified
141+
}
142+
}
143+
144+
impl ColorPrimaries {
145+
fn as_str(&self) -> &str {
146+
match self {
147+
ColorPrimaries::Bt709 => "1",
148+
ColorPrimaries::Unspecified => "2",
149+
ColorPrimaries::Bt470m => "4",
150+
ColorPrimaries::Bt470bg => "5",
151+
ColorPrimaries::Bt601 => "6",
152+
ColorPrimaries::Smpte240 => "7",
153+
ColorPrimaries::Film => "8",
154+
ColorPrimaries::Bt2020 => "9",
155+
ColorPrimaries::Xyz => "10",
156+
ColorPrimaries::Smpte431 => "11",
157+
ColorPrimaries::Smpte432 => "12",
158+
ColorPrimaries::Ebu3213 => "22",
159+
}
160+
}
161+
}
162+
163+
#[derive(PartialEq, Eq, Clone, Copy)]
164+
enum MatrixCoefficients {
165+
Identity, // [0] Identity matrix
166+
Bt709, // [1] BT.709
167+
Unspecified, // [2] unspecified, default
168+
Fcc, // [4] US FCC 73.628
169+
Bt470bg, // [5] BT.470 System B, G (historical)
170+
Bt601, // [6] BT.601
171+
Smpte240, // [7] SMPTE 240 M
172+
Ycgco, // [8] YCgCo
173+
Bt2020Ncl, // [9] BT.2020 non-constant luminance, BT.2100 YCbCr
174+
Bt2020Cl, // [10] BT.2020 constant luminance
175+
Smpte2085, // [11] SMPTE ST 2085 YDzDx
176+
ChromaNcl, // [12] Chromaticity-derived non-constant luminance
177+
ChromaCl, // [13] Chromaticity-derived constant luminance
178+
Ictcp, // [14] BT.2100 ICtCp
179+
}
180+
181+
impl Default for MatrixCoefficients {
182+
fn default() -> Self {
183+
MatrixCoefficients::Unspecified
184+
}
185+
}
186+
187+
impl MatrixCoefficients {
188+
fn as_str(&self) -> &str {
189+
match self {
190+
MatrixCoefficients::Identity => "0",
191+
MatrixCoefficients::Bt709 => "1",
192+
MatrixCoefficients::Unspecified => "2",
193+
MatrixCoefficients::Fcc => "4",
194+
MatrixCoefficients::Bt470bg => "5",
195+
MatrixCoefficients::Bt601 => "6",
196+
MatrixCoefficients::Smpte240 => "7",
197+
MatrixCoefficients::Ycgco => "8",
198+
MatrixCoefficients::Bt2020Ncl => "9",
199+
MatrixCoefficients::Bt2020Cl => "10",
200+
MatrixCoefficients::Smpte2085 => "11",
201+
MatrixCoefficients::ChromaNcl => "12",
202+
MatrixCoefficients::ChromaCl => "13",
203+
MatrixCoefficients::Ictcp => "14",
204+
}
205+
}
206+
}
207+
118208
impl AV1Studio {
119209
fn new(cc: &eframe::CreationContext<'_>) -> Self {
120210
let mut style = (*cc.egui_ctx.style()).clone();
@@ -371,6 +461,172 @@ impl eframe::App for AV1Studio {
371461
});
372462
});
373463

464+
ui.horizontal(|ui| {
465+
let label_text = "Color Primaries";
466+
let label_width = ui.label(label_text).rect.max.x - ui.min_rect().min.x;
467+
max_width = max_width.max(label_width);
468+
if label_width < max_width {
469+
ui.allocate_space(egui::vec2(max_width -label_width, 1.0));
470+
}
471+
ui.label(":");
472+
ComboBox::from_id_salt("color_primaries_combobox")
473+
.selected_text(self.color_primaries.as_str())
474+
.show_ui(ui, |ui| {
475+
ui.selectable_value(
476+
&mut self.color_primaries,
477+
ColorPrimaries::Bt709,
478+
"(1) BT.709",
479+
);
480+
ui.selectable_value(
481+
&mut self.color_primaries,
482+
ColorPrimaries::Unspecified,
483+
"(2) Unspecified, Default"
484+
);
485+
ui.selectable_value(
486+
&mut self.color_primaries,
487+
ColorPrimaries::Bt470m,
488+
"(4) BT.470 System M (historical)",
489+
);
490+
ui.selectable_value(
491+
&mut self.color_primaries,
492+
ColorPrimaries::Bt470bg,
493+
"(5) BT.470 System B, G (historical)",
494+
);
495+
ui.selectable_value(
496+
&mut self.color_primaries,
497+
ColorPrimaries::Bt601,
498+
"(6) BT.601",
499+
);
500+
ui.selectable_value(
501+
&mut self.color_primaries,
502+
ColorPrimaries::Smpte240,
503+
"(7) SMPTE 240",
504+
);
505+
ui.selectable_value(
506+
&mut self.color_primaries,
507+
ColorPrimaries::Film,
508+
"(8) Generic Film (color filters using illuminant C)",
509+
);
510+
ui.selectable_value(
511+
&mut self.color_primaries,
512+
ColorPrimaries::Bt2020,
513+
"(9) BT.2020, BT.2100",
514+
);
515+
ui.selectable_value(
516+
&mut self.color_primaries,
517+
ColorPrimaries::Xyz,
518+
"(10) SMPTE 428 (CIE 1921 XYZ)",
519+
);
520+
ui.selectable_value(
521+
&mut self.color_primaries,
522+
ColorPrimaries::Smpte431,
523+
"(11) SMPTE RP 431-2",
524+
);
525+
ui.selectable_value(
526+
&mut self.color_primaries,
527+
ColorPrimaries::Smpte432,
528+
"(12) SMPT EG 432-1",
529+
);
530+
ui.selectable_value(
531+
&mut self.color_primaries,
532+
ColorPrimaries::Ebu3213,
533+
"(22) EBU Tech. 3213-E",
534+
);
535+
});
536+
ui.label(RichText::new("ℹ").weak()).on_hover_ui(|ui| {
537+
ui.style_mut().interaction.selectable_labels = true;
538+
ui.label("Color primaries, refer to the (SVT-AV1-PSY) user guide Appendix A.2 for full details. If you don't know what you're doing, just use the default option (2).");
539+
});
540+
});
541+
542+
ui.horizontal(|ui| {
543+
let label_text = "Matrix Coefficients";
544+
let label_width = ui.label(label_text).rect.max.x - ui.min_rect().min.x;
545+
max_width = max_width.max(label_width);
546+
if label_width < max_width {
547+
ui.allocate_space(egui::vec2(max_width - label_width, 1.0));
548+
}
549+
ui.label(":");
550+
ComboBox::from_id_salt("matrix_coefficients_combobox")
551+
.selected_text(self.matrix_coefficients.as_str())
552+
.show_ui(ui, |ui| {
553+
ui.selectable_value(
554+
&mut self.matrix_coefficients,
555+
MatrixCoefficients::Identity,
556+
"(0) Identity matrix",
557+
);
558+
ui.selectable_value(
559+
&mut self.matrix_coefficients,
560+
MatrixCoefficients::Bt709,
561+
"(1) BT.709",
562+
);
563+
ui.selectable_value(
564+
&mut self.matrix_coefficients,
565+
MatrixCoefficients::Unspecified,
566+
"(2) unspecified, default",
567+
);
568+
ui.selectable_value(
569+
&mut self.matrix_coefficients,
570+
MatrixCoefficients::Fcc,
571+
"(4) US FCC 73.628",
572+
);
573+
ui.selectable_value(
574+
&mut self.matrix_coefficients,
575+
MatrixCoefficients::Bt470bg,
576+
"(5) BT.470 System B, G (historical)",
577+
);
578+
ui.selectable_value(
579+
&mut self.matrix_coefficients,
580+
MatrixCoefficients::Bt601,
581+
"(6) BT.601",
582+
);
583+
ui.selectable_value(
584+
&mut self.matrix_coefficients,
585+
MatrixCoefficients::Smpte240,
586+
"(7) SMPTE 240 M",
587+
);
588+
ui.selectable_value(
589+
&mut self.matrix_coefficients,
590+
MatrixCoefficients::Ycgco,
591+
"(8) YCgCo",
592+
);
593+
ui.selectable_value(
594+
&mut self.matrix_coefficients,
595+
MatrixCoefficients::Bt2020Ncl,
596+
"(9) BT.2020 non-constant luminance, BT.2100 YCbCr",
597+
);
598+
ui.selectable_value(
599+
&mut self.matrix_coefficients,
600+
MatrixCoefficients::Bt2020Cl,
601+
"(10) BT.2020 constant luminance",
602+
);
603+
ui.selectable_value(
604+
&mut self.matrix_coefficients,
605+
MatrixCoefficients::Smpte2085,
606+
"(11) SMPTE ST 2085 YDzDx",
607+
);
608+
ui.selectable_value(
609+
&mut self.matrix_coefficients,
610+
MatrixCoefficients::ChromaNcl,
611+
"(12) Chromaticity-derived non-constant luminance",
612+
);
613+
ui.selectable_value(
614+
&mut self.matrix_coefficients,
615+
MatrixCoefficients::ChromaCl,
616+
"(13) Chromaticity-derived constant luminance",
617+
);
618+
ui.selectable_value(
619+
&mut self.matrix_coefficients,
620+
MatrixCoefficients::Ictcp,
621+
"(14) BT.2100 ICtCp",
622+
);
623+
});
624+
ui.label(RichText::new("ℹ").weak()).on_hover_ui(|ui| {
625+
ui.style_mut().interaction.selectable_labels = true;
626+
ui.label("Matrix coefficients, refer to the (SVT-AV1-PSY) user guide Appendix A.2 for full details. If you don't know what you're doing, just use the default option (2).");
627+
});
628+
});
629+
374630
ui.add_space(ui.spacing().item_spacing.y * 2.0);
375631

376632
ui.label(RichText::new("Encoding Parameters").weak());

0 commit comments

Comments
 (0)