Esempio n. 1
0
        private static unsafe void LoadOrSaveSurfaceRegion(Stream stream, Surface surface, RectInt32[] scans, bool trueForSave)
        {
            int length = scans.Length;

            if (length != 0)
            {
                void *[]  voidPtrArray;
                ulong[]   numArray;
                RectInt32 b      = surface.Bounds <ColorBgra>();
                RectInt32 bounds = RectInt32.Intersect(scans.Bounds(), b);
                int       num5   = 0;
                long      num6   = (bounds.Width * bounds.Height) * 4L;
                if (((length == 1) && (num6 <= 0xffffffffL)) && surface.IsContiguousMemoryRegion(bounds))
                {
                    voidPtrArray = new void *[] { surface.GetPointAddressUnchecked(bounds.Location.ToGdipPoint()) };
                    numArray     = new ulong[] { num6 };
                }
                else
                {
                    for (int i = 0; i < length; i++)
                    {
                        RectInt32 num9 = RectInt32.Intersect(scans[i], b);
                        if ((num9.Width != 0) && (num9.Height != 0))
                        {
                            num5 += num9.Height;
                        }
                    }
                    int index = 0;
                    voidPtrArray = new void *[num5];
                    numArray     = new ulong[num5];
                    for (int j = 0; j < length; j++)
                    {
                        RectInt32 num11 = RectInt32.Intersect(scans[j], b);
                        if ((num11.Width != 0) && (num11.Height != 0))
                        {
                            for (int k = num11.Y; k < (num11.Y + num11.Height); k++)
                            {
                                voidPtrArray[index] = (void *)surface.GetPointAddress(num11.X, k);
                                numArray[index]     = (ulong)(num11.Width * 4L);
                                index++;
                            }
                        }
                    }
                }
                if (trueForSave)
                {
                    WriteToStreamGather(stream, voidPtrArray, numArray);
                }
                else
                {
                    ReadFromStreamScatter(stream, voidPtrArray, numArray);
                }
            }
        }