< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/gif/GIFImageWriter.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2016, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 712             writeHeader(streamMetadata, bitsPerPixel);
 713         } else if (isWritingSequence) {
 714             globalColorTable = theStreamMetadata.globalColorTable;
 715         } else {
 716             throw new IllegalArgumentException("Must write header for single image!");
 717         }
 718 
 719         // Write extension blocks, Image Descriptor, and image data.
 720         writeImage(iioimage.getRenderedImage(), imageMetadata, p,
 721                    globalColorTable, sourceBounds, destSize);
 722 
 723         // Write the trailer.
 724         if (writeTrailer) {
 725             writeTrailer();
 726         }
 727     }
 728 
 729     /**
 730      * Writes any extension blocks, the Image Descriptor, and the image data
 731      *
 732      * @param iioimage The image and image metadata.

 733      * @param param The write parameters.
 734      * @param globalColorTable The Global Color Table.
 735      * @param sourceBounds The source region.
 736      * @param destSize The destination dimensions.
 737      */
 738     private void writeImage(RenderedImage image,
 739                             GIFWritableImageMetadata imageMetadata,
 740                             ImageWriteParam param, byte[] globalColorTable,
 741                             Rectangle sourceBounds, Dimension destSize)
 742       throws IOException {
 743         ColorModel colorModel = image.getColorModel();
 744         SampleModel sampleModel = image.getSampleModel();
 745 
 746         boolean writeGraphicsControlExtension;
 747         if (imageMetadata == null) {
 748             // Create default metadata.
 749             imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata(
 750                 new ImageTypeSpecifier(image), param);
 751 
 752             // Set GraphicControlExtension flag only if there is


   1 /*
   2  * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 712             writeHeader(streamMetadata, bitsPerPixel);
 713         } else if (isWritingSequence) {
 714             globalColorTable = theStreamMetadata.globalColorTable;
 715         } else {
 716             throw new IllegalArgumentException("Must write header for single image!");
 717         }
 718 
 719         // Write extension blocks, Image Descriptor, and image data.
 720         writeImage(iioimage.getRenderedImage(), imageMetadata, p,
 721                    globalColorTable, sourceBounds, destSize);
 722 
 723         // Write the trailer.
 724         if (writeTrailer) {
 725             writeTrailer();
 726         }
 727     }
 728 
 729     /**
 730      * Writes any extension blocks, the Image Descriptor, and the image data
 731      *
 732      * @param image The image.
 733      * @param imageMetadata The image metadata.
 734      * @param param The write parameters.
 735      * @param globalColorTable The Global Color Table.
 736      * @param sourceBounds The source region.
 737      * @param destSize The destination dimensions.
 738      */
 739     private void writeImage(RenderedImage image,
 740                             GIFWritableImageMetadata imageMetadata,
 741                             ImageWriteParam param, byte[] globalColorTable,
 742                             Rectangle sourceBounds, Dimension destSize)
 743       throws IOException {
 744         ColorModel colorModel = image.getColorModel();
 745         SampleModel sampleModel = image.getSampleModel();
 746 
 747         boolean writeGraphicsControlExtension;
 748         if (imageMetadata == null) {
 749             // Create default metadata.
 750             imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata(
 751                 new ImageTypeSpecifier(image), param);
 752 
 753             // Set GraphicControlExtension flag only if there is


< prev index next >