Created
January 7, 2021 16:58
-
-
Save bakueikozo/8f37fc89ee6292a52898aa80d5997112 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
using System.Runtime.InteropServices; | |
namespace majo_565_compiler | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
public void decompile(string s) | |
{ | |
string path =s+".extracted"; | |
try { | |
System.IO.Directory.CreateDirectory(path); | |
} | |
catch (Exception e) | |
{ | |
} | |
var r = new BinaryReader(new FileStream(s, FileMode.Open)); | |
int frontLast = 4915200; | |
byte[] bFront = r.ReadBytes(frontLast); | |
byte[] bNext = r.ReadBytes((int)(r.BaseStream.Length-bFront.Length)); | |
Bitmap front = new Bitmap(640, 48, System.Drawing.Imaging.PixelFormat.Format16bppRgb565); | |
Bitmap next = new Bitmap(128, 128, System.Drawing.Imaging.PixelFormat.Format16bppRgb565); | |
int frontPictureCount = frontLast / 2 / (48 * 640); | |
int frontLengthEachPic = frontLast / frontPictureCount; | |
int fn = 0; | |
for(int n = 0; n < bFront.Length; n += frontLengthEachPic) | |
{ | |
int stride = frontLengthEachPic / 48; | |
var bd=front.LockBits(new Rectangle(0, 0, front.Width, front.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format16bppRgb565); | |
for(int y = 0; y < front.Height; y++) | |
{ | |
IntPtr p = bd.Scan0 + bd.Stride * y; | |
Marshal.Copy(bFront, frontLengthEachPic*fn + stride * y, p, stride); | |
} | |
front.UnlockBits(bd); | |
string outfile = System.IO.Path.Combine(path, fn.ToString("0000") + ".bmp"); | |
front.Save(outfile, System.Drawing.Imaging.ImageFormat.Bmp); | |
fn++; | |
} | |
int nextPictureCount = bNext.Length / 2 / (128*128); | |
int nextLengthEachPic = bNext.Length / nextPictureCount; | |
int bn = 0; | |
for (int n = 0; n < bNext.Length; n += nextLengthEachPic) | |
{ | |
int stride = nextLengthEachPic / 128; | |
var bd = next.LockBits(new Rectangle(0, 0, next.Width, next.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format16bppRgb565); | |
for (int y = 0; y < next.Height; y++) | |
{ | |
IntPtr p = bd.Scan0 + bd.Stride * y; | |
Marshal.Copy(bNext, nextLengthEachPic * bn + stride * y, p, stride); | |
} | |
next.UnlockBits(bd); | |
string outfile = System.IO.Path.Combine(path, (bn+fn).ToString("0000") + ".bmp"); | |
next.Save(outfile, System.Drawing.Imaging.ImageFormat.Bmp); | |
bn++; | |
} | |
} | |
public void compile(string dir) | |
{ | |
List<string> files=new List<string>(System.IO.Directory.GetFiles(dir, "*.bmp")); | |
files.Sort(); | |
System.IO.MemoryStream ms = new MemoryStream(); | |
for(int n = 0; n < files.Count; n++) | |
{ | |
Bitmap bitmap = new Bitmap(files[n]); | |
var bd = bitmap.LockBits(new Rectangle(0,0,bitmap.Width,bitmap.Height),System.Drawing.Imaging.ImageLockMode.ReadOnly,System.Drawing.Imaging.PixelFormat.Format16bppRgb565); | |
byte[] line = new byte[bd.Stride]; | |
for (int y = 0 ; y <bitmap.Height ; y++ ) | |
{ | |
IntPtr p = bd.Scan0 + bd.Stride * y; | |
Marshal.Copy(p, line, 0, line.Length); | |
ms.Write(line, 0, line.Length); | |
} | |
bitmap.UnlockBits(bd); | |
} | |
byte[] ball = ms.ToArray(); | |
if( ball.Length!=14155776 ) | |
{ | |
throw new Exception("Bad File size!"); | |
} | |
System.IO.File.WriteAllBytes( dir+".compiled.bin",ms.ToArray()); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
//decompile(@"C:\work\vmware\majo\AB565.bin"); | |
compile(@"C:\work\vmware\majo\AB565.bin.extracted"); | |
//decompile(@"C:\work\vmware\majo\AB565.bin.extracted.compiled.bin"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment