예제 #1
0
파일: DDSPanel.cs 프로젝트: yakoder/s3pi
 /// <summary>
 /// Sets the DDS image for this <see cref="DDSPanel"/> from the given <paramref name="image"/>;
 /// if <paramref name="supportHSV"/> is passed and true (default is false), the image will
 /// support HSV shift operations.
 /// </summary>
 /// <param name="image">A <see cref="Bitmap"/> to display in this <see cref="DDSPanel"/>.</param>
 /// <param name="supportHSV">Optional; when true, HSV operations will be supported on the image.</param>
 public void DDSLoad(Bitmap image, bool supportHSV = false)
 {
     ddsFile.CreateImage(image, supportHSV);
     loaded          = true;
     this.supportHSV = supportHSV;
     ckb_CheckedChanged(null, null);
 }
예제 #2
0
파일: DDSPanel.cs 프로젝트: yakoder/s3pi
 /// <summary>
 /// Creates a mask with given <paramref name="maskChannels"/> active and of given <paramref name="width"/> and <paramref name="height"/>.
 /// </summary>
 /// <param name="maskChannels">Which channels in the mask should be activated.</param>
 /// <param name="width">Width of image.</param>
 /// <param name="height">Height of image.</param>
 public void CreateMask(MaskChannel maskChannels, int width, int height)
 {
     ClearMask();
     ddsMask = new DdsFile();
     ddsMask.CreateImage(
         MaskChannelToByte(maskChannels, MaskChannel.C1),
         MaskChannelToByte(maskChannels, MaskChannel.C2),
         MaskChannelToByte(maskChannels, MaskChannel.C3),
         MaskChannelToByte(maskChannels, MaskChannel.C4),
         width, height, false);
 }
예제 #3
0
파일: DDSPanel.cs 프로젝트: yakoder/s3pi
        /// <summary>
        /// Get a copy of the current DDS image as a <see cref="DdsFile"/>.
        /// </summary>
        /// <returns>A new <see cref="DdsFile"/> copy of the current DDS image.</returns>
        public DdsFile GetDdsFile()
        {
            if (!this.loaded || ddsFile == null)
            {
                return(null);
            }

            DdsFile res = new DdsFile();

            res.CreateImage(ddsFile, false);
            return(res);
        }
예제 #4
0
        private void UpdatePreview()
        {
            if (!Preview_checkBox.Checked)
            {
                return;
            }
            DdsFile previewDDS = new DdsFile();

            previewDDS.CreateImage(originalDDS, false);
            contrastTrackbarValue = PurifyAmount_trackBar.Value;
            brightTrackbarValue   = Brightness_trackBar.Value;
            previewDDS.SetPixels(AdjustColors);
            previewDDS.SetPixels(TatPreview);
            Preview_pictureBox.Image = previewDDS.Image;
            previewDDS.Dispose();
        }
예제 #5
0
 public PurifyOptions_form(DdsFile dds, Purify_options options)
 {
     InitializeComponent();
     updateChannels = new bool[] { options.Red, options.Green, options.Blue, options.Alpha };
     PurifyAmount_trackBar.Value  = options.Contrast;
     PurifyRed_checkBox.Checked   = options.Red;
     PurifyGreen_checkBox.Checked = options.Green;
     PurifyBlue_checkBox.Checked  = options.Blue;
     PurifyAlpha_checkBox.Checked = options.Alpha;
     Preview_checkBox.Checked     = options.Preview;
     originalDDS = new DdsFile();
     originalDDS.CreateImage(dds.Resize(new Size(350, 350)), false);
     contrastTrackbarValue = options.Contrast;
     brightTrackbarValue   = options.Brightness;
     UpdatePreview();
 }
예제 #6
0
        private void ViewSourcebutton_Click(object sender, EventArgs e)
        {
            if (ddsOriginal == null)
            {
                return;
            }
            DdsFile tmp = new DdsFile();

            tmp.CreateImage(ddsOriginal, false);
            DDSPanel dp = new DDSPanel();

            dp.DDSLoad(tmp);
            SourceImage_Form disp = new SourceImage_Form(dp);

            disp.Show();
        }
