private ImgInfo ReadImage(Stream _stream) { ImgInfo _Info = new ImgInfo(); _Info.Info = new ImgHeader(); _Info.ChunkList = new List <Object>(); if (DTXFile.Header.Version < 7) { _Info.Info._Short1 = ReadInt16(_stream); _Info.Info._Short2 = ReadInt16(_stream); _Info.Info._Short3 = ReadInt16(_stream); _Info.Info._Short4 = ReadInt16(_stream); } if (DTXFile.Header.Version == 7) { Int32 NameSize = ReadInt32(_stream); Byte[] Raw = new Byte[NameSize]; ReadBytes(_stream, (uint)NameSize, ref Raw); _Info.Name = ASCIIEncoding.ASCII.GetString(Raw); _Info.Info._Short1 = ReadInt16(_stream); _Info.Info._Short2 = ReadInt16(_stream); _Info.Info._Short3 = ReadInt16(_stream); _Info.Info._Short4 = ReadInt16(_stream); _Info.Info._SubStrSize = ReadInt32(_stream); for (int j = 0; j < _Info.Info._SubStrSize; ++j) { Int32 tNameSize = ReadInt32(_stream); Byte[] Raw2 = new Byte[tNameSize]; ReadBytes(_stream, (uint)tNameSize, ref Raw2); int A = ReadInt32(_stream); int B = ReadInt32(_stream); } _Info.Info._Short5 = ReadInt16(_stream); _Info.Info._Short6 = ReadInt16(_stream); _Info.Info._Short7 = ReadInt16(_stream); _Info.Info._Short8 = ReadInt16(_stream); } else if (DTXFile.Header.Version == 8) { Int32 NameSize = ReadInt32(_stream); Byte[] Raw = new Byte[NameSize]; ReadBytes(_stream, (uint)NameSize, ref Raw); _Info.Name = ASCIIEncoding.ASCII.GetString(Raw); _Info.Info._Short1 = ReadInt16(_stream); _Info.Info._Short2 = ReadInt16(_stream); _Info.Info._Short3 = ReadInt16(_stream); _Info.Info._Short4 = ReadInt16(_stream); _Info.Info._Short5 = ReadInt16(_stream); _Info.Info._Short6 = ReadInt16(_stream); _Info.Info.Float1 = ReadFloat(_stream); _Info.Info.Float2 = ReadFloat(_stream); _Info.Info._SubStrSize = ReadInt32(_stream); for (int j = 0; j < _Info.Info._SubStrSize; ++j) { Int32 tNameSize = ReadInt32(_stream); Byte[] Raw2 = new Byte[tNameSize]; ReadBytes(_stream, (uint)tNameSize, ref Raw2); int A = ReadInt32(_stream); int B = ReadInt32(_stream); int C = ReadInt32(_stream); float D = ReadFloat(_stream); float E = ReadFloat(_stream); } _Info.Info._Short13 = ReadInt16(_stream); _Info.Info._Short14 = ReadInt16(_stream); _Info.Info._Short15 = ReadInt16(_stream); _Info.Info._Short16 = ReadInt16(_stream); } _Info.Info._2D = ReadInt32(_stream); _Info.Info._After2D = ReadInt16(_stream); _Info.Info.Width = ReadInt32(_stream); _Info.Info.Height = ReadInt32(_stream); _Info.Info.ChunkCount = ReadInt32(_stream); _Info.Info.X2Size = ReadInt32(_stream); for (int ChkIdx = 0; ChkIdx < _Info.Info.ChunkCount; ++ChkIdx) { ChunkInfo nImg = new ChunkInfo(); Read <ChunkInfo>(_stream, ref nImg); _Info.ChunkList.Add(nImg); } return(_Info); }
private bool BuildImage() { MemoryStream ms = null; if (DTXFile.Header.ImgType != 3) { ms = new MemoryStream(DTXFile.DataStorage); } for (int imgidx = 0; imgidx < DTXFile.Header.ImgCount; ++imgidx) { ImgInfo _i = DTXFile.ImgLists[imgidx]; if (_i.Info.Width == 0 || _i.Info.Height == 0) { //!--Error _i.Img = new System.Drawing.Bitmap(1, 1, PixelFormat.Format24bppRgb); DTXFile.ImgLists[imgidx] = _i; continue; } if (DTXFile.Header.ImgType == 0) { _i.Img = BitmapExtensions.BitmapSourceFromArray(DTXFile.DataStorage, _i.Info.Width, _i.Info.Height, 16); } else { Byte[] ImgD = Enumerable.Repeat((byte)DTXFile.FuchsiaIdx, _i.Info.Width * _i.Info.Height * DTXFile.Header.ImgType).ToArray(); System.Drawing.Bitmap ImgP = new System.Drawing.Bitmap(_i.Info.Width, _i.Info.Height, PixelFormat.Format24bppRgb); for (int ChkIdx = 0; ChkIdx < _i.Info.ChunkCount; ++ChkIdx) { if (DTXFile.Header.ImgType != 3) { ChunkInfo nChk = (ChunkInfo)_i.ChunkList[ChkIdx]; int _Row = nChk.Row; int _Pos = nChk.Pos; Byte[] Raw = new Byte[nChk.ChunkSize]; ReadBytes(ms, (uint)nChk.ChunkSize, ref Raw); Raw.CopyTo(ImgD, _Row * _i.Info.Width + _Pos); } else { ChunkInfoT3 nChk = (ChunkInfoT3)_i.ChunkList[ChkIdx]; int _Row = nChk.Row; int _Pos = nChk.Pos; int Bidx = 0; for (int x = nChk.Pos; x < nChk.Pos + nChk.Pixel; ++x) { int _Y = _Row - _i.Info.GlobalY; int _X = x - _i.Info.GlobalX; Byte R = nChk.Raw.Array[Bidx++]; Byte G = nChk.Raw.Array[Bidx++]; Byte B = nChk.Raw.Array[Bidx++]; ImgP.SetPixel(_X, _Y, Color.FromArgb(R, G, B)); } //Trace.WriteLine(String.Format("{0}\t\t{1}\t\t{2}\t\t{3} ", nChk.Row, nChk.Pos, nChk.Pixel, nChk.Pos + nChk.Pixel)); } } if (DTXFile.Header.ImgType != 3) { Bitmap _bp = null; if (DTXFile.Palette != null) { _bp = BitmapExtensions.BitmapSourceFromArrayIndex(ImgD, _i.Info.Width, _i.Info.Height, DTXFile.Header.ImgType * 8, DTXFile.Palette); } else { _bp = BitmapExtensions.BitmapSourceFromArray(ImgD, _i.Info.Width, _i.Info.Height, DTXFile.Header.ImgType * 8); } Bitmap bm = new Bitmap(_bp); _i.Img = bm; } else { _i.Img = ImgP; } } DTXFile.ImgLists[imgidx] = _i; } return(true); }