Commit 818f1951 authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Scale down the launcher images so they fit into the recommended List image size.

parent 104c5e2f
Pipeline #87119 passed with stages
in 7 minutes
......@@ -118,6 +118,8 @@ public class MidletMain
this._refreshLock = true;
}
Display mainDisplay = MidletMain._MAIN_DISPLAY;
// Used to clear the lock when done, always!
try
{
......@@ -138,7 +140,8 @@ public class MidletMain
listedSuites.clear();
// Used to add suites and indicate progress
handler = new __ProgressListener__(programList, listedSuites);
handler = new __ProgressListener__(programList, listedSuites,
mainDisplay);
}
// Scan all of the available suites for launching
......@@ -173,9 +176,9 @@ public class MidletMain
}
// Make sure the program list is showing
Displayable current = MidletMain._MAIN_DISPLAY.getCurrent();
Displayable current = mainDisplay.getCurrent();
if (current == null || (current instanceof SplashScreen))
MidletMain._MAIN_DISPLAY.setCurrent(this.programList);
mainDisplay.setCurrent(this.programList);
// Automatically launch a program?
String autoLaunch = this._autoLaunch;
......
......@@ -16,6 +16,7 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
......@@ -27,12 +28,23 @@ import javax.microedition.lcdui.List;
final class __ProgressListener__
implements SuiteScanListener
{
/** The scale shift. */
private static final short _SCALE_SHIFT =
8;
/** The scale mask. */
private static final short _SCALE_MASK =
0xFF;
/** The suites that have been listed. */
protected final ArrayList<Application> listedSuites;
/** The program list. */
protected final List programList;
/** The main display. */
protected final Display mainDisplay;
/** Comparator for sorting applications. */
private final Comparator<Application> _comparator =
new __ApplicationComparator__();
......@@ -42,11 +54,12 @@ final class __ProgressListener__
*
* @param __programList The program list used.
* @param __listedSuites The suites that are available.
* @param __mainDisplay The main display.
* @throws NullPointerException On null arguments.
* @since 2020/12/29
*/
public __ProgressListener__(List __programList,
ArrayList<Application> __listedSuites)
ArrayList<Application> __listedSuites, Display __mainDisplay)
throws NullPointerException
{
if (__programList == null || __listedSuites == null)
......@@ -54,6 +67,7 @@ final class __ProgressListener__
this.programList = __programList;
this.listedSuites = __listedSuites;
this.mainDisplay = __mainDisplay;
}
/**
......@@ -93,7 +107,74 @@ final class __ProgressListener__
e.printStackTrace();
}
// Make the icon fit nicely?
if (icon != null)
{
// Get the preferred icon size
Display mainDisplay = this.mainDisplay;
int prefW = mainDisplay.getBestImageWidth(Display.LIST_ELEMENT);
int prefH = mainDisplay.getBestImageHeight(Display.LIST_ELEMENT);
// Scale the icon
if (icon.getWidth() > prefW ||
icon.getHeight() > prefH)
try
{
icon = __ProgressListener__.__scaleIcon(
icon, prefW, prefH);
}
catch (IndexOutOfBoundsException e)
{
e.printStackTrace();
}
}
// Add entry to the list
programList.insert(at, __app.displayName(), icon);
}
/**
* Scales the given icon to the given size.
*
* @param __icon The icon to scale.
* @param __prefW The target width.
* @param __prefH The target height.
* @return The new resultant icon.
* @throws NullPointerException On null arguments.
* @since 2022/02/14
*/
private static Image __scaleIcon(Image __icon, int __prefW, int __prefH)
throws NullPointerException
{
if (__icon == null)
throw new NullPointerException("NARG");
// Get original image size
int srcW = __icon.getWidth();
int srcH = __icon.getHeight();
// Determine the pixels to scale
int scaleX = (srcW << __ProgressListener__._SCALE_SHIFT) / __prefW;
int scaleY = (srcH << __ProgressListener__._SCALE_SHIFT) / __prefH;
// Read original image
int[] src = new int[srcW * srcH];
__icon.getRGB(src, 0, srcW, 0, 0, srcW, srcH);
// Setup new target image
int[] dest = new int[__prefW * __prefH];
// Perform the scaling operation
for (int destY = 0, baseSrcY = 0; destY < __prefH;
destY++, baseSrcY += scaleY)
{
int srcI = srcW * (baseSrcY & (~__ProgressListener__._SCALE_MASK));
for (int destI = __prefW * destY, endDestI = destI + __prefW;
destI < endDestI; destI++, srcI += scaleX)
dest[destI] = src[srcI >>> __ProgressListener__._SCALE_SHIFT];
}
// Return the resultant scaled image now
return Image.createRGBImage(dest, __prefW, __prefH, __icon.hasAlpha());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment