Esempio n. 1
0
        private void exportTexture(GraphicsViewer gv)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter   = "PNG Image|*.png|JPEG Image|*.jpg|Bitmap Image|*.bmp";
            sfd.Title    = "Save as Image File";
            sfd.FileName = String.Format("{0}.{1:X05}.{2}.png", basename, offset, N64Graphics.CodecString(gv.Codec));
            DialogResult dResult = sfd.ShowDialog();

            if (dResult == DialogResult.OK)
            {
                int      width  = gv.GetPixelWidth();
                int      height = gv.GetPixelHeight();
                Bitmap   bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                Graphics g      = Graphics.FromImage(bitmap);
                N64Graphics.RenderTexture(g, romData, curPalette, offset, width, height, 1, gv.Codec, gv.Mode);
                switch (sfd.FilterIndex)
                {
                case 1: bitmap.Save(sfd.FileName, ImageFormat.Png); break;

                case 2: bitmap.Save(sfd.FileName, ImageFormat.Jpeg); break;

                case 3: bitmap.Save(sfd.FileName, ImageFormat.Bmp); break;
                }
            }
        }
Esempio n. 2
0
 private void GraphicsViewer_Paint(object sender, PaintEventArgs e)
 {
     if (data != null)
     {
         N64Graphics.RenderTexture(e.Graphics, data, palette, offset, GetPixelWidth(), GetPixelHeight(), PixScale, Codec, Mode);
     }
     e.Graphics.DrawRectangle(new Pen(Color.Black), 0, 0, GetPixelWidth() * PixScale - 1, GetPixelHeight() * PixScale - 1);
 }
Esempio n. 3
0
 private void gvCopy_Click(object sender, EventArgs e)
 {
     if (rightClickGV != null)
     {
         int      width  = rightClickGV.GetPixelWidth();
         int      height = rightClickGV.GetPixelHeight();
         Bitmap   bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
         Graphics g      = Graphics.FromImage(bitmap);
         N64Graphics.RenderTexture(g, romData, curPalette, offset, width, height, 1, rightClickGV.Codec, rightClickGV.Mode);
         Clipboard.SetImage(bitmap);
     }
 }
Esempio n. 4
0
        private void runTest(int idx, bool verbose, PictureBox pbIn, PictureBox pbOut)
        {
            int width  = 32;
            int height = 32;

            byte[] test       = new byte[width * height * 4]; // worst case
            byte[] result     = null;
            byte[] pal        = new byte[16 * 16 * 2];
            byte[] resultPal  = null;
            int    errorCount = 0;

            StringBuilder sb = new StringBuilder();

            N64Codec testCodec = WhichCodec(idx);

            // randomize inputs
            Random rng = new Random();

            rng.NextBytes(test);
            rng.NextBytes(pal);

            // if alpha bit clear, clear all bits
            switch (testCodec)
            {
            case N64Codec.RGBA16:
                for (int i = 0; i < test.Length; i += 2)
                {
                    if ((test[i + 1] & 0x1) == 0)
                    {
                        test[i]     = 0;
                        test[i + 1] = 0;
                    }
                }
                break;

            case N64Codec.IA16:
                for (int i = 0; i < test.Length; i += 2)
                {
                    if ((test[i + 1]) == 0)
                    {
                        test[i] = 0;
                    }
                }
                break;

            case N64Codec.IA8:
                for (int i = 0; i < test.Length; i++)
                {
                    if ((test[i] & 0x0F) == 0)
                    {
                        test[i] = 0;
                    }
                }
                break;

            case N64Codec.IA4:
                for (int i = 0; i < test.Length; i++)
                {
                    if ((test[i] & 0x10) == 0)
                    {
                        test[i] &= 0x0F;
                    }
                    if ((test[i] & 0x01) == 0)
                    {
                        test[i] &= 0xF0;
                    }
                }
                break;

            case N64Codec.CI4:
            case N64Codec.CI8:
                for (int i = 0; i < pal.Length; i += 2)
                {
                    if ((pal[i + 1] & 0x1) == 0)
                    {
                        pal[i]     = 0;
                        pal[i + 1] = 0;
                    }
                }
                break;
            }

            Bitmap   b = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(b);

            N64Graphics.RenderTexture(g, test, pal, 0, width, height, 1, testCodec, N64IMode.AlphaCopyIntensity);
            N64Graphics.Convert(ref result, ref resultPal, testCodec, b);
            Bitmap bres = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            N64Graphics.RenderTexture(Graphics.FromImage(bres), result, resultPal, 0, width, height, 1, testCodec, N64IMode.AlphaCopyIntensity);
            for (int i = 0; i < result.Length; i++)
            {
                if (test[i] != result[i])
                {
                    errorCount++;
                }
                if (verbose)
                {
                    sb.AppendFormat("{0:X03} {1:X02} {2:X02}\r\n", i, test[i], result[i]);
                }
            }
            if (resultPal != null)
            {
                for (int i = 0; i < resultPal.Length; i++)
                {
                    if (pal[i] != resultPal[i])
                    {
                        errorCount++;
                    }
                    if (verbose)
                    {
                        sb.AppendFormat("P {0:X03} {1:X02} {2:X02}\r\n", i, pal[i], resultPal[i]);
                    }
                }
            }

            // publish results
            sb.AppendFormat("Test[{0}] {1}: {2} errors\r\n", idx, N64Graphics.CodecString(testCodec), errorCount);
            textBoxLog.AppendText(sb.ToString());
            pbIn.Image  = b;
            pbOut.Image = bres;
        }