2
Copyright (C) 2008, 2009 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 com.sun.imageio.plugins.jpeg;
27
import java.awt.image.BufferedImage;
29
import java.util.Iterator;
31
import javax.imageio.*;
32
import javax.imageio.metadata.IIOMetadata;
33
import javax.imageio.spi.ImageReaderSpi;
34
import javax.imageio.stream.ImageInputStream;
37
* A image reader implementation that is calling the .NET API for reading the JPEG image.
39
class JPEGImageReader extends ImageReader{
41
private BufferedImage image;
44
* Default constructor, Sun compatible.
46
protected JPEGImageReader(ImageReaderSpi originatingProvider){
47
super(originatingProvider);
54
public int getHeight(int imageIndex) throws IOException{
55
return getBufferedImage().getHeight();
62
public IIOMetadata getImageMetadata(int imageIndex){
63
throw new Error("Not Implemented");
70
public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex){
71
throw new Error("Not Implemented");
78
public int getNumImages(boolean allowSearch){
86
public IIOMetadata getStreamMetadata(){
87
throw new Error("Not Implemented");
94
public int getWidth(int imageIndex) throws IOException{
95
return getBufferedImage().getWidth();
102
public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException{
103
return getBufferedImage();
107
* Read the image with .NET API if not already read.
109
private BufferedImage getBufferedImage() throws IOException{
111
ImageInputStream iis = (ImageInputStream)getInput();
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);
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];
123
while((count = iis.read(buffer)) > 0){
124
baos.write(buffer, 0, count);
126
buffer = baos.toByteArray();
128
} catch (IOException ioex) {
129
processReadAborted();
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();
b'\\ No newline at end of file'