Beispiel #1
0
        public bool CopyAndTile(byte[] data, uint texSize, TerrainTex terrainTex)
        {
            var baseTexture = terrainTex.BaseTexture;

            if (baseTexture != null)
            {
                ImgTex.CopyCSI(data, texSize, texSize, baseTexture, terrainTex.TexTiling);
                return(true);
            }

            if (terrainTex.TexGID != 0) // stru_841760
            {
                var qdid = new QualifiedDataID(11, terrainTex.TexGID);

                var surfaceTexture = DBObj.GetSurfaceTexture(terrainTex.TexGID);
                terrainTex.BaseTexture = new ImgTex(surfaceTexture);
            }
            baseTexture = terrainTex.BaseTexture;

            if (baseTexture != null)
            {
                ImgTex.CopyCSI(data, texSize, texSize, baseTexture, terrainTex.TexTiling);
                return(true);
            }
            else
            {
                ImgTex.CopyCSI(data, texSize, texSize, null, 1);
                return(false);
            }
        }
Beispiel #2
0
        public static ImgTex AllocateTempBuffer(uint _width, uint _height, SurfacePixelFormat _image_type)
        {
            var tempBuffer = new ImgTex();  // 0x88 / 136

            tempBuffer.ImageData = new RenderSurface();
            tempBuffer.ImageData.Create(_width, _height, _image_type, true);
            CustomTextureTable.Add(tempBuffer);
            return(tempBuffer);
        }
Beispiel #3
0
        public static void TileCSI(byte[] data, uint dest_height, uint dest_width, ImgTex csi_tex, uint tiling)
        {
            var src_data = csi_tex.ImageData.Data;

            for (var i = 0; i < tiling * 2; i++)
            {
                Array.Copy(src_data, 0, data, src_data.Length * i, src_data.Length);
            }
        }
Beispiel #4
0
        public static ImgTex CreateLScapeTexture(byte[] rawData, uint i_width, uint i_height)
        {
            var texture = new ImgTex();     // 0x88 / 136

            CurrentTextureScale = ImageScaleType.Full;
            if (!texture.LoadCSI(rawData, i_width, i_height))
            {
                return(null);
            }

            CustomTextureTable.Add(texture);
            return(texture);
        }
Beispiel #5
0
 public static void CopyCSI(byte[] data, uint height, uint width, ImgTex csi_tex, uint tiling)
 {
     if (csi_tex != null)
     {
         TileCSI(data, height, width, csi_tex, tiling);
     }
     else if (width * height != 0)
     {
         //memset32(data, 65280, width * height);    // FF00
         data = new byte[width * height * 4];
         for (var i = 0; i < width * height * 4; i += 4)
         {
             data[i] = 0xFF;
         }
     }
 }
Beispiel #6
0
        public bool UseTextureMap(ImgTex texture, SurfaceHandler sh)
        {
            if (sh != Handler || texture == null)
            {
                return(false);
            }

            Type     = 2;
            Base1Map = texture;
            // vfptr->AddRef(texture)
            if (OrigTextureID == 0) // stru_845060
            {
                OrigTextureID = Base1Map.ID;
            }

            //Base1Pal = null;

            return(true);
        }
Beispiel #7
0
        public static bool Merge(byte[] data, uint texSize, ImgTex texture, LandDefs.Rotation rot, TerrainTex terrainTex)
        {
            if (texture == null)
            {
                return(false);
            }

            var baseTexture = terrainTex.BaseTexture;

            if (baseTexture != null)
            {
                ImgTex.MergeTexture(data, texSize, texSize, baseTexture, terrainTex.TexTiling, texture, rot);
                return(true);
            }
            else if (terrainTex.InitEnd())
            {
                ImgTex.MergeTexture(data, texSize, texSize, terrainTex.BaseTexture, terrainTex.TexTiling, texture, rot);
                return(true);
            }
            return(false);
        }
Beispiel #8
0
 public bool CreateD3DTexture(byte[] data, uint width, ImgTex texture)
 {
     return(true);
 }
Beispiel #9
0
 public bool Load(byte[] data, uint width, ImgTex texture)
 {
     // get pixel format and width/height of this and texture
     // if they are all equal, call CreateD3DTexture()
     return(false);
 }
Beispiel #10
0
        public static void MergeTexture(byte[] data, uint dest_height, uint dest_width, ImgTex csi_merge_tex, uint tiling, ImgTex alphaMap, LandDefs.Rotation rot)
        {
            var imageData = csi_merge_tex.ImageData;

            var src_height = imageData != null ? imageData.Height : 0;
            var src_width  = imageData != null ? imageData.Width : 0;

            var alphaData    = alphaMap.ImageData;
            var alpha_width  = alphaData != null ? alphaData.Width : 0;
            var alpha_height = alphaData != null ? alphaData.Height : 0;

            var alpha_scale = (float)dest_width / alpha_width;

            var pixelIdx = 0;
            var stepX    = 0;
            var stepY    = 0;

            switch (rot)
            {
            case LandDefs.Rotation.Rot0:
                pixelIdx = 0;
                stepX    = 1;
                stepY    = src_width;
                break;

            case LandDefs.Rotation.Rot90:
                pixelIdx = src_width - 1;
                stepX    = src_width;
                stepY    = -1;
                break;

            case LandDefs.Rotation.Rot180:
                pixelIdx = src_width * src_height - 1;
                stepX    = -1;
                stepY    = -src_width;
                break;

            case LandDefs.Rotation.Rot270:
                pixelIdx = src_width * (src_height - 1);
                stepX    = -src_width;
                stepY    = -1;
                break;
            }

            // alphaStep handles upscaling / downscaling
            var alphaStep = 1.0f / alpha_scale;

            // copy csi_merge_tex into dest buffer (data)
            Array.Copy(imageData.Data, data, imageData.Data.Length);

            // start walking the alpha map
            for (var _alphaY = 0.0f; _alphaY < alpha_height; _alphaY += alphaStep)
            {
                var alphaY = (int)Math.Round(_alphaY);

                for (var _alphaX = 0.0f; _alphaX < alpha_width; _alphaX += alphaStep)
                {
                    // TODO: handle rotation
                    var alphaX = (int)Math.Round(_alphaX);

                    var idx = (alphaY * alpha_width + alphaX) * 4;
                    var a   = alphaData.Data[idx];
                    data[idx] = a;
                }
            }
        }