| 35 | namespace { |
| 36 | |
| 37 | double SampleAverageLuma(const std::shared_ptr<Frame>& frame, int sample_grid = 4) { |
| 38 | const int width = frame->GetWidth(); |
| 39 | const int height = frame->GetHeight(); |
| 40 | if (width <= 0 || height <= 0) { |
| 41 | return 0.0; |
| 42 | } |
| 43 | |
| 44 | int64_t luma_sum = 0; |
| 45 | int64_t sample_count = 0; |
| 46 | for (int y = 0; y < sample_grid; ++y) { |
| 47 | const int row = std::min(height - 1, (y * height) / sample_grid); |
| 48 | const unsigned char* pixels = frame->GetPixels(row); |
| 49 | for (int x = 0; x < sample_grid; ++x) { |
| 50 | const int col = std::min(width - 1, (x * width) / sample_grid); |
| 51 | const int pixel_index = col * 4; |
| 52 | luma_sum += (pixels[pixel_index] + pixels[pixel_index + 1] + pixels[pixel_index + 2]) / 3; |
| 53 | ++sample_count; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return sample_count > 0 |
| 58 | ? static_cast<double>(luma_sum) / static_cast<double>(sample_count) |
| 59 | : 0.0; |
| 60 | } |
| 61 | |
| 62 | struct HardwareDecoderSettingsGuard { |
| 63 | int decoder = 0; |
no test coverage detected