Program: 38265
Project: 38265
Buggy source:
public void layoutPreview(float ratio){
  FrameLayout.LayoutParams lp;
  float scaledTextureWidth, scaledTextureHeight;
  int rotation=CameraUtil.getDisplayRotation(mActivity);
  if (mScreenRatio == CameraUtil.RATIO_16_9 && CameraUtil.determineRatio(ratio) == CameraUtil.RATIO_4_3) {
    int l=(mTopMargin + mBottomMargin) * 4;
    int s=l * 9 / 16;
switch (rotation) {
case 90:
      lp=new FrameLayout.LayoutParams(l * 3 / 4,s);
    lp.setMargins(mTopMargin,0,mBottomMargin,0);
  scaledTextureWidth=l * 3 / 4;
scaledTextureHeight=s;
break;
case 180:
lp=new FrameLayout.LayoutParams(s,l * 3 / 4);
lp.setMargins(0,mBottomMargin,0,mTopMargin);
scaledTextureWidth=s;
scaledTextureHeight=l * 3 / 4;
break;
case 270:
lp=new FrameLayout.LayoutParams(l * 3 / 4,s);
lp.setMargins(mBottomMargin,0,mTopMargin,0);
scaledTextureWidth=l * 3 / 4;
scaledTextureHeight=s;
break;
default :
lp=new FrameLayout.LayoutParams(s,l * 3 / 4);
lp.setMargins(0,mTopMargin,0,mBottomMargin);
scaledTextureWidth=s;
scaledTextureHeight=l * 3 / 4;
break;
}
}
 else {
float width=mOriginalPreviewWidth, height=mOriginalPreviewHeight;
if (mOrientationResize) {
scaledTextureWidth=height * mAspectRatio;
if (scaledTextureWidth > width) {
scaledTextureWidth=width;
scaledTextureHeight=scaledTextureWidth / mAspectRatio;
}
 else {
scaledTextureHeight=height;
}
}
 else {
if (width > height) {
scaledTextureWidth=Math.max(width,height * mAspectRatio);
scaledTextureHeight=Math.max(height,width / mAspectRatio);
}
 else {
scaledTextureWidth=Math.max(width,height / mAspectRatio);
scaledTextureHeight=Math.max(height,width * mAspectRatio);
}
}
Log.v(TAG,"String_Node_Str" + scaledTextureWidth + "String_Node_Str"+ scaledTextureHeight);
int orientation=mActivity.getResources().getConfiguration().orientation;
if (((rotation == 0 || rotation == 180) && scaledTextureWidth > scaledTextureHeight) || ((rotation == 90 || rotation == 270) && scaledTextureWidth < scaledTextureHeight)) {
lp=new FrameLayout.LayoutParams((int)scaledTextureHeight,(int)scaledTextureWidth,Gravity.CENTER);
}
 else {
lp=new FrameLayout.LayoutParams((int)scaledTextureWidth,(int)scaledTextureHeight,Gravity.CENTER);
}
}
if (mSurfaceTextureUncroppedWidth != scaledTextureWidth || mSurfaceTextureUncroppedHeight != scaledTextureHeight) {
mSurfaceTextureUncroppedWidth=scaledTextureWidth;
mSurfaceTextureUncroppedHeight=scaledTextureHeight;
if (mSurfaceTextureSizeListener != null) {
mSurfaceTextureSizeListener.onSurfaceTextureSizeChanged((int)mSurfaceTextureUncroppedWidth,(int)mSurfaceTextureUncroppedHeight);
Log.d(TAG,"String_Node_Str" + mSurfaceTextureUncroppedWidth + "String_Node_Str"+ mSurfaceTextureUncroppedHeight);
}
}
mSurfaceView.setLayoutParams(lp);
if (mFaceView != null) {
mFaceView.setLayoutParams(lp);
}
}

Fixed version (ground truth):
public void layoutPreview(float ratio){
  FrameLayout.LayoutParams lp;
  float scaledTextureWidth, scaledTextureHeight;
  int rotation=CameraUtil.getDisplayRotation(mActivity);
  if (mScreenRatio == CameraUtil.RATIO_16_9 && CameraUtil.determineRatio(ratio) == CameraUtil.RATIO_4_3) {
    int l=(mTopMargin + mBottomMargin) * 4;
    int s=l * 9 / 16;
switch (rotation) {
case 90:
      lp=new FrameLayout.LayoutParams(l * 3 / 4,s);
    lp.setMargins(mTopMargin,0,mBottomMargin,0);
  scaledTextureWidth=l * 3 / 4;
scaledTextureHeight=s;
break;
case 180:
lp=new FrameLayout.LayoutParams(s,l * 3 / 4);
lp.setMargins(0,mBottomMargin,0,mTopMargin);
scaledTextureWidth=s;
scaledTextureHeight=l * 3 / 4;
break;
case 270:
lp=new FrameLayout.LayoutParams(l * 3 / 4,s);
lp.setMargins(mBottomMargin,0,mTopMargin,0);
scaledTextureWidth=l * 3 / 4;
scaledTextureHeight=s;
break;
default :
lp=new FrameLayout.LayoutParams(s,l * 3 / 4);
lp.setMargins(0,mTopMargin,0,mBottomMargin);
scaledTextureWidth=s;
scaledTextureHeight=l * 3 / 4;
break;
}
}
 else {
float width=mOriginalPreviewWidth, height=mOriginalPreviewHeight;
if (width == 0 || height == 0) return;
if (mOrientationResize) {
scaledTextureWidth=height * mAspectRatio;
if (scaledTextureWidth > width) {
scaledTextureWidth=width;
scaledTextureHeight=scaledTextureWidth / mAspectRatio;
}
 else {
scaledTextureHeight=height;
}
}
 else {
if (width > height) {
scaledTextureWidth=Math.max(width,height * mAspectRatio);
scaledTextureHeight=Math.max(height,width / mAspectRatio);
}
 else {
scaledTextureWidth=Math.max(width,height / mAspectRatio);
scaledTextureHeight=Math.max(height,width * mAspectRatio);
}
}
Log.v(TAG,"String_Node_Str" + scaledTextureWidth + "String_Node_Str"+ scaledTextureHeight);
int orientation=mActivity.getResources().getConfiguration().orientation;
if (((rotation == 0 || rotation == 180) && scaledTextureWidth > scaledTextureHeight) || ((rotation == 90 || rotation == 270) && scaledTextureWidth < scaledTextureHeight)) {
lp=new FrameLayout.LayoutParams((int)scaledTextureHeight,(int)scaledTextureWidth,Gravity.CENTER);
}
 else {
lp=new FrameLayout.LayoutParams((int)scaledTextureWidth,(int)scaledTextureHeight,Gravity.CENTER);
}
}
if (mSurfaceTextureUncroppedWidth != scaledTextureWidth || mSurfaceTextureUncroppedHeight != scaledTextureHeight) {
mSurfaceTextureUncroppedWidth=scaledTextureWidth;
mSurfaceTextureUncroppedHeight=scaledTextureHeight;
if (mSurfaceTextureSizeListener != null) {
mSurfaceTextureSizeListener.onSurfaceTextureSizeChanged((int)mSurfaceTextureUncroppedWidth,(int)mSurfaceTextureUncroppedHeight);
Log.d(TAG,"String_Node_Str" + mSurfaceTextureUncroppedWidth + "String_Node_Str"+ mSurfaceTextureUncroppedHeight);
}
}
mSurfaceView.setLayoutParams(lp);
if (mFaceView != null) {
mFaceView.setLayoutParams(lp);
}
}