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 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 generate(RGBA_Bytes[] span, int spanIndex, int x, int y, int len) { ImageBuffer SourceRenderingBuffer = (ImageBuffer)GetImageBufferAccessor().SourceImage; int bytesBetweenPixelsInclusive = SourceRenderingBuffer.GetBytesBetweenPixelsInclusive(); if (SourceRenderingBuffer.BitDepth != 8) { 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 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); byte[] fg_ptr = SourceRenderingBuffer.GetBuffer(); #if USE_UNSAFE_CODE unsafe { fixed(byte *pSource = fg_ptr) { do { span[spanIndex].red = pSource[bufferIndex]; span[spanIndex].green = pSource[bufferIndex]; span[spanIndex].blue = pSource[bufferIndex]; span[spanIndex].alpha = 255; spanIndex++; bufferIndex += bytesBetweenPixelsInclusive; } while (--len != 0); } } #else do { throw new Exception("this code is for 32 bit"); RGBA_Bytes color; color.blue = fg_ptr[bufferIndex++]; color.green = fg_ptr[bufferIndex++]; color.red = fg_ptr[bufferIndex++]; color.alpha = fg_ptr[bufferIndex++]; span[spanIndex++] = color; } while (--len != 0); #endif }
public override void generate(Color[] 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 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); byte[] fg_ptr = SourceRenderingBuffer.GetBuffer(); #if USE_UNSAFE_CODE unsafe { fixed(byte *pSource = fg_ptr) { do { span[spanIndex++] = *(RGBA_Bytes *)&(pSource[bufferIndex]); bufferIndex += 4; } while (--len != 0); } } #else Color color = Color.White; do { color.blue = fg_ptr[bufferIndex++]; color.green = fg_ptr[bufferIndex++]; color.red = fg_ptr[bufferIndex++]; span[spanIndex++] = color; } while (--len != 0); #endif }
public override void generate(RGBA_Bytes[] span, int spanIndex, int x, int y, int len) { ISpanInterpolator spanInterpolator = base.interpolator(); spanInterpolator.begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len); int[] fg = new int[3]; byte[] fg_ptr; int[] weightArray = filter().weight_array(); int diameter = (int)base.filter().diameter(); int filter_scale = diameter << (int)image_subpixel_scale_e.image_subpixel_shift; int[] weight_array = weightArray; do { int rx; int ry; int rx_inv = (int)image_subpixel_scale_e.image_subpixel_scale; int ry_inv = (int)image_subpixel_scale_e.image_subpixel_scale; spanInterpolator.coordinates(out x, out y); spanInterpolator.local_scale(out rx, out ry); base.adjust_scale(ref rx, ref ry); rx_inv = (int)image_subpixel_scale_e.image_subpixel_scale * (int)image_subpixel_scale_e.image_subpixel_scale / rx; ry_inv = (int)image_subpixel_scale_e.image_subpixel_scale * (int)image_subpixel_scale_e.image_subpixel_scale / ry; int radius_x = (diameter * rx) >> 1; int radius_y = (diameter * ry) >> 1; int len_x_lr = (diameter * rx + (int)image_subpixel_scale_e.image_subpixel_mask) >> (int)(int)image_subpixel_scale_e.image_subpixel_shift; x += base.filter_dx_int() - radius_x; y += base.filter_dy_int() - radius_y; fg[0] = fg[1] = fg[2] = (int)image_filter_scale_e.image_filter_scale / 2; int y_lr = y >> (int)(int)image_subpixel_scale_e.image_subpixel_shift; int y_hr = (((int)image_subpixel_scale_e.image_subpixel_mask - (y & (int)image_subpixel_scale_e.image_subpixel_mask)) * ry_inv) >> (int)(int)image_subpixel_scale_e.image_subpixel_shift; int total_weight = 0; int x_lr = x >> (int)(int)image_subpixel_scale_e.image_subpixel_shift; int x_hr = (((int)image_subpixel_scale_e.image_subpixel_mask - (x & (int)image_subpixel_scale_e.image_subpixel_mask)) * rx_inv) >> (int)(int)image_subpixel_scale_e.image_subpixel_shift; int x_hr2 = x_hr; int sourceIndex; fg_ptr = base.GetImageBufferAccessor().span(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)image_filter_scale_e.image_filter_scale / 2) >> downscale_shift; fg[0] += fg_ptr[sourceIndex + ImageBuffer.OrderR] * weight; fg[1] += fg_ptr[sourceIndex + ImageBuffer.OrderG] * weight; fg[2] += fg_ptr[sourceIndex + ImageBuffer.OrderB] * weight; total_weight += weight; x_hr += rx_inv; if (x_hr >= filter_scale) { break; } fg_ptr = base.GetImageBufferAccessor().next_x(out sourceIndex); } y_hr += ry_inv; if (y_hr >= filter_scale) { break; } fg_ptr = base.GetImageBufferAccessor().next_y(out sourceIndex); } fg[0] /= total_weight; fg[1] /= total_weight; fg[2] /= total_weight; if (fg[0] < 0) { fg[0] = 0; } if (fg[1] < 0) { fg[1] = 0; } if (fg[2] < 0) { fg[2] = 0; } if (fg[0] > base_mask) { fg[0] = base_mask; } if (fg[1] > base_mask) { fg[1] = base_mask; } if (fg[2] > base_mask) { fg[2] = base_mask; } span[spanIndex].alpha = base_mask; span[spanIndex].red = (byte)fg[0]; span[spanIndex].green = (byte)fg[1]; span[spanIndex].blue = (byte)fg[2]; spanIndex++; interpolator().Next(); } while (--len != 0); }
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 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 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 coordinates(out int x, out int y) { m_interpolator.coordinates(out x, out y); }