NvidiaTextureTools.ColorBlock.isSingleColor C# (CSharp) Method

isSingleColor() public method

public isSingleColor ( ) : bool
return bool
        public bool isSingleColor()
        {
            uint u = m_color[0].u();

            for (uint i = 1; i < 16; i++)
            {
                if (u != (m_color[i].u()))
                {
                    return false;
                }
            }

            return true;
        }

Usage Example

Example #1
0
        public static void compressDXT1(ColorBlock rgba, BlockDXT1 dxtBlock)
        {
            if (rgba.isSingleColor())
            {
                OptimalCompress.compressDXT1(rgba.color[0], dxtBlock);
            }
            else
            {
                // read block
                Vector3[] block = new Vector3[16];
                extractColorBlockRGB(rgba, block);
#if true
                // find min and max colors
                Vector3 maxColor = Vector3.zero, minColor = Vector3.zero;
                findMinMaxColorsBox(block, 16, ref maxColor, ref minColor);

                selectDiagonal(block, 16, ref maxColor, ref minColor);

                insetBBox(ref maxColor, ref minColor);
#else
                float[] weights = new float[16] {
                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
                };
                Vector3[] cluster = new Vector3[4];
                int       count   = Fitting.Compute4Means(16, block, weights, Vector3.one, cluster);

                Vector3 maxColor, minColor;
                float   bestError = FLT_MAX;

                for (int i = 1; i < 4; i++)
                {
                    for (int j = 0; j < i; j++)
                    {
                        uint16 color0 = roundAndExpand(&cluster[i]);
                        uint16 color1 = roundAndExpand(&cluster[j]);

                        float error = evaluatePaletteError4(block, cluster[i], cluster[j]);
                        if (error < bestError)
                        {
                            bestError = error;
                            maxColor  = cluster[i];
                            minColor  = cluster[j];
                        }
                    }
                }
#endif

                ushort color0 = roundAndExpand(ref maxColor);
                ushort color1 = roundAndExpand(ref minColor);

                if (color0 < color1)
                {
                    swap(ref maxColor, ref minColor);
                    swap(ref color0, ref color1);
                }

                dxtBlock.col0    = new Color16(color0);
                dxtBlock.col1    = new Color16(color1);
                dxtBlock.indices = computeIndices4(block, maxColor, minColor);

                optimizeEndPoints4(block, dxtBlock);
            }
        }