Project import generated by Copybara.

GitOrigin-RevId: 4143ead7dd769b489c313bb9e8856002736f5ecd
This commit is contained in:
MediaPipe Team
2020-06-08 10:30:49 -07:00
committed by jqtang
parent cd2b69d58c
commit b09cc090d4
5 changed files with 31 additions and 5 deletions
+16 -2
View File
@@ -83,6 +83,7 @@ class GlScalerCalculator : public CalculatorBase {
GlCalculatorHelper helper_;
int dst_width_ = 0;
int dst_height_ = 0;
float dst_scale_ = -1.f;
FrameRotation rotation_;
std::unique_ptr<QuadRenderer> rgb_renderer_;
std::unique_ptr<QuadRenderer> yuv_renderer_;
@@ -142,6 +143,9 @@ REGISTER_CALCULATOR(GlScalerCalculator);
if (options.has_output_height()) {
dst_height_ = options.output_height();
}
if (options.has_output_scale()) {
dst_scale_ = options.output_scale();
}
if (options.has_rotation()) {
rotation_ccw = options.rotation();
}
@@ -283,8 +287,18 @@ void GlScalerCalculator::GetOutputDimensions(int src_width, int src_height,
if (dst_width_ > 0 && dst_height_ > 0) {
*dst_width = dst_width_;
*dst_height = dst_height_;
} else if (rotation_ == FrameRotation::k90 ||
rotation_ == FrameRotation::k270) {
return;
}
if (dst_scale_ > 0) {
// Scales the destination size, but just uses src size as a temporary for
// calculations.
src_width = static_cast<int>(src_width * dst_scale_);
src_height = static_cast<int>(src_height * dst_scale_);
// Round to nearest multiply of 4 for better memory alignment.
src_width = ((src_width + 2) >> 2) << 2;
src_height = ((src_height + 2) >> 2) << 2;
}
if (rotation_ == FrameRotation::k90 || rotation_ == FrameRotation::k270) {
*dst_width = src_height;
*dst_height = src_width;
} else {
+5
View File
@@ -19,6 +19,7 @@ package mediapipe;
import "mediapipe/framework/calculator.proto";
import "mediapipe/gpu/scale_mode.proto";
// Next id: 8.
message GlScalerCalculatorOptions {
extend CalculatorOptions {
optional GlScalerCalculatorOptions ext = 166373014;
@@ -27,6 +28,10 @@ message GlScalerCalculatorOptions {
// Output dimensions.
optional int32 output_width = 1;
optional int32 output_height = 2;
// A scale factor for output size, while keeping aspect ratio. It has lower
// priority than the above two fields. That is, it is effective only when the
// above two fields are unset.
optional float output_scale = 7 [default = 1.0];
// Counterclockwise rotation in degrees. Must be a multiple of 90.
optional int32 rotation = 3;
// Flip the output texture vertically. This is applied after rotation.