[NUI] Check spelling
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Utility / ColorUtils.cs
index 52708e5..5c53eba 100755 (executable)
@@ -45,8 +45,7 @@ namespace Tizen.NUI
         /// </summary>
         public static void ColorToXyz(int color, double[] outXyz)
         {
-            System.Drawing.Color rgbColor = System.Drawing.Color.FromArgb(color);
-            RgbToXyz(rgbColor.R, rgbColor.G, rgbColor.B, outXyz);
+            RgbToXyz((color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, outXyz);
         }
 
         /// <summary>
@@ -100,19 +99,17 @@ namespace Tizen.NUI
         /// </summary>
         public static int CompositeColors(int foreground, int background)
         {
-            System.Drawing.Color foreColor = System.Drawing.Color.FromArgb(foreground);
-            System.Drawing.Color backColor = System.Drawing.Color.FromArgb(background);
-            int bgAlpha = backColor.A;
-            int fgAlpha = foreColor.A;
+            int bgAlpha = (background >> 24) & 0xff;
+            int fgAlpha = (foreground >> 24) & 0xff;
 
             int alpha = CompositeAlpha(fgAlpha, bgAlpha);
 
-            int red = CompositeComponent(foreColor.R, fgAlpha,
-                    backColor.R, bgAlpha, alpha);
-            int green = CompositeComponent(foreColor.G, fgAlpha,
-                    backColor.G, bgAlpha, alpha);
-            int blue = CompositeComponent(foreColor.B, fgAlpha,
-                    backColor.B, bgAlpha, alpha);
+            int red = CompositeComponent((foreground >> 16) & 0xff, fgAlpha,
+                    (background >> 16) & 0xff, bgAlpha, alpha);
+            int green = CompositeComponent((foreground >> 8) & 0xff, fgAlpha,
+                    (background >> 8) & 0xff, bgAlpha, alpha);
+            int blue = CompositeComponent(foreground & 0xff, fgAlpha,
+                    background & 0xff, bgAlpha, alpha);
 
             return ((alpha & 0xff) << 24 | (red & 0xff) << 16 | (green & 0xff) << 8 | (blue & 0xff));
         }
@@ -132,11 +129,8 @@ namespace Tizen.NUI
             }
             if (((foreground >> 24) & 0xff) < 255)
             {
-                System.Drawing.Color rgbColor = System.Drawing.Color.FromArgb(foreground);
-
                 // If the foreground is translucent, composite the foreground over the background
                 foreground = CompositeColors(foreground, background);
-                rgbColor = System.Drawing.Color.FromArgb(foreground);
             }
 
             double luminance1 = CalculateLuminance(foreground) + 0.05;
@@ -169,8 +163,7 @@ namespace Tizen.NUI
         /// param minContrastRatio the minimum contrast ratio
         /// return the alpha value in the range 0-255, or -1 if no value could be calculated
         /// </summary>
-        public static int CalculateMinimumAlpha(int foreground, int background,
-                float minContrastRatio)
+        public static int CalculateMinimumAlpha(int foreground, int background, float minContrastRatio)
         {
             if (((background >> 24) & 0xff) != 255)
             {
@@ -179,7 +172,6 @@ namespace Tizen.NUI
 
             // First lets check that a fully opaque foreground has sufficient contrast
             int testForeground = SetAlphaComponent(foreground, 255);
-            System.Drawing.Color rgbColor = System.Drawing.Color.FromArgb(testForeground);
             double testRatio = CalculateContrast(testForeground, background);
 
             if (testRatio < minContrastRatio)
@@ -199,7 +191,6 @@ namespace Tizen.NUI
                 int testAlpha = (minAlpha + maxAlpha) / 2;
 
                 testForeground = SetAlphaComponent(foreground, testAlpha);
-                rgbColor = System.Drawing.Color.FromArgb(testForeground);
                 testRatio = CalculateContrast(testForeground, background);
                 if (testRatio < minContrastRatio)
                 {
@@ -305,8 +296,47 @@ namespace Tizen.NUI
             return (255 << 24 | (red & 0xff) << 16 | (green & 0xff) << 8 | (blue & 0xff));
         }
 
+        public static uint GetBytesPerPixel(PixelFormat pixelFormat)
+        {
+            switch (pixelFormat)
+            {
+                case PixelFormat.L8:
+                case PixelFormat.A8:
+                {
+                    return 1;
+                }
+
+                case PixelFormat.LA88:
+                case PixelFormat.RGB565:
+                case PixelFormat.RGBA4444:
+                case PixelFormat.RGBA5551:
+                case PixelFormat.BGR565:
+                case PixelFormat.BGRA4444:
+                case PixelFormat.BGRA5551:
+                {
+                    return 2;
+                }
+
+                case PixelFormat.RGB888:
+                {
+                    return 3;
+                }
+
+                case PixelFormat.RGB8888:
+                case PixelFormat.BGR8888:
+                case PixelFormat.RGBA8888:
+                case PixelFormat.BGRA8888:
+                {
+                    return 4;
+                }
+                default:
+                    Tizen.Log.Error("Palette", "Invalided PixelFormat(" + pixelFormat + ") has been given \n");
+                    return 0;
+            }
+        }
+
         /// <summary>
-        /// return luma value according to to XYZ color space in the range 0.0 - 1.0
+        /// return luma value according to XYZ color space in the range 0.0 - 1.0
         /// </summary>
         private static int CompositeAlpha(int foregroundAlpha, int backgroundAlpha)
         {