public unsafe int[] Sharpen(int *srcBuffer1, int w, int h, int srcBufferStrideInBytes, int radius)
        {
            unsafe
            {
                int[] output = new int[(srcBufferStrideInBytes / 4) * h]; //TODO: review here again
                fixed(int *outputPtr = &output[0])
                {
                    int *outputBuffer1 = (int *)outputPtr;

                    MemHolder srcMemHolder = new MemHolder((IntPtr)srcBuffer1, srcBufferStrideInBytes / 4);//
                    Surface   srcSurface   = new Surface(srcBufferStrideInBytes, w, h, srcMemHolder);
                    //
                    MemHolder destMemHolder = new MemHolder((IntPtr)outputPtr, srcBufferStrideInBytes / 4);
                    Surface   destSurface   = new Surface(srcBufferStrideInBytes, w, h, destMemHolder);
                    //
                    SharpenRenderer shRenderer1 = new SharpenRenderer();

                    shRenderer1.Amount = radius;
                    shRenderer1.Render(srcSurface, destSurface, new PixelFarm.Drawing.Rectangle[] {
                        new PixelFarm.Drawing.Rectangle(0, 0, w, h)
                    }, 0, 1);
                }

                //ActualImage.SaveImgBufferToPngFile(output, img.Stride, img.Width + 1, img.Height + 1, "d:\\WImageTest\\test_1.png");
                return(output);
            }
        }
        public void Sharpen(IBitmapSrc img, int radius)
        {
            unsafe
            {
                TempMemPtr bufferPtr = img.GetBufferPtr();
                int[]      output    = new int[bufferPtr.LengthInBytes / 4]; //TODO: review here again

                fixed(int *outputPtr = &output[0])
                {
                    byte *srcBuffer     = (byte *)bufferPtr.Ptr;
                    int * srcBuffer1    = (int *)srcBuffer;
                    int * outputBuffer1 = (int *)outputPtr;
                    int   stride        = img.Stride;
                    int   w             = img.Width;
                    int   h             = img.Height;

                    MemHolder srcMemHolder = new MemHolder((IntPtr)srcBuffer1, bufferPtr.LengthInBytes / 4);//
                    Surface   srcSurface   = new Surface(stride, w, h, srcMemHolder);
                    //
                    MemHolder destMemHolder = new MemHolder((IntPtr)outputPtr, bufferPtr.LengthInBytes / 4);
                    Surface   destSurface   = new Surface(stride, w, h, destMemHolder);
                    //
                    SharpenRenderer shRenderer1 = new SharpenRenderer();

                    shRenderer1.Amount = radius;
                    shRenderer1.Render(srcSurface, destSurface, new PixelFarm.Drawing.Rectangle[] {
                        new PixelFarm.Drawing.Rectangle(0, 0, w, h)
                    }, 0, 1);
                }

                bufferPtr.Release();
                //ActualImage.SaveImgBufferToPngFile(output, img.Stride, img.Width + 1, img.Height + 1, "d:\\WImageTest\\test_1.png");
                img.ReplaceBuffer(output);
            }
        }
示例#3
0
        public override void Apply()
        {
            unsafe
            {
                using (TempMemPtr bufferPtr = _target.GetBufferPtr())
                {
                    int[] output = new int[bufferPtr.LengthInBytes / 4]; //TODO: review here again

                    fixed(int *outputPtr = &output[0])
                    {
                        byte *srcBuffer     = (byte *)bufferPtr.Ptr;
                        int * srcBuffer1    = (int *)srcBuffer;
                        int * outputBuffer1 = (int *)outputPtr;
                        int   stride        = _target.Stride;
                        int   w             = _target.Width;
                        int   h             = _target.Height;

                        MemHolder srcMemHolder = new MemHolder((IntPtr)srcBuffer1, bufferPtr.LengthInBytes / 4);//
                        Surface   srcSurface   = new Surface(stride, w, h, srcMemHolder);
                        //
                        MemHolder destMemHolder = new MemHolder((IntPtr)outputPtr, bufferPtr.LengthInBytes / 4);
                        Surface   destSurface   = new Surface(stride, w, h, destMemHolder);

                        //

                        _shRenderer1.Amount = Radius;
                        _shRenderer1.Render(srcSurface, destSurface, new PixelFarm.Drawing.Rectangle[] {
                            new PixelFarm.Drawing.Rectangle(0, 0, w, h)
                        }, 0, 1);
                    }

                    _target.WriteBuffer(output);
                }
            }
        }
