X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=trunk%2Fsrc%2Fjp%2Fnyatla%2Fnyartoolkit%2Fcore%2Frasterfilter%2Frgb2gs%2FNyARRasterFilter_Rgb2Gs_AveAdd.java;h=98b3dec52b8217fb7bad47edd432a1f2c09588a6;hb=170d605d7affbec948c758c097022730aad651b6;hp=e1e2ff52e9d982a688de55c855699de14f711b3f;hpb=dcb6552021c557fe584cafaa21c0d753c4008303;p=nyartoolkit-and%2Fnyartoolkit-and.git diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2gs/NyARRasterFilter_Rgb2Gs_AveAdd.java b/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2gs/NyARRasterFilter_Rgb2Gs_AveAdd.java index e1e2ff5..98b3dec 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2gs/NyARRasterFilter_Rgb2Gs_AveAdd.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2gs/NyARRasterFilter_Rgb2Gs_AveAdd.java @@ -33,7 +33,7 @@ package jp.nyatla.nyartoolkit.core.rasterfilter.rgb2gs; import jp.nyatla.nyartoolkit.NyARException; import jp.nyatla.nyartoolkit.core.raster.*; import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster; -import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader; +import jp.nyatla.nyartoolkit.core.types.NyARBufferType; import jp.nyatla.nyartoolkit.core.types.NyARIntSize; /** @@ -41,29 +41,49 @@ import jp.nyatla.nyartoolkit.core.types.NyARIntSize; * このフィルタは、RGB値の平均値を、(R+G+B)/3で算出します。 * */ -public class NyARRasterFilter_Rgb2Gs_AveAdd implements INyARRasterFilter_RgbToGs +public class NyARRasterFilter_Rgb2Gs_AveAdd implements INyARRasterFilter_Rgb2Gs { IdoThFilterImpl _do_filter_impl; - public NyARRasterFilter_Rgb2Gs_AveAdd(int i_raster_type) throws NyARException + public NyARRasterFilter_Rgb2Gs_AveAdd(int i_in_raster_type,int i_out_raster_type) throws NyARException { - switch (i_raster_type) { - case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24: - case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24: - this._do_filter_impl=new doThFilterImpl_BYTE1D_B8G8R8_24(); - break; - case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32: - this._do_filter_impl=new doThFilterImpl_BYTE1D_B8G8R8X8_32(); + if(!initInstance(i_in_raster_type,i_out_raster_type)) + { + throw new NyARException(); + } + } + public NyARRasterFilter_Rgb2Gs_AveAdd(int i_in_raster_type) throws NyARException + { + if(!initInstance(i_in_raster_type,NyARBufferType.INT1D_GRAY_8)) + { + throw new NyARException(); + } + } + protected boolean initInstance(int i_in_raster_type,int i_out_raster_type) + { + switch(i_out_raster_type){ + case NyARBufferType.INT1D_GRAY_8: + switch (i_in_raster_type){ + case NyARBufferType.BYTE1D_B8G8R8_24: + case NyARBufferType.BYTE1D_R8G8B8_24: + this._do_filter_impl=new doThFilterImpl_BYTE1D_B8G8R8_24(); + break; + case NyARBufferType.BYTE1D_B8G8R8X8_32: + this._do_filter_impl=new doThFilterImpl_BYTE1D_B8G8R8X8_32(); + break; + default: + return false; + } break; default: - throw new NyARException(); + return false; } + return true; } + public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException { - INyARBufferReader in_buffer_reader=i_input.getBufferReader(); - INyARBufferReader out_buffer_reader=i_output.getBufferReader(); assert (i_input.getSize().isEqualSize(i_output.getSize()) == true); - this._do_filter_impl.doFilter(in_buffer_reader,out_buffer_reader,i_input.getSize()); + this._do_filter_impl.doFilter(i_input,i_output,i_input.getSize()); return; } @@ -73,12 +93,13 @@ public class NyARRasterFilter_Rgb2Gs_AveAdd implements INyARRasterFilter_RgbToGs */ interface IdoThFilterImpl { - public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size); + public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size); } class doThFilterImpl_BYTE1D_B8G8R8_24 implements IdoThFilterImpl { - public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) + public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size) { + assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8)); int[] out_buf = (int[]) i_output.getBuffer(); byte[] in_buf = (byte[]) i_input.getBuffer(); @@ -94,8 +115,9 @@ public class NyARRasterFilter_Rgb2Gs_AveAdd implements INyARRasterFilter_RgbToGs } class doThFilterImpl_BYTE1D_B8G8R8X8_32 implements IdoThFilterImpl { - public void doFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size) + public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size) { + assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8)); int[] out_buf = (int[]) i_output.getBuffer(); byte[] in_buf = (byte[]) i_input.getBuffer();