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.NyARBufferType;\r
import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
\r
/**\r
* このフィルタは、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,NyARBufferType.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 NyARBufferType.INT1D_GRAY_8:\r
+ switch (i_in_raster_type){\r
+ case NyARBufferType.BYTE1D_B8G8R8_24:\r
+ case NyARBufferType.BYTE1D_R8G8B8_24:\r
+ this._do_filter_impl=new doThFilterImpl_BYTE1D_B8G8R8_24();\r
+ break;\r
+ case NyARBufferType.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
*/\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(NyARBufferType.INT1D_GRAY_8));\r
int[] out_buf = (int[]) i_output.getBuffer();\r
byte[] in_buf = (byte[]) i_input.getBuffer();\r
\r
}\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(NyARBufferType.INT1D_GRAY_8));\r
int[] out_buf = (int[]) i_output.getBuffer();\r
byte[] in_buf = (byte[]) i_input.getBuffer();\r
\r