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 think the best philosophy is that the API that provides the fewest
bells and whistles will typically be the API that executes fastest.
But due to optimizations in our code to classify complex operations
in terms of simpler equivalents, all you save in most cases is a
couple of if statements and maybe a calculation or two, so it is
probably far more important to use the API that fits in better with
the overall programming model in place at the time.

In the case of image blits it is always faster to just copy the
pixels 1 for 1 and the location of the destination is largely
irrelevant (since one just adjusts the starting memory location of
where you do the stores once for the whole operation).  With a
transform you have to watch the way that you step through memory
and do some minor calculations per pixel.

With the right setup logic, it might be possible to detect that the
AffineTransform represents a 1 for 1 mapping of pixels, but that
requires a bunch of tests just to get you back to knowing what the
other API implicitly knew (i.e. that the copy was a simple 1 for 1
transfer of memory).  It's not like this is a huge amount of
calculations - if you have a transform that may or may not be
1 for 1, just use it and we will figure it out, but if you know
ahead of time that the copy is 1 for 1, then don't obscure that
knowledge by introducing a transform when one wasn't needed in
the first place.

Other common pitfalls where users can make us do more work than is
needed:

        - If you need to draw a 1-coordinate tall wide "thing"
          you could use drawLine(x1, y, x2, y) and we would
          figure out "hey, that's really just a rectangle" and
          do the optimal thing, but if you just call
          fillRect(x1, y, w, 1) instead you save us the work
          of having to figure it out.

        - If you need to draw a rectangle and you know you want
          the corners to be square, don't use drawRoundRect(...)
          with 0 radiuses just to make us figure it out (I've
          seen a major application use roundrects to draw vertical
          lines - where did they get that from?)

In the end, I think it's OK to use whatever makes your code clearer
and not worry too much about the optimizations.  Most of the above
cases can be and are detected and optimized within our code very
easily.  But if both calls make equal conceptual sense, use the
one that is more obviously a simpler operation.

                                ...jim

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to