Ejemplo n.º 1
0
        public void blur_x(IImageByte img, double radius)
        {
            if (radius < 0.62)
            {
                return;
            }
            if (img.Width < 3)
            {
                return;
            }

            double s = (double)(radius * 0.5);
            double q = (double)((s < 2.5) ?
                                3.97156 - 4.14554 * Math.Sqrt(1 - 0.26891 * s) :
                                0.98711 * s - 0.96330);

            double q2 = (double)(q * q);
            double q3 = (double)(q2 * q);

            double b0 = (double)(1.0 / (1.578250 +
                                        2.444130 * q +
                                        1.428100 * q2 +
                                        0.422205 * q3));

            double b1 = (double)(2.44413 * q +
                                 2.85619 * q2 +
                                 1.26661 * q3);

            double b2 = (double)(-1.42810 * q2 +
                                 -1.26661 * q3);

            double b3 = (double)(0.422205 * q3);

            double b = (double)(1 - (b1 + b2 + b3) * b0);

            b1 *= b0;
            b2 *= b0;
            b3 *= b0;

            int w = img.Width;
            int h = img.Height;
            int wm = (int)w - 1;
            int x, y;

            int StartCreatingAt = (int)m_sum1.Count;

            for (int i = StartCreatingAt; i < w; i++)
            {
                m_sum1.Add(null);
                m_sum2.Add(null);
            }
            m_buf.Allocate(w);

            List <RecursizeBlurCalculator> Sum1Array = m_sum1;
            List <RecursizeBlurCalculator> Sum2Array = m_sum2;

            Color[] BufferArray = m_buf.Array;

            for (int i = StartCreatingAt; i < w; i++)
            {
                Sum1Array[i] = m_RecursizeBlurCalculatorFactory.CreateNew();
                Sum2Array[i] = m_RecursizeBlurCalculatorFactory.CreateNew();
            }

            for (y = 0; y < h; y++)
            {
                RecursizeBlurCalculator c = m_RecursizeBlurCalculatorFactory;
                c.from_pix(img.GetPixel(0, y));
                Sum1Array[0].calc(b, b1, b2, b3, c, c, c, c);
                c.from_pix(img.GetPixel(1, y));
                Sum1Array[1].calc(b, b1, b2, b3, c, Sum1Array[0], Sum1Array[0], Sum1Array[0]);
                c.from_pix(img.GetPixel(2, y));
                Sum1Array[2].calc(b, b1, b2, b3, c, Sum1Array[1], Sum1Array[0], Sum1Array[0]);

                for (x = 3; x < w; ++x)
                {
                    c.from_pix(img.GetPixel(x, y));
                    Sum1Array[x].calc(b, b1, b2, b3, c, Sum1Array[x - 1], Sum1Array[x - 2], Sum1Array[x - 3]);
                }

                Sum2Array[wm].calc(b, b1, b2, b3, Sum1Array[wm], Sum1Array[wm], Sum1Array[wm], Sum1Array[wm]);
                Sum2Array[wm - 1].calc(b, b1, b2, b3, Sum1Array[wm - 1], Sum2Array[wm], Sum2Array[wm], Sum2Array[wm]);
                Sum2Array[wm - 2].calc(b, b1, b2, b3, Sum1Array[wm - 2], Sum2Array[wm - 1], Sum2Array[wm], Sum2Array[wm]);
                Sum2Array[wm].to_pix(ref BufferArray[wm]);
                Sum2Array[wm - 1].to_pix(ref BufferArray[wm - 1]);
                Sum2Array[wm - 2].to_pix(ref BufferArray[wm - 2]);

                for (x = wm - 3; x >= 0; --x)
                {
                    Sum2Array[x].calc(b, b1, b2, b3, Sum1Array[x], Sum2Array[x + 1], Sum2Array[x + 2], Sum2Array[x + 3]);
                    Sum2Array[x].to_pix(ref BufferArray[x]);
                }

                img.copy_color_hspan(0, y, w, BufferArray, 0);
            }
        }
