Ejemplo n.º 1
0
        private static void FlipImage(BaseBitmap bitmap, Bitmap.Image image)
        {
            switch (image.Format)
            {
            case BitmapFormat.Dxt1:
            case BitmapFormat.Dxt3:
            case BitmapFormat.Dxt5:
            case BitmapFormat.Dxn:
                for (int j = 0; j < bitmap.Data.Length; j += 2)
                {
                    Array.Reverse(bitmap.Data, j, 2);
                }
                break;

            case BitmapFormat.AY8:
            case BitmapFormat.Y8:
            case BitmapFormat.A8:
            case BitmapFormat.Dxt5aMono:
            case BitmapFormat.Dxt3aMono:
            case BitmapFormat.Dxt3aAlpha:
            case BitmapFormat.Dxt5aAlpha:
            case BitmapFormat.Ctx1:
            case BitmapFormat.DxnMonoAlpha:
            case BitmapFormat.Dxt5a:
            case BitmapFormat.R5G6B5:
            case BitmapFormat.A4R4G4B4:
                break;

            case BitmapFormat.A8R8G8B8:
            case BitmapFormat.X8R8G8B8:
                for (int j = 0; j < bitmap.Data.Length; j += 4)
                {
                    Array.Reverse(bitmap.Data, j, 4);
                }
                break;

            case BitmapFormat.A16B16G16R16F:
            case BitmapFormat.A8Y8:
            case BitmapFormat.V8U8:
                for (int j = 0; j < bitmap.Data.Length; j += 2)
                {
                    Array.Reverse(bitmap.Data, j, 2);
                }
                break;

            default:
                throw new Exception($"Unsupported format {image.Format} flipping");
            }

            if (bitmap.Format == BitmapFormat.Dxn)
            {
                bitmap.Data = BitmapDecoder.SwapXYDxn(bitmap.Data, bitmap.Width, bitmap.Height);
            }
        }
Ejemplo n.º 2
0
        public static byte[] ConvertXboxFormats(byte[] data, uint width, uint height, BitmapFormat format, bool requireDecompression)
        {
            BitmapFormat destinationFormat = GetEquivalentBitmapFormat(format);

            if (format == BitmapFormat.Dxn)
            {
                // flip x and y channels
                data = BitmapDecoder.SwapXYDxn(data, (int)width, (int)height);
            }

            if (destinationFormat == format && !requireDecompression)
            {
                return(data);
            }

            if (format == BitmapFormat.Ctx1)
            {
                data   = BitmapDecoder.Ctx1ToDxn(data, (int)width, (int)height);
                format = BitmapFormat.Dxn;
            }
            else if (format != destinationFormat)
            {
                byte[] uncompressedData = BitmapDecoder.DecodeBitmap(data, format, (int)width, (int)height);

                uncompressedData = TrimAlignedBitmap(format, destinationFormat, (int)width, (int)height, uncompressedData);

                data   = BitmapDecoder.EncodeBitmap(uncompressedData, destinationFormat, (int)width, (int)height);
                format = destinationFormat;
            }

            if (requireDecompression)
            {
                data = ConvertNonMultipleBlockSizeBitmap(data, width, height, format);
            }


            return(data);
        }