Exemplo n.º 1
0
 void AttachBuffer(PixelFarm.CpuBlit.Imaging.TempMemPtr buffer,
                   int elemOffset,
                   int width,
                   int height,
                   int strideInBytes,
                   int bitDepth,
                   int distanceInBytesBetweenPixelsInclusive)
 {
     SetBufferToNull();
     SetDimmensionAndFormat(width, height, strideInBytes, bitDepth,
                            distanceInBytesBetweenPixelsInclusive);
     SetBuffer(buffer, elemOffset);
 }
Exemplo n.º 2
0
        static GlyphImage ReadGlyphImages(string filename)
        {
            PixelFarm.CpuBlit.ActualBitmap bmp = StorageService.Provider.ReadPngBitmap(filename);
            GlyphImage img = new GlyphImage(bmp.Width, bmp.Height);

            int[] buffer = new int[bmp.Width * bmp.Height];
            unsafe
            {
                PixelFarm.CpuBlit.Imaging.TempMemPtr tmp = PixelFarm.CpuBlit.ActualBitmap.GetBufferPtr(bmp);
                System.Runtime.InteropServices.Marshal.Copy(tmp.Ptr, buffer, 0, bmp.Width * bmp.Height);
                img.SetImageBuffer(buffer, true);
            }
            return(img);
        }
Exemplo n.º 3
0
 public SubBitmapBlender(PixelFarm.CpuBlit.Imaging.TempMemPtr buffer,
                         int arrayOffset32,
                         int width,
                         int height,
                         int strideInBytes,
                         int bitDepth,
                         int distanceInBytesBetweenPixelsInclusive)
 {
     AttachBuffer(buffer,
                  arrayOffset32,
                  width,
                  height,
                  strideInBytes, bitDepth,
                  distanceInBytesBetweenPixelsInclusive);
 }
Exemplo n.º 4
0
 static GlyphImage ReadGlyphImages(System.IO.Stream stream)
 {
     using (PixelFarm.CpuBlit.MemBitmap bmp = PixelFarm.CpuBlit.MemBitmap.LoadBitmap(stream))
     {
         GlyphImage img    = new GlyphImage(bmp.Width, bmp.Height);
         int[]      buffer = new int[bmp.Width * bmp.Height];
         unsafe
         {
             PixelFarm.CpuBlit.Imaging.TempMemPtr tmp = PixelFarm.CpuBlit.MemBitmap.GetBufferPtr(bmp);
             System.Runtime.InteropServices.Marshal.Copy(tmp.Ptr, buffer, 0, bmp.Width * bmp.Height);
             img.SetImageBuffer(buffer, true);
         }
         return(img);
     }
 }
Exemplo n.º 5
0
        public static void Save(MemBitmap bmp, Stream strm)
        {
            //-------------
            unsafe
            {
                PixelFarm.CpuBlit.Imaging.TempMemPtr tmp = MemBitmap.GetBufferPtr(bmp);
                int *intBuffer = (int *)tmp.Ptr;

                int imgW = bmp.Width;
                int imgH = bmp.Height;

                Hjg.Pngcs.ImageInfo imgInfo = new Hjg.Pngcs.ImageInfo(imgW, imgH, 8, true); //8 bits per channel with alpha
                Hjg.Pngcs.PngWriter writer  = new Hjg.Pngcs.PngWriter(strm, imgInfo);
                Hjg.Pngcs.ImageLine iline   = new Hjg.Pngcs.ImageLine(imgInfo, Hjg.Pngcs.ImageLine.ESampleType.BYTE);
                int startReadAt             = 0;

                int imgStride = imgW * 4;

                int srcIndex        = 0;
                int srcIndexRowHead = (tmp.LengthInBytes / 4) - imgW;

                for (int row = 0; row < imgH; row++)
                {
                    byte[] scanlineBuffer = iline.ScanlineB;
                    srcIndex = srcIndexRowHead;
                    for (int b = 0; b < imgStride;)
                    {
                        int srcInt = intBuffer[srcIndex];
                        srcIndex++;
                        scanlineBuffer[b]     = (byte)((srcInt >> 16) & 0xff);
                        scanlineBuffer[b + 1] = (byte)((srcInt >> 8) & 0xff);
                        scanlineBuffer[b + 2] = (byte)((srcInt) & 0xff);
                        scanlineBuffer[b + 3] = (byte)((srcInt >> 24) & 0xff);
                        b += 4;
                    }
                    srcIndexRowHead -= imgW;
                    startReadAt     += imgStride;
                    writer.WriteRow(iline, row);
                }
                writer.End();
            }
        }
