Skip to content

Commit 115e333

Browse files
zaptoopanonononono
andauthored
Fix scaling issue (#177)
Co-authored-by: nonononono <dev@nononono>
1 parent e265c97 commit 115e333

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

mjpeg-view/src/main/java/com/github/niqdev/mjpeg/MjpegViewDefault.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,15 @@ private Rect destRect(int bmw, int bmh) {
385385
return new Rect(tempx, tempy, bmw + tempx, bmh + tempy);
386386
}
387387
if (displayMode == MjpegViewDefault.SIZE_SCALE_FIT) {
388-
float bmasp = ((float) bmw / (float) bmh * dispWidth);
388+
float bmasp = ((float) bmw / (float) bmh);
389389
tempx = 0;
390390
tempy = 0;
391-
if(bmw < dispWidth){
391+
if (bmw < dispWidth) {
392392
bmw = dispWidth;
393-
bmh = (int) bmasp;
393+
// cross-multiplication using aspect ratio
394+
bmh = (int) (dispWidth / bmasp);
394395
// set it to the center height
395-
tempy = ((dispWidth - bmh) / 2);
396+
tempy = (dispHeight - bmh) / 4;
396397
}
397398
return new Rect(tempx, tempy, bmw, bmh + tempy);
398399
}

0 commit comments

Comments
 (0)