Ejemplo n.º 2
0
        public void blur_x(IImageByte img, int radius)
        {
            throw new NotImplementedException();
#if false
            if (radius < 1)
            {
                return;
            }

            int x, y, xp, i;
            int stack_ptr;
            int stack_start;

            color_type      pix;
            color_type *    stack_pix;
            calculator_type sum;
            calculator_type sum_in;
            calculator_type sum_out;

            int w   = img.width();
            int h   = img.height();
            int wm  = w - 1;
            int div = radius * 2 + 1;

            int div_sum = (radius + 1) * (radius + 1);
            int mul_sum = 0;
            int shr_sum = 0;
            int max_val = base_mask;

            if (max_val <= 255 && radius < 255)
            {
                mul_sum = stack_blur_tables.g_stack_blur8_mul[radius];
                shr_sum = stack_blur_tables.g_stack_blur8_shr[radius];
            }

            m_buf.allocate(w, 128);
            m_stack.allocate(div, 32);

            for (y = 0; y < h; y++)
            {
                sum.clear();
                sum_in.clear();
                sum_out.clear();

                pix = img.pixel(0, y);
                for (i = 0; i <= radius; i++)
                {
                    m_stack[i] = pix;
                    sum.add(pix, i + 1);
                    sum_out.add(pix);
                }
                for (i = 1; i <= radius; i++)
                {
                    pix = img.pixel((i > wm) ? wm : i, y);
                    m_stack[i + radius] = pix;
                    sum.add(pix, radius + 1 - i);
                    sum_in.add(pix);
                }

                stack_ptr = radius;
                for (x = 0; x < w; x++)
                {
                    if (mul_sum)
                    {
                        sum.calc_pix(m_buf[x], mul_sum, shr_sum);
                    }
                    else
                    {
                        sum.calc_pix(m_buf[x], div_sum);
                    }

                    sum.sub(sum_out);

                    stack_start = stack_ptr + div - radius;
                    if (stack_start >= div)
                    {
                        stack_start -= div;
                    }
                    stack_pix = &m_stack[stack_start];

                    sum_out.sub(*stack_pix);

                    xp = x + radius + 1;
                    if (xp > wm)
                    {
                        xp = wm;
                    }
                    pix = img.pixel(xp, y);

                    *stack_pix = pix;

                    sum_in.add(pix);
                    sum.add(sum_in);

                    ++stack_ptr;
                    if (stack_ptr >= div)
                    {
                        stack_ptr = 0;
                    }
                    stack_pix = &m_stack[stack_ptr];

                    sum_out.add(*stack_pix);
                    sum_in.sub(*stack_pix);
                }
                img.copy_color_hspan(0, y, w, &m_buf[0]);
            }
#endif
        }
Ejemplo n.º 3
0
		public void blur_x(IImageByte img, double radius)
		{
			if (radius < 0.62) return;
			if (img.Width < 3) return;

			double s = (double)(radius * 0.5);
			double q = (double)((s < 2.5) ?
									3.97156 - 4.14554 * Math.Sqrt(1 - 0.26891 * s) :
									0.98711 * s - 0.96330);

			double q2 = (double)(q * q);
			double q3 = (double)(q2 * q);

			double b0 = (double)(1.0 / (1.578250 +
											2.444130 * q +
											1.428100 * q2 +
											0.422205 * q3));

			double b1 = (double)(2.44413 * q +
									  2.85619 * q2 +
									  1.26661 * q3);

			double b2 = (double)(-1.42810 * q2 +
									 -1.26661 * q3);

			double b3 = (double)(0.422205 * q3);

			double b = (double)(1 - (b1 + b2 + b3) * b0);

			b1 *= b0;
			b2 *= b0;
			b3 *= b0;

			int w = img.Width;
			int h = img.Height;
			int wm = (int)w - 1;
			int x, y;

			int StartCreatingAt = (int)m_sum1.Count;
			for (int i = StartCreatingAt; i < w; i++)
			{
				m_sum1.Add(null);
				m_sum2.Add(null);
			}
			m_buf.Allocate(w);

			List<RecursizeBlurCalculator> Sum1Array = m_sum1;
			List<RecursizeBlurCalculator> Sum2Array = m_sum2;
			RGBA_Bytes[] BufferArray = m_buf.Array;

			for (int i = StartCreatingAt; i < w; i++)
			{
				Sum1Array[i] = m_RecursizeBlurCalculatorFactory.CreateNew();
				Sum2Array[i] = m_RecursizeBlurCalculatorFactory.CreateNew();
			}

			for (y = 0; y < h; y++)
			{
				RecursizeBlurCalculator c = m_RecursizeBlurCalculatorFactory;
				c.from_pix(img.GetPixel(0, y));
				Sum1Array[0].calc(b, b1, b2, b3, c, c, c, c);
				c.from_pix(img.GetPixel(1, y));
				Sum1Array[1].calc(b, b1, b2, b3, c, Sum1Array[0], Sum1Array[0], Sum1Array[0]);
				c.from_pix(img.GetPixel(2, y));
				Sum1Array[2].calc(b, b1, b2, b3, c, Sum1Array[1], Sum1Array[0], Sum1Array[0]);

				for (x = 3; x < w; ++x)
				{
					c.from_pix(img.GetPixel(x, y));
					Sum1Array[x].calc(b, b1, b2, b3, c, Sum1Array[x - 1], Sum1Array[x - 2], Sum1Array[x - 3]);
				}

				Sum2Array[wm].calc(b, b1, b2, b3, Sum1Array[wm], Sum1Array[wm], Sum1Array[wm], Sum1Array[wm]);
				Sum2Array[wm - 1].calc(b, b1, b2, b3, Sum1Array[wm - 1], Sum2Array[wm], Sum2Array[wm], Sum2Array[wm]);
				Sum2Array[wm - 2].calc(b, b1, b2, b3, Sum1Array[wm - 2], Sum2Array[wm - 1], Sum2Array[wm], Sum2Array[wm]);
				Sum2Array[wm].to_pix(ref BufferArray[wm]);
				Sum2Array[wm - 1].to_pix(ref BufferArray[wm - 1]);
				Sum2Array[wm - 2].to_pix(ref BufferArray[wm - 2]);

				for (x = wm - 3; x >= 0; --x)
				{
					Sum2Array[x].calc(b, b1, b2, b3, Sum1Array[x], Sum2Array[x + 1], Sum2Array[x + 2], Sum2Array[x + 3]);
					Sum2Array[x].to_pix(ref BufferArray[x]);
				}

				img.copy_color_hspan(0, y, w, BufferArray, 0);
			}
		}
