OSDN Git Service

[リリース]NyARToolkit 1.0.0
[nyartoolkit-and/nyartoolkit-and.git] / src / jp / nyatla / nyartoolkit / core / raster / NyARRaster_RGB.java
1 /* \r
2  * PROJECT: NyARToolkit\r
3  * --------------------------------------------------------------------------------\r
4  * This work is based on the original ARToolKit developed by\r
5  *   Hirokazu Kato\r
6  *   Mark Billinghurst\r
7  *   HITLab, University of Washington, Seattle\r
8  * http://www.hitl.washington.edu/artoolkit/\r
9  *\r
10  * The NyARToolkit is Java version ARToolkit class library.\r
11  * Copyright (C)2008 R.Iizuka\r
12  *\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
17  * \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
22  * \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
26  * \r
27  * For further information please contact.\r
28  *      http://nyatla.jp/nyatoolkit/\r
29  *      <airmail(at)ebony.plala.or.jp>\r
30  * \r
31  */\r
32 package jp.nyatla.nyartoolkit.core.raster;\r
33 \r
34 \r
35 public class NyARRaster_RGB implements NyARRaster\r
36 {\r
37     protected byte[] ref_buf;\r
38     protected int width;\r
39     protected int height;\r
40     public static NyARRaster_RGB wrap(byte[] i_buffer,int i_width,int i_height)\r
41     {\r
42         NyARRaster_RGB new_inst=new NyARRaster_RGB();\r
43         new_inst.ref_buf=i_buffer;\r
44         new_inst.width  =i_width;\r
45         new_inst.height =i_height;\r
46         return new_inst;\r
47     }\r
48     //RGBの合計値を返す\r
49     public int getPixelTotal(int i_x,int i_y)\r
50     {\r
51         byte[] ref=this.ref_buf;\r
52         int bp=(i_x+i_y*this.width)*3;\r
53         return (ref[bp] & 0xff)+(ref[bp+1] & 0xff)+(ref[bp+2] & 0xff);\r
54     }\r
55     public void getPixelTotalRowLine(int i_row,int[] o_line)\r
56     {\r
57         final byte[] ref=this.ref_buf;\r
58         int bp=(i_row+1)*this.width*3-3;\r
59         for(int i=this.width-1;i>=0;i--){\r
60             o_line[i]=(ref[bp] & 0xff)+(ref[bp+1] & 0xff)+(ref[bp+2] & 0xff);\r
61             bp-=3;\r
62         }\r
63     }    \r
64     public int getWidth()\r
65     {\r
66         return width;\r
67     }\r
68     public int getHeight()\r
69     {\r
70         return height;\r
71     }\r
72     public void getPixel(int i_x,int i_y,int[] i_rgb)\r
73     {\r
74         int bp=(i_x+i_y*this.width)*3;\r
75         byte[] ref=this.ref_buf;\r
76         i_rgb[0]=(ref[bp+0] & 0xff);//R\r
77         i_rgb[1]=(ref[bp+1] & 0xff);//G\r
78         i_rgb[2]=(ref[bp+2] & 0xff);//B\r
79     }\r
80     public void getPixelSet(int[] i_x,int i_y[],int i_num,int[] o_rgb)\r
81     {\r
82         int width=this.width;\r
83         byte[] ref=this.ref_buf;\r
84         int bp;\r
85         for(int i=i_num-1;i>=0;i--){\r
86             bp=(i_x[i]+i_y[i]*width)*3;\r
87             o_rgb[i*3+0]=(ref[bp+0] & 0xff);//R\r
88             o_rgb[i*3+1]=(ref[bp+1] & 0xff);//G\r
89             o_rgb[i*3+2]=(ref[bp+2] & 0xff);//B\r
90         }       \r
91     }\r
92 }\r
93 \r