OSDN Git Service

[backup]NyARToolKit
authornyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Sun, 10 Jan 2010 12:01:20 +0000 (12:01 +0000)
committernyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Sun, 10 Jan 2010 12:01:20 +0000 (12:01 +0000)
+NyARBinRasterのバッファフォーマット多重化に伴う修正
+NyARGrayscaleRasterのバッファフォーマット多重化に伴う修正
+NyARGrayscaleRasterからベクトル調査系関数を分離

git-svn-id: http://svn.sourceforge.jp/svnroot/nyartoolkit/NyARToolkit@374 7cac0a50-4618-4814-88d0-24b83990f816

18 files changed:
trunk/sample/sandbox/jp/nyatla/nyartoolkit/core/analyzer/histgram/NyARHistgramAnalyzer_PTile.java
trunk/sample/sandbox/jp/nyatla/nyartoolkit/core/rasterfilter/NyARRasterOperator_Mul.java
trunk/sample/sandbox/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2gs/NyARRasterFilter_Rgb2Gs_CbCrCut.java
trunk/sample/sandbox/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2gs/NyARRasterFilter_Rgb2Gs_RgbOr.java
trunk/src/jp/nyatla/nyartoolkit/core/labeling/artoolkit/NyARLabeling_ARToolKit.java
trunk/src/jp/nyatla/nyartoolkit/core/labeling/rlelabeling/NyARLabeling_Rle.java
trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java
trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARGrayscaleRaster.java
trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java
trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster.java
trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/NyARRasterFilter_EqualizeHist.java
trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/gs2bin/INyARRasterFilter_Gs2Bin.java
trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/gs2bin/NyARRasterFilter_ConstantThrshold.java
trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/NyARRasterFilter_ARToolkitThreshold.java
trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2gs/NyARRasterFilter_Rgb2Gs_AveAdd.java
trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2gs/NyARRasterFilter_Rgb2Gs_RgbCube.java
trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2gs/NyARRasterFilter_Rgb2Gs_YCbCr.java
trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARVectorReader_INT1D_GRAY_8.java [new file with mode: 0644]

index 0f18606..094931b 100644 (file)
@@ -37,7 +37,6 @@ public class NyARHistgramAnalyzer_PTile
        private int _persentage;\r
        public NyARHistgramAnalyzer_PTile(int i_persentage)\r
        {\r
-               assert (0 <= i_persentage && i_persentage <= 50);\r
                //初期化\r
                this._persentage=i_persentage;\r
        }       \r
