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

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/com/sun/imageio/plugins/jpeg/JPEGImageReader.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) 2008, 2009 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 com.sun.imageio.plugins.jpeg;
 
25
 
 
26
import java.awt.*;
 
27
import java.awt.image.BufferedImage;
 
28
import java.io.*;
 
29
import java.util.Iterator;
 
30
 
 
31
import javax.imageio.*;
 
32
import javax.imageio.metadata.IIOMetadata;
 
33
import javax.imageio.spi.ImageReaderSpi;
 
34
import javax.imageio.stream.ImageInputStream;
 
35
 
 
36
/**
 
37
 * A image reader implementation that is calling the .NET API for reading the JPEG image.
 
38
 */
 
39
class JPEGImageReader extends ImageReader{
 
40
    
 
41
    private BufferedImage image;
 
42
 
 
43
    /**
 
44
     * Default constructor, Sun compatible.
 
45
     */
 
46
    protected JPEGImageReader(ImageReaderSpi originatingProvider){
 
47
        super(originatingProvider);
 
48
    }
 
49
 
 
50
    /**
 
51
     * {@inheritDoc}
 
52
     */
 
53
    @Override
 
54
    public int getHeight(int imageIndex) throws IOException{
 
55
        return getBufferedImage().getHeight();
 
56
    }
 
57
 
 
58
    /**
 
59
     * {@inheritDoc}
 
60
     */
 
61
    @Override
 
62
    public IIOMetadata getImageMetadata(int imageIndex){
 
63
        throw new Error("Not Implemented");
 
64
    }
 
65
 
 
66
    /**
 
67
     * {@inheritDoc}
 
68
     */
 
69
    @Override
 
70
    public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex){
 
71
        throw new Error("Not Implemented");
 
72
    }
 
73
 
 
74
    /**
 
75
     * {@inheritDoc}
 
76
     */
 
77
    @Override
 
78
    public int getNumImages(boolean allowSearch){
 
79
        return 1;
 
80
    }
 
81
 
 
82
    /**
 
83
     * {@inheritDoc}
 
84
     */
 
85
    @Override
 
86
    public IIOMetadata getStreamMetadata(){
 
87
        throw new Error("Not Implemented");
 
88
    }
 
89
 
 
90
    /**
 
91
     * {@inheritDoc}
 
92
     */
 
93
    @Override
 
94
    public int getWidth(int imageIndex) throws IOException{
 
95
        return getBufferedImage().getWidth();
 
96
    }
 
97
 
 
98
    /**
 
99
     * {@inheritDoc}
 
100
     */
 
101
    @Override
 
102
    public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException{
 
103
        return getBufferedImage();
 
104
    }
 
105
    
 
106
    /**
 
107
     * Read the image with .NET API if not already read.
 
108
     */
 
109
    private BufferedImage getBufferedImage() throws IOException{
 
110
        if(image == null){
 
111
            ImageInputStream iis = (ImageInputStream)getInput();
 
112
            byte[] buffer;
 
113
            try {
 
114
                                if( iis.length() >0){
 
115
                                    //If length known then it it is simple
 
116
                                    buffer = new byte[(int)iis.length()];
 
117
                                    iis.readFully(buffer);
 
118
                                }else{
 
119
                                    // if the length not known then we need to read it in a loop
 
120
                                    ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
 
121
                                    buffer = new byte[8192];
 
122
                                    int count;
 
123
                                    while((count = iis.read(buffer)) > 0){
 
124
                                        baos.write(buffer, 0, count);
 
125
                                    }
 
126
                                    buffer = baos.toByteArray();
 
127
                                }
 
128
                        } catch (IOException ioex) {
 
129
                                processReadAborted();
 
130
                                throw ioex;
 
131
                        }
 
132
            processImageStarted(0);
 
133
            image = (BufferedImage)Toolkit.getDefaultToolkit().createImage(buffer);
 
134
            processPassStarted(image, 0, 0, 1, 0, 0, 1, 1, new int[0]);
 
135
            processImageProgress(100.0F);
 
136
            processImageUpdate(image, 0, 0, 0, 0, 1, 1, new int[0]);
 
137
            processPassComplete(image);
 
138
            processImageComplete();
 
139
        }
 
140
        return image;
 
141
    }
 
142
 
 
143
}
 
 
b'\\ No newline at end of file'