Exemple #1
0
        private void b_src_change_file_Click(object sender, EventArgs e)
        {
            if ((null != m_sel_header) && (1 == m_sel_items.Count))
            {
                ListViewItem li = m_sel_items[0];

                conv_core.cImageFile img = li.Tag as conv_core.cImageFile;
                conv_core.cFormat    fmt = conv_core.workbench.file_format(img.path);

                string all_files_format = "";
                string file_formats     = "";

                for (int sd = 0; conv_core.workbench.formats.count > sd; sd++)
                {
                    if (conv_core.workbench.formats[sd].has_reader)
                    {
                        all_files_format += ((0 == sd)? "" : ";") + "*." + conv_core.workbench.formats[sd].ext;
                        file_formats     += "|" + conv_core.workbench.formats[sd].desc + "|*." + conv_core.workbench.formats[sd].ext;
                    }
                    ;
                }
                ;

                dw_save.Title            = "Change file location";
                dw_save.InitialDirectory = Path.GetDirectoryName(img.path);
                dw_save.Filter           = ((0 < all_files_format.Length)? "all supported formats|" + all_files_format : "") + ((0 < file_formats.Length)? file_formats + "|" : "") + "any file|*.*";
                dw_save.FileName         = Path.GetFileName(img.path);
                dw_save.OverwritePrompt  = false;

                switch (dw_save.ShowDialog(this))
                {
                case DialogResult.OK:
                    if (dw_save.FileName != li.ToolTipText)
                    {
                        img.path       = dw_save.FileName;
                        li.Text        = Path.GetFileName(img.path);
                        li.ToolTipText = img.path;

                        if (fmt != conv_core.workbench.file_format(img.path))
                        {
                            img.options = null;
                        }
                        ;

                        t_mod.Enabled = true;
                        m_sel_header.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                    }
                    ;
                    break;
                }
                ;
            }
            ;
        }
Exemple #2
0
        bool load_images(string[] files)
        {
            if (ConvertProcessor.in_process)
            {
                return(false);
            }
            ;

            int included_count = 0;

            foreach (string file in files)
            {
                if (conv_core.workbench.valid_file(file) && !source_file_exists(file.ToLower()))
                {
                    ListViewItem li = lv_files.Items.Add("");
                    li.Name        = Path.GetFileNameWithoutExtension(file).ToLower();
                    li.Text        = Path.GetFileName(file).ToLower();
                    li.ToolTipText = file;
                    conv_core.cImageFile img = new conv_core.cImageFile(file);
                    li.Tag = img;
                    li.UseItemStyleForSubItems = false;

                    img.new_crc = img.crc = conv_core.workbench.file_crc(file);

                    foreach (ColumnHeader hdr in m_formats)
                    {
                        conv_core.cFormat            fmt = hdr.Tag as conv_core.cFormat;
                        ListViewItem.ListViewSubItem lsi = li.SubItems.Add(li.Name + "." + fmt.ext);
                        lsi.Tag = new conv_core.cImageFile(t_base_dir.Text + "\\" + lsi.Text);
                        hdr.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                    }
                    ;

                    included_count++;
                }
                ;
            }
            ;

            t_mod.Enabled |= 0 < included_count;
            return(0 < included_count);
        }
