+2007-04-16 Sebastien Pouliot <sebastien@ximian.com>
+
+ * GDIPlusTest.cs: Add test cases for GdipBitmap[Get|Set]Pixel on an
+ indexed bitmap (1bpp) and on a 16bpp grayscale bitmap.
+ * TestBitmap.cs: Add test cases for Format[1,4,8]bppIndexed and
+ Format16bppGrayScale.
+
2007-04-14 Sebastien Pouliot <sebastien@ximian.com>
* TestBitmap.cs: Always test buffer byte-by-byte to avoid endian
Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipCreateBitmapFromScan0 (-1, 10, 10, PixelFormat.Format32bppArgb, IntPtr.Zero, out bmp), "negative width");
}
+ [Test]
+ public void Format1bppIndexed_GetSetPixel ()
+ {
+ IntPtr bmp;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format1bppIndexed, IntPtr.Zero, out bmp), "GdipCreateBitmapFromScan0");
+ Assert.IsTrue (bmp != IntPtr.Zero, "bmp");
+ try {
+ int argb;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipBitmapGetPixel (bmp, 0, 0, out argb), "GdipBitmapGetPixel");
+ Assert.AreEqual (-16777216, argb, "argb");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipBitmapSetPixel (bmp, 0, 0, argb), "GdipBitmapSetPixel");
+ }
+ finally {
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (bmp), "GdipDisposeImage");
+ }
+ }
+
+ [Test]
+ [Category ("NotWorking")] // libgdiplus doesn't support this format
+ public void Format16bppGrayScale_GetSetPixel ()
+ {
+ IntPtr bmp;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format16bppGrayScale, IntPtr.Zero, out bmp), "GdipCreateBitmapFromScan0");
+ Assert.IsTrue (bmp != IntPtr.Zero, "bmp");
+ try {
+ int argb = 0;
+ // and MS GDI+ can get or set pixels on it
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipBitmapGetPixel (bmp, 0, 0, out argb), "GdipBitmapGetPixel");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipBitmapSetPixel (bmp, 0, 0, argb), "GdipBitmapSetPixel");
+ }
+ finally {
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (bmp), "GdipDisposeImage");
+ }
+ }
+
[Test]
public void Unlock ()
{
}
#endif
+ [Test]
+#if NET_2_0
+ [ExpectedException (typeof (InvalidOperationException))]
+#else
+ [ExpectedException (typeof (Exception))]
+#endif
+ public void Format1bppIndexed ()
+ {
+ using (Bitmap bmp = new Bitmap (1, 1, PixelFormat.Format1bppIndexed)) {
+ Color c = bmp.GetPixel (0, 0);
+ Assert.AreEqual (-16777216, c.ToArgb (), "Color");
+ bmp.SetPixel (0, 0, c);
+ }
+ }
+
+ [Test]
+#if NET_2_0
+ [ExpectedException (typeof (InvalidOperationException))]
+#else
+ [ExpectedException (typeof (Exception))]
+#endif
+ public void Format4bppIndexed ()
+ {
+ using (Bitmap bmp = new Bitmap (1, 1, PixelFormat.Format4bppIndexed)) {
+ Color c = bmp.GetPixel (0, 0);
+ Assert.AreEqual (-16777216, c.ToArgb (), "Color");
+ bmp.SetPixel (0, 0, c);
+ }
+ }
+
+ [Test]
+#if NET_2_0
+ [ExpectedException (typeof (InvalidOperationException))]
+#else
+ [ExpectedException (typeof (Exception))]
+#endif
+ public void Format8bppIndexed ()
+ {
+ using (Bitmap bmp = new Bitmap (1, 1, PixelFormat.Format8bppIndexed)) {
+ Color c = bmp.GetPixel (0, 0);
+ Assert.AreEqual (-16777216, c.ToArgb (), "Color");
+ bmp.SetPixel (0, 0, c);
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ [Category ("NotWorking")] // libgdiplus doesn't support this format
+ public void Format16bppGrayScale ()
+ {
+ using (Bitmap bmp = new Bitmap (1, 1, PixelFormat.Format16bppGrayScale)) {
+ // and MS GDI+ support seems quite limited too
+ bmp.GetPixel (0, 0);
+ }
+ }
+
private void FormatTest (PixelFormat format)
{
bool alpha = Image.IsAlphaPixelFormat (format);