void StackBlurRGBA32(BitmapBlenderBase img, int radius, int ry) { int width = img.Width; int height = img.Height; //TODO: review here again //need to copy ? int[] srcBuffer = new int[width * height]; BitmapBlenderBase.CopySubBufferToInt32Array(img, 0, 0, width, height, srcBuffer); StackBlurARGB.FastBlur32ARGB(srcBuffer, srcBuffer, img.Width, img.Height, radius); int i = 0; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { //TODO: review here again=> //find a better way to set pixel... int dest = srcBuffer[i]; img.SetPixel(x, y, Color.FromArgb( (byte)((dest >> 16) & 0xff), (byte)((dest >> 8) & 0xff), (byte)((dest) & 0xff))); i++; } } }
public void DoSharpen(BitmapBlenderBase readerWriter, int radius) { if (pdnSharpen == null) { pdnSharpen = new ShapenFilterPdn(); } pdnSharpen.Sharpen(readerWriter, radius); }
public void DoRecursiveBlur(BitmapBlenderBase readerWriter, int radius) { if (m_recursive_blur == null) { m_recursive_blur = new RecursiveBlur(new RecursiveBlurCalcRGB()); } m_recursive_blur.Blur(readerWriter, radius); }
public void DoStackBlur(BitmapBlenderBase readerWriter, int radius) { if (stackBlur == null) { stackBlur = new StackBlur(); } stackBlur.Blur(readerWriter, radius, radius); }
public void Blur(BitmapBlenderBase img, int rx, int ry) { switch (img.BitDepth) { case 24: StackBlurRGB24(img, rx, ry); break; case 32: StackBlurRGBA32(img, rx, ry); break; default: throw new NotImplementedException(); } }
void StackBlurRGB24(BitmapBlenderBase img, int rx, int ry) { throw new NotImplementedException(); #if false //typedef typename Img::color_type color_type; //typedef typename Img::order_type order_type; int x, y, xp, yp, i; int stack_ptr; int stack_start; byte * src_pix_ptr; byte * dst_pix_ptr; color_type *stack_pix_ptr; int sum_r; int sum_g; int sum_b; int sum_in_r; int sum_in_g; int sum_in_b; int sum_out_r; int sum_out_g; int sum_out_b; int w = img.width(); int h = img.height(); int wm = w - 1; int hm = h - 1; int div; int mul_sum; int shr_sum; pod_vector <color_type> stack; if (rx > 0) { if (rx > 254) { rx = 254; } div = rx * 2 + 1; mul_sum = stack_blur_tables.g_stack_blur8_mul[rx]; shr_sum = stack_blur_tables.g_stack_blur8_shr[rx]; stack.allocate(div); for (y = 0; y < h; y++) { sum_r = sum_g = sum_b = sum_in_r = sum_in_g = sum_in_b = sum_out_r = sum_out_g = sum_out_b = 0; src_pix_ptr = img.pix_ptr(0, y); for (i = 0; i <= rx; i++) { stack_pix_ptr = &stack[i]; stack_pix_ptr->r = src_pix_ptr[R]; stack_pix_ptr->g = src_pix_ptr[G]; stack_pix_ptr->b = src_pix_ptr[B]; sum_r += src_pix_ptr[R] * (i + 1); sum_g += src_pix_ptr[G] * (i + 1); sum_b += src_pix_ptr[B] * (i + 1); sum_out_r += src_pix_ptr[R]; sum_out_g += src_pix_ptr[G]; sum_out_b += src_pix_ptr[B]; } for (i = 1; i <= rx; i++) { if (i <= wm) { src_pix_ptr += Img::pix_width; } stack_pix_ptr = &stack[i + rx]; stack_pix_ptr->r = src_pix_ptr[R]; stack_pix_ptr->g = src_pix_ptr[G]; stack_pix_ptr->b = src_pix_ptr[B]; sum_r += src_pix_ptr[R] * (rx + 1 - i); sum_g += src_pix_ptr[G] * (rx + 1 - i); sum_b += src_pix_ptr[B] * (rx + 1 - i); sum_in_r += src_pix_ptr[R]; sum_in_g += src_pix_ptr[G]; sum_in_b += src_pix_ptr[B]; } stack_ptr = rx; xp = rx; if (xp > wm) { xp = wm; } src_pix_ptr = img.pix_ptr(xp, y); dst_pix_ptr = img.pix_ptr(0, y); for (x = 0; x < w; x++) { dst_pix_ptr[R] = (sum_r * mul_sum) >> shr_sum; dst_pix_ptr[G] = (sum_g * mul_sum) >> shr_sum; dst_pix_ptr[B] = (sum_b * mul_sum) >> shr_sum; dst_pix_ptr += Img::pix_width; sum_r -= sum_out_r; sum_g -= sum_out_g; sum_b -= sum_out_b; stack_start = stack_ptr + div - rx; if (stack_start >= div) { stack_start -= div; } stack_pix_ptr = &stack[stack_start]; sum_out_r -= stack_pix_ptr->r; sum_out_g -= stack_pix_ptr->g; sum_out_b -= stack_pix_ptr->b; if (xp < wm) { src_pix_ptr += Img::pix_width; ++xp; } stack_pix_ptr->r = src_pix_ptr[R]; stack_pix_ptr->g = src_pix_ptr[G]; stack_pix_ptr->b = src_pix_ptr[B]; sum_in_r += src_pix_ptr[R]; sum_in_g += src_pix_ptr[G]; sum_in_b += src_pix_ptr[B]; sum_r += sum_in_r; sum_g += sum_in_g; sum_b += sum_in_b; ++stack_ptr; if (stack_ptr >= div) { stack_ptr = 0; } stack_pix_ptr = &stack[stack_ptr]; sum_out_r += stack_pix_ptr->r; sum_out_g += stack_pix_ptr->g; sum_out_b += stack_pix_ptr->b; sum_in_r -= stack_pix_ptr->r; sum_in_g -= stack_pix_ptr->g; sum_in_b -= stack_pix_ptr->b; } } } if (ry > 0) { if (ry > 254) { ry = 254; } div = ry * 2 + 1; mul_sum = stack_blur_tables.g_stack_blur8_mul[ry]; shr_sum = stack_blur_tables.g_stack_blur8_shr[ry]; stack.allocate(div); int stride = img.stride(); for (x = 0; x < w; x++) { sum_r = sum_g = sum_b = sum_in_r = sum_in_g = sum_in_b = sum_out_r = sum_out_g = sum_out_b = 0; src_pix_ptr = img.pix_ptr(x, 0); for (i = 0; i <= ry; i++) { stack_pix_ptr = &stack[i]; stack_pix_ptr->r = src_pix_ptr[R]; stack_pix_ptr->g = src_pix_ptr[G]; stack_pix_ptr->b = src_pix_ptr[B]; sum_r += src_pix_ptr[R] * (i + 1); sum_g += src_pix_ptr[G] * (i + 1); sum_b += src_pix_ptr[B] * (i + 1); sum_out_r += src_pix_ptr[R]; sum_out_g += src_pix_ptr[G]; sum_out_b += src_pix_ptr[B]; } for (i = 1; i <= ry; i++) { if (i <= hm) { src_pix_ptr += stride; } stack_pix_ptr = &stack[i + ry]; stack_pix_ptr->r = src_pix_ptr[R]; stack_pix_ptr->g = src_pix_ptr[G]; stack_pix_ptr->b = src_pix_ptr[B]; sum_r += src_pix_ptr[R] * (ry + 1 - i); sum_g += src_pix_ptr[G] * (ry + 1 - i); sum_b += src_pix_ptr[B] * (ry + 1 - i); sum_in_r += src_pix_ptr[R]; sum_in_g += src_pix_ptr[G]; sum_in_b += src_pix_ptr[B]; } stack_ptr = ry; yp = ry; if (yp > hm) { yp = hm; } src_pix_ptr = img.pix_ptr(x, yp); dst_pix_ptr = img.pix_ptr(x, 0); for (y = 0; y < h; y++) { dst_pix_ptr[R] = (sum_r * mul_sum) >> shr_sum; dst_pix_ptr[G] = (sum_g * mul_sum) >> shr_sum; dst_pix_ptr[B] = (sum_b * mul_sum) >> shr_sum; dst_pix_ptr += stride; sum_r -= sum_out_r; sum_g -= sum_out_g; sum_b -= sum_out_b; stack_start = stack_ptr + div - ry; if (stack_start >= div) { stack_start -= div; } stack_pix_ptr = &stack[stack_start]; sum_out_r -= stack_pix_ptr->r; sum_out_g -= stack_pix_ptr->g; sum_out_b -= stack_pix_ptr->b; if (yp < hm) { src_pix_ptr += stride; ++yp; } stack_pix_ptr->r = src_pix_ptr[R]; stack_pix_ptr->g = src_pix_ptr[G]; stack_pix_ptr->b = src_pix_ptr[B]; sum_in_r += src_pix_ptr[R]; sum_in_g += src_pix_ptr[G]; sum_in_b += src_pix_ptr[B]; sum_r += sum_in_r; sum_g += sum_in_g; sum_b += sum_in_b; ++stack_ptr; if (stack_ptr >= div) { stack_ptr = 0; } stack_pix_ptr = &stack[stack_ptr]; sum_out_r += stack_pix_ptr->r; sum_out_g += stack_pix_ptr->g; sum_out_b += stack_pix_ptr->b; sum_in_r -= stack_pix_ptr->r; sum_in_g -= stack_pix_ptr->g; sum_in_b -= stack_pix_ptr->b; } } } #endif }
public void SetPixelHighRes(BitmapBlenderBase sourceImage, Color[] destBuffer, int destBufferOffset, int x, int y) { int r, g, b, a; r = g = b = a = LineAA.SUBPIXEL_SCALE * LineAA.SUBPIXEL_SCALE / 2; int weight; int x_lr = x >> LineAA.SUBPIXEL_SHIFT; int y_lr = y >> LineAA.SUBPIXEL_SHIFT; x &= LineAA.SUBPIXEL_MARK; y &= LineAA.SUBPIXEL_MARK; int sourceOffset; // unsafe { TempMemPtr ptr1 = sourceImage.GetBufferPtr(); int * ptr = (int *)ptr1.Ptr; sourceOffset = sourceImage.GetBufferOffsetXY32(x_lr, y_lr); weight = (LineAA.SUBPIXEL_SCALE - x) * (LineAA.SUBPIXEL_SCALE - y); // int ptr_v = ptr[sourceOffset]; r += weight * ((ptr_v >> (CO.R_SHIFT) & 0xff)); // ptr[sourceOffset + CO.R]; g += weight * ((ptr_v >> (CO.G_SHIFT) & 0xff)); //ptr[sourceOffset + CO.G]; b += weight * ((ptr_v >> (CO.B_SHIFT) & 0xff)); //ptr[sourceOffset + CO.B]; a += weight * ((ptr_v >> (CO.A_SHIFT) & 0xff)); //ptr[sourceOffset + CO.A]; // sourceOffset += 1; // sourceImage.BytesBetweenPixelsInclusive; weight = x * (LineAA.SUBPIXEL_SCALE - y); //r += weight * ptr[sourceOffset + CO.R]; //g += weight * ptr[sourceOffset + CO.G]; //b += weight * ptr[sourceOffset + CO.B]; //a += weight * ptr[sourceOffset + CO.A]; ptr_v = ptr[sourceOffset]; r += weight * ((ptr_v >> (CO.R_SHIFT) & 0xff)); // ptr[sourceOffset + CO.R]; g += weight * ((ptr_v >> (CO.G_SHIFT) & 0xff)); //ptr[sourceOffset + CO.G]; b += weight * ((ptr_v >> (CO.B_SHIFT) & 0xff)); //ptr[sourceOffset + CO.B]; a += weight * ((ptr_v >> (CO.A_SHIFT) & 0xff)); //ptr[sourceOffset + CO.A]; // sourceOffset = sourceImage.GetBufferOffsetXY32(x_lr, y_lr + 1); weight = (LineAA.SUBPIXEL_SCALE - x) * y; //r += weight * ptr[sourceOffset + CO.R]; //g += weight * ptr[sourceOffset + CO.G]; //b += weight * ptr[sourceOffset + CO.B]; //a += weight * ptr[sourceOffset + CO.A]; ptr_v = ptr[sourceOffset]; r += weight * ((ptr_v >> (CO.R_SHIFT) & 0xff)); // ptr[sourceOffset + CO.R]; g += weight * ((ptr_v >> (CO.G_SHIFT) & 0xff)); //ptr[sourceOffset + CO.G]; b += weight * ((ptr_v >> (CO.B_SHIFT) & 0xff)); //ptr[sourceOffset + CO.B]; a += weight * ((ptr_v >> (CO.A_SHIFT) & 0xff)); //ptr[sourceOffset + CO.A]; // sourceOffset += 1; // sourceImage.BytesBetweenPixelsInclusive; weight = x * y; //r += weight * ptr[sourceOffset + CO.R]; //g += weight * ptr[sourceOffset + CO.G]; //b += weight * ptr[sourceOffset + CO.B]; //a += weight * ptr[sourceOffset + CO.A]; ptr_v = ptr[sourceOffset]; r += weight * ((ptr_v >> (CO.R_SHIFT) & 0xff)); // ptr[sourceOffset + CO.R]; g += weight * ((ptr_v >> (CO.G_SHIFT) & 0xff)); //ptr[sourceOffset + CO.G]; b += weight * ((ptr_v >> (CO.B_SHIFT) & 0xff)); //ptr[sourceOffset + CO.B]; a += weight * ((ptr_v >> (CO.A_SHIFT) & 0xff)); //ptr[sourceOffset + CO.A]; //destBuffer[destBufferOffset].red = (byte)(r >> LineAA.SUBPIXEL_SHIFT * 2); //destBuffer[destBufferOffset].green = (byte)(g >> LineAA.SUBPIXEL_SHIFT * 2); //destBuffer[destBufferOffset].blue = (byte)(b >> LineAA.SUBPIXEL_SHIFT * 2); //destBuffer[destBufferOffset].alpha = (byte)(a >> LineAA.SUBPIXEL_SHIFT * 2); } destBuffer[destBufferOffset] = Color.FromArgb( (byte)(a >> LineAA.SUBPIXEL_SHIFT * 2), (byte)(r >> LineAA.SUBPIXEL_SHIFT * 2), (byte)(g >> LineAA.SUBPIXEL_SHIFT * 2), (byte)(b >> LineAA.SUBPIXEL_SHIFT * 2) ); }