~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/sun/awt/image/IkvmImageDecoder.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2010 Volker Berlin (i-net software)
 
3
 
 
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.
 
7
 
 
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:
 
11
 
 
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.
 
19
 
 
20
  Jeroen Frijters
 
21
  jeroen@frijters.net
 
22
  
 
23
 */
 
24
package sun.awt.image;
 
25
 
 
26
import java.awt.image.*;
 
27
import java.io.IOException;
 
28
import java.io.InputStream;
 
29
 
 
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;
 
37
 
 
38
abstract class IkvmImageDecoder extends ImageDecoder {
 
39
 
 
40
    IkvmImageDecoder(InputStreamImageSource src, InputStream is){
 
41
        super(src, is);
 
42
    }
 
43
 
 
44
    @Override
 
45
    @cli.System.Security.SecuritySafeCriticalAttribute.Annotation
 
46
    public void produceImage() throws IOException, ImageFormatException{
 
47
        Stream stream = new Stream(){
 
48
 
 
49
            @Override
 
50
            public void Flush(){
 
51
                Util.throwException(new NotSupportedException());
 
52
            }
 
53
 
 
54
            @Override
 
55
            public int Read(byte[] bytes, int off, int len){
 
56
                try{
 
57
                    int count = input.read(bytes, off, len);
 
58
                    if( count < 0 ){
 
59
                        return 0;
 
60
                    }
 
61
                    return count;
 
62
                }catch(IOException ex){
 
63
                    throw new RuntimeException(ex);
 
64
                }
 
65
            }
 
66
 
 
67
            @Override
 
68
            public long Seek(long arg0, SeekOrigin arg1){
 
69
                Util.throwException(new NotSupportedException());
 
70
                return 0;
 
71
            }
 
72
 
 
73
            @Override
 
74
            public void SetLength(long arg0){
 
75
                Util.throwException(new NotSupportedException());
 
76
            }
 
77
 
 
78
            @Override
 
79
            public void Write(byte[] arg0, int arg1, int arg2){
 
80
                Util.throwException(new NotSupportedException());
 
81
            }
 
82
 
 
83
            @Override
 
84
            public boolean get_CanRead(){
 
85
                return true;
 
86
            }
 
87
 
 
88
            @Override
 
89
            public boolean get_CanSeek(){
 
90
                return false;
 
91
            }
 
92
 
 
93
            @Override
 
94
            public boolean get_CanWrite(){
 
95
                return true;
 
96
            }
 
97
 
 
98
            @Override
 
99
            public long get_Length(){
 
100
                try{
 
101
                    return input.available();
 
102
                }catch(IOException ex){
 
103
                    throw new RuntimeException(ex);
 
104
                }
 
105
            }
 
106
 
 
107
            @Override
 
108
            public long get_Position(){
 
109
                Util.throwException(new NotSupportedException());
 
110
                return 0;
 
111
            }
 
112
 
 
113
            @Override
 
114
            public void set_Position(long arg0){
 
115
                Util.throwException(new NotSupportedException());
 
116
            }
 
117
            
 
118
        };
 
119
        try{
 
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];
 
125
            
 
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);
 
131
            
 
132
            //source.
 
133
            
 
134
            setDimensions(width, height);
 
135
            ColorModel cm = ColorModel.getRGBdefault();
 
136
            setColorModel(cm);
 
137
            //setHints(flags);
 
138
            headerComplete();
 
139
            
 
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);
 
146
        } finally {
 
147
            try { close(); } catch(Throwable e){e.printStackTrace();}
 
148
        }
 
149
    }
 
150
}