Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Java2D: not possible to set 32bpp ints?

Reply
Thread Tools

Java2D: not possible to set 32bpp ints?

 
 
Timo Nentwig
Guest
Posts: n/a
 
      04-29-2004
Hi!

It seems that it's not possible to use 32bpp ARGB encoded integers in
Java2D, at least I didn't find such a method in the WriteableRaster API.

Is there same different way to do so?

Timo
 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      04-30-2004
Timo Nentwig wrote:
> It seems that it's not possible to use 32bpp ARGB encoded integers in
> Java2D, at least I didn't find such a method in the WriteableRaster API.


This might do (I didn't try):

Using integers:

Raster.createPackedRaster(
DataBuffer.TYPE_INT, // data type
w, h, // image width, height
4, // bands
8, // bits per band
null); // use default (0,0) location
Using bytes:

Raster.createInterleavedRaster(
DataBuffer.TYPE_BYTE, // data type
w, h, // image width, height
w * 4, // scan line stride
4, // pixel stride
new int[]{3, 2, 1, 0}, // band offset
null); // use default (0, 0) location

/Thomas
 
Reply With Quote
 
 
 
 
Timo Nentwig
Guest
Posts: n/a
 
      04-30-2004
Thomas Weidenfeller wrote:
> Timo Nentwig wrote:
>
>> It seems that it's not possible to use 32bpp ARGB encoded integers in
>> Java2D, at least I didn't find such a method in the WriteableRaster API.

>
>
> This might do (I didn't try):
>
> Using integers:
>
> Raster.createPackedRaster(
> DataBuffer.TYPE_INT, // data type
> w, h, // image width, height
> 4, // bands
> 8, // bits per band
> null); // use default (0,0) location


What I meant is that I want to encode all the channels in a single int:

int pixel = a << 24 | r << 16 | g << 8 | b;
raster.setPixel(x,y,pixel);


Java2D is incredibly slow At least 5 times slower than a old-style
MemoryImageSource solution.
 
Reply With Quote
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      04-30-2004
Timo Nentwig wrote:
> What I meant is that I want to encode all the channels in a single int:


That's why I suggested createPackedRaster. If I didn't mix up things, my
example would pack 4 bands (A, R, G, B) with 8 bits per band into
integers. Which should give you, if my math didn't fail me 4 * 8 = 32
bits per pixel, which just happen to fit nicely in one Java 32 bit integer.

/Thomas
 
Reply With Quote
 
Timo Nentwig
Guest
Posts: n/a
 
      05-01-2004
Thomas Weidenfeller wrote:
> Timo Nentwig wrote:
>
>> What I meant is that I want to encode all the channels in a single int:

>
> That's why I suggested createPackedRaster. If I didn't mix up things, my
> example would pack 4 bands (A, R, G, B) with 8 bits per band into
> integers. Which should give you, if my math didn't fail me 4 * 8 = 32
> bits per pixel, which just happen to fit nicely in one Java 32 bit integer.


And how do I set that one integer? There's no Raster.setPixel() that
accepts a single integer.
 
Reply With Quote
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      05-04-2004
Timo Nentwig wrote:
> And how do I set that one integer? There's no Raster.setPixel() that
> accepts a single integer.


If nothing else helps, drill down to the DataBuffer and insert the data
there.

/Thomas
 
Reply With Quote
 
hondacivic@whoever.com
Guest
Posts: n/a
 
      05-08-2004
Timo Nentwig <(E-Mail Removed)> wrote in message news:<c70bo0$gp03o$(E-Mail Removed)-berlin.de>...

> And how do I set that one integer? There's no Raster.setPixel() that
> accepts a single integer.


Raster is general and doesn't know directly about any specific format.
getDataBuffer() still is generic.

If you know that the pixels are stored in ints, then you can cast the
DataBuffer that comes out of Raster's getDataBuffer() to
DataBufferInt.

DataBufferInt has a getData(), that returns int[], at which point you
can access the pixels directly.

How about starting with a BufferedImage, which wraps all the
colorspace/format issues all in one package:
BufferedImage image = new BufferedImage(640, 480,
BufferedImage.TYPE_INT_ARGB);
int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()) .getData();
for (int y = 0; y < 480; y++)
for (int x = 0; x < 640; x++)
pixels[y * 640 + x] = x * y;
....
I'm not sure, but the compiler has some nifty optimization features,
where something like this may actually not be any faster:
for (int y = 0; y < 480; y++)
{
int offset = y * 640;
for (int x = 0; x < 640; x++)
pixels[offset + x] = x * y;
}

On an exciting side note, Java's bytecode to machine code translator
is efficient enough that it can compete and sometimes outperform
optimized C++ code! So raster-hacking in Java can be far more
exciting as many people with presumptions about Java are willing to
admit. Discover for yourself.

Also, Java2D is one of *THE* cleanest, if not *THE* cleanest graphics
library ever written. You get a lot of flexibility, performance,
extendability in an amazing package. By the looks of it, it's better
than GDI+, and most definitely way better than GNU land's GTK/GTK++.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
efficient data loading with Python, is that possible possible? igor.tatarinov@gmail.com Python 10 12-14-2007 04:44 PM
is it possible to possible to create an iterator from a callback interace? aninnymouse@gmail.com C Programming 4 02-21-2006 02:10 PM
XML + XSD: Is it possible to get all possible Values for an Element? Markus Java 1 11-22-2005 02:51 PM
MissingSourceFile in <controller not set>#<action not set> - No such file to load -- /config/routes.rb Seth Rasmussen Ruby 3 09-17-2005 12:13 AM
Possible to set up WinFaxPro 10 to answer faxes but not voice calls? Jimmy Dean Computer Support 1 10-13-2004 05:42 AM



Advertisments