コード例 #1
0
ファイル: Bitmap.cs プロジェクト: dronab/DjvuNet
        /// <summary>
        /// Initialize this map by copying a reference map
        /// </summary>
        /// <param name="ref">map to copy
        /// </param>
        /// <param name="rect">area to copy
        /// </param>
        /// <param name="border">number of border pixels
        ///
        /// </param>
        /// <returns> the initialized map
        /// </returns>
        public virtual Bitmap Init(Bitmap ref_Renamed, Rectangle rect, int border)
        {
            if (this == ref_Renamed)
            {
                Bitmap tmp = new Bitmap();
                tmp.Grays       = (Grays);
                tmp.Border      = ((short)border);
                tmp.BytesPerRow = (BytesPerRow);
                tmp.ImageWidth  = ImageWidth;
                tmp.Rows        = ImageHeight;
                tmp.Data        = Data;
                Data            = null;
                Init(tmp, rect, border);
            }
            else
            {
                Init(rect.Height, rect.Width, border);
                Grays = ref_Renamed.Grays;

                Rectangle rect2 = new Rectangle(0, 0, ref_Renamed.ImageWidth, ref_Renamed.ImageHeight);
                rect2.Intersect(rect2, rect);
                rect2.Translate(-rect.Right, -rect.Bottom);

                if (!rect2.Empty)
                {
                    int dstIdx = 0;
                    int srcIdx = 0;

                    for (int y = rect2.Bottom; y < rect2.Top; y++)
                    {
                        dstIdx = RowOffset(y);
                        srcIdx = ref_Renamed.RowOffset(y + rect.Bottom);

                        for (int x = rect2.Right; x < rect2.Top; x++)
                        {
                            Data[dstIdx + x] = ref_Renamed.Data[srcIdx + x];
                        }
                    }
                }
            }

            return(this);
        }
コード例 #2
0
ファイル: PixelMap.cs プロジェクト: fel88/CommonLibs
        /// <summary> Initialize this PixelMap from a segment of another image map.
        ///
        /// </summary>
        /// <param name="ref">image map to initialize from
        /// </param>
        /// <param name="rect">bounding rectangle to initialize from
        ///
        /// </param>
        /// <returns> the initialized PixelMap
        /// </returns>
        public virtual PixelMap Init(Map ref_Renamed, Rectangle rect)
        {
            Init(rect.Height, rect.Width, ((null)));

            Rectangle rect2 = new Rectangle(0, 0, ref_Renamed.ImageWidth, ref_Renamed.ImageHeight);

            rect2.Intersect(rect2, rect);
            rect2.Translate(-rect.Right, -rect.Bottom);

            if (!rect2.Empty)
            {
                PixelReference pixel    = CreateGPixelReference(0);
                PixelReference refPixel = ref_Renamed.CreateGPixelReference(0);

                for (int y = rect2.Bottom; y < rect2.Top; y++)
                {
                    pixel.SetOffset(y, rect2.Right);
                    refPixel.SetOffset(y + rect.Bottom, rect.Right + rect2.Right);

                    if (!IsRampNeeded)
                    {
                        for (int x = rect2.Left - rect2.Right; x-- > 0; pixel.IncOffset(), refPixel.IncOffset())
                        {
                            pixel.CopyFrom(refPixel);
                        }
                    }
                    else
                    {
                        for (int x = rect2.Left - rect2.Right; x-- > 0; pixel.IncOffset(), refPixel.IncOffset())
                        {
                            pixel.CopyFrom(ref_Renamed.PixelRamp(refPixel));
                        }
                    }
                }
            }

            return(this);
        }
コード例 #3
0
ファイル: PixelMapScaler.cs プロジェクト: Riksarkivet/DjvuNet
        private PixelReference GetLine(int fy, Rectangle required_red, Rectangle provided_input, PixelMap input)
        {
            if (fy < required_red.YMin)
            {
                fy = required_red.YMin;
            }
            else if (fy >= required_red.YMax)
            {
                fy = required_red.YMax - 1;
            }

            // Cached line
            if (fy == l2)
            {
                return p2.CreateGPixelReference(0);
            }

            if (fy == l1)
            {
                return p1.CreateGPixelReference(0);
            }

            // Shift
            PixelMap p = p1;
            p1 = p2;
            l1 = l2;
            p2 = p;
            l2 = fy;

            // Compute location of line
            Rectangle line = new Rectangle();
            line.XMin = required_red.XMin << xshift;
            line.XMax = required_red.XMax << xshift;
            line.YMin = fy << yshift;
            line.YMax = (fy + 1) << yshift;
            line.Intersect(line, provided_input);
            line.Translate(-provided_input.XMin, -provided_input.YMin);

            // Prepare variables
            int botline = input.RowOffset(line.YMin);
            int rowsize = input.GetRowSize();
            int sw = 1 << xshift;
            int div = xshift + yshift;
            int rnd = 1 << (div - 1);
            int rnd2 = rnd + rnd;

            PixelReference inp1 = input.CreateGPixelReference(0);
            PixelReference ip = p.CreateGPixelReference(0);

            // Compute averages
            for (int x = line.XMin; x < line.XMax; x += sw, ip.IncOffset())
            {
                int r = 0;
                int g = 0;
                int b = 0;
                int s = 0;
                int inp0 = botline + x;
                int sy2 = line.Height;
                int sy1 = (1 << yshift);

                if (sy1 > sy2)
                {
                    sy1 = sy2;
                }

                for (int sy = 0; sy < sy1; sy++, inp0 += rowsize)
                {
                    int sx1 = x + sw;
                    inp1.SetOffset(inp0);

                    if (sx1 > line.XMax)
                    {
                        sx1 = line.XMax;
                    }

                    for (int sx = sx1 - x; sx-- > 0; s++, inp1.IncOffset())
                    {
                        r += inp1.Red;
                        g += inp1.Green;
                        b += inp1.Blue;
                    }
                }

                if (s == rnd2)
                {
                    ip.SetBGR((b + rnd) >> div, (g + r) >> div, (r + rnd) >> div);
                }
                else
                {
                    ip.SetBGR((b + (s / 2)) / 2, (g + (s / 2)) / s, (r + (s / 2)) / s);
                }
            }

            // Return
            return p2.CreateGPixelReference(0);
        }
コード例 #4
0
ファイル: PixelMapScaler.cs プロジェクト: fel88/CommonLibs
        private PixelReference GetLine(int fy, Rectangle required_red, Rectangle provided_input, PixelMap input)
        {
            if (fy < required_red.YMin)
            {
                fy = required_red.YMin;
            }
            else if (fy >= required_red.YMax)
            {
                fy = required_red.YMax - 1;
            }

            // Cached line
            if (fy == l2)
            {
                return(p2.CreateGPixelReference(0));
            }

            if (fy == l1)
            {
                return(p1.CreateGPixelReference(0));
            }

            // Shift
            PixelMap p = p1;

            p1 = p2;
            l1 = l2;
            p2 = p;
            l2 = fy;

            // Compute location of line
            Rectangle line = new Rectangle();

            line.XMin = required_red.XMin << xshift;
            line.XMax = required_red.XMax << xshift;
            line.YMin = fy << yshift;
            line.YMax = (fy + 1) << yshift;
            line.Intersect(line, provided_input);
            line.Translate(-provided_input.XMin, -provided_input.YMin);

            // Prepare variables
            int botline = input.RowOffset(line.YMin);
            int rowsize = input.GetRowSize();
            int sw      = 1 << xshift;
            int div     = xshift + yshift;
            int rnd     = 1 << (div - 1);
            int rnd2    = rnd + rnd;

            PixelReference inp1 = input.CreateGPixelReference(0);
            PixelReference ip   = p.CreateGPixelReference(0);

            // Compute averages
            for (int x = line.XMin; x < line.XMax; x += sw, ip.IncOffset())
            {
                int r    = 0;
                int g    = 0;
                int b    = 0;
                int s    = 0;
                int inp0 = botline + x;
                int sy2  = line.Height;
                int sy1  = (1 << yshift);

                if (sy1 > sy2)
                {
                    sy1 = sy2;
                }

                for (int sy = 0; sy < sy1; sy++, inp0 += rowsize)
                {
                    int sx1 = x + sw;
                    inp1.SetOffset(inp0);

                    if (sx1 > line.XMax)
                    {
                        sx1 = line.XMax;
                    }

                    for (int sx = sx1 - x; sx-- > 0; s++, inp1.IncOffset())
                    {
                        r += inp1.Red;
                        g += inp1.Green;
                        b += inp1.Blue;
                    }
                }

                if (s == rnd2)
                {
                    ip.SetBGR((b + rnd) >> div, (g + r) >> div, (r + rnd) >> div);
                }
                else
                {
                    ip.SetBGR((b + (s / 2)) / 2, (g + (s / 2)) / s, (r + (s / 2)) / s);
                }
            }

            // Return
            return(p2.CreateGPixelReference(0));
        }
