show white page when the image files in jar are missing
This commit is contained in:
@@ -144,7 +144,7 @@ public final class Main implements Runnable {
|
|||||||
try {
|
try {
|
||||||
PluginManager.getPlugin(Class.forName(c));
|
PluginManager.getPlugin(Class.forName(c));
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
LOGGER.log(Level.WARNING, "Class: " + c + " not found, please add your plugin jar to class path.", ex);
|
HMCLog.warn("Class: " + c + " not found, please add your plugin jar to class path.", ex);
|
||||||
}
|
}
|
||||||
} else if (s.startsWith("--help")) {
|
} else if (s.startsWith("--help")) {
|
||||||
System.out.println("HMCL command line help");
|
System.out.println("HMCL command line help");
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import java.util.jar.Pack200;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
import org.jackhuang.hmcl.Main;
|
import org.jackhuang.hmcl.Main;
|
||||||
|
import org.jackhuang.hmcl.api.HMCLog;
|
||||||
import org.jackhuang.hmcl.api.event.SimpleEvent;
|
import org.jackhuang.hmcl.api.event.SimpleEvent;
|
||||||
import org.jackhuang.hmcl.util.C;
|
import org.jackhuang.hmcl.util.C;
|
||||||
import org.jackhuang.hmcl.core.MCUtils;
|
import org.jackhuang.hmcl.core.MCUtils;
|
||||||
@@ -98,7 +99,7 @@ public class AppDataUpgrader extends IUpgrader {
|
|||||||
} catch (JsonSyntaxException ex) {
|
} catch (JsonSyntaxException ex) {
|
||||||
f.delete();
|
f.delete();
|
||||||
} catch (IOException | PrivilegedActionException t) {
|
} catch (IOException | PrivilegedActionException t) {
|
||||||
Main.LOGGER.log(Level.SEVERE, "Failed to execute newer version application", t);
|
HMCLog.err("Failed to execute newer version application", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +132,7 @@ public class AppDataUpgrader extends IUpgrader {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Main.LOGGER.log(Level.SEVERE, "Failed to create upgrader", ex);
|
HMCLog.err("Failed to create upgrader", ex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String url = C.URL_PUBLISH;
|
String url = C.URL_PUBLISH;
|
||||||
@@ -145,7 +146,7 @@ public class AppDataUpgrader extends IUpgrader {
|
|||||||
try {
|
try {
|
||||||
java.awt.Desktop.getDesktop().browse(new URI(url));
|
java.awt.Desktop.getDesktop().browse(new URI(url));
|
||||||
} catch (URISyntaxException | IOException e) {
|
} catch (URISyntaxException | IOException e) {
|
||||||
Main.LOGGER.log(Level.WARNING, "Failed to browse uri: " + url, e);
|
HMCLog.err("Failed to browse uri: " + url, e);
|
||||||
Utils.setClipborad(url);
|
Utils.setClipborad(url);
|
||||||
MessageBox.show(C.i18n("update.no_browser"));
|
MessageBox.show(C.i18n("update.no_browser"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.laf.utils;
|
package org.jackhuang.hmcl.laf.utils;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import org.jb2011.ninepatch4j.NinePatch;
|
import org.jb2011.ninepatch4j.NinePatch;
|
||||||
|
|
||||||
@@ -13,6 +14,8 @@ import org.jb2011.ninepatch4j.NinePatch;
|
|||||||
* @author huang
|
* @author huang
|
||||||
*/
|
*/
|
||||||
public class Icon9Factory extends RawCache<NinePatch> {
|
public class Icon9Factory extends RawCache<NinePatch> {
|
||||||
|
|
||||||
|
private static final NinePatch EMPTY = NinePatch.load(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB), false, true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 相对路径根(默认是相对于本类的相对物理路径).
|
* 相对路径根(默认是相对于本类的相对物理路径).
|
||||||
@@ -50,7 +53,13 @@ public class Icon9Factory extends RawCache<NinePatch> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public NinePatch get(String key) {
|
public NinePatch get(String key) {
|
||||||
return icons.get(ns + ":" + key);
|
NinePatch p = icons.get(ns + ":" + key);
|
||||||
|
if (p == null) {
|
||||||
|
System.err.println("Could not find 9patch: " + key);
|
||||||
|
icons.put(ns + ":" + key, EMPTY);
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NinePatch get(String key, String state) {
|
public NinePatch get(String key, String state) {
|
||||||
|
|||||||
@@ -5,12 +5,8 @@ package org.jb2011.ninepatch4j;
|
|||||||
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.GraphicsConfiguration;
|
import java.awt.GraphicsConfiguration;
|
||||||
import java.awt.GraphicsDevice;
|
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
import java.awt.Image;
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.ColorModel;
|
|
||||||
import java.awt.image.ImageObserver;
|
|
||||||
import java.awt.image.WritableRaster;
|
import java.awt.image.WritableRaster;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -18,14 +14,13 @@ import java.net.URL;
|
|||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
public class GraphicsUtilities {
|
public class GraphicsUtilities {
|
||||||
|
|
||||||
public static BufferedImage loadCompatibleImage(URL resource) throws IOException {
|
public static BufferedImage loadCompatibleImage(URL resource) throws IOException {
|
||||||
BufferedImage image = ImageIO.read(resource);
|
return GraphicsUtilities.toCompatibleImage(ImageIO.read(resource));
|
||||||
return GraphicsUtilities.toCompatibleImage(image);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BufferedImage loadCompatibleImage(InputStream stream) throws IOException {
|
public static BufferedImage loadCompatibleImage(InputStream stream) throws IOException {
|
||||||
BufferedImage image = ImageIO.read(stream);
|
return GraphicsUtilities.toCompatibleImage(ImageIO.read(stream));
|
||||||
return GraphicsUtilities.toCompatibleImage(image);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BufferedImage createCompatibleImage(int width, int height) {
|
public static BufferedImage createCompatibleImage(int width, int height) {
|
||||||
@@ -33,12 +28,10 @@ public class GraphicsUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static BufferedImage toCompatibleImage(BufferedImage image) {
|
public static BufferedImage toCompatibleImage(BufferedImage image) {
|
||||||
if (GraphicsUtilities.isHeadless()) {
|
if (GraphicsUtilities.isHeadless())
|
||||||
return image;
|
return image;
|
||||||
}
|
if (image.getColorModel().equals(GraphicsUtilities.getGraphicsConfiguration().getColorModel()))
|
||||||
if (image.getColorModel().equals(GraphicsUtilities.getGraphicsConfiguration().getColorModel())) {
|
|
||||||
return image;
|
return image;
|
||||||
}
|
|
||||||
BufferedImage compatibleImage = GraphicsUtilities.getGraphicsConfiguration().createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
|
BufferedImage compatibleImage = GraphicsUtilities.getGraphicsConfiguration().createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
|
||||||
Graphics g = compatibleImage.getGraphics();
|
Graphics g = compatibleImage.getGraphics();
|
||||||
g.drawImage(image, 0, 0, null);
|
g.drawImage(image, 0, 0, null);
|
||||||
@@ -64,20 +57,17 @@ public class GraphicsUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int[] getPixels(BufferedImage img, int x, int y, int w, int h, int[] pixels) {
|
public static int[] getPixels(BufferedImage img, int x, int y, int w, int h, int[] pixels) {
|
||||||
if (w == 0 || h == 0) {
|
if (w == 0 || h == 0)
|
||||||
return new int[0];
|
return new int[0];
|
||||||
}
|
if (pixels == null)
|
||||||
if (pixels == null) {
|
|
||||||
pixels = new int[w * h];
|
pixels = new int[w * h];
|
||||||
} else if (pixels.length < w * h) {
|
else if (pixels.length < w * h)
|
||||||
throw new IllegalArgumentException("Pixels array must have a length >= w * h");
|
throw new IllegalArgumentException("Pixels array must have a length >= w * h");
|
||||||
}
|
|
||||||
int imageType = img.getType();
|
int imageType = img.getType();
|
||||||
if (imageType == 2 || imageType == 1) {
|
if (imageType == 2 || imageType == 1) {
|
||||||
WritableRaster raster = img.getRaster();
|
WritableRaster raster = img.getRaster();
|
||||||
return (int[])raster.getDataElements(x, y, w, h, pixels);
|
return (int[]) raster.getDataElements(x, y, w, h, pixels);
|
||||||
}
|
}
|
||||||
return img.getRGB(x, y, w, h, pixels, 0, w);
|
return img.getRGB(x, y, w, h, pixels, 0, w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,21 +3,19 @@
|
|||||||
*/
|
*/
|
||||||
package org.jb2011.ninepatch4j;
|
package org.jb2011.ninepatch4j;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Image;
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.ImageObserver;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import org.jb2011.ninepatch4j.GraphicsUtilities;
|
|
||||||
import org.jb2011.ninepatch4j.NinePatchChunk;
|
|
||||||
|
|
||||||
public class NinePatch {
|
public class NinePatch {
|
||||||
|
|
||||||
public static final String EXTENSION_9PATCH = ".9.png";
|
public static final String EXTENSION_9PATCH = ".9.png";
|
||||||
private BufferedImage mImage;
|
private final BufferedImage mImage;
|
||||||
private NinePatchChunk mChunk;
|
private final NinePatchChunk mChunk;
|
||||||
|
|
||||||
public BufferedImage getImage() {
|
public BufferedImage getImage() {
|
||||||
return this.mImage;
|
return this.mImage;
|
||||||
@@ -28,26 +26,20 @@ public class NinePatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static NinePatch load(URL fileUrl, boolean convert) throws IOException {
|
public static NinePatch load(URL fileUrl, boolean convert) throws IOException {
|
||||||
BufferedImage image = null;
|
|
||||||
try {
|
try {
|
||||||
image = GraphicsUtilities.loadCompatibleImage(fileUrl);
|
boolean is9Patch = fileUrl.getPath().toLowerCase().endsWith(".9.png");
|
||||||
}
|
return NinePatch.load(GraphicsUtilities.loadCompatibleImage(fileUrl), is9Patch, convert);
|
||||||
catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
boolean is9Patch = fileUrl.getPath().toLowerCase().endsWith(".9.png");
|
|
||||||
return NinePatch.load(image, is9Patch, convert);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NinePatch load(InputStream stream, boolean is9Patch, boolean convert) throws IOException {
|
public static NinePatch load(InputStream stream, boolean is9Patch, boolean convert) throws IOException {
|
||||||
BufferedImage image = null;
|
|
||||||
try {
|
try {
|
||||||
image = GraphicsUtilities.loadCompatibleImage(stream);
|
return NinePatch.load(GraphicsUtilities.loadCompatibleImage(stream), is9Patch, convert);
|
||||||
}
|
} catch (MalformedURLException e) {
|
||||||
catch (MalformedURLException e) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return NinePatch.load(image, is9Patch, convert);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -56,12 +48,12 @@ public class NinePatch {
|
|||||||
*/
|
*/
|
||||||
public static NinePatch load(BufferedImage image, boolean is9Patch, boolean convert) {
|
public static NinePatch load(BufferedImage image, boolean is9Patch, boolean convert) {
|
||||||
if (!is9Patch) {
|
if (!is9Patch) {
|
||||||
if (!convert) return null;
|
if (!convert)
|
||||||
|
return null;
|
||||||
image = NinePatch.convertTo9Patch(image);
|
image = NinePatch.convertTo9Patch(image);
|
||||||
return new NinePatch(image);
|
return new NinePatch(image);
|
||||||
} else {
|
} else
|
||||||
NinePatch.ensure9Patch(image);
|
NinePatch.ensure9Patch(image);
|
||||||
}
|
|
||||||
return new NinePatch(image);
|
return new NinePatch(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,23 +86,19 @@ public class NinePatch {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < width) {
|
while (i < width) {
|
||||||
pixel = image.getRGB(i, 0);
|
pixel = image.getRGB(i, 0);
|
||||||
if (pixel != 0 && pixel != -16777216) {
|
if (pixel != 0 && pixel != -16777216)
|
||||||
image.setRGB(i, 0, 0);
|
image.setRGB(i, 0, 0);
|
||||||
}
|
if ((pixel = image.getRGB(i, height - 1)) != 0 && pixel != -16777216)
|
||||||
if ((pixel = image.getRGB(i, height - 1)) != 0 && pixel != -16777216) {
|
|
||||||
image.setRGB(i, height - 1, 0);
|
image.setRGB(i, height - 1, 0);
|
||||||
}
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < height) {
|
while (i < height) {
|
||||||
pixel = image.getRGB(0, i);
|
pixel = image.getRGB(0, i);
|
||||||
if (pixel != 0 && pixel != -16777216) {
|
if (pixel != 0 && pixel != -16777216)
|
||||||
image.setRGB(0, i, 0);
|
image.setRGB(0, i, 0);
|
||||||
}
|
if ((pixel = image.getRGB(width - 1, i)) != 0 && pixel != -16777216)
|
||||||
if ((pixel = image.getRGB(width - 1, i)) != 0 && pixel != -16777216) {
|
|
||||||
image.setRGB(width - 1, i, 0);
|
image.setRGB(width - 1, i, 0);
|
||||||
}
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,6 +107,11 @@ public class NinePatch {
|
|||||||
BufferedImage buffer = GraphicsUtilities.createTranslucentCompatibleImage(image.getWidth() + 2, image.getHeight() + 2);
|
BufferedImage buffer = GraphicsUtilities.createTranslucentCompatibleImage(image.getWidth() + 2, image.getHeight() + 2);
|
||||||
Graphics2D g2 = buffer.createGraphics();
|
Graphics2D g2 = buffer.createGraphics();
|
||||||
g2.drawImage(image, 1, 1, null);
|
g2.drawImage(image, 1, 1, null);
|
||||||
|
g2.setColor(Color.black);
|
||||||
|
g2.fillRect(0, 1, 1, 1);
|
||||||
|
g2.fillRect(1, 0, 1, 1);
|
||||||
|
g2.fillRect(1, image.getHeight() + 1, 1, 1);
|
||||||
|
g2.fillRect(image.getWidth() + 1, 1, 1, 1);
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
@@ -127,4 +120,3 @@ public class NinePatch {
|
|||||||
return image.getSubimage(1, 1, image.getWidth() - 2, image.getHeight() - 2);
|
return image.getSubimage(1, 1, image.getWidth() - 2, image.getHeight() - 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import java.util.List;
|
|||||||
/*
|
/*
|
||||||
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
|
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
|
||||||
*/
|
*/
|
||||||
public class NinePatchChunk
|
public class NinePatchChunk implements Serializable {
|
||||||
implements Serializable {
|
|
||||||
private static final long serialVersionUID = -7353439224505296217L;
|
private static final long serialVersionUID = -7353439224505296217L;
|
||||||
private static final int[] sPaddingRect = new int[4];
|
private static final int[] sPaddingRect = new int[4];
|
||||||
private boolean mVerticalStartWithPatch;
|
private boolean mVerticalStartWithPatch;
|
||||||
@@ -36,31 +36,28 @@ implements Serializable {
|
|||||||
public void draw(BufferedImage image, Graphics2D graphics2D, int x, int y, int scaledWidth, int scaledHeight, int destDensity, int srcDensity) {
|
public void draw(BufferedImage image, Graphics2D graphics2D, int x, int y, int scaledWidth, int scaledHeight, int destDensity, int srcDensity) {
|
||||||
boolean scaling;
|
boolean scaling;
|
||||||
boolean bl = scaling = destDensity != srcDensity && destDensity != 0 && srcDensity != 0;
|
boolean bl = scaling = destDensity != srcDensity && destDensity != 0 && srcDensity != 0;
|
||||||
if (scaling) {
|
if (scaling)
|
||||||
try {
|
try {
|
||||||
graphics2D = (Graphics2D)graphics2D.create();
|
graphics2D = (Graphics2D) graphics2D.create();
|
||||||
float densityScale = (float)destDensity / (float)srcDensity;
|
float densityScale = (float) destDensity / (float) srcDensity;
|
||||||
graphics2D.translate(x, y);
|
graphics2D.translate(x, y);
|
||||||
graphics2D.scale(densityScale, densityScale);
|
graphics2D.scale(densityScale, densityScale);
|
||||||
scaledWidth = (int)((float)scaledWidth / densityScale);
|
scaledWidth = (int) ((float) scaledWidth / densityScale);
|
||||||
scaledHeight = (int)((float)scaledHeight / densityScale);
|
scaledHeight = (int) ((float) scaledHeight / densityScale);
|
||||||
y = 0;
|
y = 0;
|
||||||
x = 0;
|
x = 0;
|
||||||
this.draw(image, graphics2D, x, y, scaledWidth, scaledHeight);
|
this.draw(image, graphics2D, x, y, scaledWidth, scaledHeight);
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
graphics2D.dispose();
|
graphics2D.dispose();
|
||||||
}
|
}
|
||||||
} else {
|
else
|
||||||
this.draw(image, graphics2D, x, y, scaledWidth, scaledHeight);
|
this.draw(image, graphics2D, x, y, scaledWidth, scaledHeight);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void draw(BufferedImage image, Graphics2D graphics2D, int x, int y, int scaledWidth, int scaledHeight) {
|
private void draw(BufferedImage image, Graphics2D graphics2D, int x, int y, int scaledWidth, int scaledHeight) {
|
||||||
if (scaledWidth <= 1 || scaledHeight <= 1) {
|
if (scaledWidth <= 1 || scaledHeight <= 1)
|
||||||
return;
|
return;
|
||||||
}
|
Graphics2D g = (Graphics2D) graphics2D.create();
|
||||||
Graphics2D g = (Graphics2D)graphics2D.create();
|
|
||||||
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||||
try {
|
try {
|
||||||
if (this.mPatches.isEmpty()) {
|
if (this.mPatches.isEmpty()) {
|
||||||
@@ -91,10 +88,10 @@ implements Serializable {
|
|||||||
if (!vStretch) {
|
if (!vStretch) {
|
||||||
if (hStretch) {
|
if (hStretch) {
|
||||||
r = this.mHorizontalPatches.get(horizontalIndex++);
|
r = this.mHorizontalPatches.get(horizontalIndex++);
|
||||||
extra = (float)r.width / data.mHorizontalPatchesSum;
|
extra = (float) r.width / data.mHorizontalPatchesSum;
|
||||||
width = (int)(extra * hRemainder / hWeightSum);
|
width = (int) (extra * hRemainder / hWeightSum);
|
||||||
hWeightSum -= extra;
|
hWeightSum -= extra;
|
||||||
hRemainder -= (float)width;
|
hRemainder -= (float) width;
|
||||||
g.drawImage(image, x, y, x + width, y + r.height, r.x, r.y, r.x + r.width, r.y + r.height, null);
|
g.drawImage(image, x, y, x + width, y + r.height, r.x, r.y, r.x + r.width, r.y + r.height, null);
|
||||||
x += width;
|
x += width;
|
||||||
} else {
|
} else {
|
||||||
@@ -105,18 +102,18 @@ implements Serializable {
|
|||||||
height = r.height;
|
height = r.height;
|
||||||
} else if (hStretch) {
|
} else if (hStretch) {
|
||||||
r = this.mPatches.get(patchIndex++);
|
r = this.mPatches.get(patchIndex++);
|
||||||
vExtra = (float)r.height / data.mVerticalPatchesSum;
|
vExtra = (float) r.height / data.mVerticalPatchesSum;
|
||||||
height = (int)(vExtra * vRemainder / vWeightSum);
|
height = (int) (vExtra * vRemainder / vWeightSum);
|
||||||
extra = (float)r.width / data.mHorizontalPatchesSum;
|
extra = (float) r.width / data.mHorizontalPatchesSum;
|
||||||
width = (int)(extra * hRemainder / hWeightSum);
|
width = (int) (extra * hRemainder / hWeightSum);
|
||||||
hWeightSum -= extra;
|
hWeightSum -= extra;
|
||||||
hRemainder -= (float)width;
|
hRemainder -= (float) width;
|
||||||
g.drawImage(image, x, y, x + width, y + height, r.x, r.y, r.x + r.width, r.y + r.height, null);
|
g.drawImage(image, x, y, x + width, y + height, r.x, r.y, r.x + r.width, r.y + r.height, null);
|
||||||
x += width;
|
x += width;
|
||||||
} else {
|
} else {
|
||||||
r = this.mVerticalPatches.get(verticalIndex++);
|
r = this.mVerticalPatches.get(verticalIndex++);
|
||||||
vExtra = (float)r.height / data.mVerticalPatchesSum;
|
vExtra = (float) r.height / data.mVerticalPatchesSum;
|
||||||
height = (int)(vExtra * vRemainder / vWeightSum);
|
height = (int) (vExtra * vRemainder / vWeightSum);
|
||||||
g.drawImage(image, x, y, x + r.width, y + height, r.x, r.y, r.x + r.width, r.y + r.height, null);
|
g.drawImage(image, x, y, x + r.width, y + height, r.x, r.y, r.x + r.width, r.y + r.height, null);
|
||||||
x += r.width;
|
x += r.width;
|
||||||
}
|
}
|
||||||
@@ -126,12 +123,11 @@ implements Serializable {
|
|||||||
y += height;
|
y += height;
|
||||||
if (vStretch) {
|
if (vStretch) {
|
||||||
vWeightSum -= vExtra;
|
vWeightSum -= vExtra;
|
||||||
vRemainder -= (float)height;
|
vRemainder -= (float) height;
|
||||||
}
|
}
|
||||||
boolean bl = vStretch = !vStretch;
|
boolean bl = vStretch = !vStretch;
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
g.dispose();
|
g.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,56 +152,60 @@ implements Serializable {
|
|||||||
int remainderHorizontal = 0;
|
int remainderHorizontal = 0;
|
||||||
int remainderVertical = 0;
|
int remainderVertical = 0;
|
||||||
if (this.mFixed.size() > 0) {
|
if (this.mFixed.size() > 0) {
|
||||||
start = this.mFixed.get((int)0).y;
|
start = this.mFixed.get((int) 0).y;
|
||||||
for (Rectangle rect : this.mFixed) {
|
for (Rectangle rect : this.mFixed) {
|
||||||
if (rect.y > start) {
|
if (rect.y > start) {
|
||||||
endRow = true;
|
endRow = true;
|
||||||
measuredWidth = true;
|
measuredWidth = true;
|
||||||
}
|
}
|
||||||
if (!measuredWidth) {
|
if (!measuredWidth)
|
||||||
remainderHorizontal += rect.width;
|
remainderHorizontal += rect.width;
|
||||||
}
|
if (!endRow)
|
||||||
if (!endRow) continue;
|
continue;
|
||||||
remainderVertical += rect.height;
|
remainderVertical += rect.height;
|
||||||
endRow = false;
|
endRow = false;
|
||||||
start = rect.y;
|
start = rect.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DrawingData.access$4(data, scaledWidth - remainderHorizontal);
|
data.mRemainderHorizontal = scaledWidth - remainderHorizontal;
|
||||||
DrawingData.access$5(data, scaledHeight - remainderVertical);
|
data.mRemainderVertical = scaledHeight - remainderVertical;
|
||||||
DrawingData.access$6(data, 0.0f);
|
data.mHorizontalPatchesSum = 0.0f;
|
||||||
if (this.mHorizontalPatches.size() > 0) {
|
if (this.mHorizontalPatches.size() > 0) {
|
||||||
start = -1;
|
start = -1;
|
||||||
for (Rectangle rect : this.mHorizontalPatches) {
|
for (Rectangle rect : this.mHorizontalPatches) {
|
||||||
if (rect.x <= start) continue;
|
if (rect.x <= start)
|
||||||
|
continue;
|
||||||
DrawingData drawingData = data;
|
DrawingData drawingData = data;
|
||||||
DrawingData.access$6(drawingData, drawingData.mHorizontalPatchesSum + (float)rect.width);
|
drawingData.mHorizontalPatchesSum = drawingData.mHorizontalPatchesSum + (float) rect.width;
|
||||||
start = rect.x;
|
start = rect.x;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
start = -1;
|
start = -1;
|
||||||
for (Rectangle rect : this.mPatches) {
|
for (Rectangle rect : this.mPatches) {
|
||||||
if (rect.x <= start) continue;
|
if (rect.x <= start)
|
||||||
|
continue;
|
||||||
DrawingData drawingData = data;
|
DrawingData drawingData = data;
|
||||||
DrawingData.access$6(drawingData, drawingData.mHorizontalPatchesSum + (float)rect.width);
|
drawingData.mHorizontalPatchesSum = drawingData.mHorizontalPatchesSum + (float) rect.width;
|
||||||
start = rect.x;
|
start = rect.x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DrawingData.access$7(data, 0.0f);
|
data.mVerticalPatchesSum = 0.0f;
|
||||||
if (this.mVerticalPatches.size() > 0) {
|
if (this.mVerticalPatches.size() > 0) {
|
||||||
start = -1;
|
start = -1;
|
||||||
for (Rectangle rect : this.mVerticalPatches) {
|
for (Rectangle rect : this.mVerticalPatches) {
|
||||||
if (rect.y <= start) continue;
|
if (rect.y <= start)
|
||||||
|
continue;
|
||||||
DrawingData drawingData = data;
|
DrawingData drawingData = data;
|
||||||
DrawingData.access$7(drawingData, drawingData.mVerticalPatchesSum + (float)rect.height);
|
drawingData.mVerticalPatchesSum = drawingData.mVerticalPatchesSum + (float) rect.height;
|
||||||
start = rect.y;
|
start = rect.y;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
start = -1;
|
start = -1;
|
||||||
for (Rectangle rect : this.mPatches) {
|
for (Rectangle rect : this.mPatches) {
|
||||||
if (rect.y <= start) continue;
|
if (rect.y <= start)
|
||||||
|
continue;
|
||||||
DrawingData drawingData = data;
|
DrawingData drawingData = data;
|
||||||
DrawingData.access$7(drawingData, drawingData.mVerticalPatchesSum + (float)rect.height);
|
drawingData.mVerticalPatchesSum = drawingData.mVerticalPatchesSum + (float) rect.height;
|
||||||
start = rect.y;
|
start = rect.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,16 +225,16 @@ implements Serializable {
|
|||||||
result = new boolean[1];
|
result = new boolean[1];
|
||||||
Pair<List<Pair<Integer>>> top = this.getPatches(row, result);
|
Pair<List<Pair<Integer>>> top = this.getPatches(row, result);
|
||||||
this.mHorizontalStartWithPatch = result[0];
|
this.mHorizontalStartWithPatch = result[0];
|
||||||
this.mFixed = this.getRectangles((List)left.mFirst, (List)top.mFirst);
|
this.mFixed = this.getRectangles((List) left.mFirst, (List) top.mFirst);
|
||||||
this.mPatches = this.getRectangles((List)left.mSecond, (List)top.mSecond);
|
this.mPatches = this.getRectangles((List) left.mSecond, (List) top.mSecond);
|
||||||
if (this.mFixed.size() > 0) {
|
if (this.mFixed.size() > 0) {
|
||||||
this.mHorizontalPatches = this.getRectangles((List)left.mFirst, (List)top.mSecond);
|
this.mHorizontalPatches = this.getRectangles((List) left.mFirst, (List) top.mSecond);
|
||||||
this.mVerticalPatches = this.getRectangles((List)left.mSecond, (List)top.mFirst);
|
this.mVerticalPatches = this.getRectangles((List) left.mSecond, (List) top.mFirst);
|
||||||
} else if (((List)top.mFirst).size() > 0) {
|
} else if (((List) top.mFirst).size() > 0) {
|
||||||
this.mHorizontalPatches = new ArrayList<>(0);
|
this.mHorizontalPatches = new ArrayList<>(0);
|
||||||
this.mVerticalPatches = this.getVerticalRectangles(height, (List)top.mFirst);
|
this.mVerticalPatches = this.getVerticalRectangles(height, (List) top.mFirst);
|
||||||
} else if (((List)left.mFirst).size() > 0) {
|
} else if (((List) left.mFirst).size() > 0) {
|
||||||
this.mHorizontalPatches = this.getHorizontalRectangles(width, (List)left.mFirst);
|
this.mHorizontalPatches = this.getHorizontalRectangles(width, (List) left.mFirst);
|
||||||
this.mVerticalPatches = new ArrayList<>(0);
|
this.mVerticalPatches = new ArrayList<>(0);
|
||||||
} else {
|
} else {
|
||||||
this.mVerticalPatches = new ArrayList<>(0);
|
this.mVerticalPatches = new ArrayList<>(0);
|
||||||
@@ -243,9 +243,9 @@ implements Serializable {
|
|||||||
row = GraphicsUtilities.getPixels(image, 1, height + 1, width, 1, row);
|
row = GraphicsUtilities.getPixels(image, 1, height + 1, width, 1, row);
|
||||||
column = GraphicsUtilities.getPixels(image, width + 1, 1, 1, height, column);
|
column = GraphicsUtilities.getPixels(image, width + 1, 1, 1, height, column);
|
||||||
top = this.getPatches(row, result);
|
top = this.getPatches(row, result);
|
||||||
this.mHorizontalPadding = this.getPadding((List)top.mFirst);
|
this.mHorizontalPadding = this.getPadding((List) top.mFirst);
|
||||||
left = this.getPatches(column, result);
|
left = this.getPatches(column, result);
|
||||||
this.mVerticalPadding = this.getPadding((List)left.mFirst);
|
this.mVerticalPadding = this.getPadding((List) left.mFirst);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Rectangle> getVerticalRectangles(int imageHeight, List<Pair<Integer>> topPairs) {
|
private List<Rectangle> getVerticalRectangles(int imageHeight, List<Pair<Integer>> topPairs) {
|
||||||
@@ -269,17 +269,15 @@ implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Pair<Integer> getPadding(List<Pair<Integer>> pairs) {
|
private Pair<Integer> getPadding(List<Pair<Integer>> pairs) {
|
||||||
if (pairs.isEmpty()) {
|
if (pairs.isEmpty())
|
||||||
return new Pair<>(0, 0);
|
return new Pair<>(0, 0);
|
||||||
}
|
|
||||||
if (pairs.size() == 1) {
|
if (pairs.size() == 1) {
|
||||||
if (pairs.get((int)0).mFirst == 0) {
|
if (pairs.get((int) 0).mFirst == 0)
|
||||||
return new Pair<>(pairs.get((int)0).mSecond - pairs.get((int)0).mFirst, 0);
|
return new Pair<>(pairs.get((int) 0).mSecond - pairs.get((int) 0).mFirst, 0);
|
||||||
}
|
return new Pair<>(0, pairs.get((int) 0).mSecond - pairs.get((int) 0).mFirst);
|
||||||
return new Pair<>(0, pairs.get((int)0).mSecond - pairs.get((int)0).mFirst);
|
|
||||||
}
|
}
|
||||||
int index = pairs.size() - 1;
|
int index = pairs.size() - 1;
|
||||||
return new Pair<>(pairs.get((int)0).mSecond - pairs.get((int)0).mFirst, pairs.get((int)index).mSecond - pairs.get((int)index).mFirst);
|
return new Pair<>(pairs.get((int) 0).mSecond - pairs.get((int) 0).mFirst, pairs.get((int) index).mSecond - pairs.get((int) index).mFirst);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Rectangle> getRectangles(List<Pair<Integer>> leftPairs, List<Pair<Integer>> topPairs) {
|
private List<Rectangle> getRectangles(List<Pair<Integer>> leftPairs, List<Pair<Integer>> topPairs) {
|
||||||
@@ -307,13 +305,11 @@ implements Serializable {
|
|||||||
int pixel = pixels[i];
|
int pixel = pixels[i];
|
||||||
if (pixel != lastPixel) {
|
if (pixel != lastPixel) {
|
||||||
if (lastPixel == -16777216) {
|
if (lastPixel == -16777216) {
|
||||||
if (first) {
|
if (first)
|
||||||
startWithPatch[0] = true;
|
startWithPatch[0] = true;
|
||||||
}
|
|
||||||
patches.add(new Pair<>(lastIndex, i));
|
patches.add(new Pair<>(lastIndex, i));
|
||||||
} else {
|
} else
|
||||||
fixed.add(new Pair<>(lastIndex, i));
|
fixed.add(new Pair<>(lastIndex, i));
|
||||||
}
|
|
||||||
first = false;
|
first = false;
|
||||||
lastIndex = i;
|
lastIndex = i;
|
||||||
lastPixel = pixel;
|
lastPixel = pixel;
|
||||||
@@ -321,13 +317,11 @@ implements Serializable {
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
if (lastPixel == -16777216) {
|
if (lastPixel == -16777216) {
|
||||||
if (first) {
|
if (first)
|
||||||
startWithPatch[0] = true;
|
startWithPatch[0] = true;
|
||||||
}
|
|
||||||
patches.add(new Pair<>(lastIndex, pixels.length));
|
patches.add(new Pair<>(lastIndex, pixels.length));
|
||||||
} else {
|
} else
|
||||||
fixed.add(new Pair<>(lastIndex, pixels.length));
|
fixed.add(new Pair<>(lastIndex, pixels.length));
|
||||||
}
|
|
||||||
if (patches.isEmpty()) {
|
if (patches.isEmpty()) {
|
||||||
patches.add(new Pair<>(1, pixels.length));
|
patches.add(new Pair<>(1, pixels.length));
|
||||||
startWithPatch[0] = true;
|
startWithPatch[0] = true;
|
||||||
@@ -337,36 +331,15 @@ implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static final class DrawingData {
|
static final class DrawingData {
|
||||||
private int mRemainderHorizontal;
|
|
||||||
private int mRemainderVertical;
|
|
||||||
private float mHorizontalPatchesSum;
|
|
||||||
private float mVerticalPatchesSum;
|
|
||||||
|
|
||||||
DrawingData() {
|
int mRemainderHorizontal;
|
||||||
}
|
int mRemainderVertical;
|
||||||
|
float mHorizontalPatchesSum;
|
||||||
static /* synthetic */ void access$4(DrawingData drawingData, int n) {
|
float mVerticalPatchesSum;
|
||||||
drawingData.mRemainderHorizontal = n;
|
|
||||||
}
|
|
||||||
|
|
||||||
static /* synthetic */ void access$5(DrawingData drawingData, int n) {
|
|
||||||
drawingData.mRemainderVertical = n;
|
|
||||||
}
|
|
||||||
|
|
||||||
static /* synthetic */ void access$6(DrawingData drawingData, float f) {
|
|
||||||
drawingData.mHorizontalPatchesSum = f;
|
|
||||||
}
|
|
||||||
|
|
||||||
static /* synthetic */ void access$7(DrawingData drawingData, float f) {
|
|
||||||
drawingData.mVerticalPatchesSum = f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static class Pair<E> implements Serializable {
|
||||||
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
|
|
||||||
*/
|
|
||||||
static class Pair<E>
|
|
||||||
implements Serializable {
|
|
||||||
private static final long serialVersionUID = -2204108979541762418L;
|
private static final long serialVersionUID = -2204108979541762418L;
|
||||||
E mFirst;
|
E mFirst;
|
||||||
E mSecond;
|
E mSecond;
|
||||||
@@ -383,4 +356,3 @@ implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user