public void init(uint *input, Graphics _device) { _input = input; _output = (uint *)Marshal.AllocHGlobal(sizeof(uint) * 600 * 480); NativeGDI.initHighSpeed(_device, 600, 480, _output, 0, 0); LibScanline.init(_input, _output); }
public void init(uint *input, Graphics _device) { _input = input; _output = (uint *)Marshal.AllocHGlobal(sizeof(uint) * 256 * 3 * 240 * 3); NativeGDI.initHighSpeed(_device, 256 * 3, 240 * 3, _output, 0, 0); HS_XBRz.initTable(256, 240); }
private void button1_Click(object sender, EventArgs e) { //簡易版本 pattern 樣版明暗排列模擬版本 bool even = false; for (int y = 0; y < 960; y++) { for (int x = 0; x < 1196; x++) { int _x = (int)(x / 1196.0 * 512.0); int _y = y / 2; uint color_o = ScreenBuf1x[_x + _y * 512]; byte b1_o = (byte)(color_o & 0xff); byte b2_o = (byte)((color_o & 0xff00) >> 8); byte b3_o = (byte)((color_o & 0xff0000) >> 16); float m = 0.2f; if (even) { m = 0; } byte b1_n = (byte)(b1_o * (1 - m)); byte b2_n = (byte)(b2_o * (1 - m)); byte b3_n = (byte)(b3_o * (1 - m)); result2[x + y * 1196] = (uint)(0xff000000 | (b3_n << 16) | (b2_n << 8) | b1_n); } even = !even; } NativeGDI.initHighSpeed(panel1.CreateGraphics(), 1196, 960, result2, 0, 0); NativeGDI.DrawImageHighSpeedtoDevice(); }
public void init(uint *input, Graphics _device) { _input = input; _output_tmp = (uint *)Marshal.AllocHGlobal(sizeof(uint) * 256 * 3 * 240 * 3); _output = (uint *)Marshal.AllocHGlobal(sizeof(uint) * 1792 * 1440); NativeGDI.initHighSpeed(_device, 1792, 1440, _output, 0, 0); HS_XBRz.initTable(256, 240); LibScanline.init(_output_tmp, _output); }
private void button7_Click(object sender, EventArgs e) { if (running) { MessageBox.Show("running"); return; } running = true; uint * input = (uint *)Marshal.AllocHGlobal(sizeof(uint) * 512 * 480); Bitmap bg = new Bitmap(Application.StartupPath + "/sample.png"); BitmapData srcData = bg.LockBits(new Rectangle(Point.Empty, bg.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); for (int y = 0; y < 480; y++) { for (int x = 0; x < 512; x++) { input[x + y * 512] = ((uint *)srcData.Scan0.ToPointer())[x + y * 512]; } } bg.UnlockBits(srcData); uint *output = (uint *)Marshal.AllocHGlobal(sizeof(uint) * 1196 * 960); LibScanline.init(input, output); new Thread(() => { Stopwatch ST = new Stopwatch(); ST.Restart(); for (int i = 0; i < 400; i++) { LibScanline.ScanlineFor2x(); } ST.Stop(); Console.WriteLine(ST.ElapsedMilliseconds); Console.WriteLine(ST.ElapsedMilliseconds / 400f); NativeGDI.initHighSpeed(panel1.CreateGraphics(), 1196, 960, output, 0, 0); NativeGDI.DrawImageHighSpeedtoDevice(); running = false; }).Start(); }
private void button4_Click(object sender, EventArgs e) { //單純YIQ轉換 4:4:4取樣 for (int y = 0; y < 960; y++) { for (int x = 0; x < 1196; x++) { //nearest get sample 512*480 -> 1197*960 int _x = (int)(x / 1196.0 * 512.0); int _y = y / 2; //format ARGB 8:8:8:8 uint color_o = ScreenBuf1x[_x + _y * 512]; byte b1_o = (byte)(color_o & 0xff); //Blue byte b2_o = (byte)((color_o & 0xff00) >> 8); //Green byte b3_o = (byte)((color_o & 0xff0000) >> 16); //Red //get float float TO_FLOAT = 1 / 255.0f; float R_f = b3_o * TO_FLOAT; float G_f = b2_o * TO_FLOAT; float B_f = b1_o * TO_FLOAT; //convert float Y = 0.299f * R_f + 0.587f * G_f + 0.114f * B_f; float I = 0.596f * R_f - 0.274f * G_f - 0.322f * B_f; float Q = 0.211f * R_f - 0.523f * G_f + 0.312f * B_f; #region YIQ TO TGB R_f = Y + I * 0.956f + Q * 0.621f; G_f = Y + I * (-0.272f) + Q * (-0.647f); B_f = Y + I * (-1.106f) + Q * (1.703f); b1_o = (byte)(B_f * 255.0f); b2_o = (byte)(G_f * 255.0f); b3_o = (byte)(R_f * 255.0f); #endregion result2[x + y * 1196] = (uint)(0xff000000 | (b3_o << 16) | (b2_o << 8) | b1_o); } } NativeGDI.initHighSpeed(panel1.CreateGraphics(), 1196, 960, result2, 0, 0); NativeGDI.DrawImageHighSpeedtoDevice(); }
public void init(Graphics _device, byte[] bios_bytes, byte[] vbios_bytes) { Stopwatch st = new Stopwatch(); st.Restart(); NativeGDI.initHighSpeed(_device, 640, 350, screen_buffer, 0, 0); for (int i = 0; i < 256; i++) { int c = 0; byte v = (byte)i; for (int j = 0; j < 8; j++) { if ((v & 1) > 0) { c++; } v >>= 1; } Table_Paritys[i] = ((c % 2) == 0) ? true : false; } //init ram for (int i = 0; i < 0x100000; i++) { PA_mem[i] = 0; } //reset Reg_CS = 0xffff; Reg_IP = 0; //load system bios Array.Copy(bios_bytes, 0, PA_mem, 0x100000 - bios_bytes.Count(), bios_bytes.Count()); //load vga bios Array.Copy(vbios_bytes, 0, PA_mem, 0xc0000, vbios_bytes.Count()); if (File.Exists(@"c:\log\log.txt")) { File.Delete(@"c:\log\log.txt"); } if (!Directory.Exists(@"c:\log")) { Directory.CreateDirectory((@"c:\log")); } StepsLog = File.AppendText(@"c:\log\log.txt"); List <string> lines = File.ReadAllLines(Application.StartupPath + @"\io_step.dat").ToList(); foreach (string i in lines) { io_steps.Add(Convert.ToInt32(i.Substring(0, 6).Replace(" ", ""), 16), (ushort)Convert.ToUInt16(i.Substring(7, 4).Replace(" ", ""), 16)); } //load font to array for (int i = 0; i < 256; i++) { Bitmap bmp = new Bitmap(Application.StartupPath + @"\ASII_FONT\" + i.ToString("x2") + ".png"); int start = i * 8 * 14; for (int y = 0; y < 14; y++) { for (int x = 0; x < 8; x++) { font[start + x + (y << 3)] = (uint)(bmp.GetPixel(x, y).ToArgb()); } } bmp.Dispose(); } st.Stop(); Console.WriteLine("init : " + st.ElapsedMilliseconds + " ms done!\n"); }
public void init(uint *input, Graphics _device) { _input = input; NativeGDI.initHighSpeed(_device, 256 * 1, 240 * 1, _input, 0, 0); HS_XBRz.initTable(256, 240); }
private void button2_Click(object sender, EventArgs e) { //YUV取樣版本 bool even = false; for (int y = 0; y < 960; y++) { for (int x = 0; x < 1196; x++) { //nearest get sample 512*480 -> 1197*960 int _x = (int)(x / 1196.0 * 512.0); int _y = y / 2; //format ARGB 8:8:8:8 uint color_o = ScreenBuf1x[_x + _y * 512]; byte b3_o = (byte)(color_o & 0xff); //Blue byte b2_o = (byte)((color_o & 0xff00) >> 8); //Green byte b1_o = (byte)((color_o & 0xff0000) >> 16); //Red //get float float R_f = b1_o; float G_f = b2_o; float B_f = b3_o; //convert float Y = 0.299f * R_f + 0.587f * G_f + 0.114f * B_f; float U = (-0.169f) * R_f - 0.331f * G_f + 0.5f * B_f + 128; float V = 0.5f * R_f - 0.419f * G_f - 0.081f * B_f + 128; if (Y > 255.0) { Y = 255.0f; } if (U > 255.0) { U = 255.0f; } if (V > 255.0) { V = 255.0f; } if (Y < .0) { Y = .0f; } if (U < .0) { U = .0f; } if (V < .0) { V = .0f; } yuv[(x + y * 1196) * 3] = Y; yuv[(x + y * 1196) * 3 + 1] = U; yuv[(x + y * 1196) * 3 + 2] = V; } } for (int y = 0; y < 960; y++) { for (int x = 0; x < 1196; x++) { float Y = yuv[(x + y * 1196) * 3]; float U = yuv[(((x >> 2) << 2) + y * 1196) * 3 + 1]; float V = yuv[(((x >> 2) << 2) + y * 1196) * 3 + 2]; float R_f = Y + 1.13983f * (V - 128f); float G_f = Y - 0.39465f * (U - 128f) - 0.5806f * (V - 128f); float B_f = Y + 2.03211f * (U - 128f); if (R_f > 255.0) { R_f = 255.0f; } if (G_f > 255.0) { G_f = 255.0f; } if (B_f > 255.0) { B_f = 255.0f; } if (R_f < .0) { R_f = .0f; } if (G_f < .0) { G_f = .0f; } if (B_f < .0) { B_f = .0f; } byte b1_o = (byte)(B_f); byte b2_o = (byte)(G_f); byte b3_o = (byte)(R_f); #region blend scanline pattern float m = 0.1f; if (even) { m = 0; } byte b1_n = (byte)(b1_o * (1 - m)); byte b2_n = (byte)(b2_o * (1 - m)); byte b3_n = (byte)(b3_o * (1 - m)); #endregion result2[x + y * 1196] = (uint)(0xff000000 | (b3_n << 16) | (b2_n << 8) | b1_n); } even = !even; } NativeGDI.initHighSpeed(panel1.CreateGraphics(), 1196, 960, result2, 0, 0); NativeGDI.DrawImageHighSpeedtoDevice(); }
private void button3_Click(object sender, EventArgs e) { if (running) { MessageBox.Show("running.."); return; } new Thread(() => { running = true; Stopwatch ST = new Stopwatch(); ST.Restart(); //YIQ版本 4:1:1取樣 且加入pixel模糊特效 for (int y = 0; y < 960; y++) { for (int x = 0; x < 1196; x++) { int _x = (int)(x / 1196.0 * 512.0); int _y = y / 2; //format ARGB 8:8:8:8 uint color_o = ScreenBuf1x[_x + _y * 512]; byte b1_o = (byte)(color_o & 0xff); //Blue byte b2_o = (byte)((color_o & 0xff00) >> 8); //Green byte b3_o = (byte)((color_o & 0xff0000) >> 16); //Red //get float float TO_FLOAT = 1 / 255.0f; float R_f = b3_o * TO_FLOAT; float G_f = b2_o * TO_FLOAT; float B_f = b1_o * TO_FLOAT; //convert float Y = 0.299f * R_f + 0.587f * G_f + 0.114f * B_f; float I = 0.596f * R_f - 0.274f * G_f - 0.322f * B_f; float Q = 0.211f * R_f - 0.523f * G_f + 0.312f * B_f; yiq[(x + y * 1196) * 3] = Y; yiq[(x + y * 1196) * 3 + 1] = I; yiq[(x + y * 1196) * 3 + 2] = Q; } } bool even = false; for (int y = 0; y < 960; y++) { for (int x = 0; x < 1196; x++) { float Y = yiq[(x + y * 1196) * 3]; float I = yiq[((x & 0xffc) + y * 1196) * 3 + 1]; float Q = yiq[((x & 0xffc) + y * 1196) * 3 + 2]; Y += 0.05F;//加點亮度 float R_f = Y + I * 0.956f + Q * 0.621f; float G_f = Y + I * (-0.272f) + Q * (-0.647f); float B_f = Y + I * (-1.106f) + Q * (1.703f); R_f *= 255.0f; G_f *= 255.0f; B_f *= 255.0f; if (R_f > 255.0) { R_f = 255.0f; } if (G_f > 255.0) { G_f = 255.0f; } if (B_f > 255.0) { B_f = 255.0f; } if (R_f < .0) { R_f = .0f; } if (G_f < .0) { G_f = .0f; } if (B_f < .0) { B_f = .0f; } byte b1_o = (byte)(B_f); byte b2_o = (byte)(G_f); byte b3_o = (byte)(R_f); result2[x + y * 1196] = (uint)(0xff000000 | (b3_o << 16) | (b2_o << 8) | b1_o); } } //模糊化 for (int y = 0; y < 960; y++) { for (int x = 0; x < 1196; x++) { uint color_l = 0xffffffff, color_r = 0xffffffff, color_o; color_o = result2[x + y * 1196]; if (x > 0) { color_l = result2[x - 1 + y * 1196]; } if (x < 1195) { color_r = result2[x + 1 + y * 1196]; } byte b1_o = (byte)(color_o & 0xff); //Blue byte b2_o = (byte)((color_o & 0xff00) >> 8); //Green byte b3_o = (byte)((color_o & 0xff0000) >> 16); //Red byte b1_l = (byte)(color_l & 0xff); //Blue byte b2_l = (byte)((color_l & 0xff00) >> 8); //Green byte b3_l = (byte)((color_l & 0xff0000) >> 16); //Red byte b1_r = (byte)(color_r & 0xff); //Blue byte b2_r = (byte)((color_r & 0xff00) >> 8); //Green byte b3_r = (byte)((color_r & 0xff0000) >> 16); //Red b1_o = (byte)((b1_o * 1 + b1_l * 3 + b1_r * 1) / 5); b2_o = (byte)((b2_o * 1 + b2_l * 3 + b2_r * 1) / 5); b3_o = (byte)((b3_o * 1 + b3_l * 3 + b3_r * 1) / 5); #region blend scanline pattern float m = 0.1f; if (even) { m = 0; } byte b1_n = (byte)(b1_o * (1 - m)); byte b2_n = (byte)(b2_o * (1 - m)); byte b3_n = (byte)(b3_o * (1 - m)); #endregion result3[x + y * 1196] = (uint)(0xff000000 | (b3_n << 16) | (b2_n << 8) | b1_n); } if (y % 2 == 0) { even = !even; } } ST.Stop(); Console.WriteLine(ST.ElapsedMilliseconds); NativeGDI.initHighSpeed(panel1.CreateGraphics(), 1196, 960, result3, 0, 0); NativeGDI.DrawImageHighSpeedtoDevice(); running = false; }).Start(); }