Ejemplo n.º 1
0
        private bool Initalize(SvrPixelFormat pixelFormat, SvrDataFormat dataFormat)
        {
            // Set the default values
            hasGlobalIndex = true;
            globalIndex    = 0;

            // Set the data format and pixel format and load the appropiate codecs
            this.pixelFormat = pixelFormat;
            pixelCodec       = SvrPixelCodec.GetPixelCodec(pixelFormat);

            this.dataFormat = dataFormat;
            dataCodec       = SvrDataCodec.GetDataCodec(dataFormat);

            // Make sure the pixel and data codecs exists and we can encode to it
            if (pixelCodec == null || !pixelCodec.CanEncode)
            {
                return(false);
            }
            if (dataCodec == null || !dataCodec.CanEncode)
            {
                return(false);
            }

            // Set the correct data format (it's ok to do it after getting the codecs).
            if (dataFormat == SvrDataFormat.Index4Rgb5a3Rectangle || dataFormat == SvrDataFormat.Index4Rgb5a3Square ||
                dataFormat == SvrDataFormat.Index4Argb8Rectangle || dataFormat == SvrDataFormat.Index4Argb8Square)
            {
                if (textureWidth == textureHeight) // Square texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index4Rgb5a3Square;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index4Argb8Square;
                    }
                }
                else // Rectangular texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index4Rgb5a3Rectangle;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index4Argb8Rectangle;
                    }
                }
            }

            else if (dataFormat == SvrDataFormat.Index8Rgb5a3Rectangle || dataFormat == SvrDataFormat.Index8Rgb5a3Square ||
                     dataFormat == SvrDataFormat.Index8Argb8Rectangle || dataFormat == SvrDataFormat.Index8Argb8Square)
            {
                if (textureWidth == textureHeight) // Square texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index8Rgb5a3Square;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index8Argb8Square;
                    }
                }
                else // Rectangular texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index8Rgb5a3Rectangle;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index8Argb8Rectangle;
                    }
                }
            }

            if (dataCodec.PaletteEntries != 0)
            {
                // Convert the bitmap to an array containing indicies.
                decodedData = BitmapToRawIndexed(decodedBitmap, dataCodec.PaletteEntries, out texturePalette);

                // If this texture has an external palette file, set up the palette encoder
                if (dataCodec.NeedsExternalPalette)
                {
                    paletteEncoder = new SvpPaletteEncoder(texturePalette, (ushort)dataCodec.PaletteEntries, pixelFormat, pixelCodec);
                }
            }
            else
            {
                // Convert the bitmap to an array
                decodedData = BitmapToRaw(decodedBitmap);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private bool Initalize(SvrPixelFormat pixelFormat, SvrDataFormat dataFormat)
        {
            // Set the default values
            hasGlobalIndex = true;
            globalIndex = 0;

            // Set the data format and pixel format and load the appropiate codecs
            this.pixelFormat = pixelFormat;
            pixelCodec = SvrPixelCodec.GetPixelCodec(pixelFormat);

            this.dataFormat = dataFormat;
            dataCodec = SvrDataCodec.GetDataCodec(dataFormat);

            // Make sure the pixel and data codecs exists and we can encode to it
            if (pixelCodec == null || !pixelCodec.CanEncode) return false;
            if (dataCodec == null || !dataCodec.CanEncode) return false;

            // Set the correct data format (it's ok to do it after getting the codecs).
            if (dataFormat == SvrDataFormat.Index4Rgb5a3Rectangle || dataFormat == SvrDataFormat.Index4Rgb5a3Square ||
                dataFormat == SvrDataFormat.Index4Argb8Rectangle || dataFormat == SvrDataFormat.Index4Argb8Square)
            {
                if (textureWidth == textureHeight) // Square texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index4Rgb5a3Square;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index4Argb8Square;
                    }
                }
                else // Rectangular texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index4Rgb5a3Rectangle;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index4Argb8Rectangle;
                    }
                }
            }

            else if (dataFormat == SvrDataFormat.Index8Rgb5a3Rectangle || dataFormat == SvrDataFormat.Index8Rgb5a3Square ||
                dataFormat == SvrDataFormat.Index8Argb8Rectangle || dataFormat == SvrDataFormat.Index8Argb8Square)
            {
                if (textureWidth == textureHeight) // Square texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index8Rgb5a3Square;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index8Argb8Square;
                    }
                }
                else // Rectangular texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index8Rgb5a3Rectangle;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index8Argb8Rectangle;
                    }
                }
            }

            if (dataCodec.PaletteEntries != 0)
            {
                // Convert the bitmap to an array containing indicies.
                decodedData = BitmapToRawIndexed(decodedBitmap, dataCodec.PaletteEntries, out texturePalette);

                // If this texture has an external palette file, set up the palette encoder
                if (dataCodec.NeedsExternalPalette)
                {
                    paletteEncoder = new SvpPaletteEncoder(texturePalette, (ushort)dataCodec.PaletteEntries, pixelFormat, pixelCodec);
                }
            }
            else
            {
                // Convert the bitmap to an array
                decodedData = BitmapToRaw(decodedBitmap);
            }

            return true;
        }