private void importToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { try { Bitmap chunk = (Bitmap)Image.FromFile(dialog.FileName); if (treeView1.SelectedNode != null) { if (treeView1.SelectedNode.Tag != null) { ShapeChunk data = (ShapeChunk)treeView1.SelectedNode.Tag; data.Replace(chunk); m_vStorageObject.AddChange(m_vStorageObject.GetTextures()[data.GetTextureId()]); Render(); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
public Texture(Decoder scs) { m_vStorageObject = scs; m_vScImageTypes = new Dictionary<byte, Type>(); m_vScImageTypes.Add(0, typeof(ImageRgba8888)); m_vScImageTypes.Add(2, typeof(ImageRgba4444)); m_vScImageTypes.Add(4, typeof(ImageRgb565)); m_vTextureId = (short)m_vStorageObject.GetTextures().Count(); }
public Texture(Decoder scs) { m_vStorageObject = scs; m_vScImageTypes = new Dictionary <byte, Type>(); m_vScImageTypes.Add(0, typeof(ImageRgba8888)); m_vScImageTypes.Add(2, typeof(ImageRgba4444)); m_vScImageTypes.Add(4, typeof(ImageRgb565)); m_vTextureId = (short)m_vStorageObject.GetTextures().Count(); }
private void LoadSC(string fileName) { m_vStorageObject = new Decoder(fileName); m_vStorageObject.Decode(); treeView1.Nodes.Clear(); pictureBox1.Image = null; label1.Text = null; RefreshMenu(); treeView1.Populate(m_vStorageObject.GetExports()); //treeView1.Populate(m_vStorageObject.GetShapes()); treeView1.Populate(m_vStorageObject.GetTextures()); //treeView1.Populate(m_vStorageObject.GetMovieClips()); }
public override void ParseData(BinaryReader br) { Debug.WriteLine("Parsing chunk data from shape " + m_vShapeId); m_vOffset = br.BaseStream.Position; m_vTextureId = br.ReadByte(); //00 byte shapePointCount = br.ReadByte(); //04 var texture = (Texture)m_vStorageObject.GetTextures()[m_vTextureId]; for (int i = 0; i < shapePointCount; i++) { float x = (float)(br.ReadInt32() * 0.05); //* 0.05); float y = (float)(br.ReadInt32() * 0.05); //* 0.05); m_vPointsXY.Add(new PointF(x, y)); Debug.WriteLine("x: " + x + ", y: " + y); } if (m_vChunkType == 22) { for (int i = 0; i < shapePointCount; i++) { float u = (float)(br.ReadUInt16() / 65535.0) * texture.GetImage().GetWidth(); float v = (float)(br.ReadUInt16() / 65535.0) * texture.GetImage().GetHeight(); m_vPointsUV.Add(new PointF(u, v)); Debug.WriteLine("u: " + u + ", v: " + v); } } else { for (int i = 0; i < shapePointCount; i++) { ushort u = br.ReadUInt16(); // image.Width); ushort v = br.ReadUInt16(); // image.Height);//(short) (65535 * br.ReadInt16() / image.Height); m_vPointsUV.Add(new Point(u, v)); Debug.WriteLine("u: " + u + ", v: " + v); } } }
public Texture(Texture t) { m_vFileType = t.m_vFileType; m_vImageType = t.GetImageType(); m_vStorageObject = t.GetStorageObject(); m_vTextureId = (short)m_vStorageObject.GetTextures().Count(); if (m_vScImageTypes.ContainsKey(m_vImageType)) { m_vImage = (ScImage)Activator.CreateInstance(m_vScImageTypes[m_vImageType]); } else { m_vImage = new ScImage(); } m_vImage.SetBitmap(new Bitmap(t.GetBitmap())); m_vOffset = t.GetOffset() > 0 ? -t.GetOffset() : t.GetOffset(); }
public Texture(Texture t) { m_vImageType = t.GetImageType(); m_vStorageObject = t.GetStorageObject(); m_vTextureId = (short)m_vStorageObject.GetTextures().Count(); m_vScImageTypes = new Dictionary <byte, Type>(); m_vScImageTypes.Add(0, typeof(ImageRgba8888)); m_vScImageTypes.Add(2, typeof(ImageRgba4444)); m_vScImageTypes.Add(4, typeof(ImageRgb565)); if (m_vScImageTypes.ContainsKey(m_vImageType)) { m_vImage = (ScImage)Activator.CreateInstance(m_vScImageTypes[m_vImageType]); } else { m_vImage = new ScImage(); } m_vImage.SetBitmap(new Bitmap(t.GetBitmap())); m_vOffset = t.GetOffset() > 0 ? -t.GetOffset() : t.GetOffset(); }
public Texture(Texture t) { m_vImageType = t.GetImageType(); m_vStorageObject = t.GetStorageObject(); m_vTextureId = (short)m_vStorageObject.GetTextures().Count(); m_vScImageTypes = new Dictionary<byte, Type>(); m_vScImageTypes.Add(0, typeof(ImageRgba8888)); m_vScImageTypes.Add(2, typeof(ImageRgba4444)); m_vScImageTypes.Add(4, typeof(ImageRgb565)); if (m_vScImageTypes.ContainsKey(m_vImageType)) { m_vImage = (ScImage)Activator.CreateInstance(m_vScImageTypes[m_vImageType]); } else { m_vImage = new ScImage(); } m_vImage.SetBitmap(new Bitmap(t.GetBitmap())); m_vOffset = t.GetOffset() > 0 ? -t.GetOffset() : t.GetOffset(); }
private void LoadSC(string fileName) { m_vStorageObject = new Decoder(fileName); m_vStorageObject.Decode(); treeView1.Nodes.Clear(); pictureBox1.Image = null; label1.Text = null; RefreshMenu(); treeView1.Populate(m_vStorageObject.GetExports()); //treeView1.Populate(m_vStorageObject.GetShapes()); treeView1.Populate(m_vStorageObject.GetTextures()); //treeView1.Populate(m_vStorageObject.GetMovieClips()); }
public Texture(Decoder scs) { m_vStorageObject = scs; m_vTextureId = (short)m_vStorageObject.GetTextures().Count(); }
public override void Save(FileStream input) { input.Seek(0, SeekOrigin.Begin); byte[] file = new byte[input.Length]; input.Read(file, 0, file.Length); int cursor = (int)m_vStorageObject.GetStartExportsOffset(); input.Seek(m_vStorageObject.GetStartExportsOffset(), SeekOrigin.Begin); ushort exportCount = BitConverter.ToUInt16(file, cursor); input.Write(BitConverter.GetBytes((ushort)(exportCount + 1)), 0, 2); cursor += 2; input.Seek(exportCount * 2, SeekOrigin.Current); cursor += exportCount * 2; input.Write(BitConverter.GetBytes(m_vExportId), 0, 2); for (int i = 0; i < exportCount; i++) { byte nameLength = file[cursor]; cursor++; byte[] exportName = new byte[nameLength]; Array.Copy(file, cursor, exportName, 0, nameLength); input.WriteByte(nameLength); input.Write(exportName, 0, nameLength); cursor += nameLength; } input.WriteByte((byte)m_vExportName.Length); input.Write(Encoding.UTF8.GetBytes(m_vExportName), 0, (byte)m_vExportName.Length); while (cursor < file.Length) { input.WriteByte(file[cursor]); cursor++; } //refresh all offsets foreach (Texture t in m_vStorageObject.GetTextures()) { long offset = t.GetOffset(); if (offset > 0) { offset += 2 + 1 + m_vExportName.Length; } else { offset = offset - 2 - 1 - m_vExportName.Length; } t.SetOffset(offset); } foreach (Shape s in m_vStorageObject.GetShapes()) { long offset = s.GetOffset(); if (offset > 0) { offset += 2 + 1 + m_vExportName.Length; } else { offset = offset - 2 - 1 - m_vExportName.Length; } s.SetOffset(offset); foreach (ShapeChunk sc in s.GetChunks()) { long chunkOffset = sc.GetOffset(); if (chunkOffset > 0) { chunkOffset += 2 + 1 + m_vExportName.Length; } else { chunkOffset = chunkOffset - 2 - 1 - m_vExportName.Length; } sc.SetOffset(chunkOffset); } } foreach (MovieClip mc in m_vStorageObject.GetMovieClips()) { long offset = mc.GetOffset(); if (offset > 0) { offset += 2 + 1 + m_vExportName.Length; } else { offset = offset - 2 - 1 - m_vExportName.Length; } mc.SetOffset(offset); } m_vStorageObject.SetEofOffset(m_vStorageObject.GetEofOffset() + 2 + 1 + m_vExportName.Length); //ne pas oublier eofoffset }
public override Bitmap Render(RenderingOptions options) { /* * Log("XY:"); * foreach(ShapeChunk chunk in m_vChunks) * { * foreach(var p in chunk.GetPointsXY()) * { * Log("x: " + p.X + ", y: " + p.Y); * } * Log(""); * } * * foreach (ShapeChunk chunk in m_vChunks) * { * foreach (var p in chunk.GetPointsUV()) * { * Log("u: " + p.X + ", u: " + p.Y); * } * Log(""); * } */ Log("Rendering image of " + m_vChunks.Count.ToString() + " polygons"); //Calculate et initialize the final shape size List <PointF> pointsXY = m_vChunks.SelectMany(chunk => ((ShapeChunk)chunk).GetPointsXY()).ToList(); GraphicsPath pathXY = new GraphicsPath(); pathXY.AddPolygon(pointsXY.ToArray()); int width = Rectangle.Round(pathXY.GetBounds()).Width; width = width > 0 ? width : 1; int height = Rectangle.Round(pathXY.GetBounds()).Height; height = height > 0 ? height : 1; int x = Rectangle.Round(pathXY.GetBounds()).X; int y = Rectangle.Round(pathXY.GetBounds()).Y; var finalShape = new Bitmap(width, height); //Assemble shape chunks foreach (ShapeChunk chunk in m_vChunks) { var texture = (Texture)m_vStorageObject.GetTextures()[chunk.GetTextureId()]; Bitmap bitmap = texture.GetBitmap(); var polygonUV = chunk.GetPointsUV(); var polygonXY = chunk.GetPointsXY(); GraphicsPath gpuv = new GraphicsPath(); gpuv.AddPolygon(polygonUV.ToArray()); GraphicsPath gpxy = new GraphicsPath(); gpxy.AddPolygon(polygonXY.ToArray()); int gpuvWidth = Rectangle.Round(gpuv.GetBounds()).Width; gpuvWidth = gpuvWidth > 0 ? gpuvWidth : 1; int gpuvHeight = Rectangle.Round(gpuv.GetBounds()).Height; gpuvHeight = gpuvHeight > 0 ? gpuvHeight : 1; var shapeChunk = new Bitmap(gpuvWidth, gpuvHeight); int chunkX = Rectangle.Round(gpuv.GetBounds()).X; int chunkY = Rectangle.Round(gpuv.GetBounds()).Y; //bufferizing shape using (Graphics g = Graphics.FromImage(shapeChunk)) { //On conserve la qualité de l'image intacte gpuv.Transform(new Matrix(1, 0, 0, 1, -chunkX, -chunkY)); g.SetClip(gpuv); g.DrawImage(bitmap, -chunkX, -chunkY); } GraphicsPath gp = new GraphicsPath(); gp.AddPolygon(new Point[] { new Point(0, 0), new Point(gpuvWidth, 0), new Point(0, gpuvHeight) }); //Calculate transformation Matrix of UV //double[,] matrixArrayUV = { { polygonUV[0].X, polygonUV[1].X, polygonUV[2].X }, { polygonUV[0].Y, polygonUV[1].Y, polygonUV[2].Y }, { 1, 1, 1 } }; double[,] matrixArrayUV = { { gpuv.PathPoints[0].X, gpuv.PathPoints[1].X, gpuv.PathPoints[2].X }, { gpuv.PathPoints[0].Y, gpuv.PathPoints[1].Y, gpuv.PathPoints[2].Y }, { 1, 1, 1 } }; double[,] matrixArrayXY = { { polygonXY[0].X, polygonXY[1].X, polygonXY[2].X }, { polygonXY[0].Y, polygonXY[1].Y, polygonXY[2].Y }, { 1, 1, 1 } }; var matrixUV = Matrix <double> .Build.DenseOfArray(matrixArrayUV); var matrixXY = Matrix <double> .Build.DenseOfArray(matrixArrayXY); var inverseMatrixUV = matrixUV.Inverse(); var transformMatrix = matrixXY * inverseMatrixUV; var m = new Matrix((float)transformMatrix[0, 0], (float)transformMatrix[1, 0], (float)transformMatrix[0, 1], (float)transformMatrix[1, 1], (float)transformMatrix[0, 2], (float)transformMatrix[1, 2]); //var m = new Matrix((float)transformMatrix[0, 0], (float)transformMatrix[1, 0], (float)transformMatrix[0, 1], (float)transformMatrix[1, 1], (float)Math.Round(transformMatrix[0, 2]), (float)Math.Round(transformMatrix[1, 2])); //Perform transformations gp.Transform(m); using (Graphics g = Graphics.FromImage(finalShape)) { //g.InterpolationMode = InterpolationMode.NearestNeighbor; //g.PixelOffsetMode = PixelOffsetMode.None; //Set origin Matrix originTransform = new Matrix(); originTransform.Translate(-x, -y); g.Transform = originTransform; g.DrawImage(shapeChunk, gp.PathPoints, gpuv.GetBounds(), System.Drawing.GraphicsUnit.Pixel); if (options.ViewPolygons) { gpuv.Transform(m); g.DrawPath(new Pen(Color.DarkGray, 1), gpuv); } } } return(finalShape); }