test/jdk/java/awt/image/OpaquePNGToGIFTest.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42217
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
     1
/*
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
     4
 *
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
     7
 * published by the Free Software Foundation.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
     8
 *
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    13
 * accompanied this code).
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    14
 *
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    18
 *
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    21
 * questions.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    22
 */
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    23
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    24
 /*
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    25
 * @test
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    26
 * @bug     6334602
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    27
 * @summary Test verifies that when we create GIF image from Opaque PNG images
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    28
 *          it should not be transparent.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    29
 * @modules java.desktop/com.sun.imageio.plugins.gif
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    30
 * @run     main/manual OpaquePNGToGIFTest
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    31
 */
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    32
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    33
import java.awt.image.BufferedImage;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    34
import com.sun.imageio.plugins.gif.GIFImageMetadata;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    35
import java.awt.Canvas;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    36
import java.awt.Color;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    37
import java.awt.Dimension;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    38
import java.awt.Frame;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    39
import java.awt.Graphics;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    40
import java.awt.Graphics2D;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    41
import java.awt.GridBagConstraints;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    42
import java.awt.GridBagLayout;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    43
import java.awt.Image;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    44
import java.awt.Toolkit;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    45
import java.awt.event.ActionEvent;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    46
import java.awt.event.ActionListener;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    47
import java.awt.event.WindowAdapter;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    48
import java.awt.event.WindowEvent;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    49
import java.io.File;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    50
import java.io.FileOutputStream;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    51
import java.io.IOException;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    52
import java.nio.file.Files;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    53
import java.util.ArrayList;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    54
import java.util.Iterator;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    55
import java.util.logging.Level;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    56
import java.util.logging.Logger;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    57
import javax.imageio.IIOImage;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    58
import javax.imageio.ImageIO;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    59
import javax.imageio.ImageReader;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    60
import javax.imageio.ImageTypeSpecifier;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    61
import javax.imageio.ImageWriteParam;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    62
import javax.imageio.ImageWriter;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    63
import javax.imageio.metadata.IIOMetadata;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    64
import javax.imageio.stream.ImageInputStream;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    65
import javax.imageio.stream.ImageOutputStream;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    66
import javax.swing.JButton;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    67
import javax.swing.JDialog;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    68
import javax.swing.JLabel;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    69
import javax.swing.JPanel;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    70
import javax.swing.SwingUtilities;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    71
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    72
public final class OpaquePNGToGIFTest extends Frame {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    73
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    74
    Image img = null;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    75
    private Dimension prefImgSize = new Dimension(100, 100);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    76
    private Color canvasColor = new Color(0, 255, 0);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    77
    File outputFile = null;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    78
    ImageCanvas imageCanvas = new ImageCanvas();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    79
    FileOutputStream fos;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    80
    private static GridBagLayout layout;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    81
    private static JPanel mainControlPanel;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    82
    private static JPanel resultButtonPanel;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    83
    private static JPanel canvasPanel;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    84
    private static JLabel instructionText;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    85
    private static JButton startTestButton;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    86
    private static JButton passButton;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    87
    private static JButton failButton;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    88
    private static JDialog dialog;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    89
    private static Frame instructionFrame;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    90
    private static Frame imageFrame;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    91
    Toolkit tk;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    92
    ImageWriter writer = null;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    93
    boolean testPassed, testGeneratedInterrupt, startButtonClicked;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    94
    private static Thread mainThread;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    95
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    96
    public OpaquePNGToGIFTest() throws Exception {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    97
        SwingUtilities.invokeAndWait(() -> {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    98
            try {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
    99
                startTest();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   100
            } catch (Exception ex) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   101
                Logger.getLogger(OpaquePNGToGIFTest.class.getName()).
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   102
                        log(Level.SEVERE, null, ex);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   103
            }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   104
        });
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   105
        mainThread = Thread.currentThread();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   106
        try {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   107
            Thread.sleep(60000);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   108
        } catch (InterruptedException e) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   109
            if (!testPassed && testGeneratedInterrupt) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   110
                throw new RuntimeException("Test failed or didnt run"
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   111
                        + " properly");
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   112
            }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   113
        }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   114
        if (!testGeneratedInterrupt) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   115
            if (img != null) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   116
                img.flush();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   117
            }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   118
            instructionFrame.dispose();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   119
            if (startButtonClicked) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   120
                imageFrame.dispose();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   121
            }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   122
            fos.close();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   123
            Files.delete(outputFile.toPath());
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   124
            throw new RuntimeException("user has not executed the test");
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   125
        }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   126
    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   127
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   128
    public void startTest() throws Exception {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   129
        instructionFrame = new Frame();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   130
        dialog = new JDialog(instructionFrame);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   131
        dialog.setTitle("Instruction Dialog");
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   132
        layout = new GridBagLayout();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   133
        mainControlPanel = new JPanel(layout);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   134
        resultButtonPanel = new JPanel(layout);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   135
        canvasPanel = new JPanel();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   136
        GridBagConstraints gbc = new GridBagConstraints();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   137
        String instructions
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   138
                = "<html>    INSTRUCTIONS:<br><br>"
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   139
                + "After clicking on Start Test button you will see Red<br> "
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   140
                + " circle drawn with light blue background, if the circle<br>"
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   141
                + " color changes from Red to Green then press button Fail,<br>"
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   142
                + " if it stays Red then press button Pass.<br><br></html>";
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   143
        instructionText = new JLabel();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   144
        instructionText.setText(instructions);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   145
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   146
        gbc.gridx = 0;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   147
        gbc.gridy = 0;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   148
        gbc.fill = GridBagConstraints.HORIZONTAL;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   149
        mainControlPanel.add(instructionText, gbc);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   150
        startTestButton = new JButton("Start Test");
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   151
        startTestButton.setActionCommand("Start Test");
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   152
        startTestButton.addActionListener(new ActionListener() {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   153
            @Override
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   154
            public void actionPerformed(ActionEvent e) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   155
                try {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   156
                    startButtonClicked = true;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   157
                    imageFrame = new Frame();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   158
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   159
                    Iterator it = ImageIO.getImageWritersByFormatName("GIF");
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   160
                    while (it.hasNext()) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   161
                        writer = (ImageWriter) it.next();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   162
                        break;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   163
                    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   164
                    // read input opaque PNG image.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   165
                    String fileName = "opaque_input.png";
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   166
                    String sep = System.getProperty("file.separator");
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   167
                    String dir = System.getProperty("test.src", ".");
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   168
                    System.out.println(dir + "     " + sep);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   169
                    String filePath = dir + sep + fileName;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   170
                    File inputFile = new File(filePath);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   171
                    ImageInputStream iis = ImageIO.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   172
                            createImageInputStream(inputFile);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   173
                    ImageReader reader = null;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   174
                    Iterator readerIter = ImageIO.getImageReaders(iis);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   175
                    while (readerIter.hasNext()) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   176
                        reader = (ImageReader) readerIter.next();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   177
                        break;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   178
                    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   179
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   180
                    reader.setInput(iis);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   181
                    IIOMetadata imgData = reader.getImageMetadata(0);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   182
                    BufferedImage bi = reader.read(0);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   183
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   184
                    //create temporary GIF imageas output
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   185
                    File directory = new File(dir + sep);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   186
                    outputFile = File.createTempFile("output",
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   187
                            ".gif", directory);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   188
                    createAnimatedImage(bi, imgData,
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   189
                            writer, outputFile);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   190
                    writer.dispose();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   191
                    iis.close();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   192
                    if (outputFile == null) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   193
                        throw new RuntimeException("Unable to create output GIF"
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   194
                                + " file");
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   195
                    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   196
                    // extract GIF image using Toolkit and show it on a Panel.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   197
                    tk = Toolkit.getDefaultToolkit();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   198
                    img = tk.getImage(dir + sep + outputFile.getName());
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   199
                    directory.delete();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   200
                    imageCanvas.setBackground(canvasColor);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   201
                    imageCanvas.setImage(img);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   202
                    imageCanvas.setPreferredSize(prefImgSize);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   203
                    canvasPanel.doLayout();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   204
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   205
                    canvasPanel.add(imageCanvas);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   206
                    imageFrame.add("Center", canvasPanel);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   207
                    imageFrame.setSize(200, 200);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   208
                    imageFrame.setVisible(true);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   209
                    imageFrame.addWindowListener(new WindowAdapter() {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   210
                        @Override
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   211
                        public void windowClosing(WindowEvent e) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   212
                            try {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   213
                                img.flush();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   214
                                instructionFrame.dispose();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   215
                                imageFrame.dispose();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   216
                                fail();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   217
                            } finally {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   218
                                try {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   219
                                    fos.close();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   220
                                    Files.delete(outputFile.toPath());
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   221
                                } catch (IOException ex) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   222
                                    Logger.getLogger(OpaquePNGToGIFTest.class.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   223
                                            getName()).log(Level.SEVERE, null,
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   224
                                                    ex);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   225
                                }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   226
                            }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   227
                        }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   228
                    });
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   229
                } catch (IOException ex) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   230
                    Logger.getLogger(OpaquePNGToGIFTest.class.getName()).
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   231
                            log(Level.SEVERE, null, ex);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   232
                }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   233
            }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   234
        });
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   235
        passButton = new JButton("Pass");
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   236
        passButton.setActionCommand("Pass");
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   237
        passButton.addActionListener(new ActionListener() {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   238
            @Override
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   239
            public void actionPerformed(ActionEvent e) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   240
                try {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   241
                    if (img != null) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   242
                        img.flush();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   243
                    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   244
                    instructionFrame.dispose();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   245
                    if (!startButtonClicked) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   246
                        fail();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   247
                    } else {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   248
                        imageFrame.dispose();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   249
                        pass();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   250
                    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   251
                } finally {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   252
                    try {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   253
                        fos.close();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   254
                        Files.delete(outputFile.toPath());
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   255
                    } catch (IOException ex) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   256
                        Logger.getLogger(OpaquePNGToGIFTest.class.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   257
                                getName()).log(Level.SEVERE, null, ex);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   258
                    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   259
                }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   260
            }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   261
        });
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   262
        failButton = new JButton("Fail");
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   263
        failButton.setActionCommand("Fail");
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   264
        failButton.addActionListener(new ActionListener() {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   265
            @Override
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   266
            public void actionPerformed(ActionEvent e) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   267
                try {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   268
                    if (img != null) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   269
                        img.flush();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   270
                    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   271
                    instructionFrame.dispose();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   272
                    if (!startButtonClicked) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   273
                        fail();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   274
                    } else {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   275
                        imageFrame.dispose();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   276
                        fail();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   277
                    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   278
                } finally {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   279
                    try {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   280
                        fos.close();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   281
                        Files.delete(outputFile.toPath());
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   282
                    } catch (IOException ex) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   283
                        Logger.getLogger(OpaquePNGToGIFTest.class.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   284
                                getName()).log(Level.SEVERE, null, ex);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   285
                    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   286
                }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   287
            }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   288
        });
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   289
        gbc.gridx = 1;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   290
        gbc.gridy = 0;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   291
        resultButtonPanel.add(startTestButton, gbc);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   292
        gbc.gridx = 2;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   293
        gbc.gridy = 0;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   294
        resultButtonPanel.add(passButton, gbc);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   295
        gbc.gridx = 3;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   296
        gbc.gridy = 0;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   297
        resultButtonPanel.add(failButton, gbc);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   298
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   299
        gbc.gridx = 0;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   300
        gbc.gridy = 1;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   301
        mainControlPanel.add(resultButtonPanel, gbc);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   302
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   303
        dialog.add(mainControlPanel);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   304
        dialog.setSize(400, 200);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   305
        dialog.setLocationRelativeTo(null);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   306
        dialog.setVisible(true);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   307
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   308
        dialog.addWindowListener(new WindowAdapter() {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   309
            @Override
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   310
            public void windowClosing(WindowEvent e) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   311
                try {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   312
                    if (img != null) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   313
                        img.flush();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   314
                    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   315
                    instructionFrame.dispose();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   316
                    if (!startButtonClicked) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   317
                        fail();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   318
                    } else {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   319
                        imageFrame.dispose();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   320
                        fail();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   321
                    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   322
                } finally {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   323
                    try {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   324
                        fos.close();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   325
                        Files.delete(outputFile.toPath());
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   326
                    } catch (IOException ex) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   327
                        Logger.getLogger(OpaquePNGToGIFTest.class.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   328
                                getName()).log(Level.SEVERE, null, ex);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   329
                    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   330
                }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   331
            }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   332
        });
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   333
    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   334
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   335
    public synchronized void pass() {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   336
        testPassed = true;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   337
        testGeneratedInterrupt = true;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   338
        mainThread.interrupt();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   339
    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   340
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   341
    public synchronized void fail() {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   342
        testPassed = false;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   343
        testGeneratedInterrupt = true;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   344
        mainThread.interrupt();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   345
    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   346
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   347
    public void createAnimatedImage(BufferedImage bi, IIOMetadata metadata,
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   348
            ImageWriter writer, File outputFile) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   349
        try {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   350
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   351
            fos = new FileOutputStream(outputFile);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   352
            ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   353
            System.out.println(ios);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   354
            writer.setOutput(ios);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   355
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   356
            ImageWriteParam param = writer.getDefaultWriteParam();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   357
            IIOMetadata streamData = writer.getDefaultStreamMetadata(param);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   358
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   359
            writer.prepareWriteSequence(streamData);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   360
            ImageTypeSpecifier specify = new ImageTypeSpecifier(bi);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   361
            IIOMetadata imgData = writer.convertImageMetadata(
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   362
                    (IIOMetadata) metadata, specify, param);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   363
            GIFImageMetadata gifData = setAnimationProperties(imgData);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   364
            IIOImage iim = new IIOImage(bi, null, gifData);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   365
            param.setProgressiveMode(param.MODE_DISABLED);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   366
            writer.writeToSequence(iim, param);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   367
            writer.endWriteSequence();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   368
            ios.close();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   369
        } catch (Exception e) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   370
            e.printStackTrace();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   371
        }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   372
    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   373
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   374
    public GIFImageMetadata setAnimationProperties(IIOMetadata data) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   375
        ArrayList appIDs = new ArrayList();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   376
        appIDs.add(new String("NETSCAPE").getBytes());
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   377
        ArrayList authCodes = new ArrayList();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   378
        authCodes.add(new String("2.0").getBytes());
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   379
        ArrayList appData = new ArrayList();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   380
        byte[] authData = {1, 0, 0};
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   381
        appData.add(authData);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   382
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   383
        GIFImageMetadata gifData = (GIFImageMetadata) data;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   384
        gifData.delayTime = 200;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   385
        // If we set disposalMethod to 2 then only the issue is reproduced.
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   386
        gifData.disposalMethod = 2;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   387
        gifData.userInputFlag = false;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   388
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   389
        gifData.applicationIDs = appIDs;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   390
        gifData.authenticationCodes = authCodes;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   391
        gifData.applicationData = appData;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   392
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   393
        return gifData;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   394
    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   395
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   396
    public static void main(String args[]) throws Exception {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   397
        OpaquePNGToGIFTest test = new OpaquePNGToGIFTest();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   398
    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   399
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   400
    class ImageCanvas extends Canvas {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   401
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   402
        Image im = null;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   403
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   404
        public void setImage(Image img) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   405
            im = img;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   406
        }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   407
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   408
        public void clearImage() {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   409
            im = null;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   410
            repaint();
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   411
        }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   412
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   413
        public void paint(Graphics g) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   414
            Graphics2D g2d = (Graphics2D) g;
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   415
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   416
            if (im != null) {
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   417
                g2d.drawImage(im, 1, 1, getWidth(), getHeight(), this);
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   418
            }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   419
        }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   420
    }
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   421
}
53ac12e1344a 6334602: Animated GIFs created from opaque PNG image frames appear transparent when loaded with Toolkit APIs
jdv
parents:
diff changeset
   422