OSDN Git Service

[NyARToolKit for java]update document
[nyartoolkit-and/nyartoolkit-and.git] / lib / src / jp / nyatla / nyartoolkit / core / rasterfilter / NyARRasterFilter_CustomToneTable.java
1 /* \r
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
6  *\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
11  * \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
16  *\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
19  * \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
23  * \r
24  */\r
25 package jp.nyatla.nyartoolkit.core.rasterfilter;\r
26 \r
27 import jp.nyatla.nyartoolkit.NyARException;\r
28 import jp.nyatla.nyartoolkit.core.raster.*;\r
29 import jp.nyatla.nyartoolkit.core.types.NyARBufferType;\r
30 import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
31 \r
32 /**\r
33  * このクラスは、色調フィルタのベースクラスです。\r
34  * 継承クラスで{@link #table}に変換ルールを書き込む処理を実装します。 \r
35  * <p>対応している画素形式は以下の通りです。\r
36  * <li>{@link NyARBufferType#INT1D_GRAY_8}\r
37  * </p>\r
38  */\r
39 public class NyARRasterFilter_CustomToneTable implements INyARRasterFilter\r
40 {\r
41         protected final int[] table=new int[256];\r
42         private IdoFilterImpl _dofilterimpl;\r
43         /**\r
44          * コンストラクタです。\r
45          * 入力/出力ラスタの画素形式を指定して、インスタンスを生成します。\r
46          * @param i_raster_type\r
47          * ラスタ形式。\r
48          * @throws NyARException\r
49          */\r
50         protected NyARRasterFilter_CustomToneTable(int i_raster_type) throws NyARException\r
51         {\r
52                 switch (i_raster_type) {\r
53                 case NyARBufferType.INT1D_GRAY_8:\r
54                         this._dofilterimpl=new IdoFilterImpl_INT1D_GRAY_8();\r
55                         break;\r
56                 default:\r
57                         throw new NyARException();\r
58                 }\r
59                 this._dofilterimpl._table_ref=this.table;\r
60         }\r
61         /**\r
62          * 変換テーブルに従って、画素値を交換した画像を出力します。\r
63          * 画素形式は、コンストラクタに指定した形式に合せてください。\r
64          */\r
65         public void doFilter(INyARRaster i_input, INyARRaster i_output) throws NyARException\r
66         {\r
67                 assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
68                 this._dofilterimpl.doFilter(i_input,i_output,i_input.getSize());\r
69         }\r
70         \r
71         private abstract class IdoFilterImpl\r
72         {\r
73                 public int[] _table_ref;\r
74                 public abstract void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size) throws NyARException;\r
75                 \r
76         }\r
77         private class IdoFilterImpl_INT1D_GRAY_8 extends IdoFilterImpl\r
78         {\r
79                 public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size) throws NyARException\r
80                 {\r
81                         assert(         i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));\r
82                         \r
83                         int[] out_buf = (int[]) i_output.getBuffer();\r
84                         int[] in_buf = (int[]) i_input.getBuffer();\r
85                         for(int i=i_size.h*i_size.w-1;i>=0;i--)\r
86                         {\r
87                                 out_buf[i]=this._table_ref[in_buf[i]];\r
88                         }\r
89                         return;\r
90                 }\r
91         }\r
92 }\r