示例#1
0
        private unsafe void RenderOneToOne(Cairo.ImageSurface src, Cairo.ImageSurface dst, Gdk.Point offset, bool checker)
        {
            Gdk.Rectangle srcRect = new Gdk.Rectangle(offset, dst.GetBounds().Size);
            srcRect.Intersect(src.GetBounds());

            ColorBgra *src_ptr = (ColorBgra *)src.DataPtr;
            ColorBgra *dst_ptr = (ColorBgra *)dst.DataPtr;

            int src_width  = src.Width;
            int dst_width  = dst.Width;
            int dst_height = dst.Height;

            for (int dstRow = 0; dstRow < srcRect.Height; ++dstRow)
            {
                ColorBgra *dstRowPtr = dst.GetRowAddressUnchecked(dst_ptr, dst_width, dstRow);
                ColorBgra *srcRowPtr = src.GetPointAddressUnchecked(src_ptr, src_width, offset.X, dstRow + offset.Y);

                int dstCol    = offset.X;
                int dstColEnd = offset.X + srcRect.Width;
                int checkerY  = dstRow + offset.Y;

                while (dstCol < dstColEnd)
                {
                    // Blend it over the checkerboard background
                    if (checker)
                    {
                        int b = srcRowPtr->B;
                        int g = srcRowPtr->G;
                        int r = srcRowPtr->R;
                        int a = srcRowPtr->A;

                        int v = (((dstCol ^ checkerY) & 8) << 3) + 191;
                        a = a + (a >> 7);
                        int vmia = v * (256 - a);

                        r = ((r * a) + vmia) >> 8;
                        g = ((g * a) + vmia) >> 8;
                        b = ((b * a) + vmia) >> 8;

                        dstRowPtr->Bgra = (uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)255 << 24);
                    }
                    else
                    {
                        *dstRowPtr = *srcRowPtr;
                    }

                    ++dstRowPtr;
                    ++srcRowPtr;
                    ++dstCol;
                }
            }
        }