1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.utils.ui.gfx.clipboard.streams;
14 import java.io.IOException;
15 import java.io.InputStream;
17 import org.simantics.utils.ui.gfx.clipboard.headers.BitmapInfoHeader;
18 import org.simantics.utils.ui.gfx.clipboard.headers.Win32Constants;
23 * Intended to uncompress compressed image streams so that
24 * SWT can use images sent to clipboard (native WIN32)
27 * Currently no uncompression methods are implemented, so
28 * stream throws <code>IOException</code> if its used to
29 * stream compressed images.
32 * @author Marko Luukkainen
35 public class UncompressedDIBInputStream extends InputStream {
36 private InputStream iStream;
37 private int readBytes = 0;
38 private byte [] header;
40 public UncompressedDIBInputStream(InputStream iStream) throws IOException{
41 this.iStream = iStream;
42 header = new byte[BitmapInfoHeader.sizeof];
43 iStream.read(header, 0, BitmapInfoHeader.sizeof);
45 BitmapInfoHeader infoHeader = new BitmapInfoHeader();
46 infoHeader.setBytes(header);
47 if (infoHeader.biCompression == Win32Constants.BI_BITFIELDS) {
48 throw new IOException("BI_BITFIELDS stream not supported");
50 if (infoHeader.biCompression == Win32Constants.BI_JPEG) {
51 throw new IOException("BI_JPEG stream not supported");
53 if (infoHeader.biCompression == Win32Constants.BI_PNG) {
54 throw new IOException("BI_PNG stream not supported");
56 if (infoHeader.biCompression == Win32Constants.BI_RLE8) {
57 throw new IOException("BI_RLE8 stream not supported");
59 if (infoHeader.biCompression == Win32Constants.BI_RLE24) {
60 throw new IOException("BI_RLE24 stream not supported");
65 public int read() throws IOException {
66 if (readBytes < header.length) {
67 return 0xff & header[readBytes++];
69 return iStream.read();