OSDN Git Service

[backup]NyARToolkit
[nyartoolkit-and/nyartoolkit-and.git] / trunk / src / jp / nyatla / nyartoolkit / core / rasterfilter / rgb2gs / NyARRasterFilter_Rgb2Gs_AveAdd.java
index e1e2ff5..661774a 100644 (file)
@@ -33,7 +33,6 @@ package jp.nyatla.nyartoolkit.core.rasterfilter.rgb2gs;
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.raster.*;\r
 import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster;\r
-import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
 import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
 \r
 /**\r
@@ -41,29 +40,49 @@ import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
  * このフィルタは、RGB値の平均値を、(R+G+B)/3で算出します。\r
  *\r
  */\r
-public class NyARRasterFilter_Rgb2Gs_AveAdd implements INyARRasterFilter_RgbToGs\r
+public class NyARRasterFilter_Rgb2Gs_AveAdd implements INyARRasterFilter_Rgb2Gs\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,INyARRaster.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 INyARRaster.BUFFERFORMAT_INT1D_GRAY_8:\r
+                       switch (i_in_raster_type){\r
+                       case INyARRaster.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
+                       case INyARRaster.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
+                               this._do_filter_impl=new doThFilterImpl_BYTE1D_B8G8R8_24();\r
+                               break;\r
+                       case INyARRaster.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
-               INyARBufferReader out_buffer_reader=i_output.getBufferReader(); \r
                assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
-               this._do_filter_impl.doFilter(in_buffer_reader,out_buffer_reader,i_input.getSize());\r
+               this._do_filter_impl.doFilter(i_input,i_output,i_input.getSize());\r
                return;\r
        }\r
        \r
@@ -73,12 +92,13 @@ public class NyARRasterFilter_Rgb2Gs_AveAdd implements INyARRasterFilter_RgbToGs
         */\r
        interface IdoThFilterImpl\r
        {\r
-               public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size);\r
+               public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size);\r
        }\r
        class doThFilterImpl_BYTE1D_B8G8R8_24 implements IdoThFilterImpl\r
        {\r
-               public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size)\r
+               public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size)\r
                {\r
+                       assert(i_output.isEqualBufferType(INyARRaster.BUFFERFORMAT_INT1D_GRAY_8));\r
                        int[] out_buf = (int[]) i_output.getBuffer();\r
                        byte[] in_buf = (byte[]) i_input.getBuffer();\r
                        \r
@@ -94,8 +114,9 @@ public class NyARRasterFilter_Rgb2Gs_AveAdd implements INyARRasterFilter_RgbToGs
        }\r
        class doThFilterImpl_BYTE1D_B8G8R8X8_32 implements IdoThFilterImpl\r
        {\r
-               public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size)\r
+               public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size)\r
                {\r
+                       assert(i_output.isEqualBufferType(INyARRaster.BUFFERFORMAT_INT1D_GRAY_8));\r
                        int[] out_buf = (int[]) i_output.getBuffer();\r
                        byte[] in_buf = (byte[]) i_input.getBuffer();\r
 \r