示例#4
0
            public object this[int index] {
                get {
                    index = PythonOps.FixIndex(index, ((ArrayType)NativeType).Length);
                    INativeType elementType = ElementType;
                    return(elementType.GetValue(
                               MemHolder,
                               this,
                               checked (index * elementType.Size),
                               false
                               ));
                }
                set {
                    index = PythonOps.FixIndex(index, ((ArrayType)NativeType).Length);
                    INativeType elementType = ElementType;

                    object keepAlive = elementType.SetValue(
                        MemHolder,
                        checked (index * elementType.Size),
                        value
                        );

                    if (keepAlive != null)
                    {
                        MemHolder.AddObject(index.ToString(), keepAlive);
                    }
                }
            }
示例#5
0
        private void button2_Click(object sender, EventArgs e)
        {
            //create surface from memory
            //on 32 argb format


            Bitmap bmp     = new Bitmap("lion1.png");
            var    bmpData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
                                          System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                          System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            int w         = bmp.Width;
            int h         = bmp.Height;
            int stride    = bmpData.Stride;
            int bufferLen = w * h;

            int[] srcBmpBuffer  = new int[bufferLen];
            int[] destBmpBuffer = new int[bufferLen];

            System.Runtime.InteropServices.Marshal.Copy(bmpData.Scan0, srcBmpBuffer, 0, srcBmpBuffer.Length);
            bmp.UnlockBits(bmpData);
            //
            unsafe
            {
                fixed(int *srcBmpH = &srcBmpBuffer[0])
                fixed(int *destBmpH = &destBmpBuffer[0])
                {
                    MemHolder srcMemHolder = new MemHolder((IntPtr)srcBmpH, bufferLen);
                    Surface   srcSurface   = new Surface(stride, w, h, srcMemHolder);

                    MemHolder destMemHolder = new MemHolder((IntPtr)destBmpH, bufferLen);
                    Surface   destSurface   = new Surface(stride, w, h, destMemHolder);

                    //effect
                    RotateZoomEffect eff = new RotateZoomEffect();

                    eff.SelectionBounds = new PixelFarm.Drawing.Rectangle(0, 0, w, h);
                    eff.Parameters      = _rotateZoomConfigToken;
                    eff.Render(srcSurface, destSurface, new PixelFarm.Drawing.Rectangle[] {
                        new PixelFarm.Drawing.Rectangle(0, 0, w, h)
                    }, 0, 1);
                }
            }

            //save to output
            Bitmap outputBmp = new Bitmap(bmp.Width, bmp.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            var    bmpData2  = outputBmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
                                                  System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            System.Runtime.InteropServices.Marshal.Copy(destBmpBuffer, 0, bmpData2.Scan0, destBmpBuffer.Length);
            outputBmp.UnlockBits(bmpData2);

            this.pictureBox2.Image = outputBmp;
            this.pictureBox1.Image = bmp;


            //process the image
            //then copy to bitmap
            //
        }
示例#6
0
 public void Setvalue(object value)
 {
     NativeType.SetValue(MemHolder, 0, value);
     if (IsString)
     {
         MemHolder.AddObject("str", value);
     }
 }
示例#7
0
            public object this[int index] {
                get {
                    INativeType  type    = ((PointerType)NativeType)._type;
                    MemoryHolder address = MemHolder.ReadMemoryHolder(0);

                    return(type.GetValue(address, this, checked (type.Size * index), false));
                }
                set {
                    MemoryHolder address = MemHolder.ReadMemoryHolder(0);

                    INativeType type      = ((PointerType)NativeType)._type;
                    object      keepAlive = type.SetValue(address, checked (type.Size * index), value);
                    if (keepAlive != null)
                    {
                        MemHolder.AddObject(index.ToString(), keepAlive);
                    }
                }
            }
示例#8
0
        private void button1_Click(object sender, EventArgs e)
        {
            //create surface from memory
            //on 32 argb format

            Bitmap bmp = new Bitmap("d:\\WImageTest\\lion1.png");

            var bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                                       System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                       System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            int w      = bmp.Width;
            int h      = bmp.Height;
            int stride = bmpData.Stride;

            int[] srcBmpBuffer = new int[w * h];

            int[] destBmpBuffer = new int[w * h];
            System.Runtime.InteropServices.Marshal.Copy(bmpData.Scan0, srcBmpBuffer, 0, srcBmpBuffer.Length);
            bmp.UnlockBits(bmpData);
            //
            unsafe
            {
                fixed(int *srcBmpH = &srcBmpBuffer[0])
                fixed(int *destBmpH = &destBmpBuffer[0])
                {
                    MemHolder srcMemHolder = new MemHolder((IntPtr)srcBmpH, srcBmpBuffer.Length);
                    Surface   srcSurface   = new Surface(stride, w, h, srcMemHolder);

                    MemHolder destMemHolder = new MemHolder((IntPtr)destBmpH, destBmpBuffer.Length);
                    Surface   destSurface   = new Surface(stride, w, h, destMemHolder);

                    //
                    //apply some filter
                    //

                    EmbossRenderer emboss = new EmbossRenderer();

                    emboss.SetParameters(30);
                    emboss.Render(srcSurface, destSurface, new PixelFarm.Drawing.Rectangle[] {
                        new PixelFarm.Drawing.Rectangle(0, 0, w, h)
                    }, 0, 1);

                    //SharpenRenderer sharpen = new SharpenRenderer();
                    //sharpen.Amount = 2;
                    //sharpen.Render(srcSurface, destSurface, new PixelFarm.Drawing.Rectangle[]{
                    //        new PixelFarm.Drawing.Rectangle(0,0,w,h)
                    //    }, 0, 0);
                }
            }

            //save to output
            Bitmap outputBmp = new Bitmap(bmp.Width, bmp.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            var    bmpData2  = outputBmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                                                  System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            System.Runtime.InteropServices.Marshal.Copy(destBmpBuffer, 0, bmpData2.Scan0, destBmpBuffer.Length);
            outputBmp.UnlockBits(bmpData2);

            this.pictureBox2.Image = outputBmp;
            this.pictureBox1.Image = bmp;


            //process the image
            //then copy to bitmap
            //
        }
示例#9
0
            public object this[Slice index] {
                get {
                    if (index.stop == null)
                    {
                        throw PythonOps.ValueError("slice stop is required");
                    }

                    int start = index.start != null ? (int)index.start : 0;
                    int stop  = index.stop != null ? (int)index.stop : 0;
                    int step  = index.step != null ? (int)index.step : 1;

                    if (step < 0 && index.start == null)
                    {
                        throw PythonOps.ValueError("slice start is required for step < 0");
                    }

                    if (start < 0)
                    {
                        start = 0;
                    }
                    INativeType type     = ((PointerType)NativeType)._type;
                    SimpleType  elemType = type as SimpleType;

                    if ((stop < start && step > 0) || (start < stop && step < 0))
                    {
                        if (elemType != null)
                        {
                            if (elemType._type == SimpleTypeKind.Char)
                            {
                                return(Bytes.Empty);
                            }
                            if (elemType._type == SimpleTypeKind.WChar)
                            {
                                return(string.Empty);
                            }
                        }
                        return(new PythonList());
                    }

                    MemoryHolder address = MemHolder.ReadMemoryHolder(0);
                    if (elemType != null)
                    {
                        if (elemType._type == SimpleTypeKind.Char)
                        {
                            Debug.Assert(((INativeType)elemType).Size == 1);
                            var sb = new MemoryStream();

                            for (int i = start; stop > start ? i <stop : i> stop; i += step)
                            {
                                sb.WriteByte(address.ReadByte(i));
                            }

                            return(Bytes.Make(sb.ToArray()));
                        }
                        if (elemType._type == SimpleTypeKind.WChar)
                        {
                            int elmSize = ((INativeType)elemType).Size;
                            var sb      = new StringBuilder();

                            for (int i = start; stop > start ? i <stop : i> stop; i += step)
                            {
                                sb.Append((char)address.ReadInt16(checked (i * elmSize)));
                            }

                            return(sb.ToString());
                        }
                    }

                    PythonList res = new PythonList((stop - start) / step);
                    for (int i = start; stop > start ? i <stop : i> stop; i += step)
                    {
                        res.AddNoLock(
                            type.GetValue(address, this, checked (type.Size * i), false)
                            );
                    }
                    return(res);
                }
            }
示例#10
0
 public bool __bool__()
 {
     return(MemHolder.ReadIntPtr(0) != IntPtr.Zero);
 }
示例#11
0
            public object this[[NotNone] Slice slice] {
                get {
                    int        start, stop, step, count;
                    int        size     = ((ArrayType)NativeType).Length;
                    SimpleType elemType = ((ArrayType)NativeType).ElementType as SimpleType;

                    slice.GetIndicesAndCount(size, out start, out stop, out step, out count);
                    if ((step > 0 && start >= stop) || (step < 0 && start <= stop))
                    {
                        if (elemType != null)
                        {
                            if (elemType._type == SimpleTypeKind.Char)
                            {
                                return(Bytes.Empty);
                            }
                            if (elemType._type == SimpleTypeKind.WChar)
                            {
                                return(string.Empty);
                            }
                        }
                        return(new PythonList());
                    }

                    if (elemType != null)
                    {
                        if (elemType._type == SimpleTypeKind.Char)
                        {
                            Debug.Assert(((INativeType)elemType).Size == 1);
                            if (step == 1)
                            {
                                return(MemHolder.ReadBytes(start, count));
                            }
                            else
                            {
                                var buffer = new byte[count];
                                for (int i = 0, index = start; i < count; i++, index += step)
                                {
                                    buffer[i] = MemHolder.ReadByte(index);
                                }
                                return(Bytes.Make(buffer));
                            }
                        }
                        if (elemType._type == SimpleTypeKind.WChar)
                        {
                            int elmSize = ((INativeType)elemType).Size;
                            if (step == 1)
                            {
                                return(MemHolder.ReadUnicodeString(checked (start * elmSize), count));
                            }
                            else
                            {
                                var res = new StringBuilder(count);
                                for (int i = 0, index = start; i < count; i++, index += step)
                                {
                                    res.Append((char)MemHolder.ReadInt16(checked (index * elmSize)));
                                }
                                return(res.ToString());
                            }
                        }
                    }

                    object[] ret = new object[count];
                    for (int i = 0, index = start; i < count; i++, index += step)
                    {
                        ret[i] = this[index];
                    }

                    return(PythonList.FromArrayNoCopy(ret));
                }
                set {
                    int start, stop, step, count;
                    int size = ((ArrayType)NativeType).Length;

                    slice.GetIndicesAndCount(size, out start, out stop, out step, out count);

                    IEnumerator ie = PythonOps.GetEnumerator(value);
                    for (int i = 0, index = start; i < count; i++, index += step)
                    {
                        if (!ie.MoveNext())
                        {
                            throw PythonOps.ValueError("sequence not long enough");
                        }
                        this[index] = ie.Current;
                    }

                    if (ie.MoveNext())
                    {
                        throw PythonOps.ValueError("not all values consumed while slicing");
                    }
                }
            }