1 /*
   2  * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.awt.*;
  25 import java.awt.image.*;
  26 import javax.swing.*;
  27 
  28 /**
  29  * @test
  30  * @key headful
  31  * @bug 8162591
  32  * @summary tests gradients with start/endpoints exceeding Short.MAX coordinates
  33  * @author ceisserer
  34  */
  35 
  36 public class HugeGradientTest extends Frame {
  37         public static volatile boolean success = false;
  38 
  39         public HugeGradientTest() {
  40                 Image dstImg = getGraphicsConfiguration()
  41                         .createCompatibleVolatileImage(30, 30);
  42                 Graphics2D g = (Graphics2D) dstImg.getGraphics();
  43 
  44                 g.setPaint(new LinearGradientPaint(0f, Short.MAX_VALUE, 0f, Short.MAX_VALUE +31,
  45                         new float[]{0f, 1f}, new Color[]{Color.BLACK, Color.RED}));
  46                 g.translate(0, -Short.MAX_VALUE);
  47                 g.fillRect (0, 0, Short.MAX_VALUE*2 , Short.MAX_VALUE*2);
  48 
  49                 BufferedImage readBackImg = new BufferedImage(dstImg.getWidth(null),
  50                 dstImg.getHeight(null), BufferedImage.TYPE_INT_RGB);
  51                 readBackImg.getGraphics().drawImage(dstImg, 0, 0, null);
  52 
  53                 for (int x = 0; x < readBackImg.getWidth(); x++) {
  54                         for (int y = 0; y < readBackImg.getHeight(); y++) {
  55                                 int redVal = (readBackImg.getRGB(x, y) & 0x00FF0000) >> 16;
  56 
  57                                 if (redVal > 127) {
  58                                         return;
  59                                 }
  60                         }
  61                 }
  62 
  63                 throw new RuntimeException("Test Failed");
  64         }
  65 
  66         public static void main(String[] args) throws Exception {
  67                 SwingUtilities.invokeLater(new Runnable() {
  68                         public void run() {
  69                                 new HugeGradientTest();
  70                         }
  71                 });
  72         }
  73 }