1 7 package org.jboss.media.exampleplugins; 8 9 import javax.media.Buffer; 10 11 import org.jboss.media.engine.MediaPlugin; 12 13 17 public class ColorToGrayScale extends MediaPlugin 18 { 19 20 24 public int process(Object out) 25 { 26 Buffer output = (Buffer)out; 27 byte[] data = (byte[]) output.getData(); 28 29 float blue = 0.299f; 30 float green = 0.587f; 31 float red = 0.114f; 32 33 for (int i = 0; i < data.length; i += 3) 34 { 35 37 int grey = 38 java.lang.Math.round( 39 (data[i] * blue + data[i + 1] * green + data[i + 2] * red)) 40 & 0xff; 41 42 data[i] = (byte) grey; 43 data[i + 1] = (byte) grey; 44 data[i + 2] = (byte) grey; 45 } 46 47 return 0; 48 } 49 50 } 51 | Popular Tags |