Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » BUG: Graphics.drawImage and Graphics.drawPoint w/ Graphics.setClip(Path path)
BUG: Graphics.drawImage and Graphics.drawPoint w/ Graphics.setClip(Path path) [message #190948] Sun, 07 August 2005 19:32 Go to next message
Josh Reed is currently offline Josh ReedFriend
Messages: 38
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------050504000002080701060006
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

I believe I have found a bug within the Graphics class. The bug may
actually be in SWT, but since I'm working through the Draw2D Graphics
class, I thought this would be the best place to start. If need be, I
can open a bug report against SWT.

Problem:

I have a figure that needs a texture or pattern drawn on it. The
texture is defined in a GIF file and is much smaller than the figure.
To accomodate this, the image is repeatedly tiled over the figure. The
figure is irregularly shaped; defined by a PointList. I have found a
way to accomplish the task on both Linux and Windows, but it requires
two separate approaches due to inconsistencies between implementations
on each platform.

I've attached the relevant code from my Figure subclass.

The crux of the problem is that Graphics.drawImage and
Graphics.drawPoint seem to perform inconsistently on different platforms
when using Graphics.setClip(Path path).

For Windows, Graphics.drawImage honors the path such that sections of
the tiled image that are outside the path are not drawn. However,
Graphics.drawPoint doesn't seem to honor the path clip. So when you
iterate over the clip, the pixels are drawn outside the clip set. There
is a secondary problem with the Image and pulling pixels out of it, but
this is not a problem with GEF or Draw2d.

For Linux, Graphics.drawImage does not honor the path clip. The image
is tiled over the entire rectangular bounds of the image, even outside
of the path clip. Graphics.drawPoint honors the path clip so that the
pattern only appears inside the path clip.

Am I approaching the tiled image problem incorrectly, or is the
inconsistent behavior indeed a bug?

A cursory glance at GEF's bugzilla revealed this bug:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=76571
which appears to be related. It talks about the setClip(Path path) but
not the drawing aspects.

I'd appreciate any help. If it needs to be sent on over to SWT, let me
know and I'll do that.


Thanks,
Josh Reed



--------------050504000002080701060006
Content-Type: text/x-java;
name="snippet.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="snippet.java"

protected void paintFigure(Graphics g) {
PointList points = getOutline();
g.setForegroundColor(ColorConstants.black);
g.setBackgroundColor(fillColor);

g.fillPolygon(points);
g.drawPolygon(points);

fillPolygon(g, points, fillPattern);
}

private void fillPolygon(Graphics g, PointList points, Image img) {
g.setForegroundColor(ColorConstants.black);
ImageData imgData = img.getImageData();

// get the bounds of the clip so we don't waste time
// painting the whole bounds, even parts that aren't
// visible
Rectangle r = g.getClip(new Rectangle());

// The path should be built properly because I can get it to work
// with one of the two approaches below, depending on platform.
Path p = pointListToPath(points);
g.setClip(p);

// Tile the image over the whole bounds
// Works on Windows
// Fails on Linux
// -- The pattern is not clipped to the path. It fills the whole
// rectangular region. During scrolling, the pattern moves down
// so that there are uncovered regions near the top of the diagram.
for (int y = r.y; y < r.y + r.height; y += imgData.height) {
for (int x = r.x; x < r.x + r.width; x += imgData.width) {
g.drawImage(fillPattern, new Point(x, y));
}
}

// Loop through the image data and draw out all the black pixels
// Works on Linux
// Fails on Windows
// -- The region is not clipped to the path. The whole rectangular
// region is filled with black. No non-black pixels are recognized.
int pixel = -1;
for (int y = r.y; y < r.y + r.height; y++) {
for (int x = r.x; x < r.x + r.width; x++) {
pixel = imgData.getPixel((x-r.x)%imgData.width, (y-r.y)%imgData.height);
// this is a simple hack
if (pixel == 0) {
g.drawPoint(x, y);
}
}
}
}

private Path pointListToPath(PointList points) {
Path path = new Path(null);

Point start = points.getFirstPoint();
path.moveTo(start.x, start.y);
for (int i = 1; i < points.size(); i++) {
Point p = points.getPoint(i);
path.lineTo(p.x, p.y);
}
if (!points.getLastPoint().equals(start)) {
path.lineTo(start.x, start.y);
}
path.close();

return path;
}

--------------050504000002080701060006--
Re: Graphics.drawImage and Graphics.drawPoint w/ Graphics.setClip(Path path) [message #191092 is a reply to message #190948] Mon, 08 August 2005 19:38 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Please complete the snippet so that it is runnable and contains the minimum
needed to show the problem and attach it to a bugzilla. We will investigate
for 3.1.1 or reroute to SWT.

"Josh Reed" <jareed@iastate.edu> wrote in message
news:dd5nl9$ifb$1@news.eclipse.org...
>I believe I have found a bug within the Graphics class. The bug may
> actually be in SWT, but since I'm working through the Draw2D Graphics
> class, I thought this would be the best place to start. If need be, I
> can open a bug report against SWT.
>
> Problem:
>
> I have a figure that needs a texture or pattern drawn on it. The
> texture is defined in a GIF file and is much smaller than the figure.
> To accomodate this, the image is repeatedly tiled over the figure. The
> figure is irregularly shaped; defined by a PointList. I have found a
> way to accomplish the task on both Linux and Windows, but it requires
> two separate approaches due to inconsistencies between implementations
> on each platform.
>
> I've attached the relevant code from my Figure subclass.
>
> The crux of the problem is that Graphics.drawImage and
> Graphics.drawPoint seem to perform inconsistently on different platforms
> when using Graphics.setClip(Path path).
>
> For Windows, Graphics.drawImage honors the path such that sections of
> the tiled image that are outside the path are not drawn. However,
> Graphics.drawPoint doesn't seem to honor the path clip. So when you
> iterate over the clip, the pixels are drawn outside the clip set. There
> is a secondary problem with the Image and pulling pixels out of it, but
> this is not a problem with GEF or Draw2d.
>
> For Linux, Graphics.drawImage does not honor the path clip. The image
> is tiled over the entire rectangular bounds of the image, even outside
> of the path clip. Graphics.drawPoint honors the path clip so that the
> pattern only appears inside the path clip.
>
> Am I approaching the tiled image problem incorrectly, or is the
> inconsistent behavior indeed a bug?
>
> A cursory glance at GEF's bugzilla revealed this bug:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=76571
> which appears to be related. It talks about the setClip(Path path) but
> not the drawing aspects.
>
> I'd appreciate any help. If it needs to be sent on over to SWT, let me
> know and I'll do that.
>
>
> Thanks,
> Josh Reed
>
>
>


------------------------------------------------------------ --------------------


> protected void paintFigure(Graphics g) {
> PointList points = getOutline();
> g.setForegroundColor(ColorConstants.black);
> g.setBackgroundColor(fillColor);
>
> g.fillPolygon(points);
> g.drawPolygon(points);
>
> fillPolygon(g, points, fillPattern);
> }
>
> private void fillPolygon(Graphics g, PointList points, Image img) {
> g.setForegroundColor(ColorConstants.black);
> ImageData imgData = img.getImageData();
>
> // get the bounds of the clip so we don't waste time
> // painting the whole bounds, even parts that aren't
> // visible
> Rectangle r = g.getClip(new Rectangle());
>
> // The path should be built properly because I can get it to work
> // with one of the two approaches below, depending on platform.
> Path p = pointListToPath(points);
> g.setClip(p);
>
> // Tile the image over the whole bounds
> // Works on Windows
> // Fails on Linux
> // -- The pattern is not clipped to the path. It fills the whole
> // rectangular region. During scrolling, the pattern moves down
> // so that there are uncovered regions near the top of the diagram.
> for (int y = r.y; y < r.y + r.height; y += imgData.height) {
> for (int x = r.x; x < r.x + r.width; x += imgData.width) {
> g.drawImage(fillPattern, new Point(x, y));
> }
> }
>
> // Loop through the image data and draw out all the black pixels
> // Works on Linux
> // Fails on Windows
> // -- The region is not clipped to the path. The whole rectangular
> // region is filled with black. No non-black pixels are recognized.
> int pixel = -1;
> for (int y = r.y; y < r.y + r.height; y++) {
> for (int x = r.x; x < r.x + r.width; x++) {
> pixel = imgData.getPixel((x-r.x)%imgData.width,
> (y-r.y)%imgData.height);
> // this is a simple hack
> if (pixel == 0) {
> g.drawPoint(x, y);
> }
> }
> }
> }
>
> private Path pointListToPath(PointList points) {
> Path path = new Path(null);
>
> Point start = points.getFirstPoint();
> path.moveTo(start.x, start.y);
> for (int i = 1; i < points.size(); i++) {
> Point p = points.getPoint(i);
> path.lineTo(p.x, p.y);
> }
> if (!points.getLastPoint().equals(start)) {
> path.lineTo(start.x, start.y);
> }
> path.close();
>
> return path;
> }
>
Previous Topic:TextFlow and Text Alignment
Next Topic:Non-rectangular clipping
Goto Forum:
  


Current Time: Thu Apr 25 23:54:33 GMT 2024

Powered by FUDForum. Page generated in 0.03762 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top