OSDN Git Service

[TAG]NyARToolkit for Java 2.4.2
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.4.2 / src / jp / nyatla / nyartoolkit / nyidmarker / data / NyIdMarkerDataEncoder_RawBit.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.nyidmarker.data;\r
26 \r
27 import jp.nyatla.nyartoolkit.nyidmarker.*;\r
28 \r
29 \r
30 public class NyIdMarkerDataEncoder_RawBit implements INyIdMarkerDataEncoder\r
31 {       \r
32         private final static int _DOMAIN_ID=0;\r
33         private final static int[] _mod_data={7,31,127,511,2047,4095};\r
34         public boolean encode(NyIdMarkerPattern i_data,INyIdMarkerData o_dest)\r
35         {\r
36                 final NyIdMarkerData_RawBit dest=(NyIdMarkerData_RawBit)o_dest;\r
37                 if(i_data.ctrl_domain!=_DOMAIN_ID){\r
38                         return false;\r
39                 }\r
40                 //パケット数計算\r
41                 final int resolution_len=(i_data.model+1);\r
42                 final int packet_length=(resolution_len*resolution_len)/8+1;\r
43                 int sum=0;\r
44                 for(int i=0;i<packet_length;i++){\r
45                         dest.packet[i]=i_data.data[i];\r
46                         sum+=i_data.data[i];\r
47                 }\r
48                 //チェックドット値計算\r
49                 sum=sum%_mod_data[i_data.model-2];\r
50                 //チェックドット比較\r
51                 if(i_data.check!=sum){\r
52                         return false;\r
53                 }\r
54                 dest.length=packet_length;\r
55                 return true;\r
56         }\r
57         public INyIdMarkerData createDataInstance()\r
58         {\r
59                 return new NyIdMarkerData_RawBit();\r
60         }\r
61 }\r