Skip to content

Commit

Permalink
fix(render): change int to float to avoid precision loss
Browse files Browse the repository at this point in the history
  • Loading branch information
I-m-SuperMan committed Jun 5, 2020
1 parent 0becd1e commit 526f199
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 50 deletions.
32 changes: 16 additions & 16 deletions framework/render/video/glRender/CV420PProgramContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,41 +322,41 @@ void CV420PProgramContext::updateDrawRegion() {
return;
}

int windowWidth = mWindowWidth;
int windowHeight = mWindowHeight;
int off_x = 0;
int off_y = 0;
int w = mWindowWidth;
int h = mWindowHeight;
int realWidth = 0;
int realHeight = 0;
float windowWidth = mWindowWidth;
float windowHeight = mWindowHeight;
float off_x = 0;
float off_y = 0;
float w = mWindowWidth;
float h = mWindowHeight;
float realWidth = 0;
float realHeight = 0;

if (mRotate == IVideoRender::Rotate::Rotate_90 ||
mRotate == IVideoRender::Rotate::Rotate_270) {
realWidth = mFrameHeight;
realHeight = static_cast<int>(mFrameHeight * mDar);
realHeight = static_cast<float>(mFrameHeight * mDar);
} else {
realWidth = static_cast<int>(mFrameHeight * mDar);
realWidth = static_cast<float>(mFrameHeight * mDar);
realHeight = mFrameHeight;
}

float scale_w = windowWidth * 1.0f / realWidth;
float scale_h = windowHeight * 1.0f / realHeight;
float scale_w = windowWidth / realWidth;
float scale_h = windowHeight / realHeight;

if (mScale == IVideoRender::Scale::Scale_AspectFit) {
if (scale_w >= scale_h) {
w = static_cast<int>(scale_h * realWidth);
w = scale_h * realWidth;
off_x = (windowWidth - w) / 2;
} else {
h = static_cast<int>(scale_w * realHeight);
h = scale_w * realHeight;
off_y = (windowHeight - h) / 2;
}
} else if (mScale == IVideoRender::Scale::Scale_AspectFill) {
if (scale_w < scale_h) {
w = static_cast<int>(scale_h * realWidth);
w = scale_h * realWidth;
off_x = (windowWidth - w) / 2;
} else {
h = static_cast<int>(scale_w * realHeight);
h = scale_w * realHeight;
off_y = (windowHeight - h) / 2;
}
}
Expand Down
36 changes: 18 additions & 18 deletions framework/render/video/glRender/OESProgramContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,47 +153,47 @@ void OESProgramContext::updateDrawRegion() {
return;
}

int windowWidth = mWindowWidth;
int windowHeight = mWindowHeight;
int off_x = 0;
int off_y = 0;
int w = mWindowWidth;
int h = mWindowHeight;
int realWidth = 0;
int realHeight = 0;
float windowWidth = mWindowWidth;
float windowHeight = mWindowHeight;
float off_x = 0;
float off_y = 0;
float w = mWindowWidth;
float h = mWindowHeight;
float realWidth = 0;
float realHeight = 0;

if (mRotate == IVideoRender::Rotate::Rotate_90 ||
mRotate == IVideoRender::Rotate::Rotate_270) {
realWidth = mFrameHeight;
realHeight = static_cast<int>(mFrameHeight * mDar);
realHeight = static_cast<float>(mFrameHeight * mDar);
} else {
realWidth = static_cast<int>(mFrameHeight * mDar);
realWidth = static_cast<float>(mFrameHeight * mDar);
realHeight = mFrameHeight;
}

float scale_w = windowWidth * 1.0f / realWidth;
float scale_h = windowHeight * 1.0f / realHeight;
float scale_w = windowWidth / realWidth;
float scale_h = windowHeight / realHeight;

if (mScale == IVideoRender::Scale::Scale_AspectFit) {
if (scale_w >= scale_h) {
w = static_cast<int>(scale_h * realWidth);
w = scale_h * realWidth;
off_x = (windowWidth - w);
} else {
h = static_cast<int>(scale_w * realHeight);
h = scale_w * realHeight;
off_y = (windowHeight - h);
}
} else if (mScale == IVideoRender::Scale::Scale_AspectFill) {
if (scale_w < scale_h) {
w = static_cast<int>(scale_h * realWidth);
w = scale_h * realWidth;
off_x = (windowWidth - w);
} else {
h = static_cast<int>(scale_w * realHeight);
h = scale_w * realHeight;
off_y = (windowHeight - h);
}
}

float offX = off_x * 1.0f / windowWidth;
float offY = off_y * 1.0f / windowHeight;
float offX = off_x / windowWidth;
float offY = off_y / windowHeight;

if (mRotate == IVideoRender::Rotate::Rotate_None) {
mDrawRegion[0] = (GLfloat) 1.0f - offX;
Expand Down
32 changes: 16 additions & 16 deletions framework/render/video/glRender/YUVProgramContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,41 +268,41 @@ void YUVProgramContext::updateDrawRegion() {
return;
}

int windowWidth = mWindowWidth;
int windowHeight = mWindowHeight;
int off_x = 0;
int off_y = 0;
int w = mWindowWidth;
int h = mWindowHeight;
int realWidth = 0;
int realHeight = 0;
float windowWidth = mWindowWidth;
float windowHeight = mWindowHeight;
float off_x = 0;
float off_y = 0;
float w = mWindowWidth;
float h = mWindowHeight;
float realWidth = 0;
float realHeight = 0;

if (mRotate == IVideoRender::Rotate::Rotate_90 ||
mRotate == IVideoRender::Rotate::Rotate_270) {
realWidth = mFrameHeight;
realHeight = static_cast<int>(mFrameHeight * mDar);
realHeight = static_cast<float>(mFrameHeight * mDar);
} else {
realWidth = static_cast<int>(mFrameHeight * mDar);
realWidth = static_cast<float>(mFrameHeight * mDar);
realHeight = mFrameHeight;
}

float scale_w = windowWidth * 1.0f / realWidth;
float scale_h = windowHeight * 1.0f / realHeight;
float scale_w = windowWidth / realWidth;
float scale_h = windowHeight / realHeight;

if (mScale == IVideoRender::Scale::Scale_AspectFit) {
if (scale_w >= scale_h) {
w = static_cast<int>(scale_h * realWidth);
w = scale_h * realWidth;
off_x = (windowWidth - w) / 2;
} else {
h = static_cast<int>(scale_w * realHeight);
h = scale_w * realHeight;
off_y = (windowHeight - h) / 2;
}
} else if (mScale == IVideoRender::Scale::Scale_AspectFill) {
if (scale_w < scale_h) {
w = static_cast<int>(scale_h * realWidth);
w = scale_h * realWidth;
off_x = (windowWidth - w) / 2;
} else {
h = static_cast<int>(scale_w * realHeight);
h = scale_w * realHeight;
off_y = (windowHeight - h) / 2;
}
}
Expand Down

0 comments on commit 526f199

Please sign in to comment.