(PngQuant attr, BufferedImage image)
| 50 | } |
| 51 | |
| 52 | private static long handleFromImage(PngQuant attr, BufferedImage image) { |
| 53 | // The JNI wrapper will accept non-premultiplied ABGR and BGR only. |
| 54 | int type = image.getType(); |
| 55 | if (type != BufferedImage.TYPE_3BYTE_BGR && |
| 56 | type != BufferedImage.TYPE_4BYTE_ABGR && |
| 57 | type != BufferedImage.TYPE_4BYTE_ABGR_PRE) return 0; |
| 58 | |
| 59 | WritableRaster raster = image.getRaster(); |
| 60 | ColorModel color = image.getColorModel(); |
| 61 | if (type == BufferedImage.TYPE_4BYTE_ABGR_PRE) color.coerceData(raster, false); |
| 62 | |
| 63 | DataBuffer buffer = raster.getDataBuffer(); |
| 64 | if (buffer instanceof DataBufferByte) { |
| 65 | byte[] imageData = ((DataBufferByte)buffer).getData(); |
| 66 | return liq_image_create(attr.handle, imageData, |
| 67 | raster.getWidth(), raster.getHeight(), color.getNumComponents()); |
| 68 | } |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | private static native long liq_image_create(long attr, byte[] bitmap, int width, int height, int components); |
| 73 | private static native void liq_image_destroy(long handle); |
no test coverage detected