Esempio n. 1
0
        private void SetFromLutAB(CLUT clut, TagDataEntry[] curveA, TagDataEntry[] curveB, TagDataEntry[] curveM)
        {
            if (clut.Values != null)
            {
                var clutCtrl = new ClutControl(clut);
                AddTabPage("CLUT", clutCtrl);
            }

            if (curveA != null)
            {
                var curveACtrl = new CurveControl(GetCurveValues(curveA));
                AddTabPage("Curve A", curveACtrl);
            }

            if (curveB != null)
            {
                var curveBCtrl = new CurveControl(GetCurveValues(curveB));
                AddTabPage("Curve B", curveBCtrl);
            }

            if (curveM != null)
            {
                var curveMCtrl = new CurveControl(GetCurveValues(curveM));
                AddTabPage("Curve M", curveMCtrl);
            }
        }
Esempio n. 2
0
        public ClutControl(CLUT clut)
            : this()
        {
            DataTypeLabel.Text = clut.DataType.ToString();
            Clut = clut;

            for (int i = 0; i < clut.InputChannelCount; i++)
            {
                NumericUpDown num = new NumericUpDown();
                num.MaximumDecimalPlaces = 0;
                Slider sl = new Slider();
                sl.SnapToTick    = true;
                num.MinValue     = sl.MinValue = 0;
                num.MaxValue     = sl.MaxValue = clut.GridPointCount[i] - 1;
                sl.ValueChanged += Slider_ValueChanged;
                sl.ValueChanged += (o, s) => { if ((int)num.Value != sl.Value)
                                               {
                                                   num.Value = sl.Value;
                                               }
                };
                num.ValueChanged += (o, s) => { if (sl.Value != (int)num.Value)
                                                {
                                                    sl.Value = (int)num.Value;
                                                }
                };
                TableRow row = new TableRow
                {
                    Cells =
                    {
                        new TableCell(sl,   true),
                        new TableCell(num),
                    }
                };
                InSliders.Add(sl);
                InValuesTable.Rows.Add(row);
            }
            InValuesTable.Rows.Add(new TableRow {
                ScaleHeight = true
            });

            for (int i = 0; i < clut.OutputChannelCount; i++)
            {
                Label lb = new Label();
                lb.Text = $"Channel {i}:";
                TextBox txt = new TextBox();
                txt.ReadOnly = true;
                txt.Text     = "0";
                OutTextBoxes.Add(txt);
                OutValuesLayout.Items.Add(lb);
                OutValuesLayout.Items.Add(txt);
            }
            OutValuesLayout.Items.Add(new StackLayoutItem {
                Expand = true
            });
        }
        public override void GetTagData(byte[] iccData, int index, ICCHeader header)
        {
            //Number of Input Channels (1 byte)
            InputChannelCount = iccData[index];
            //Number of Output Channels (1 byte)
            OutputChannelCount = iccData[index + 1];
            //Reserved for padding (2 bytes)
            //Offset to first "B" curve (4 bytes)
            BCurveOffset = (int)HighEndianReader.GetUint32(iccData, index + 4, IsLittleEndian);
            //Offset to matrix (4 bytes)
            MatrixOffset = (int)HighEndianReader.GetUint32(iccData, index + 8, IsLittleEndian);
            MCurveOffset = (int)HighEndianReader.GetUint32(iccData, index + 12, IsLittleEndian);
            //Offset to CLUT (4 bytes)
            CLUTOffset = (int)HighEndianReader.GetUint32(iccData, index + 16, IsLittleEndian);
            //Offset to first "A" curve (4 bytes)
            ACurveOffset = (int)HighEndianReader.GetUint32(iccData, index + 20, IsLittleEndian);

            //Curves
            if (BCurveOffset != 0)
            {
                GetCurve(iccData, ACurveOffset, ref curveB, index, InputChannelCount);
            }
            if (MCurveOffset != 0)
            {
                GetCurve(iccData, ACurveOffset, ref curveM, index, InputChannelCount);
            }
            if (CLUTOffset != 0)
            {
                CLUTValues = CLUT.GetCLUT(iccData, index - 8 + CLUTOffset, false, InputChannelCount, OutputChannelCount);
            }
            if (ACurveOffset != 0)
            {
                GetCurve(iccData, ACurveOffset, ref curveA, index, InputChannelCount);
            }

            //Matrix
            if (MatrixOffset != 0)
            {
                int i = MatrixOffset + index - 8;
                //Matrix 3x3 (4 bytes each)
                Matrix3x3 = HighEndianReader.GetMatrix(iccData, 3, 3, i, false, IsLittleEndian);
                //Matrix 3x1 (4 bytes each)
                Matrix3x1 = HighEndianReader.GetMatrix(iccData, 3, i + 36, false, IsLittleEndian);
            }
        }
