public static BufferedImage renderOrientation(GrayU8 direction , BufferedImage out ) { if( out == null ) { out = new BufferedImage(direction.getWidth(),direction.getHeight(),BufferedImage.TYPE_INT_RGB); } WritableRaster raster = out.getRaster(); if( raster.getDataBuffer().getDataType() == DataBuffer.TYPE_INT) { int colors[] = new int[4]; colors[0] = Color.RED.getRGB(); colors[1] = Color.GREEN.getRGB(); colors[2] = Color.BLUE.getRGB(); colors[3] = Color.BLACK.getRGB(); int dataDst[] = ((DataBufferInt)raster.getDataBuffer()).getData(); int strideDst = ConvertRaster.stride(raster); int offsetDst = ConvertRaster.getOffset(raster); int w = direction.getWidth(); int h = direction.getHeight(); for( int y = 0; y < h; y++ ) { int indexDst = offsetDst + y*strideDst; int indexSrc = direction.startIndex + y*direction.stride; for( int x = 0; x < w; x++ ) { dataDst[indexDst++] = colors[direction.data[indexSrc++]]; } } } else { throw new RuntimeException("Raster not supported yet"); } return out; }
int strideDst = ConvertRaster.stride(raster); int offsetDst = ConvertRaster.getOffset(raster);