Пример #1
0
        static aRGBA[] loadCMPR(aBinaryReader reader, int width, int height)
        {
            var       data = new aRGBA[width * height];
            const int cTileWidth = 8, cTileHeight = 8;
            const int cBlockWidth = 4, cBlockHeight = 4;

            for (var y = 0; y < height; y += cTileHeight)               // tile
            {
                for (var x = 0; x < width; x += cTileWidth)
                {
                    for (var by = 0; by < cTileHeight; by += cBlockHeight)                       // block
                    {
                        for (var bx = 0; bx < cTileWidth; bx += cBlockWidth)
                        {
                            var colors = aRGBA.FromST3C1(reader.Read64());
                            for (var ty = 0; ty < cBlockHeight && y + by + ty < height; ty++)                               // texel
                            {
                                for (var tx = 0; tx < cBlockWidth && x + bx + tx < width; tx++)
                                {
                                    data[width * (y + by + ty) + (x + bx + tx)] = colors[(ty * cBlockWidth) + tx];
                                }
                            }
                        }
                    }
                }
            }
            return(data);
        }
Пример #2
0
        static aRGBA[] loadI4(aBinaryReader reader, int width, int height)
        {
            var       data = new aRGBA[width * height];
            const int cBlockWidth = 8, cBlockHeight = 8;

            for (var y = 0; y < height; y += cBlockHeight)
            {
                for (var x = 0; x < width; x += cBlockWidth)
                {
                    for (var by = 0; by < cBlockHeight; ++by)
                    {
                        for (var bx = 0; bx < cBlockWidth; bx += 2)
                        {
                            var i4    = reader.Read8();
                            var index = (width * (y + by) + (x + bx));
                            if ((by + y) >= height)
                            {
                                continue;
                            }
                            if ((bx + x) < width)
                            {
                                data[index] = new aRGBA(sNybbleToByte[(i4 >> 4) & 0xF]);
                            }
                            if ((bx + x + 1) < width)
                            {
                                data[index + 1] = new aRGBA(sNybbleToByte[i4 & 0xF]);
                            }
                        }
                    }
                }
            }
            return(data);
        }
Пример #3
0
        static aRGBA[] loadRGB5A3(aBinaryReader reader, int width, int height)
        {
            var       data = new aRGBA[width * height];
            const int cBlockWidth = 4, cBlockHeight = 4;

            for (var y = 0; y < height; y += cBlockHeight)
            {
                for (var x = 0; x < width; x += cBlockWidth)
                {
                    for (var by = 0; by < cBlockHeight; ++by)
                    {
                        for (var bx = 0; bx < cBlockWidth; ++bx)
                        {
                            var color = reader.Read16();
                            if ((bx + x) >= width || (by + y) >= height)
                            {
                                continue;
                            }
                            data[(width * (y + by)) + (x + bx)] = (
                                (color & 0x8000) != 0 ?
                                aRGBA.FromRGB5(color) :
                                aRGBA.FromRGB4A3(color)
                                );
                        }
                    }
                }
            }
            return(data);
        }
Пример #4
0
        static aRGBA[] loadIA4(aBinaryReader reader, int width, int height)
        {
            var       data = new aRGBA[width * height];
            const int cBlockWidth = 8, cBlockHeight = 4;

            for (var y = 0; y < height; y += cBlockHeight)
            {
                for (var x = 0; x < width; x += cBlockWidth)
                {
                    for (var by = 0; by < cBlockHeight; ++by)
                    {
                        for (var bx = 0; bx < cBlockWidth; ++bx)
                        {
                            var ia4 = reader.Read8();
                            if ((bx + x) >= width || (by + y) >= height)
                            {
                                continue;
                            }
                            data[width * (y + by) + (x + bx)] = new aRGBA(sNybbleToByte[ia4 & 0xF], sNybbleToByte[(ia4 >> 4) & 0xF]);
                        }
                    }
                }
            }
            return(data);
        }
Пример #5
0
        static aRGBA[] loadIA8(aBinaryReader reader, int width, int height)
        {
            var       data = new aRGBA[width * height];
            const int cBlockWidth = 4, cBlockHeight = 4;

            for (var y = 0; y < height; y += cBlockHeight)
            {
                for (var x = 0; x < width; x += cBlockWidth)
                {
                    for (var by = 0; by < cBlockHeight; ++by)
                    {
                        for (var bx = 0; bx < cBlockWidth; ++bx)
                        {
                            var intensity = reader.Read8();
                            var alpha     = reader.Read8();
                            if ((bx + x) >= width || (by + y) >= height)
                            {
                                continue;
                            }
                            data[width * (y + by) + (x + bx)] = new aRGBA(intensity, alpha);
                        }
                    }
                }
            }
            return(data);
        }
