Exemple #1
0
        private void gvSetPaletteBefore_Click(object sender, EventArgs e)
        {
            int paletteBytes = N64Graphics.PixelsToBytes(gviewPalette.Codec, gviewPalette.PixSize.Width * gviewPalette.PixSize.Height);

            setPaletteOffset(offset - paletteBytes);
            checkExtPalette.Checked = false;
        }
Exemple #2
0
        private void gvSetPaletteAfter_Click(object sender, EventArgs e)
        {
            int paletteBytes = N64Graphics.PixelsToBytes(rightClickGV.Codec, rightClickGV.PixSize.Width * rightClickGV.PixSize.Height);

            setPaletteOffset(offset + paletteBytes);
            checkExtPalette.Checked = false;
        }
Exemple #3
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;
                }
            }
        }
Exemple #4
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);
 }
Exemple #5
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);
     }
 }
Exemple #6
0
        private void InsertImage(Bitmap bm)
        {
            if (romData != null)
            {
                byte[] imageData = null, paletteData = null;

                N64Graphics.Convert(ref imageData, ref paletteData, viewerCodec, bm);

                bool bufferChanged = ensureCapacity(ref romData, imageData, offset);
                if (bufferChanged)
                {
                    DisplayFileSize(romData.Length);
                }
                Array.Copy(imageData, 0, romData, offset, imageData.Length);
                fileDataChanged = true;

                if (paletteData != null && paletteData.Length > 0)
                {
                    int    palOffset = (int)numericPalette.Value;
                    byte[] paletteDest;
                    if (separatePalette && extPaletteData != null)
                    {
                        ensureCapacity(ref extPaletteData, paletteData, palOffset);
                        extPaletteChanged = true;
                        paletteDest       = extPaletteData;
                    }
                    else
                    {
                        bufferChanged = ensureCapacity(ref romData, paletteData, palOffset);
                        if (bufferChanged)
                        {
                            DisplayFileSize(romData.Length);
                        }
                        paletteDest = romData;
                    }

                    Array.Copy(paletteData, 0, paletteDest, palOffset, paletteData.Length);
                    UpdatePalette();
                }

                foreach (GraphicsViewer gv in viewers)
                {
                    if (bufferChanged)
                    {
                        gv.SetData(romData);
                    }
                    gv.Invalidate();
                }
            }
        }
Exemple #7
0
        private void advancePaletteOffset(GraphicsViewer gv, int direction, int advancePixels)
        {
            int offsetSize;

            if (advancePixels == 0)
            {
                offsetSize = N64Graphics.PixelsToBytes(gv.Codec, gv.PixSize.Width * gv.PixSize.Height);
            }
            else
            {
                offsetSize = N64Graphics.PixelsToBytes(gv.Codec, advancePixels);
            }
            int palOffset = (int)numericPalette.Value;
            int change    = direction * offsetSize;

            setPaletteOffset(palOffset + change);
        }
Exemple #8
0
 private void advanceOffset(GraphicsViewer gv, int direction, int advancePixels)
 {
     if (romData != null)
     {
         int offsetSize;
         if (advancePixels == 0)
         {
             offsetSize = N64Graphics.PixelsToBytes(gv.Codec, gv.GetPixelWidth() * gv.GetPixelHeight());
         }
         else
         {
             offsetSize = N64Graphics.PixelsToBytes(gv.Codec, advancePixels);
         }
         int change    = direction * offsetSize;
         int newOffset = Math.Max(0, Math.Min(romData.Length - 1, offset + change));
         numericOffset.Value = newOffset;
     }
 }
