Пример #1
0
        public static CMPRBlock optimalCompressDXT1a(ARGBPixel rgba)
        {
            if (rgba.A < 128)
            {
                CMPRBlock block = new CMPRBlock();
                block._root0._data = 0;
                block._root1._data = 0;
                block._lookup      = 0xFFFFFFFF;
                return(block);
            }

            return(optimalCompressDXT1(rgba));
        }
Пример #2
0
        private static CMPRBlock optimalCompressDXT1(ARGBPixel c)
        {
            CMPRBlock block = new CMPRBlock();

            uint indices = 0xAAAAAAAA;

            block._root0._data = (ushort)((OMatch5[c.R, 0] << 11) | (OMatch6[c.G, 0] << 5) | OMatch5[c.B, 0]);
            block._root1._data = (ushort)((OMatch5[c.R, 1] << 11) | (OMatch6[c.G, 1] << 5) | OMatch5[c.B, 1]);

            if (block._root0 < block._root1)
            {
                VoidPtr.Swap((short *)&block._root0, (short *)&block._root1);
                indices ^= 0x55555555;
            }
            block._lookup = indices;
            return(block);
        }
Пример #3
0
        private static CMPRBlock compressDXT1(ARGBPixel *pBlock)
        {
            float *  pointData = stackalloc float[48];
            Vector3 *points    = (Vector3 *)pointData;

            extractColorBlockRGB(pBlock, points);

            // find min and max colors
            Vector3 maxColor, minColor;

            findMinMaxColorsBox(points, 16, &maxColor, &minColor);

            selectDiagonal(points, 16, &maxColor, &minColor);

            insetBBox(&maxColor, &minColor);

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

            if (color0 < color1)
            {
                Vector3 t = maxColor;
                maxColor = minColor;
                minColor = t;
                VoidPtr.Swap(&color0, &color1);
            }

            CMPRBlock block = new CMPRBlock();

            block._root0._data = color0;
            block._root1._data = color1;
            block._lookup      = computeIndices4(points, &maxColor, &minColor);


            optimizeEndPoints4(points, &block);

            return(block);
        }
Пример #4
0
        public static CMPRBlock compressDXT1a(ARGBPixel *img, int imgX, int imgY, int imgW, int imgH)
        {
            uint *     pData  = stackalloc uint[16];
            ARGBPixel *pBlock = (ARGBPixel *)pData;

            bool hasAlpha = false;
            bool isSingle = true;

            ARGBPixel  p;
            ARGBPixel *sPtr  = img + (imgX + imgY * imgW);
            int        index = 0;

            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    p = sPtr[x + y * imgW];
                    pBlock[index++] = p;
                    if (p != pBlock[0])
                    {
                        isSingle = false;
                    }

                    if (p.A < 128)
                    {
                        hasAlpha = true;
                    }
                }
            }

            if (isSingle)
            {
                return(optimalCompressDXT1a(sPtr[0]));
            }

            if (!hasAlpha)
            {
                return(compressDXT1(pBlock));
            }

            // @@ Handle single RGB, with varying alpha? We need tables for single color compressor in 3 color mode.
            //else if (rgba.isSingleColorNoAlpha()) { ... }

            float *  pointData = stackalloc float[48];
            Vector3 *points    = (Vector3 *)pointData;

            // read block
            //Vector3 block[16];
            int num = extractColorBlockRGBA(pBlock, points);

            // find min and max colors
            Vector3 maxColor, minColor;

            findMinMaxColorsBox(points, num, &maxColor, &minColor);

            selectDiagonal(points, num, &maxColor, &minColor);

            insetBBox(&maxColor, &minColor);

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

            if (color0 < color1)
            {
                Vector3 t = maxColor;
                maxColor = minColor;
                minColor = t;
                VoidPtr.Swap(&color0, &color1);
            }

            CMPRBlock block = new CMPRBlock();

            block._root0._data = color1;
            block._root1._data = color0;
            block._lookup      = computeIndices3(pBlock, &maxColor, &minColor);

            //	optimizeEndPoints(block, dxtBlock);

            return(block);
        }