Hi Thomas, Andrew,
Thanks for your help - I have had some success now in displaying
smooth-edged, rotated images with several of the methods described.
thomas.deweese wrote:
>
> So the image is broken into tiles, but they are aligned properly. I
> suspect that the anti-aliasing you see on Mac OS X is causing the
> tile edges to be visible even when they shouldn't be.
>
Indeed - I displayed each tile scaled up in a separate window, and it was
clear that they were anti-aliased along the top and left edges. I think
I've seen this behaviour on the Mac before. One way around it is to extend
the clip area as in the patch below:
Index:
xml-batik/sources/org/apache/batik/gvt/filter/GraphicsNodeRed8Bit.java
===================================================================
--- xml-batik/sources/org/apache/batik/gvt/filter/GraphicsNodeRed8Bit.java
(revision 471963)
+++ xml-batik/sources/org/apache/batik/gvt/filter/GraphicsNodeRed8Bit.java
(working copy)
@@ -125,6 +125,7 @@
null);
Graphics2D g = GraphicsUtil.createGraphics(offScreen, hints);
+ if (onMacOSX) g.setClip(-1, -1, wr.getWidth() + 1, wr.getHeight() +
1); // prevent anti-aliasing at edges of tiles
g.setComposite(AlphaComposite.Clear);
g.fillRect(0, 0, wr.getWidth(), wr.getHeight());
g.setComposite(AlphaComposite.SrcOver);
This stops the tile edges from showing in clip and mask operations.
Removing the "if (onMacOSX)" bit doesn't appear to have any affect in
Windows. I guess this kind of thing is also what causes lines to appear
sometimes when a dynamic document is updated on the Mac.
thomas.deweese wrote:
>
> Another method to try would be to put the image with the mask in
> a pattern and fill a rotated rect with that. You might not even need
> to mask the image in this case.
>
This works perfectly wrt shape rendering (no mask required), but on the Mac
the image is blocky - it looks like it is rendered at the size of the
pattern and then scaled up.
I wrote in my original post:
> ii) Apply a mask to the image. This looks great on Windows and Linux,
> but
> on OS X ... it looks like gradients that would smooth the edge out have
> been
> applied the wrong way around, mirrored.
This problem appears to arise when the mask is converted to a luminance
colorspace using Any2LumRed. I have attached a patch below which works for
me on Mac, Windows and Linux, all with various revisions of Java 1.5. The
source code mentions a bug in ColorConvertOp, and my patch attempts to
remove the workaround for that bug. I don't know the history though, so I
can't tell if the bug has been fixed in a subsequent Java release or if it
applies to a situation other than what I am testing.
Regards,
Steve Drake
Index:
xml-batik/sources/org/apache/batik/ext/awt/image/rendered/Any2LumRed.java
===================================================================
---
xml-batik/sources/org/apache/batik/ext/awt/image/rendered/Any2LumRed.java
(revision 471963)
+++
xml-batik/sources/org/apache/batik/ext/awt/image/rendered/Any2LumRed.java
(working copy)
@@ -86,65 +86,18 @@
} else {
WritableRaster srcWr = (WritableRaster)srcRas;
- // Divide out alpha if we have it. We need to do this since
- // the color convert may not be a linear operation which may
- // lead to out of range values.
- if (srcCM.hasAlpha())
- GraphicsUtil.coerceData(srcWr, srcCM, false);
-
BufferedImage srcBI, dstBI;
srcBI = new BufferedImage(srcCM,
srcWr.createWritableTranslatedChild(0,0),
- false,
+ srcCM.isAlphaPremultiplied(),
null);
ColorModel dstCM = getColorModel();
- if (!dstCM.hasAlpha()) {
- // No alpha ao we don't have to work around the bug
- // in the color convert op.
- dstBI = new BufferedImage
- (dstCM, wr.createWritableTranslatedChild(0,0),
- dstCM.isAlphaPremultiplied(), null);
- } else {
- // All this nonsense is to work around the fact that the
- // Color convert op doesn't properly copy the Alpha from
- // src to dst.
- PixelInterleavedSampleModel dstSM;
- dstSM = (PixelInterleavedSampleModel)wr.getSampleModel();
- SampleModel smna = new PixelInterleavedSampleModel
- (dstSM.getDataType(),
- dstSM.getWidth(), dstSM.getHeight(),
- dstSM.getPixelStride(), dstSM.getScanlineStride(),
- new int [] { 0 });
+ dstBI = new BufferedImage
+ (dstCM, wr.createWritableTranslatedChild(0,0),
+ dstCM.isAlphaPremultiplied(), null);
- WritableRaster dstWr;
- dstWr = Raster.createWritableRaster(smna,
- wr.getDataBuffer(),
- new Point(0,0));
- dstWr = dstWr.createWritableChild
- (wr.getMinX()-wr.getSampleModelTranslateX(),
- wr.getMinY()-wr.getSampleModelTranslateY(),
- wr.getWidth(), wr.getHeight(),
- 0, 0, null);
-
- ColorModel cmna = new ComponentColorModel
- (ColorSpace.getInstance(ColorSpace.CS_GRAY),
- new int [] {8}, false, false,
- Transparency.OPAQUE,
- DataBuffer.TYPE_BYTE);
-
- dstBI = new BufferedImage(cmna, dstWr, false, null);
- }
-
ColorConvertOp op = new ColorConvertOp(null);
op.filter(srcBI, dstBI);
-
- // Have to 'fix' alpha premult
- if (dstCM.hasAlpha()) {
- copyBand(srcWr, sm.getNumBands()-1,
- wr, getSampleModel().getNumBands()-1);
- if (dstCM.isAlphaPremultiplied())
- GraphicsUtil.multiplyAlpha(wr);
- }
}
return wr;
}
--
View this message in context:
http://www.nabble.com/Effect-of-shape-rendering-property-tf2586765.html#a7253364
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]