2 * PROJECT: NyARToolkit(Extension)
\r
3 * --------------------------------------------------------------------------------
\r
4 * The NyARToolkit is Java edition ARToolKit class library.
\r
5 * Copyright (C)2008-2009 Ryo Iizuka
\r
7 * This program is free software: you can redistribute it and/or modify
\r
8 * it under the terms of the GNU General Public License as published by
\r
9 * the Free Software Foundation, either version 3 of the License, or
\r
10 * (at your option) any later version.
\r
12 * This program is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 * GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
20 * For further information please contact.
\r
21 * http://nyatla.jp/nyatoolkit/
\r
22 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
25 package jp.nyatla.nyartoolkit.core.rasterfilter.rgb2gs;
\r
27 import jp.nyatla.nyartoolkit.NyARException;
\r
28 import jp.nyatla.nyartoolkit.core.raster.*;
\r
29 import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster;
\r
30 import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2gs.INyARRasterFilter_Rgb2Gs;
\r
31 import jp.nyatla.nyartoolkit.core.types.NyARBufferType;
\r
32 import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
\r
35 * YCbCr変換して、Y成分のグレースケールの値を計算します。
\r
36 * 変換式は、http://www.tyre.gotdns.org/を参考にしました。
\r
38 public class NyARRasterFilter_Rgb2Gs_YCbCr implements INyARRasterFilter_Rgb2Gs
\r
40 private IdoFilterImpl _dofilterimpl;
\r
41 public NyARRasterFilter_Rgb2Gs_YCbCr(int i_in_raster_type) throws NyARException
\r
43 if(!initInstance(i_in_raster_type,NyARBufferType.INT1D_GRAY_8))
\r
45 throw new NyARException();
\r
48 public NyARRasterFilter_Rgb2Gs_YCbCr(int i_in_raster_type,int i_out_raster) throws NyARException
\r
50 if(!initInstance(i_in_raster_type,i_out_raster))
\r
52 throw new NyARException();
\r
55 protected boolean initInstance(int i_in_raster_type,int i_out_raster_type)
\r
57 switch(i_out_raster_type){
\r
58 case NyARBufferType.INT1D_GRAY_8:
\r
59 switch (i_in_raster_type) {
\r
60 case NyARBufferType.BYTE1D_B8G8R8_24:
\r
61 this._dofilterimpl=new IdoFilterImpl_BYTE1D_B8G8R8_24();
\r
63 case NyARBufferType.BYTE1D_R8G8B8_24:
\r
74 public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException
\r
76 assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);
\r
77 this._dofilterimpl.doFilter(i_input,i_output,i_input.getSize());
\r
80 interface IdoFilterImpl
\r
82 public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size) throws NyARException;
\r
84 class IdoFilterImpl_BYTE1D_B8G8R8_24 implements IdoFilterImpl
\r
87 * This function is not optimized.
\r
89 public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size) throws NyARException
\r
91 assert( i_input.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24));
\r
92 assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
\r
94 int[] out_buf = (int[]) i_output.getBuffer();
\r
95 byte[] in_buf = (byte[]) i_input.getBuffer();
\r
98 for (int y = 0; y < i_size.h; y++){
\r
99 for (int x = 0; x < i_size.w; x++){
\r
100 out_buf[y*i_size.w+x]=(306*(in_buf[bp+2] & 0xff)+601*(in_buf[bp + 1] & 0xff)+117 * (in_buf[bp + 0] & 0xff))>>10;
\r