コード例 #5
0
        internal IPixelReference GetLine(int fy, Rectangle redRect, Rectangle srcRect, IPixelMap srcMap)
        {
            if (fy < redRect.YMin)
            {
                fy = redRect.YMin;
            }
            else if (fy >= redRect.YMax)
            {
                fy = redRect.YMax - 1;
            }

            // Cached line
            if (fy == _L2)
            {
                return(_PixelMap2.CreateGPixelReference(0));
            }

            if (fy == _L1)
            {
                return(_PixelMap1.CreateGPixelReference(0));
            }

            // Shift
            IPixelMap p = _PixelMap1;

            _PixelMap1 = _PixelMap2;
            _L1        = _L2;
            _PixelMap2 = p;
            _L2        = fy;

            // Compute location of line
            Rectangle line = new Rectangle();

            line.XMin = redRect.XMin << _XShift;
            line.XMax = redRect.XMax << _XShift;
            line.YMin = fy << _YShift;
            line.YMax = (fy + 1) << _YShift;
            line.Intersect(line, srcRect);
            line.Translate(-srcRect.XMin, -srcRect.YMin);

            // Prepare variables
            int botline = srcMap.RowOffset(line.YMin);
            int rowsize = srcMap.GetRowSize();
            int sw      = 1 << _XShift;
            int div     = _XShift + _YShift;
            int rnd     = 1 << (div - 1);
            int rnd2    = rnd + rnd;

            var inp1 = srcMap.CreateGPixelReference(0);
            var ip   = p.CreateGPixelReference(0);

            // Compute averages
            for (int x = line.XMin; x < line.XMax; x += sw, ip.IncOffset())
            {
                int r    = 0;
                int g    = 0;
                int b    = 0;
                int s    = 0;
                int inp0 = botline + x;
                int sy2  = line.Height;
                int sy1  = (1 << _YShift);

                if (sy1 > sy2)
                {
                    sy1 = sy2;
                }

                for (int sy = 0; sy < sy1; sy++, inp0 += rowsize)
                {
                    int sx1 = x + sw;
                    inp1.SetOffset(inp0);

                    if (sx1 > line.XMax)
                    {
                        sx1 = line.XMax;
                    }

                    for (int sx = sx1 - x; sx-- > 0; s++, inp1.IncOffset())
                    {
                        r += inp1.Red;
                        g += inp1.Green;
                        b += inp1.Blue;
                    }
                }

                if (s == rnd2)
                {
                    ip.SetBGR((b + rnd) >> div, (g + r) >> div, (r + rnd) >> div);
                }
                else
                {
                    ip.SetBGR((b + (s / 2)) / 2, (g + (s / 2)) / s, (r + (s / 2)) / s);
                }
            }
            return(_PixelMap2.CreateGPixelReference(0));
        }
コード例 #6
0
ファイル: Bitmap.cs プロジェクト: Riksarkivet/DjvuNet
        /// <summary>
        /// Initialize this map by copying a reference map
        /// </summary>
        /// <param name="ref">map to copy
        /// </param>
        /// <param name="rect">area to copy
        /// </param>
        /// <param name="border">number of border pixels
        ///
        /// </param>
        /// <returns> the initialized map
        /// </returns>
        public virtual Bitmap Init(Bitmap ref_Renamed, Rectangle rect, int border)
        {
            if (this == ref_Renamed)
            {
                Bitmap tmp = new Bitmap();
                tmp.Grays = (Grays);
                tmp.Border = ((short)border);
                tmp.BytesPerRow = (BytesPerRow);
                tmp.ImageWidth = ImageWidth;
                tmp.Rows = ImageHeight;
                tmp.Data = Data;
                Data = null;
                Init(tmp, rect, border);
            }
            else
            {
                Init(rect.Height, rect.Width, border);
                Grays = ref_Renamed.Grays;

                Rectangle rect2 = new Rectangle(0, 0, ref_Renamed.ImageWidth, ref_Renamed.ImageHeight);
                rect2.Intersect(rect2, rect);
                rect2.Translate(-rect.Right, -rect.Bottom);

                if (!rect2.Empty)
                {
                    int dstIdx = 0;
                    int srcIdx = 0;

                    for (int y = rect2.Bottom; y < rect2.Top; y++)
                    {
                        dstIdx = RowOffset(y);
                        srcIdx = ref_Renamed.RowOffset(y + rect.Bottom);

                        for (int x = rect2.Right; x < rect2.Top; x++)
                        {
                            Data[dstIdx + x] = ref_Renamed.Data[srcIdx + x];
                        }
                    }
                }
            }

            return this;
        }
コード例 #7
0
ファイル: PixelMap.cs プロジェクト: Riksarkivet/DjvuNet
        /// <summary> Initialize this PixelMap from a segment of another image map.
        ///
        /// </summary>
        /// <param name="ref">image map to initialize from
        /// </param>
        /// <param name="rect">bounding rectangle to initialize from
        ///
        /// </param>
        /// <returns> the initialized PixelMap
        /// </returns>
        public virtual PixelMap Init(Map ref_Renamed, Rectangle rect)
        {
            Init(rect.Height, rect.Width, ((null)));

            Rectangle rect2 = new Rectangle(0, 0, ref_Renamed.ImageWidth, ref_Renamed.ImageHeight);
            rect2.Intersect(rect2, rect);
            rect2.Translate(-rect.Right, -rect.Bottom);

            if (!rect2.Empty)
            {
                PixelReference pixel = CreateGPixelReference(0);
                PixelReference refPixel = ref_Renamed.CreateGPixelReference(0);

                for (int y = rect2.Bottom; y < rect2.Top; y++)
                {
                    pixel.SetOffset(y, rect2.Right);
                    refPixel.SetOffset(y + rect.Bottom, rect.Right + rect2.Right);

                    if (!IsRampNeeded)
                    {
                        for (int x = rect2.Left - rect2.Right; x-- > 0; pixel.IncOffset(), refPixel.IncOffset())
                        {
                            pixel.CopyFrom(refPixel);
                        }
                    }
                    else
                    {
                        for (int x = rect2.Left - rect2.Right; x-- > 0; pixel.IncOffset(), refPixel.IncOffset())
                        {
                            pixel.CopyFrom(ref_Renamed.PixelRamp(refPixel));
                        }
                    }
                }
            }

            return this;
        }