If you have a data element for each band seperately  then use a
ComponentColorModel.

Vidya Sagar schrieb:

> Hi Selman and all,
>    Thanks for your responses. I am using a color model
> bcos, I have R, G, B samples/values individually,  and
> not a single pixel value. To get a single pixel value
> from three individual values I am using ColorModel.
>
> I have corrected my code, and used DirectColorModel,
> and SinglePixelPackedSampleModel. Now I am passing
> these RGB values to a method in DirectColorModel to
> get the pixel value represented as a single int and
> storing that value in the data buffer, which is to be
> passed to the bufferedImage creation. This works but I
> am weird images on my frame, but not the original one.
>
> I am attaching the sample code below...
>
> cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
>
> // Color Model
> DirectColorModel dcm = new DirectColorModel(cs, 24,
> 0xff0000, 0x00ff00, 0x0000ff, 0x0, false,
> DataBuffer.TYPE_BYTE);
>
>         int[] bandMasks = new int[3];
>                 bandMasks[0] = 0x00ff0000;
>                 bandMasks[1] = 0x0000ff00;
>                 bandMasks[2] = 0x000000ff;
>
>         SinglePixelPackedSampleModel spsm = new
> SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE,
> texturewidth, textureheight, texturewidth, bandMasks);
>
> SampleModel smm =
> spsm.createCompatibleSampleModel(texturewidth,
> textureheight);
> DataBuffer newDB = spsm.createDataBuffer();
>
> // Filling the DataBuffer with pixels
> for(int ii=0; ii<texturewidth * textureheight; ii++)
>   {
>     components[0] = inputData[ctr1++]; //Red
>     components[1] = inputData[ctr1++]; //Green
>     components[2] = inputData[ctr1++]; //Blue
>
>     int dataElement1 = dcm.getDataElement(components,
> 0); // Return a single int pixel value for R,G,B
> values
>
>   newDB.setElem(ctr, dataElement1); // Filling the
> Data Buffer
>     ctr++;
>  }
> raster = WritableRaster.createWritableRaster(smm,
> newDB, null);
>
> img = new BufferedImage(dcm, raster, false, null);
>
> For the above code, I am getting a texture mapped
> image totally different from the original one.
> Suggestions please.....
>
> Thanks,
> Sagar.
>
> --- Daniel Selman <[EMAIL PROTECTED]> wrote:
> > Vidya,
> >
> > I just use something like:
> >
> > BufferedImage perlinTextureImage = new
> > BufferedImage( MAX_TEXTURE_SIZE,
> > MAX_TEXTURE_SIZE, BufferedImage.TYPE_3BYTE_BGR );
> >
> > I can then use getRGB(), setRGB() to read/write the
> > color data. What are the
> > advantages of setting up the ColorModel explicitly?
> >
> > Sincerely,
> >
> > Daniel Selman
> >
> > Author - "Java 3D Programming"
> > http://www.manning.com/selman
> >
> > -----Original Message-----
> > From: Discussion list for Java 3D API
> > [mailto:[EMAIL PROTECTED]]On Behalf Of
> > Vidya Sagar
> > Sent: Thursday, April 04, 2002 1:36 AM
> > To: [EMAIL PROTECTED]
> > Subject: Buffered Image creation
> >
> >
> > Hi all,
> >    I am creating a buffered image in the code given
> > below. I am getting the exception shown. Could
> > anyone
> > suggest some possible correction or any other
> > solution
> > to it? I need to use the DirectColorModel since I
> > want
> > to access individual RGB components of each pixel.
> >
> >
> > cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
> > DirectColorModel dcm = new DirectColorModel(cs, 24,
> > 0xff0000, 0x00ff00, 0x0000ff, 0x0, false,
> > DataBuffer.TYPE_BYTE);
> >
> > byte[] readData = new byte[128 * 128 * 3];
> > /* reading the data into the byte array readData
> > takes
> > here */
> >
> > //After reading..the data
> > DataBuffer db = new DataBufferByte(readData,
> > texturewidth * textureheight * 3);
> >
> > int[] band = new int[3];
> >
> > raster = WritableRaster.createInterleavedRaster(db,
> > texturewidth, textureheight, texturewidth * 3, 3,
> > band, null);
> >
> > Exception in thread "main"
> > java.lang.IllegalArgumentException: Raster
> > ByteInterleavedRaster: width = 128 height = 128
> > #numDataElements 3 dataOff[0] = 0 is incompatible
> > with
> > ColorModel DirectColorModel: rmask=ff0000 gmask=ff00
> > bmask=ff amask=0
> >         at
> >
> java.awt.image.BufferedImage.<init>(BufferedImage.java:517)
> >
> >
> > Thanks,
> > Sagar.
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Yahoo! Tax Center - online filing with TurboTax
> > http://taxes.yahoo.com/
> >
> >
> ===========================================================================
> > To unsubscribe, send email to [EMAIL PROTECTED]
> > and include in the body
> > of the message "signoff JAVA3D-INTEREST".  For
> > general help, send email to
> > [EMAIL PROTECTED] and include in the body of the
> > message "help".
> >
> >
> ===========================================================================
> > To unsubscribe, send email to [EMAIL PROTECTED]
> > and include in the body
> > of the message "signoff JAVA3D-INTEREST".  For
> > general help, send email to
> > [EMAIL PROTECTED] and include in the body of the
> > message "help".
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Tax Center - online filing with TurboTax
> http://taxes.yahoo.com/
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

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

Reply via email to