Esempio n. 4
0
        private void SetFromLUT(CLUT clut, LUT[] inLut, LUT[] outLut)
        {
            if (inLut != null)
            {
                var inCurve = GetLutCurveControl(inLut);
                AddTabPage("In LUT", inCurve);
            }

            if (clut.Values != null)
            {
                var clutCtrl = new ClutControl(clut);
                AddTabPage("CLUT", clutCtrl);
            }

            if (outLut != null)
            {
                var outCurve = GetLutCurveControl(outLut);
                AddTabPage("Out LUT", outCurve);
            }
        }
        private void btnExport_Click(object sender, EventArgs e)
        {
            var    img         = picOptimized.Image;
            var    bmp         = img as Bitmap;
            var    pal         = img.Palette;
            var    exportImage = new List <byte>();
            var    dic         = new Dictionary <int, int>();
            string filename2   = fileName.Replace(".png", "-optimized.png");

            picOptimized.Image.Save(filename2);

            int y = 0;

            foreach (var zone in zones.Items)
            {
                CLUT clut = null;
                if (zone.CLUT >= 0)
                {
                    clut = zones.Palette.CLUTs[zone.CLUT];
                }
                for (int y1 = 0; y1 < zone.Height; y1++)
                {
                    int x = 0;
                    for (int x2 = 0; x2 < (img.Width / 2); x2++)
                    {
                        byte b;
                        if (zone.CLUT >= 0)
                        {
                            var colL = bmp.GetPixel(x, y);
                            var ulaL = clut.GetColourFromULAplusRGB(colL);
                            x++;
                            var colR = bmp.GetPixel(x, y);
                            var ulaR = clut.GetColourFromULAplusRGB(colR);
                            x++;

                            b = clut.GetRadastanColourByte(ulaL, ulaR);
                        }
                        else
                        {
                            b = 0;
                            x = x + 2;
                        }
                        exportImage.Add(b);
                    }
                    y++;
                }
            }

            string filename3 = fileName.Replace(".png", ".radscr");

            File.WriteAllBytes(filename3, exportImage.ToArray());

            var sb   = new StringBuilder();
            int line = 0;

            for (int i = 0; i < zones.Items.Count; i++)
            {
                line += zones.Items[i].Height * 2;
                sb.Append("; Zone ");
                sb.Append(i);
                sb.Append(": RASTERCTRL line ");
                sb.AppendLine(line.ToString());
            }
            sb.AppendLine();
            for (int i = 0; i < 4; i++)
            {
                var clut = zones.Palette.CLUTs[i];
                sb.Append("; CLUT ");
                sb.Append(i);
                sb.Append(" (");
                sb.Append(zones.GetZoneDescription(i));
                sb.Append(") - ");
                sb.AppendLine(clut.HexString);
                sb.Append("  db ");
                string join = "";
                foreach (var col in clut.Colours)
                {
                    sb.Append(join);
                    sb.Append("$");
                    sb.Append(col.ULAplusByte.ToString("X2").ToUpper());
                    join = ", ";
                }
                sb.AppendLine();
            }
            string filename4 = fileName.Replace(".png", "-palette.asm");

            File.WriteAllText(filename4, sb.ToString());

            sb = new StringBuilder();
            foreach (string size in zones.Tiles.Sizes)
            {
                sb.Append(Tiles.GetDescription(size));
                sb.AppendLine(" proc Table:");
                sb.AppendLine();
                sb.Append(Tiles.GetHeader(size));
                sb.AppendLine();
                int index = zones.Tiles.StartIndex;
                foreach (var tile in zones.Tiles.GetTilesForSize(size))
                {
                    var clut = zones.GetCLUTForCoordinate(bmp, tile.Y);
                    for (int h = 0; h < tile.VCount; h++)
                    {
                        int    ty = tile.Y + (h * tile.Height);
                        string hc = (h + 1).ToString();
                        for (int w = 0; w < tile.HCount; w++)
                        {
                            int    tx   = tile.X + (w * tile.Width);
                            string wc   = ((char)(65 + w)).ToString();
                            string name = (tile.Name ?? "").Trim() + " " + wc + hc;
                            sb.Append("  dh \"");
                            for (int yy = 0; yy < tile.Height; yy++)
                            {
                                int tyy = ty + yy;
                                for (int xx = 0; xx < (tile.Width / 2); xx++)
                                {
                                    int txx = tx + (xx * 2);
                                    var b   = exportImage.GetRadastanByte(txx, tyy);
                                    sb.Append(b.ToString("X2"));
                                }
                            }
                            sb.Append("\" ; ");
                            sb.Append(index.ToString().PadLeft(3));
                            sb.Append("  ");
                            sb.AppendLine(name);
                            index++;
                        }
                    }
                }
                sb.AppendLine();
                sb.AppendLine("  Length equ $-Table");
                sb.Append("  Size   equ ");
                sb.AppendLine(Tiles.GetLength(size).ToString());
                sb.AppendLine("  Count  equ Length/Size ");
                sb.AppendLine("pend");
                sb.AppendLine();
            }
            string filename5 = fileName.Replace(".png", "-tiles.asm");

            File.WriteAllText(filename5, sb.ToString());
        }
