< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/wbmp/WBMPImageWriter.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 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


  41 
  42 import javax.imageio.IIOImage;
  43 import javax.imageio.IIOException;
  44 import javax.imageio.ImageTypeSpecifier;
  45 import javax.imageio.ImageWriteParam;
  46 import javax.imageio.ImageWriter;
  47 import javax.imageio.metadata.IIOMetadata;
  48 import javax.imageio.metadata.IIOMetadataFormatImpl;
  49 import javax.imageio.metadata.IIOInvalidTreeException;
  50 import javax.imageio.spi.ImageWriterSpi;
  51 import javax.imageio.stream.ImageOutputStream;
  52 
  53 import com.sun.imageio.plugins.common.I18N;
  54 
  55 /**
  56  * The Java Image IO plugin writer for encoding a binary RenderedImage into
  57  * a WBMP format.
  58  *
  59  * The encoding process may clip, subsample using the parameters
  60  * specified in the {@code ImageWriteParam}.
  61  *
  62  * @see com.sun.media.imageio.plugins.WBMPImageWriteParam
  63  */
  64 public class WBMPImageWriter extends ImageWriter {
  65     /** The output stream to write into */
  66     private ImageOutputStream stream = null;
  67 
  68     // Get the number of bits required to represent an int.
  69     private static int getNumBits(int intValue) {
  70         int numBits = 32;
  71         int mask = 0x80000000;
  72         while(mask != 0 && (intValue & mask) == 0) {
  73             numBits--;
  74             mask >>>= 1;
  75         }
  76         return numBits;
  77     }
  78 
  79     // Convert an int value to WBMP multi-byte format.
  80     private static byte[] intToMultiByte(int intValue) {
  81         int numBitsLeft = getNumBits(intValue);
  82         byte[] multiBytes = new byte[(numBitsLeft + 6)/7];


   1 /*
   2  * Copyright (c) 2003, 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


  41 
  42 import javax.imageio.IIOImage;
  43 import javax.imageio.IIOException;
  44 import javax.imageio.ImageTypeSpecifier;
  45 import javax.imageio.ImageWriteParam;
  46 import javax.imageio.ImageWriter;
  47 import javax.imageio.metadata.IIOMetadata;
  48 import javax.imageio.metadata.IIOMetadataFormatImpl;
  49 import javax.imageio.metadata.IIOInvalidTreeException;
  50 import javax.imageio.spi.ImageWriterSpi;
  51 import javax.imageio.stream.ImageOutputStream;
  52 
  53 import com.sun.imageio.plugins.common.I18N;
  54 
  55 /**
  56  * The Java Image IO plugin writer for encoding a binary RenderedImage into
  57  * a WBMP format.
  58  *
  59  * The encoding process may clip, subsample using the parameters
  60  * specified in the {@code ImageWriteParam}.


  61  */
  62 public class WBMPImageWriter extends ImageWriter {
  63     /** The output stream to write into */
  64     private ImageOutputStream stream = null;
  65 
  66     // Get the number of bits required to represent an int.
  67     private static int getNumBits(int intValue) {
  68         int numBits = 32;
  69         int mask = 0x80000000;
  70         while(mask != 0 && (intValue & mask) == 0) {
  71             numBits--;
  72             mask >>>= 1;
  73         }
  74         return numBits;
  75     }
  76 
  77     // Convert an int value to WBMP multi-byte format.
  78     private static byte[] intToMultiByte(int intValue) {
  79         int numBitsLeft = getNumBits(intValue);
  80         byte[] multiBytes = new byte[(numBitsLeft + 6)/7];


< prev index next >