| 105 | |
| 106 | @dataclass |
| 107 | class VideoCompressionConfig(CompressionConfig): |
| 108 | # Use PLAS sort in compression or not |
| 109 | use_sort: bool = True |
| 110 | # Verbose or not |
| 111 | verbose: bool = True |
| 112 | # QP configuration - can be either int or dict for different attributes |
| 113 | qp: Dict[str, Union[int, Dict[str, Any]]] = field(default_factory=default_qp_values) |
| 114 | # Number of cluster of VQ for shN compression |
| 115 | n_clusters: int = 32768 |
| 116 | # Maps attribute names to their codec functions |
| 117 | attribute_codec_registry: Optional[AttributeCodecs] = field(default_factory=lambda: AttributeCodecs()) |
| 118 | # Enable All Intra coding mode |
| 119 | use_all_intra: bool = False |
| 120 | # Enable debug mode |
| 121 | debug: bool = False |
| 122 | # Indicate which attributes to transform domain before sorting and compression, |
| 123 | # e.g. SH: RGB -> YCbCr, Quat: Unit Quaternion -> Euler Angles |
| 124 | transform_attributes: Dict[str, bool] = field( |
| 125 | default_factory=lambda: { |
| 126 | "means": False, |
| 127 | "scales": False, |
| 128 | "quats": False, |
| 129 | "opacities": False, |
| 130 | "sh0": False, |
| 131 | "shN": False |
| 132 | } |
| 133 | ) |
| 134 | # Chroma subsampling for shN compression |
| 135 | chroma_subsampling: Dict[str, str] = field(default_factory=lambda: { |
| 136 | "sh0": "444", |
| 137 | "shN": "420" |
| 138 | }) |
| 139 | # Use chroma qp offset for sh0 and shN compression |
| 140 | use_chroma_qp_offset: Dict[str, bool]= field(default_factory=lambda: { |
| 141 | "sh0": False, |
| 142 | "shN": False |
| 143 | }) |
| 144 | |
| 145 | def to_dict(self) -> Dict[str, Any]: |
| 146 | """ |
| 147 | Convert the CompressionConfig instance to a dictionary. |
| 148 | If attribute_codec_registry is not None, it will be converted to a dictionary using its to_dict method. |
| 149 | """ |
| 150 | # Get only attributes defined in VideoCompressionConfig |
| 151 | video_compression_attrs = [ |
| 152 | "use_sort", "verbose", "qp", "n_clusters", |
| 153 | "use_all_intra", "debug", "transform_attributes", |
| 154 | "chroma_subsampling", "use_chroma_qp_offset" |
| 155 | ] |
| 156 | |
| 157 | result = {attr: getattr(self, attr) for attr in video_compression_attrs} |
| 158 | |
| 159 | # handle attribute_codec_registry |
| 160 | if self.attribute_codec_registry is not None: |
| 161 | result["attribute_codec_registry"] = self.attribute_codec_registry.to_dict() |
| 162 | |
| 163 | return result |
| 164 |
no test coverage detected