1 /*
   2  * Copyright (c) 2014, 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  * @bug 8162591
  31  * @summary tests gradients with start/endpoints exceeding Short.MAX coordinates
  32  * @author ceisserer
  33  */
  34 public class HugeGradientTest extends Frame {
  35         public static volatile boolean success = false;
  36 
  37         public HugeGradientTest() {
  38                 Image dstImg = getGraphicsConfiguration()
  39                         .createCompatibleVolatileImage(30, 30);
  40                 Graphics2D g = (Graphics2D) dstImg.getGraphics();
  41 
  42                 g.setPaint(new LinearGradientPaint(0f, Short.MAX_VALUE, 0f, Short.MAX_VALUE +31,
  43                         new float[]{0f, 1f}, new Color[]{Color.BLACK, Color.RED}));
  44                 g.translate(0, -Short.MAX_VALUE);
  45                 g.fillRect (0, 0, Short.MAX_VALUE*2 , Short.MAX_VALUE*2);
  46 
  47                 BufferedImage readBackImg = new BufferedImage(dstImg.getWidth(null),
  48                 dstImg.getHeight(null), BufferedImage.TYPE_INT_RGB);
  49                 readBackImg.getGraphics().drawImage(dstImg, 0, 0, null);
  50 
  51                 for (int x = 0; x < readBackImg.getWidth(); x++) {
  52                         for (int y = 0; y < readBackImg.getHeight(); y++) {
  53                                 int redVal = (readBackImg.getRGB(x, y) & 0x00FF0000) >> 16;
  54 
  55                                 if (redVal > 127) {
  56                                         return;
  57                                 }
  58                         }
  59                 }
  60 
  61                 throw new RuntimeException("Test Failed");
  62         }
  63 
  64         public static void main(String[] args) throws Exception {
  65                 SwingUtilities.invokeLater(new Runnable() {
  66                         public void run() {
  67                                 new HugeGradientTest();
  68                         }
  69                 });
  70         }
  71 }