One thing to check with "custom" buffered image object is that if the
format you were trying to construct was one of the common formats that
has a constant associated with it then you should call getType() and
verify that it was recognized as that type. If it wasn't recognized,
then unpack
Hi, I was wondering if someone at Sun could let
us know if the horrendous performance of methods
like GeneralPath.intersects(), apparently due to
a "fix" put into the albert package between beta4
and rc1, has been fixed in the maintenance release?
You should be pleasantly surprised by the
Does this mean that the Albert package no longer
Correct. The Albert package is no longer there at all.
(Though a different storage format is still used for Area in order
to speed up doing the geometry calculations. The new format more
closely matches the Shape/PathIterator requirements,
Is there any way to control the palette used by a BufferedImage?
There is a constructor that takes an IndexColorModel as an argument.
If you need a boilerplate for creating an IndexColorModel with a
6x6x6 color cube, then this code from the BufferedImage class will
work:
// Create a
However, despite what I said in the original post what I actually
need to do is process an Image rather than a BufferedImage.
Create the BufferedImage and then use:
Graphics2D g2d = bufimg.createGraphics();
// After making sure that gifImage is fully loaded...
There are only 2 public final versions of the JDK. They are 1.2 FCS (I
believe it is tagged as build "V" in fullversion) and 1.2.1. 1.2.1 contains
only a security bug fix and is otherwise identical to 1.2 FCS. Both versions
have *exactly* the same Area code and that code flattens all curves.
Transforms on Area objects are problematic in the 1.2 and 1.2.1 releases.
Try using a GeneralPath instead, or use createTransformedArea to create
a new area in the new position rather than repositioning the old Area
object.
...jim
Hi Ron,
Still, from your feedback AA text without expansion should have been
possible for Java2D and Swing (like Microsoft TT). If Java2D was going to
alter text length, the Swing team should have been prepared a long time ago.
One difference that you aren't taking into account with this
Hi Jean-Marc,
I would like to know if the Java 2D API takes advantage of the graphic card
in my computer. If I have to render an image will it be faster with a good
graphic card
The current implementation of the API primarily uses DirectDraw to talk
to the video memory of the display card
I noticed that on X platforms, you use software rendering
loops for ALL cases of drawImage.
There is actually one case of X11 use for transparent GIFs since it is
easier to send over a clip for the image than to do a read/modify/write.
On Windows, all drawImage calls use software loops
Why cant you use the same approach
in JDK 1.2 for NON-Graphics2D versions of drawImage. The current
approach (software rendering) leads to horrible performance for
existing 1.1 applications on REMOTE displays. JDK 1.1 was fast
because the XPixmap held on the X-Server avoided transfer of
the
Hi Josh,
We currently don't have very good pipelines for drawing text through
a complex clip. We render those characters as outlines in all cases.
We also don't check to see if the result of scan converting an arbitrary
clip shape ends up being a rectangle in the end. If it's not a
Here is a list of bugs that represent specific performance problems with
drawImage. These bugs represent most, hopefully all, of the problems
that developers have been experiencing that used to be tracked under the
single umbrella bug 4185726. The problem with bug 4185726 was that it
became the
Hi Luc,
I have however downloaded and tried the JDK1.3beta, and none of the 2
manifestations disappear, so is it
possible that the bug is not solved or another is releated to ?
Unfortunately the JDC does not indicate the release or dates when the
bugs are fixed, but in this case the
Hi Julian,
The number of possible combinations for source and destination
images and video hardware is rather large for me to make any
definitive estimates of what you will see without further
information.
We have done nothing in 1.3 to improve the performance of copying
offscreen images to the
could anyone explain how to interpret 'pixelstride' and 'scanlinestride' ?
have looked for an explanation but its well-hidden.
These terms are defined in the class comment for PixelInterleavedSampleModel.
Pixel stride is the number of data array elements between
two samples
Hi Graeme,
I can make some guesses as to how they were designed that might give
better performance. If they store the images in VRAM, then they can
take advantage of hardware acceleration for the blits to the screen.
The downside is that the Windows APIs for doing this are very limited
Then use direct draw. You have access to everything there.
Actually we are already using DirectDraw, but we aren't using it to
create surfaces since the DD surfaces don't solve the problem.
I'll spell out all of the alternatives that we are aware of and their
problems since we seem to be going
I had figured that, as Swing components are double-buffered, that the
default image buffers used would have alpha channels.
The intention is that the images created by "createImage(w,h)" that
Swing uses for double buffering will match the display as closely as
possible - which means that the
Hi Michael,
Is there a way to access individual frames?
Not directly. That is one of the things that the Image I/O interface,
currently undergoing the JCP, will solve. For now, the best you can
do is to listen for when a new frame is available.
The ImageObserver that is passed to
If you don't call the dispose method on a Graphics object when you are
done with it, then that object may hold onto system resources until it
is garbage collected and finalized. Note that the VM makes very loose
promises on how often or soon objects will be GC'd and any dangling
references to
Hi Gary,
The current implementation of the TexturePaint object is optimized for
ByteComponent and IntegerComponent images such as:
TYPE_INT_XRGB
TYPE_INT_ARGB
TYPE_BYTE_INDEXED
You should notice a drastic improvement in speed if you use one of those
formats for your
Hi Darren,
(Even though you found a more direct way of solving your problem, I
wanted to respond to some of the points and questions made in this
thread...)
first, the application hangs at the DOS prompt and never completes
although the final println _does_ happen.
Whenever you use the AWT
I switch antialiasing on, then fills with same color two really small
polygons side by side. Then somehow there is
small lines , that are following by edges of polygons, and these lines has
color a bit brighter than fill color of both polygons (i.e if i fill it with
black, lines will be
What I'd like to see is that the black pixels of the watermark image are
treated as "clear" so that shapes drawn there are not obscured at all.
You need to give them 0 alpha somehow. If the watermark was something
you drew yourself then you can start with a blank INT_ARGB image and just
not
Hi Abel,
If you read the comment for the MemoryImageSource constructor that you are
using and the corresponding ColorModel.getRGBdefault() method which is
where it states that it gets the ColorModel from, you should see that
the format of pixels in an image of that format is a single integer
per
I am trying to display video from a file.
My code is structured like...
while (true) {
getHeader()
doLotsOfMath();
frameNumber++;
update(getGraphics());
}
What have you done to deal with either of these two issues:
- throttling your updates
- making sure you
Hi Bill,
Why should you write
g = getGraphics()
each time you want to update it?
It's the most foolproof way.
Why shouldn't you fix g at some early point in the component's
life?
You can, but there are a number of circumstances in which a Graphics
can become invalid and then you are
Don't think this'll fix your problem, but my understanding of AWT is that
you should be calling the repaint() method, not the update() method.
This is definately the recommended course of action and the safest bet
generally. Be careful not to make assumptions about when your update
method
Hi Sergei,
version java2d, which would have native core?
What do you mean by a "native core" to 2D? The reference implementation
of the 2D API has always been a blend of both native and Java code, each
being used where it seems to work best...
...jim
My application needs to draw a variety of arbitrary shapes using
different pen styles.
I think the problem you are running into is that our implementation
currently only has two modes:
Draw thin undashed lines
Draw lines using full path widening/dashing geometry calculation
Hi Peter,
If you use or distribute GIF encoder code, you may get a call from Unisys
attorneys and a demand for licensing and payment, even if you wrote the
software yourself and are only using it for non-commercial purposes or
giving away the software free.
Even if the algorithm doesn't use
Hi Ted,
I think others have shown how you can easily achieve the effect you want
by using different SampleModels and DataBuffers with offsets defined and
that is the best way to do this, but I wanted to address a philosophical
issue that you raised in the way that you used subclassing here.
To
Hi Ted,
The typical way that I do this kind of "transforming about a point
other than the origin" is:
imgx = imgw/2;
imgy = imgh/2;
translate(imgx, imgy);
scale(scalex, scaley);
translate(-imgx, -imgy);
That lets the transform object do the calculations
What is actually used to represent an "unsigned short" in the DataBuffer?
What is the upper limit gray scale value?
The data values are stored in an array of shorts and are "interpretted"
as unsigned. This is the same way that we deal with byte array data
for ByteIndexed images. When you
Hi Jesse,
A problem that we have is when you zoom in or out to extreme distances
Graphics2D eventually chokes and wont draw anything. And this is
understandable since the numbers are running out of resolution at these
large scaling.
What is probably happening is that our rendering code is
An easy way to determine the rotation effects (or other effects) of
a given affine transformation is to apply it to unit vectors and
see what happens to them. Note that using only one unit vector and
attempting to draw too many conclusions about the result can lead to
mistaken conclusions, but
Should repeated antialiased renderings render pixels exactly
the same on each pass with a rule like AlphaComposite.Src (or
AlphaComposite.SrcOver on an onscreen buffer)?
Each AA operation will individually take each partially covered pixel,
compute the value that would be stored there if the
Hi Eddie,
The typical way to merge an alpha channel into another image is to use
the AlphaComposite.DstIn mode. This takes the destination color and
multiplies it by the source alpha. Wherever the source was transparent
the destination becomes transparent. Wherever the source was opaque the
This message will serve a couple of purposes. First the 2D team is
now back in offices and reading their email (and this list) again
after having moved offices to a new campus. Second, the beta 2 release
of JDK 1.4 was published just before we moved and we did not get a chance
to mention a
Handling ordering of operations with affine transforms is always one
of the trickiest parts of mastering 2D transformations. A while back
someone posted a pointer to this tutorial which both teaches some
fundamental properties of affine transformations and also has a few
applets that let you
I would like to echo Ron's request to concentrate on rigid backward
compatibility before adding new features. Like Ron we've been bitten by
changes in behavior between 1.2 and 1.3/1.4 which is costing us inordinate
amounts of time simply to stand still, i.e. to keep our application doing
the
Hi Damon,
Have you tried your application on 1.4 beta 3 yet? I believe that beta2
was missing support for the 25-bit format we use for transparent images in
most Graphics Configurations. That should help with your transparent
performance numbers quite a lot.
1.4 beta 3 also has much better
You can now download early access versions of 1.4 beta 3 from the Java
Developer's Connection:
http://java.sun.com/j2se/1.4/
Some interesting changes in this release include:
- performance improvements to scaling and compositing VRAM images
(including VolatileImage,
D'oh!
I knew I'd forget an important feature. Try running your application
with either:
-Dsun.java2d.trace=count
or use:
-Dsun.java2d.trace=help
for more information on this feature...
...jim
--On Wednesday, November 14, 2001 12:40:32 -0600 Ernest Hill [EMAIL PROTECTED]
wrote:
i tried it. it didn't seem to do anything.
regards,
ernest
At 02:40 PM 11/1/2001 -0800, Jim Graham wrote:
D'oh!
I knew I'd forget an important feature. Try running your application
with either
Hi Jonathan,
If you can't use Java 2 APIs (introduced in version 1.2) then there are
going to be performance losses with having to deal with the ImageConsumer
and ImageProducer system, but there's not anything you can do about that.
(We created BufferedImages in 1.2 to facilitate the kinds of
is there any workaround for making an alpha enabled color in java 1.1?
1.1 supported alpha values for colors in images, but not for the Color
object. It supported only the SrcOver mode of rendering images and
the reference implementations did not actually blend the colors, but
instead used a
Hi John,
The ANTIALIAS hints only affect drawing and filling shapes and text.
The hints that affect image rendering are the INTERPOLATION hints, but
they only affect the rendering when you are scaling the image (i.e. the
destination pixels don't match the source pixels 1:1...)
Hi Ted,
The answer is that you should restore the origAtx and not set an identity.
In many cases, on the screen, the transform that appeared in the Graphics
object that your Swing component was handed was Identity anyway. In earlier
implementations, they would draw nested components by using
Hi Aant,
We would need to see some code here to understand what you are saying.
The description is not precise enough.
Can you write a small (less than 50 lines) test case for this?
...jim
--On Thursday, March 28, 2002 16:02:37 +0100 aant [EMAIL PROTECTED]
Hi Aant,
This test case appears to demonstrate an idiosyncrasy of the way that we
store the data internally in an Area object. Both paths represent their
input polygons accurately - explicitly drawing a line back to the starting
point before a closepath is superfluous but not incorrect. Thus
Hi Aant,
One more thing. You mentioned that the Area's iteration had the
direction in reverse. The Area has digested the geometry and
simplified it so there is no guarantee that the ordering or the
number of subpaths or any aspect of the original geometry iteration
will be preserved in the
Hi Jerome,
You sent out this question right before JavaOne so I don't think anyone
got back to you.
I was wondering what is the best way to draw fixed size images between :
* drawImage(Image image, AffineTransform at, ImageObserver o)
* drawImage(Image image, int x, int y, ...) ?
I
Hi Nicolas,
I use your excellent class Area to merge polygon and extract the outline.
So, i have lots of cases where the result is a mix of plain polygons and holes.
But, the pathiterator doesnt tell when you iterate the subpaths if its a
plain polygon or a hole
Is there a field or an
Hi Todd,
By any chance are you using a BYTE_INDEXED destination to do the
blending? Often the data gets corrupted when we calculate a color
and then try to put that color back into an image with a small
fixed palette - we try to do some dithering and it can often introduce
errors where you
Hi Jan,
The short answer to the fillRect vs. drawLine question is for the
developers to always use the simplest API call that matches their
needs.
Rectangles are, well, a box of pixels (unless you are transformed in
which case it might be a tilted box of pixels).
Lines are complicated little
Hi Jan,
Does anybody know any resources where these systems are explained
(preferably with some conversion algorithms)?
Foley and Van Dam's Computer Graphics: Principles and Practice
describes a lot of the terms and protocols we use in the 2D API.
In particular, they define the HSV (aka HSB)
Square root will give you a non-linear translation into the destination
space. Also, adding 32768 will mean that 32767 or 0x7fff will map to
full intensity, 0 will map to half intensity, and -32768 will map to
blackness - is that the mapping you want? If you want to convert a
signed short
Hi Rhett,
In 1.2 we tried to deal with stroke/fill pixelization and alignment
issues by specifying a user-space offest for strokes so that the
typical behavior on a screen using standard bresenham algorithms for
drawing lines and polygon borders would be closely approximated in a
theoretical
Hi Ramón,
Use the Area class to either subtract or intersect the original shape
with/from the outline created with BasicStroke.createStrokedShape().
Intersection will produce the inside part, subtract will produce the
outside part.
As far as non-convex polygons, you will probably find lots of
Ted and Ramón,
Using the Area and BasicStroke classes, you can achieve any of the effects
that you two have been asking for. Assuming a source Shape object S, and
wanting to outsideline, insideline, expand or contract it by N pixels...
First get all your variables set up:
BasicStroke
In normal usage the private paintContext field of the Color object should
never be used. The graphics code treats colors specially and simply fills
the rectangles with the appropriate color rather than invoking its
PaintContext object.
But, if anyone ever calls the createContext() method of a
, it would seem that I could use Strokes and Areas to expand and
contract by different amounts in x and y.
Thank you,
Ted Hill
- Original Message -
From: Jim Graham [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, November 26, 2002 4:37 PM
Subject: [JAVA2D] Path fun (in Re
Hi Sven,
Component.createImage(width, height) does not take a snapshot of the
window as you seem to expect, it simply creates a brand new blank
image (cleared to the background color of the component) that is
compatible with the component so that you can use it as an offscreen
buffer for double
Hi Eric,
BufferedImage questions are always welcome on the Java2D list.
You might have better luck getting the ColorModel, asking it to
create you a compatible raster, and then using the BufferedImage
constructor that takes a ColorModel and a Raster.
But, if the original image was a GIF then
Hi Joe,
--Joe Bowbeer wrote:
Is any progress being made with bug 4151279?
http://developer.java.sun.com/developer/bugParade/bugs/4151279.html
Is this scheduled to be fixed in Tiger 1.5?
Is this the right place to ask about this?
This is the best place I can think of to ask this question.
This
My current redraw strategy is to iterate the linkedlist in the paint
method and pass the getBounds method of each element into the hitClip
method of the graphics object to determine if I need to draw it.
Try eliminating the hitClip call and see how things go. That method
is not meant to be used
Hi Ted,
We don't provide such a facility in the J2SE APIs, but I would
think that someone would have created an area calculation module
somewhere.
One problem is that you have to be careful how you state the
question because the answer depends on whether you are looking
for:
- The discrete
The AffineTransformOp can do affine transforms of images for you
and the filter() method that does the work takes an optional
second parameter that is the destination BufferedImage to store
the data into. Try using that with your own temporary image
to store the transformed results into. If you
Rectangle2D bar = ...;
g2.setPaint(gradientPaint);
g2.fill(bar);
g2.setColor(Color.black);
g2.draw(bar);
The issue here is that we could use completely different implementations
to handle gradients vs. solid colors and while each of those pipelines
enforces consistency between its own fills and
Hi Michael,
Yes, I guess you do apply *a* transform to *a* graphics object before
you get to the code that draws the text, but it's the wrong graphics
object that you apply the scale to.
You are scaling the graphics object that is passed to your paint
method - the one that you subsequently hand
So if I wanted the fill and draw of the same shape to align properly,
I should stick to one type of Paint?
Yes, and as you discovered through your test case, that may not even
be enough because some of our pipelines still don't have agreement
between their fills and draws.
Fill/Draw status
Does anyone know under what circumstances
AffineTransform.inverseTransform() is
Mathematically, this occurs when the matrix has a zero determinant.
Visually this happens when the transform specifies a transform that
maps all coordinates in user space to a line or a point in device
space.
(To
An example of where something like this is likely to occur in
practice is if you animate a figure to flip over by scaling it
with values that vary from 1.0 (normal rendering) down to
-1.0 (flipped rendering). As you iterate through the scale
values from 1.0 to -1.0 you can at some point in the
sorry, i don't understand what i must do that my application work. can
you show it to me in my example? has it woked for you?
greetings michael
All of the tips and tricks involved in doing a proper zoomable GUI
make the subject far too involved for a forum like this.
You really should look into
Hi Alfred,
I would need to see a small test case that demonstrates this (which
you can send just to me to not bother the list), because...
Everything works great until I try to concatenate a flip operation to
the AffineTranform object. Assuming I want to flip the image
LEFT_RIGHT
An image of TYPE_INT_ARGB uses a PackedColorModel with a Packed
Raster with a TYPE_INT DataBuffer. It is incompatible with the
Byte-based ComponentColorModel (and SampleModel) that you are
creating. I'm not sure how these two pieces of data would
interact in this case...
First it looks to me like green affects red, not blue. Given
that, then this looks like a byte endian issue. For integer
data types:
XRGB bigendian
BGRX smallendian
G and R would get confused and B would get confused with an unused
channel. We're tracking down a few byte endian
int l1x = x2 - x1;
int l1y = y2 - y1;
int l2x = x3 - x1;
int l2y = y3 - y1;
float tan1 = (float)l1y/(float)l1x;
float tan2 = (float)l2y/(float)l2x;
double ang1 = Math.atan(tan1);
double ang2 = Math.atan(tan2);
This will fail because Math.atan(tangent) does not know which
quadrant the line is in
When I iterate over the path iterator, I find many DUPLICATE
CONSECUTIVE POINTS.
Is there some way to get a PathIterator from an Area that will not
have duplicate consecutive points?
One question is whether or not you have discovered any practical
problems from these extra points or is it just
The repaint model is more targetted at applications which have
a concept of the current state that needs to be displayed which
tends to be updated mostly atomically. Repainting just a small
rectangle is meant more as an optimization to indicate which
parts of the screen have new data that needs
Hi Lincoln,
One of the problems you may run into is that we only have routines that
handle image formats that we recognize, whether accelerated or not. Thus,
if you create some kind of custom 32-bit format you would end up causing us
to invoke our general custom-format routines which use all of
Before loading: Mem Usage: 18700K -- VM Size: 16856K
After loading: Mem Usage: 28656K -- VM Size: 34304K
All that it does
is read the image in as a ImageIcon, convert the ImageIcon's getImage
result to a BufferedImage, store a reference to the BufferedImage for
later use in manipulations, and
--On 09/03/04 09:52:59 PM -0400 Gregory Pierce wrote:
Okay here is the scenario (and I'm hoping there is something in the
API that permits this because at this point I haven't found anything).
What I have are two RoundRectangle2Ds that have an alpha of 50
percent. I want to draw a line connecting
2) Do a CAG adding all of the rounded rectangles together into one
gigantic clipping shape. This is probably Er definitely the
easiest to code since I'm already iterating through the RR2Ds anyways
and can make this master shape. I'll probably do that one before I go
to sleep. Since I'm at a
2) Do a CAG adding all of the rounded rectangles together into one
gigantic clipping shape. This is probably Er definitely the
BTW, Area is great for doing lots of complex CAG operations on
arbitrary geometry, but for a specific subset of its capabilities:
- All geometry is known to
g2d.setClip( clipArea );
// draw all of the links
Iterator linkIterator = links.iterator();
while (linkIterator.hasNext())
{
WidgetIF widget = (WidgetIF) linkIterator.next();
widget.draw( g2d );
}
One minor optimization here.
What I did was compare renderingMethod0() which is the rendering of
all of the shapes with no form of clipping with 1000 RR2Ds with a
translucent color and it was taking about 1200-1300 ms. I considered
this slow. I swapped the shape to a regular rectangle to make sure it
wasn't the curve that
The reason there is no method for drawing them is that they don't
describe any geometry to draw. Also, the question of what exactly the
user wants us to draw gets a little fuzzy as we introduce antialiasing,
scaling, and printing on high resolution printers to the mix.
If this were a pixel-based
It would be nice to have an RFE filed on this. There are a lot of
issues here, but at the very least the RFE would give us a place to
increase awareness of the issues, even if we don't find an acceptable
solution to put into our APIs.
There are two parts to this - whether to have Point2D
It's hard to know what is going on here without knowing what the transform
is at the time of the drawPolyline call since the line width is relative to
the current transform. Do you have an isolated standalone test case for
this?
...jim
--On Thursday, October
Hi Nancy,
The issue you encountered here is related to bug report #4114921 which
asks for a way to scale coordinates independently of things like the
line width. This isn't really a bug since the current system scales
both together by design, but we could potentially add new
capabilities to make
My problem: if I use a color that is not contained in the palette, or if I
call drawString() with font antialiasing , which will produce pixels with
a color not contained in the palette. How is are these new colors mapped
to the palette color?
There is no specification to define how this mapping
Hi David,
The short guess answer for your problem is that I imagine that doing a
getColorModel() on one of your screen components will help you make this
determination, but the fact that you have to check this screen depth
concerns me for the following reasons:
Robot always returns a 24-bit image
It's hard to diagnose this problem without a complete example to run, but I
can make some guesses and recommendations.
Which release are you running this on? The reason I ask is that there is
an image scaling regression in JDK 1.5.0 that causes us to use a slightly
slower rendering path when the
We don't support soft edged clipping currently since our antialiasing
approach is currently done on a per-operation basis, rather than a global
technique like Full Screen Antialiasing. This means that repeated AA
operations over the same area will accumulate the coverages on the edges
and if you
Another way of managing this is to keep various decomposed values around
and then compose the matrix only at render time.
For example, if you want to independently control scaling and rotation and
set limits on them:
On mouse motion:
if (scaling motion) {
public void update(Graphics g) {
// Background: map field
g.drawImage(backbuffer, 0, 0, this);
// Foreground: headsup display
headsup.draw(g);
}
public void paint(Graphics g) {
update(g);
}
Now the
From the Component javadocs:
The update method of Component calls this component's paint
method to redraw this component.
and:
Subclasses of Component that override this method should
either call super.update(g), or call paint(g) directly
from their update
1 - 100 of 199 matches
Mail list logo