Esempio n. 1
0
        private static RGBA loadPixel(RGBA[] pal, ushort address, ushort mode, int texel, RGBA pixel)
        {
            switch (mode)
            {
            case 0:
            {
                pixel = pal[(address << 1) + texel];
                if (texel == 3)
                {
                    pixel = RGBA.Transparent;
                }
                break;
            }

            case 1:
            {
                switch (texel)
                {
                case 2:
                    pixel.R = (byte)(((long)(pal[address << 1].R + pal[(address << 1) + 1].R)) / 2L);
                    pixel.G = (byte)(((long)(pal[address << 1].G + pal[(address << 1) + 1].G)) / 2L);
                    pixel.B = (byte)(((long)(pal[address << 1].B + pal[(address << 1) + 1].B)) / 2L);
                    pixel.A = 0xff;
                    break;

                case 3:
                    pixel = RGBA.Transparent;
                    break;
                }
                break;
            }

            case 2:
            {
                pixel = pal[(address << 1) + texel];
                break;
            }

            case 3:
            {
                switch (texel)
                {
                case 0:
                case 1:
                    pixel = pal[(address << 1) + texel];
                    break;

                case 2:
                    pixel.R = (byte)(((pal[address << 1].R * 5L) + (pal[(address << 1) + 1].R * 3L)) / ((long)8L));
                    pixel.G = (byte)(((pal[address << 1].G * 5L) + (pal[(address << 1) + 1].G * 3L)) / ((long)8L));
                    pixel.B = (byte)(((pal[address << 1].B * 5L) + (pal[(address << 1) + 1].B * 3L)) / ((long)8L));
                    pixel.A = 0xff;
                    break;

                case 3:
                    pixel.R = (byte)(((pal[address << 1].R * 3L) + (pal[(address << 1) + 1].R * 5L)) / ((long)8L));
                    pixel.G = (byte)(((pal[address << 1].G * 3L) + (pal[(address << 1) + 1].G * 5L)) / ((long)8L));
                    pixel.B = (byte)(((pal[address << 1].B * 3L) + (pal[(address << 1) + 1].B * 5L)) / ((long)8L));
                    pixel.A = 0xff;
                    break;
                }
                break;
            }

            default:
            {
                break;
            }
            }
            pixel = pal[(address << 1) + texel];
            return(pixel);
        }
Esempio n. 2
0
        private void checkImageFlipRotated()
        {
            int pixelNum = actualMat.width * actualMat.heigth;

            if ((actualMat.flipS == 1) && (actualMat.repeatS > 0))
            {
                var newImage      = new RGBA[pixelNum * 2];
                int newWidth      = actualMat.width * 2;
                int newWidth2     = newWidth - 1;
                int heightCounter = 0;
                while (heightCounter < actualMat.heigth)
                {
                    int texBase      = heightCounter * actualMat.width;
                    int newBase      = heightCounter * newWidth;
                    int widthCounter = 0;
                    while (widthCounter < actualMat.width)
                    {
                        var pixel = image[texBase + widthCounter];
                        newImage[newBase + widthCounter] = pixel;
                        newImage[(newBase + newWidth2) - widthCounter] = pixel;
                        widthCounter++;
                    }
                    heightCounter++;
                }
                actualMat.width = newWidth;
                image           = newImage;
            }
            if ((actualMat.flipT == 1) && (actualMat.repeatT > 0))
            {
                var newImage      = new RGBA[pixelNum * 2];
                var newHeigth     = actualMat.heigth * 2;
                var newHeight2    = actualMat.heigth - 1;
                int heigthCounter = 0;
                while (heigthCounter < actualMat.heigth)
                {
                    int texBase      = heigthCounter * actualMat.width;
                    int newBase      = (newHeight2 - heigthCounter) * actualMat.width;
                    int widthCounter = 0;
                    while (widthCounter < actualMat.width)
                    {
                        newImage[newBase + widthCounter] = image[texBase + widthCounter];
                        widthCounter++;
                    }
                    heigthCounter++;
                }
                actualMat.heigth = newHeigth;
                image            = newImage;
            }
            if ((((actualMat.flipS == 1) && (actualMat.repeatS > 0)) && (actualMat.flipT == 1)) && (actualMat.repeatT > 0))
            {
                var newImage   = new RGBA[pixelNum * 4];
                int newWidth   = actualMat.width * 2;
                int newWidth2  = newWidth - 1;
                int newHeigth  = actualMat.heigth * 2;
                int newHeigth2 = newHeigth - 1;
                for (int heigthCounter = 0; heigthCounter < actualMat.heigth; heigthCounter++)
                {
                    int texBase    = heigthCounter * actualMat.width;
                    int topBase    = heigthCounter * newWidth;
                    int bottomBase = (newHeigth2 - heigthCounter) * newWidth;
                    for (int widthCounter = 0; widthCounter < actualMat.width; widthCounter++)
                    {
                        var pixel = image[texBase + widthCounter];
                        newImage[topBase + widthCounter] = pixel;
                        newImage[(topBase + newWidth2) - widthCounter]    = pixel;
                        newImage[bottomBase + widthCounter]               = pixel;
                        newImage[(bottomBase + newWidth2) - widthCounter] = pixel;
                    }
                }
                actualMat.width  = newWidth;
                actualMat.heigth = newHeigth;
                image            = newImage;
            }
        }