undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
57
test/jdk/sun/java2d/loops/ARGBBgToRGB.java
Normal file
57
test/jdk/sun/java2d/loops/ARGBBgToRGB.java
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4238978
|
||||
* @summary This test verifies that the correct blitting loop is being used.
|
||||
* The correct output should have a yellow border on the top and
|
||||
* left sides of a red box. The incorrect output would have only
|
||||
* a red box -- no yellow border."
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ARGBBgToRGB {
|
||||
|
||||
public static void main(String[] argv) {
|
||||
BufferedImage bi = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D big = bi.createGraphics();
|
||||
big.setColor(Color.red);
|
||||
big.fillRect(30, 30, 150, 150);
|
||||
|
||||
BufferedImage bi2 = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D big2 = bi2.createGraphics();
|
||||
big2.drawImage(bi, 0, 0, Color.yellow, null);
|
||||
|
||||
int expectYellowPix = bi2.getRGB(0, 0);
|
||||
int expectRedPix = bi2.getRGB(50, 50);
|
||||
if ((expectYellowPix != Color.yellow.getRGB()) ||
|
||||
(expectRedPix != Color.red.getRGB()))
|
||||
{
|
||||
throw new RuntimeException("Unexpected colors " + expectYellowPix + " " + expectRedPix);
|
||||
}
|
||||
}
|
||||
}
|
||||
77
test/jdk/sun/java2d/loops/Bug7049339.java
Normal file
77
test/jdk/sun/java2d/loops/Bug7049339.java
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright 2011 Red Hat, Inc. All Rights Reserved.
|
||||
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@bug 7049339
|
||||
@summary Copying images with a non-rectangular clip and a custom composite
|
||||
fails
|
||||
@author Denis Lila <dlila@redhat.com>
|
||||
@run main Bug7049339
|
||||
*/
|
||||
|
||||
import java.awt.Composite;
|
||||
import java.awt.CompositeContext;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
|
||||
public class Bug7049339 {
|
||||
public static void main(String[] argv) {
|
||||
int x = 100, y = 100;
|
||||
BufferedImage src = new BufferedImage(x, y, BufferedImage.TYPE_INT_ARGB);
|
||||
BufferedImage dst = new BufferedImage(x, y, BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
Graphics2D dstg2d = dst.createGraphics();
|
||||
dstg2d.setComposite(new Composite() {
|
||||
@Override
|
||||
public CompositeContext createContext(
|
||||
ColorModel srcColorModel,
|
||||
ColorModel dstColorModel,
|
||||
RenderingHints hints)
|
||||
{
|
||||
return new CompositeContext() {
|
||||
@Override
|
||||
public void compose(Raster src, Raster dstIn,
|
||||
WritableRaster dstOut)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
Shape clip = new Ellipse2D.Double(x/4, y/4, x/2, y/2);
|
||||
dstg2d.setClip(clip);
|
||||
// This will throw a RasterFormatException if the bug is present.
|
||||
dstg2d.drawImage(src, 0, 0, null);
|
||||
}
|
||||
}
|
||||
122
test/jdk/sun/java2d/loops/ConvertToByteIndexedTest.java
Normal file
122
test/jdk/sun/java2d/loops/ConvertToByteIndexedTest.java
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7116979
|
||||
* @summary Test verifies whether BufferedImage with primary colors are
|
||||
* stored properly when we draw into ByteIndexed BufferedImage.
|
||||
* @run main ConvertToByteIndexedTest
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConvertToByteIndexedTest {
|
||||
static final int[] SRC_TYPES = new int[] {
|
||||
BufferedImage.TYPE_INT_RGB,
|
||||
BufferedImage.TYPE_INT_ARGB,
|
||||
BufferedImage.TYPE_INT_ARGB_PRE,
|
||||
BufferedImage.TYPE_INT_BGR,
|
||||
BufferedImage.TYPE_3BYTE_BGR,
|
||||
BufferedImage.TYPE_4BYTE_ABGR,
|
||||
BufferedImage.TYPE_4BYTE_ABGR_PRE,
|
||||
BufferedImage.TYPE_USHORT_565_RGB,
|
||||
BufferedImage.TYPE_USHORT_555_RGB,
|
||||
BufferedImage.TYPE_BYTE_INDEXED};
|
||||
|
||||
static final String[] TYPE_NAME = new String[] {
|
||||
"INT_RGB",
|
||||
"INT_ARGB",
|
||||
"INT_ARGB_PRE",
|
||||
"INT_BGR",
|
||||
"3BYTE_BGR",
|
||||
"4BYTE_ABGR",
|
||||
"4BYTE_ABGR_PRE",
|
||||
"USHORT_565_RGB",
|
||||
"USHORT_555_RGB",
|
||||
"BYTE_INDEXED"};
|
||||
|
||||
static final Color[] COLORS = new Color[] {
|
||||
//Color.WHITE,
|
||||
Color.BLACK,
|
||||
Color.RED,
|
||||
Color.YELLOW,
|
||||
Color.GREEN,
|
||||
Color.MAGENTA,
|
||||
Color.CYAN,
|
||||
Color.BLUE};
|
||||
|
||||
static final HashMap<Integer,String> TYPE_TABLE =
|
||||
new HashMap<Integer,String>();
|
||||
|
||||
static {
|
||||
for (int i = 0; i < SRC_TYPES.length; i++) {
|
||||
TYPE_TABLE.put(new Integer(SRC_TYPES[i]), TYPE_NAME[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static int width = 50;
|
||||
static int height = 50;
|
||||
|
||||
public static void ConvertToByteIndexed(Color color, int srcType) {
|
||||
// setup source image and graphics for conversion.
|
||||
BufferedImage srcImage = new BufferedImage(width, height, srcType);
|
||||
Graphics2D srcG2D = srcImage.createGraphics();
|
||||
srcG2D.setColor(color);
|
||||
srcG2D.fillRect(0, 0, width, height);
|
||||
|
||||
// setup destination image and graphics for conversion.
|
||||
int dstType = BufferedImage.TYPE_BYTE_INDEXED;
|
||||
BufferedImage dstImage = new BufferedImage(width, height, dstType);
|
||||
Graphics2D dstG2D = (Graphics2D)dstImage.getGraphics();
|
||||
// draw source image into Byte Indexed destination
|
||||
dstG2D.drawImage(srcImage, 0, 0, null);
|
||||
|
||||
// draw into ARGB image to verify individual pixel value.
|
||||
BufferedImage argbImage = new BufferedImage(width, height,
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D argbG2D = (Graphics2D)argbImage.getGraphics();
|
||||
argbG2D.drawImage(dstImage, 0, 0, null);
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
if (color.getRGB() != argbImage.getRGB(i, j)) {
|
||||
throw new RuntimeException("Conversion from " +
|
||||
TYPE_TABLE.get(srcType) + " to BYTE_INDEXED is not"
|
||||
+ " done properly for " + color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
for (int srcType : SRC_TYPES) {
|
||||
for (Color color : COLORS) {
|
||||
ConvertToByteIndexed(color, srcType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
143
test/jdk/sun/java2d/loops/CopyAreaSpeed.java
Normal file
143
test/jdk/sun/java2d/loops/CopyAreaSpeed.java
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4189070
|
||||
* @summary This test prints out the time it takes for a certain amount of
|
||||
* copyArea calls to be completed. Because the performance measurement is
|
||||
* relative, this code only provides a benchmark to run with different releases
|
||||
* to compare the outcomes.
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual CopyAreaSpeed
|
||||
*/
|
||||
|
||||
public class CopyAreaSpeed {
|
||||
public static void main(String args[]) throws Exception {
|
||||
String instructions = """
|
||||
This test prints out the time it takes for a certain amount
|
||||
of copyArea calls to be completed. Because the performance
|
||||
measurement is relative, this code only provides a benchmark
|
||||
to run with different releases to compare the outcomes.
|
||||
""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(instructions)
|
||||
.rows(5)
|
||||
.columns(35)
|
||||
.testUI(CopyAreaSpeed::initialize)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static JFrame initialize() {
|
||||
JFrame frame = new JFrame("Copy Area Test");
|
||||
frame.add(new CopyAreaSpeedTest());
|
||||
frame.setSize(300, 320);
|
||||
frame.setVisible(true);
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
|
||||
class CopyAreaSpeedTest extends Container implements Runnable {
|
||||
int top = 0;
|
||||
public static String result;
|
||||
|
||||
public CopyAreaSpeedTest() {
|
||||
super();
|
||||
(new Thread(this)).start();
|
||||
}
|
||||
|
||||
public void update(Graphics g) {
|
||||
paint(g);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
synchronized (this) {
|
||||
Rectangle rct = g.getClipBounds();
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(rct.x, rct.y, rct.width, rct.height);
|
||||
g.setFont(getFont());
|
||||
g.setColor(Color.black);
|
||||
|
||||
Dimension dm = getSize();
|
||||
for (int y = 0; y <= (dm.height + 10); y += 20) {
|
||||
if (y > rct.y) {
|
||||
int z = y / 20 + top;
|
||||
g.drawString("" + z, 10, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static long millsec(Date s, Date e) {
|
||||
long ts = s.getTime();
|
||||
long te = e.getTime();
|
||||
return te - ts;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
int count = 1000;
|
||||
int loops = count;
|
||||
Date start;
|
||||
Date end;
|
||||
|
||||
start = new Date();
|
||||
while (count-- > 0) {
|
||||
Dimension dm = getSize();
|
||||
if (dm != null && dm.width != 0 && dm.height != 0) {
|
||||
synchronized (this) {
|
||||
top++;
|
||||
Graphics g = getGraphics();
|
||||
g.copyArea(0, 20, dm.width, dm.height - 20, 0, -20);
|
||||
g.setClip(0, dm.height - 20, dm.width, 20);
|
||||
paint(g);
|
||||
g.dispose();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
end = new Date();
|
||||
Graphics g = getGraphics();
|
||||
g.setFont(getFont());
|
||||
g.setColor(Color.black);
|
||||
result = "copyArea X " + loops + " = " + millsec(start, end) + " msec";
|
||||
JOptionPane.showMessageDialog(null, result);
|
||||
}
|
||||
}
|
||||
103
test/jdk/sun/java2d/loops/CopyNegative.java
Normal file
103
test/jdk/sun/java2d/loops/CopyNegative.java
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4188744
|
||||
* @summary This test verifies that copyArea performs correctly for negative offset values.
|
||||
* The correct output shows that the text area is moved to the left and down,
|
||||
* leaving some garbage on the right and the top.
|
||||
* The incorrect copy would show the text area garbled and no text is legible.
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual CopyNegative
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.Panel;
|
||||
|
||||
public class CopyNegative extends Panel {
|
||||
|
||||
private static final String INSTRUCTIONS = """
|
||||
This test verifies that copyArea performs correctly for negative offset values.
|
||||
The test draws text in an image, then copies the contents repeatedly.
|
||||
The correct output shows that the text is moved to the left and down,
|
||||
leaving some garbage on the top / right and some legible text at the bottom left.
|
||||
The incorrect copy would show the whole text area garbled and no text is legible.
|
||||
""";
|
||||
|
||||
public static void main(String[] argv) throws Exception {
|
||||
PassFailJFrame.builder()
|
||||
.title("CopyNegativeTest")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.testUI(CopyNegative::createUI)
|
||||
.testTimeOut(5)
|
||||
.rows(10)
|
||||
.columns(50)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
Image img;
|
||||
|
||||
static final int W = 200, H = 200;
|
||||
|
||||
static Frame createUI() {
|
||||
Frame f = new Frame("CopyNegative");
|
||||
f.add(new CopyNegative());
|
||||
f.pack();
|
||||
return f;
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(W, H);
|
||||
}
|
||||
|
||||
private void doCopy() {
|
||||
Graphics g = img.getGraphics();
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0, 0, W, H);
|
||||
g.setColor(Color.black);
|
||||
String text = "Some Text To Display, it is long enough to fill the entire display line.";
|
||||
StringBuffer sb = new StringBuffer(text);
|
||||
|
||||
for (int i = 1; i < 50; i++) {
|
||||
g.drawString(sb.toString(), 5,20 * i - 10);
|
||||
sb.insert(0, Integer.toString(i));
|
||||
}
|
||||
for (int i = 0 ; i < 20 ; i++ ) {
|
||||
g.copyArea(0, 0, W, H, -3, 3);
|
||||
}
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
img = createImage(W, H);
|
||||
doCopy();
|
||||
g.drawImage(img, 0, 0, this);
|
||||
}
|
||||
|
||||
}
|
||||
73
test/jdk/sun/java2d/loops/DitheredSolidFill.java
Normal file
73
test/jdk/sun/java2d/loops/DitheredSolidFill.java
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4181172
|
||||
* @summary Confirm that solid white fill is not dithered on an 8-bit indexed surface.
|
||||
* The test draws two areas filled with white solid color.
|
||||
* The upper left square is filled in aliasing mode and
|
||||
* the lower right square is filled in anti-aliasing mode.
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class DitheredSolidFill {
|
||||
|
||||
public static void main(String args[]) {
|
||||
BufferedImage bi = new BufferedImage(120, 120, BufferedImage.TYPE_BYTE_INDEXED);
|
||||
Graphics2D g2D = bi.createGraphics();
|
||||
|
||||
g2D.setColor(Color.black);
|
||||
g2D.fillRect(0, 0, 100, 100);
|
||||
|
||||
g2D.setColor(Color.white);
|
||||
g2D.fillRect(5, 5, 40, 40);
|
||||
checkPixels(bi, 5, 5, 40, 40);
|
||||
|
||||
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2D.fillRect(55, 55, 40, 40);
|
||||
checkPixels(bi, 55, 55, 40, 40);
|
||||
}
|
||||
|
||||
static void checkPixels(BufferedImage bi, int x, int y, int w, int h) {
|
||||
// pixel can be off white, but must be the same in all cases.
|
||||
int expectedPix = bi.getRGB(x, y);
|
||||
for (int x0 = x; x0 < x + w; x0++) {
|
||||
for (int y0 = y; y0 < y + h; y0++) {
|
||||
if (bi.getRGB(x0, y0) != expectedPix) {
|
||||
try {
|
||||
javax.imageio.ImageIO.write(bi, "png", new java.io.File("failed.png"));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
throw new RuntimeException("Not expected pix : " +
|
||||
Integer.toHexString(bi.getRGB(x0, y0)) +
|
||||
" at " + x0 + "," + y0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
68
test/jdk/sun/java2d/loops/GraphicsPrimitiveMgrTest.java
Normal file
68
test/jdk/sun/java2d/loops/GraphicsPrimitiveMgrTest.java
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Azul Systems, Inc. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 6995195
|
||||
* @summary Verify that concurrent classloading of GraphicsPrimitiveMgr
|
||||
* and Blit doesn't deadlock
|
||||
* @run main/othervm/timeout=20 GraphicsPrimitiveMgrTest
|
||||
*/
|
||||
public class GraphicsPrimitiveMgrTest {
|
||||
|
||||
private static volatile CountDownLatch latch;
|
||||
|
||||
private static final String C1 = "sun.java2d.loops.GraphicsPrimitiveMgr";
|
||||
private static final String C2 = "sun.java2d.loops.Blit";
|
||||
|
||||
public static void main(final String[] args)
|
||||
throws ClassNotFoundException, InterruptedException
|
||||
{
|
||||
// force loading awt library
|
||||
Class.forName("java.awt.Toolkit");
|
||||
|
||||
latch = new CountDownLatch(2);
|
||||
|
||||
Thread t1 = new Thread(() -> loadClass(C1));
|
||||
Thread t2 = new Thread(() -> loadClass(C2));
|
||||
|
||||
t1.start();
|
||||
t2.start();
|
||||
|
||||
t1.join();
|
||||
t2.join();
|
||||
}
|
||||
|
||||
private static void loadClass(String className) {
|
||||
System.out.println(Thread.currentThread().getName() + " loading " + className);
|
||||
try {
|
||||
latch.countDown();
|
||||
latch.await();
|
||||
Class.forName(className);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
68
test/jdk/sun/java2d/loops/OffsetCalculationTest.java
Normal file
68
test/jdk/sun/java2d/loops/OffsetCalculationTest.java
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@bug 4236576
|
||||
@summary tests that a BufferedImage in TYPE_3BYTE_BGR format is correctly
|
||||
drawn when there is an offset between the Graphics clip bounds
|
||||
and the clip box of the underlying device context.
|
||||
@run main OffsetCalculationTest
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBuffer;
|
||||
|
||||
public class OffsetCalculationTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
BufferedImage srcImage = new BufferedImage(500, 500, BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
DataBuffer buffer = srcImage.getRaster().getDataBuffer();
|
||||
for (int i = 2; i < buffer.getSize(); i+=3) {
|
||||
// setting each pixel to blue via the data buffer elements.
|
||||
buffer.setElem(i - 2, 0xff);
|
||||
buffer.setElem(i - 1, 0);
|
||||
buffer.setElem(i, 0);
|
||||
}
|
||||
|
||||
int w = 200, h = 200;
|
||||
BufferedImage destImage = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
|
||||
Graphics2D g = destImage.createGraphics();
|
||||
Rectangle r = new Rectangle(0, 0, w, h);
|
||||
g.setClip(r.x - 1, r.y, r.width + 1, r.height);
|
||||
g.drawImage(srcImage, 0, 0, null);
|
||||
|
||||
int bluepix = Color.blue.getRGB();
|
||||
for (int y = 0; y < w; y++) {
|
||||
for (int x = 0; x < h; x++) {
|
||||
if (destImage.getRGB(x, y) != bluepix) {
|
||||
throw new RuntimeException("Not Blue");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
115
test/jdk/sun/java2d/loops/RenderToCustomBufferTest.java
Normal file
115
test/jdk/sun/java2d/loops/RenderToCustomBufferTest.java
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/**
|
||||
* @test
|
||||
* @bug 8015606 8220150
|
||||
* @summary Test verifies whether a text is rendered correctly to
|
||||
* a custom buffered image.
|
||||
*
|
||||
* @run main RenderToCustomBufferTest
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.ComponentColorModel;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.WritableRaster;
|
||||
|
||||
public class RenderToCustomBufferTest {
|
||||
public static void main(String[] args) {
|
||||
final BufferedImage dst_custom = createCustomBuffer();
|
||||
final BufferedImage dst_dcm = new BufferedImage(width, height,
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
renderTo(dst_custom);
|
||||
renderTo(dst_dcm);
|
||||
|
||||
check(dst_custom, dst_dcm);
|
||||
}
|
||||
|
||||
private static void check(BufferedImage a, BufferedImage b) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int pa = a.getRGB(x, y);
|
||||
int pb = b.getRGB(x, y);
|
||||
|
||||
if (pa != pb) {
|
||||
String msg = String.format(
|
||||
"Point [%d, %d] has different colors: %08X and %08X",
|
||||
x, y, pa, pb);
|
||||
throw new RuntimeException("Test failed: " + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedImage createCustomBuffer() {
|
||||
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||
ColorModel cm = new ComponentColorModel(cs, false, false,
|
||||
Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
|
||||
WritableRaster wr = cm.createCompatibleWritableRaster(width, height);
|
||||
|
||||
return new BufferedImage(cm, wr, false, null);
|
||||
}
|
||||
|
||||
private static void renderTo(BufferedImage dst) {
|
||||
System.out.println("The buffer: " + dst);
|
||||
Graphics2D g = dst.createGraphics();
|
||||
|
||||
final int w = dst.getWidth();
|
||||
final int h = dst.getHeight();
|
||||
|
||||
g.setColor(Color.blue);
|
||||
g.fillRect(0, 0, w, h);
|
||||
|
||||
g.setColor(Color.red);
|
||||
Font f = g.getFont();
|
||||
g.setFont(f.deriveFont(48f));
|
||||
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
|
||||
// NB: this clip ctriggers the problem
|
||||
g.setClip(50, 50, 200, 100);
|
||||
|
||||
g.drawString("AA Text", 52, 90);
|
||||
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
|
||||
// NB: this clip ctriggers the problem
|
||||
g.setClip(50, 100, 100, 100);
|
||||
g.drawString("Text", 52, 148);
|
||||
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
private static final int width = 230;
|
||||
private static final int height = 150;
|
||||
}
|
||||
89
test/jdk/sun/java2d/loops/SkipConversionIfPossible.java
Normal file
89
test/jdk/sun/java2d/loops/SkipConversionIfPossible.java
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static java.awt.image.BufferedImage.TYPE_3BYTE_BGR;
|
||||
import static java.awt.image.BufferedImage.TYPE_4BYTE_ABGR;
|
||||
import static java.awt.image.BufferedImage.TYPE_4BYTE_ABGR_PRE;
|
||||
import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
|
||||
import static java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE;
|
||||
import static java.awt.image.BufferedImage.TYPE_INT_BGR;
|
||||
import static java.awt.image.BufferedImage.TYPE_INT_RGB;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8297681
|
||||
* @summary The blit TYPE_4BYTE_ABGR_PRE to TYPE_INT_ARGB_PRE should be "direct"
|
||||
*/
|
||||
public final class SkipConversionIfPossible {
|
||||
|
||||
private static final int SIZE = 256;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Initial bug was in the TYPE_4BYTE_ABGR_PRE to TYPE_INT_ARGB_PRE blit.
|
||||
// But I checked other blits just in case.
|
||||
test(new int[]{TYPE_INT_ARGB_PRE, TYPE_4BYTE_ABGR_PRE});
|
||||
test(new int[]{TYPE_INT_RGB, TYPE_INT_BGR, TYPE_3BYTE_BGR});
|
||||
test(new int[]{TYPE_INT_ARGB, TYPE_4BYTE_ABGR});
|
||||
}
|
||||
|
||||
private static void test(int[] types) {
|
||||
for (int src : types) {
|
||||
for (int dst : types) {
|
||||
render(src, dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void render(int src, int dst) {
|
||||
BufferedImage from = new BufferedImage(SIZE, SIZE, src);
|
||||
for (int a = 0; a < SIZE; ++a) {
|
||||
for (int c = 0; c < SIZE; ++c) {
|
||||
// The data is intentionally broken for the argb_pre format, but
|
||||
// it should be stored as is in dst if no conversion was done.
|
||||
from.getRaster().setPixel(c, a, new int[]{c, c << 24, -c, a});
|
||||
}
|
||||
}
|
||||
BufferedImage to = new BufferedImage(SIZE, SIZE, dst);
|
||||
Graphics2D g = to.createGraphics();
|
||||
g.setComposite(AlphaComposite.Src);
|
||||
g.drawImage(from, 0, 0, null);
|
||||
g.dispose();
|
||||
|
||||
for (int a = 0; a < SIZE; ++a) {
|
||||
for (int c = 0; c < SIZE; ++c) {
|
||||
int[] pixel1 = from.getRaster().getPixel(c, a, (int[]) null);
|
||||
int[] pixel2 = to.getRaster().getPixel(c, a, (int[]) null);
|
||||
if (!Arrays.equals(pixel1, pixel2)) {
|
||||
System.err.println(Arrays.toString(pixel1));
|
||||
System.err.println(Arrays.toString(pixel2));
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
93
test/jdk/sun/java2d/loops/XORClearRect.java
Normal file
93
test/jdk/sun/java2d/loops/XORClearRect.java
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4088173
|
||||
* @summary This interactive test verifies that the XOR mode is not affecting
|
||||
* the clearRect() call. The correct output looks like:
|
||||
*
|
||||
* \ /
|
||||
* \ /
|
||||
* The backgound is blue.
|
||||
* The lines outside the central rectangle are green.
|
||||
* The central rectangle is also blue (the result of clearRect())
|
||||
* / \
|
||||
* / \
|
||||
*
|
||||
* @key headful
|
||||
* @run main XORClearRect
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Point;
|
||||
import java.awt.Robot;
|
||||
|
||||
public class XORClearRect extends Panel {
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
EventQueue.invokeAndWait(XORClearRect::createUI);
|
||||
try {
|
||||
Robot robot = new Robot();
|
||||
robot.waitForIdle();
|
||||
robot.delay(2000);
|
||||
Point p = frame.getLocationOnScreen();
|
||||
int pix = robot.getPixelColor(p.x + 100, p.y + 100).getRGB();
|
||||
if (pix != Color.blue.getRGB()) {
|
||||
throw new RuntimeException("Not blue");
|
||||
}
|
||||
} finally {
|
||||
if (frame != null) {
|
||||
EventQueue.invokeAndWait(frame::dispose);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static volatile Frame frame;
|
||||
|
||||
static void createUI() {
|
||||
frame = new Frame("XORClearRect");
|
||||
frame.setBackground(Color.blue);
|
||||
XORClearRect xor = new XORClearRect();
|
||||
frame.add(xor);
|
||||
frame.setSize(200,200);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
public XORClearRect() {
|
||||
setBackground(Color.blue);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(Color.green);
|
||||
g.drawLine(0,0,200,200);
|
||||
g.drawLine(0,200,200,0);
|
||||
g.setXORMode(Color.blue);
|
||||
g.clearRect(50,50,100,100); //expecting the rectangle to be filled
|
||||
// with the background color (blue)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue