ImageList.cs: ReduceColorDepth: Clean up pointer operations.
authorKornél Pál <kornelpal@gmail.com>
Fri, 30 Sep 2005 10:38:18 +0000 (10:38 -0000)
committerKornél Pál <kornelpal@gmail.com>
Fri, 30 Sep 2005 10:38:18 +0000 (10:38 -0000)
svn path=/trunk/mcs/; revision=51037

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ImageList.cs

index 1fcc20a0f99b4fcad3c1270da0359829f62ceb25..d7eae3d0f17bbf3be973803b1fc8e23221b47868 100644 (file)
@@ -1,3 +1,7 @@
+2005-09-30  Kornél Pál  <kornelpal@hotmail.com>
+
+       * ImageList.cs: ReduceColorDepth: Clean up pointer operations.
+
 2005-09-30  Kornél Pál  <kornelpal@hotmail.com>
 
        * ImageList.cs: ImageCollection: Removed owner field as it is no more used.
index 550a95ad98b64332eb79d12a632b16d6a1dc69fa..9f990ed22392f0a9d2e48f6f95509afdaa289ae3 100644 (file)
@@ -363,21 +363,21 @@ namespace System.Windows.Forms
 
                        private unsafe Image ReduceColorDepth(Bitmap bitmap)
                        {
-                               int y;
-                               int x;
-                               int origPixel;
+                               byte* pixelPtr;
+                               byte* lineEndPtr;
+                               byte* linePtr;
+                               int line;
                                int pixel;
                                int height;
                                int widthBytes;
                                int stride;
-                               byte* pixels;
                                BitmapData bitmapData;
                                ArgbColor[] palette;
 
                                if (this.colorDepth < ColorDepth.Depth32Bit) {
                                        bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                                        try {
-                                               pixels = (byte*)bitmapData.Scan0;
+                                               linePtr = (byte*)bitmapData.Scan0;
                                                height = bitmapData.Height;
                                                widthBytes = bitmapData.Width << 2;
                                                stride = bitmapData.Stride;
@@ -385,30 +385,27 @@ namespace System.Windows.Forms
                                                if (this.colorDepth < ColorDepth.Depth16Bit) {
                                                        palette = (this.colorDepth < ColorDepth.Depth8Bit) ? IndexedColorDepths.Palette4Bit : IndexedColorDepths.Palette8Bit;
 
-                                                       for (y = 0; y < height; y++) {
-                                                               for (x = 0; x < widthBytes; x += 4)
-                                                                       if ((pixel = (((origPixel = *(int*)(pixels + x)) & AlphaMask) == 0) ? 0x00000000 : IndexedColorDepths.GetNearestColor(palette, origPixel | AlphaMask)) != origPixel)
-                                                                               *(int*)(pixels + x) = pixel;
-
-                                                               pixels += stride;
+                                                       for (line = 0; line < height; line++) {
+                                                               lineEndPtr = linePtr + widthBytes;
+                                                               for (pixelPtr = linePtr; pixelPtr < lineEndPtr; pixelPtr += 4)
+                                                                       *(int*)pixelPtr = (((pixel = *(int*)pixelPtr) & AlphaMask) == 0) ? 0x00000000 : IndexedColorDepths.GetNearestColor(palette, pixel | AlphaMask);
+                                                               linePtr += stride;
                                                        }
                                                }
                                                else if (this.colorDepth < ColorDepth.Depth24Bit) {
-                                                       for (y = 0; y < height; y++) {
-                                                               for (x = 0; x < widthBytes; x += 4)
-                                                                       if ((pixel = (((origPixel = *(int*)(pixels + x)) & AlphaMask) == 0) ? 0x00000000 : (origPixel & 0x00F8F8F8) | AlphaMask) != origPixel)
-                                                                               *(int*)(pixels + x) = pixel;
-
-                                                               pixels += stride;
+                                                       for (line = 0; line < height; line++) {
+                                                               lineEndPtr = linePtr + widthBytes;
+                                                               for (pixelPtr = linePtr; pixelPtr < lineEndPtr; pixelPtr += 4)
+                                                                       *(int*)pixelPtr = (((pixel = *(int*)pixelPtr) & AlphaMask) == 0) ? 0x00000000 : (pixel & 0x00F8F8F8) | AlphaMask;
+                                                               linePtr += stride;
                                                        }
                                                }
                                                else {
-                                                       for (y = 0; y < height; y++) {
-                                                               for (x = 0; x < widthBytes; x += 4)
-                                                                       if ((pixel = (((origPixel = *(int*)(pixels + x)) & AlphaMask) == 0) ? 0x00000000 : origPixel | AlphaMask) != origPixel)
-                                                                               *(int*)(pixels + x) = pixel;
-
-                                                               pixels += stride;
+                                                       for (line = 0; line < height; line++) {
+                                                               lineEndPtr = linePtr + widthBytes;
+                                                               for (pixelPtr = linePtr; pixelPtr < lineEndPtr; pixelPtr += 4)
+                                                                       *(int*)pixelPtr = (((pixel = *(int*)pixelPtr) & AlphaMask) == 0) ? 0x00000000 : pixel | AlphaMask;
+                                                               linePtr += stride;
                                                        }
                                                }
                                        }