Exemple #3
0
        private bool build_image(conv_core.cImageFile img, conv_core.cFormat format, ToolStripButton button)
        {
            Bitmap bmp = new Bitmap(img.width, img.height, PixelFormat.Format32bppArgb);

            button.Tag = bmp;

            Rectangle  r  = new Rectangle(0, 0, img.width, img.height);
            BitmapData bd = bmp.LockBits(r, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            int[] img_row = new int[r.Width];

            unsafe {
                byte *bstr = (byte *)bd.Scan0.ToPointer();
                int   row  = 0;

                while (r.Height > row)
                {
                    img.get_row(row, img_row);
                    int *pix = (int *)bstr;

                    foreach (int pixel in img_row)
                    {
                        byte *ch    = (byte *)pix;
                        *     pix++ = pixel;

                        byte c = ch[0];
                        ch[0] = ch[2];
                        ch[2] = c;
                    }
                    ;

                    bstr += bd.Stride;
                    row++;
                }
                ;
            };

            bmp.UnlockBits(bd);

            return(true);
        }
Exemple #4
0
        public bool add_format(string name)
        {
            if (ConvertProcessor.in_process)
            {
                return(false);
            }
            ;

            if (0 > m_formats.FindIndex(delegate(ColumnHeader h) { return(name == h.Text); }))
            {
                conv_core.cFormat format = conv_core.workbench.formats[name];
                ColumnHeader      hdr    = lv_files.Columns.Add(name);
                m_formats.Add(hdr);
                hdr.Tag       = format;
                hdr.TextAlign = HorizontalAlignment.Center;
                hdr.AutoResize((0 < lv_files.Items.Count)? ColumnHeaderAutoResizeStyle.ColumnContent : ColumnHeaderAutoResizeStyle.None);

                return(true);
            }
            ;

            return(false);
        }
Exemple #5
0
        private void b_format_change_file_Click(object sender, EventArgs e)
        {
            if ((null != m_sel_header) && (0 < m_sel_subitems.Count))
            {
                if (2 > m_sel_subitems.Count)
                {
                    ListViewItem.ListViewSubItem lsi = m_sel_subitems[0];

                    conv_core.cFormat    fmt = m_sel_header.Tag as conv_core.cFormat;
                    conv_core.cImageFile img = lsi.Tag as conv_core.cImageFile;

                    dw_save.Title            = "Change file location";
                    dw_save.InitialDirectory = Path.GetDirectoryName(img.path);
                    dw_save.Filter           = fmt.desc + "|*." + fmt.ext;
                    dw_save.FileName         = Path.GetFileName(img.path);

                    switch (dw_save.ShowDialog(this))
                    {
                    case DialogResult.OK:
                        string new_path = conv_core.workbench.relative_path(t_base_dir.Text, dw_save.FileName);
                        if ((0 < new_path.Length) && (new_path != lsi.Text))
                        {
                            img.path = dw_save.FileName.ToLower();
                            lsi.Text = new_path;

                            t_mod.Enabled = true;
                            m_sel_header.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                        }
                        ;
                        break;
                    }
                    ;
                }
                else
                {
                    dw_dir.Description  = "Select new files location.";
                    dw_dir.SelectedPath = Path.GetDirectoryName((m_sel_subitems[0].Tag as conv_core.cImageFile).path);

                    switch (dw_dir.ShowDialog(this))
                    {
                    case DialogResult.OK:
                        foreach (ListViewItem.ListViewSubItem lsi in m_sel_subitems)
                        {
                            conv_core.cImageFile img = lsi.Tag as conv_core.cImageFile;
                            string file_name         = Path.GetFileName(img.path);
                            string new_path          = conv_core.workbench.relative_path(t_base_dir.Text, dw_dir.SelectedPath + "\\" + file_name);
                            if ((0 < new_path.Length) && (new_path != lsi.Text))
                            {
                                img.path = dw_dir.SelectedPath.ToLower() + "\\" + file_name;
                                lsi.Text = new_path;
                            }
                            ;
                        }
                        ;

                        t_mod.Enabled = true;
                        m_sel_header.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                        break;
                    }
                    ;
                };
            }
            ;
        }
Exemple #6
0
        private void b_export_list_Click(object sender, EventArgs e)
        {
            if (ConvertProcessor.in_process)
            {
                return;
            }
            ;

            ExportersListForm form = new ExportersListForm();

            for (int op = 0; conv_core.workbench.formats.count > op; op++)
            {
                conv_core.cFormat format = conv_core.workbench.formats[op];
                if (format.has_writer)
                {
                    form.m_all_items.Add(format.name);
                }
                ;
            }
            ;

            foreach (ColumnHeader hdr in m_formats)
            {
                form.m_selected_items.Add(hdr.Text);
            }
            ;

            switch (form.ShowDialog(this))
            {
            case DialogResult.OK: {
                int hdr_id = 0;
                while (m_formats.Count > hdr_id)
                {
                    ColumnHeader hdr = m_formats[hdr_id];
                    if (0 > form.m_selected_items.FindIndex(delegate(string str){ return(hdr.Text == str); }))
                    {
                        m_formats.Remove(hdr);

                        foreach (ListViewItem li in lv_files.Items)
                        {
                            li.SubItems.RemoveAt(hdr.Index);
                        }
                        ;

                        lv_files.Columns.Remove(hdr);

                        t_mod.Enabled = true;
                    }
                    else
                    {
                        hdr_id++;
                    };
                }
                ;

                foreach (string fmt in form.m_selected_items)
                {
                    if (0 > m_formats.FindIndex(delegate(ColumnHeader hdr) { return(fmt == hdr.Text); }))
                    {
                        conv_core.cFormat format = conv_core.workbench.formats[fmt];

                        foreach (ListViewItem li in lv_files.Items)
                        {
                            ListViewItem.ListViewSubItem lsi = li.SubItems.Add(
                                Path.GetFileNameWithoutExtension(li.Text) + "." + format.ext
                                );
                            lsi.Tag = new conv_core.cImageFile(t_base_dir.Text + "\\" + lsi.Text);
                        }
                        ;

                        add_format(fmt);

                        t_mod.Enabled = true;
                    }
                    ;
                }
                ;
            } break;
            }
            ;

            form.Dispose();
        }
Exemple #7
0
        private static void thread_routine(object reference)
        {
            List <ListViewItem> pool = reference as List <ListViewItem>;
            bool do_cancel           = false;

            lock ( m_form ){
                do_cancel = m_cancel;
            };

            while (!do_cancel && (0 < pool.Count))
            {
                bool mod_flag = true;
                bool do_mod   = false;

                ListViewItem         li      = pool.First();
                conv_core.cImageFile src_img = li.Tag as conv_core.cImageFile;

                if (src_img.enabled)
                {
                    int coverted = 0;
                    foreach (ColumnHeader hdr in m_form.m_formats)
                    {
                        if (!(li.SubItems[hdr.Index].Tag as conv_core.cImageFile).enabled)
                        {
                            li.SubItems[hdr.Index].BackColor = MainForm.cell_back_disabled;
                            coverted++;
                            continue;
                        }
                        ;

                        conv_core.cFormat            fmt = hdr.Tag as conv_core.cFormat;
                        ListViewItem.ListViewSubItem lsi = li.SubItems[hdr.Index];
                        if (fmt.convert(src_img, lsi.Tag as conv_core.cImageFile))
                        {
                            lsi.BackColor = Color.LightGreen;
                            coverted++;
                        }
                        else
                        {
                            lsi.BackColor = Color.LightPink;
                        };
                    }
                    ;

                    if (m_form.m_formats.Count == coverted)
                    {
                        li.BackColor = MainForm.cell_back_done;

                        if (mod_flag && (src_img.crc != src_img.new_crc))
                        {
                            do_mod = true;
                        }
                        ;

                        src_img.crc = src_img.new_crc;
                    }
                    else if (src_img.crc == src_img.new_crc)
                    {
                        li.BackColor = MainForm.cell_back_error;
                    }
                    ;

                    src_img.close();
                }
                ;

                pool.RemoveAt(0);

                lock ( m_form ){
                    m_form.Invoke(new Action(() => {
                        m_form.pb_progress.PerformStep();
                    }));

                    if (mod_flag && do_mod)
                    {
                        m_form.Invoke(new Action(() => {
                            m_form.t_mod.Enabled = true;
                        }));
                        mod_flag = false;
                    }
                    ;

                    do_cancel = m_cancel;
                };
            }
            ;
        }
Exemple #8
0
        public static bool load(string path, MainForm form)
        {
            try{
                XmlDocument file = new XmlDocument();

                file.Load(path);

                form.t_base_dir.Text = file["project"].Attributes["destination"].Value.ToLower();

                if ('\\' == form.t_base_dir.Text.Last())
                {
                    form.t_base_dir.Text = form.t_base_dir.Text.Remove(form.t_base_dir.Text.Length - 1);
                }
                ;

                XmlElement formats = file["project"]["formats"];
                XmlElement files   = file["project"]["files"];

                foreach (XmlElement fmt in formats.ChildNodes)
                {
                    form.add_format(fmt.Attributes["name"].Value);
                }
                ;

                foreach (XmlElement fd in files.ChildNodes)
                {
                    if (conv_core.workbench.valid_file(fd.Attributes["file.path"].Value))
                    {
                        bool                 check_crc = fd.HasAttribute("file.crc");
                        ListViewItem         li        = form.lv_files.Items.Add("");
                        conv_core.cImageFile fid       = new conv_core.cImageFile(fd.Attributes["file.path"].Value);

                        li.ToolTipText             = fid.path.ToLower();
                        li.Name                    = Path.GetFileNameWithoutExtension(li.ToolTipText).ToLower();
                        li.Text                    = Path.GetFileName(li.ToolTipText).ToLower();
                        li.Tag                     = fid;
                        fid.enabled                = Convert.ToBoolean(fd.Attributes["file.enabled"].Value);
                        fid.crc                    = (check_crc)? Convert.ToUInt32(fd.Attributes["file.crc"].Value) : conv_core.workbench.file_crc(fid.path);
                        li.ForeColor               = (fid.enabled)? MainForm.cell_font_normal : MainForm.cell_font_disabled;
                        li.UseItemStyleForSubItems = false;

                        if ((null != fd.Attributes["file.format"]) && Convert.ToBoolean(fd.Attributes["file.format"].Value))
                        {
                            //fid.options =
                        }
                        ;

                        if (check_crc)
                        {
                            fid.new_crc = conv_core.workbench.file_crc(fid.path);
                            if (fid.crc != fid.new_crc)
                            {
                                li.BackColor = MainForm.cell_back_modified;
                            }
                            ;
                        }
                        else
                        {
                            fid.new_crc        = fid.crc;
                            form.t_mod.Enabled = true;
                        };

                        foreach (ColumnHeader hdr in form.m_formats)
                        {
                            XmlElement convert = null;
                            foreach (XmlElement cvt in fd.ChildNodes)
                            {
                                if (hdr.Text == cvt.Attributes["format"].Value)
                                {
                                    convert = cvt;
                                    break;
                                }
                                ;
                            }
                            ;

                            conv_core.cFormat fmt = hdr.Tag as conv_core.cFormat;
                            if (null == convert)
                            {
                                ListViewItem.ListViewSubItem lsi = li.SubItems.Add(li.Name + "." + fmt.ext);
                                lsi.Tag = new conv_core.cImageFile(form.t_base_dir.Text + "\\" + lsi.Text);
                            }
                            else
                            {
                                string conv_name = convert.Attributes["destination"].Value;
                                if ('\\' == conv_name[0])
                                {
                                    conv_name = conv_name.Remove(0, 1);
                                }
                                ;

                                ListViewItem.ListViewSubItem lsi = li.SubItems.Add(conv_name);
                                conv_core.cImageFile         img = new conv_core.cImageFile(form.t_base_dir.Text + "\\" + lsi.Text);
                                lsi.Tag       = img;
                                img.enabled   = Convert.ToBoolean(convert.Attributes["enabled"].Value);
                                lsi.ForeColor = Color.FromArgb((int)((img.enabled)? 0xFF000000 : 0xFF666666));

                                if (0 < convert.ChildNodes.Count)
                                {
                                    img.options = fmt.writer_options_desc.create_options();
                                    foreach (XmlElement prop in convert.ChildNodes)
                                    {
                                        if ("property" != prop.Name)
                                        {
                                            continue;
                                        }
                                        ;

                                        string op_name = prop.Attributes["name"].Value;
                                        if (null != img.options[op_name])
                                        {
                                            conv_core.cOption opt = img.options[op_name];
                                            switch (img.options.desc[op_name].type)
                                            {
                                            case conv_core.OptionType.STRING:
                                                opt.value_str = prop.Attributes["value"].Value;
                                                break;

                                            default:
                                                opt.value = Convert.ToInt32(prop.Attributes["value"].Value);
                                                break;
                                            }
                                            ;
                                        }
                                        ;
                                    }
                                    ;
                                }
                                ;
                            };
                        }
                        ;
                    }
                    ;
                }
                ;

                foreach (ColumnHeader hdr in form.m_formats)
                {
                    hdr.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                }
                ;
            }catch (Exception) {
                return(false);
            };

            return(true);
        }
Exemple #9
0
        public void set_imagelist(ListViewItem li)
        {
            conv_core.cImageFile src_img = li.Tag as conv_core.cImageFile;
            conv_core.cFormat    src_fmt = conv_core.workbench.file_format(src_img.path);

            if (!src_img.open())
            {
                return;
            }
            ;

            ToolStripButton img_btn  = new ToolStripButton(src_fmt.name, null, null, src_fmt.name);
            ToolStripButton diff_btn = new ToolStripButton(src_fmt.name, null, null, src_fmt.name);

            diff_btn.Width        = img_btn.Width = 23;
            diff_btn.Height       = img_btn.Height = 22;
            diff_btn.DisplayStyle = img_btn.DisplayStyle = ToolStripItemDisplayStyle.Text;
            diff_btn.CheckOnClick = img_btn.CheckOnClick = true;
            img_btn.Click        += views_handler;
            diff_btn.Click       += diffs_handler;

            build_image(src_img, src_fmt, img_btn);
            diff_btn.Tag = img_btn.Tag;
            ts_views.Items.Add(img_btn);
            ts_diffs.Items.Add(diff_btn);

            for (int id = 1; li.SubItems.Count > id; id++)
            {
                conv_core.cImageFile img = li.SubItems[id].Tag as conv_core.cImageFile;
                conv_core.cFormat    fmt = conv_core.workbench.file_format(img.path);

                img_btn               = new ToolStripButton(fmt.name, null, null, fmt.name);
                diff_btn              = new ToolStripButton(fmt.name, null, null, fmt.name);
                diff_btn.Width        = img_btn.Width = 23;
                diff_btn.Height       = img_btn.Height = 22;
                diff_btn.DisplayStyle = img_btn.DisplayStyle = ToolStripItemDisplayStyle.Text;
                diff_btn.CheckOnClick = img_btn.CheckOnClick = true;
                img_btn.Click        += views_handler;
                diff_btn.Click       += diffs_handler;

                if (!img.open())
                {
                    if (fmt.convert(src_img, img))
                    {
                        img.open();
                    }
                    else
                    {
                        break;
                    };
                }
                ;

                build_image(img, fmt, img_btn);
                diff_btn.Tag = img_btn.Tag;
                img.close();

                ts_views.Items.Add(img_btn);
                ts_diffs.Items.Add(diff_btn);
            }
            ;

            m_view = new Bitmap(src_img.width, src_img.height, PixelFormat.Format32bppArgb);
            src_img.close();

            Graphics gr = Graphics.FromImage(m_view);

            gr.Clear(Color.FromArgb(0x00FF, 0, 0, 0));
            gr.Dispose();
            img_view.Width  = m_view.Width;
            img_view.Height = m_view.Height;

            m_current_diff = ts_diffs.Items[0].Tag as Bitmap;
            m_current_view = ts_views.Items[0].Tag as Bitmap;
            (ts_views.Items[0] as ToolStripButton).Checked = true;
            (ts_diffs.Items[0] as ToolStripButton).Checked = true;
        }