01: /*
02: * $RCSfile: JPEGCodec.java,v $
03: *
04: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
05: *
06: * Use is subject to license terms.
07: *
08: * $Revision: 1.1 $
09: * $Date: 2005/02/11 04:55:36 $
10: * $State: Exp $
11: */
12:
13: package com.sun.media.jai.codecimpl;
14:
15: import java.awt.image.RenderedImage;
16: import java.io.File;
17: import java.io.FileInputStream;
18: import java.io.InputStream;
19: import java.io.IOException;
20: import java.io.OutputStream;
21: import com.sun.media.jai.codec.ImageCodec;
22: import com.sun.media.jai.codec.ImageDecoder;
23: import com.sun.media.jai.codec.ImageDecodeParam;
24: import com.sun.media.jai.codec.ImageEncoder;
25: import com.sun.media.jai.codec.ImageEncodeParam;
26: import com.sun.media.jai.codec.JPEGDecodeParam;
27: import com.sun.media.jai.codec.JPEGEncodeParam;
28: import com.sun.media.jai.codec.SeekableStream;
29:
30: /**
31: * @since EA2
32: */
33: public final class JPEGCodec extends ImageCodec {
34:
35: public JPEGCodec() {
36: }
37:
38: public String getFormatName() {
39: return "jpeg";
40: }
41:
42: public Class getEncodeParamClass() {
43: return com.sun.media.jai.codec.JPEGEncodeParam.class;
44: }
45:
46: public Class getDecodeParamClass() {
47: return com.sun.media.jai.codec.JPEGDecodeParam.class;
48: }
49:
50: public boolean canEncodeImage(RenderedImage im,
51: ImageEncodeParam param) {
52: return true;
53: }
54:
55: protected ImageEncoder createImageEncoder(OutputStream dst,
56: ImageEncodeParam param) {
57: JPEGEncodeParam p = null;
58: if (param != null) {
59: p = (JPEGEncodeParam) param;
60: }
61:
62: return new JPEGImageEncoder(dst, p);
63: }
64:
65: protected ImageDecoder createImageDecoder(InputStream src,
66: ImageDecodeParam param) {
67: return new JPEGImageDecoder(src, param);
68: }
69:
70: protected ImageDecoder createImageDecoder(File src,
71: ImageDecodeParam param) throws IOException {
72: return new JPEGImageDecoder(new FileInputStream(src), param);
73: }
74:
75: protected ImageDecoder createImageDecoder(SeekableStream src,
76: ImageDecodeParam param) {
77: return new JPEGImageDecoder(src, param);
78: }
79:
80: public int getNumHeaderBytes() {
81: return 3;
82: }
83:
84: public boolean isFormatRecognized(byte[] header) {
85: return ((header[0] == (byte) 0xff)
86: && (header[1] == (byte) 0xd8) && (header[2] == (byte) 0xff));
87: }
88: }
|