
Signature
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
Hi Andrey,
Thanks for your reply. I added some code as below, but the output
images still like before. I chose to use the 12 bit ColorSpace:
short temp[] = new short[width*height];
int index = 0;
try{
byte data[] = new byte[pixelDataLength];
BufferedFileInputStream.read(data);
for( int i =0; i<temp.length;i++){
temp[i] = (short) (data[index++]+((data[index++])<<8));
}
}catch(IOException ex){}
DataBufferUShort dbs= new DataBufferUShort(temp, width*height);
byte r[] = new byte[0x1000];
byte g[] = new byte[0x1000];
byte b[] = new byte[0x1000];
int i;
double d = 255.0/4096;
for(i = 0;i < 4096; i++) {
byte b1 = (byte) ((d * i));
r[i] = g[i] = b[i] = (byte)(255-b1) ;
}
IndexColorModel icm = new IndexColorModel(12, 0x1000, r,g,b);
WritableRaster raster =
Raster.createInterleavedRaster(dbs,width,
height, width,
1,new int[]{0},null);
BufferedImage myBI = new BufferedImage(icm, raster, false, new
Hashtable());
Woud you think the code is ok, or I didn't get your idea.
Many thanks
Andrey Kuznetsov - 26 May 2006 15:49 GMT
> short temp[] = new short[width*height];
> int index = 0;
> try{
> byte data[] = new byte[pixelDataLength];
> BufferedFileInputStream.read(data);
note that InputStream.read(byte [] buffer)
does not guaranteed to fill given buffer,
it returns how much byte was read
So, you have to read in a loop or use readFully(byte [] buffer)
> }catch(IOException ex){}
this is really BAD thing, newer swallow exception,
at least make ex.printStackTrace();
> for( int i =0; i<temp.length;i++){
> temp[i] = (short) (data[index++]+((data[index++])<<8));
BTW are you sure that you are using right byte order?
Andrey

Signature
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
Java_New - 27 May 2006 15:24 GMT
Thanks very much for your help. That was my low level mistake. Every
thing become ok after I change code:
temp[i] = (short) (data[index++]+((data[index++])<<8));
to
temp[i] = (short) (((data[index++])&0xff)+(((data[index++])&0x0F)<<8));
I also appreciate those comments / tips you gave to me.
Thanks
Andrey Kuznetsov - 27 May 2006 16:24 GMT
> Thanks very much for your help. That was my low level mistake. Every
> thing become ok after I change code:
> temp[i] = (short) (data[index++]+((data[index++])<<8));
>
> to
> temp[i] = (short) (((data[index++])&0xff)+(((data[index++])&0x0F)<<8));
yes, this is frequent mistake and is difficult to find, I know it too good.
Andrey

Signature
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities