示例#1
0
        // conncomp.c (738, 1)
        // pixSeedfill8BB(pixs, stack, x, y) as Box
        // pixSeedfill8BB(PIX *, L_STACK *, l_int32, l_int32) as BOX *
        ///  <summary>
        /// (1) This is Paul Heckbert's stack-based 8-cc seedfill algorithm.<para/>
        ///
        /// (2) This operates on the input 1 bpp pix to remove the fg seed
        /// pixel, at (x,y), and all pixels that are 8-connected to it.
        /// The seed pixel at (x,y) must initially be ON.<para/>
        ///
        /// (3) Returns the bounding box of the erased 8-cc component.<para/>
        ///
        /// (4) Reference: see Paul Heckbert's stack-based seed fill algorithm
        /// in "Graphic Gems", ed. Andrew Glassner, Academic
        /// Press, 1990.  The algorithm description is given
        /// on pp. 275-277 working C code is on pp. 721-722.)
        /// The code here follows Heckbert's closely, except
        /// the leak checks are changed for 8 connectivity.
        /// See comments on pixSeedfill4BB() for more details.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/pixSeedfill8BB/*"/>
        ///  <param name="pixs">[in] - 1 bpp</param>
        ///  <param name="stack">[in] - for holding fillsegs</param>
        ///  <param name="x">[in] - ,y   location of seed pixel</param>
        ///   <returns>box or NULL on error.</returns>
        public static Box pixSeedfill8BB(
            Pix pixs,
            L_Stack stack,
            int x,
            int y)
        {
            if (pixs == null)
            {
                throw new ArgumentNullException("pixs cannot be Nothing");
            }

            if (stack == null)
            {
                throw new ArgumentNullException("stack cannot be Nothing");
            }

            if ((new List <int> {
                1
            }).Contains((int)pixs.d) == false)
            {
                throw new ArgumentException("1 bpp");
            }
            IntPtr _Result = Natives.pixSeedfill8BB(pixs.Pointer, stack.Pointer, x, y);

            if (_Result == IntPtr.Zero)
            {
                return(null);
            }

            return(new Box(_Result));
        }
示例#2
0
        // conncomp.c (982, 1)
        // pixSeedfill8(pixs, stack, x, y) as int
        // pixSeedfill8(PIX *, L_STACK *, l_int32, l_int32) as l_ok
        ///  <summary>
        /// (1) This is Paul Heckbert's stack-based 8-cc seedfill algorithm.<para/>
        ///
        /// (2) This operates on the input 1 bpp pix to remove the fg seed
        /// pixel, at (x,y), and all pixels that are 8-connected to it.
        /// The seed pixel at (x,y) must initially be ON.<para/>
        ///
        /// (3) Reference: see pixSeedFill8BB()
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/pixSeedfill8/*"/>
        ///  <param name="pixs">[in] - 1 bpp</param>
        ///  <param name="stack">[in] - for holding fillsegs</param>
        ///  <param name="x">[in] - ,y   location of seed pixel</param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int pixSeedfill8(
            Pix pixs,
            L_Stack stack,
            int x,
            int y)
        {
            if (pixs == null)
            {
                throw new ArgumentNullException("pixs cannot be Nothing");
            }

            if (stack == null)
            {
                throw new ArgumentNullException("stack cannot be Nothing");
            }

            if ((new List <int> {
                1
            }).Contains((int)pixs.d) == false)
            {
                throw new ArgumentException("1 bpp");
            }
            int _Result = Natives.pixSeedfill8(pixs.Pointer, stack.Pointer, x, y);

            return(_Result);
        }
示例#3
0
        // stack.c (247, 1)
        // lstackGetCount(lstack) as int
        // lstackGetCount(L_STACK *) as l_int32
        ///  <summary>
        /// lstackGetCount()
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/lstackGetCount/*"/>
        ///  <param name="lstack">[in] - </param>
        ///   <returns>count, or 0 on error</returns>
        public static int lstackGetCount(
            L_Stack lstack)
        {
            if (lstack == null)
            {
                throw new ArgumentNullException("lstack cannot be Nothing");
            }

            int _Result = Natives.lstackGetCount(lstack.Pointer);

            return(_Result);
        }
示例#4
0
        // stack.c (197, 1)
        // lstackRemove(lstack) as Object
        // lstackRemove(L_STACK *) as void *
        ///  <summary>
        /// lstackRemove()
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/lstackRemove/*"/>
        ///  <param name="lstack">[in] - </param>
        ///   <returns>ptr to item popped from the top of the lstack, or NULL if the lstack is empty or on error</returns>
        public static Object lstackRemove(
            L_Stack lstack)
        {
            if (lstack == null)
            {
                throw new ArgumentNullException("lstack cannot be Nothing");
            }

            IntPtr _Result = Natives.lstackRemove(lstack.Pointer);

            Byte[] B = new Byte[1];
            Marshal.Copy(_Result, B, 0, B.Length);
            return(B);
        }
示例#5
0
        // stack.c (270, 1)
        // lstackPrint(fp, lstack) as int
        // lstackPrint(FILE *, L_STACK *) as l_ok
        ///  <summary>
        /// lstackPrint()
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/lstackPrint/*"/>
        ///  <param name="fp">[in] - file stream</param>
        ///  <param name="lstack">[in] - </param>
        ///   <returns>0 if OK 1 on error</returns>
        public static int lstackPrint(
            FILE fp,
            L_Stack lstack)
        {
            if (fp == null)
            {
                throw new ArgumentNullException("fp cannot be Nothing");
            }

            if (lstack == null)
            {
                throw new ArgumentNullException("lstack cannot be Nothing");
            }

            int _Result = Natives.lstackPrint(fp.Pointer, lstack.Pointer);

            return(_Result);
        }
示例#6
0
        // stack.c (121, 1)
        // lstackDestroy(plstack, freeflag) as Object
        // lstackDestroy(L_STACK **, l_int32) as void
        ///  <summary>
        /// (1) If freeflag is TRUE, frees each struct in the array.<para/>
        ///
        /// (2) If freeflag is FALSE but there are elements on the array,
        /// gives a warning and destroys the array.  This will
        /// cause a memory leak of all the items that were on the lstack.
        /// So if the items require their own destroy function, they
        /// must be destroyed before the lstack.<para/>
        ///
        /// (3) To destroy the lstack, we destroy the ptr array, then
        /// the lstack, and then null the contents of the input ptr.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/lstackDestroy/*"/>
        ///  <param name="plstack">[in,out] - to be nulled</param>
        ///  <param name="freeflag">[in] - TRUE to free each remaining struct in the array</param>
        public static void lstackDestroy(
            ref L_Stack plstack,
            int freeflag)
        {
            IntPtr plstackPtr = IntPtr.Zero;        if (plstack != null)

            {
                plstackPtr = plstack.Pointer;
            }

            Natives.lstackDestroy(ref plstackPtr, freeflag);
            if (plstackPtr == IntPtr.Zero)
            {
                plstack = null;
            }
            else
            {
                plstack = new L_Stack(plstackPtr);
            };
        }
示例#7
0
        // stack.c (167, 1)
        // lstackAdd(lstack, item) as int
        // lstackAdd(L_STACK *, void *) as l_ok
        ///  <summary>
        /// lstackAdd()
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/lstackAdd/*"/>
        ///  <param name="lstack">[in] - </param>
        ///  <param name="item">[in] - to be added to the lstack</param>
        ///   <returns>0 if OK 1 on error.</returns>
        public static int lstackAdd(
            L_Stack lstack,
            Object item)
        {
            if (lstack == null)
            {
                throw new ArgumentNullException("lstack cannot be Nothing");
            }

            if (item == null)
            {
                throw new ArgumentNullException("item cannot be Nothing");
            }

            IntPtr itemPtr = IntPtr.Zero;

            if (item.GetType() == typeof(IntPtr))
            {
                itemPtr = (IntPtr)item;
            }
            else if (item.GetType() == typeof(Byte[]))
            {
                var cdata = (Byte[])item;
                itemPtr = Marshal.AllocHGlobal(cdata.Length);
                Marshal.Copy(cdata, 0, itemPtr, cdata.Length);
            }
            else if (item.GetType().GetProperty("item") != null)
            {
                var cdata = (Byte[])item.GetType().GetProperty("data").GetValue(item, null);
                itemPtr = Marshal.AllocHGlobal(cdata.Length);
                Marshal.Copy(cdata, 0, itemPtr, cdata.Length);
            }

            int _Result = Natives.lstackAdd(lstack.Pointer, itemPtr);

            Marshal.FreeHGlobal(itemPtr);
            return(_Result);
        }