public synchronized Raster getRaster(int x, int y, int w, int h) { if (wrn == null) { DirectColorModel dcm = (DirectColorModel) getColorModel(); SampleModel smHw; int dataType = 0; int scanStride = width; if (dcm.getPixelSize() == 24 || dcm.getPixelSize() == 32) { dataType = DataBuffer.TYPE_INT; } else { // 15, 16 dataType = DataBuffer.TYPE_USHORT; } // note that we have to use the surface width and height here, // not the passed w,h smHw = new SinglePixelPackedSampleModel(dataType, width, height, scanStride, dcm.getMasks()); DataBuffer dbn = new D3DDataBufferNative( this, dataType, width, height); wrn = WritableRasterNative.createNativeRaster(smHw, dbn); } return wrn; }