1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
* Foundation.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* or from the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* Copyright (c) 2000 - 2009 Pentaho Corporation, Object Refinery Limited and Contributors. All rights reserved.
*/
package org.pentaho.reporting.libraries.pixie.wmf;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.ImageConsumer;
import java.awt.image.ImageProducer;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
/**
* Implements the ImageProducer interface for the MetaFiles
*/
public class WmfImageProducer implements ImageProducer
{
private WmfFile metafile;
private ArrayList consumers;
public WmfImageProducer(final String inName, final int width, final int height)
throws IOException
{
consumers = new ArrayList();
metafile = new WmfFile(inName, width, height);
// metafile.replay ();
}
public WmfImageProducer(final URL inName, final int width, final int height)
throws IOException
{
consumers = new ArrayList();
metafile = new WmfFile(inName, width, height);
// metafile.replay ();
}
public WmfImageProducer(final URL inName)
throws IOException
{
consumers = new ArrayList();
metafile = new WmfFile(inName);
// metafile.replay ();
}
public synchronized void addConsumer(final ImageConsumer ic)
{
if (isConsumer(ic))
{
return;
}
consumers.add(ic);
}
public synchronized boolean isConsumer(final ImageConsumer ic)
{
return consumers.contains(ic);
}
public synchronized void removeConsumer(final ImageConsumer ic)
{
consumers.remove(ic);
}
public synchronized void requestTopDownLeftRightResend(final ImageConsumer ic)
{
startProduction(ic);
}
public synchronized void startProduction(final ImageConsumer pic)
{
if (pic != null)
{
addConsumer(pic);
}
final ImageConsumer[] cons = (ImageConsumer[]) consumers.toArray(new ImageConsumer[consumers.size()]);
final BufferedImage image = metafile.replay();
final int w = image.getWidth();
final int h = image.getHeight();
final ColorModel model = image.getColorModel();
for (int i = 0; i < cons.length; i++)
{
final ImageConsumer ic = cons[i];
ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT);
ic.setHints(ImageConsumer.SINGLEFRAME);
ic.setHints(ImageConsumer.SINGLEPASS);
ic.setHints(ImageConsumer.COMPLETESCANLINES);
ic.setDimensions(w, h);
ic.setColorModel(model);
}
final int LINES = 10;
int[] pixels = new int[w * LINES];
for (int i = 0; i < h; i += LINES)
{
final int rows;
if ((i + LINES) > h)
{
rows = h - i;
}
else
{
rows = LINES;
}
pixels = image.getRGB(0, i, w, rows, pixels, 0, w);
for (int j = 0; j < cons.length; j++)
{
final ImageConsumer ic = cons[j];
ic.setPixels(0, i, w, rows, model, pixels, 0, w);
}
}
for (int i = 0; i < cons.length; i++)
{
final ImageConsumer ic = cons[i];
ic.imageComplete(ImageConsumer.STATICIMAGEDONE);
}
if (pic != null)
{
removeConsumer(pic);
}
}
}
|