index 583bb06..2603163 100644 (file)
@@ -70,6 +70,10 @@ public class NyARRasterOperator_Mul
        {\r
                public void doFilter(INyARBufferReader i_input_a,INyARBufferReader i_input_b,INyARBufferReader i_output,NyARIntSize i_size) throws NyARException\r
                {\r
+                       assert(i_input_a.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
+                       assert(i_input_b.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
+                       assert(i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
+                       \r
                        int[] out_buf = (int[]) i_output.getBuffer();\r
                        int[] in_buf1 = (int[]) i_input_a.getBuffer();\r
                        int[] in_buf2 = (int[]) i_input_b.getBuffer();\r
index f588e97..c85c777 100644 (file)
@@ -53,7 +53,8 @@ public class NyARRasterFilter_Rgb2Gs_CbCrCut implements INyARRasterFilter_RgbToG
        {\r
                public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) throws NyARException\r
                {\r
-                       assert(         i_input.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24));\r
+                       assert( i_input.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24));\r
+                       assert( i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
                        \r
                        int[] out_buf = (int[]) i_output.getBuffer();\r
                        byte[] in_buf = (byte[]) i_input.getBuffer();\r
index d77e14f..c91aa7b 100644 (file)
@@ -41,8 +41,10 @@ public class NyARRasterFilter_Rgb2Gs_RgbOr implements INyARRasterFilter_RgbToGs
 {\r
        public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException\r
        {\r
+               \r
                INyARBufferReader in_buffer_reader=i_input.getBufferReader();   \r
                INyARBufferReader out_buffer_reader=i_output.getBufferReader();                 \r
+               assert( out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
                assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
 \r
                final int[] out_buf = (int[]) out_buffer_reader.getBuffer();\r
index f19d8f6..de61db2 100644 (file)
@@ -32,6 +32,7 @@ package jp.nyatla.nyartoolkit.core.labeling.artoolkit;
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.raster.*;\r
+import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
 \r
 /**\r
@@ -54,6 +55,7 @@ final public class NyARLabeling_ARToolKit
         */\r
        public int labeling(NyARBinRaster i_raster,NyARLabelingImage o_destination) throws NyARException\r
        {\r
+               assert(i_raster.getBufferReader().getBufferType()==INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8);\r
                int label_img_ptr1, label_pixel;\r
                int i, j;\r
                int n, k; /* work */\r
index 1a8eb7f..c4ee7ed 100644 (file)
@@ -26,6 +26,7 @@ package jp.nyatla.nyartoolkit.core.labeling.rlelabeling;
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.raster.*;\r
+import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
 import jp.nyatla.nyartoolkit.core.types.stack.NyObjectStack;\r
 \r
 class RleInfoStack extends NyObjectStack<RleInfoStack.RleInfo>\r
@@ -204,6 +205,7 @@ public class NyARLabeling_Rle
         */\r
        public int labeling(NyARBinRaster i_bin_raster, int i_top, int i_bottom,RleLabelFragmentInfoStack o_stack) throws NyARException\r
        {\r
+               assert(i_bin_raster.getBufferReader().getBufferType()==INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8);\r
                return this.imple_labeling(i_bin_raster,0,i_top,i_bottom,o_stack);\r
        }\r
        /**\r
@@ -219,6 +221,7 @@ public class NyARLabeling_Rle
         */\r
        public int labeling(NyARGrayscaleRaster i_gs_raster,int i_th, int i_top, int i_bottom,RleLabelFragmentInfoStack o_stack) throws NyARException\r
        {\r
+               assert(i_gs_raster.getBufferReader().getBufferType()==INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8);\r
                return this.imple_labeling(i_gs_raster,i_th,i_top,i_bottom,o_stack);\r
        }\r
        private int imple_labeling(INyARRaster i_raster,int i_th,int i_top, int i_bottom,RleLabelFragmentInfoStack o_stack) throws NyARException\r
index b6b816b..b46582e 100644 (file)
@@ -32,20 +32,43 @@ package jp.nyatla.nyartoolkit.core.raster;
 \r
 import jp.nyatla.nyartoolkit.core.rasterreader.*;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
+import jp.nyatla.nyartoolkit.*;\r
 \r
 public class NyARBinRaster extends NyARRaster_BasicClass\r
 {\r
-       private INyARBufferReader _buffer_reader;\r
-       protected int[] _ref_buf;\r
+       protected Object _buf;\r
+       protected INyARBufferReader _buffer_reader;\r
 \r
-       public NyARBinRaster(int i_width, int i_height)\r
+       public NyARBinRaster(int i_width, int i_height,int i_raster_type) throws NyARException\r
        {\r
                super(new NyARIntSize(i_width,i_height));\r
-               this._ref_buf = new int[i_height*i_width];\r
-               this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8);\r
+               if(!initInstance(this._size,i_raster_type)){\r
+                       throw new NyARException();\r
+               }\r
        }\r
+       public NyARBinRaster(int i_width, int i_height) throws NyARException\r
+       {\r
+               super(new NyARIntSize(i_width,i_height));\r
+               if(!initInstance(this._size,INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8)){\r
+                       throw new NyARException();\r
+               }\r
+       }       \r
        public INyARBufferReader getBufferReader()\r
        {\r
                return this._buffer_reader;\r
        }\r
+       protected boolean initInstance(NyARIntSize i_size,int i_buf_type)\r
+       {\r
+               switch(i_buf_type)\r
+               {\r
+                       case INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8:\r
+                               this._buf = new int[i_size.w*i_size.h];\r
+                               this._buffer_reader=new NyARBufferReader(this._buf,INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8);\r
+                               break;\r
+                       default:\r
+                               return false;\r
+               }\r
+               this._buffer_reader=new NyARBufferReader(this._buf,i_buf_type);\r
+               return true;\r
+       }       \r
 }\r
index 2a50800..21258c4 100644 (file)
@@ -38,68 +38,37 @@ import jp.nyatla.nyartoolkit.core.types.*;
 public final class NyARGrayscaleRaster extends NyARRaster_BasicClass\r
 {\r
 \r
-       protected int[] _ref_buf;\r
-       private INyARBufferReader _buffer_reader;\r
-       \r
-       public NyARGrayscaleRaster(int i_width, int i_height)\r
+       protected Object _buf;\r
+       protected INyARBufferReader _buffer_reader;\r
+       public NyARGrayscaleRaster(int i_width, int i_height) throws NyARException\r
        {\r
                super(new NyARIntSize(i_width,i_height));\r
-               this._ref_buf = new int[i_height*i_width];\r
-               this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8);\r
+               if(!initInstance(this._size,INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8)){\r
+                       throw new NyARException();\r
+               }\r
+       }       \r
+       public NyARGrayscaleRaster(int i_width, int i_height,int i_raster_type) throws NyARException\r
+       {\r
+               super(new NyARIntSize(i_width,i_height));\r
+               if(!initInstance(this._size,i_raster_type)){\r
+                       throw new NyARException();\r
+               }\r
        }\r
        public INyARBufferReader getBufferReader()\r
        {\r
                return this._buffer_reader;\r
        }\r
-       /**\r
-        * 4近傍の画素ベクトルを取得します。\r
-        * 0,1,0\r
-        * 1,x,1\r
-        * 0,1,0\r
-        * @param i_raster\r
-        * @param x\r
-        * @param y\r
-        * @param o_v\r
-        */\r
-       public void getPixelVector4(int x,int y,NyARIntPoint2d o_v)\r
+       protected boolean initInstance(NyARIntSize i_size,int i_buf_type)\r
        {\r
-               int[] buf=this._ref_buf;\r
-               int w=this._size.w;\r
-               int idx=w*y+x;\r
-               o_v.x=buf[idx+1]-buf[idx-1];\r
-               o_v.y=buf[idx+w]-buf[idx-w];\r
+               switch(i_buf_type)\r
+               {\r
+                       case INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8:\r
+                               this._buf = new int[i_size.w*i_size.h];\r
+                               break;\r
+                       default:\r
+                               return false;\r
+               }\r
+               this._buffer_reader=new NyARBufferReader(this._buf,i_buf_type);\r
+               return true;\r
        }\r
-       /**\r
-        * 8近傍画素ベクトル\r
-        * 1,2,1\r
-        * 2,x,2\r
-        * 1,2,1\r
-        * @param i_raster\r
-        * @param x\r
-        * @param y\r
-        * @param o_v\r
-        */\r
-       public void getPixelVector8(int x,int y,NyARIntPoint2d o_v)\r
-       {\r
-               int[] buf=this._ref_buf;\r
-               NyARIntSize s=this._size;\r
-               int idx_0 =s.w*y+x;\r
-               int idx_p1=idx_0+s.w;\r
-               int idx_m1=idx_0-s.w;\r
-               int b=buf[idx_m1-1];\r
-               int d=buf[idx_m1+1];\r
-               int h=buf[idx_p1-1];\r
-               int f=buf[idx_p1+1];\r
-               o_v.x=buf[idx_0+1]-buf[idx_0-1]+(d-b+f-h)/2;\r
-               o_v.y=buf[idx_p1]-buf[idx_m1]+(f-d+h-b)/2;\r
-       }\r
-       \r
-       public void copyFrom(NyARGrayscaleRaster i_input) throws NyARException\r
-       {\r
-               int[] out_buf = (int[])this._ref_buf;\r
-               int[] in_buf = (int[]) i_input._ref_buf;\r
-               System.arraycopy(in_buf,0,out_buf,0,this._size.h*this._size.w);\r
-               return;\r
-       }       \r
-       \r
 }\r
index 57f52ae..bf8ee12 100644 (file)
@@ -40,7 +40,8 @@ import jp.nyatla.nyartoolkit.core.types.*;
  */\r
 public final class NyARRaster extends NyARRaster_BasicClass\r
 {\r
-       private NyARBufferReader _reader;\r
+       protected NyARBufferReader _reader;\r
+       protected Object _buf;\r
        public INyARBufferReader getBufferReader()\r
        {\r
                return this._reader;\r
@@ -48,20 +49,22 @@ public final class NyARRaster extends NyARRaster_BasicClass
        public NyARRaster(NyARIntSize i_size,int i_buf_type) throws NyARException\r
        {\r
                super(i_size);\r
-               init(i_size,i_buf_type);\r
+               if(!initInstance(i_size,i_buf_type)){\r
+                       throw new NyARException();\r
+               }\r
                return;\r
        }\r
-       private void init(NyARIntSize i_size,int i_buf_type) throws NyARException\r
+       protected boolean initInstance(NyARIntSize i_size,int i_buf_type)\r
        {\r
-               Object buf;\r
                switch(i_buf_type)\r
                {\r
                        case INyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32:\r
-                               buf=new int[i_size.w*i_size.h];\r
+                               this._buf=new int[i_size.w*i_size.h];\r
                                break;\r
                        default:\r
-                               throw new NyARException();\r
+                               return false;\r
                }\r
-               this._reader=new NyARBufferReader(buf,i_buf_type);\r
+               this._reader=new NyARBufferReader(this._buf,i_buf_type);\r
+               return true;\r
        }       \r
 }
\ No newline at end of file
index 09e50ab..87133f7 100644 (file)
@@ -6,27 +6,15 @@ import jp.nyatla.nyartoolkit.*;
 \r
 public class NyARRgbRaster extends NyARRgbRaster_BasicClass\r
 {\r
-       protected Object _ref_buf;\r
-\r
-       private INyARRgbPixelReader _reader;\r
-       private INyARBufferReader _buffer_reader;\r
-       private void init(NyARIntSize i_size,int i_raster_type) throws NyARException\r
-       {\r
-               switch(i_raster_type)\r
-               {\r
-                       case INyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32:\r
-                               this._ref_buf=new int[i_size.w*i_size.h];\r
-                               this._reader=new NyARRgbPixelReader_INT1D_X8R8G8B8_32((int[])this._ref_buf,i_size);\r
-                               break;\r
-                       default:\r
-                               throw new NyARException();\r
-               }\r
-               this._buffer_reader=new NyARBufferReader(this._ref_buf,i_raster_type);\r
-       }\r
+       protected Object _buf;\r
+       protected INyARRgbPixelReader _reader;\r
+       protected INyARBufferReader _buffer_reader;\r
        public NyARRgbRaster(NyARIntSize i_size,int i_raster_type) throws NyARException\r
        {\r
                super(i_size);\r
-               init(i_size,i_raster_type);\r
+               if(!initInstance(i_size,i_raster_type)){\r
+                       throw new NyARException();\r
+               }\r
                return;\r
        }\r
        public INyARRgbPixelReader getRgbPixelReader()\r
@@ -36,5 +24,19 @@ public class NyARRgbRaster extends NyARRgbRaster_BasicClass
        public INyARBufferReader getBufferReader()\r
        {\r
                return this._buffer_reader;\r
+       }\r
+       protected boolean initInstance(NyARIntSize i_size,int i_raster_type)\r
+       {\r
+               switch(i_raster_type)\r
+               {\r
+                       case INyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32:\r
+                               this._buf=new int[i_size.w*i_size.h];\r
+                               this._reader=new NyARRgbPixelReader_INT1D_X8R8G8B8_32((int[])this._buf,i_size);\r
+                               break;\r
+                       default:\r
+                               return false;\r
+               }\r
+               this._buffer_reader=new NyARBufferReader(this._buf,i_raster_type);\r
+               return true;\r
        }       \r
 }\r
index 8835041..8808f35 100644 (file)
@@ -43,7 +43,6 @@ public class NyARRasterFilter_EqualizeHist extends NyARRasterFilter_CustomToneTa
        }\r
        public void doFilter(INyARRaster i_input, INyARRaster i_output) throws NyARException\r
        {\r
-               assert (i_input!=i_output);\r
                //ヒストグラムを得る\r
                NyARHistgram hist=this._histgram;\r
                this._hist_analyzer.analyzeRaster(i_input,hist);\r
index 83d2c84..14daf29 100644 (file)
@@ -6,6 +6,6 @@ import jp.nyatla.nyartoolkit.core.raster.NyARGrayscaleRaster;
 \r
 public interface INyARRasterFilter_Gs2Bin\r
 {\r
-       public abstract void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException;\r
+       public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException;\r
 \r
 }\r
index 91c6feb..ecf4a70 100644 (file)
@@ -9,10 +9,13 @@ import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
 public class NyARRasterFilter_ConstantThrshold implements INyARRasterFilter_Gs2Bin\r
 {\r
        public int _threshold;\r
-       public NyARRasterFilter_ConstantThrshold(int i_initial_threshold) throws NyARException\r
+       public NyARRasterFilter_ConstantThrshold(int i_initial_threshold,int i_in_raster_type,int i_out_raster_type) throws NyARException\r
        {\r
+               assert(i_in_raster_type==INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8);\r
+               assert(i_out_raster_type==INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8);\r
                //初期化\r
                this._threshold=i_initial_threshold;\r
+               \r
        }\r
        /**\r
         * 2値化の閾値を設定する。\r
@@ -31,10 +34,10 @@ public class NyARRasterFilter_ConstantThrshold implements INyARRasterFilter_Gs2B
        }\r
        public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException\r
        {\r
-               INyARBufferReader in_buffer_reader=i_input.getBufferReader();   \r
-               INyARBufferReader out_buffer_reader=i_output.getBufferReader();\r
-               int[] out_buf = (int[]) out_buffer_reader.getBuffer();\r
-               int[] in_buf = (int[]) in_buffer_reader.getBuffer();\r
+               assert(i_input.getBufferReader().getBufferType()==INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8);\r
+               assert(i_output.getBufferReader().getBufferType()==INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8);\r
+               int[] out_buf = (int[]) i_output.getBufferReader().getBuffer();\r
+               int[] in_buf = (int[]) i_input.getBufferReader().getBuffer();\r
                NyARIntSize s=i_input.getSize();\r
                \r
                final int th=this._threshold;\r
index dbe6057..e60c29b 100644 (file)
@@ -14,35 +14,53 @@ import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
  */\r
 public class NyARRasterFilter_ARToolkitThreshold implements INyARRasterFilter_RgbToBin\r
 {\r
-       private int _threshold;\r
+       protected int _threshold;\r
        private IdoThFilterImpl _do_threshold_impl;\r
 \r
-       public NyARRasterFilter_ARToolkitThreshold(int i_threshold,int i_input_raster_type) throws NyARException\r
+       public NyARRasterFilter_ARToolkitThreshold(int i_threshold,int i_in_raster_type) throws NyARException\r
        {\r
-               this._threshold = i_threshold;\r
-               switch (i_input_raster_type) {\r
-               case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
-               case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
-                       this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_RGB_24();\r
-                       break;\r
-               case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:\r
-                       this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_B8G8R8X8_32();\r
-                       break;\r
-               case INyARBufferReader.BUFFERFORMAT_BYTE1D_X8R8G8B8_32:\r
-                       this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_X8R8G8B8_32();\r
-                       break;\r
-               case INyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32:\r
-                       this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_INT1D_X8R8G8B8_32();\r
-                       break;\r
-               case INyARBufferReader.BUFFERFORMAT_WORD1D_R5G6B5_16LE:\r
-                       this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_WORD1D_R5G6B5_16LE();\r
-                       break;\r
-               default:\r
+               if(!initInstance(i_threshold,i_in_raster_type,INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8)){\r
+                       throw new NyARException();\r
+               }\r
+       }\r
+       public NyARRasterFilter_ARToolkitThreshold(int i_threshold,int i_in_raster_type,int i_out_raster_type) throws NyARException\r
+       {\r
+               if(!initInstance(i_threshold,i_in_raster_type,i_out_raster_type)){\r
                        throw new NyARException();\r
                }\r
-\r
-               \r
        }\r
+       protected boolean initInstance(int i_threshold,int i_in_raster_type,int i_out_raster_type)\r
+       {\r
+               switch(i_out_raster_type){\r
+               case INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8:\r
+                       switch (i_in_raster_type){\r
+                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
+                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
+                               this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_RGB_24();\r
+                               break;\r
+                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:\r
+                               this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_B8G8R8X8_32();\r
+                               break;\r
+                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_X8R8G8B8_32:\r
+                               this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_X8R8G8B8_32();\r
+                               break;\r
+                       case INyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32:\r
+                               this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_INT1D_X8R8G8B8_32();\r
+                               break;\r
+                       case INyARBufferReader.BUFFERFORMAT_WORD1D_R5G6B5_16LE:\r
+                               this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_WORD1D_R5G6B5_16LE();\r
+                               break;\r
+                       default:\r
+                               return false;//サポートしない組み合わせ\r
+                       }\r
+                       break;\r
+               default:\r
+                       return false;//サポートしない組み合わせ\r
+               }\r
+               this._threshold = i_threshold;\r
+               return true;\r
+       }       \r
+       \r
        /**\r
         * 画像を2値化するための閾値。暗点<=th<明点となります。\r
         * @param i_threshold\r
@@ -57,7 +75,6 @@ public class NyARRasterFilter_ARToolkitThreshold implements INyARRasterFilter_Rg
                INyARBufferReader in_buffer_reader=i_input.getBufferReader();   \r
                INyARBufferReader out_buffer_reader=i_output.getBufferReader();\r
 \r
-               assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));\r
                assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
                this._do_threshold_impl.doThFilter(in_buffer_reader,out_buffer_reader,i_output.getSize(), this._threshold);\r
                return;\r
@@ -73,6 +90,8 @@ public class NyARRasterFilter_ARToolkitThreshold implements INyARRasterFilter_Rg
        {\r
                public void doThFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size,int i_threshold)\r
                {\r
+                       assert (i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));\r
+                       \r
                        int[] out_buf = (int[]) i_output.getBuffer();\r
                        byte[] in_buf = (byte[]) i_input.getBuffer();\r
                        \r
@@ -130,6 +149,9 @@ public class NyARRasterFilter_ARToolkitThreshold implements INyARRasterFilter_Rg
        {\r
                public void doThFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size,int i_threshold)\r
                {\r
+                       assert (i_input.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32));\r
+                       assert (i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));\r
+                       \r
                        int[] out_buf = (int[]) i_output.getBuffer();\r
                        byte[] in_buf = (byte[]) i_input.getBuffer();\r
                        \r
@@ -186,6 +208,8 @@ public class NyARRasterFilter_ARToolkitThreshold implements INyARRasterFilter_Rg
        {\r
                public void doThFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size,int i_threshold)\r
                {\r
+                       assert (i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));\r
+                       \r
                        int[] out_buf = (int[]) i_output.getBuffer();\r
                        byte[] in_buf = (byte[]) i_input.getBuffer();\r
                        \r
@@ -244,6 +268,8 @@ public class NyARRasterFilter_ARToolkitThreshold implements INyARRasterFilter_Rg
        {\r
                public void doThFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size,int i_threshold)\r
                {\r
+                       assert (i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));\r
+                       \r
                        int[] out_buf = (int[]) i_output.getBuffer();\r
                        int[] in_buf = (int[]) i_input.getBuffer();\r
                        \r
@@ -291,6 +317,8 @@ public class NyARRasterFilter_ARToolkitThreshold implements INyARRasterFilter_Rg
        {\r
                public void doThFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size,int i_threshold)\r
                {\r
+                       assert (i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));\r
+                       \r
                        int[] out_buf = (int[]) i_output.getBuffer();\r
                        short[] in_buf = (short[]) i_input.getBuffer();\r
                        \r
index e1e2ff5..4d2df26 100644 (file)
@@ -44,20 +44,42 @@ import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
 public class NyARRasterFilter_Rgb2Gs_AveAdd implements INyARRasterFilter_RgbToGs\r
 {\r
        IdoThFilterImpl _do_filter_impl;\r
-       public NyARRasterFilter_Rgb2Gs_AveAdd(int i_raster_type) throws NyARException\r
+       public NyARRasterFilter_Rgb2Gs_AveAdd(int i_in_raster_type,int i_out_raster_type) throws NyARException\r
        {\r
-               switch (i_raster_type) {\r
-               case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
-               case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
-                       this._do_filter_impl=new doThFilterImpl_BYTE1D_B8G8R8_24();\r
-                       break;\r
-               case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:\r
-                       this._do_filter_impl=new doThFilterImpl_BYTE1D_B8G8R8X8_32();\r
+               if(!initInstance(i_in_raster_type,i_out_raster_type))\r
+               {\r
+                       throw new NyARException();\r
+               }\r
+       }\r
+       public NyARRasterFilter_Rgb2Gs_AveAdd(int i_in_raster_type) throws NyARException\r
+       {\r
+               if(!initInstance(i_in_raster_type,INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8))\r
+               {\r
+                       throw new NyARException();\r
+               }\r
+       }\r
+       protected boolean initInstance(int i_in_raster_type,int i_out_raster_type)\r
+       {\r
+               switch(i_out_raster_type){\r
+               case INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8:\r
+                       switch (i_in_raster_type){\r
+                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
+                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
+                               this._do_filter_impl=new doThFilterImpl_BYTE1D_B8G8R8_24();\r
+                               break;\r
+                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:\r
+                               this._do_filter_impl=new doThFilterImpl_BYTE1D_B8G8R8X8_32();\r
+                               break;\r
+                       default:\r
+                               return false;\r
+                       }\r
                        break;\r
                default:\r
-                       throw new NyARException();\r
+                       return false;\r
                }\r
+               return true;\r
        }\r
+       \r
        public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException\r
        {\r
                INyARBufferReader in_buffer_reader=i_input.getBufferReader();   \r
@@ -79,6 +101,7 @@ public class NyARRasterFilter_Rgb2Gs_AveAdd implements INyARRasterFilter_RgbToGs
        {\r
                public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size)\r
                {\r
+                       assert(i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
                        int[] out_buf = (int[]) i_output.getBuffer();\r
                        byte[] in_buf = (byte[]) i_input.getBuffer();\r
                        \r
@@ -96,6 +119,7 @@ public class NyARRasterFilter_Rgb2Gs_AveAdd implements INyARRasterFilter_RgbToGs
        {\r
                public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size)\r
                {\r
+                       assert(i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
                        int[] out_buf = (int[]) i_output.getBuffer();\r
                        byte[] in_buf = (byte[]) i_input.getBuffer();\r
 \r
index c9ec345..7c88855 100644 (file)
@@ -48,17 +48,40 @@ import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
 public class NyARRasterFilter_Rgb2Gs_RgbCube implements INyARRasterFilter_RgbToGs\r
 {\r
        private IdoFilterImpl _dofilterimpl;\r
-       public NyARRasterFilter_Rgb2Gs_RgbCube(int i_raster_type) throws NyARException\r
+       public NyARRasterFilter_Rgb2Gs_RgbCube(int i_in_raster_type) throws NyARException\r
        {\r
-               switch (i_raster_type) {\r
-               case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
-               case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
-                       this._dofilterimpl=new IdoFilterImpl_BYTE1D_B8G8R8_24();\r
-                       break;\r
-               default:\r
+               if(!initInstance(i_in_raster_type,INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8))\r
+               {\r
                        throw new NyARException();\r
                }\r
        }\r
+       public NyARRasterFilter_Rgb2Gs_RgbCube(int i_in_raster_type,int i_out_raster) throws NyARException\r
+       {\r
+               if(!initInstance(i_in_raster_type,i_out_raster))\r
+               {\r
+                       throw new NyARException();\r
+               }\r
+       }       \r
+       protected boolean initInstance(int i_in_raster_type,int i_out_raster_type)\r
+       {\r
+               switch(i_out_raster_type){\r
+               case INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8:\r
+                       switch (i_in_raster_type) {\r
+                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
+                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
+                               this._dofilterimpl=new IdoFilterImpl_BYTE1D_B8G8R8_24();\r
+                               break;\r
+                       default:\r
+                               return false;\r
+                       }\r
+                       break;\r
+               default:\r
+                       return false;\r
+               }\r
+               return true;\r
+       }       \r
+       \r
+       \r
        public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException\r
        {\r
                assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
@@ -78,6 +101,7 @@ public class NyARRasterFilter_Rgb2Gs_RgbCube implements INyARRasterFilter_RgbToG
                {\r
                        assert(         i_input.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24)\r
                                        ||      i_input.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24));\r
+                       assert(i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
                        \r
                        int[] out_buf = (int[]) i_output.getBuffer();\r
                        byte[] in_buf = (byte[]) i_input.getBuffer();\r
index cd56979..1077340 100644 (file)
@@ -38,17 +38,39 @@ import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
 public class NyARRasterFilter_Rgb2Gs_YCbCr implements INyARRasterFilter_RgbToGs\r
 {\r
        private IdoFilterImpl _dofilterimpl;\r
-       public NyARRasterFilter_Rgb2Gs_YCbCr(int i_raster_type) throws NyARException\r
+       public NyARRasterFilter_Rgb2Gs_YCbCr(int i_in_raster_type) throws NyARException\r
        {\r
-               switch (i_raster_type) {\r
-               case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
-                       this._dofilterimpl=new IdoFilterImpl_BYTE1D_B8G8R8_24();\r
-                       break;\r
-               case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
-               default:\r
+               if(!initInstance(i_in_raster_type,INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8))\r
+               {\r
                        throw new NyARException();\r
                }\r
        }\r
+       public NyARRasterFilter_Rgb2Gs_YCbCr(int i_in_raster_type,int i_out_raster) throws NyARException\r
+       {\r
+               if(!initInstance(i_in_raster_type,i_out_raster))\r
+               {\r
+                       throw new NyARException();\r
+               }\r
+       }       \r
+       protected boolean initInstance(int i_in_raster_type,int i_out_raster_type)\r
+       {\r
+               switch(i_out_raster_type){\r
+               case INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8:\r
+                       switch (i_in_raster_type) {\r
+                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
+                               this._dofilterimpl=new IdoFilterImpl_BYTE1D_B8G8R8_24();\r
+                               break;\r
+                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
+                       default:\r
+                               return false;\r
+                       }\r
+                       break;\r
+               default:\r
+                       return false;\r
+               }\r
+               return true;\r
+       }       \r
+       \r
        public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException\r
        {\r
                assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
@@ -66,7 +88,8 @@ public class NyARRasterFilter_Rgb2Gs_YCbCr implements INyARRasterFilter_RgbToGs
                 */\r
                public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) throws NyARException\r
                {\r
-                       assert(         i_input.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24));\r
+                       assert( i_input.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24));\r
+                       assert(i_output.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8));\r
                        \r
                        int[] out_buf = (int[]) i_output.getBuffer();\r
                        byte[] in_buf = (byte[]) i_input.getBuffer();\r
diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARVectorReader_INT1D_GRAY_8.java b/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARVectorReader_INT1D_GRAY_8.java
new file mode 100644 (file)
index 0000000..41ea65a
--- /dev/null
@@ -0,0 +1,83 @@
+/* \r
+ * PROJECT: NyARToolkit(Extension)\r
+ * --------------------------------------------------------------------------------\r
+ * The NyARToolkit is Java edition ARToolKit class library.\r
+ * Copyright (C)2008-2009 Ryo Iizuka\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+ * \r
+ * For further information please contact.\r
+ *     http://nyatla.jp/nyatoolkit/\r
+ *     <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core.rasterreader;\r
+\r
+import jp.nyatla.nyartoolkit.core.raster.INyARRaster;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntPoint2d;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
+\r
+public         class NyARVectorReader_INT1D_GRAY_8\r
+{\r
+       private int[] _ref_buf;\r
+       private NyARIntSize _ref_size;\r
+       public NyARVectorReader_INT1D_GRAY_8(INyARRaster i_ref_raster)\r
+       {\r
+               assert(i_ref_raster.getBufferReader().getBufferType()==INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8);\r
+               this._ref_buf=(int[])(i_ref_raster.getBufferReader().getBuffer());\r
+               this._ref_size=i_ref_raster.getSize();\r
+       }\r
+       /**\r
+        * 4近傍の画素ベクトルを取得します。\r
+        * 0,1,0\r
+        * 1,x,1\r
+        * 0,1,0\r
+        * @param i_raster\r
+        * @param x\r
+        * @param y\r
+        * @param o_v\r
+        */\r
+       public void getPixelVector4(int x,int y,NyARIntPoint2d o_v)\r
+       {\r
+               int[] buf=this._ref_buf;\r
+               int w=this._ref_size.w;\r
+               int idx=w*y+x;\r
+               o_v.x=buf[idx+1]-buf[idx-1];\r
+               o_v.y=buf[idx+w]-buf[idx-w];\r
+       }\r
+       /**\r
+        * 8近傍画素ベクトル\r
+        * 1,2,1\r
+        * 2,x,2\r
+        * 1,2,1\r
+        * @param i_raster\r
+        * @param x\r
+        * @param y\r
+        * @param o_v\r
+        */\r
+       public void getPixelVector8(int x,int y,NyARIntPoint2d o_v)\r
+       {\r
+               int[] buf=this._ref_buf;\r
+               NyARIntSize s=this._ref_size;\r
+               int idx_0 =s.w*y+x;\r
+               int idx_p1=idx_0+s.w;\r
+               int idx_m1=idx_0-s.w;\r
+               int b=buf[idx_m1-1];\r
+               int d=buf[idx_m1+1];\r
+               int h=buf[idx_p1-1];\r
+               int f=buf[idx_p1+1];\r
+               o_v.x=buf[idx_0+1]-buf[idx_0-1]+(d-b+f-h)/2;\r
+               o_v.y=buf[idx_p1]-buf[idx_m1]+(f-d+h-b)/2;\r
+       }       \r
+}
\ No newline at end of file