예제 #7
0
        private void TattooImageFile_button_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter          = ImageFilterOpen;
            openFileDialog1.Title           = "Select Image File";
            openFileDialog1.FilterIndex     = 1;
            openFileDialog1.CheckFileExists = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                TattooImageFile.Text = openFileDialog1.FileName;
            }
            else
            {
                return;
            }
            if (String.CompareOrdinal(TattooImageFile.Text, " ") <= 0 || !File.Exists(TattooImageFile.Text))
            {
                MessageBox.Show("You must select a compatible image file!");
                return;
            }

            dds = ImageHandler.OpenDDS(TattooImageFile.Text);
            if (dds == null)
            {
                return;
            }

            Wait_label.Visible = true;
            Wait_label.Refresh();

            ddsOriginal = new DdsFile();
            ddsOriginal.CreateImage(dds, false);

            if (dds.AlphaDepth == 0)
            {
                dds.UseDXT     = false;
                dds.AlphaDepth = 8;
                dds.SetPixels(ZeroAlpha);
            }

            Update_DDSdisplay();
        }
예제 #8
0
        private void ImagePaste_button_Click(object sender, EventArgs e)
        {
            Bitmap clip = (Bitmap)Clipboard.GetImage();

            if (clip == null)
            {
                return;
            }
            dds = new DdsFile();
            dds.CreateImage(clip, false);
            if (!Image.IsAlphaPixelFormat(clip.PixelFormat))
            {
                dds.UseDXT     = false;
                dds.AlphaDepth = 8;
                dds.SetPixels(ZeroAlpha);
            }
            ddsOriginal = new DdsFile();
            ddsOriginal.CreateImage(dds, false);
            Update_DDSdisplay();
        }
예제 #9
0
        private void TransformReset_button_Click(object sender, EventArgs e)
        {
            Wait_label.Visible = true;
            Wait_label.Refresh();

            dds.CreateImage(ddsOriginal, false);
            if (dds.AlphaDepth == 0)
            {
                dds.UseDXT     = false;
                dds.AlphaDepth = 8;
                dds.SetPixels(ZeroAlpha);
            }

            Update_DDSdisplay();
            Black2Red_radioButton.Checked    = false;
            PhotoConvert_radioButton.Checked = false;
            ReplaceAlpha_checkBox.Checked    = false;
            Black2Alpha_radioButton.Checked  = false;
            White2Alpha_radioButton.Checked  = false;
            BlankAlpha_radioButton.Checked   = false;
            White2Back_checkBox.Checked      = false;
        }
예제 #10
0
        internal void Update_DDSdisplay()
        {
            if (dds == null)
            {
                return;
            }
            Wait_label.Visible = true;
            Wait_label.Refresh();
            DdsFile preview = new DdsFile();

            preview.CreateImage(dds, false);
            preview.SetPixels(TatPreview);
            if (!preview.Size.Equals(new System.Drawing.Size(512, 512)))
            {
                preview = preview.Resize(new System.Drawing.Size(512, 512));
            }
            Preview_pictureBox.Image = preview.Image;
            preview.Dispose();
            Wait_label.Visible      = false;
            Preset1_button.Font     = (currentPreset == 0) ? new Font(Preset1_button.Font, FontStyle.Bold) : new Font(Preset1_button.Font, FontStyle.Regular);
            Preset2_button.Font     = (currentPreset == 1) ? new Font(Preset2_button.Font, FontStyle.Bold) : new Font(Preset2_button.Font, FontStyle.Regular);
            Preset3_button.Font     = (currentPreset == 2) ? new Font(Preset3_button.Font, FontStyle.Bold) : new Font(Preset3_button.Font, FontStyle.Regular);
            Resize_checkBox.Checked = !dds.Size.Equals(new System.Drawing.Size(512, 512));
        }
