isValidIndex() public method

public isValidIndex ( uint i ) : bool
i uint
return bool
Example #1
0
// maxColor and minColor are expected to be in the same range as the color set.
        static uint computeIndices3(ColorSet set, Vector3 maxColor, Vector3 minColor)
        {
            Vector3[] palette = new Vector3[4];
            palette[0] = minColor;
            palette[1] = maxColor;
            palette[2] = (palette[0] + palette[1]) * 0.5f;

            uint indices = 0;

            for (uint i = 0; i < 16; i++)
            {
                if (!set.isValidIndex(i))
                {
                    // Skip masked pixels and out of bounds.
                    indices |= (uint)3 << (int)(2 * i);
                    continue;
                }

                Vector3 color = new Vector3(set.color[i].x, set.color[i].y, set.color[i].z);

                float d0 = colorDistance(palette[0], color);
                float d1 = colorDistance(palette[1], color);
                float d2 = colorDistance(palette[2], color);

                uint index;
                if (d0 < d1 && d0 < d2)
                {
                    index = 0;
                }
                else if (d1 < d2)
                {
                    index = 1;
                }
                else
                {
                    index = 2;
                }

                indices |= index << (int)(2 * i);
            }

            return(indices);
        }
Example #2
0
// maxColor and minColor are expected to be in the same range as the color set.
        static uint computeIndices4(ColorSet set, Vector3 maxColor, Vector3 minColor)
        {
            Vector3[] palette = new Vector3[4];
            palette[0] = maxColor;
            palette[1] = minColor;
            palette[2] = Vector3.Lerp(palette[0], palette[1], 1.0f / 3.0f);
            palette[3] = Vector3.Lerp(palette[0], palette[1], 2.0f / 3.0f);


            Vector3[] row0 = new Vector3[6];
            Vector3[] row1 = new Vector3[6];

            uint indices = 0;

            //for(int i = 0; i < 16; i++)
            for (uint y = 0; y < 4; y++)
            {
                for (uint x = 0; x < 4; x++)
                {
                    uint i = y * 4 + x;

                    if (!set.isValidIndex(i))
                    {
                        // Skip masked pixels and out of bounds.
                        continue;
                    }

                    Vector3 color = new Vector3(set.color[i].x, set.color[i].y, set.color[i].z);

                    // Add error.
                    color += row0[1 + x];

                    float d0 = colorDistance(palette[0], color);
                    float d1 = colorDistance(palette[1], color);
                    float d2 = colorDistance(palette[2], color);
                    float d3 = colorDistance(palette[3], color);

                    uint b0 = d0 > d3?(uint)1:(uint)0;
                    uint b1 = d1 > d2?(uint)1:(uint)0;
                    uint b2 = d0 > d2?(uint)1:(uint)0;
                    uint b3 = d1 > d3?(uint)1:(uint)0;
                    uint b4 = d2 > d3?(uint)1:(uint)0;

                    uint x0 = b1 & b2;
                    uint x1 = b0 & b3;
                    uint x2 = b0 & b4;

                    uint index = x2 | ((x0 | x1) << 1);
                    indices |= index << (int)(2 * i);

                    // Compute new error.
                    Vector3 diff = color - palette[index];

                    // Propagate new error.
                    //row0[1+x+1] += 7.0f / 16.0f * diff;
                    //row1[1+x-1] += 3.0f / 16.0f * diff;
                    //row1[1+x+0] += 5.0f / 16.0f * diff;
                    //row1[1+x+1] += 1.0f / 16.0f * diff;
                }

                swap(ref row0, ref row1);
                row1 = new Vector3[6];
            }

            return(indices);
        }