Ejemplo n.º 4
0
 public virtual void copy_color_hspan(int x, int y, int len, RGBA_Bytes[] colors, int colorIndex)
 {
     linkedImage.copy_color_hspan(x, y, len, colors, colorIndex);
 }
Ejemplo n.º 5
0
		public void blur_x(IImageByte img, int radius)
		{
			throw new NotImplementedException();
#if false
            if(radius < 1) return;

            int x, y, xp, i;
            int stack_ptr;
            int stack_start;

            color_type      pix;
            color_type*     stack_pix;
            calculator_type sum;
            calculator_type sum_in;
            calculator_type sum_out;

            int w   = img.width();
            int h   = img.height();
            int wm  = w - 1;
            int div = radius * 2 + 1;

            int div_sum = (radius + 1) * (radius + 1);
            int mul_sum = 0;
            int shr_sum = 0;
            int max_val = base_mask;

            if(max_val <= 255 && radius < 255)
            {
                mul_sum = stack_blur_tables.g_stack_blur8_mul[radius];
                shr_sum = stack_blur_tables.g_stack_blur8_shr[radius];
            }

            m_buf.allocate(w, 128);
            m_stack.allocate(div, 32);

            for(y = 0; y < h; y++)
            {
                sum.clear();
                sum_in.clear();
                sum_out.clear();

                pix = img.pixel(0, y);
                for(i = 0; i <= radius; i++)
                {
                    m_stack[i] = pix;
                    sum.add(pix, i + 1);
                    sum_out.add(pix);
                }
                for(i = 1; i <= radius; i++)
                {
                    pix = img.pixel((i > wm) ? wm : i, y);
                    m_stack[i + radius] = pix;
                    sum.add(pix, radius + 1 - i);
                    sum_in.add(pix);
                }

                stack_ptr = radius;
                for(x = 0; x < w; x++)
                {
                    if(mul_sum) sum.calc_pix(m_buf[x], mul_sum, shr_sum);
                    else        sum.calc_pix(m_buf[x], div_sum);

                    sum.sub(sum_out);

                    stack_start = stack_ptr + div - radius;
                    if(stack_start >= div) stack_start -= div;
                    stack_pix = &m_stack[stack_start];

                    sum_out.sub(*stack_pix);

                    xp = x + radius + 1;
                    if(xp > wm) xp = wm;
                    pix = img.pixel(xp, y);

                    *stack_pix = pix;

                    sum_in.add(pix);
                    sum.add(sum_in);

                    ++stack_ptr;
                    if(stack_ptr >= div) stack_ptr = 0;
                    stack_pix = &m_stack[stack_ptr];

                    sum_out.add(*stack_pix);
                    sum_in.sub(*stack_pix);
                }
                img.copy_color_hspan(0, y, w, &m_buf[0]);
            }
#endif
		}