Parse the log output for PSNR and performance metrics. Args: image: The test image that was compressed. output: The astcenc compression output log. Return: Tuple containing PSNR in dB, total time in seconds, coding time in se
(self, image: TestImage, output: list[str])
| 119 | return result.stdout.splitlines() |
| 120 | |
| 121 | def parse_output(self, image: TestImage, output: list[str]) -> RunResult: |
| 122 | ''' |
| 123 | Parse the log output for PSNR and performance metrics. |
| 124 | |
| 125 | Args: |
| 126 | image: The test image that was compressed. |
| 127 | output: The astcenc compression output log. |
| 128 | |
| 129 | Return: |
| 130 | Tuple containing PSNR in dB, total time in seconds, coding time |
| 131 | in seconds, and coding rate in MT/s. |
| 132 | ''' |
| 133 | # Regex patterns. provided by this particular subclass |
| 134 | pattern_psnr = self.get_psnr_pattern(image) |
| 135 | pattern_total_time = self.get_total_time_pattern() |
| 136 | pattern_coding_time = self.get_coding_time_pattern() |
| 137 | pattern_coding_rate = self.get_coding_rate_pattern() |
| 138 | |
| 139 | # Extract results from the log |
| 140 | psnr = None |
| 141 | total_time = None |
| 142 | coding_time = None |
| 143 | coding_rate = None |
| 144 | |
| 145 | for line in output: |
| 146 | if match := pattern_psnr.match(line): |
| 147 | psnr = float(match.group(1)) |
| 148 | continue |
| 149 | |
| 150 | if match := pattern_total_time.match(line): |
| 151 | total_time = float(match.group(1)) |
| 152 | continue |
| 153 | |
| 154 | if match := pattern_coding_time.match(line): |
| 155 | coding_time = float(match.group(1)) |
| 156 | continue |
| 157 | |
| 158 | if match := pattern_coding_rate.match(line): |
| 159 | coding_rate = float(match.group(1)) |
| 160 | continue |
| 161 | |
| 162 | stdout = '\n'.join(output) |
| 163 | assert psnr is not None, f'Missing PSNR {stdout}' |
| 164 | assert total_time is not None, f'Missing total time {stdout}' |
| 165 | assert coding_time is not None, f'Missing coding time {stdout}' |
| 166 | assert coding_rate is not None, f'Missing coding rate {stdout}' |
| 167 | |
| 168 | return (psnr, total_time, coding_time, coding_rate) |
| 169 | |
| 170 | def get_psnr_pattern(self, image: TestImage) -> re.Pattern: |
| 171 | ''' |
no test coverage detected