Odds and Ends
January 31, 2007 7 Comments
- Today I finally grokked how the Java2D Image API could be implemented. Basically the biggest problem (to me) always has been the BufferedImage constructor, which allowed BIes of all kinds to be created. What about image formats that are not supported by the native rendering engine? How are we supposed to render into that? Well, the solution would be to have 2 buffers like:
RE --> nBuffer < -- > jBuffer <-- Java2D API
where the native buffer has a format that is supported by the RE and the java buffer (I call it so, it is not required to have that in Java, could be any memory area thanks to the fine DataBuffer abstraction) holds the data in the requested ColorModel/SampleModel. Well, the obvious problem here is when to sync the data and what to sync. Fortunately (that’s what I discovered today), BufferedImage implements WritableRenderedImage, which provides a couple of methods to grab the buffer for writing and release it. This is find, as it provides very nice syncpoints.One remaining obstactle is when the RE does not support a super-format (I call it like this. For instance, ARGB8888 is a superformat of RGB565) of the requested format. For instance, when the RE only supports ARGB1888 (which is the case for one system I am currently implementing this API for) but the app requires ARGB8888. How is the RE supposed to render into that. The API is a little weak in this respect as it doesn’t allow to reject the request. The only real solution would be to have a Java only renderer do the rendering, but this is very ugly for several reasons: The rendering would be noticably different and noticably slow (well the latter isn’t that bad. what do you expect when you request something not supported by the HW). Any comments and ideas on this are very appreciated.All in all, nowadays I feel about Java2D almost like I feel about NIO: Quite confusing for the start, but once things are sorted out and have found their place in the mind-picture, it seems relativly well thought out and nice. Only problem with Java2D probably is that it carries quite some cruft from the <= AWT1.1 days, which makes it even more confusing.
- Today a collegue pointed me to this, makes my mind boggle. I copy it into here as a riddle to solve. So please make up your mind and find out what this is supposed to do. And yes, this is legal C code compilable by GCC. 🙂
switch ( count % 8 ) /* count > 0 assumed */ { case 0: do { *to++ = *from++; case 7: *to++ = *from++; case 6: *to++ = *from++; case 5: *to++ = *from++; case 4: *to++ = *from++; case 3: *to++ = *from++; case 2: *to++ = *from++; case 1: *to++ = *from++; } while (( count -= 8 ) > 0); }
- Found an interesting JSR: Application Framework for Swing Gotta have a deeper look at it ASAP.