- // Nothing to do, since we have direct access to the image data.
- public void cacheRowForLuminance(int y) {
+ // For efficiency, the RGB data and the luminance data share the same array.
+ protected int[] getLuminanceRow(int y, int[] row) {
+ int width = getWidth();
+ if (row == null || row.length < width) {
+ row = new int[width];
+ }
+ image.getRGB(row, 0, width, 0, y, width, 1);
+ for (int x = 0; x < width; x++) {
+ int pixel = row[x];
+ row[x] = (((pixel & 0x00FF0000) >> 16) +
+ ((pixel & 0x0000FF00) >> 7) +
+ (pixel & 0x000000FF )) >> 2;
+ }
+ return row;
+ }