public static int GetMaxPixls(N64Graphics.N64Codec texFormat) { switch (texFormat) { case N64Graphics.N64Codec.CI4: return(64 * 64); case N64Graphics.N64Codec.CI8: return(32 * 64); case N64Graphics.N64Codec.I4: return(128 * 64); case N64Graphics.N64Codec.I8: return(64 * 64); case N64Graphics.N64Codec.IA4: return(128 * 64); case N64Graphics.N64Codec.IA8: return(64 * 64); case N64Graphics.N64Codec.IA16: return(32 * 64); case N64Graphics.N64Codec.RGBA16: return(32 * 64); case N64Graphics.N64Codec.RGBA32: return(32 * 32); default: return(32 * 32); } }
public TextureLoadedInfos(string name, N64Graphics.N64Codec textureFormat, int textureSegAddress, int texturePaletteSegAddress, int textureRomAddress, int texturePaletteRomAddress, Size textureSize, bool isReadOnly) { Name = name; TextureFormat = textureFormat; TextureSegAddress = textureSegAddress; TexturePaletteSegAddress = texturePaletteSegAddress; TextureRomAddress = textureRomAddress; TexturePaletteRomAddress = texturePaletteRomAddress; TextureSize = textureSize; IsReadOnly = isReadOnly; }
private static void GetTextureImage(Stream s, int pos, Material mat, N64Graphics.N64Codec texFormat, Size curTexSize, byte[] curTexPalette) { // Create Image & Graphics mat.Image = new Bitmap(curTexSize.Width, curTexSize.Height); var g = Graphics.FromImage(mat.Image); // Get Texture Data var bytes = new byte[(N64Graphics.N64Graphics.PixelsToBytes(texFormat, curTexSize.Width * curTexSize.Height))]; s.Position = pos; s.Read(bytes, 0, bytes.Length); try { // Decode Texture N64Graphics.N64Graphics.RenderTexture(g, bytes.ToArray(), curTexPalette, 0, curTexSize.Width, curTexSize.Height, 1, texFormat, N64Graphics.N64IMode.AlphaCopyIntensity); } catch (Exception) { } }
public static void PrepaireImage(ref Bitmap bmp, RotateFlipType rotateFlipTexture, N64Graphics.N64Codec texFormat, bool fitImageSize) { if (fitImageSize) { int maxPixels = GetMaxPixls(texFormat); // Resize Texture if (bmp.Height * bmp.Width > maxPixels) { int curPixels = bmp.Height * bmp.Width; float verhälltnis = Conversions.ToSingle(Math.Sqrt(curPixels / (double)maxPixels)); float newHeight = bmp.Height / verhälltnis; float newWidth = bmp.Width / verhälltnis; int nhlog = Conversions.ToInteger(Math.Truncate(Math.Log(newHeight, 2))); int nwlog = Conversions.ToInteger(Math.Truncate(Math.Log(newWidth, 2))); newHeight = Conversions.ToSingle(Math.Pow(2, nhlog)); newWidth = Conversions.ToSingle(Math.Pow(2, nwlog)); bmp = (Bitmap)ResizeImage(bmp, new Size(Conversions.ToInteger(newHeight), Conversions.ToInteger(newWidth))); } } RotateFlipImage(bmp, rotateFlipTexture); }
private static void ProcessTexture(Object3D obj, RomManager rommgr, byte?AreaID, DisplayList dl, N64Graphics.N64Codec texFormat, Dictionary <int, Material> knownTextures, ref Material curTexture, int curTexSegAddr, Size curTexSize, int curTexWrapT, int curTexWrapS, System.Numerics.Vector2 curTexScale, byte[] curTexPalette, int curTexPaletteSegAddr, Color?curColor, ref TextureLoadedInfos curTexLoadedInfos) { if (curTexSegAddr == 0 && curTexScale.X == 0 && curTexScale.Y == 0) { return; } if (knownTextures.ContainsKey(curTexSegAddr)) { curTexture = knownTextures[curTexSegAddr]; } else { try { var mat = new Material(); mat.Wrap = new System.Numerics.Vector2(curTexWrapT, curTexWrapS); mat.Scale = curTexScale; mat.Color = curColor; var seg = GetSegBank(rommgr, curTexSegAddr, AreaID); if (seg is null) { return; } GetTextureImage(seg.Data, seg.BankOffsetFromSegAddr(curTexSegAddr), mat, texFormat, curTexSize, curTexPalette); if (mat.Image is object) { mat.Tag = new TextureLoadedInfos(Microsoft.VisualBasic.Conversion.Hex(curTexSegAddr), texFormat, curTexSegAddr, curTexPaletteSegAddr, seg.SegToRomAddr(curTexSegAddr), seg.SegToRomAddr(curTexPaletteSegAddr), mat.Image.Size); } curTexture = mat; knownTextures.Add(curTexSegAddr, mat); if (!obj.Materials.ContainsKey(Conversions.ToString(curTexSegAddr))) { obj.Materials.Add(Conversions.ToString(curTexSegAddr), mat); } } catch (Exception /*ex*/) { //Interaction.MsgBox(ex.Message); } } }
public TextureLoadedInfos(string name, N64Graphics.N64Codec textureFormat, int textureSegAddress, int texturePaletteSegAddress, int textureRomAddress, int texturePaletteRomAddress, Size textureSize) : this(name, textureFormat, textureSegAddress, texturePaletteSegAddress, textureRomAddress, texturePaletteRomAddress, textureSize, false) { }