Esempio n. 1
0
        /// <summary>
        /// 
        /// </summary>
        public void ReplaceImage( int sglImageIndex, int sglFrameIndex, byte[] byteTgaBuffer, int x, int y )
        {
#if !DEMO
            TargaHeader targaHeader = TargaHeader.GetTargaHeader( byteTgaBuffer );

            byte[] dataBuffer = new byte[targaHeader.Width * targaHeader.Height * 2];

            for ( int iIndex = TargaHeader.TargaHeaderSize, iDataBufferIndex = 0; iIndex < targaHeader.Width * targaHeader.Height * 4 + TargaHeader.TargaHeaderSize; iIndex += 4, iDataBufferIndex += 2 )
            {
                dataBuffer[iDataBufferIndex] = (byte)( ( ( byteTgaBuffer[iIndex] & 0xF0 ) >> 4 ) | ( byteTgaBuffer[iIndex + 1] & 0xF0 ) );
                dataBuffer[iDataBufferIndex + 1] = (byte)( ( ( byteTgaBuffer[iIndex + 2] & 0xF0 ) >> 4 ) | ( byteTgaBuffer[iIndex + 3] & 0xF0 ) );
            }

            //FileStream fileStreamx = File.Open( "f:\\xxxxx1.bin", FileMode.Create );
            //fileStreamx.Write( dataBuffer, 0, dataBuffer.Length );
            //fileStreamx.Close();

            SGLImage.BlockInfo refBlockInfo = new SGLImage.BlockInfo();
            refBlockInfo.Width = targaHeader.Width;
            refBlockInfo.Height = targaHeader.Height;
            refBlockInfo.BlocksX = ( refBlockInfo.Width / 256 + 1 );
            refBlockInfo.BlocksY = ( refBlockInfo.Height / 256 + 1 );
            refBlockInfo.BlockSizeArray = new SGLImage.BlockInfo.BlockSize[refBlockInfo.BlocksX, refBlockInfo.BlocksY];

            //MessageBox.Show( string.Format( "{0}:{1}", refBlockInfo.Width, refBlockInfo.Height ) );
            int byteRLE16Size = 0;
            for ( int iIndexY = 0; iIndexY < refBlockInfo.BlocksY; iIndexY++ )
            {
                for ( int iIndexX = 0; iIndexX < refBlockInfo.BlocksX; iIndexX++ )
                {
                    refBlockInfo.BlockSizeArray[iIndexX, iIndexY] = new SGLImage.BlockInfo.BlockSize();

                    if ( iIndexX == ( refBlockInfo.BlocksX - 1 ) )
                        refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockWidth = ( ( refBlockInfo.Width - 1 ) % 256 );
                    else
                        refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockWidth = 255;

                    if ( iIndexY == ( refBlockInfo.BlocksY - 1 ) )
                        refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockHeight = ( ( refBlockInfo.Height - 1 ) % 256 );
                    else
                        refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockHeight = 255;

                    byte[] byteBuffer = new byte[( refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockHeight + 1 ) * ( refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockWidth + 1 ) * 2];

                    for ( int iHeight = 0; iHeight < refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockHeight + 1; iHeight++ )
                    {
                        int byteBufferIndex = ( iHeight * ( refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockWidth + 1 ) * 2 );

                        for ( int iWidth = 0; iWidth < ( refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockWidth + 1 ); iWidth++ )
                        {
                            byteBuffer[byteBufferIndex + ( iWidth * 2 )] = dataBuffer[( ( ( iIndexY * 255 ) + iHeight ) * refBlockInfo.Width * 2 ) + ( iIndexX * 255 * 2 ) + ( iWidth * 2 )];
                            byteBuffer[byteBufferIndex + ( iWidth * 2 ) + 1] = dataBuffer[( ( ( iIndexY * 255 ) + iHeight ) * refBlockInfo.Width * 2 ) + ( iIndexX * 255 * 2 ) + ( iWidth * 2 ) + 1];
                        }
                    }

                    //FileStream fileStream = File.Open( string.Format( "f:\\[{0}][{1}]-x1.bin", refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockWidth, refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockHeight ), FileMode.Create );
                    //fileStream.Write( byteBuffer, 0, byteBuffer.Length );
                    //fileStream.Close();

                    byte[] byteBufferRLE16 = Editor.SGLImage.SGLEncodeRLE16( byteBuffer );
                    if ( byteBufferRLE16 == null )
                        return;
                    else
                        refBlockInfo.BlockSizeArray[iIndexX, iIndexY].byteRLE16 = byteBufferRLE16;

                    byteRLE16Size += byteBufferRLE16.Length;

                    //fileStream = File.Open( string.Format( "f:\\[{0}][{1}]-o1.bin", refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockWidth, refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockHeight ), FileMode.Create );
                    //fileStream.Write( byteBufferRLE16, 0, byteBufferRLE16.Length );
                    //fileStream.Close();
                }
            }

            //byte[] byteRLE16 = new byte[byteRLE16Size];
            //if ( byteRLE16 == null )
            //    return;

            //int byteRLE16SizeIndex = 0;
            //for ( int iIndexY = 0; iIndexY < refBlockInfo.BlocksY; iIndexY++ )
            //{
            //    for ( int iIndexX = 0; iIndexX < refBlockInfo.BlocksX; iIndexX++ )
            //    {
            //        Buffer.BlockCopy( refBlockInfo.BlockSizeArray[iIndexX, iIndexY].byteRLE16, 0, byteRLE16, byteRLE16SizeIndex, refBlockInfo.BlockSizeArray[iIndexX, iIndexY].byteRLE16.Length );

            //        byteRLE16SizeIndex += refBlockInfo.BlockSizeArray[iIndexX, iIndexY].byteRLE16.Length;
            //    }
            //}

            //MessageBox.Show( "fff" );

            byte[] byteUSHORT = new byte[sizeof( ushort )];
            byte[] byteUINT = new byte[sizeof( uint )];

            SGLFileStream.Seek( 0, SeekOrigin.End );

            uint iPosition = (uint)SGLFileStream.Position;


            SGLImage sglImage = SGLImage[sglImageIndex];

            if ( sglImage.SGLFrames.Length == 0 )
                return;

            SGLFileStream.WriteByte( sglImage.Unknown1 );
            SGLFileStream.WriteByte( sglImage.Format );

            byteUSHORT[0] = (byte)( sglImage.Frames & 0xFF );
            byteUSHORT[1] = (byte)( ( sglImage.Frames & 0xFF00 ) >> 8 );
            SGLFileStream.Write( byteUSHORT, 0, byteUSHORT.Length );

            byteUSHORT[0] = (byte)( sglImage.Unknown2 & 0xFF );
            byteUSHORT[1] = (byte)( ( sglImage.Unknown2 & 0xFF00 ) >> 8 );
            SGLFileStream.Write( byteUSHORT, 0, byteUSHORT.Length );

            for ( int iIndex = 0; iIndex < sglImage.SGLFrames.Length; iIndex++ )
            {
                if ( sglFrameIndex == iIndex )
                {
                    SGLFrame sglFrame = new SGLFrame();

                    sglFrame.FrameWidth = targaHeader.Width;
                    sglFrame.FrameHeight = targaHeader.Height;

                    sglFrame.CenterX = (ushort)x;
                    sglFrame.CenterY = (ushort)y;

                    sglFrame.BlocksX = (byte)refBlockInfo.BlocksX;
                    sglFrame.BlocksY = (byte)refBlockInfo.BlocksY;

                    switch ( sglImage.Format )
                    {
                        case 0x02:

                            break;
                        case 0x82:

                            break;
                        case 0x88:

                            break;
                        case 0x06:

                            break;
                        case 0x18:
                        case 0x28:

                            break;
                        case 0x11:
                        case 0x12:
                        case 0x22:
                            sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray = new SGLFrameFormat11Or12Or22.SGLFrameData[refBlockInfo.BlocksX * refBlockInfo.BlocksY];

                            for ( int iIndexY = 0; iIndexY < refBlockInfo.BlocksY; iIndexY++ )
                            {
                                for ( int iIndexX = 0; iIndexX < refBlockInfo.BlocksX; iIndexX++ )
                                {
                                    sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray[iIndexY * refBlockInfo.BlocksX + iIndexX].BlockWidth = (byte)refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockWidth;
                                    sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray[iIndexY * refBlockInfo.BlocksX + iIndexX].BlockHeight = (byte)refBlockInfo.BlockSizeArray[iIndexX, iIndexY].BlockHeight;

                                    sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray[iIndexY * refBlockInfo.BlocksX + iIndexX].BlockSize = (uint)refBlockInfo.BlockSizeArray[iIndexX, iIndexY].byteRLE16.Length;
                                    sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray[iIndexY * refBlockInfo.BlocksX + iIndexX].BlockData = refBlockInfo.BlockSizeArray[iIndexX, iIndexY].byteRLE16;
                                }
                            }

                            break;
                        case 0x62:

                            break;
                        default:

                            break;
                    }

                    sglImage.SGLFrames[iIndex] = sglFrame;
                    SaveFrame( SGLFileStream, sglFrame, sglImage );
                }
                else
                {
                    SGLFrame sglFrame = sglImage.SGLFrames[iIndex];

                    SaveFrame( SGLFileStream, sglFrame, sglImage );
                }
            }

            SGLFileStream.Seek( SGLOffsetInfo.FilePosition[sglImageIndex], SeekOrigin.Begin );

            byteUINT[0] = (byte)( iPosition & 0xFF );
            byteUINT[1] = (byte)( ( iPosition & 0xFF00 ) >> 8 );
            byteUINT[2] = (byte)( ( iPosition & 0xFF0000 ) >> 16 );
            byteUINT[3] = (byte)( ( iPosition & 0xFF000000 ) >> 24 );

            SGLOffsetInfo.OffserTable[sglImageIndex] = iPosition;

            SGLFileStream.Write( byteUINT, 0, byteUINT.Length );

            SGLFileStream.Flush();
#endif
        }
Esempio n. 2
0
        public void SaveFrame( FileStream fileStream, SGLFrame sglFrame, SGLImage sglImage )
        {
            byte[] byteUINT = new byte[sizeof( uint )];
            byte[] byteUSHORT = new byte[sizeof( ushort )];

            sglFrame.FilePosition = fileStream.Position;

            byteUSHORT[0] = (byte)( sglFrame.FrameWidth & 0xFF );
            byteUSHORT[1] = (byte)( ( sglFrame.FrameWidth & 0xFF00 ) >> 8 );
            SGLFileStream.Write( byteUSHORT, 0, byteUSHORT.Length );

            byteUSHORT[0] = (byte)( sglFrame.FrameHeight & 0xFF );
            byteUSHORT[1] = (byte)( ( sglFrame.FrameHeight & 0xFF00 ) >> 8 );
            SGLFileStream.Write( byteUSHORT, 0, byteUSHORT.Length );

            byteUSHORT[0] = (byte)( sglFrame.CenterX & 0xFF );
            byteUSHORT[1] = (byte)( ( sglFrame.CenterX & 0xFF00 ) >> 8 );
            SGLFileStream.Write( byteUSHORT, 0, byteUSHORT.Length );

            byteUSHORT[0] = (byte)( sglFrame.CenterY & 0xFF );
            byteUSHORT[1] = (byte)( ( sglFrame.CenterY & 0xFF00 ) >> 8 );
            SGLFileStream.Write( byteUSHORT, 0, byteUSHORT.Length );

            SGLFileStream.WriteByte( sglFrame.BlocksX );
            SGLFileStream.WriteByte( sglFrame.BlocksY );

            switch ( sglImage.Format )
            {
                case 0x02:

                    break;
                case 0x82:

                    break;
                case 0x88:

                    break;
                case 0x06:

                    break;
                case 0x18:
                case 0x28:

                    break;
                case 0x11:
                case 0x12:
                case 0x22:
                    sglFrame.SGLFrameFormat11Or12Or22.FileStream = fileStream;
                    sglFrame.SGLFrameFormat11Or12Or22.SGLFrame = sglFrame;
                    sglFrame.SGLFrameFormat11Or12Or22.FilePosition = fileStream.Position;

                    for ( int i = 0; i < sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray.Length; i++ )
                    {
                        SGLFileStream.WriteByte( sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray[i].BlockWidth );
                        SGLFileStream.WriteByte( sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray[i].BlockHeight );

                        byteUINT[0] = (byte)( sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray[i].BlockSize & 0xFF );
                        byteUINT[1] = (byte)( ( sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray[i].BlockSize & 0xFF00 ) >> 8 );
                        byteUINT[2] = (byte)( ( sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray[i].BlockSize & 0xFF0000 ) >> 16 );
                        byteUINT[3] = (byte)( ( sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray[i].BlockSize & 0xFF000000 ) >> 24 );
                        SGLFileStream.Write( byteUINT, 0, byteUINT.Length );

                        SGLFileStream.Write( sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray[i].BlockData, 0, sglFrame.SGLFrameFormat11Or12Or22.SGLFrameDataArray[i].BlockData.Length );
                    }

                    break;
                case 0x62:

                    break;
                default:

                    break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sglFrame"></param>
        /// <returns></returns>
        public static SGLFrameFormat11Or12Or22 GetSGLFrameFormat11Or12Or22( FileStream fileStream, SGLFrame sglFrame )
        {
            SGLFrameFormat11Or12Or22 sglFrameFormat11Or12Or22 = new SGLFrameFormat11Or12Or22();

            sglFrameFormat11Or12Or22.FileStream = fileStream;
            sglFrameFormat11Or12Or22.SGLFrame = sglFrame;
            sglFrameFormat11Or12Or22.FilePosition = fileStream.Position;

            byte[] byteUINT = new byte[sizeof( uint )];

            for ( int iBlocksY = 0; iBlocksY < sglFrame.BlocksY; iBlocksY++ )
            {
                for ( int iBlocksX = 0; iBlocksX < sglFrame.BlocksX; iBlocksX++ )
                {
                    fileStream.Seek( 2, SeekOrigin.Current );

                    fileStream.Read( byteUINT, 0, byteUINT.Length );
                    uint iBlockSize = (uint)( byteUINT[0] | ( byteUINT[1] << 8 ) | ( byteUINT[2] << 16 ) | ( byteUINT[3] << 24 ) );

                    fileStream.Seek( iBlockSize, SeekOrigin.Current );
                }
            }

            return sglFrameFormat11Or12Or22;
        }
Esempio n. 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sglFrame"></param>
        /// <returns></returns>
        public static SGLFrameFormat62 GetSGLFrameFormat62( FileStream fileStream, SGLFrame sglFrame )
        {
            SGLFrameFormat62 sglFrameFormat62 = new SGLFrameFormat62();

            int iBlocksSize = sglFrame.BlocksX * sglFrame.BlocksY;

            sglFrameFormat62.SGLFrameFormat62Data = new SGLFrameFormat62Data[iBlocksSize];
            for ( int iIndex = 0; iIndex < iBlocksSize; iIndex++ )
            {
                sglFrameFormat62.SGLFrameFormat62Data[iIndex] = new SGLFrameFormat62Data();

                sglFrameFormat62.SGLFrameFormat62Data[iIndex].BlockWidth = (byte)fileStream.ReadByte();
                sglFrameFormat62.SGLFrameFormat62Data[iIndex].BlockHeight = (byte)fileStream.ReadByte();

                byte[] byteUINT = new byte[sizeof( uint )];

                fileStream.Read( byteUINT, 0, byteUINT.Length );
                sglFrameFormat62.SGLFrameFormat62Data[iIndex].BlockSize = (uint)( byteUINT[0] | ( byteUINT[1] << 8 ) | ( byteUINT[2] << 16 ) | ( byteUINT[3] << 24 ) );

                sglFrameFormat62.SGLFrameFormat62Data[iIndex].BlockData = new byte[sglFrameFormat62.SGLFrameFormat62Data[iIndex].BlockSize];
                fileStream.Read( sglFrameFormat62.SGLFrameFormat62Data[iIndex].BlockData, 0, sglFrameFormat62.SGLFrameFormat62Data[iIndex].BlockData.Length );

                fileStream.Read( byteUINT, 0, byteUINT.Length );
                sglFrameFormat62.SGLFrameFormat62Data[iIndex].AlphaSize = (uint)( byteUINT[0] | ( byteUINT[1] << 8 ) | ( byteUINT[2] << 16 ) | ( byteUINT[3] << 24 ) );

                sglFrameFormat62.SGLFrameFormat62Data[iIndex].AlphaData = new byte[sglFrameFormat62.SGLFrameFormat62Data[iIndex].AlphaSize];
                fileStream.Read( sglFrameFormat62.SGLFrameFormat62Data[iIndex].AlphaData, 0, sglFrameFormat62.SGLFrameFormat62Data[iIndex].AlphaData.Length );
            }

            return sglFrameFormat62;
        }
Esempio n. 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sglFrame"></param>
        /// <returns></returns>
        public static SGLFrameFormat02 GetSGLFrameFormat02( FileStream fileStream, SGLFrame sglFrame )
        {
            SGLFrameFormat02 sglFrameFormat02 = new SGLFrameFormat02();

            int iBlocksSize = sglFrame.BlocksX * sglFrame.BlocksY;

            sglFrameFormat02.SGLFrameFormat02Data = new SGLFrameFormat02Data[iBlocksSize];
            for ( int iIndex = 0; iIndex < iBlocksSize; iIndex++ )
            {
                sglFrameFormat02.SGLFrameFormat02Data[iIndex] = new SGLFrameFormat02Data();
                sglFrameFormat02.SGLFrameFormat02Data[iIndex].BlockWidth = (byte)fileStream.ReadByte();
                sglFrameFormat02.SGLFrameFormat02Data[iIndex].BlockHeight = (byte)fileStream.ReadByte();

                sglFrameFormat02.SGLFrameFormat02Data[iIndex].BlockData = new byte[sglFrameFormat02.SGLFrameFormat02Data[iIndex].BlockWidth * sglFrameFormat02.SGLFrameFormat02Data[iIndex].BlockHeight * 2];
                fileStream.Read( sglFrameFormat02.SGLFrameFormat02Data[iIndex].BlockData, 0, sglFrameFormat02.SGLFrameFormat02Data[iIndex].BlockData.Length );
            }

            return sglFrameFormat02;
        }
Esempio n. 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sglFrame"></param>
        /// <returns></returns>
        public static SGLFrameFormat18Or28 GetSGLFrameFormat18Or28( FileStream fileStream, SGLFrame sglFrame )
        {
            SGLFrameFormat18Or28 sglFrameFormat18Or28 = new SGLFrameFormat18Or28();

            byte[] byteUINT = new byte[sizeof( uint )];

            fileStream.Read( byteUINT, 0, byteUINT.Length );
            sglFrameFormat18Or28.FrameSize = (uint)( byteUINT[0] | ( byteUINT[1] << 8 ) | ( byteUINT[2] << 16 ) | ( byteUINT[3] << 24 ) );

            sglFrameFormat18Or28.FrameData = new byte[sglFrameFormat18Or28.FrameSize];
            fileStream.Read( sglFrameFormat18Or28.FrameData, 0, sglFrameFormat18Or28.FrameData.Length );

            return sglFrameFormat18Or28;
        }
Esempio n. 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sglFrame"></param>
        /// <returns></returns>
        public static SGLFrameFormat06 GetSGLFrameFormat06( FileStream fileStream, SGLFrame sglFrame )
        {
            SGLFrameFormat06 sglFrameFormat06 = new SGLFrameFormat06();

            byte[] byteUINT = new byte[sizeof( uint )];

            fileStream.Read( byteUINT, 0, byteUINT.Length );
            sglFrameFormat06.FrameSize = (uint)( byteUINT[0] | ( byteUINT[1] << 8 ) | ( byteUINT[2] << 16 ) | ( byteUINT[3] << 24 ) );

            sglFrameFormat06.FrameData = new byte[sglFrameFormat06.FrameSize];
            fileStream.Read( sglFrameFormat06.FrameData, 0, sglFrameFormat06.FrameData.Length );

            fileStream.Read( byteUINT, 0, byteUINT.Length );
            sglFrameFormat06.AlphaSize = (uint)( byteUINT[0] | ( byteUINT[1] << 8 ) | ( byteUINT[2] << 16 ) | ( byteUINT[3] << 24 ) );

            sglFrameFormat06.AlphaData = new byte[sglFrameFormat06.AlphaSize];
            fileStream.Read( sglFrameFormat06.AlphaData, 0, sglFrameFormat06.AlphaData.Length );

            return sglFrameFormat06;
        }
Esempio n. 8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sglFrame"></param>
        /// <returns></returns>
        public static SGLFrameFormat88 GetSGLFrameFormat88( FileStream fileStream, SGLFrame sglFrame )
        {
            SGLFrameFormat88 sglFrameFormat88 = new SGLFrameFormat88();

            sglFrameFormat88.FrameData = new byte[sglFrame.FrameWidth * sglFrame.FrameHeight * 2];
            fileStream.Read( sglFrameFormat88.FrameData, 0, sglFrameFormat88.FrameData.Length );

            return sglFrameFormat88;
        }
Esempio n. 9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sglFrame"></param>
        /// <returns></returns>
        public static SGLFrameFormat82 GetSGLFrameFormat82( FileStream fileStream, SGLFrame sglFrame )
        {
            SGLFrameFormat82 sglFrameFormat82 = new SGLFrameFormat82();

            sglFrameFormat82.FrameData = new byte[sglFrame.FrameWidth * sglFrame.FrameHeight * 2];
            fileStream.Read( sglFrameFormat82.FrameData, 0, sglFrameFormat82.FrameData.Length );

            sglFrameFormat82.AlphaData = new byte[sglFrame.FrameWidth * sglFrame.FrameHeight * 2];
            fileStream.Read( sglFrameFormat82.AlphaData, 0, sglFrameFormat82.AlphaData.Length );

            return sglFrameFormat82;
        }