Esempio n. 6
0
        public TFSData Read(Stream stream)
        {
            TFSData tfsData = new TFSData();

            bitmapData = new Dictionary <int, Dictionary <int, int> >();

            tfsData.Header = new TFSHeader(stream);

            CLUT colorLookupTable = new CLUT();

            colorLookupTable.Width  = 256;
            colorLookupTable.Height = tfsData.Header.PaletteCount;

            var newLookupTable = new CLUTColor[colorLookupTable.Width, colorLookupTable.Height];

            for (var y = 0; y < colorLookupTable.Height; ++y)
            {
                for (var x = 0; x < colorLookupTable.Width; ++x)
                {
                    var data = stream.ReadUShort();
                    newLookupTable[x, y] = new CLUTColor(data);
                }
            }

            colorLookupTable.LookupTable = newLookupTable;
            tfsData.ColourLookupTable    = colorLookupTable;

            for (var tileIndex = 0;
                 tileIndex < (tfsData.Header.Width * tfsData.Header.Height);
                 ++tileIndex)
            {
                var tileData = new List <byte>();
                int tileX    = stream.ReadShort() * 2;
                int tileY    = stream.ReadShort();

                if (tileX < 0 || tileY < 0)
                {
                    continue;
                }

                for (var i = 0; i < (TILE_WIDTH * TILE_HEIGHT); ++i)
                {
                    tileData.Add((byte)stream.ReadByte());
                }

                var tileDataIndex = 0;

                for (var y = 0; y < TILE_HEIGHT; ++y)
                {
                    for (var x = 0; x < TILE_WIDTH; ++x)
                    {
                        if (!bitmapData.ContainsKey(x + tileX))
                        {
                            bitmapData[x + tileX] = new Dictionary <int, int>();
                        }

                        bitmapData[x + tileX][y + tileY] = tileData[tileDataIndex];
                        ++tileDataIndex;
                    }
                }
            }

            int imageDataWidth  = bitmapData.Keys.Max() + 1;
            int imageDataHeight = bitmapData[0].Keys.Max() + 1;

            short[,] imageData = new short[imageDataWidth, imageDataHeight];

            for (int y = 0; y < imageDataHeight; ++y)
            {
                for (int x = 0; x < imageDataWidth; ++x)
                {
                    var currentIndex = -1;

                    if (bitmapData.ContainsKey(x) && bitmapData[x].ContainsKey(y))
                    {
                        currentIndex = bitmapData[x][y];
                    }

                    imageData[x, y] = (byte)currentIndex;
                }
            }

            tfsData.ImageData = imageData;

            return(tfsData);
        }