예제 #11
0
        private void openTattooPackageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter          = PackageFilter;
            openFileDialog1.Title           = "Select Tattoo Package File";
            openFileDialog1.FilterIndex     = 1;
            openFileDialog1.CheckFileExists = true;
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Package myPack;

            try
            {
                myPack = (Package)Package.OpenPackage(0, openFileDialog1.FileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot open package: " + openFileDialog1.FileName + " - Error is:" + System.Environment.NewLine +
                                ex.Message + System.Environment.NewLine + ex.InnerException);
                return;
            }

            Predicate <IResourceIndexEntry> isCASP   = r => r.ResourceType == (uint)ResourceTypes.CASP;
            List <IResourceIndexEntry>      CASPlist = myPack.FindAll(isCASP);

            if (CASPlist.Count == 0)
            {
                MessageBox.Show("No CASP files found in package!");
                Package.ClosePackage(0, (IPackage)myPack);
                return;
            }

            Predicate <IResourceIndexEntry> isKEY = r => r.ResourceType == (uint)ResourceTypes.KEY;
            IResourceIndexEntry             irKey = myPack.Find(isKEY);

            NameMapResource.NameMapResource nMap = null;
            if (irKey != null)
            {
                Stream n = myPack.GetResource(irKey);
                nMap = new NameMapResource.NameMapResource(0, n);
            }

            int numTattoos = 0;

            foreach (IResourceIndexEntry r in CASPlist)
            {
                Stream s = myPack.GetResource(r);
                s.Position = 0;
                CASPartResource.CASPartResource casp = new CASPartResource.CASPartResource(0, s);
                if (casp.Clothing == ClothingType.TattooTemplate)
                {
                    numTattoos++;
                    string tatName = "";
                    if (casp.Presets.Count > 0)
                    {
                        XmlDocument imp = new XmlDocument();
                        imp.LoadXml(casp.Presets[0].XmlFile.ReadToEnd());
                        XmlNodeList nodes = imp.GetElementsByTagName("value");
                        foreach (XmlNode n in nodes)
                        {
                            if (n.Attributes["key"].InnerXml.Contains("daeFileName"))
                            {
                                tatName = n.Attributes["value"].InnerXml;
                                break;
                            }
                        }
                    }
                    string tmp;
                    if (nMap != null && nMap.TryGetValue(r.Instance, out tmp))
                    {
                        tatName = tmp;
                    }
                    DialogResult res = MessageBox.Show("Open tattoo: " + tatName + "?", "Select Tattoo", MessageBoxButtons.YesNoCancel);
                    if (res == DialogResult.Yes)
                    {
                        bool gotImage = false;
                        for (int i = 0; i < Math.Min(casp.Presets.Count, 3); i++)
                        {
                            XmlDocument imp = new XmlDocument();
                            imp.LoadXml(casp.Presets[i].XmlFile.ReadToEnd());
                            XmlNodeList nodes = imp.GetElementsByTagName("value");
                            foreach (XmlNode n in nodes)
                            {
                                if (n.Attributes["key"].InnerXml.Contains("Layer1ColorR"))
                                {
                                    presets[i].rChannelColor = new Color(n.Attributes["value"].InnerXml);
                                }
                                else if (n.Attributes["key"].InnerXml.Contains("Layer1ColorG"))
                                {
                                    presets[i].gChannelColor = new Color(n.Attributes["value"].InnerXml);
                                }
                                else if (n.Attributes["key"].InnerXml.Contains("Layer1ColorB"))
                                {
                                    presets[i].bChannelColor = new Color(n.Attributes["value"].InnerXml);
                                }
                                else if (n.Attributes["key"].InnerXml.Contains("Layer1ColorA"))
                                {
                                    presets[i].aChannelColor = new Color(n.Attributes["value"].InnerXml);
                                }
                                else if (n.Attributes["key"].InnerXml.Contains("Layer1Mask") && !gotImage)
                                {
                                    string[] imgTgi = n.Attributes["value"].InnerXml.Split(':');
                                    Predicate <IResourceIndexEntry> isIMG;
                                    try
                                    {
                                        isIMG = ri => ri.ResourceType == UInt32.Parse(imgTgi[1], System.Globalization.NumberStyles.HexNumber) &
                                                ri.ResourceGroup == UInt32.Parse(imgTgi[2], System.Globalization.NumberStyles.HexNumber) &
                                                ri.Instance == UInt64.Parse(imgTgi[3], System.Globalization.NumberStyles.HexNumber);
                                    }
                                    catch
                                    {
                                        MessageBox.Show("Could not parse TGI of tattoo image!");
                                        return;
                                    }
                                    IResourceIndexEntry img = myPack.Find(isIMG);
                                    if (img != null)
                                    {
                                        Stream d = myPack.GetResource(img);
                                        d.Position = 0;
                                        dds        = new DdsFile();
                                        dds.Load(d, false);
                                        ddsOriginal = new DdsFile();
                                        ddsOriginal.CreateImage(dds, false);
                                        gotImage = true;
                                    }
                                }
                            }
                        }
                        if (!gotImage)
                        {
                            MessageBox.Show("Could not find tattoo image!");
                        }
                        bgColor = new Color(0x00D2B48Cu);
                        BGcolor_panel.BackColor = System.Drawing.Color.FromArgb(bgColor.Red, bgColor.Green, bgColor.Blue);
                        currentPreset           = 0;
                        PresetPrep();
                        Update_DDSdisplay();
                        TattooImageFile.Text = "";
                        Predicate <IResourceIndexEntry> isTHUM = ri => ri.ResourceType == (uint)ResourceTypes.THUM &
                                                                 ri.ResourceGroup == 1U & ri.Instance == r.Instance;
                        IResourceIndexEntry irThum = myPack.Find(isTHUM);
                        if (irThum != null)
                        {
                            Stream t = myPack.GetResource(irThum);
                            thumbNail = new Bitmap(t);
                        }
                        else
                        {
                            thumbNail = null;
                        }
                        TattooName.Text     = tatName;
                        TattooInstance.Text = r.Instance.ToString("X16");
                        AgeGenderFlags ag = casp.AgeGender;
                        CASPtodder_checkBox.Checked = ((ag.Age & AgeFlags.Toddler) > 0);
                        CASPchild_checkBox.Checked  = ((ag.Age & AgeFlags.Child) > 0);
                        CASPteen_checkBox.Checked   = ((ag.Age & AgeFlags.Teen) > 0);
                        CASPadult_checkBox.Checked  = ((ag.Age & AgeFlags.Adult) > 0);
                        CASPelder_checkBox.Checked  = ((ag.Age & AgeFlags.Elder) > 0);
                        CASPmale_checkBox.Checked   = ((ag.Gender & GenderFlags.Male) > 0);
                        CASPfemale_checkBox.Checked = ((ag.Gender & GenderFlags.Female) > 0);
                        CASPsortOrder.Text          = casp.SortPriority.ToString();
                        saveOptionsDDS = new DdsSaveOptions("DXT5", true, 90);
                        PhotoConvert_radioButton.Checked = false;
                        Black2Red_radioButton.Checked    = false;
                        Resize_checkBox.Checked          = false;
                        ReplaceAlpha_checkBox.Checked    = false;
                        Black2Alpha_radioButton.Checked  = true;
                        White2Alpha_radioButton.Checked  = false;
                        BlankAlpha_radioButton.Checked   = false;
                        invertAlpha_radioButton.Checked  = false;
                        White2Back_checkBox.Checked      = false;
                        break;
                    }
                    else if (res == DialogResult.No)
                    {
                        continue;
                    }
                    else
                    {
                        Package.ClosePackage(0, (IPackage)myPack);
                        return;
                    }
                }
            }

            if (numTattoos == 0)
            {
                MessageBox.Show("No tattoos found in package!");
            }
            Package.ClosePackage(0, (IPackage)myPack);
            // CASPartResource.CASPartResource casp =
        }
예제 #12
0
        private void TransformGo_button_Click(object sender, EventArgs e)
        {
            Wait_label.Visible = true;
            Wait_label.Refresh();

            dds.SetPixels(TatTransform);
            if (Black2Red_radioButton.Checked)
            {
                ChannelG_checkBox.Checked = false;
                ChannelB_checkBox.Checked = false;
                ChannelA_checkBox.Checked = false;
            }
            if (Black2Alpha_radioButton.Checked)
            {
                for (int i = 0; i < 3; i++)
                {
                    presets[i].aChannelHue = 0x00000000;
                    Presets_dataGridView.Rows[i].Cells["ChannelA"].Style.BackColor = presets[i].aChannelColor.SystemColor;
                }
            }
            else if (White2Alpha_radioButton.Checked)
            {
                for (int i = 0; i < 3; i++)
                {
                    presets[i].aChannelHue = 0x00FFFFFF;
                    Presets_dataGridView.Rows[i].Cells["ChannelA"].Style.BackColor = presets[i].aChannelColor.SystemColor;
                }
            }

            if (Resize_checkBox.Checked & !dds.Size.Equals(new Size(512, 512)))
            {
                Bitmap bits   = dds.GetImage(true, true, true, true, false);
                int    width  = bits.Width;
                int    height = bits.Height;

                float factorH = height / 512f;
                if (width == height)
                {
                    dds = dds.Resize(new Size(512, 512));
                }
                else if (width > height)
                {
                    float factor = 512f / width;
                    resizeSize = new Size(512, (int)(height * factor));
                    DdsFile tmp = new DdsFile();
                    tmp.CreateImage(dds, resizeSize.Width, resizeSize.Height, false);
                    resizePixels = tmp.GetImage(true, true, true, true, false).ToARGBData();
                    dds          = dds.Resize(new Size(512, 512));
                    dds.SetPixels(Resizer);
                }
                else if (width < height)
                {
                    float factor = 512f / height;
                    resizeSize = new Size((int)(width * factor), 512);
                    DdsFile tmp = new DdsFile();
                    tmp.CreateImage(dds, resizeSize.Width, resizeSize.Height, false);
                    resizePixels = tmp.GetImage(true, true, true, true, false).ToARGBData();
                    dds          = dds.Resize(new Size(512, 512));
                    dds.SetPixels(Resizer);
                }
            }

            Update_DDSdisplay();
        }