import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import java.util.function.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;
import java.math.*;
// Results for ThinkPad in MPixels/s:
// 852 (alpha 0) / 158 (alpha 0x80) / 401 (alpha 0xFF)
import java.text.NumberFormat;
import static x30_pkg.x30_util.DynamicObject;
import java.awt.geom.*;
class main {
static class BenchDrawingImageOnImageWithAlpha {
int w = 1000, h = w;
long nanos;
final public BenchDrawingImageOnImageWithAlpha setAlphaValue(int alphaValue){ return alphaValue(alphaValue); }
public BenchDrawingImageOnImageWithAlpha alphaValue(int alphaValue) { this.alphaValue = alphaValue; return this; } final public int getAlphaValue(){ return alphaValue(); }
public int alphaValue() { return alphaValue; }
int alphaValue = 0x80; // alpha 0 (draw nothing) and alpha 255 (draw opaque) are faster than other values
public void run() { try {
int[] pixels = repIntAsArray(w*h, -1);
var img = bufferedImageWithoutAlpha(w, h, pixels);
pixels = repIntAsArray(w*h, alphaValue << 24);
var img2 = bufferedImageWithAlpha(w, h, pixels);
var g = graphics(img);
nanos = benchFor5("draw " + nPixels(w*h), () -> drawImage(g, img2));
print("Fastest result for alpha " + alphaValue + ": Can draw " + n2(w*h*1000/nanos) + " MPixels/s");
} catch (Exception __e) { throw rethrow(__e); } }
}
static void benchDrawingImageOnImageWithAlpha() {
new BenchDrawingImageOnImageWithAlpha().alphaValue(0).run();
new BenchDrawingImageOnImageWithAlpha().alphaValue(0x80).run();
new BenchDrawingImageOnImageWithAlpha().alphaValue(0xFF).run();
}
static int[] repIntAsArray(int n, int value) {
int[] a = new int[n];
fillArray(a, value);
return a;
}
// from: https://stackoverflow.com/questions/14416107/int-array-to-bufferedimage
// pixels are RGB pixels
static BufferedImage bufferedImageWithoutAlpha(int[] pixels, int w, int h) {
return intArrayToBufferedImageWithoutAlpha(pixels, w, h);
}
static BufferedImage bufferedImageWithoutAlpha(int w, int h, int[] pixels) {
return intArrayToBufferedImageWithoutAlpha(pixels, w, h);
}
static BufferedImage bufferedImageWithAlpha(int w, int h, int[] pixels) {
return newBufferedImageWithAlpha(w, h, pixels);
}
static BufferedImage bufferedImageWithAlpha(int[] pixels, int w, int h) {
return newBufferedImageWithAlpha(w, h, pixels);
}
static Graphics2D graphics(BufferedImage img) {
return imageGraphics(img);
}
// returns minimal time needed
static long benchFor5(String desc, Runnable r) {
return benchFor5Seconds(desc, r);
}
static long benchFor5(Runnable r) {
return benchFor5Seconds(r);
}
// returns result of function
static A benchFor5(IF0 f) { return benchFor5(str(f), f); }
static A benchFor5(String desc, IF0 f) {
return benchFor5Seconds(desc, f);
}
static String nPixels(long n) { return n2(n, "pixel"); }
static String nPixels(Collection l) { return nPixels(l(l)); }
// changes & returns canvas
static BufferedImage drawImage(BufferedImage canvas, Image img, Pt p) {
return drawImageOnImage(img, canvas, p.x, p.y);
}
static void drawImage(BufferedImage g, Image img) { drawImage(graphics(g), img); }
static void drawImage(Graphics2D g, Image img) {
drawImage(g, img, 0, 0);
}
static void drawImage(Graphics2D g, Image img, Pt p) {
drawImage(g, img, p.x, p.y);
}
static void drawImage(Graphics2D g, Image img, int x, int y) {
{ if (g != null) g.drawImage(img, x, y, null); }
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static boolean printAlsoToSystemOut = true;
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal