Beispiel #1
0
 public BaseBitmap(BitmapTextureInterleavedInteropResource definition, int index, Bitmap.Image image)
 {
     if (index == 0)
     {
         var def = definition.Texture.Definition.Bitmap1;
         Height      = def.Height;
         Width       = def.Width;
         Depth       = def.Depth;
         MipMapCount = def.MipmapCount - 1;
         Type        = def.BitmapType;
         Flags       = image.Flags;
         UpdateFormat(image.Format);
     }
     else
     {
         var def = definition.Texture.Definition.Bitmap2;
         Height      = def.Height;
         Width       = def.Width;
         Depth       = def.Depth;
         MipMapCount = def.MipmapCount - 1;
         Type        = def.BitmapType;
         Flags       = image.Flags;
         UpdateFormat(image.Format);
     }
     MipMapOffset = image.MipMapOffset;
     Curve        = image.Curve;
 }
Beispiel #2
0
    public BaseBitmap(BitmapTextureInterleavedInteropResource definition, int index, Bitmap.Image image)
    {
        var def = definition.Texture.Definition;

        if (index == 0)
        {
            Height      = def.Height1;
            Width       = def.Width1;
            Depth       = def.Depth1;
            MipMapCount = def.MipmapCount1 - 1;
            Type        = def.Type1;
            Flags       = image.Flags;
            UpdateFormat(image.Format);
        }
        else
        {
            Height      = def.Height2;
            Width       = def.Width2;
            Depth       = def.Depth2;
            MipMapCount = def.MipmapCount2 - 1;
            Type        = def.Type2;
            Flags       = image.Flags;
            UpdateFormat(image.Format);
        }
    }
Beispiel #3
0
 public XboxBitmap(BitmapTextureInteropDefinition definition, Bitmap.Image image) : base(definition, image)
 {
     UpdateFormat(image.Format);
     MultipleOfBlockDimension = Width % BlockDimension == 0 && Height % BlockDimension == 0;
     NotExact = Width != VirtualWidth || Height != VirtualHeight;
     InTile   = Width <= MinimalBitmapSize / 2 && Height <= MinimalBitmapSize / 2;
     Offset   = 0;
 }
Beispiel #4
0
        private static List <XboxBitmap> ParseImages(XboxBitmap xboxBitmap, Bitmap.Image image, byte[] imageData, int bitmapSize)
        {
            List <XboxBitmap> xboxBitmaps = new List <XboxBitmap>();

            switch (image.Type)
            {
            case BitmapType.Texture2D:
                xboxBitmap.Data = imageData;
                xboxBitmaps.Add(xboxBitmap);
                if ((image.XboxFlags.HasFlag(BitmapFlagsXbox.TiledTexture) && image.XboxFlags.HasFlag(BitmapFlagsXbox.Xbox360ByteOrder)))
                {
                    xboxBitmap.Data = BitmapDecoder.ConvertToLinearTexture(xboxBitmap.Data, xboxBitmap.VirtualWidth, xboxBitmap.VirtualHeight, xboxBitmap.Format);
                }
                break;

            case BitmapType.Texture3D:
            case BitmapType.Array:
                var count = xboxBitmap.Depth;
                var size  = bitmapSize / count;
                for (int i = 0; i < count; i++)
                {
                    byte[] data = new byte[size];
                    Array.Copy(imageData, i * size, data, 0, size);
                    XboxBitmap newXboxBitmap = xboxBitmap.ShallowCopy();

                    if ((image.XboxFlags.HasFlag(BitmapFlagsXbox.TiledTexture) && image.XboxFlags.HasFlag(BitmapFlagsXbox.Xbox360ByteOrder)))
                    {
                        data = BitmapDecoder.ConvertToLinearTexture(data, xboxBitmap.VirtualWidth, xboxBitmap.VirtualHeight, xboxBitmap.Format);
                    }

                    newXboxBitmap.Data = data;
                    xboxBitmaps.Add(newXboxBitmap);
                }
                break;

            case BitmapType.CubeMap:
                count = 6;
                size  = bitmapSize / count;
                for (int i = 0; i < count; i++)
                {
                    byte[] data = new byte[size];
                    Array.Copy(imageData, i * size, data, 0, size);
                    XboxBitmap newXboxBitmap = xboxBitmap.ShallowCopy();

                    if ((image.XboxFlags.HasFlag(BitmapFlagsXbox.TiledTexture) && image.XboxFlags.HasFlag(BitmapFlagsXbox.Xbox360ByteOrder)))
                    {
                        data = BitmapDecoder.ConvertToLinearTexture(data, xboxBitmap.VirtualWidth, xboxBitmap.VirtualHeight, xboxBitmap.Format);
                    }

                    newXboxBitmap.Data = data;
                    xboxBitmaps.Add(newXboxBitmap);
                }
                break;
            }
            return(xboxBitmaps);
        }
Beispiel #5
0
 public BaseBitmap(Bitmap.Image image)
 {
     Height      = image.Height;
     Width       = image.Width;
     Depth       = image.Depth;
     MipMapCount = image.MipmapCount;
     Type        = image.Type;
     Flags       = image.Flags;
     UpdateFormat(image.Format);
 }
Beispiel #6
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);
            }
        }
Beispiel #7
0
 public BaseBitmap(BitmapTextureInteropDefinition definition, Bitmap.Image image)
 {
     Height       = definition.Height;
     Width        = definition.Width;
     Depth        = definition.Depth;
     MipMapCount  = definition.MipmapCount != 0 ? definition.MipmapCount - 1 : 0;
     Type         = definition.BitmapType;
     Flags        = image.Flags;
     Curve        = image.Curve;
     MipMapOffset = image.MipMapOffset;
     UpdateFormat(image.Format);
 }
Beispiel #8
0
    public BaseBitmap(BitmapTextureInteropResource definition, Bitmap.Image image)
    {
        var def = definition.Texture.Definition;

        Height      = def.Height;
        Width       = def.Width;
        Depth       = def.Depth;
        MipMapCount = def.MipmapCount - 1;
        Type        = def.Type;
        Flags       = image.Flags;
        UpdateFormat(image.Format);
    }
 private void SetResourceDefinitionData(BaseBitmap bitmap, Bitmap.Image image, BitmapTextureInteropResource.BitmapDefinition definition)
 {
     definition.Data        = new TagData(bitmap.Data.Length, new CacheAddress(CacheAddressType.Resource, 0));
     definition.Width       = (short)bitmap.Width;
     definition.Height      = (short)bitmap.Height;
     definition.Depth       = (sbyte)bitmap.Depth;
     definition.MipmapCount = (sbyte)(bitmap.MipMapCount + 1);
     definition.Type        = bitmap.Type;
     definition.D3DFormat   = GetUnusedFormat(bitmap.Format);
     definition.Format      = bitmap.Format;
     definition.Curve       = image.Curve;
     definition.Flags       = bitmap.Flags;
 }
        private void SetTagData(BaseBitmap bitmap, Bitmap.Image image)
        {
            image.Width       = (short)bitmap.Width;
            image.Height      = (short)bitmap.Height;
            image.Depth       = (sbyte)bitmap.Depth;
            image.Format      = bitmap.Format;
            image.Type        = bitmap.Type;
            image.MipmapCount = (sbyte)bitmap.MipMapCount;
            image.DataSize    = bitmap.Data.Length;
            image.XboxFlags   = BitmapFlagsXbox.None;
            image.Flags       = bitmap.Flags;

            if (image.Format == BitmapFormat.Dxn)
            {
                image.Flags |= BitmapFlags.Unknown3;
            }
        }
Beispiel #11
0
        public static Bitmap.Image CreateBitmapImageFromResourceDefinition(BitmapTextureInteropDefinition definition)
        {
            var result = new Bitmap.Image()
            {
                Signature   = "mtib",
                Width       = definition.Width,
                Height      = definition.Height,
                Depth       = (sbyte)definition.Depth,
                Format      = definition.Format,
                Type        = definition.BitmapType,
                MipmapCount = (sbyte)(definition.MipmapCount != 0 ? definition.MipmapCount - 1 : 0),
                Flags       = definition.Flags,
                Curve       = definition.Curve
            };

            return(result);
        }
Beispiel #12
0
 public static int GetXboxImageSize(Bitmap.Image image)
 {
     return(GetXboxImageSize(new XboxBitmap(image)));
 }
Beispiel #13
0
        public DDSHeader(Bitmap.Image image)
        {
            var mipMapCount = image.MipmapCount != 0 ? (1 + image.MipmapCount) : 0;

            CreateHeaderFromType(image.Height, image.Width, image.Depth, mipMapCount, image.Format, image.Type, image.Flags);
        }
Beispiel #14
0
        public static RealArgbColor DecodeBitmapPixelXbox(byte[] bitmapData, Bitmap.Image image, D3DTexture9 pTexture, int layerIndex, int mipmapIndex)
        {
            RealArgbColor result = new RealArgbColor(1, 0, 0, 0);

            if (image.Type != BitmapType.Texture3D && (
                    (image.Type == BitmapType.Texture2D && layerIndex == 1) ||
                    (image.Type == BitmapType.CubeMap && layerIndex >= 0 && layerIndex < 6) ||
                    (image.Type == BitmapType.Array && layerIndex >= 0 && layerIndex < image.Depth)) &&
                (pTexture.GetBaseOffset() > 0 || pTexture.GetMipOffset() > 0))
            {
                uint blockWidth  = 0;
                uint blockHeight = 0;
                int  dataOffset  = 0;
                int  layerOffset = 0;

                // verify the mipmap level index
                var minMipLevel = pTexture.GetMinMipLevel();
                var maxMipLevel = pTexture.GetMaxMipLevel();

                // if mipmapIndex is too low
                if (mipmapIndex < minMipLevel)
                {
                    mipmapIndex = minMipLevel;
                }
                // if mipmapIndex is too high
                if (mipmapIndex > maxMipLevel)
                {
                    mipmapIndex = maxMipLevel;
                }

                var currentHeight = image.Height >> mipmapIndex;
                var currentWidth  = image.Width >> mipmapIndex;

                if (currentWidth < 1)
                {
                    currentWidth = 1;
                }

                if (currentHeight < 1)
                {
                    currentHeight = 1;
                }


                //XGGetTextureDesc
                XboxGraphics.XGTEXTURE_DESC textureDesc = new XboxGraphics.XGTEXTURE_DESC();


                XboxGraphics.XGGetBlockDimensions(XboxGraphics.XGGetGpuFormat(textureDesc.D3DFormat), out blockWidth, out blockHeight);

                layerOffset = 0; // Unknown XG function


                if (mipmapIndex > 0 && pTexture.GetMipOffset() > 0)
                {
                    dataOffset = pTexture.GetMipOffset() + layerOffset;
                }
                else
                {
                    dataOffset = pTexture.GetBaseOffset() + layerOffset;
                }

                for (int h = 0; h < currentHeight; h++)
                {
                    for (int w = 0; w < currentWidth; w++)
                    {
                    }
                }
            }


            return(result);
        }
Beispiel #15
0
 public static void FixBitmapFlags(Bitmap.Image image)
 {
     image.Flags &= ~BitmapFlags.Compressed;
 }