Beispiel #1
0
 public BitmapBasedRegion(ReconstructedRegionData reconRgnData)
 {
     _reconRgnData = reconRgnData;
     _bounds       = reconRgnData.GetBounds();
 }
Beispiel #2
0
        public static CpuBlit.MemBitmap CreateMaskBitmap(this ReconstructedRegionData rgnData,
                                                         Drawing.Color solidPartColor,
                                                         Drawing.Color holeColor,
                                                         bool useFitBounds = true)
        {
            //1. find size of membitmap
            Drawing.Rectangle fitBounds = rgnData.GetBounds();
            //2. fit bounds or not
            int bmpW, bmpH, offsetX, offsetY;

            if (useFitBounds)
            {
                bmpW    = fitBounds.Width;
                bmpH    = fitBounds.Height;
                offsetX = -fitBounds.X;
                offsetY = -fitBounds.Y;
            }
            else
            {
                bmpW    = fitBounds.Left + fitBounds.Right;
                bmpH    = fitBounds.Top + fitBounds.Height;
                offsetX = 0;
                offsetY = 0;
            }

            //3. create mask bmp
            MemBitmap maskBmp = new MemBitmap(bmpW, bmpH);

            //4. fill mask data
            maskBmp.Clear(solidPartColor);

            int holdColorInt32 =
                (holeColor.A << CO.A_SHIFT) |
                (holeColor.B << CO.B_SHIFT) |
                (holeColor.G << CO.G_SHIFT) |
                (holeColor.R << CO.R_SHIFT);

            var memPtr = MemBitmap.GetBufferPtr(maskBmp);

            unsafe
            {
                int *buffer = (int *)memPtr.Ptr;
                //fill
                HSpan[] hspans = rgnData.HSpans;
                if (useFitBounds)
                {
                    int totalBufferLen = bmpW * bmpH;

                    for (int i = 0; i < hspans.Length; ++i)
                    {
                        HSpan span = hspans[i];
                        int   len  = span.endX - span.startX;

#if DEBUG
                        int offset = ((span.y + offsetY) * bmpW + (span.startX + offsetX));
                        if (offset >= totalBufferLen || offset + len > totalBufferLen)
                        {
                            throw new System.Exception("out-of-range");
                            break;
                        }
                        else if (offset < 0 || offset + len < 0)
                        {
                        }
#endif

                        int *pixAddr = buffer + ((span.y + offsetY) * bmpW + (span.startX + offsetX)); //with offsetX,offsetY

                        for (int n = len - 1; n >= 0; --n)
                        {
                            *pixAddr = holdColorInt32;
                            pixAddr++;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < hspans.Length; ++i)
                    {
                        HSpan span = hspans[i];
                        int   len  = span.endX - span.startX;

                        int *pixAddr = buffer + ((span.y) * bmpW + (span.startX)); //no offsetX,offsetY

                        for (int n = len - 1; n >= 0; --n)
                        {
                            *pixAddr = holdColorInt32;
                            pixAddr++;
                        }
                    }
                }
            }

            //return null;
            return(maskBmp);
        }
Beispiel #3
0
 public static CpuBlit.MemBitmap CreateMaskBitmap(this ReconstructedRegionData rgnData,
                                                  bool useFitBounds = true)
 {
     return(CreateMaskBitmap(rgnData, Drawing.Color.Black, Drawing.Color.White, useFitBounds));
 }
Beispiel #4
0
 public static BitmapBasedRegion CreateBitmapBasedRegion(this ReconstructedRegionData rgnData)
 {
     return(new BitmapBasedRegion(rgnData));
 }
Beispiel #5
0
        /// <summary>
        /// reconstruct regionOutline from internal region data
        /// </summary>
        /// <param name="rgnOutline"></param>
        public static void ReconstructOutline(this ReconstructedRegionData rgnData, RawOutline rgnOutline)
        {
            var outlineTracer = new OutlineTracer();

            outlineTracer.TraceOutline(rgnData, rgnOutline);
        }
Beispiel #6
0
 public void TraceOutline(ReconstructedRegionData rgnData, RawOutline output)
 {
     TraceOutline(rgnData.HSpans, output);
 }