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