TinyScale.java revision 8729:0242fce0f717
1321936Shselasky/*
2321936Shselasky * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3321936Shselasky * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4321936Shselasky *
5321936Shselasky * This code is free software; you can redistribute it and/or modify it
6321936Shselasky * under the terms of the GNU General Public License version 2 only, as
7321936Shselasky * published by the Free Software Foundation.
8321936Shselasky *
9321936Shselasky * This code is distributed in the hope that it will be useful, but WITHOUT
10321936Shselasky * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11321936Shselasky * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12321936Shselasky * version 2 for more details (a copy is included in the LICENSE file that
13321936Shselasky * accompanied this code).
14321936Shselasky *
15321936Shselasky * You should have received a copy of the GNU General Public License version
16321936Shselasky * 2 along with this work; if not, write to the Free Software Foundation,
17321936Shselasky * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18321936Shselasky *
19321936Shselasky * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20321936Shselasky * or visit www.oracle.com if you need additional information or have any
21321936Shselasky * questions.
22321936Shselasky */
23321936Shselasky
24321936Shselasky/*
25321936Shselasky * @test %W% %E%
26321936Shselasky * @bug 7016495
27321936Shselasky * @summary Test tiny scales of BufferedImage
28321936Shselasky */
29321936Shselasky
30321936Shselaskyimport java.awt.*;
31321936Shselaskyimport java.awt.geom.*;
32321936Shselaskyimport java.awt.image.*;
33321936Shselasky
34321936Shselaskypublic class TinyScale {
35321936Shselasky    static double tinyscales[] = {
36321936Shselasky        1E-0,
37321936Shselasky        1E-1,
38321936Shselasky        1E-2,
39321936Shselasky        1E-3,
40321936Shselasky        1E-4,
41321936Shselasky        1E-5,
42321936Shselasky        1E-6,
43321936Shselasky        1E-7,
44321936Shselasky        1E-8,
45321936Shselasky        1E-9,
46321936Shselasky        1E-10,
47321936Shselasky        1E-11,
48321936Shselasky        1E-12,
49321936Shselasky        1E-13,
50321936Shselasky        1E-14,
51321936Shselasky        1E-15,
52321936Shselasky        1E-16,
53321936Shselasky        1E-17,
54321936Shselasky        1E-18,
55321936Shselasky        1E-19,
56321936Shselasky        1E-20,
57321936Shselasky        1E-21,
58321936Shselasky        1E-22,
59321936Shselasky        1E-23,
60321936Shselasky        1E-24,
61321936Shselasky        1E-25,
62321936Shselasky        1E-26,
63321936Shselasky        1E-27,
64321936Shselasky        1E-28,
65        1E-29,
66    };
67
68    static void test(BufferedImage rendImg, BufferedImage drawImg, double s) {
69        Graphics2D g = drawImg.createGraphics();
70        g.transform(new AffineTransform(s, 0.0, -1.0, 1.0, 0.0, 0.0));
71        g.drawImage(rendImg,
72                    -rendImg.getWidth() / 2,
73                    -rendImg.getHeight() / 2,
74                    null);
75        g.drawImage(rendImg, 0, 0, null);
76        g.dispose();
77    }
78
79    public static void main(String[] args) {
80        BufferedImage rendImg =
81            new BufferedImage(100, 100, BufferedImage.TYPE_3BYTE_BGR);
82        BufferedImage drawImg =
83            new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
84        for (double s: tinyscales) {
85            test(rendImg, drawImg, s);
86            for (int i = 0; args.length > 0 && i < 10; i++) {
87                test(rendImg, drawImg, Math.random()*s);
88            }
89        }
90    }
91}
92