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; } }
/// <summary> /// /// </summary> /// <param name="stringFileName"></param> /// <returns></returns> public bool OpenSGLFile( String stringFileName, ListView listViewSGLImage ) { FileName = stringFileName; SGLFileStream = File.Open( stringFileName, FileMode.Open, FileAccess.ReadWrite ); SGLHeader.ByteTitle = new byte[SGLHeader.TitleSize]; SGLFileStream.Read( SGLHeader.ByteTitle, 0, SGLHeader.TitleSize ); string strTitle = Encoding.ASCII.GetString( SGLHeader.ByteTitle ); if ( string.Equals( strTitle, SGLHeader.SGLTitle, StringComparison.CurrentCulture ) == false ) return false; byte[] byteUINT = new byte[sizeof( uint )]; SGLFileStream.Read( byteUINT, 0, byteUINT.Length ); SGLHeader.Comp = (uint)( byteUINT[0] | ( byteUINT[1] << 8 ) | ( byteUINT[2] << 16 ) | ( byteUINT[3] << 24 ) ); SGLFileStream.Read( byteUINT, 0, byteUINT.Length ); SGLHeader.Offset = (uint)( byteUINT[0] | ( byteUINT[1] << 8 ) | ( byteUINT[2] << 16 ) | ( byteUINT[3] << 24 ) ); SGLFileStream.Seek( SGLHeader.Offset, SeekOrigin.Begin ); SGLFileStream.Read( byteUINT, 0, byteUINT.Length ); SGLOffsetInfo.ImageCount = (uint)( byteUINT[0] | ( byteUINT[1] << 8 ) | ( byteUINT[2] << 16 ) | ( byteUINT[3] << 24 ) ); SGLOffsetInfo.OffserTable = new uint[SGLOffsetInfo.ImageCount]; SGLOffsetInfo.FilePosition = new long[SGLOffsetInfo.ImageCount]; long iOffserPosition = SGLFileStream.Position; byte[] byteBuffer = new byte[byteUINT.Length * SGLOffsetInfo.ImageCount]; SGLFileStream.Read( byteBuffer, 0, byteBuffer.Length ); for ( int iIndex = 0, iOffserTable = 0; iIndex < byteBuffer.Length; iOffserTable++, iOffserPosition += byteUINT.Length ) { SGLOffsetInfo.OffserTable[iOffserTable] = (uint)( byteBuffer[iIndex++] | ( byteBuffer[iIndex++] << 8 ) | ( byteBuffer[iIndex++] << 16 ) | ( byteBuffer[iIndex++] << 24 ) ); SGLOffsetInfo.FilePosition[iOffserTable] = iOffserPosition; } ListViewItemArray = new ListViewItem[SGLOffsetInfo.OffserTable.Length]; SGLImage = new SGLImage[SGLOffsetInfo.OffserTable.Length]; for ( int iIndex = 0; iIndex < SGLImage.Length; iIndex++ ) { SGLImage[iIndex] = new SGLImage(); if ( SGLOffsetInfo.OffserTable[iIndex] == 0 ) { { // NULL ListViewItemArray[iIndex] = new ListViewItem( iIndex.ToString(), 0 ); ListViewItemArray[iIndex].SubItems.Add( SGLImage[iIndex].Format.ToString() ); ListViewItemArray[iIndex].SubItems.Add( SGLImage[iIndex].Frames.ToString() ); ListViewItemArray[iIndex].SubItems.Add( string.Empty ); } continue; } SGLFileStream.Seek( SGLOffsetInfo.OffserTable[iIndex], SeekOrigin.Begin ); SGLImage[iIndex].Unknown1 = (byte)SGLFileStream.ReadByte(); SGLImage[iIndex].Format = (byte)SGLFileStream.ReadByte(); SGLFileStream.Read( byteUINT, 0, byteUINT.Length ); SGLImage[iIndex].Frames = (ushort)( byteUINT[0] | ( byteUINT[1] << 8 ) ); SGLImage[iIndex].Unknown2 = (ushort)( byteUINT[2] | ( byteUINT[3] << 8 ) ); { ListViewItemArray[iIndex] = new ListViewItem( iIndex.ToString(), 0 ); ListViewItemArray[iIndex].SubItems.Add( SGLImage[iIndex].Format.ToString() ); ListViewItemArray[iIndex].SubItems.Add( SGLImage[iIndex].Frames.ToString() ); ListViewItemArray[iIndex].SubItems.Add( string.Empty ); } SGLImage[iIndex].SGLFrames = new SGLFrame[SGLImage[iIndex].Frames]; for ( int iIndex2 = 0; iIndex2 < SGLImage[iIndex].SGLFrames.Length; iIndex2++ ) { SGLImage[iIndex].SGLFrames[iIndex2] = new SGLFrame(); SGLImage[iIndex].SGLFrames[iIndex2].FilePosition = SGLFileStream.Position; SGLFileStream.Read( byteUINT, 0, byteUINT.Length ); SGLImage[iIndex].SGLFrames[iIndex2].FrameWidth = (ushort)( byteUINT[0] | ( byteUINT[1] << 8 ) ); SGLImage[iIndex].SGLFrames[iIndex2].FrameHeight = (ushort)( byteUINT[2] | ( byteUINT[3] << 8 ) ); SGLFileStream.Read( byteUINT, 0, byteUINT.Length ); SGLImage[iIndex].SGLFrames[iIndex2].CenterX = (ushort)( byteUINT[0] | ( byteUINT[1] << 8 ) ); SGLImage[iIndex].SGLFrames[iIndex2].CenterY = (ushort)( byteUINT[2] | ( byteUINT[3] << 8 ) ); SGLImage[iIndex].SGLFrames[iIndex2].BlocksX = (byte)SGLFileStream.ReadByte(); SGLImage[iIndex].SGLFrames[iIndex2].BlocksY = (byte)SGLFileStream.ReadByte(); switch ( SGLImage[iIndex].Format ) { case 0x02: SGLImage[iIndex].SGLFrames[iIndex2].SGLFrameFormat02 = SGLFrameFormat02.GetSGLFrameFormat02( SGLFileStream, SGLImage[iIndex].SGLFrames[iIndex2] ); MessageBox.Show( "0x02" ); break; case 0x82: SGLImage[iIndex].SGLFrames[iIndex2].SGLFrameFormat82 = SGLFrameFormat82.GetSGLFrameFormat82( SGLFileStream, SGLImage[iIndex].SGLFrames[iIndex2] ); MessageBox.Show( "0x82" ); break; case 0x88: SGLImage[iIndex].SGLFrames[iIndex2].SGLFrameFormat88 = SGLFrameFormat88.GetSGLFrameFormat88( SGLFileStream, SGLImage[iIndex].SGLFrames[iIndex2] ); MessageBox.Show( "0x88" ); break; case 0x06: SGLImage[iIndex].SGLFrames[iIndex2].SGLFrameFormat06 = SGLFrameFormat06.GetSGLFrameFormat06( SGLFileStream, SGLImage[iIndex].SGLFrames[iIndex2] ); MessageBox.Show( "0x06" ); break; case 0x18: case 0x28: SGLImage[iIndex].SGLFrames[iIndex2].SGLFrameFormat18Or28 = SGLFrameFormat18Or28.GetSGLFrameFormat18Or28( SGLFileStream, SGLImage[iIndex].SGLFrames[iIndex2] ); MessageBox.Show( "0x28" ); break; case 0x11: case 0x12: case 0x22: SGLImage[iIndex].SGLFrames[iIndex2].SGLFrameFormat11Or12Or22 = SGLFrameFormat11Or12Or22.GetSGLFrameFormat11Or12Or22( SGLFileStream, SGLImage[iIndex].SGLFrames[iIndex2] ); break; case 0x62: SGLImage[iIndex].SGLFrames[iIndex2].SGLFrameFormat62 = SGLFrameFormat62.GetSGLFrameFormat62( SGLFileStream, SGLImage[iIndex].SGLFrames[iIndex2] ); MessageBox.Show( "0x62" ); break; default: break; } } } ListViewSGLImage = listViewSGLImage; listViewSGLImage.VirtualListSize = ListViewItemArray.Length; listViewSGLImage.RetrieveVirtualItem += new RetrieveVirtualItemEventHandler( RetrieveVirtualItemEventHandler ); listViewSGLImage.VirtualMode = true; return true; }