Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class ETImage {
private final Uri uri;
private final ContentResolver contentResolver;

ETImage(ContentResolver contentResolver, Uri uri) {
ETImage(ContentResolver contentResolver, Uri uri, int sideSize) {
this.contentResolver = contentResolver;
this.uri = uri;
bytes = getBytesFromImageURI(uri);
bytes = getBytesFromImageURI(uri, sideSize);
}

public int getWidth() {
Expand Down Expand Up @@ -64,10 +64,9 @@ public float[] getFloats() {
return floatArray;
}

private byte[] getBytesFromImageURI(Uri uri) {
private byte[] getBytesFromImageURI(Uri uri, int sideSize) {
try {
int RESIZED_IMAGE_WIDTH = 336;
Bitmap bitmap = resizeImage(uri, RESIZED_IMAGE_WIDTH);
Bitmap bitmap = resizeImage(uri, sideSize);

if (bitmap == null) {
ETLogging.getInstance().log("Unable to get bytes from Image URI. Bitmap is null");
Expand Down Expand Up @@ -102,7 +101,7 @@ private byte[] getBytesFromImageURI(Uri uri) {
}

@Nullable
private Bitmap resizeImage(Uri uri, int maxLength) throws FileNotFoundException {
private Bitmap resizeImage(Uri uri, int sideSize) throws FileNotFoundException {
InputStream inputStream = contentResolver.openInputStream(uri);
if (inputStream == null) {
ETLogging.getInstance().log("Unable to resize image, input streams is null");
Expand All @@ -114,21 +113,6 @@ private Bitmap resizeImage(Uri uri, int maxLength) throws FileNotFoundException
return null;
}

float aspectRatio;
int finalWidth, finalHeight;

if (bitmap.getWidth() > bitmap.getHeight()) {
// width > height --> width = maxLength, height scale with aspect ratio
aspectRatio = bitmap.getWidth() / (float) bitmap.getHeight();
finalWidth = maxLength;
finalHeight = Math.round(maxLength / aspectRatio);
} else {
// height >= width --> height = maxLength, width scale with aspect ratio
aspectRatio = bitmap.getHeight() / (float) bitmap.getWidth();
finalHeight = maxLength;
finalWidth = Math.round(maxLength / aspectRatio);
}

return Bitmap.createScaledBitmap(bitmap, finalWidth, finalHeight, false);
return Bitmap.createScaledBitmap(bitmap, sideSize, sideSize, false);
Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from aspect-ratio-preserving resize to square resizing may distort images. This could negatively impact model performance if the models expect properly proportioned images. Consider whether this change is intentional or if aspect ratio should be preserved.

Copilot uses AI. Check for mistakes.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,23 @@ private void setupGalleryPicker() {
});
}

private int getInputImageSideSize() {
switch (mCurrentSettingsFields.getModelType()) {
case LLAVA_1_5:
return 336;
case GEMMA_3:
return 896;
default:
throw new IllegalArgumentException("Unsupported model type: " + mCurrentSettingsFields.getModelType());
}
}

private List<ETImage> getProcessedImagesForModel(List<Uri> uris) {
List<ETImage> imageList = new ArrayList<>();
if (uris != null) {
uris.forEach(
(uri) -> {
imageList.add(new ETImage(this.getContentResolver(), uri));
imageList.add(new ETImage(this.getContentResolver(), uri, getInputImageSideSize()));
});
}
return imageList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,5 @@ public enum ModelType {
LLAVA_1_5,
LLAMA_GUARD_3,
QWEN_3,
VOXTRAL;

@Override
public String toString() {
// Replace underscores with spaces, capitalize words, and handle special cases
String pretty = name().replace('_', ' ').toLowerCase();
// Capitalize the first letter if needed
if (!pretty.isEmpty()) {
pretty = pretty.substring(0, 1).toUpperCase() + pretty.substring(1);
}
// Optionally, handle special capitalization
pretty = pretty.replace("Llava 1 5", "LLaVA 1.5");
return pretty;
}
VOXTRAL,
}