OSDN Git Service

[tag]NyARToolkit/2.5.1
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.5.1 / src / jp / nyatla / nyartoolkit / core / rasterfilter / NyARRasterFilter_ToneTable.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 \r
29 /**\r
30  * 色調テーブルを使用したフィルターです。\r
31  * 基本的な関数テーブルで色調テーブルを作成できます。\r
32  */\r
33 public class NyARRasterFilter_ToneTable extends NyARRasterFilter_CustomToneTable\r
34 {\r
35         public NyARRasterFilter_ToneTable(int i_raster_type) throws NyARException\r
36         {\r
37                 super(i_raster_type);\r
38         }\r
39         /**\r
40          * 点x,yを通過する、傾きi_aの直線をテーブルに書き込みます。\r
41          * @param i_x\r
42          * @param i_y\r
43          * @param i_a\r
44          */\r
45         public void setLine(int i_x,int i_y,double i_a)\r
46         {\r
47                 if(i_a==0){\r
48                         int i;\r
49                         for(i=0;i<=i_x;i++){\r
50                                 this.table[i]=0;\r
51                         }\r
52                         for(i=0;i<256;i++){\r
53                                 this.table[i]=255;\r
54                         }\r
55                 }else{\r
56                         int b=i_y-(int)(i_a*i_x);\r
57                         for(int i=0;i<256;i++){\r
58                                 int v=(int)(i_a*i)+b;\r
59                                 this.table[i]=v<0?0:v>255?255:v;\r
60                         }\r
61                 }\r
62         }\r
63         /**\r
64          * 点0,0を通過する、傾きaの直線をテーブルに書き込みます。\r
65          * i_aの値をvとしたとき、以下のようになります。\r
66          * v<=0         黒色\r
67          * 0<v<1        暗くする。\r
68          * v=0          変化しない\r
69          * 1<v<255      明るくする。\r
70          * 255<=v       白色\r
71          * @param i_ax\r
72          * @param i_ay\r
73          */\r
74         public void setLine(double i_a)\r
75         {\r
76                 setLine(0,0,i_a);\r
77         }\r
78         /**\r
79          * 点 i_x,i_yを中心とする、ゲインi_gainのシグモイド関数をテーブルに書き込みます。\r
80          * @param i_x\r
81          * @param i_y\r
82          * @param i_gain\r
83          */\r
84         public void setSigmoid(int i_x,int i_y,double i_gain)\r
85         {\r
86                 for(int i=0;i<256;i++){\r
87                         int v=255*(int)(1/(1+Math.exp(i_gain*(i-i_x)))-0.5)+i_y;\r
88                         this.table[i]=v<0?0:v>255?255:v;\r
89                 }\r
90         }\r
91         /**\r
92          * ガンマ補正値をテーブルに書き込みます。\r
93          * @param i_gamma\r
94          */\r
95         public void setGamma(double i_gamma)\r
96         {\r
97                 for(int i=0;i<256;i++){\r
98                         this.table[i]=(int)(Math.pow((double)i/255.0,i_gamma)*255.0);\r
99                 }\r
100         }\r
101 }\r