示例#1
0
        public void Clear(RGBColor oColor)
        {
            if (oColor.Argb == 0)
            {
                Array.Clear(_oPixels, 0, _oPixels.Length);
                return;
            }

            //only set one row
            for (int x = 0; x < _nStride; x++)
            {
                _oPixels[x] = oColor.Argb;
            }
            //copy the rest of rows
            for (int y = 1; y < this._nHeight; y++)
            {
                Buffer.BlockCopy(_oPixels, 0, _oPixels, (y * _nStride) * sizeof(int), _nStride * sizeof(int));
            }
        }
示例#2
0
        public void SetPixel(int x, int y, RGBColor oColor)
        {
            if (x < 0 || x >= _nWidth || y < 0 || y >= _nHeight)
            {
                return;
            }

            if (oColor.A == 0xFF || _oCompositingMode == CompositingMode.SourceCopy)            //full opacity
            {
                _oPixels[y * _nStride + x] = oColor.Argb;
            }
            else if (oColor.A == 0x0)            //no opacity
            {
                return;
            }
            else             // alpha blend
            {
                int nPos = y * _nStride + x;
                _SetPixel.Argb = _oPixels[nPos];

                /*if(oOriginalColor.A==0)
                 * {
                 *      _oPixels[nPos] = oColor.Argb;
                 *      return;
                 * }*/
                float nColorAlpha    = ((float)oColor.A / 255f);
                float nOriginalAlpha = 1 - nColorAlpha;

                _SetPixel.R = (byte)((nOriginalAlpha * _SetPixel.R) + (nColorAlpha * oColor.R));
                _SetPixel.G = (byte)((nOriginalAlpha * _SetPixel.G) + (nColorAlpha * oColor.G));
                _SetPixel.B = (byte)((nOriginalAlpha * _SetPixel.B) + (nColorAlpha * oColor.B));

                //_oPixels[y * _nStride + x] = new RGBColor(nNR, nNG, nNB);
                //int nRGB = 0xFF;

                _oPixels[nPos] = _SetPixel.Argb;
            }
        }
示例#3
0
        public static void DrawBitmap(FastBitmap oTexture, Point topLeft, Point topRight, Point bottomRight, Point bottomLeft, FastBitmap oCanvas)
        {
            //top line
            float nDeltaX      = topRight.X - topLeft.X;
            float nDeltaY      = topRight.Y - topLeft.Y;
            float nNumOfPixels = Math.Max(Math.Abs(nDeltaX), Math.Abs(nDeltaY));
            //nNumOfPixels *= 2;
            float      nIncrementX = nDeltaX / nNumOfPixels;
            float      nIncrementY = nDeltaY / nNumOfPixels;
            FastPointF oPixel      = new FastPointF(topLeft.X, topLeft.Y);

            float nTextureIncrementX = (oTexture.Width / (nNumOfPixels + 1));
            float nTextureX          = 0;


            PointMap[] oTopLine = new PointMap[(int)(nNumOfPixels + 1)];
            for (int nCurrentPixel = 0; nCurrentPixel <= nNumOfPixels; nCurrentPixel++)
            {
                oTopLine[nCurrentPixel] = new PointMap(new FastPointF(nTextureX, 0), oPixel);

                nTextureX += nTextureIncrementX;
                oPixel.X  += nIncrementX;
                oPixel.Y  += nIncrementY;
            }

            //bottom line
            nDeltaX      = bottomRight.X - bottomLeft.X;
            nDeltaY      = bottomRight.Y - bottomLeft.Y;
            nNumOfPixels = Math.Max(Math.Abs(nDeltaX), Math.Abs(nDeltaY));
            //nNumOfPixels *= 2;
            nIncrementX = nDeltaX / nNumOfPixels;
            nIncrementY = nDeltaY / nNumOfPixels;
            oPixel      = new FastPointF(bottomLeft.X, bottomLeft.Y);


            nTextureIncrementX = (oTexture.Width / (nNumOfPixels + 1));
            nTextureX          = 0;

            PointMap[] oBottomLine = new PointMap[(int)(nNumOfPixels + 1)];
            for (int nCurrentPixel = 0; nCurrentPixel <= nNumOfPixels; nCurrentPixel++)
            {
                oBottomLine[nCurrentPixel] = new PointMap(new FastPointF(nTextureX, oTexture.Height - 1), oPixel);

                oPixel.X  += nIncrementX;
                oPixel.Y  += nIncrementY;
                nTextureX += nTextureIncrementX;
            }

            //cross lines
            PointMap[] oStartLine = oTopLine.Length > oBottomLine.Length ? oTopLine : oBottomLine;
            PointMap[] oEndLine   = oTopLine.Length > oBottomLine.Length ? oBottomLine : oTopLine;
            float      nFactor    = (float)oEndLine.Length / (float)oStartLine.Length;

            Rectangle oBox = _ComputeBox(topLeft, topRight, bottomLeft, bottomRight);

            Boolean[,] oPainted = new Boolean[oBox.Width + 1, oBox.Height + 1];

            for (int s = 0; s < oStartLine.Length; s++)
            {
                FastPointF oStart        = oStartLine[s].To;
                FastPointF oStartTexture = oStartLine[s].From;
                float      nEndPoint     = (float)Math.Floor(nFactor * s);
                FastPointF oEnd          = oEndLine[(int)nEndPoint].To;
                FastPointF oEndTexture   = oEndLine[(int)nEndPoint].From;


                nDeltaX      = oEnd.X - oStart.X;
                nDeltaY      = oEnd.Y - oStart.Y;
                nNumOfPixels = Math.Max(Math.Abs(nDeltaX), Math.Abs(nDeltaY));
                //nNumOfPixels *= 2;
                nIncrementX = nDeltaX / nNumOfPixels;
                nIncrementY = nDeltaY / nNumOfPixels;

                float nTextureDeltaX = oEndTexture.X - oStartTexture.X;
                float nTextureDeltaY = oEndTexture.Y - oStartTexture.Y;
                nTextureIncrementX = nTextureDeltaX / (nNumOfPixels + 1);
                float      nTextureIncrementY = nTextureDeltaY / (nNumOfPixels + 1);
                FastPointF oDestination       = oStart;
                FastPointF oSource            = oStartTexture;
                for (int nCurrentPixel = 0; nCurrentPixel <= nNumOfPixels; nCurrentPixel++)
                {
                    RGBColor c = oTexture.GetPixel((int)oSource.X, (int)oSource.Y);
                    oCanvas.SetPixel((int)oDestination.X, (int)oDestination.Y, c);
                    oPainted[(int)(oDestination.X - oBox.X), (int)(oDestination.Y - oBox.Y)] = true;
                    oDestination.X += nIncrementX;
                    oDestination.Y += nIncrementY;
                    oSource.X      += nTextureIncrementX;
                    oSource.Y      += nTextureIncrementY;
                }
            }

            //paint missing pixels
            for (int ny = 0; ny < oBox.Height; ny++)
            {
                for (int nx = 0; nx < oBox.Width; nx++)
                {
                    if (oPainted[nx, ny] == true)
                    {
                        continue;
                    }

                    int      nNeigh = 0;
                    RGBColor oColor;
                    int      R = 0;
                    int      G = 0;
                    int      B = 0;
                    if (nx > 0 && oPainted[nx - 1, ny] == true)
                    {
                        oColor = oCanvas.GetPixel((nx + oBox.X) - 1, (ny + oBox.Y));
                        R     += oColor.R;
                        G     += oColor.G;
                        B     += oColor.B;
                        nNeigh++;
                    }
                    if (ny > 0 && oPainted[nx, ny - 1] == true)
                    {
                        oColor = oCanvas.GetPixel((nx + oBox.X), (ny + oBox.Y) - 1);
                        R     += oColor.R;
                        G     += oColor.G;
                        B     += oColor.B;
                        nNeigh++;
                    }
                    if (nx < oCanvas.Width - 1 && oPainted[nx + 1, ny] == true)
                    {
                        oColor = oCanvas.GetPixel((nx + oBox.X) + 1, (ny + oBox.Y));
                        R     += oColor.R;
                        G     += oColor.G;
                        B     += oColor.B;
                        nNeigh++;
                    }
                    if (ny < oCanvas.Height - 1 && oPainted[nx, ny + 1] == true)
                    {
                        oColor = oCanvas.GetPixel((nx + oBox.X), (ny + oBox.Y) + 1);
                        R     += oColor.R;
                        G     += oColor.G;
                        B     += oColor.B;
                        nNeigh++;
                    }
                    if (nNeigh == 0)
                    {
                        continue;
                    }
                    oCanvas.SetPixel((nx + oBox.X), (ny + oBox.Y), new RGBColor((byte)(R / nNeigh), (byte)(G / nNeigh), (byte)(B / nNeigh)));
                }
            }
        }