deweese 01/09/27 04:33:21
Modified: sources/org/apache/batik/ext/awt/image/rendered TileRed.java
sources/org/apache/batik/util
ParsedURLDefaultProtocolHandler.java
test-resources/org/apache/batik/util regParsedURL.xml
Log:
1) Fixed relative base and child urls.
2) Added tests
Revision Changes Path
1.10 +121 -55
xml-batik/sources/org/apache/batik/ext/awt/image/rendered/TileRed.java
Index: TileRed.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/rendered/TileRed.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TileRed.java 2001/09/17 20:45:18 1.9
+++ TileRed.java 2001/09/27 11:33:20 1.10
@@ -20,9 +20,11 @@
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
+import java.awt.image.DataBufferInt;
import java.awt.image.Raster;
import java.awt.image.RenderedImage;
import java.awt.image.SampleModel;
+import java.awt.image.SinglePixelPackedSampleModel;
import java.awt.image.WritableRaster;
import java.awt.image.renderable.RenderContext;
@@ -37,7 +39,7 @@
* left corner of the tiled region.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
- * @version $Id: TileRed.java,v 1.9 2001/09/17 20:45:18 deweese Exp $
+ * @version $Id: TileRed.java,v 1.10 2001/09/27 11:33:20 deweese Exp $
*/
public class TileRed extends AbstractRed implements TileGenerator {
static final AffineTransform IDENTITY = new AffineTransform();
@@ -100,7 +102,9 @@
this.hints = hints;
this.alphaPremult = false;
- SampleModel sm = fixSampleModel(tile, xStep, yStep);
+ SampleModel sm = fixSampleModel(tile, xStep, yStep,
+ tiledRegion.width,
+ tiledRegion.height);
ColorModel cm = fixColorModel(tile, alphaPremult);
double smSz = AbstractTiledRed.getDefaultTileSize();
@@ -139,62 +143,13 @@
tile.getMinX(), tile.getMinY(), null);
if (raster != null) {
- int minX = raster.getMinX();
- int minY = raster.getMinY();
- int width = raster.getWidth();
- int height = raster.getHeight();
-
- // This is a fairly expensive operation so do it once
- // upfront. If we wanted this to go even faster we could
- // bypass copyData alltogeather and do the copy loops
- // directly.
- boolean int_pack = GraphicsUtil.is_INT_PACK_Data(sm, false);
-
WritableRaster fromRaster = raster.createWritableChild
- (minX, minY, xStep, yStep, minX, minY, null);
+ (tile.getMinX(), tile.getMinY(),
+ xStep, yStep, tile.getMinX(), tile.getMinY(), null);
// Fill one 'tile' of the input....
fillRasterFrom(fromRaster, tile);
- this.tile = null; // don't need it anymore (It's in the raster).
-
- // Now replicate that out to the rest of the
- // raster. We keep growing the size of the
- // chunk we replicate by 2x.
-
- // Start replicating across the first row...
- int step=xStep;
- for (int x=xStep; x<width; x+=step, step*=2) {
- int w = step;
- if (x+w > width) w = width-x;
- WritableRaster toRaster = raster.createWritableChild
- (minX+x, minY, w, yStep, minX, minY, null);
-
- if (int_pack)
- GraphicsUtil.copyData_INT_PACK(fromRaster, toRaster);
- else
- GraphicsUtil.copyData_FALLBACK(fromRaster, toRaster);
-
- fromRaster = raster.createWritableChild
- (minX, minY, x+w, yStep, minX, minY, null);
- }
-
- // Next replicate that row down to the bottom of the raster...
- step = yStep;
- for (int y=yStep; y<height; y+=step, step*=2) {
- int h = step;
- if (y+h > height) h = height-y;
- WritableRaster toRaster = raster.createWritableChild
- (minX, minY+y, width, h, minX, minY, null);
-
- if (int_pack)
- GraphicsUtil.copyData_INT_PACK(fromRaster, toRaster);
- else
- GraphicsUtil.copyData_FALLBACK(fromRaster, toRaster);
-
-
- fromRaster = raster.createWritableChild
- (minX, minY, width, y+h, minX, minY, null);
- }
+ fillOutRaster(raster);
}
else {
this.tile = new TileCacheRed(GraphicsUtil.wrap(tile));
@@ -330,6 +285,114 @@
return wr;
}
+ protected void fillOutRaster(WritableRaster wr) {
+ if (is_INT_PACK)
+ fillOutRaster_INT_PACK(wr);
+ else
+ fillOutRaster_FALLBACK(wr);
+
+ }
+
+ protected void fillOutRaster_INT_PACK(WritableRaster wr) {
+ // System.out.println("Fast copyData");
+ int x0 = wr.getMinX();
+ int y0 = wr.getMinY();
+ int width = wr.getWidth();
+ int height = wr.getHeight();
+
+ SinglePixelPackedSampleModel sppsm;
+ sppsm = (SinglePixelPackedSampleModel)wr.getSampleModel();
+
+ final int scanStride = sppsm.getScanlineStride();
+ DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
+ final int [] pixels = db.getBankData()[0];
+ final int base =
+ (db.getOffset() +
+ sppsm.getOffset(x0-wr.getSampleModelTranslateX(),
+ y0-wr.getSampleModelTranslateY()));
+ int step = xStep;
+ for (int x=xStep; x<width; x+=step, step*=2) {
+ int w = step;
+ if (x+w > width) w = width-x;
+ if (w >= 128) {
+ int srcSP = base;
+ int dstSP = base+x;
+ for(int y=0; y<yStep; y++) {
+ System.arraycopy(pixels, srcSP, pixels, dstSP, w);
+ srcSP += scanStride;
+ dstSP += scanStride;
+ }
+ } else {
+ int srcSP = base;
+ int dstSP = base+x;
+ for(int y=0; y<yStep; y++) {
+ int end = srcSP;
+ srcSP += w-1;
+ dstSP += w-1;
+ while(srcSP>=end)
+ pixels[dstSP--] = pixels[srcSP--];
+ srcSP+=scanStride+1;
+ dstSP+=scanStride+1;
+ }
+ }
+ }
+
+ step = yStep;
+ for (int y=yStep; y<height; y+=step, step*=2) {
+ int h = step;
+ if (y+h > height) h = height-y;
+ int dstSP = base+y*scanStride;
+ System.arraycopy(pixels, base, pixels, dstSP, h*scanStride);
+ }
+ }
+
+ protected void fillOutRaster_FALLBACK(WritableRaster wr) {
+ // System.out.println("Fast copyData");
+ int x0 = wr.getMinX();
+ int y0 = wr.getMinY();
+ int width = wr.getWidth();
+ int height = wr.getHeight();
+
+ Object data = null;
+
+ int step = xStep;
+ for (int x=xStep; x<width; x+=step, step*=4) {
+ int w = step;
+ if (x+w > width) w = width-x;
+ data = wr.getDataElements(0, 0, w, yStep, data);
+ wr.setDataElements(x, 0, w, yStep, data);
+ x+=w;
+
+ if (x >= width) break;
+ if (x+w > width) w = width-x;
+ wr.setDataElements(x, 0, w, yStep, data);
+ x+=w;
+
+ if (x >= width) break;
+ if (x+w > width) w = width-x;
+ wr.setDataElements(x, 0, w, yStep, data);
+ }
+
+ step = yStep;
+ for (int y=yStep; y<height; y+=step, step*=4) {
+ int h = step;
+ if (y+h > height) h = height-y;
+ data = wr.getDataElements(0, 0, width, h, data);
+ wr.setDataElements(0, y, width, h, data);
+ y+=h;
+
+ if (h >= height) break;
+ if (y+h > height) h = height-y;
+ wr.setDataElements(0, y, width, h, data);
+ y+=h;
+
+ if (h >= height) break;
+ if (y+h > height) h = height-y;
+ wr.setDataElements(0, y, width, h, data);
+ y+=h;
+ }
+ }
+
protected static ColorModel fixColorModel(RenderedImage src,
boolean alphaPremult) {
return GraphicsUtil.coerceColorModel(src.getColorModel(),
@@ -342,15 +405,18 @@
* much larger than my width.
*/
protected static SampleModel fixSampleModel(RenderedImage src,
- int stepX, int stepY) {
+ int stepX, int stepY,
+ int width, int height) {
int defSz = AbstractTiledRed.getDefaultTileSize();
SampleModel sm = src.getSampleModel();
int w = sm.getWidth();
if (w < defSz) w = defSz;
if (w > stepX) w = stepX;
+ // if (w > width) w = width;
int h = sm.getHeight();
if (h < defSz) h = defSz;
if (h > stepY) h = stepY;
+ // if (h > height) h = height;
return sm.createCompatibleSampleModel(w, h);
}
}
1.4 +5 -2
xml-batik/sources/org/apache/batik/util/ParsedURLDefaultProtocolHandler.java
Index: ParsedURLDefaultProtocolHandler.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/util/ParsedURLDefaultProtocolHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ParsedURLDefaultProtocolHandler.java 2001/09/26 14:49:58 1.3
+++ ParsedURLDefaultProtocolHandler.java 2001/09/27 11:33:20 1.4
@@ -206,10 +206,13 @@
baseURL.getPath() + urlStr);
String path = baseURL.getPath();
- if (path == null) path = "/";
+ // No path? well we will treat this as being relative to it's self.
+ if (path == null) path = "";
idx = path.lastIndexOf('/');
if (idx == -1)
- path = "/";
+ // baseURL is just a filename (in current dir) so use current dir
+ // as base of new URL.
+ path = "";
else
path = path.substring(0,idx+1);
1.4 +13 -1 xml-batik/test-resources/org/apache/batik/util/regParsedURL.xml
Index: regParsedURL.xml
===================================================================
RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/util/regParsedURL.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- regParsedURL.xml 2001/09/26 14:49:58 1.3
+++ regParsedURL.xml 2001/09/27 11:33:20 1.4
@@ -8,7 +8,7 @@
<!-- ====================================================================== -->
<!-- @author [EMAIL PROTECTED] -->
-<!-- @version $Id: regParsedURL.xml,v 1.3 2001/09/26 14:49:58 deweese Exp $ -->
+<!-- @version $Id: regParsedURL.xml,v 1.4 2001/09/27 11:33:20 deweese Exp $ -->
<!-- ====================================================================== -->
<testSuite name="Parsed URL test Suite">
@@ -98,5 +98,17 @@
<arg class="java.lang.String" value="http://xml.apache.org/batik/" />
<arg class="java.lang.String" value="/fop/" />
<arg class="java.lang.String" value="http://xml.apache.org/fop/" />
+ </test>
+ <test class="org.apache.batik.util.ParsedURLTest">
+ <!-- Test relative with absolute path to item -->
+ <arg class="java.lang.String" value="file:helloWorld.svg" />
+ <arg class="java.lang.String" value="file:test.svg#Foo" />
+ <arg class="java.lang.String" value="file:test.svg#Foo" />
+ </test>
+ <test class="org.apache.batik.util.ParsedURLTest">
+ <!-- Test relative with absolute path to item -->
+ <arg class="java.lang.String" value="file:" />
+ <arg class="java.lang.String" value="file:junk.svg#Bar" />
+ <arg class="java.lang.String" value="file:junk.svg#Bar" />
</test>
</testSuite>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]