2 * PROJECT: NyARToolkit
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java version ARToolkit class library.
\r
11 * Copyright (C)2008 R.Iizuka
\r
13 * This program is free software; you can redistribute it and/or
\r
14 * modify it under the terms of the GNU General Public License
\r
15 * as published by the Free Software Foundation; either version 2
\r
16 * of the License, or (at your option) any later version.
\r
18 * This program is distributed in the hope that it will be useful,
\r
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 * GNU General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this framework; if not, write to the Free Software
\r
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
27 * For further information please contact.
\r
28 * http://nyatla.jp/nyatoolkit/
\r
29 * <airmail(at)ebony.plala.or.jp>
\r
32 package jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs;
\r
34 import jp.nyatla.nyartoolkit.NyARException;
\r
35 import jp.nyatla.nyartoolkit.core.raster.*;
\r
36 import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster;
\r
37 import jp.nyatla.nyartoolkit.core.rasterfilter.INyARRasterFilter_RgbToGs;
\r
38 import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;
\r
39 import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
\r
41 public class NyARRasterFilter_RgbAve implements INyARRasterFilter_RgbToGs
\r
43 public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException
\r
45 INyARBufferReader in_buffer_reader=i_input.getBufferReader();
\r
46 INyARBufferReader out_buffer_reader=i_output.getBufferReader();
\r
47 assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);
\r
49 int[] out_buf = (int[]) out_buffer_reader.getBuffer();
\r
50 byte[] in_buf = (byte[]) in_buffer_reader.getBuffer();
\r
52 NyARIntSize size = i_output.getSize();
\r
53 switch (in_buffer_reader.getBufferType()) {
\r
54 case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:
\r
55 case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:
\r
56 convert24BitRgb(in_buf, out_buf, size);
\r
58 case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:
\r
59 convert32BitRgbx(in_buf, out_buf, size);
\r
62 throw new NyARException();
\r
67 private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size)
\r
70 for (int y = 0; y < i_size.h; y++) {
\r
71 for (int x = 0; x < i_size.w; x++) {
\r
72 i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)) / 3;
\r
78 private void convert32BitRgbx(byte[] i_in, int[] i_out, NyARIntSize i_size)
\r
81 for (int y = 0; y < i_size.h; y++) {
\r
82 for (int x = 0; x < i_size.w; x++) {
\r
83 i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)) / 3;
\r