D
Dashesy
I am trying to find how I can use ComponentColorModel and
MemoryImageSource together. I would prefer not to use BufferdImage or
WritableRaster (because it requires copynig image data to a DataBuffer
again !! which is not performance wise)
Is there any solution discussed here:
http://groups.google.com/group/comp...onentcolormodel&rnum=1&hl=en#cb95b2d11a2e388f
and here:
http://groups.google.com/group/comp...onentcolormodel&rnum=4&hl=en#894e0134017ff203
and here:
http://groups.google.com/group/comp...onentcolormodel&rnum=3&hl=en#1fbb438f58c3e88e
a partial solution is here:
http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?forum=177&thread=98473&cat=10
(in one of replies)
Also my code is this:
//grab data
byte[] pixels = vic.vic32jni.convertbuffertobytearray(timage.ibuff,
(width) * (height) * 3);
byte reds = 0;
byte greens = 0;
byte blues = 0;
int[] pix = new int[ (width) * (height)];
int j = 0;
//this for loop gives an integer array that works fine with
ComponentColorModel and MemoryImageSource, but it is actually not
performance wise too
//If I can not use ComponentColorModel and MemoryImageSource, I guess
the follownig solution is better than BufferedImage
for (int i = 0; i < (width) * (height) * 3; i += 3, j++) {
reds = pixels;
greens = pixels[i + 1];
blues = pixels[i + 2];
pix[j] = 0xff * 0x1000000 + blues * 0x10000 + greens * 0x100 +
reds;
}
int bits[] = {
8, 8, 8};
//Using IndexedColorModel also works fineunless you have 16 million
colors (more than 256).
ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(
ColorSpace.CS_sRGB), bits, false, false, Transparency.OPAQUE,
DataBuffer.TYPE_BYTE);
// if I uncomment the following lines(imp#1) and use it instead of the
next MemoryImageSource (in imp#2) it works fine !
//imp#1
// img = Toolkit.getDefaultToolkit().createImage(
// new MemoryImageSource(width, height,
// pix, 0, width));
//imp#2
img = Toolkit.getDefaultToolkit().createImage(
new MemoryImageSource(width, height,
cm, pixels, 0, width));
g.drawImage(img, 0, 0, null);
MemoryImageSource together. I would prefer not to use BufferdImage or
WritableRaster (because it requires copynig image data to a DataBuffer
again !! which is not performance wise)
Is there any solution discussed here:
http://groups.google.com/group/comp...onentcolormodel&rnum=1&hl=en#cb95b2d11a2e388f
and here:
http://groups.google.com/group/comp...onentcolormodel&rnum=4&hl=en#894e0134017ff203
and here:
http://groups.google.com/group/comp...onentcolormodel&rnum=3&hl=en#1fbb438f58c3e88e
a partial solution is here:
http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?forum=177&thread=98473&cat=10
(in one of replies)
Also my code is this:
//grab data
byte[] pixels = vic.vic32jni.convertbuffertobytearray(timage.ibuff,
(width) * (height) * 3);
byte reds = 0;
byte greens = 0;
byte blues = 0;
int[] pix = new int[ (width) * (height)];
int j = 0;
//this for loop gives an integer array that works fine with
ComponentColorModel and MemoryImageSource, but it is actually not
performance wise too
//If I can not use ComponentColorModel and MemoryImageSource, I guess
the follownig solution is better than BufferedImage
for (int i = 0; i < (width) * (height) * 3; i += 3, j++) {
reds = pixels;
greens = pixels[i + 1];
blues = pixels[i + 2];
pix[j] = 0xff * 0x1000000 + blues * 0x10000 + greens * 0x100 +
reds;
}
int bits[] = {
8, 8, 8};
//Using IndexedColorModel also works fineunless you have 16 million
colors (more than 256).
ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(
ColorSpace.CS_sRGB), bits, false, false, Transparency.OPAQUE,
DataBuffer.TYPE_BYTE);
// if I uncomment the following lines(imp#1) and use it instead of the
next MemoryImageSource (in imp#2) it works fine !
//imp#1
// img = Toolkit.getDefaultToolkit().createImage(
// new MemoryImageSource(width, height,
// pix, 0, width));
//imp#2
img = Toolkit.getDefaultToolkit().createImage(
new MemoryImageSource(width, height,
cm, pixels, 0, width));
g.drawImage(img, 0, 0, null);