public override void generate(RGBA_Bytes[] span, int spanIndex, int x, int y, int len) { ImageBuffer SourceRenderingBuffer = (ImageBuffer)GetImageBufferAccessor().SourceImage; if (SourceRenderingBuffer.BitDepth != 24) { throw new NotSupportedException("The source is expected to be 32 bit."); } ISpanInterpolator spanInterpolator = interpolator(); spanInterpolator.begin(x + filter_dx_dbl(), y + filter_dy_dbl(), len); int offset; byte[] fg_ptr = SourceRenderingBuffer.GetBuffer(out offset); do { int x_hr; int y_hr; spanInterpolator.coordinates(out x_hr, out y_hr); int x_lr = x_hr >> (int)image_subpixel_scale_e.image_subpixel_shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.image_subpixel_shift; int bufferIndex; bufferIndex = SourceRenderingBuffer.GetBufferOffsetXY(x_lr, y_lr); RGBA_Bytes color; color.blue = fg_ptr[bufferIndex++]; color.green = fg_ptr[bufferIndex++]; color.red = fg_ptr[bufferIndex++]; color.alpha = 255; span[spanIndex] = color; spanIndex++; spanInterpolator.Next(); } while (--len != 0); }
//-------------------------------------------------------------------- public void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len) { m_interpolator.Begin(x + 0.5, y + 0.5, len); do { m_interpolator.GetCoord(out x, out y); float d = m_grValueCalculator.Calculate(x >> DOWN_SCALE_SHIFT, y >> DOWN_SCALE_SHIFT, m_d2); d = ((d - m_d1) * stepRatio); if (d < 0) { d = 0; } if (d >= m_colorsProvider.GradientSteps) { d = m_colorsProvider.GradientSteps - 1; } outputColors[startIndex++] = m_colorsProvider.GetColor((int)d); m_interpolator.Next(); }while (--len != 0); }
public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len) { RasterBuffer pSourceRenderingBuffer = base.Source().PixelFormat.GetRenderingBuffer(); ISpanInterpolator <T> spanInterpolator = base.Interpolator; spanInterpolator.Begin(M.New <T>(x).Add(base.FilterDxDbl()), M.New <T>(y).Add(base.FilterDyDbl()), len); do { int x_hr; int y_hr; spanInterpolator.Coordinates(out x_hr, out y_hr); int x_lr = x_hr >> (int)image_subpixel_scale_e.Shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift; byte *fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2); //byte* fg_ptr = spanInterpolator.span(x_lr, y_lr, 1); //(*span).R = fg_ptr[OrderR]; //(*span).G = fg_ptr[OrderG]; //(*span).B = fg_ptr[OrderB]; //(*span).A = fg_ptr[OrderA]; (*span) = new RGBA_Bytes(fg_ptr[OrderR], fg_ptr[OrderG], fg_ptr[OrderB], fg_ptr[OrderA]); ++span; spanInterpolator.Next(); } while (--len != 0); }
//-------------------------------------------------------------------- public unsafe void Generate(RGBA_Bytes *span, int x, int y, uint len) { int dd = m_d2 - m_d1; if (dd < 1) { dd = 1; } m_interpolator.Begin(x + 0.5, y + 0.5, len); do { m_interpolator.Coordinates(out x, out y); int d = m_gradient_function.Calculate(x >> downscale_shift, y >> downscale_shift, m_d2); d = ((d - m_d1) * (int)m_color_function.Size) / dd; if (d < 0) { d = 0; } if (d >= (int)m_color_function.Size) { d = m_color_function.Size - 1; } *span++ = m_color_function[d]; m_interpolator.Next(); }while(--len != 0); }
//-------------------------------------------------------------------- public void generate(Color[] span, int spanIndex, int x, int y, int len) { int dd = m_d2 - m_d1; if (dd < 1) { dd = 1; } m_interpolator.begin(x + 0.5, y + 0.5, len); do { m_interpolator.coordinates(out x, out y); int d = m_gradient_function.calculate(x >> downscale_shift, y >> downscale_shift, m_d2); d = ((d - m_d1) * (int)m_color_function.size()) / dd; if (d < 0) { d = 0; } if (d >= (int)m_color_function.size()) { d = m_color_function.size() - 1; } span[spanIndex++] = m_color_function[d]; m_interpolator.Next(); }while (--len != 0); }
public override void GenerateColors(Drawing.Color[] outputColors, int startIndex, int x, int y, int len) { if (_noTransformation) { //Interpolator.GetCoord(out int x_hr, out int y_hr); //int x_lr = x_hr >> subpix_const.SHIFT; //int y_lr = y_hr >> subpix_const.SHIFT; Interpolator.SubPixTranslateBeginCoord(x + dx, y + dy, out int x_lr, out int y_lr); NN_StepXBy1(_bmpSrc, _bmpSrc.GetBufferOffsetXY32(x_lr, y_lr), outputColors, startIndex, len); } else { ISpanInterpolator spanInterpolator = Interpolator; spanInterpolator.Begin(x + dx, y + dy, len); unsafe { using (TempMemPtr.FromBmp(_bmpSrc, out int *srcBuffer)) { //TODO: if no any transformation,=> skip spanInterpolator (see above example) do { //spanInterpolator.GetCoord(out int x_hr, out int y_hr); //int x_lr = x_hr >> subpix_const.SHIFT; //int y_lr = y_hr >> subpix_const.SHIFT; spanInterpolator.SubPixGetTranslatedCoord(out int x_lr, out int y_lr); int bufferIndex = _bmpSrc.GetBufferOffsetXY32(x_lr, y_lr); int srcColor = srcBuffer[bufferIndex++]; outputColors[startIndex] = Drawing.Color.FromArgb( (srcColor >> CO.A_SHIFT) & 0xff, //a (srcColor >> CO.R_SHIFT) & 0xff, //r (srcColor >> CO.G_SHIFT) & 0xff, //g (srcColor >> CO.B_SHIFT) & 0xff); //b ++startIndex; spanInterpolator.Next(); } while (--len != 0); } } } }
//---------------------------------------------------------------- public void Next() { m_interpolator.Next(); if (m_pos >= m_subdiv_size) { uint len = m_len; if (len > m_subdiv_size) { len = (uint)m_subdiv_size; } m_interpolator.Resynchronize(M.New <T>(m_src_x).Divide((double)SubPixelScale).Add(len), m_src_y, len); m_pos = 0; } m_src_x += SubPixelScale; ++m_pos; --m_len; }
//---------------------------------------------------------------- public void Next() { m_interpolator.Next(); if (m_pos >= m_subdiv_size) { uint len = m_len; if (len > m_subdiv_size) { len = (uint)m_subdiv_size; } m_interpolator.ReSynchronize((double)m_src_x / (double)subpixel_scale + len, m_src_y, len); m_pos = 0; } m_src_x += subpixel_scale; ++m_pos; --m_len; }
public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len) { RasterBuffer pSourceRenderingBuffer = base.source().PixelFormat.RenderingBuffer; ISpanInterpolator spanInterpolator = base.interpolator(); spanInterpolator.Begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len); do { int x_hr; int y_hr; spanInterpolator.Coordinates(out x_hr, out y_hr); int x_lr = x_hr >> (int)image_subpixel_scale_e.Shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift; byte *fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2); //byte* fg_ptr = spanInterpolator.Span(x_lr, y_lr, 1); (*span).m_R = fg_ptr[OrderR]; (*span).m_G = fg_ptr[OrderG]; (*span).m_B = fg_ptr[OrderB]; (*span).m_A = fg_ptr[OrderA]; ++span; spanInterpolator.Next(); } while(--len != 0); }
//-------------------------------------------------------------------- public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len) { ISpanInterpolator spanInterpolator = base.interpolator(); spanInterpolator.Begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len); int *fg = stackalloc int[3]; byte *fg_ptr; fixed(short *pWeightArray = filter().weight_array()) { short *weight_array = pWeightArray; weight_array = &pWeightArray[((filter().diameter() / 2 - 1) << (int)image_subpixel_scale_e.Shift)]; do { int x_hr; int y_hr; spanInterpolator.Coordinates(out x_hr, out y_hr); x_hr -= filter_dx_int(); y_hr -= filter_dy_int(); int x_lr = x_hr >> (int)image_subpixel_scale_e.Shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift; uint weight; fg[0] = fg[1] = fg[2] = (int)image_filter_scale_e.Scale / 2; x_hr &= (int)image_subpixel_scale_e.Mask; y_hr &= (int)image_subpixel_scale_e.Mask; fg_ptr = source().Span(x_lr, y_lr, 2); weight = (uint)((weight_array[x_hr + (int)image_subpixel_scale_e.Scale] * weight_array[y_hr + (int)image_subpixel_scale_e.Scale] + (int)image_filter_scale_e.Scale / 2) >> (int)image_filter_scale_e.Shift); fg[0] += (int)weight * *fg_ptr++; fg[1] += (int)weight * *fg_ptr++; fg[2] += (int)weight * *fg_ptr; fg_ptr = source().NextX(); weight = (uint)((weight_array[x_hr] * weight_array[y_hr + (int)image_subpixel_scale_e.Scale] + (int)image_filter_scale_e.Scale / 2) >> (int)image_filter_scale_e.Shift); fg[0] += (int)weight * *fg_ptr++; fg[1] += (int)weight * *fg_ptr++; fg[2] += (int)weight * *fg_ptr; fg_ptr = source().NextY(); weight = (uint)((weight_array[x_hr + (int)image_subpixel_scale_e.Scale] * weight_array[y_hr] + (int)image_filter_scale_e.Scale / 2) >> (int)image_filter_scale_e.Shift); fg[0] += (int)weight * *fg_ptr++; fg[1] += (int)weight * *fg_ptr++; fg[2] += (int)weight * *fg_ptr; fg_ptr = source().NextX(); weight = (uint)((weight_array[x_hr] * weight_array[y_hr] + (int)image_filter_scale_e.Scale / 2) >> (int)image_filter_scale_e.Shift); fg[0] += (int)weight * *fg_ptr++; fg[1] += (int)weight * *fg_ptr++; fg[2] += (int)weight * *fg_ptr; fg[0] >>= (int)image_filter_scale_e.Shift; fg[1] >>= (int)image_filter_scale_e.Shift; fg[2] >>= (int)image_filter_scale_e.Shift; if (fg[OrderR] > base_mask) { fg[OrderR] = base_mask; } if (fg[OrderG] > base_mask) { fg[OrderG] = base_mask; } if (fg[OrderB] > base_mask) { fg[OrderB] = base_mask; } span->R_Byte = (byte)fg[OrderR]; span->G_Byte = (byte)fg[OrderG]; span->B_Byte = (byte)fg[OrderB]; span->A_Byte = (uint)base_mask; ++span; spanInterpolator.Next(); } while (--len != 0); } }
//-------------------------------------------------------------------- public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len) { base.interpolator().Begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len); int *fg = stackalloc int[3]; byte *fg_ptr; uint diameter = m_filter.diameter(); int start = m_filter.start(); short[] weight_array = m_filter.weight_array(); int x_count; int weight_y; ISpanInterpolator spanInterpolator = base.interpolator(); do { spanInterpolator.Coordinates(out x, out y); x -= base.filter_dx_int(); y -= base.filter_dy_int(); int x_hr = x; int y_hr = y; int x_lr = x_hr >> (int)image_subpixel_scale_e.Shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift; fg[0] = fg[1] = fg[2] = (int)image_filter_scale_e.Scale / 2; int x_fract = x_hr & (int)image_subpixel_scale_e.Mask; uint y_count = diameter; y_hr = (int)image_subpixel_scale_e.Mask - (y_hr & (int)image_subpixel_scale_e.Mask); fg_ptr = source().Span(x_lr + start, y_lr + start, diameter); for (; ;) { x_count = (int)diameter; weight_y = weight_array[y_hr]; x_hr = (int)image_subpixel_scale_e.Mask - x_fract; for (; ;) { int weight = (weight_y * weight_array[x_hr] + (int)image_filter_scale_e.Scale / 2) >> (int)image_filter_scale_e.Shift; fg[0] += weight * *fg_ptr++; fg[1] += weight * *fg_ptr++; fg[2] += weight * *fg_ptr; if (--x_count == 0) { break; } x_hr += (int)image_subpixel_scale_e.Scale; fg_ptr = source().NextX(); } if (--y_count == 0) { break; } y_hr += (int)image_subpixel_scale_e.Scale; fg_ptr = source().NextY(); } fg[0] >>= (int)image_filter_scale_e.Shift; fg[1] >>= (int)image_filter_scale_e.Shift; fg[2] >>= (int)image_filter_scale_e.Shift; if (fg[0] < 0) { fg[0] = 0; } if (fg[1] < 0) { fg[1] = 0; } if (fg[2] < 0) { fg[2] = 0; } if (fg[OrderR] > base_mask) { fg[OrderR] = (int)base_mask; } if (fg[OrderG] > base_mask) { fg[OrderG] = (int)base_mask; } if (fg[OrderB] > base_mask) { fg[OrderB] = (int)base_mask; } span->R_Byte = (Byte)fg[OrderR]; span->G_Byte = (Byte)fg[OrderG]; span->B_Byte = (Byte)fg[OrderB]; span->A_Byte = base_mask; ++span; spanInterpolator.Next(); } while (--len != 0); }
public override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len) { ISpanInterpolator spanInterpolator = base.Interpolator; spanInterpolator.Begin(x + base.dx, y + base.dy, len); int c0, c1, c2; int diameter = base.FilterLookup.Diameter; int filter_scale = diameter << img_subpix_const.SHIFT; int[] weight_array = FilterLookup.WeightArray; do { int rx; int ry; int rx_inv = img_subpix_const.SCALE; int ry_inv = img_subpix_const.SCALE; spanInterpolator.GetCoord(out x, out y); spanInterpolator.GetLocalScale(out rx, out ry); AdjustScale(ref rx, ref ry); rx_inv = img_subpix_const.SCALE * img_subpix_const.SCALE / rx; ry_inv = img_subpix_const.SCALE * img_subpix_const.SCALE / ry; int radius_x = (diameter * rx) >> 1; int radius_y = (diameter * ry) >> 1; int len_x_lr = (diameter * rx + img_subpix_const.MASK) >> img_subpix_const.SHIFT; x += base.dxInt - radius_x; y += base.dyInt - radius_y; c0 = c1 = c2 = img_filter_const.SCALE / 2; int y_lr = y >> img_subpix_const.SHIFT; int y_hr = ((img_subpix_const.MASK - (y & img_subpix_const.MASK)) * ry_inv) >> img_subpix_const.SHIFT; int total_weight = 0; int x_lr = x >> img_subpix_const.SHIFT; int x_hr = ((img_subpix_const.MASK - (x & img_subpix_const.MASK)) * rx_inv) >> img_subpix_const.SHIFT; int x_hr2 = x_hr; int sourceIndex; byte[] buff = BaseGetSpan(x_lr, y_lr, len_x_lr, out sourceIndex); for (;;) { int weight_y = weight_array[y_hr]; x_hr = x_hr2; for (;;) { int weight = (weight_y * weight_array[x_hr] + (int)img_filter_const.SCALE / 2) >> DOWNSCALE_SHIFT; c0 += buff[sourceIndex + CO.R] * weight; c1 += buff[sourceIndex + CO.G] * weight; c2 += buff[sourceIndex + CO.B] * weight; total_weight += weight; x_hr += rx_inv; if (x_hr >= filter_scale) { break; } buff = BaseNextX(out sourceIndex); } y_hr += ry_inv; if (y_hr >= filter_scale) { break; } buff = BaseNextY(out sourceIndex); } c0 /= total_weight; c1 /= total_weight; c2 /= total_weight; //clamps.. if (c0 < 0) { c0 = 0; } else if (c0 > BASE_MASK) { c0 = BASE_MASK; } if (c1 < 0) { c1 = 0; } else if (c1 > BASE_MASK) { c1 = BASE_MASK; } if (c2 < 0) { c2 = 0; } else if (c2 > BASE_MASK) { c2 = BASE_MASK; } outputColors[startIndex].alpha = BASE_MASK; outputColors[startIndex].red = (byte)c0; outputColors[startIndex].green = (byte)c1; outputColors[startIndex].blue = (byte)c2; startIndex++; spanInterpolator.Next(); } while (--len != 0); }
//-------------------------------------------------------------------- public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len) { base.Interpolator.Begin(M.New <T>(x).Add(base.FilterDxDbl()), M.New <T>(y).Add(base.FilterDyDbl()), len); int *fg = stackalloc int[3]; byte *fg_ptr; uint diameter = m_filter.Diameter(); int start = m_filter.Start(); short[] weight_array = m_filter.WeightArray(); int x_count; int weight_y; ISpanInterpolator <T> spanInterpolator = base.Interpolator; do { spanInterpolator.Coordinates(out x, out y); x -= base.FilterDxInt(); y -= base.FilterDyInt(); int x_hr = x; int y_hr = y; int x_lr = x_hr >> (int)image_subpixel_scale_e.Shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift; fg[0] = fg[1] = fg[2] = (int)image_filter_scale_e.Scale / 2; int x_fract = x_hr & (int)image_subpixel_scale_e.Mask; uint y_count = diameter; y_hr = (int)image_subpixel_scale_e.Mask - (y_hr & (int)image_subpixel_scale_e.Mask); fg_ptr = Source().span(x_lr + start, y_lr + start, diameter); for (; ;) { x_count = (int)diameter; weight_y = weight_array[y_hr]; x_hr = (int)image_subpixel_scale_e.Mask - x_fract; for (; ;) { int weight = (weight_y * weight_array[x_hr] + (int)image_filter_scale_e.Scale / 2) >> (int)image_filter_scale_e.Shift; fg[0] += weight * *fg_ptr++; fg[1] += weight * *fg_ptr++; fg[2] += weight * *fg_ptr; if (--x_count == 0) { break; } x_hr += (int)image_subpixel_scale_e.Scale; fg_ptr = Source().next_x(); } if (--y_count == 0) { break; } y_hr += (int)image_subpixel_scale_e.Scale; fg_ptr = Source().next_y(); } fg[0] >>= (int)image_filter_scale_e.Shift; fg[1] >>= (int)image_filter_scale_e.Shift; fg[2] >>= (int)image_filter_scale_e.Shift; if (fg[0] < 0) { fg[0] = 0; } if (fg[1] < 0) { fg[1] = 0; } if (fg[2] < 0) { fg[2] = 0; } if (fg[OrderR] > BaseMask) { fg[OrderR] = (int)BaseMask; } if (fg[OrderG] > BaseMask) { fg[OrderG] = (int)BaseMask; } if (fg[OrderB] > BaseMask) { fg[OrderB] = (int)BaseMask; } //span->R_Byte = (Byte)fg[OrderR]; //span->G_Byte = (Byte)fg[OrderG]; //span->B_Byte = (Byte)fg[OrderB]; //span->A_Byte = BaseMask; (*span) = new RGBA_Bytes((Byte)fg[OrderR], (Byte)fg[OrderG], (Byte)fg[OrderB], BaseMask); ++span; spanInterpolator.Next(); } while (--len != 0); }
public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len) { #if use_timers Generate_Span.Start(); #endif base.Interpolator.Begin(M.New <T>(x).Add(base.FilterDxDbl()), M.New <T>(y).Add(base.FilterDyDbl()), len); uint *fg = stackalloc uint[4]; byte *fg_ptr; RasterBuffer pSourceRenderingBuffer = base.Source().PixelFormat.GetRenderingBuffer(); int maxx = (int)pSourceRenderingBuffer.Width - 1; int maxy = (int)pSourceRenderingBuffer.Height - 1; ISpanInterpolator <T> spanInterpolator = base.Interpolator; unchecked { do { int x_hr; int y_hr; spanInterpolator.Coordinates(out x_hr, out y_hr); x_hr -= base.FilterDxInt(); y_hr -= base.FilterDyInt(); int x_lr = x_hr >> (int)image_subpixel_scale_e.Shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift; uint weight; fg[0] = fg[1] = fg[2] = fg[3] = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / 2; x_hr &= (int)image_subpixel_scale_e.Mask; y_hr &= (int)image_subpixel_scale_e.Mask; fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2); weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * ((int)image_subpixel_scale_e.Scale - y_hr)); fg[0] += weight * fg_ptr[0]; fg[1] += weight * fg_ptr[1]; fg[2] += weight * fg_ptr[2]; fg[3] += weight * fg_ptr[3]; weight = (uint)(x_hr * ((int)image_subpixel_scale_e.Scale - y_hr)); fg[0] += weight * fg_ptr[4]; fg[1] += weight * fg_ptr[5]; fg[2] += weight * fg_ptr[6]; fg[3] += weight * fg_ptr[7]; ++y_lr; fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2); weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * y_hr); fg[0] += weight * fg_ptr[0]; fg[1] += weight * fg_ptr[1]; fg[2] += weight * fg_ptr[2]; fg[3] += weight * fg_ptr[3]; weight = (uint)(x_hr * y_hr); fg[0] += weight * fg_ptr[4]; fg[1] += weight * fg_ptr[5]; fg[2] += weight * fg_ptr[6]; fg[3] += weight * fg_ptr[7]; fg[0] >>= (int)image_subpixel_scale_e.Shift * 2; fg[1] >>= (int)image_subpixel_scale_e.Shift * 2; fg[2] >>= (int)image_subpixel_scale_e.Shift * 2; fg[3] >>= (int)image_subpixel_scale_e.Shift * 2; //(*span).R = (byte)fg[OrderR]; //(*span).G = (byte)fg[OrderG]; //(*span).B = (byte)fg[OrderB]; //(*span).A = (byte)fg[OrderA]; (*span) = new RGBA_Bytes((byte)fg[OrderR], (byte)fg[OrderG], (byte)fg[OrderB], (byte)fg[OrderA]); ++span; spanInterpolator.Next(); } while (--len != 0); } #if use_timers Generate_Span.Stop(); #endif }
public override void generate(RGBA_Bytes[] span, int spanIndex, int x, int y, int len) { base.interpolator().begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len); int f_r, f_g, f_b; byte[] fg_ptr; int diameter = m_filter.diameter(); int start = m_filter.start(); int[] weight_array = m_filter.weight_array(); int x_count; int weight_y; ISpanInterpolator spanInterpolator = base.interpolator(); do { spanInterpolator.coordinates(out x, out y); x -= base.filter_dx_int(); y -= base.filter_dy_int(); int x_hr = x; int y_hr = y; int x_lr = x_hr >> (int)image_subpixel_scale_e.image_subpixel_shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.image_subpixel_shift; f_b = f_g = f_r = (int)image_filter_scale_e.image_filter_scale / 2; int x_fract = x_hr & (int)image_subpixel_scale_e.image_subpixel_mask; int y_count = diameter; y_hr = (int)image_subpixel_scale_e.image_subpixel_mask - (y_hr & (int)image_subpixel_scale_e.image_subpixel_mask); int bufferIndex; fg_ptr = GetImageBufferAccessor().span(x_lr + start, y_lr + start, diameter, out bufferIndex); for (; ;) { x_count = (int)diameter; weight_y = weight_array[y_hr]; x_hr = (int)image_subpixel_scale_e.image_subpixel_mask - x_fract; for (; ;) { int weight = (weight_y * weight_array[x_hr] + (int)image_filter_scale_e.image_filter_scale / 2) >> (int)image_filter_scale_e.image_filter_shift; f_b += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR]; f_g += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG]; f_r += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB]; if (--x_count == 0) { break; } x_hr += (int)image_subpixel_scale_e.image_subpixel_scale; GetImageBufferAccessor().next_x(out bufferIndex); } if (--y_count == 0) { break; } y_hr += (int)image_subpixel_scale_e.image_subpixel_scale; fg_ptr = GetImageBufferAccessor().next_y(out bufferIndex); } f_b >>= (int)image_filter_scale_e.image_filter_shift; f_g >>= (int)image_filter_scale_e.image_filter_shift; f_r >>= (int)image_filter_scale_e.image_filter_shift; unchecked { if ((uint)f_b > base_mask) { if (f_b < 0) { f_b = 0; } if (f_b > base_mask) { f_b = (int)base_mask; } } if ((uint)f_g > base_mask) { if (f_g < 0) { f_g = 0; } if (f_g > base_mask) { f_g = (int)base_mask; } } if ((uint)f_r > base_mask) { if (f_r < 0) { f_r = 0; } if (f_r > base_mask) { f_r = (int)base_mask; } } } span[spanIndex].alpha = (byte)base_mask; span[spanIndex].red = (byte)f_b; span[spanIndex].green = (byte)f_g; span[spanIndex].blue = (byte)f_r; spanIndex++; spanInterpolator.Next(); } while (--len != 0); }
//-------------------------------------------------------------------- public override unsafe void Generate(RGBA_Bytes *span, int x, int y, uint len) { #if use_timers Generate_Span.Start(); #endif base.Interpolator.Begin(x + base.FilterDxDbl(), y + base.FilterDyDbl(), len); uint *fg = stackalloc uint[3]; uint src_alpha; RasterBuffer SourceRenderingBuffer = base.Source().PixelFormat.GetRenderingBuffer(); ISpanInterpolator spanInterpolator = base.Interpolator; unchecked { do { int x_hr; int y_hr; spanInterpolator.Coordinates(out x_hr, out y_hr); x_hr -= base.FilterDxInt(); y_hr -= base.FilterDyInt(); int x_lrX3 = (x_hr >> (int)image_subpixel_scale_e.Shift) * 3; int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift; uint weight; fg[0] = fg[1] = fg[2] = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / 2; x_hr &= (int)image_subpixel_scale_e.Mask; y_hr &= (int)image_subpixel_scale_e.Mask; byte *fg_ptr = SourceRenderingBuffer.GetPixelPointer(y_lr) + x_lrX3; weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * ((int)image_subpixel_scale_e.Scale - y_hr)); fg[0] += weight * fg_ptr[0]; fg[1] += weight * fg_ptr[1]; fg[2] += weight * fg_ptr[2]; weight = (uint)(x_hr * ((int)image_subpixel_scale_e.Scale - y_hr)); fg[0] += weight * fg_ptr[3]; fg[1] += weight * fg_ptr[4]; fg[2] += weight * fg_ptr[5]; ++y_lr; fg_ptr = SourceRenderingBuffer.GetPixelPointer(y_lr) + x_lrX3; weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * y_hr); fg[0] += weight * fg_ptr[0]; fg[1] += weight * fg_ptr[1]; fg[2] += weight * fg_ptr[2]; weight = (uint)(x_hr * y_hr); fg[0] += weight * fg_ptr[3]; fg[1] += weight * fg_ptr[4]; fg[2] += weight * fg_ptr[5]; fg[0] >>= (int)image_subpixel_scale_e.Shift * 2; fg[1] >>= (int)image_subpixel_scale_e.Shift * 2; fg[2] >>= (int)image_subpixel_scale_e.Shift * 2; src_alpha = BaseMask; (*span).m_R = (byte)fg[OrderR]; (*span).m_G = (byte)fg[OrderG]; (*span).m_B = (byte)fg[OrderB]; (*span).m_A = (byte)src_alpha; ++span; spanInterpolator.Next(); } while(--len != 0); } #if use_timers Generate_Span.Stop(); #endif }
//-------------------------------------------------------------------- public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len) { ISpanInterpolator <T> spanInterpolator = base.Interpolator; spanInterpolator.Begin(M.New <T>(x).Add(base.FilterDxDbl()), M.New <T>(y).Add(base.FilterDyDbl()), len); int *fg = stackalloc int[3]; byte *fg_ptr; fixed(short *pWeightArray = Filter.WeightArray()) { short *weight_array = pWeightArray; weight_array = &pWeightArray[((Filter.Diameter() / 2 - 1) << (int)image_subpixel_scale_e.Shift)]; do { int x_hr; int y_hr; spanInterpolator.Coordinates(out x_hr, out y_hr); x_hr -= FilterDxInt(); y_hr -= FilterDyInt(); int x_lr = x_hr >> (int)image_subpixel_scale_e.Shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift; uint weight; fg[0] = fg[1] = fg[2] = (int)image_filter_scale_e.Scale / 2; x_hr &= (int)image_subpixel_scale_e.Mask; y_hr &= (int)image_subpixel_scale_e.Mask; fg_ptr = Source().span(x_lr, y_lr, 2); weight = (uint)((weight_array[x_hr + (int)image_subpixel_scale_e.Scale] * weight_array[y_hr + (int)image_subpixel_scale_e.Scale] + (int)image_filter_scale_e.Scale / 2) >> (int)image_filter_scale_e.Shift); fg[0] += (int)weight * *fg_ptr++; fg[1] += (int)weight * *fg_ptr++; fg[2] += (int)weight * *fg_ptr; fg_ptr = Source().next_x(); weight = (uint)((weight_array[x_hr] * weight_array[y_hr + (int)image_subpixel_scale_e.Scale] + (int)image_filter_scale_e.Scale / 2) >> (int)image_filter_scale_e.Shift); fg[0] += (int)weight * *fg_ptr++; fg[1] += (int)weight * *fg_ptr++; fg[2] += (int)weight * *fg_ptr; fg_ptr = Source().next_y(); weight = (uint)((weight_array[x_hr + (int)image_subpixel_scale_e.Scale] * weight_array[y_hr] + (int)image_filter_scale_e.Scale / 2) >> (int)image_filter_scale_e.Shift); fg[0] += (int)weight * *fg_ptr++; fg[1] += (int)weight * *fg_ptr++; fg[2] += (int)weight * *fg_ptr; fg_ptr = Source().next_x(); weight = (uint)((weight_array[x_hr] * weight_array[y_hr] + (int)image_filter_scale_e.Scale / 2) >> (int)image_filter_scale_e.Shift); fg[0] += (int)weight * *fg_ptr++; fg[1] += (int)weight * *fg_ptr++; fg[2] += (int)weight * *fg_ptr; fg[0] >>= (int)image_filter_scale_e.Shift; fg[1] >>= (int)image_filter_scale_e.Shift; fg[2] >>= (int)image_filter_scale_e.Shift; if (fg[OrderR] > BaseMask) { fg[OrderR] = BaseMask; } if (fg[OrderG] > BaseMask) { fg[OrderG] = BaseMask; } if (fg[OrderB] > BaseMask) { fg[OrderB] = BaseMask; } //span->R_Byte = (byte)fg[OrderR]; //span->G_Byte = (byte)fg[OrderG]; //span->B_Byte = (byte)fg[OrderB]; //span->A_Byte = (uint)BaseMask; (*span) = new RGBA_Bytes((byte)fg[OrderR], (byte)fg[OrderG], (byte)fg[OrderB], (uint)BaseMask); ++span; spanInterpolator.Next(); } while (--len != 0); } }
public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len) { #if use_timers Generate_Span.Start(); #endif base.interpolator().Begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len); uint *fg = stackalloc uint[4]; byte *fg_ptr; RasterBuffer pSourceRenderingBuffer = base.source().PixelFormat.RenderingBuffer; int maxx = (int)pSourceRenderingBuffer.Width() - 1; int maxy = (int)pSourceRenderingBuffer.Height() - 1; ISpanInterpolator spanInterpolator = base.interpolator(); unchecked { do { int x_hr; int y_hr; spanInterpolator.Coordinates(out x_hr, out y_hr); x_hr -= base.filter_dx_int(); y_hr -= base.filter_dy_int(); int x_lr = x_hr >> (int)image_subpixel_scale_e.Shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift; uint weight; fg[0] = fg[1] = fg[2] = fg[3] = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / 2; x_hr &= (int)image_subpixel_scale_e.Mask; y_hr &= (int)image_subpixel_scale_e.Mask; fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2); weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * ((int)image_subpixel_scale_e.Scale - y_hr)); fg[0] += weight * fg_ptr[0]; fg[1] += weight * fg_ptr[1]; fg[2] += weight * fg_ptr[2]; fg[3] += weight * fg_ptr[3]; weight = (uint)(x_hr * ((int)image_subpixel_scale_e.Scale - y_hr)); fg[0] += weight * fg_ptr[4]; fg[1] += weight * fg_ptr[5]; fg[2] += weight * fg_ptr[6]; fg[3] += weight * fg_ptr[7]; ++y_lr; fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2); weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * y_hr); fg[0] += weight * fg_ptr[0]; fg[1] += weight * fg_ptr[1]; fg[2] += weight * fg_ptr[2]; fg[3] += weight * fg_ptr[3]; weight = (uint)(x_hr * y_hr); fg[0] += weight * fg_ptr[4]; fg[1] += weight * fg_ptr[5]; fg[2] += weight * fg_ptr[6]; fg[3] += weight * fg_ptr[7]; fg[0] >>= (int)image_subpixel_scale_e.Shift * 2; fg[1] >>= (int)image_subpixel_scale_e.Shift * 2; fg[2] >>= (int)image_subpixel_scale_e.Shift * 2; fg[3] >>= (int)image_subpixel_scale_e.Shift * 2; (*span).m_R = (byte)fg[OrderR]; (*span).m_G = (byte)fg[OrderG]; (*span).m_B = (byte)fg[OrderB]; (*span).m_A = (byte)fg[OrderA]; ++span; spanInterpolator.Next(); } while (--len != 0); } #if use_timers Generate_Span.Stop(); #endif }
public override void generate(RGBA_Bytes[] span, int spanIndex, int x, int y, int len) { base.interpolator().begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len); ImageBuffer SourceRenderingBuffer = (ImageBuffer)base.GetImageBufferAccessor().SourceImage; ISpanInterpolator spanInterpolator = base.interpolator(); int bufferIndex; byte[] fg_ptr = SourceRenderingBuffer.GetBuffer(out bufferIndex); unchecked { do { int tempR; int tempG; int tempB; int x_hr; int y_hr; spanInterpolator.coordinates(out x_hr, out y_hr); x_hr -= base.filter_dx_int(); y_hr -= base.filter_dy_int(); int x_lr = x_hr >> (int)image_subpixel_scale_e.image_subpixel_shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.image_subpixel_shift; int weight; tempR = tempG = tempB = (int)image_subpixel_scale_e.image_subpixel_scale * (int)image_subpixel_scale_e.image_subpixel_scale / 2; x_hr &= (int)image_subpixel_scale_e.image_subpixel_mask; y_hr &= (int)image_subpixel_scale_e.image_subpixel_mask; bufferIndex = SourceRenderingBuffer.GetBufferOffsetXY(x_lr, y_lr); weight = (((int)image_subpixel_scale_e.image_subpixel_scale - x_hr) * ((int)image_subpixel_scale_e.image_subpixel_scale - y_hr)); tempR += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR]; tempG += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG]; tempB += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB]; bufferIndex += 3; weight = (x_hr * ((int)image_subpixel_scale_e.image_subpixel_scale - y_hr)); tempR += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR]; tempG += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG]; tempB += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB]; y_lr++; bufferIndex = SourceRenderingBuffer.GetBufferOffsetXY(x_lr, y_lr); weight = (((int)image_subpixel_scale_e.image_subpixel_scale - x_hr) * y_hr); tempR += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR]; tempG += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG]; tempB += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB]; bufferIndex += 3; weight = (x_hr * y_hr); tempR += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR]; tempG += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG]; tempB += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB]; tempR >>= (int)image_subpixel_scale_e.image_subpixel_shift * 2; tempG >>= (int)image_subpixel_scale_e.image_subpixel_shift * 2; tempB >>= (int)image_subpixel_scale_e.image_subpixel_shift * 2; RGBA_Bytes color; color.red = (byte)tempR; color.green = (byte)tempG; color.blue = (byte)tempB; color.alpha = 255; span[spanIndex] = color; spanIndex++; spanInterpolator.Next(); } while (--len != 0); } }
//-------------------------------------------------------------------- public void GenerateColors(Color[] outputColors, int startIndex, int x, int y, int spanLen) { //set interpolation start point //spanLen => horizontal span len #if COSMOS #else _interpolator.Begin(_grad0X + _xoffset + x + 0.5, _grad0Y + _yoffset + y + 0.5, spanLen); int gradientSteps = _colorsProvider.GradientSteps; int scanline_x = x; do { //find actual x and y _interpolator.GetCoord(out x, out y); float d = _grValueCalculator.Calculate(x >> DOWN_SCALE_SHIFT, y >> DOWN_SCALE_SHIFT, _dist) * _stepRatio; if (d < 0) { if (PartNo == 0) { d = 0; } else { //move to prev part d = 0; //move to next part if (RequestGradientPart != null) { GradientSpanGen nextPart = RequestGradientPart(this.PartNo - 1); if (nextPart != null) { //generate next part nextPart.GenerateColors(outputColors, startIndex, scanline_x, y, spanLen); return; } } else { d = 0; } } } else if (d >= gradientSteps) { if (IsLastPart) { d = gradientSteps - 1; } else { //move to next part if (RequestGradientPart != null) { GradientSpanGen nextPart = RequestGradientPart(this.PartNo + 1); if (nextPart != null) { //generate next part nextPart.GenerateColors(outputColors, startIndex, scanline_x, y, spanLen); return; } } else { d = gradientSteps - 1; } } } else { // } outputColors[startIndex++] = _colorsProvider.GetColor((int)d); _interpolator.Next();//** scanline_x++; }while (--spanLen != 0); #endif }
public override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len) { ISpanInterpolator spanInterpolator = base.Interpolator; spanInterpolator.Begin(x + base.dx, y + base.dy, len); int accColor0, accColor1, accColor2; int sourceAlpha; int back_r = m_bgcolor.red; int back_g = m_bgcolor.green; int back_b = m_bgcolor.blue; int back_a = m_bgcolor.alpha; int bufferIndex; int maxx = (int)srcRW.Width - 1; int maxy = (int)srcRW.Height - 1; byte[] srcBuffer = srcRW.GetBuffer(); unchecked { do { int x_hr; int y_hr; spanInterpolator.GetCoord(out x_hr, out y_hr); x_hr -= base.dxInt; y_hr -= base.dyInt; int x_lr = x_hr >> img_subpix_const.SHIFT; int y_lr = y_hr >> img_subpix_const.SHIFT; int weight; if (x_lr >= 0 && y_lr >= 0 && x_lr < maxx && y_lr < maxy) { accColor0 = accColor1 = accColor2 = img_subpix_const.SCALE * img_subpix_const.SCALE / 2; x_hr &= img_subpix_const.MASK; y_hr &= img_subpix_const.MASK; bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr); weight = ((img_subpix_const.SCALE - x_hr) * (img_subpix_const.SCALE - y_hr)); accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; bufferIndex += 3; weight = (x_hr * (img_subpix_const.SCALE - y_hr)); accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; y_lr++; bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr); weight = ((img_subpix_const.SCALE - x_hr) * y_hr); accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; bufferIndex += 3; weight = (x_hr * y_hr); accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; accColor0 >>= img_subpix_const.SHIFT * 2; accColor1 >>= img_subpix_const.SHIFT * 2; accColor2 >>= img_subpix_const.SHIFT * 2; sourceAlpha = BASE_MASK; } else { if (x_lr < -1 || y_lr < -1 || x_lr > maxx || y_lr > maxy) { accColor0 = back_r; accColor1 = back_g; accColor2 = back_b; sourceAlpha = back_a; } else { accColor0 = accColor1 = accColor2 = img_subpix_const.SCALE * img_subpix_const.SCALE / 2; sourceAlpha = img_subpix_const.SCALE * img_subpix_const.SCALE / 2; x_hr &= img_subpix_const.MASK; y_hr &= img_subpix_const.MASK; weight = ((img_subpix_const.SCALE - x_hr) * (img_subpix_const.SCALE - y_hr)); if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref sourceAlpha, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; sourceAlpha += back_a * weight; } x_lr++; weight = (x_hr * (img_subpix_const.SCALE - y_hr)); if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref sourceAlpha, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; sourceAlpha += back_a * weight; } x_lr--; y_lr++; weight = ((img_subpix_const.SCALE - x_hr) * y_hr); if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref sourceAlpha, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; sourceAlpha += back_a * weight; } x_lr++; weight = (x_hr * y_hr); if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref sourceAlpha, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; sourceAlpha += back_a * weight; } accColor0 >>= img_subpix_const.SHIFT * 2; accColor1 >>= img_subpix_const.SHIFT * 2; accColor2 >>= img_subpix_const.SHIFT * 2; sourceAlpha >>= img_subpix_const.SHIFT * 2; } } outputColors[startIndex].red = (byte)accColor0; outputColors[startIndex].green = (byte)accColor1; outputColors[startIndex].blue = (byte)accColor2; outputColors[startIndex].alpha = (byte)sourceAlpha; startIndex++; spanInterpolator.Next(); } while (--len != 0); } }
//-------------------------------------------------------------------- public override unsafe void Generate(RGBA_Bytes *span, int x, int y, uint len) { #if use_timers Generate_Span.Start(); #endif base.Interpolator.Begin(M.New <T>(x).Add(base.FilterDxDbl()), M.New <T>(y).Add(base.FilterDyDbl()), len); uint *fg = stackalloc uint[3]; uint src_alpha; uint back_r = m_back_color.R; uint back_g = m_back_color.G; uint back_b = m_back_color.B; uint back_a = m_back_color.A; byte *fg_ptr; RasterBuffer SourceRenderingBuffer = base.Source().PixelFormat.GetRenderingBuffer(); int maxx = (int)SourceRenderingBuffer.Width - 1; int maxy = (int)SourceRenderingBuffer.Height - 1; ISpanInterpolator <T> spanInterpolator = base.Interpolator; unchecked { do { int x_hr; int y_hr; spanInterpolator.Coordinates(out x_hr, out y_hr); x_hr -= base.FilterDxInt(); y_hr -= base.FilterDyInt(); int x_lr = x_hr >> (int)image_subpixel_scale_e.Shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift; uint weight; if (x_lr >= 0 && y_lr >= 0 && x_lr < maxx && y_lr < maxy) { fg[0] = fg[1] = fg[2] = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / 2; x_hr &= (int)image_subpixel_scale_e.Mask; y_hr &= (int)image_subpixel_scale_e.Mask; fg_ptr = SourceRenderingBuffer.GetPixelPointer(y_lr) + x_lr * 3; weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * ((int)image_subpixel_scale_e.Scale - y_hr)); fg[0] += weight * fg_ptr[0]; fg[1] += weight * fg_ptr[1]; fg[2] += weight * fg_ptr[2]; weight = (uint)(x_hr * ((int)image_subpixel_scale_e.Scale - y_hr)); fg[0] += weight * fg_ptr[3]; fg[1] += weight * fg_ptr[4]; fg[2] += weight * fg_ptr[5]; ++y_lr; fg_ptr = SourceRenderingBuffer.GetPixelPointer(y_lr) + x_lr * 3; weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * y_hr); fg[0] += weight * fg_ptr[0]; fg[1] += weight * fg_ptr[1]; fg[2] += weight * fg_ptr[2]; weight = (uint)(x_hr * y_hr); fg[0] += weight * fg_ptr[3]; fg[1] += weight * fg_ptr[4]; fg[2] += weight * fg_ptr[5]; fg[0] >>= (int)image_subpixel_scale_e.Shift * 2; fg[1] >>= (int)image_subpixel_scale_e.Shift * 2; fg[2] >>= (int)image_subpixel_scale_e.Shift * 2; src_alpha = BaseMask; } else { if (x_lr < -1 || y_lr < -1 || x_lr > maxx || y_lr > maxy) { fg[OrderR] = back_r; fg[OrderG] = back_g; fg[OrderB] = back_b; src_alpha = back_a; } else { fg[0] = fg[1] = fg[2] = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / 2; src_alpha = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / 2; x_hr &= (int)image_subpixel_scale_e.Mask; y_hr &= (int)image_subpixel_scale_e.Mask; weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * ((int)image_subpixel_scale_e.Scale - y_hr)); BlendInFilterPixel(fg, ref src_alpha, back_r, back_g, back_b, back_a, SourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight); x_lr++; weight = (uint)(x_hr * ((int)image_subpixel_scale_e.Scale - y_hr)); BlendInFilterPixel(fg, ref src_alpha, back_r, back_g, back_b, back_a, SourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight); x_lr--; y_lr++; weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * y_hr); BlendInFilterPixel(fg, ref src_alpha, back_r, back_g, back_b, back_a, SourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight); x_lr++; weight = (uint)(x_hr * y_hr); BlendInFilterPixel(fg, ref src_alpha, back_r, back_g, back_b, back_a, SourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight); fg[0] >>= (int)image_subpixel_scale_e.Shift * 2; fg[1] >>= (int)image_subpixel_scale_e.Shift * 2; fg[2] >>= (int)image_subpixel_scale_e.Shift * 2; src_alpha >>= (int)image_subpixel_scale_e.Shift * 2; } } //(*span).R = (byte)fg[0]; //(*span).G = (byte)fg[1]; //(*span).B = (byte)fg[2]; //(*span).A = (byte)src_alpha; (*span) = new RGBA_Bytes((byte)fg[0], (byte)fg[1], (byte)fg[2], (byte)src_alpha); ++span; spanInterpolator.Next(); } while (--len != 0); } #if use_timers Generate_Span.Stop(); #endif }
public sealed override void GenerateColors(Drawing.Color[] outputColors, int startIndex, int x, int y, int len) { #if DEBUG int tmp_len = len; #endif unsafe { //TODO: review here if (_noTransformation) { using (CpuBlit.TempMemPtr.FromBmp(_bmpSrc, out int *srcBuffer)) { int bufferIndex = _bmpSrc.GetBufferOffsetXY32(x, y); do { //TODO: review here, match component? //ORDER IS IMPORTANT! //TODO : use CO (color order instead) int srcColor = srcBuffer[bufferIndex++]; outputColors[startIndex] = Drawing.Color.FromArgb( (srcColor >> CO.A_SHIFT) & 0xff, //a (srcColor >> CO.R_SHIFT) & 0xff, //r (srcColor >> CO.G_SHIFT) & 0xff, //g (srcColor >> CO.B_SHIFT) & 0xff); //b ++startIndex; } while (--len != 0); } } else { //Bilinear interpolation, without lookup table ISpanInterpolator spanInterpolator = base.Interpolator; using (CpuBlit.TempMemPtr srcBufferPtr = _bmpSrc.GetBufferPtr()) { int *srcBuffer = (int *)srcBufferPtr.Ptr; spanInterpolator.Begin(x + base.dx, y + base.dy, len); //accumulated color component int acc_r, acc_g, acc_b, acc_a; Color bgColor = this.BackgroundColor; int back_r = bgColor.R; int back_g = bgColor.G; int back_b = bgColor.B; int back_a = bgColor.A; int maxx = _bmpSrc.Width - 1; int maxy = _bmpSrc.Height - 1; int srcColor = 0; do { int x_hr; int y_hr; spanInterpolator.GetCoord(out x_hr, out y_hr); x_hr -= base.dxInt; y_hr -= base.dyInt; int x_lr = x_hr >> subpix_const.SHIFT; int y_lr = y_hr >> subpix_const.SHIFT; int weight; if (x_lr >= 0 && y_lr >= 0 && x_lr < maxx && y_lr < maxy) { int bufferIndex = _bmpSrc.GetBufferOffsetXY32(x_lr, y_lr); //accumulated color components acc_r = acc_g = acc_b = acc_a = subpix_const.SCALE * subpix_const.SCALE / 2; x_hr &= subpix_const.MASK; y_hr &= subpix_const.MASK; weight = (subpix_const.SCALE - x_hr) * (subpix_const.SCALE - y_hr); if (weight > BASE_MASK) { srcColor = srcBuffer[bufferIndex]; acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b } weight = (x_hr * (subpix_const.SCALE - y_hr)); if (weight > BASE_MASK) { bufferIndex++; srcColor = srcBuffer[bufferIndex]; // acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b } weight = ((subpix_const.SCALE - x_hr) * y_hr); if (weight > BASE_MASK) { ++y_lr; // bufferIndex = _bmpSrc.GetBufferOffsetXY32(x_lr, y_lr); srcColor = srcBuffer[bufferIndex]; // acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b } weight = (x_hr * y_hr); if (weight > BASE_MASK) { bufferIndex++; srcColor = srcBuffer[bufferIndex]; // acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b } acc_r >>= subpix_const.SHIFT * 2; acc_g >>= subpix_const.SHIFT * 2; acc_b >>= subpix_const.SHIFT * 2; acc_a >>= subpix_const.SHIFT * 2; } else { if (x_lr < -1 || y_lr < -1 || x_lr > maxx || y_lr > maxy) { acc_r = back_r; acc_g = back_g; acc_b = back_b; acc_a = back_a; } else { acc_r = acc_g = acc_b = acc_a = subpix_const.SCALE * subpix_const.SCALE / 2; x_hr &= subpix_const.MASK; y_hr &= subpix_const.MASK; weight = (subpix_const.SCALE - x_hr) * (subpix_const.SCALE - y_hr); if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { srcColor = srcBuffer[_bmpSrc.GetBufferOffsetXY32(x_lr, y_lr)]; // acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b } else { acc_r += back_r * weight; acc_g += back_g * weight; acc_b += back_b * weight; acc_a += back_a * weight; } } x_lr++; weight = x_hr * (subpix_const.SCALE - y_hr); if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { srcColor = srcBuffer[_bmpSrc.GetBufferOffsetXY32(x_lr, y_lr)]; // acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b } else { acc_r += back_r * weight; acc_g += back_g * weight; acc_b += back_b * weight; acc_a += back_a * weight; } } x_lr--; y_lr++; weight = (subpix_const.SCALE - x_hr) * y_hr; if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { srcColor = srcBuffer[_bmpSrc.GetBufferOffsetXY32(x_lr, y_lr)]; // acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b } else { acc_r += back_r * weight; acc_g += back_g * weight; acc_b += back_b * weight; acc_a += back_a * weight; } } x_lr++; weight = (x_hr * y_hr); if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { srcColor = srcBuffer[_bmpSrc.GetBufferOffsetXY32(x_lr, y_lr)]; // acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b } else { acc_r += back_r * weight; acc_g += back_g * weight; acc_b += back_b * weight; acc_a += back_a * weight; } } acc_r >>= subpix_const.SHIFT * 2; acc_g >>= subpix_const.SHIFT * 2; acc_b >>= subpix_const.SHIFT * 2; acc_a >>= subpix_const.SHIFT * 2; } } #if DEBUG if (startIndex >= outputColors.Length) { } #endif outputColors[startIndex] = PixelFarm.Drawing.Color.FromArgb( (byte)acc_a, (byte)acc_r, (byte)acc_g, (byte)acc_b ); ++startIndex; spanInterpolator.Next(); } while (--len != 0); } //using } //else } //unsafe }
public override void generate(RGBA_Bytes[] span, int spanIndex, int x, int y, int len) { base.interpolator().begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len); int[] accumulatedColor = new int[3]; int sourceAlpha; int back_r = m_OutsideSourceColor.red; int back_g = m_OutsideSourceColor.green; int back_b = m_OutsideSourceColor.blue; int back_a = m_OutsideSourceColor.alpha; int bufferIndex; byte[] fg_ptr; ImageBuffer SourceRenderingBuffer = (ImageBuffer)base.GetImageBufferAccessor().SourceImage; int maxx = (int)SourceRenderingBuffer.Width - 1; int maxy = (int)SourceRenderingBuffer.Height - 1; ISpanInterpolator spanInterpolator = base.interpolator(); unchecked { do { int x_hr; int y_hr; spanInterpolator.coordinates(out x_hr, out y_hr); x_hr -= base.filter_dx_int(); y_hr -= base.filter_dy_int(); int x_lr = x_hr >> (int)image_subpixel_scale_e.image_subpixel_shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.image_subpixel_shift; int weight; if (x_lr >= 0 && y_lr >= 0 && x_lr < maxx && y_lr < maxy) { accumulatedColor[0] = accumulatedColor[1] = accumulatedColor[2] = (int)image_subpixel_scale_e.image_subpixel_scale * (int)image_subpixel_scale_e.image_subpixel_scale / 2; x_hr &= (int)image_subpixel_scale_e.image_subpixel_mask; y_hr &= (int)image_subpixel_scale_e.image_subpixel_mask; fg_ptr = SourceRenderingBuffer.GetPixelPointerXY(x_lr, y_lr, out bufferIndex); weight = (((int)image_subpixel_scale_e.image_subpixel_scale - x_hr) * ((int)image_subpixel_scale_e.image_subpixel_scale - y_hr)); accumulatedColor[0] += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR]; accumulatedColor[1] += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG]; accumulatedColor[2] += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB]; bufferIndex += 3; weight = (x_hr * ((int)image_subpixel_scale_e.image_subpixel_scale - y_hr)); accumulatedColor[0] += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR]; accumulatedColor[1] += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG]; accumulatedColor[2] += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB]; y_lr++; fg_ptr = SourceRenderingBuffer.GetPixelPointerXY(x_lr, y_lr, out bufferIndex); weight = (((int)image_subpixel_scale_e.image_subpixel_scale - x_hr) * y_hr); accumulatedColor[0] += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR]; accumulatedColor[1] += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG]; accumulatedColor[2] += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB]; bufferIndex += 3; weight = (x_hr * y_hr); accumulatedColor[0] += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR]; accumulatedColor[1] += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG]; accumulatedColor[2] += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB]; accumulatedColor[0] >>= (int)image_subpixel_scale_e.image_subpixel_shift * 2; accumulatedColor[1] >>= (int)image_subpixel_scale_e.image_subpixel_shift * 2; accumulatedColor[2] >>= (int)image_subpixel_scale_e.image_subpixel_shift * 2; sourceAlpha = base_mask; } else { if (x_lr < -1 || y_lr < -1 || x_lr > maxx || y_lr > maxy) { accumulatedColor[0] = back_r; accumulatedColor[1] = back_g; accumulatedColor[2] = back_b; sourceAlpha = back_a; } else { accumulatedColor[0] = accumulatedColor[1] = accumulatedColor[2] = (int)image_subpixel_scale_e.image_subpixel_scale * (int)image_subpixel_scale_e.image_subpixel_scale / 2; sourceAlpha = (int)image_subpixel_scale_e.image_subpixel_scale * (int)image_subpixel_scale_e.image_subpixel_scale / 2; x_hr &= (int)image_subpixel_scale_e.image_subpixel_mask; y_hr &= (int)image_subpixel_scale_e.image_subpixel_mask; weight = (((int)image_subpixel_scale_e.image_subpixel_scale - x_hr) * ((int)image_subpixel_scale_e.image_subpixel_scale - y_hr)); BlendInFilterPixel(accumulatedColor, ref sourceAlpha, back_r, back_g, back_b, back_a, SourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight); x_lr++; weight = (x_hr * ((int)image_subpixel_scale_e.image_subpixel_scale - y_hr)); BlendInFilterPixel(accumulatedColor, ref sourceAlpha, back_r, back_g, back_b, back_a, SourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight); x_lr--; y_lr++; weight = (((int)image_subpixel_scale_e.image_subpixel_scale - x_hr) * y_hr); BlendInFilterPixel(accumulatedColor, ref sourceAlpha, back_r, back_g, back_b, back_a, SourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight); x_lr++; weight = (x_hr * y_hr); BlendInFilterPixel(accumulatedColor, ref sourceAlpha, back_r, back_g, back_b, back_a, SourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight); accumulatedColor[0] >>= (int)image_subpixel_scale_e.image_subpixel_shift * 2; accumulatedColor[1] >>= (int)image_subpixel_scale_e.image_subpixel_shift * 2; accumulatedColor[2] >>= (int)image_subpixel_scale_e.image_subpixel_shift * 2; sourceAlpha >>= (int)image_subpixel_scale_e.image_subpixel_shift * 2; } } span[spanIndex].red = (byte)accumulatedColor[0]; span[spanIndex].green = (byte)accumulatedColor[1]; span[spanIndex].blue = (byte)accumulatedColor[2]; span[spanIndex].alpha = (byte)sourceAlpha; spanIndex++; spanInterpolator.Next(); } while (--len != 0); } }
public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len) { #if use_timers Generate_Span.Start(); #endif base.interpolator().Begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len); //uint[] fg = new uint[4]; uint *fg = stackalloc uint[4]; uint back_r = m_back_color.m_R; uint back_g = m_back_color.m_G; uint back_b = m_back_color.m_B; uint back_a = m_back_color.m_A; byte *fg_ptr; RasterBuffer pSourceRenderingBuffer = base.source().PixelFormat.RenderingBuffer; int maxx = (int)pSourceRenderingBuffer.Width() - 1; int maxy = (int)pSourceRenderingBuffer.Height() - 1; ISpanInterpolator spanInterpolator = base.interpolator(); unchecked { do { int x_hr; int y_hr; spanInterpolator.Coordinates(out x_hr, out y_hr); x_hr -= base.filter_dx_int(); y_hr -= base.filter_dy_int(); int x_lr = x_hr >> (int)image_subpixel_scale_e.Shift; int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift; uint weight; if (x_lr >= 0 && y_lr >= 0 && x_lr < maxx && y_lr < maxy) { fg[0] = fg[1] = fg[2] = fg[3] = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / 2; x_hr &= (int)image_subpixel_scale_e.Mask; y_hr &= (int)image_subpixel_scale_e.Mask; fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2); weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * ((int)image_subpixel_scale_e.Scale - y_hr)); fg[0] += weight * fg_ptr[0]; fg[1] += weight * fg_ptr[1]; fg[2] += weight * fg_ptr[2]; fg[3] += weight * fg_ptr[3]; weight = (uint)(x_hr * ((int)image_subpixel_scale_e.Scale - y_hr)); fg[0] += weight * fg_ptr[4]; fg[1] += weight * fg_ptr[5]; fg[2] += weight * fg_ptr[6]; fg[3] += weight * fg_ptr[7]; ++y_lr; fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2); weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * y_hr); fg[0] += weight * fg_ptr[0]; fg[1] += weight * fg_ptr[1]; fg[2] += weight * fg_ptr[2]; fg[3] += weight * fg_ptr[3]; weight = (uint)(x_hr * y_hr); fg[0] += weight * fg_ptr[4]; fg[1] += weight * fg_ptr[5]; fg[2] += weight * fg_ptr[6]; fg[3] += weight * fg_ptr[7]; fg[0] >>= (int)image_subpixel_scale_e.Shift * 2; fg[1] >>= (int)image_subpixel_scale_e.Shift * 2; fg[2] >>= (int)image_subpixel_scale_e.Shift * 2; fg[3] >>= (int)image_subpixel_scale_e.Shift * 2; } else { if (x_lr < -1 || y_lr < -1 || x_lr > maxx || y_lr > maxy) { fg[OrderR] = back_r; fg[OrderG] = back_g; fg[OrderB] = back_b; fg[OrderA] = back_a; } else { fg[0] = fg[1] = fg[2] = fg[3] = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / 2; x_hr &= (int)image_subpixel_scale_e.Mask; y_hr &= (int)image_subpixel_scale_e.Mask; weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * ((int)image_subpixel_scale_e.Scale - y_hr)); BlendInFilterPixel(fg, back_r, back_g, back_b, back_a, pSourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight); x_lr++; weight = (uint)(x_hr * ((int)image_subpixel_scale_e.Scale - y_hr)); BlendInFilterPixel(fg, back_r, back_g, back_b, back_a, pSourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight); x_lr--; y_lr++; weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * y_hr); BlendInFilterPixel(fg, back_r, back_g, back_b, back_a, pSourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight); x_lr++; weight = (uint)(x_hr * y_hr); BlendInFilterPixel(fg, back_r, back_g, back_b, back_a, pSourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight); fg[0] >>= (int)image_subpixel_scale_e.Shift * 2; fg[1] >>= (int)image_subpixel_scale_e.Shift * 2; fg[2] >>= (int)image_subpixel_scale_e.Shift * 2; fg[3] >>= (int)image_subpixel_scale_e.Shift * 2; } } (*span).m_R = (byte)fg[0]; (*span).m_G = (byte)fg[1]; (*span).m_B = (byte)fg[2]; (*span).m_A = (byte)fg[3]; ++span; spanInterpolator.Next(); } while (--len != 0); } #if use_timers Generate_Span.Stop(); #endif }
public override void GenerateColors(Color[] outputColors, int startIndex, int x, int y, int len) { ISpanInterpolator spanInterpolator = this.Interpolator; int acc_r, acc_g, acc_b, acc_a; int diameter = _lut.Diameter; int start = _lut.Start; int[] weight_array = _lut.WeightArray; int x_count; int weight_y; unsafe { using (CpuBlit.TempMemPtr srcBufferPtr = _bmpSrc.GetBufferPtr()) { int *srcBuffer = (int *)srcBufferPtr.Ptr; spanInterpolator.Begin(x + base.dx, y + base.dy, len); do { spanInterpolator.GetCoord(out x, out y); x -= base.dxInt; y -= base.dyInt; int x_hr = x; int y_hr = y; int x_lr = x_hr >> subpix_const.SHIFT; int y_lr = y_hr >> subpix_const.SHIFT; //accumualted color components acc_r = acc_g = acc_b = acc_a = filter_const.SCALE / 2; int x_fract = x_hr & subpix_const.MASK; int y_count = diameter; y_hr = subpix_const.MASK - (y_hr & subpix_const.MASK); int bufferIndex = _bmpSrc.GetBufferOffsetXY32(x_lr, y_lr); int tmp_Y = y_lr; for (; ;) { x_count = diameter; weight_y = weight_array[y_hr]; x_hr = subpix_const.MASK - x_fract; //------------------- for (; ;) { int weight = (weight_y * weight_array[x_hr] + filter_const.SCALE / 2) >> filter_const.SHIFT; int srcColor = srcBuffer[bufferIndex]; acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b if (--x_count == 0) { break; //for } x_hr += subpix_const.SCALE; bufferIndex++; } //------------------- if (--y_count == 0) { break; } y_hr += subpix_const.SCALE; tmp_Y++; //move down to next row-> and find start bufferIndex bufferIndex = _bmpSrc.GetBufferOffsetXY32(x_lr, tmp_Y); } acc_r >>= filter_const.SHIFT; acc_g >>= filter_const.SHIFT; acc_b >>= filter_const.SHIFT; acc_a >>= filter_const.SHIFT; unchecked { if ((uint)acc_r > BASE_MASK) { if (acc_r < 0) { acc_r = 0; } if (acc_r > BASE_MASK) { acc_r = BASE_MASK; } } if ((uint)acc_g > BASE_MASK) { if (acc_g < 0) { acc_g = 0; } if (acc_g > BASE_MASK) { acc_g = BASE_MASK; } } if ((uint)acc_b > BASE_MASK) { if (acc_b < 0) { acc_b = 0; } if (acc_b > BASE_MASK) { acc_b = BASE_MASK; } } if ((uint)acc_a > BASE_MASK) { if (acc_a < 0) { acc_a = 0; } if (acc_a > BASE_MASK) { acc_a = BASE_MASK; } } } outputColors[startIndex] = PixelFarm.Drawing.Color.FromArgb( (byte)acc_a, //a (byte)acc_r, (byte)acc_g, (byte)acc_b); startIndex++; spanInterpolator.Next(); } while (--len != 0); } } }
public sealed override void GenerateColors(Drawing.Color[] outputColors, int startIndex, int x, int y, int len) { #if DEBUG int tmp_len = len; #endif unsafe { //TODO: review here if (_mode0) { using (CpuBlit.Imaging.TempMemPtr.FromBmp(_imgsrc, out int *srcBuffer)) { int bufferIndex = _imgsrc.GetBufferOffsetXY32(x, y); //unsafe { #if true do { //TODO: review here, match component? //ORDER IS IMPORTANT! //TODO : use CO (color order instead) int color = srcBuffer[bufferIndex++]; //byte b = (byte)srcBuffer[bufferIndex++]; //byte g = (byte)srcBuffer[bufferIndex++]; //byte r = (byte)srcBuffer[bufferIndex++]; //byte a = (byte)srcBuffer[bufferIndex++]; //outputColors[startIndex] = Drawing.Color.FromArgb(a, r, g, b); outputColors[startIndex] = Drawing.Color.FromArgb( (color >> 24) & 0xff, //a (color >> 16) & 0xff, //r (color >> 8) & 0xff, //b (color) & 0xff //b ); ++startIndex; } while (--len != 0); #else fixed(byte *pSource = &fg_ptr[bufferIndex]) { int *pSourceInt = (int *)pSource; fixed(RGBA_Bytes *pDest = &span[spanIndex]) { int *pDestInt = (int *)pDest; do { *pDestInt++ = *pSourceInt++; } while (--len != 0); } } #endif } } } else { ISpanInterpolator spanInterpolator = base.Interpolator; using (CpuBlit.Imaging.TempMemPtr srcBufferPtr = _imgsrc.GetBufferPtr()) { int *srcBuffer = (int *)srcBufferPtr.Ptr; spanInterpolator.Begin(x + base.dx, y + base.dy, len); int accColor0, accColor1, accColor2, accColor3; int back_r = m_bgcolor.red; int back_g = m_bgcolor.green; int back_b = m_bgcolor.blue; int back_a = m_bgcolor.alpha; int maxx = _imgsrc.Width - 1; int maxy = _imgsrc.Height - 1; int color = 0; unchecked { do { int x_hr; int y_hr; spanInterpolator.GetCoord(out x_hr, out y_hr); x_hr -= base.dxInt; y_hr -= base.dyInt; int x_lr = x_hr >> img_subpix_const.SHIFT; int y_lr = y_hr >> img_subpix_const.SHIFT; int weight; if (x_lr >= 0 && y_lr >= 0 && x_lr < maxx && y_lr < maxy) { int bufferIndex = _imgsrc.GetBufferOffsetXY32(x_lr, y_lr); accColor0 = accColor1 = accColor2 = accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2; x_hr &= img_subpix_const.MASK; y_hr &= img_subpix_const.MASK; //bufferIndex = _imgsrc.GetBufferOffsetXY32(x_lr, y_lr); weight = ((img_subpix_const.SCALE - x_hr) * (img_subpix_const.SCALE - y_hr)); if (weight > BASE_MASK) { color = srcBuffer[bufferIndex]; accColor3 += weight * ((color >> 24) & 0xff); //a accColor0 += weight * ((color >> 16) & 0xff); //r accColor1 += weight * ((color >> 8) & 0xff); //g accColor2 += weight * ((color) & 0xff); //b } weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr)); if (weight > BASE_MASK) { bufferIndex++; color = srcBuffer[bufferIndex]; // accColor3 += weight * ((color >> 24) & 0xff); //a accColor0 += weight * ((color >> 16) & 0xff); //r accColor1 += weight * ((color >> 8) & 0xff); //g accColor2 += weight * ((color) & 0xff); //b } weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr); if (weight > BASE_MASK) { ++y_lr; // bufferIndex = _imgsrc.GetBufferOffsetXY32(x_lr, y_lr); color = srcBuffer[bufferIndex]; // accColor3 += weight * ((color >> 24) & 0xff); //a accColor0 += weight * ((color >> 16) & 0xff); //r accColor1 += weight * ((color >> 8) & 0xff); //g accColor2 += weight * ((color) & 0xff); //b } weight = (x_hr * y_hr); if (weight > BASE_MASK) { bufferIndex++; color = srcBuffer[bufferIndex]; // accColor3 += weight * ((color >> 24) & 0xff); //a accColor0 += weight * ((color >> 16) & 0xff); //r accColor1 += weight * ((color >> 8) & 0xff); //g accColor2 += weight * ((color) & 0xff); //b } accColor0 >>= img_subpix_const.SHIFT * 2; accColor1 >>= img_subpix_const.SHIFT * 2; accColor2 >>= img_subpix_const.SHIFT * 2; accColor3 >>= img_subpix_const.SHIFT * 2; } else { if (x_lr < -1 || y_lr < -1 || x_lr > maxx || y_lr > maxy) { accColor0 = back_r; accColor1 = back_g; accColor2 = back_b; accColor3 = back_a; } else { accColor0 = accColor1 = accColor2 = accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2; x_hr &= (int)img_subpix_const.MASK; y_hr &= (int)img_subpix_const.MASK; weight = (((int)img_subpix_const.SCALE - x_hr) * ((int)img_subpix_const.SCALE - y_hr)); if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel( ref accColor0, ref accColor1, ref accColor2, ref accColor3, srcBuffer, _imgsrc.GetBufferOffsetXY32(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; accColor3 += back_a * weight; } } x_lr++; weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr)); if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3, srcBuffer, _imgsrc.GetBufferOffsetXY32(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; accColor3 += back_a * weight; } } x_lr--; y_lr++; weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr); if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3, srcBuffer, _imgsrc.GetBufferOffsetXY32(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; accColor3 += back_a * weight; } } x_lr++; weight = (x_hr * y_hr); if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3, srcBuffer, _imgsrc.GetBufferOffsetXY32(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; accColor3 += back_a * weight; } } accColor0 >>= img_subpix_const.SHIFT * 2; accColor1 >>= img_subpix_const.SHIFT * 2; accColor2 >>= img_subpix_const.SHIFT * 2; accColor3 >>= img_subpix_const.SHIFT * 2; } } #if DEBUG if (startIndex >= outputColors.Length) { } #endif outputColors[startIndex] = PixelFarm.Drawing.Color.FromArgb( (byte)accColor3, (byte)accColor0, (byte)accColor1, (byte)accColor2 ); //outputColors[startIndex].red = (byte)accColor0; //outputColors[startIndex].green = (byte)accColor1; //outputColors[startIndex].blue = (byte)accColor2; //outputColors[startIndex].alpha = (byte)accColor3; ++startIndex; spanInterpolator.Next(); } while (--len != 0); } } } } }
public override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len) { ISpanInterpolator spanInterpolator = base.Interpolator; int bufferIndex; byte[] srcBuffer = srcRW.GetBuffer(); if (spanInterpolator.GetType() == typeof(PixelFarm.Agg.Transform.SpanInterpolatorLinear) && ((PixelFarm.Agg.Transform.SpanInterpolatorLinear)spanInterpolator).Transformer.GetType() == typeof(PixelFarm.Agg.Transform.Affine) && ((PixelFarm.Agg.Transform.Affine)((PixelFarm.Agg.Transform.SpanInterpolatorLinear)spanInterpolator).Transformer).IsIdentity()) { bufferIndex = srcRW.GetBufferOffsetXY(x, y); //unsafe { #if true do { outputColors[startIndex].blue = (byte)srcBuffer[bufferIndex++]; outputColors[startIndex].green = (byte)srcBuffer[bufferIndex++]; outputColors[startIndex].red = (byte)srcBuffer[bufferIndex++]; outputColors[startIndex].alpha = (byte)srcBuffer[bufferIndex++]; ++startIndex; } while (--len != 0); #else fixed(byte *pSource = &fg_ptr[bufferIndex]) { int *pSourceInt = (int *)pSource; fixed(RGBA_Bytes *pDest = &span[spanIndex]) { int *pDestInt = (int *)pDest; do { *pDestInt++ = *pSourceInt++; } while (--len != 0); } } #endif } return; } spanInterpolator.Begin(x + base.dx, y + base.dy, len); int accColor0, accColor1, accColor2, accColor3; int back_r = m_bgcolor.red; int back_g = m_bgcolor.green; int back_b = m_bgcolor.blue; int back_a = m_bgcolor.alpha; int maxx = srcRW.Width - 1; int maxy = srcRW.Height - 1; srcBuffer = srcRW.GetBuffer(); unchecked { do { int x_hr; int y_hr; spanInterpolator.GetCoord(out x_hr, out y_hr); x_hr -= base.dxInt; y_hr -= base.dyInt; int x_lr = x_hr >> img_subpix_const.SHIFT; int y_lr = y_hr >> img_subpix_const.SHIFT; int weight; if (x_lr >= 0 && y_lr >= 0 && x_lr < maxx && y_lr < maxy) { accColor0 = accColor1 = accColor2 = accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2; x_hr &= (int)img_subpix_const.MASK; y_hr &= (int)img_subpix_const.MASK; bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr); weight = (((int)img_subpix_const.SCALE - x_hr) * ((int)img_subpix_const.SCALE - y_hr)); if (weight > BASE_MASK) { accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; accColor3 += weight * srcBuffer[bufferIndex + CO.A]; } weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr)); if (weight > BASE_MASK) { bufferIndex += bytesBetweenPixelInclusive; accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; accColor3 += weight * srcBuffer[bufferIndex + CO.A]; } weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr); if (weight > BASE_MASK) { ++y_lr; bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr); accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; accColor3 += weight * srcBuffer[bufferIndex + CO.A]; } weight = (x_hr * y_hr); if (weight > BASE_MASK) { bufferIndex += bytesBetweenPixelInclusive; accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; accColor3 += weight * srcBuffer[bufferIndex + CO.A]; } accColor0 >>= img_subpix_const.SHIFT * 2; accColor1 >>= img_subpix_const.SHIFT * 2; accColor2 >>= img_subpix_const.SHIFT * 2; accColor3 >>= img_subpix_const.SHIFT * 2; } else { if (x_lr < -1 || y_lr < -1 || x_lr > maxx || y_lr > maxy) { accColor0 = back_r; accColor1 = back_g; accColor2 = back_b; accColor3 = back_a; } else { accColor0 = accColor1 = accColor2 = accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2; x_hr &= (int)img_subpix_const.MASK; y_hr &= (int)img_subpix_const.MASK; weight = (((int)img_subpix_const.SCALE - x_hr) * ((int)img_subpix_const.SCALE - y_hr)); if (weight > BASE_MASK) { } x_lr++; weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr)); if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; accColor3 += back_a * weight; } } x_lr--; y_lr++; weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr); if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; accColor3 += back_a * weight; } } x_lr++; weight = (x_hr * y_hr); if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; accColor3 += back_a * weight; } } accColor0 >>= img_subpix_const.SHIFT * 2; accColor1 >>= img_subpix_const.SHIFT * 2; accColor2 >>= img_subpix_const.SHIFT * 2; accColor3 >>= img_subpix_const.SHIFT * 2; } } outputColors[startIndex].red = (byte)accColor0; outputColors[startIndex].green = (byte)accColor1; outputColors[startIndex].blue = (byte)accColor2; outputColors[startIndex].alpha = (byte)accColor3; ++startIndex; spanInterpolator.Next(); } while (--len != 0); } }