From b63a0e15a3a769a862b1ffec139264727a21a00e Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Sat, 15 Apr 2023 00:57:45 -0700 Subject: [PATCH] Internal change PiperOrigin-RevId: 524485761 --- mediapipe/util/cpu_util.cc | 14 +++---- mediapipe/util/image_frame_util.cc | 59 +++++++++++++++--------------- mediapipe/util/label_map_util.cc | 4 +- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/mediapipe/util/cpu_util.cc b/mediapipe/util/cpu_util.cc index c1be9793..052eabb8 100644 --- a/mediapipe/util/cpu_util.cc +++ b/mediapipe/util/cpu_util.cc @@ -43,7 +43,7 @@ ABSL_FLAG(std::string, system_cpu_max_freq_file, namespace mediapipe { namespace { -constexpr uint32 kBufferLength = 64; +constexpr uint32_t kBufferLength = 64; absl::StatusOr GetFilePath(int cpu) { if (!absl::StrContains(absl::GetFlag(FLAGS_system_cpu_max_freq_file), "$0")) { @@ -54,7 +54,7 @@ absl::StatusOr GetFilePath(int cpu) { return absl::Substitute(absl::GetFlag(FLAGS_system_cpu_max_freq_file), cpu); } -absl::StatusOr GetCpuMaxFrequency(int cpu) { +absl::StatusOr GetCpuMaxFrequency(int cpu) { auto path_or_status = GetFilePath(cpu); if (!path_or_status.ok()) { return path_or_status.status(); @@ -65,7 +65,7 @@ absl::StatusOr GetCpuMaxFrequency(int cpu) { char buffer[kBufferLength]; file.getline(buffer, kBufferLength); file.close(); - uint64 frequency; + uint64_t frequency; if (absl::SimpleAtoi(buffer, &frequency)) { return frequency; } else { @@ -79,7 +79,7 @@ absl::StatusOr GetCpuMaxFrequency(int cpu) { } std::set InferLowerOrHigherCoreIds(bool lower) { - std::vector> cpu_freq_pairs; + std::vector> cpu_freq_pairs; for (int cpu = 0; cpu < NumCPUCores(); ++cpu) { auto freq_or_status = GetCpuMaxFrequency(cpu); if (freq_or_status.ok()) { @@ -90,12 +90,12 @@ std::set InferLowerOrHigherCoreIds(bool lower) { return {}; } - absl::c_sort(cpu_freq_pairs, [lower](const std::pair& left, - const std::pair& right) { + absl::c_sort(cpu_freq_pairs, [lower](const std::pair& left, + const std::pair& right) { return (lower && left.second < right.second) || (!lower && left.second > right.second); }); - uint64 edge_freq = cpu_freq_pairs[0].second; + uint64_t edge_freq = cpu_freq_pairs[0].second; std::set inferred_cores; for (const auto& cpu_freq_pair : cpu_freq_pairs) { diff --git a/mediapipe/util/image_frame_util.cc b/mediapipe/util/image_frame_util.cc index a3a038b0..bf2773fd 100644 --- a/mediapipe/util/image_frame_util.cc +++ b/mediapipe/util/image_frame_util.cc @@ -89,12 +89,12 @@ void ImageFrameToYUVImage(const ImageFrame& image_frame, YUVImage* yuv_image) { const int uv_stride = (uv_width + 15) & ~15; const int y_size = y_stride * height; const int uv_size = uv_stride * uv_height; - uint8* data = - reinterpret_cast(aligned_malloc(y_size + uv_size * 2, 16)); + uint8_t* data = + reinterpret_cast(aligned_malloc(y_size + uv_size * 2, 16)); std::function deallocate = [data]() { aligned_free(data); }; - uint8* y = data; - uint8* u = y + y_size; - uint8* v = u + uv_size; + uint8_t* y = data; + uint8_t* u = y + y_size; + uint8_t* v = u + uv_size; yuv_image->Initialize(libyuv::FOURCC_I420, deallocate, // y, y_stride, // u, uv_stride, // @@ -123,10 +123,11 @@ void ImageFrameToYUVNV12Image(const ImageFrame& image_frame, const int uv_stride = y_stride; const int uv_height = (height + 1) / 2; const int uv_size = uv_stride * uv_height; - uint8* data = reinterpret_cast(aligned_malloc(y_size + uv_size, 16)); + uint8_t* data = + reinterpret_cast(aligned_malloc(y_size + uv_size, 16)); std::function deallocate = [data] { aligned_free(data); }; - uint8* y = data; - uint8* uv = y + y_size; + uint8_t* y = data; + uint8_t* uv = y + y_size; yuv_nv12_image->Initialize(libyuv::FOURCC_NV12, deallocate, y, y_stride, uv, uv_stride, nullptr, 0, width, height); const int rv = libyuv::I420ToNV12( @@ -210,44 +211,44 @@ void YUVImageToImageFrameFromFormat(const YUVImage& yuv_image, } } -void SrgbToMpegYCbCr(const uint8 r, const uint8 g, const uint8 b, // - uint8* y, uint8* cb, uint8* cr) { +void SrgbToMpegYCbCr(const uint8_t r, const uint8_t g, const uint8_t b, // + uint8_t* y, uint8_t* cb, uint8_t* cr) { // ITU-R BT.601 conversion from sRGB to YCbCr. // FastIntRound is used rather than SafeRound since the possible // range of values is [16,235] for Y and [16,240] for Cb and Cr and we // don't care about the rounding direction for values exactly between // two integers. - *y = static_cast( + *y = static_cast( mediapipe::MathUtil::FastIntRound(16.0 + // 65.481 * r / 255.0 + // 128.553 * g / 255.0 + // 24.966 * b / 255.0)); - *cb = static_cast( + *cb = static_cast( mediapipe::MathUtil::FastIntRound(128.0 + // -37.797 * r / 255.0 + // -74.203 * g / 255.0 + // 112.0 * b / 255.0)); - *cr = static_cast( + *cr = static_cast( mediapipe::MathUtil::FastIntRound(128.0 + // 112.0 * r / 255.0 + // -93.786 * g / 255.0 + // -18.214 * b / 255.0)); } -void MpegYCbCrToSrgb(const uint8 y, const uint8 cb, const uint8 cr, // - uint8* r, uint8* g, uint8* b) { +void MpegYCbCrToSrgb(const uint8_t y, const uint8_t cb, const uint8_t cr, // + uint8_t* r, uint8_t* g, uint8_t* b) { // ITU-R BT.601 conversion from YCbCr to sRGB // Use SafeRound since many MPEG YCbCr values do not correspond directly // to an sRGB value. - *r = mediapipe::MathUtil::SafeRound( // - 255.0 / 219.0 * (y - 16.0) + // + *r = mediapipe::MathUtil::SafeRound( // + 255.0 / 219.0 * (y - 16.0) + // 255.0 / 112.0 * 0.701 * (cr - 128.0)); - *g = mediapipe::MathUtil::SafeRound( + *g = mediapipe::MathUtil::SafeRound( 255.0 / 219.0 * (y - 16.0) - // 255.0 / 112.0 * 0.886 * 0.114 / 0.587 * (cb - 128.0) - // 255.0 / 112.0 * 0.701 * 0.299 / 0.587 * (cr - 128.0)); - *b = mediapipe::MathUtil::SafeRound( // - 255.0 / 219.0 * (y - 16.0) + // + *b = mediapipe::MathUtil::SafeRound( // + 255.0 / 219.0 * (y - 16.0) + // 255.0 / 112.0 * 0.886 * (cb - 128.0)); } @@ -260,15 +261,15 @@ void MpegYCbCrToSrgb(const uint8 y, const uint8 cb, const uint8 cr, // cv::Mat GetSrgbToLinearRgb16Lut() { cv::Mat lut(1, 256, CV_16UC1); - uint16* ptr = lut.ptr(); + uint16_t* ptr = lut.ptr(); constexpr double kUint8Max = 255.0; constexpr double kUint16Max = 65535.0; for (int i = 0; i < 256; ++i) { if (i < 0.04045 * kUint8Max) { - ptr[i] = static_cast( + ptr[i] = static_cast( (static_cast(i) / kUint8Max / 12.92) * kUint16Max + .5); } else { - ptr[i] = static_cast( + ptr[i] = static_cast( pow((static_cast(i) / kUint8Max + 0.055) / 1.055, 2.4) * kUint16Max + .5); @@ -279,15 +280,15 @@ cv::Mat GetSrgbToLinearRgb16Lut() { cv::Mat GetLinearRgb16ToSrgbLut() { cv::Mat lut(1, 65536, CV_8UC1); - uint8* ptr = lut.ptr(); + uint8_t* ptr = lut.ptr(); constexpr double kUint8Max = 255.0; constexpr double kUint16Max = 65535.0; for (int i = 0; i < 65536; ++i) { if (i < 0.0031308 * kUint16Max) { - ptr[i] = static_cast( + ptr[i] = static_cast( (static_cast(i) / kUint16Max * 12.92) * kUint8Max + .5); } else { - ptr[i] = static_cast( + ptr[i] = static_cast( (1.055 * pow(static_cast(i) / kUint16Max, 1.0 / 2.4) - .055) * kUint8Max + .5); @@ -306,13 +307,13 @@ void LinearRgb16ToSrgb(const cv::Mat& source, cv::Mat* destination) { destination->create(source.size(), CV_8UC(source.channels())); static const cv::Mat kLut = GetLinearRgb16ToSrgbLut(); - const uint8* lookup_table_ptr = kLut.ptr(); + const uint8_t* lookup_table_ptr = kLut.ptr(); const int num_channels = source.channels(); for (int row = 0; row < source.rows; ++row) { for (int col = 0; col < source.cols; ++col) { for (int channel = 0; channel < num_channels; ++channel) { - uint8* ptr = destination->ptr(row); - const uint16* ptr16 = source.ptr(row); + uint8_t* ptr = destination->ptr(row); + const uint16_t* ptr16 = source.ptr(row); ptr[col * num_channels + channel] = lookup_table_ptr[ptr16[col * num_channels + channel]]; } diff --git a/mediapipe/util/label_map_util.cc b/mediapipe/util/label_map_util.cc index 914a2ba7..eb909349 100644 --- a/mediapipe/util/label_map_util.cc +++ b/mediapipe/util/label_map_util.cc @@ -25,7 +25,7 @@ namespace mediapipe { -absl::StatusOr> BuildLabelMapFromFiles( +absl::StatusOr> BuildLabelMapFromFiles( absl::string_view labels_file_contents, absl::string_view display_names_file) { if (labels_file_contents.empty()) { @@ -68,7 +68,7 @@ absl::StatusOr> BuildLabelMapFromFiles( label_map_items[i].set_display_name(display_names[i]); } } - proto_ns::Map label_map; + proto_ns::Map label_map; for (int i = 0; i < label_map_items.size(); ++i) { label_map[i] = label_map_items[i]; }