Internal change

PiperOrigin-RevId: 520263349
This commit is contained in:
MediaPipe Team 2023-03-29 01:31:00 -07:00 committed by Copybara-Service
parent dc132a5629
commit 316bd05e86
6 changed files with 68 additions and 68 deletions

View File

@ -87,7 +87,7 @@ void ImageSubmodule(pybind11::module* module) {
image
.def(
py::init([](mediapipe::ImageFormat::Format format,
const py::array_t<uint8, py::array::c_style>& data) {
const py::array_t<uint8_t, py::array::c_style>& data) {
if (format != mediapipe::ImageFormat::GRAY8 &&
format != mediapipe::ImageFormat::SRGB &&
format != mediapipe::ImageFormat::SRGBA) {
@ -96,13 +96,13 @@ void ImageSubmodule(pybind11::module* module) {
"SRGB, and SRGBA MediaPipe image formats.");
}
return Image(std::shared_ptr<ImageFrame>(
CreateImageFrame<uint8>(format, data)));
CreateImageFrame<uint8_t>(format, data)));
}),
R"doc(For uint8 data type, valid ImageFormat are GRAY8, SGRB, and SRGBA.)doc",
py::arg("image_format"), py::arg("data").noconvert())
.def(
py::init([](mediapipe::ImageFormat::Format format,
const py::array_t<uint16, py::array::c_style>& data) {
const py::array_t<uint16_t, py::array::c_style>& data) {
if (format != mediapipe::ImageFormat::GRAY16 &&
format != mediapipe::ImageFormat::SRGB48 &&
format != mediapipe::ImageFormat::SRGBA64) {
@ -112,7 +112,7 @@ void ImageSubmodule(pybind11::module* module) {
"SRGB48, and SRGBA64 MediaPipe image formats.");
}
return Image(std::shared_ptr<ImageFrame>(
CreateImageFrame<uint16>(format, data)));
CreateImageFrame<uint16_t>(format, data)));
}),
R"doc(For uint16 data type, valid ImageFormat are GRAY16, SRGB48, and SRGBA64.)doc",
py::arg("image_format"), py::arg("data").noconvert())
@ -182,11 +182,11 @@ void ImageSubmodule(pybind11::module* module) {
py::cast(self, py::return_value_policy::reference);
switch (self.GetImageFrameSharedPtr()->ByteDepth()) {
case 1:
return GetValue<uint8>(*self.GetImageFrameSharedPtr(), pos,
py_object);
return GetValue<uint8_t>(*self.GetImageFrameSharedPtr(), pos,
py_object);
case 2:
return GetValue<uint16>(*self.GetImageFrameSharedPtr(), pos,
py_object);
return GetValue<uint16_t>(*self.GetImageFrameSharedPtr(), pos,
py_object);
case 4:
return GetValue<float>(*self.GetImageFrameSharedPtr(), pos,
py_object);
@ -223,7 +223,7 @@ void ImageSubmodule(pybind11::module* module) {
R"doc(Return True if the pixel data is unallocated.)doc")
.def(
"is_aligned",
[](Image& self, uint32 alignment_boundary) {
[](Image& self, uint32_t alignment_boundary) {
return self.GetImageFrameSharedPtr()->IsAligned(alignment_boundary);
},
R"doc(Return True if each row of the data is aligned to alignment boundary, which must be 1 or a power of 2.

View File

@ -114,7 +114,7 @@ void ImageFrameSubmodule(pybind11::module* module) {
image_frame
.def(
py::init([](mediapipe::ImageFormat::Format format,
const py::array_t<uint8, py::array::c_style>& data) {
const py::array_t<uint8_t, py::array::c_style>& data) {
if (format != mediapipe::ImageFormat::GRAY8 &&
format != mediapipe::ImageFormat::SRGB &&
format != mediapipe::ImageFormat::SRGBA) {
@ -122,13 +122,13 @@ void ImageFrameSubmodule(pybind11::module* module) {
"uint8 image data should be one of the GRAY8, "
"SRGB, and SRGBA MediaPipe image formats.");
}
return CreateImageFrame<uint8>(format, data);
return CreateImageFrame<uint8_t>(format, data);
}),
R"doc(For uint8 data type, valid ImageFormat are GRAY8, SGRB, and SRGBA.)doc",
py::arg("image_format"), py::arg("data").noconvert())
.def(
py::init([](mediapipe::ImageFormat::Format format,
const py::array_t<uint16, py::array::c_style>& data) {
const py::array_t<uint16_t, py::array::c_style>& data) {
if (format != mediapipe::ImageFormat::GRAY16 &&
format != mediapipe::ImageFormat::SRGB48 &&
format != mediapipe::ImageFormat::SRGBA64) {
@ -137,7 +137,7 @@ void ImageFrameSubmodule(pybind11::module* module) {
"uint16 image data should be one of the GRAY16, "
"SRGB48, and SRGBA64 MediaPipe image formats.");
}
return CreateImageFrame<uint16>(format, data);
return CreateImageFrame<uint16_t>(format, data);
}),
R"doc(For uint16 data type, valid ImageFormat are GRAY16, SRGB48, and SRGBA64.)doc",
py::arg("image_format"), py::arg("data").noconvert())
@ -203,9 +203,9 @@ void ImageFrameSubmodule(pybind11::module* module) {
py::cast(self, py::return_value_policy::reference);
switch (self.ByteDepth()) {
case 1:
return GetValue<uint8>(self, pos, py_object);
return GetValue<uint8_t>(self, pos, py_object);
case 2:
return GetValue<uint16>(self, pos, py_object);
return GetValue<uint16_t>(self, pos, py_object);
case 4:
return GetValue<float>(self, pos, py_object);
default:

View File

@ -53,11 +53,11 @@ void PacketSubmodule(pybind11::module* module) {
packet.def(py::init<Packet const&>())
.def("at", [](Packet* self,
int64 ts_value) { return self->At(Timestamp(ts_value)); })
int64_t ts_value) { return self->At(Timestamp(ts_value)); })
.def("at", [](Packet* self, Timestamp ts) { return self->At(ts); })
.def_property(
"timestamp", &Packet::Timestamp,
[](Packet* p, int64 ts_value) { *p = p->At(Timestamp(ts_value)); })
[](Packet* p, int64_t ts_value) { *p = p->At(Timestamp(ts_value)); })
.def("__repr__", [](const Packet& self) {
return absl::StrCat(
"<mediapipe.Packet with timestamp: ",

View File

@ -36,11 +36,11 @@ Packet CreateImageFramePacket(mediapipe::ImageFormat::Format format,
if (format == mediapipe::ImageFormat::SRGB ||
format == mediapipe::ImageFormat::SRGBA ||
format == mediapipe::ImageFormat::GRAY8) {
return Adopt(CreateImageFrame<uint8>(format, data, copy).release());
return Adopt(CreateImageFrame<uint8_t>(format, data, copy).release());
} else if (format == mediapipe::ImageFormat::GRAY16 ||
format == mediapipe::ImageFormat::SRGB48 ||
format == mediapipe::ImageFormat::SRGBA64) {
return Adopt(CreateImageFrame<uint16>(format, data, copy).release());
return Adopt(CreateImageFrame<uint16_t>(format, data, copy).release());
} else if (format == mediapipe::ImageFormat::VEC32F1 ||
format == mediapipe::ImageFormat::VEC32F2) {
return Adopt(CreateImageFrame<float>(format, data, copy).release());
@ -56,12 +56,12 @@ Packet CreateImagePacket(mediapipe::ImageFormat::Format format,
format == mediapipe::ImageFormat::SRGBA ||
format == mediapipe::ImageFormat::GRAY8) {
return MakePacket<Image>(std::shared_ptr<ImageFrame>(
CreateImageFrame<uint8>(format, data, copy)));
CreateImageFrame<uint8_t>(format, data, copy)));
} else if (format == mediapipe::ImageFormat::GRAY16 ||
format == mediapipe::ImageFormat::SRGB48 ||
format == mediapipe::ImageFormat::SRGBA64) {
return MakePacket<Image>(std::shared_ptr<ImageFrame>(
CreateImageFrame<uint16>(format, data, copy)));
CreateImageFrame<uint16_t>(format, data, copy)));
} else if (format == mediapipe::ImageFormat::VEC32F1 ||
format == mediapipe::ImageFormat::VEC32F2) {
return MakePacket<Image>(std::shared_ptr<ImageFrame>(
@ -139,7 +139,7 @@ void PublicPacketCreators(pybind11::module* m) {
m->def(
"create_int",
[](int64 data) {
[](int64_t data) {
RaisePyErrorIfOverflow(data, INT_MIN, INT_MAX);
return MakePacket<int>(data);
},
@ -163,9 +163,9 @@ void PublicPacketCreators(pybind11::module* m) {
m->def(
"create_int8",
[](int64 data) {
[](int64_t data) {
RaisePyErrorIfOverflow(data, INT8_MIN, INT8_MAX);
return MakePacket<int8>(data);
return MakePacket<int8_t>(data);
},
R"doc(Create a MediaPipe int8 Packet from an integer.
@ -187,9 +187,9 @@ void PublicPacketCreators(pybind11::module* m) {
m->def(
"create_int16",
[](int64 data) {
[](int64_t data) {
RaisePyErrorIfOverflow(data, INT16_MIN, INT16_MAX);
return MakePacket<int16>(data);
return MakePacket<int16_t>(data);
},
R"doc(Create a MediaPipe int16 Packet from an integer.
@ -211,9 +211,9 @@ void PublicPacketCreators(pybind11::module* m) {
m->def(
"create_int32",
[](int64 data) {
[](int64_t data) {
RaisePyErrorIfOverflow(data, INT32_MIN, INT32_MAX);
return MakePacket<int32>(data);
return MakePacket<int32_t>(data);
},
R"doc(Create a MediaPipe int32 Packet from an integer.
@ -234,7 +234,7 @@ void PublicPacketCreators(pybind11::module* m) {
py::arg().noconvert(), py::return_value_policy::move);
m->def(
"create_int64", [](int64 data) { return MakePacket<int64>(data); },
"create_int64", [](int64_t data) { return MakePacket<int64_t>(data); },
R"doc(Create a MediaPipe int64 Packet from an integer.
Args:
@ -254,9 +254,9 @@ void PublicPacketCreators(pybind11::module* m) {
m->def(
"create_uint8",
[](int64 data) {
[](int64_t data) {
RaisePyErrorIfOverflow(data, 0, UINT8_MAX);
return MakePacket<uint8>(data);
return MakePacket<uint8_t>(data);
},
R"doc(Create a MediaPipe uint8 Packet from an integer.
@ -278,9 +278,9 @@ void PublicPacketCreators(pybind11::module* m) {
m->def(
"create_uint16",
[](int64 data) {
[](int64_t data) {
RaisePyErrorIfOverflow(data, 0, UINT16_MAX);
return MakePacket<uint16>(data);
return MakePacket<uint16_t>(data);
},
R"doc(Create a MediaPipe uint16 Packet from an integer.
@ -302,9 +302,9 @@ void PublicPacketCreators(pybind11::module* m) {
m->def(
"create_uint32",
[](int64 data) {
[](int64_t data) {
RaisePyErrorIfOverflow(data, 0, UINT32_MAX);
return MakePacket<uint32>(data);
return MakePacket<uint32_t>(data);
},
R"doc(Create a MediaPipe uint32 Packet from an integer.
@ -325,7 +325,7 @@ void PublicPacketCreators(pybind11::module* m) {
py::arg().noconvert(), py::return_value_policy::move);
m->def(
"create_uint64", [](uint64 data) { return MakePacket<uint64>(data); },
"create_uint64", [](uint64_t data) { return MakePacket<uint64_t>(data); },
R"doc(Create a MediaPipe uint64 Packet from an integer.
Args:

View File

@ -100,15 +100,15 @@ void PublicPacketGetters(pybind11::module* m) {
"get_int",
[](const Packet& packet) {
if (packet.ValidateAsType<int>().ok()) {
return static_cast<int64>(packet.Get<int>());
} else if (packet.ValidateAsType<int8>().ok()) {
return static_cast<int64>(packet.Get<int8>());
} else if (packet.ValidateAsType<int16>().ok()) {
return static_cast<int64>(packet.Get<int16>());
} else if (packet.ValidateAsType<int32>().ok()) {
return static_cast<int64>(packet.Get<int32>());
} else if (packet.ValidateAsType<int64>().ok()) {
return static_cast<int64>(packet.Get<int64>());
return static_cast<int64_t>(packet.Get<int>());
} else if (packet.ValidateAsType<int8_t>().ok()) {
return static_cast<int64_t>(packet.Get<int8_t>());
} else if (packet.ValidateAsType<int16_t>().ok()) {
return static_cast<int64_t>(packet.Get<int16_t>());
} else if (packet.ValidateAsType<int32_t>().ok()) {
return static_cast<int64_t>(packet.Get<int32_t>());
} else if (packet.ValidateAsType<int64_t>().ok()) {
return static_cast<int64_t>(packet.Get<int64_t>());
}
throw RaisePyError(
PyExc_ValueError,
@ -133,14 +133,14 @@ void PublicPacketGetters(pybind11::module* m) {
m->def(
"get_uint",
[](const Packet& packet) {
if (packet.ValidateAsType<uint8>().ok()) {
return static_cast<std::uint64_t>(packet.Get<uint8>());
} else if (packet.ValidateAsType<uint16>().ok()) {
return static_cast<std::uint64_t>(packet.Get<uint16>());
} else if (packet.ValidateAsType<uint32>().ok()) {
return static_cast<std::uint64_t>(packet.Get<uint32>());
} else if (packet.ValidateAsType<uint64>().ok()) {
return static_cast<std::uint64_t>(packet.Get<uint64>());
if (packet.ValidateAsType<uint8_t>().ok()) {
return static_cast<std::uint64_t>(packet.Get<uint8_t>());
} else if (packet.ValidateAsType<uint16_t>().ok()) {
return static_cast<std::uint64_t>(packet.Get<uint16_t>());
} else if (packet.ValidateAsType<uint32_t>().ok()) {
return static_cast<std::uint64_t>(packet.Get<uint32_t>());
} else if (packet.ValidateAsType<uint64_t>().ok()) {
return static_cast<std::uint64_t>(packet.Get<uint64_t>());
}
throw RaisePyError(
PyExc_ValueError,
@ -194,19 +194,19 @@ void PublicPacketGetters(pybind11::module* m) {
[](const Packet& packet) {
if (packet.ValidateAsType<std::vector<int>>().ok()) {
auto int_list = packet.Get<std::vector<int>>();
return std::vector<int64>(int_list.begin(), int_list.end());
} else if (packet.ValidateAsType<std::vector<int8>>().ok()) {
auto int_list = packet.Get<std::vector<int8>>();
return std::vector<int64>(int_list.begin(), int_list.end());
} else if (packet.ValidateAsType<std::vector<int16>>().ok()) {
auto int_list = packet.Get<std::vector<int16>>();
return std::vector<int64>(int_list.begin(), int_list.end());
} else if (packet.ValidateAsType<std::vector<int32>>().ok()) {
auto int_list = packet.Get<std::vector<int32>>();
return std::vector<int64>(int_list.begin(), int_list.end());
} else if (packet.ValidateAsType<std::vector<int64>>().ok()) {
auto int_list = packet.Get<std::vector<int64>>();
return std::vector<int64>(int_list.begin(), int_list.end());
return std::vector<int64_t>(int_list.begin(), int_list.end());
} else if (packet.ValidateAsType<std::vector<int8_t>>().ok()) {
auto int_list = packet.Get<std::vector<int8_t>>();
return std::vector<int64_t>(int_list.begin(), int_list.end());
} else if (packet.ValidateAsType<std::vector<int16_t>>().ok()) {
auto int_list = packet.Get<std::vector<int16_t>>();
return std::vector<int64_t>(int_list.begin(), int_list.end());
} else if (packet.ValidateAsType<std::vector<int32_t>>().ok()) {
auto int_list = packet.Get<std::vector<int32_t>>();
return std::vector<int64_t>(int_list.begin(), int_list.end());
} else if (packet.ValidateAsType<std::vector<int64_t>>().ok()) {
auto int_list = packet.Get<std::vector<int64_t>>();
return std::vector<int64_t>(int_list.begin(), int_list.end());
}
throw RaisePyError(PyExc_ValueError,
"Packet doesn't contain int, int8, int16, int32, or "

View File

@ -56,7 +56,7 @@ void TimestampSubmodule(pybind11::module* module) {
)doc");
timestamp.def(py::init<const Timestamp&>())
.def(py::init<int64>())
.def(py::init<int64_t>())
.def_property_readonly("value", &Timestamp::Value)
.def_property_readonly_static(
"UNSET", [](py::object) { return Timestamp::Unset(); })
@ -137,7 +137,7 @@ void TimestampSubmodule(pybind11::module* module) {
timestamp_now = mp.Timestamp.from_seconds(time.time())
)doc");
py::implicitly_convertible<int64, Timestamp>();
py::implicitly_convertible<int64_t, Timestamp>();
}
} // namespace python