Index: Core/Common/src/Core.Common.Utils/Drawing/ColorAccess.cs
===================================================================
diff -u -r569a286badd9b3494f5465cc2767a8cf6a77f618 -r3b51a30f833b58265a599b56920597d656f906c6
--- Core/Common/src/Core.Common.Utils/Drawing/ColorAccess.cs (.../ColorAccess.cs) (revision 569a286badd9b3494f5465cc2767a8cf6a77f618)
+++ Core/Common/src/Core.Common.Utils/Drawing/ColorAccess.cs (.../ColorAccess.cs) (revision 3b51a30f833b58265a599b56920597d656f906c6)
@@ -20,9 +20,11 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
+using System.Linq;
using System.Runtime.InteropServices;
using Core.Common.Utils.Properties;
@@ -63,12 +65,14 @@
private readonly ColorPalette palette;
private readonly Rectangle validRange;
+ private readonly byte[] buffer;
+
private ColorAccess(BitmapData data, ColorPalette palette, Rectangle validRange)
{
stride = data.Stride;
- Buffer = new byte[stride * data.Height];
- Marshal.Copy(data.Scan0, Buffer, 0, Buffer.Length);
+ buffer = new byte[stride * data.Height];
+ Marshal.Copy(data.Scan0, buffer, 0, buffer.Length);
format = data.PixelFormat;
bitsPerPixel = GetPixelSize(format);
this.palette = palette;
@@ -93,10 +97,10 @@
switch (format)
{
case PixelFormat.Format1bppIndexed:
- return palette.Entries[(Buffer[index] & bitMask[mod]) == 0 ? 0 : 1];
+ return palette.Entries[(Buffer.ElementAt(index) & bitMask[mod]) == 0 ? 0 : 1];
case PixelFormat.Format4bppIndexed:
- pIndex = Buffer[index];
+ pIndex = Buffer.ElementAt(index);
mod /= 4;
if (mod != 0)
{
@@ -105,17 +109,17 @@
return palette.Entries[pIndex & 0x7];
case PixelFormat.Format8bppIndexed:
- pIndex = Buffer[index];
+ pIndex = Buffer.ElementAt(index);
return palette.Entries[pIndex];
case PixelFormat.Format24bppRgb:
- return Color.FromArgb(Buffer[index + 2], Buffer[index + 1],
- Buffer[index]);
+ return Color.FromArgb(Buffer.ElementAt(index + 2), Buffer.ElementAt(index + 1),
+ Buffer.ElementAt(index));
case PixelFormat.Format32bppArgb:
case PixelFormat.Format32bppRgb:
- return Color.FromArgb(Buffer[index + 3], Buffer[index + 2],
- Buffer[index + 1], Buffer[index]);
+ return Color.FromArgb(Buffer.ElementAt(index + 3), Buffer.ElementAt(index + 2),
+ Buffer.ElementAt(index + 1), Buffer.ElementAt(index));
default:
throw new InvalidOperationException($"Indexing image for image format '{format}' isn't supported.");
}
@@ -130,10 +134,10 @@
int mod;
int index = GetIndex(x, y, out mod);
- Buffer[index++] = value.B;
- Buffer[index++] = value.G;
- Buffer[index++] = value.R;
- Buffer[index] = value.A;
+ buffer[index++] = value.B;
+ buffer[index++] = value.G;
+ buffer[index++] = value.R;
+ buffer[index] = value.A;
}
}
@@ -142,7 +146,13 @@
/// can be used to create a new image with the changed data (for example using
/// ).
///
- public byte[] Buffer { get; }
+ public IEnumerable Buffer
+ {
+ get
+ {
+ return buffer;
+ }
+ }
///
/// Sets the current image back at the original location in
@@ -160,7 +170,7 @@
}
BitmapData bitmapData = bitmap.LockBits(validRange, ImageLockMode.WriteOnly, bitmap.PixelFormat);
- Marshal.Copy(Buffer, 0, bitmapData.Scan0, Buffer.Length);
+ Marshal.Copy(Buffer.ToArray(), 0, bitmapData.Scan0, Buffer.Count());
bitmap.UnlockBits(bitmapData);
}
Index: Core/Common/test/Core.Common.TestUtil/WindowsFormsTestHelper.cs
===================================================================
diff -u -r6b8f6422c0a6f96f8e563bb6afb82a7a192142b4 -r3b51a30f833b58265a599b56920597d656f906c6
--- Core/Common/test/Core.Common.TestUtil/WindowsFormsTestHelper.cs (.../WindowsFormsTestHelper.cs) (revision 6b8f6422c0a6f96f8e563bb6afb82a7a192142b4)
+++ Core/Common/test/Core.Common.TestUtil/WindowsFormsTestHelper.cs (.../WindowsFormsTestHelper.cs) (revision 3b51a30f833b58265a599b56920597d656f906c6)
@@ -49,7 +49,7 @@
InitializeComponent();
}
- public static object[] PropertyObjects { get; set; }
+ public static IEnumerable