Exemplo n.º 6
0
        //bool Attach(IBitmapBlender sourceImage, int x1, int y1, int x2, int y2)
        //{
        //    _sourceImage = sourceImage;
        //    SetBufferToNull();
        //    if (x1 > x2 || y1 > y2)
        //    {
        //        throw new Exception("You need to have your x1 and y1 be the lower left corner of your sub image.");
        //    }
        //    RectInt boundsRect = new RectInt(x1, y1, x2, y2);
        //    if (boundsRect.Clip(new RectInt(0, 0, sourceImage.Width - 1, sourceImage.Height - 1)))
        //    {
        //        SetDimmensionAndFormat(boundsRect.Width, boundsRect.Height, sourceImage.Stride, sourceImage.BitDepth, sourceImage.BytesBetweenPixelsInclusive);
        //        int bufferOffset = sourceImage.GetByteBufferOffsetXY(boundsRect.Left, boundsRect.Bottom) / 4;
        //        int[] buffer = sourceImage.GetInt32Buffer();
        //        SetBuffer(buffer, bufferOffset);
        //        return true;
        //    }

        //    return false;
        //}

        void SetBuffer(PixelFarm.CpuBlit.Imaging.TempMemPtr src, int arrayElemOffset)
        {
            int height = this.Height;

            if ((src.LengthInBytes / 4) < height * Width)
            {
                throw new Exception("Your buffer does not have enough room it it for your height and strideInBytes.");
            }

            SetBuffer(src);
            _int32ArrayStartPixelAt = arrayElemOffset;

            if (this.Stride < 0) //stride in bytes
            {
                //TODO: review here
                int addAmount = -((height - 1) * Width);
                _int32ArrayStartPixelAt = addAmount + arrayElemOffset;
            }
            SetUpLookupTables();
        }
Exemplo n.º 7
0
        // Create
        //--------------------------------------------------------------------
        public void Create(IBitmapSrc src)
        {
            // we are going to create a dialated image for filtering
            // we add m_dilation pixels to every side of the image and then copy the image in the x
            // dirrection into each end so that we can sample into this image to get filtering on x repeating
            // if the original image look like this
            //
            // 123456 
            //
            // the new image would look like this
            //
            // 0000000000
            // 0000000000
            // 5612345612
            // 0000000000
            // 0000000000

            _height = (int)AggMath.uceil(src.Height);
            _width = (int)AggMath.uceil(src.Width);
            _width_hr = (int)AggMath.uround(src.Width * LineAA.SUBPIXEL_SCALE);
            _half_height_hr = (int)AggMath.uround(src.Height * LineAA.SUBPIXEL_SCALE / 2);
            _offset_y_hr = _dilation_hr + _half_height_hr - LineAA.SUBPIXEL_SCALE / 2;
            _half_height_hr += LineAA.SUBPIXEL_SCALE / 2;
            int bufferWidth = _width + _dilation * 2;
            int bufferHeight = _height + _dilation * 2;
            int bytesPerPixel = src.BitDepth / 8;
            int newSizeInBytes = bufferWidth * bufferHeight * bytesPerPixel;
            if (_DataSizeInBytes < newSizeInBytes)
            {
                _DataSizeInBytes = newSizeInBytes;

                _data.Dispose();

                IntPtr nativeBuff = System.Runtime.InteropServices.Marshal.AllocHGlobal(_DataSizeInBytes);
                _data = new Imaging.TempMemPtr(nativeBuff, _DataSizeInBytes);
            }

            _buf = new PixelProcessing.SubBitmapBlender(_data, 0, bufferWidth, bufferHeight, bufferWidth * bytesPerPixel, src.BitDepth, bytesPerPixel);

            unsafe
            {

                using (CpuBlit.Imaging.TempMemPtr destMemPtr = _buf.GetBufferPtr())
                using (CpuBlit.Imaging.TempMemPtr srcMemPtr = src.GetBufferPtr())
                {
                    int* destBuffer = (int*)destMemPtr.Ptr;
                    int* srcBuffer = (int*)srcMemPtr.Ptr;
                    // copy the image into the middle of the dest
                    for (int y = 0; y < _height; y++)
                    {
                        for (int x = 0; x < _width; x++)
                        {
                            int sourceOffset = src.GetBufferOffsetXY32(x, y);
                            int destOffset = _buf.GetBufferOffsetXY32(_dilation, y + _dilation);
                            destBuffer[destOffset] = srcBuffer[sourceOffset];
                        }
                    }

                    // copy the first two pixels form the end into the begining and from the begining into the end
                    for (int y = 0; y < _height; y++)
                    {
                        int s1Offset = src.GetBufferOffsetXY32(0, y);
                        int d1Offset = _buf.GetBufferOffsetXY32(_dilation + _width, y);
                        int s2Offset = src.GetBufferOffsetXY32(_width - _dilation, y);
                        int d2Offset = _buf.GetBufferOffsetXY32(0, y);

                        for (int x = 0; x < _dilation; x++)
                        {
                            destBuffer[d1Offset++] = srcBuffer[s1Offset++];
                            destBuffer[d2Offset++] = srcBuffer[s2Offset++];
                        }
                    }
                }
            }



        }