Skip to content

Commit

Permalink
try to improve ux
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Apr 23, 2024
1 parent b5e6dab commit 39205b2
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/main/java/ai/nets/samj/models/AbstractSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,10 @@ public Rectangle getCurrentlyEncodedArea() {
* TODO Explain reencoding logic
* TODO Explain reencoding logic
* TODO Explain reencoding logic
* TODO Threshold for scale (0.7)
* TODO Threshold for scale (0.7)
* TODO Threshold for scale (0.7)
* TODO Threshold for scale (0.7)
* @param pointsList
* @param pointsNegList
* @param rect
Expand All @@ -680,27 +684,33 @@ private void evaluateReencodingNeeded(List<int[]> pointsList, List<int[]> points
if (alreadyEncoded.x <= rect.x && alreadyEncoded.y <= rect.y
&& alreadyEncoded.width + alreadyEncoded.x >= rect.width + rect.x
&& alreadyEncoded.height + alreadyEncoded.y >= rect.height + rect.y
&& alreadyEncoded.width * 0.9 < rect.width && alreadyEncoded.height * 0.9 < rect.height
&& alreadyEncoded.width * 0.7 < rect.width && alreadyEncoded.height * 0.7 < rect.height
&& notInRect.size() == 0 && alreadyEncoded.contains(neededArea)) {
return;
} else if (notInRect.size() != 0) {
this.encodeCoords = new long[] {rect.x, rect.y};
this.reencodeCrop(new long[] {rect.width, rect.height});
this.encodeCoords = new long[] {(long) Math.max(0, rect.x - rect.width * 0.1),
(long) Math.max(0, rect.y - rect.height * 0.1)};
this.reencodeCrop(new long[] {(long) Math.min(rect.width * 0.2, img.dimensionsAsLongArray()[0] - encodeCoords[0]),
(long) Math.min(rect.height * 0.2, img.dimensionsAsLongArray()[1] - encodeCoords[1])});
} else if (alreadyEncoded.x <= rect.x && alreadyEncoded.y <= rect.y
&& alreadyEncoded.width + alreadyEncoded.x >= rect.width + rect.x
&& alreadyEncoded.height + alreadyEncoded.y >= rect.height + rect.y
&& (alreadyEncoded.width * 0.9 > rect.width || alreadyEncoded.height * 0.9 > rect.height)) {
this.encodeCoords = new long[] {rect.x, rect.y};
this.reencodeCrop(new long[] {rect.width, rect.height});
&& (alreadyEncoded.width * 0.7 > rect.width || alreadyEncoded.height * 0.7 > rect.height)
&& rect.contains(neededArea)) {
this.encodeCoords = new long[] {(long) Math.max(0, rect.x - rect.width * 0.1),
(long) Math.max(0, rect.y - rect.height * 0.1)};
this.reencodeCrop(new long[] {(long) Math.min(rect.width * 0.2, img.dimensionsAsLongArray()[0] - encodeCoords[0]),
(long) Math.min(rect.height * 0.2, img.dimensionsAsLongArray()[1] - encodeCoords[1])});
} else if (alreadyEncoded.x <= neededArea.x && alreadyEncoded.y <= neededArea.y
&& alreadyEncoded.width + alreadyEncoded.x >= neededArea.width + neededArea.x
&& alreadyEncoded.height + alreadyEncoded.y >= neededArea.height + neededArea.y
&& alreadyEncoded.width * 0.9 < neededArea.width && alreadyEncoded.height * 0.9 < neededArea.height
&& notInRect.size() == 0) {
return;
} else {
this.encodeCoords = new long[] {rect.x, rect.y};
this.reencodeCrop(new long[] {rect.width, rect.height});
this.encodeCoords = new long[] {Math.min(rect.x, neededArea.x), Math.min(rect.y, neededArea.y)};
this.reencodeCrop(new long[] {Math.max(rect.x + rect.width, neededArea.x + neededArea.width) - encodeCoords[0],
Math.max(rect.y + rect.height, neededArea.y + neededArea.height) - encodeCoords[1]});
}
}

Expand Down

0 comments on commit 39205b2

Please sign in to comment.