mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
IDEA-230367 OOM when trying to view very large image
GitOrigin-RevId: 488baa6f511b057afd78363df8306d1b77a12567
This commit is contained in:
committed by
intellij-monorepo-bot
parent
45e4de875b
commit
fee7d3a3e0
@@ -8,13 +8,13 @@ import com.intellij.debugger.engine.evaluation.EvaluateException;
|
||||
import com.intellij.debugger.engine.evaluation.EvaluationContext;
|
||||
import com.intellij.debugger.engine.evaluation.EvaluationContextImpl;
|
||||
import com.intellij.debugger.impl.ClassLoadingUtils;
|
||||
import com.intellij.debugger.impl.DebuggerUtilsImpl;
|
||||
import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.rt.debugger.ImageSerializer;
|
||||
import com.intellij.xdebugger.frame.XFullValueEvaluator;
|
||||
import com.sun.jdi.ClassType;
|
||||
import com.sun.jdi.Method;
|
||||
import com.sun.jdi.StringReference;
|
||||
import com.sun.jdi.Value;
|
||||
import org.intellij.images.editor.impl.ImageEditorManagerImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -62,8 +63,7 @@ class ImageObjectRenderer extends CompoundReferenceRenderer implements FullValue
|
||||
@Nullable
|
||||
static ImageIcon getIcon(EvaluationContext evaluationContext, Value obj, String methodName) {
|
||||
try {
|
||||
Value bytes = getImageBytes(evaluationContext, obj, methodName);
|
||||
byte[] data = DebuggerUtilsImpl.readBytesArray(bytes);
|
||||
byte[] data = getImageBytes(evaluationContext, obj, methodName);
|
||||
if (data != null) {
|
||||
return new ImageIcon(data);
|
||||
}
|
||||
@@ -74,7 +74,8 @@ class ImageObjectRenderer extends CompoundReferenceRenderer implements FullValue
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Value getImageBytes(EvaluationContext evaluationContext, Value obj, String methodName)
|
||||
@Nullable
|
||||
private static byte[] getImageBytes(EvaluationContext evaluationContext, Value obj, String methodName)
|
||||
throws EvaluateException {
|
||||
DebugProcess process = evaluationContext.getDebugProcess();
|
||||
EvaluationContext copyContext = evaluationContext.createEvaluationContext(obj);
|
||||
@@ -83,7 +84,11 @@ class ImageObjectRenderer extends CompoundReferenceRenderer implements FullValue
|
||||
if (helperClass != null) {
|
||||
List<Method> methods = helperClass.methodsByName(methodName);
|
||||
if (!methods.isEmpty()) {
|
||||
return process.invokeMethod(copyContext, helperClass, methods.get(0), Collections.singletonList(obj));
|
||||
StringReference bytes =
|
||||
(StringReference)process.invokeMethod(copyContext, helperClass, methods.get(0), Collections.singletonList(obj));
|
||||
if (bytes != null) {
|
||||
return bytes.value().getBytes(StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.io.IOException;
|
||||
* @author egor
|
||||
*/
|
||||
public class ImageSerializer {
|
||||
public static byte[] imageToBytes(Image image) throws IOException {
|
||||
public static String imageToBytes(Image image) throws IOException {
|
||||
//noinspection UndesirableClassUsage
|
||||
BufferedImage bi = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = bi.createGraphics();
|
||||
@@ -34,10 +34,10 @@ public class ImageSerializer {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(bi, "png", baos);
|
||||
g.dispose();
|
||||
return baos.toByteArray();
|
||||
return new String(baos.toByteArray(), "ISO-8859-1");
|
||||
}
|
||||
|
||||
public static byte[] iconToBytesPreview(Icon icon, int maxSize) throws IOException {
|
||||
public static String iconToBytesPreview(Icon icon, int maxSize) throws IOException {
|
||||
if (icon.getIconHeight() <= maxSize && icon.getIconWidth() <= maxSize) {
|
||||
return imageToBytes(toImage(icon));
|
||||
}
|
||||
@@ -45,17 +45,17 @@ public class ImageSerializer {
|
||||
}
|
||||
|
||||
/** @noinspection unused*/
|
||||
public static byte[] iconToBytesPreviewNormal(Icon icon) throws IOException {
|
||||
public static String iconToBytesPreviewNormal(Icon icon) throws IOException {
|
||||
return iconToBytesPreview(icon, 16);
|
||||
}
|
||||
|
||||
/** @noinspection unused*/
|
||||
public static byte[] iconToBytesPreviewRetina(Icon icon) throws IOException {
|
||||
public static String iconToBytesPreviewRetina(Icon icon) throws IOException {
|
||||
return iconToBytesPreview(icon, 32);
|
||||
}
|
||||
|
||||
/** @noinspection unused*/
|
||||
public static byte[] iconToBytes(Icon icon) throws IOException {
|
||||
public static String iconToBytes(Icon icon) throws IOException {
|
||||
return imageToBytes(toImage(icon));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user