Exemple #9
0
        private void insertImage(Bitmap bm)
        {
            if (romData != null)
            {
                byte[] imageData = null, paletteData = null;

                N64Graphics.Convert(ref imageData, ref paletteData, viewerCodec, bm);

                int copyLength = Math.Min(imageData.Length, romData.Length - offset);
                Array.Copy(imageData, 0, romData, offset, copyLength);
                fileDataChanged = true;

                if (paletteData != null)
                {
                    byte[] paletteDest;
                    if (separatePalette && extPaletteData != null)
                    {
                        extPaletteChanged = true;
                        paletteDest       = extPaletteData;
                    }
                    else
                    {
                        paletteDest = romData;
                    }
                    int palOffset = (int)numericPalette.Value;
                    copyLength = Math.Min(paletteData.Length, paletteDest.Length - palOffset);
                    if (copyLength > 0)
                    {
                        Array.Copy(paletteData, 0, paletteDest, palOffset, copyLength);
                        UpdatePalette();
                    }
                }

                foreach (GraphicsViewer gv in viewers)
                {
                    gv.Invalidate();
                }
            }
        }
Exemple #10
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;
        }
Exemple #11
0
        private void graphicsViewer_MouseMove(object sender, MouseEventArgs e)
        {
            if (romData != null)
            {
                GraphicsViewer gv            = (GraphicsViewer)sender;
                int            pixOffset     = (e.Y / gv.PixScale) * gv.GetPixelWidth() + e.X / gv.PixScale;
                int            byteOffset    = N64Graphics.PixelsToBytes(gv.Codec, pixOffset);
                int            nibblesPerPix = 1;
                int            select        = 0;
                int            selectBits    = 0;
                switch (gv.Codec)
                {
                case N64Codec.RGBA32:
                    nibblesPerPix = 8;
                    pixOffset    *= nibblesPerPix / 2;
                    break;

                case N64Codec.RGBA16:
                case N64Codec.IA16:
                    nibblesPerPix = 4;
                    pixOffset    *= nibblesPerPix / 2;
                    break;

                case N64Codec.IA8:
                case N64Codec.I8:
                case N64Codec.CI8:
                    nibblesPerPix = 2;
                    break;

                case N64Codec.IA4:
                case N64Codec.I4:
                case N64Codec.CI4:
                    selectBits = 4;
                    select     = pixOffset & 0x1;
                    pixOffset /= 2;
                    break;

                case N64Codec.ONEBPP:
                    selectBits = 1;
                    select     = pixOffset & 0x7;
                    pixOffset /= 8;
                    break;
                }

                byte[] colorData;
                if (gv == gviewPalette)
                {
                    colorData = curPalette;
                }
                else
                {
                    byteOffset += offset;
                    colorData   = romData;
                }
                if (byteOffset >= 0 && (byteOffset + nibblesPerPix / 2) <= colorData.Length)
                {
                    Color c     = N64Graphics.MakeColor(colorData, curPalette, byteOffset, select, gv.Codec, gv.Mode);
                    int   value = 0;
                    for (int i = 0; i < (nibblesPerPix + 1) / 2; i++)
                    {
                        value = (value << 8) | colorData[byteOffset + i];
                    }
                    switch (selectBits)
                    {
                    case 4: value = (value >> ((1 - select) * 4)) & 0xf; break;

                    case 1: value = (value >> select) & 0x1; break;
                    }
                    string hexFormat = String.Format("Hex: {{0:X0{0}}}", nibblesPerPix);
                    pictureBoxColor.BackColor = c;
                    labelColorHex.Text        = String.Format(hexFormat, value);
                    labelColorR.Text          = String.Format("R: {0}", c.R);
                    labelColorG.Text          = String.Format("G: {0}", c.G);
                    labelColorB.Text          = String.Format("B: {0}", c.B);
                    labelColorA.Text          = String.Format("A: {0}", c.A);
                }
                else
                {
                    pictureBoxColor.BackColor = Color.Empty;
                    labelColorHex.Text        = "Hex:";
                    labelColorR.Text          = "R:";
                    labelColorG.Text          = "G:";
                    labelColorB.Text          = "B:";
                    labelColorA.Text          = "A:";
                }
            }
        }