Пример #6
0
        public static aRGBA[] FromST3C1(ulong st3c1)
        {
            var colors = new aRGBA[4];

            colors[0] = FromRGB565((ushort)((st3c1 >> 48) & 0xFFFF));
            colors[1] = FromRGB565((ushort)((st3c1 >> 32) & 0xFFFF));
            if (colors[0].ARGB > colors[1].ARGB)
            {
                colors[2] = Lerp(colors[0], colors[1], 0.333333f);
                colors[3] = Lerp(colors[0], colors[1], 0.666666f);
            }
            else
            {
                colors[2] = Lerp(colors[0], colors[1], 0.5f);
                colors[3] = new aRGBA(0, 0);
            }
            var data = new aRGBA[16];
            var bits = 30;

            for (var y = 0; y < 4; y++)
            {
                for (var x = 0; x < 4; x++)
                {
                    data[4 * y + x] = colors[(st3c1 >> bits) & 0x3];
                    bits           -= 2;
                }
            }
            return(data);
        }
Пример #7
0
 void loadPaletteDataIA8(aBinaryReader reader)
 {
     for (int i = 0; i < mEntryCount; ++i)
     {
         var i8 = reader.Read8();
         var a8 = reader.Read8();
         mData[i] = new aRGBA(i8, a8);
     }
 }
Пример #8
0
 public static aRGBA Lerp(aRGBA from, aRGBA to, float percent)
 {
     return(new aRGBA
            (
                (int)(from.r + (to.r - from.r) * percent),
                (int)(from.g + (to.g - from.g) * percent),
                (int)(from.b + (to.b - from.b) * percent),
                (int)(from.a + (to.a - from.a) * percent)
            ));
 }
Пример #9
0
        static aRGBA[] loadRGBA8(aBinaryReader reader, int width, int height)
        {
            var       data = new aRGBA[width * height];
            const int cBlockWidth = 4, cBlockHeight = 4;
            var       colors = new uint[16];

            for (var y = 0; y < height; y += cBlockHeight)
            {
                for (var x = 0; x < width; x += cBlockWidth)
                {
                    for (var by = 0; by < cBlockHeight && (y + by) < height; ++by)                       // AR
                    {
                        for (var bx = 0; bx < cBlockWidth && (x + bx) < width; ++bx)
                        {
                            colors[(cBlockWidth * by) + bx] = (uint)(reader.Read16() << 16);
                        }
                    }
                    for (var by = 0; by < cBlockHeight && (y + by) < height; ++by)                       // GB
                    {
                        for (var bx = 0; bx < cBlockWidth && (x + bx) < width; ++bx)
                        {
                            colors[(cBlockWidth * by) + bx] |= reader.Read16();
                        }
                    }
                    for (var by = 0; by < cBlockHeight; ++by)
                    {
                        for (var bx = 0; bx < cBlockWidth; ++bx)
                        {
                            if ((x + bx) >= width || (y + by) >= height)
                            {
                                continue;
                            }
                            data[width * (y + by) + (x + bx)] = aRGBA.FromARGB8(colors[(cBlockWidth * by) + bx]);
                        }
                    }
                }
            }
            return(data);
        }
Пример #10
0
 public aRGBA(aRGBA color, int alpha)
     : this(color.r, color.g, color.b, alpha)
 {
 }
Пример #11
0
 public aRGBA(aRGBA color)
     : this(color.r, color.g, color.b, color.a)
 {
 }
Пример #12
0
 public static aRGBA Lerp(aRGBA from, aRGBA to, float percent)
 {
     return new aRGBA
     (
         (int)(from.r + (to.r - from.r) * percent),
         (int)(from.g + (to.g - from.g) * percent),
         (int)(from.b + (to.b - from.b) * percent),
         (int)(from.a + (to.a - from.a) * percent)
     );
 }
Пример #13
0
 public static aRGBA[] FromST3C1(ulong st3c1)
 {
     var colors = new aRGBA[4];
     colors[0] = FromRGB565((ushort)((st3c1 >> 48) & 0xFFFF));
     colors[1] = FromRGB565((ushort)((st3c1 >> 32) & 0xFFFF));
     if (colors[0].ARGB > colors[1].ARGB) {
         colors[2] = Lerp(colors[0], colors[1], 0.333333f);
         colors[3] = Lerp(colors[0], colors[1], 0.666666f);
     }
     else {
         colors[2] = Lerp(colors[0], colors[1], 0.5f);
         colors[3] = new aRGBA(0, 0);
     }
     var data = new aRGBA[16];
     var bits = 30;
     for (var y = 0; y < 4; y++) {
         for (var x = 0; x < 4; x++) {
             data[4 * y + x] = colors[(st3c1 >> bits) & 0x3];
             bits -= 2;
         }
     }
     return data;
 }
Пример #14
0
 public aRGBA(aRGBA color, int alpha)
     : this(color.r, color.g, color.b, alpha)
 {
 }
Пример #15
0
 public aRGBA(aRGBA color)
     : this(color.r, color.g, color.b, color.a)
 {
 }