01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. You may obtain a copy of the License at
09:
10: http://www.apache.org/licenses/LICENSE-2.0
11:
12: Unless required by applicable law or agreed to in writing, software
13: distributed under the License is distributed on an "AS IS" BASIS,
14: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: See the License for the specific language governing permissions and
16: limitations under the License.
17:
18: */
19: package org.apache.batik.svggen;
20:
21: import java.awt.image.BufferedImage;
22: import java.io.IOException;
23: import java.io.OutputStream;
24:
25: import org.apache.batik.ext.awt.image.spi.ImageWriter;
26: import org.apache.batik.ext.awt.image.spi.ImageWriterParams;
27: import org.apache.batik.ext.awt.image.spi.ImageWriterRegistry;
28:
29: /**
30: * GenericImageHandler which caches JPEG images.
31: *
32: * @author <a href="mailto:paul_evenblij@compuware.com">Paul Evenblij</a>
33: * @version $Id: CachedImageHandlerJPEGEncoder.java 475477 2006-11-15 22:44:28Z cam $
34: */
35: public class CachedImageHandlerJPEGEncoder extends
36: DefaultCachedImageHandler {
37: public static final String CACHED_JPEG_PREFIX = "jpegImage";
38: public static final String CACHED_JPEG_SUFFIX = ".jpg";
39:
40: protected String refPrefix = "";
41:
42: /**
43: * @param imageDir directory where this handler should generate images.
44: * If null, an IllegalArgumentException is thrown.
45: * @param urlRoot root for the urls that point to images created by this
46: * image handler. If null, then the url corresponding to imageDir
47: * is used.
48: */
49: public CachedImageHandlerJPEGEncoder(String imageDir, String urlRoot)
50: throws SVGGraphics2DIOException {
51: refPrefix = urlRoot + "/";
52: setImageCacher(new ImageCacher.External(imageDir,
53: CACHED_JPEG_PREFIX, CACHED_JPEG_SUFFIX));
54: }
55:
56: /**
57: * Uses JPEG encoding.
58: */
59: public void encodeImage(BufferedImage buf, OutputStream os)
60: throws IOException {
61: ImageWriter writer = ImageWriterRegistry.getInstance()
62: .getWriterFor("image/jpeg");
63: ImageWriterParams params = new ImageWriterParams();
64: params.setJPEGQuality(1, false);
65: writer.writeImage(buf, os, params);
66: }
67:
68: public int getBufferedImageType() {
69: return BufferedImage.TYPE_INT_RGB;
70: }
71:
72: public String getRefPrefix() {
73: return refPrefix;
74: }
75: }
|