2
Copyright (C) 2010 Volker Berlin (i-net software)
4
This software is provided 'as-is', without any express or implied
5
warranty. In no event will the authors be held liable for any damages
6
arising from the use of this software.
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
10
freely, subject to the following restrictions:
12
1. The origin of this software must not be misrepresented; you must not
13
claim that you wrote the original software. If you use this software
14
in a product, an acknowledgment in the product documentation would be
15
appreciated but is not required.
16
2. Altered source versions must be plainly marked as such, and must not be
17
misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
24
package sun.awt.image;
26
import java.awt.image.*;
27
import java.io.IOException;
28
import java.io.InputStream;
30
import cli.System.Drawing.Bitmap;
31
import cli.System.Drawing.Imaging.ImageLockMode;
32
import cli.System.Drawing.Imaging.PixelFormat;
33
import cli.System.IO.SeekOrigin;
34
import cli.System.IO.Stream;
35
import cli.System.NotSupportedException;
36
import ikvm.runtime.Util;
38
abstract class IkvmImageDecoder extends ImageDecoder {
40
IkvmImageDecoder(InputStreamImageSource src, InputStream is){
45
@cli.System.Security.SecuritySafeCriticalAttribute.Annotation
46
public void produceImage() throws IOException, ImageFormatException{
47
Stream stream = new Stream(){
51
Util.throwException(new NotSupportedException());
55
public int Read(byte[] bytes, int off, int len){
57
int count = input.read(bytes, off, len);
62
}catch(IOException ex){
63
throw new RuntimeException(ex);
68
public long Seek(long arg0, SeekOrigin arg1){
69
Util.throwException(new NotSupportedException());
74
public void SetLength(long arg0){
75
Util.throwException(new NotSupportedException());
79
public void Write(byte[] arg0, int arg1, int arg2){
80
Util.throwException(new NotSupportedException());
84
public boolean get_CanRead(){
89
public boolean get_CanSeek(){
94
public boolean get_CanWrite(){
99
public long get_Length(){
101
return input.available();
102
}catch(IOException ex){
103
throw new RuntimeException(ex);
108
public long get_Position(){
109
Util.throwException(new NotSupportedException());
114
public void set_Position(long arg0){
115
Util.throwException(new NotSupportedException());
120
Bitmap bitmap = new Bitmap(stream);
121
int width = bitmap.get_Width();
122
int height = bitmap.get_Height();
123
int size = width * height;
124
int[] pixelData = new int[size];
126
cli.System.Drawing.Rectangle rect = new cli.System.Drawing.Rectangle(0, 0, width, height);
127
cli.System.Drawing.Imaging.BitmapData data = bitmap.LockBits(rect, ImageLockMode.wrap(ImageLockMode.ReadOnly), PixelFormat.wrap(PixelFormat.Format32bppArgb));
128
cli.System.IntPtr pixelPtr = data.get_Scan0();
129
cli.System.Runtime.InteropServices.Marshal.Copy(pixelPtr, pixelData, 0, size);
130
bitmap.UnlockBits(data);
134
setDimensions(width, height);
135
ColorModel cm = ColorModel.getRGBdefault();
140
setPixels(0,0,width,height, cm, pixelData,0,width);
141
imageComplete(ImageConsumer.STATICIMAGEDONE, true);
142
}catch(Throwable th){
143
th.printStackTrace();
144
imageComplete(ImageConsumer.IMAGEERROR|ImageConsumer.STATICIMAGEDONE, true);
145
throw new IOException(th);
147
try { close(); } catch(Throwable e){e.printStackTrace();}