MCPcopy Create free account
hub / github.com/ImageOptim/libimagequant / handleFromImage

Method handleFromImage

imagequant-sys/org/pngquant/Image.java:52–70  ·  view source on GitHub ↗
(PngQuant attr, BufferedImage image)

Source from the content-addressed store, hash-verified

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);

Callers 1

ImageMethod · 0.95

Calls 3

liq_image_createMethod · 0.95
getWidthMethod · 0.80
getHeightMethod · 0.80

Tested by

no test coverage detected