Example #1
0
        private ImgInfo ReadImageT3(Stream _stream, ref ImgInfo _Info)
        {
            _Info.ChunkList = new List <Object>();
            Int32 ChunkCount = ReadInt32(_stream);

            _Info.Info.ChunkCount = ChunkCount;

            if (ChunkCount - 1 >= 0)
            {
                for (int ChkIdx = 0; ChkIdx < ChunkCount; ++ChkIdx)
                {
                    ChunkInfoT3 nImg = ReadStreamStruct <ChunkInfoT3>(_stream);
                    int         _Row = nImg.Row;
                    int         _Pos = nImg.Pos;
                    _Info.ChunkList.Add(nImg);
                }
            }
            return(_Info);
        }
Example #2
0
        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);
        }