1/*
2 * Copyright (c) 2011, 2013, 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/*
25 * @test %W% %E%
26 * @bug 7016495
27 * @summary Test tiny scales of BufferedImage
28 */
29
30import java.awt.*;
31import java.awt.geom.*;
32import java.awt.image.*;
33
34public class TinyScale {
35    static double tinyscales[] = {
36        1E-0,
37        1E-1,
38        1E-2,
39        1E-3,
40        1E-4,
41        1E-5,
42        1E-6,
43        1E-7,
44        1E-8,
45        1E-9,
46        1E-10,
47        1E-11,
48        1E-12,
49        1E-13,
50        1E-14,
51        1E-15,
52        1E-16,
53        1E-17,
54        1E-18,
55        1E-19,
56        1E-20,
57        1E-21,
58        1E-22,
59        1E-23,
60        1E-24,
61        1E-25,
62        1E-26,
63        1E-27,
64        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