Here you can find the source of extractFromPixeldata(short[] pixeldata, int columns, int stride, int mask, byte[] ovlyData, int off, int length)
private static void extractFromPixeldata(short[] pixeldata, int columns, int stride, int mask, byte[] ovlyData, int off, int length)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Weasis Team and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w . j av a 2 s . com * Nicolas Roduit - initial API and implementation *******************************************************************************/ import java.awt.image.ComponentSampleModel; import java.awt.image.DataBuffer; import java.awt.image.DataBufferByte; import java.awt.image.DataBufferShort; import java.awt.image.DataBufferUShort; import java.awt.image.Raster; public class Main { public static void extractFromPixeldata(Raster raster, int mask, byte[] ovlyData, int off, int length) { ComponentSampleModel sm = (ComponentSampleModel) raster.getSampleModel(); int columns = raster.getWidth(); int stride = sm.getScanlineStride(); DataBuffer db = raster.getDataBuffer(); switch (db.getDataType()) { case DataBuffer.TYPE_BYTE: extractFromPixeldata(((DataBufferByte) db).getData(), columns, stride, mask, ovlyData, off, length); break; case DataBuffer.TYPE_USHORT: extractFromPixeldata(((DataBufferUShort) db).getData(), columns, stride, mask, ovlyData, off, length); break; case DataBuffer.TYPE_SHORT: extractFromPixeldata(((DataBufferShort) db).getData(), columns, stride, mask, ovlyData, off, length); break; default: throw new UnsupportedOperationException("Unsupported DataBuffer type: " + db.getDataType()); //$NON-NLS-1$ } } private static void extractFromPixeldata(byte[] pixeldata, int columns, int stride, int mask, byte[] ovlyData, int off, int length) { for (int y = 0, i = off, imax = off + length; y < columns && i < imax; y++) { for (int j = y * stride; j < imax && i < imax; j++, i++) { if ((pixeldata[j] & mask) != 0) { ovlyData[i >>> 3] |= 1 << (i & 7); } } } } private static void extractFromPixeldata(short[] pixeldata, int columns, int stride, int mask, byte[] ovlyData, int off, int length) { for (int y = 0, i = off, imax = off + length; y < columns && i < imax; y++) { for (int j = y * stride; j < imax && i < imax; j++, i++) { if ((pixeldata[j] & mask) != 0) { ovlyData[i >>> 3] |= 1 << (i & 7); } } } } }