コード例 #1
0
ファイル: FileTypes.cs プロジェクト: nkaligin/paint-mono
        private static Type[] GetFileTypeFactoriesFromAssemblies(ICollection assemblies)
        {
            List<Type> allFactories = new List<Type>();

            foreach (Assembly assembly in assemblies)
            {
                Type[] factories;

                try
                {
                    factories = GetFileTypeFactoriesFromAssembly(assembly);
                }

                catch (Exception)
                {
                    continue;
                }

                foreach (Type type in factories)
                {
                    allFactories.Add(type);
                }
            }

            return allFactories.ToArray();
        }
コード例 #2
0
        protected override PropertyCollection OnCreatePropertyCollection()
        {
            List<Property> propsBuilder = new List<Property>();
            propsBuilder.Add(new DoubleProperty("X", 0.3, 0, 1));
            propsBuilder.Add(new DoubleProperty("Y", 0.5, 0, 1));
            propsBuilder.Add(new DoubleProperty("Z", 0.11, 0, 1));

            return new PropertyCollection(propsBuilder.ToArray());
        }
コード例 #3
0
ファイル: FileTypes.cs プロジェクト: herbqiao/paint.net
        private static Type[] GetFileTypeFactoriesFromAssembly(Assembly assembly)
        {
            List<Type> fileTypeFactories = new List<Type>();

            foreach (Type type in assembly.GetTypes())
            {
                if (IsInterfaceImplemented(type, typeof(IFileTypeFactory)) && !type.IsAbstract)
                {
                    fileTypeFactories.Add(type);
                }
            }

            return fileTypeFactories.ToArray();
        }
コード例 #4
0
ファイル: UserBlendOps.cs プロジェクト: nkaligin/paint-mono
        /// <summary>
        /// Returns an array of Type objects that lists all of the pixel ops contained
        /// within this class. You can then use Utility.GetStaticName to retrieve the
        /// value of the StaticName property.
        /// </summary>
        /// <returns></returns>
        public static Type[] GetBlendOps()
        {
            Type[] allTypes = typeof(UserBlendOps).GetNestedTypes();
            List<Type> types = new List<Type>(allTypes.Length);

            foreach (Type type in allTypes)
            {
                if (type.IsSubclassOf(typeof(UserBlendOp)) && !type.IsAbstract)
                {
                    types.Add(type);
                }
            }

            return types.ToArray();
        }
コード例 #5
0
ファイル: PdnResources.cs プロジェクト: nkaligin/paint-mono
        public static string[] GetLocaleNameChain()
        {
            List<string> names = new List<string>();
            CultureInfo ci = pdnCulture;

            while (ci.Name != string.Empty)
            {
                names.Add(ci.Name);
                ci = ci.Parent;
            }

            return names.ToArray();
        }
コード例 #6
0
ファイル: PdnResources.cs プロジェクト: nkaligin/paint-mono
        public static string[] GetInstalledLocales()
        {
            const string left = "PaintDotNet.Strings.3";
            const string right = ".resources";
            string ourDir = ResourcesDir;
            string fileSpec = left + "*" + right;
            string[] pathNames = Directory.GetFiles(ourDir, fileSpec);
            List<String> locales = new List<string>();

            for (int i = 0; i < pathNames.Length; ++i)
            {
                string pathName = pathNames[i];
                string dirName = Path.GetDirectoryName(pathName);
                string fileName = Path.GetFileName(pathName);
                string sansRight = fileName.Substring(0, fileName.Length - right.Length);
                string sansLeft = sansRight.Substring(left.Length);

                string locale;

                if (sansLeft.Length > 0 && sansLeft[0] == '.')
                {
                    locale = sansLeft.Substring(1);
                }
                else if (sansLeft.Length == 0)
                {
                    locale = "en-US";
                }
                else
                {
                    locale = sansLeft;
                }

                try
                {
                    // Ensure this locale can create a valid CultureInfo object.
                    CultureInfo ci = new CultureInfo(locale);
                }

                catch (Exception)
                {
                    // Skip past invalid locales -- don't let them crash us
                    continue;
                }

                locales.Add(locale);
            }

            return locales.ToArray();
        }
コード例 #7
0
        public override void PerformAction(AppWorkspace appWorkspace)
        {
            DocumentWorkspace originalDW = appWorkspace.ActiveDocumentWorkspace;

            int oldLatency = 10;

            try
            {
                oldLatency = appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency;
                appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency = 0;
            }

            catch (NullReferenceException)
            {
                // See bug #2544
            }

            List<DocumentWorkspace> unsavedDocs = new List<DocumentWorkspace>();
            foreach (DocumentWorkspace dw in appWorkspace.DocumentWorkspaces)
            {
                if (dw.Document != null && dw.Document.Dirty)
                {
                    unsavedDocs.Add(dw);
                }
            }

            if (unsavedDocs.Count == 1)
            {
                CloseWorkspaceAction cwa = new CloseWorkspaceAction(unsavedDocs[0]);
                cwa.PerformAction(appWorkspace);
                this.cancelled = cwa.Cancelled;
            }
            else if (unsavedDocs.Count > 1)
            {
                using (UnsavedChangesDialog dialog = new UnsavedChangesDialog())
                {
                    dialog.DocumentClicked += (s, e2) => { appWorkspace.ActiveDocumentWorkspace = e2.Data; };

                    dialog.Documents = unsavedDocs.ToArray();

                    if (appWorkspace.ActiveDocumentWorkspace.Document.Dirty)
                    {
                        dialog.SelectedDocument = appWorkspace.ActiveDocumentWorkspace;
                    }

                    Form mainForm = appWorkspace.FindForm();
                    if (mainForm != null)
                    {
                        PdnBaseForm asPDF = mainForm as PdnBaseForm;

                        if (asPDF != null)
                        {
                            asPDF.RestoreWindow();
                        }
                    }

                    DialogResult dr = Utility.ShowDialog(dialog, appWorkspace);

                    switch (dr)
                    {
                        case DialogResult.Yes:
                            {
                                foreach (DocumentWorkspace dw in unsavedDocs)
                                {
                                    appWorkspace.ActiveDocumentWorkspace = dw;
                                    bool result = dw.DoSave();

                                    if (result)
                                    {
                                        appWorkspace.RemoveDocumentWorkspace(dw);
                                    }
                                    else
                                    {
                                        this.cancelled = true;
                                        break;
                                    }
                                }
                            }
                            break;

                        case DialogResult.No:
                            this.cancelled = false;
                            break;

                        case DialogResult.Cancel:
                            this.cancelled = true;
                            break;

                        default:
                            throw new InvalidEnumArgumentException();
                    }
                }
            }

            try
            {
                appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency = oldLatency;
            }

            catch (NullReferenceException)
            {
                // See bug #2544
            }

            if (this.cancelled)
            {
                if (appWorkspace.ActiveDocumentWorkspace != originalDW &&
                    !originalDW.IsDisposed)
                {
                    appWorkspace.ActiveDocumentWorkspace = originalDW;
                }
            }
            else
            {
                UI.SuspendControlPainting(appWorkspace);
                
                foreach (DocumentWorkspace dw in appWorkspace.DocumentWorkspaces)
                {
                    appWorkspace.RemoveDocumentWorkspace(dw);
                }

                UI.ResumeControlPainting(appWorkspace);
                appWorkspace.Invalidate(true);
            }
        }
コード例 #8
0
        int NativeInterfaces.IFileDialogEvents.OnFileOk(NativeInterfaces.IFileDialog pfd)
        {
            int hr = NativeConstants.S_OK;

            NativeInterfaces.IShellItemArray results = null;
            FileOpenDialog.GetResults(out results);

            uint count = 0;
            results.GetCount(out count);

            List<NativeInterfaces.IShellItem> items = new List<NativeInterfaces.IShellItem>();
            List<NativeInterfaces.IShellItem> needLocalCopy = new List<NativeInterfaces.IShellItem>();
            List<NativeInterfaces.IShellItem> cannotCopy = new List<NativeInterfaces.IShellItem>();
            List<string> localPathNames = new List<string>();

            for (uint i = 0; i < count; ++i)
            {
                NativeInterfaces.IShellItem item = null;
                results.GetItemAt(i, out item);
                items.Add(item);
            }

            foreach (NativeInterfaces.IShellItem item in items)
            {
                // If it's a file system object, nothing special needs to be done.
                NativeConstants.SFGAO sfgaoAttribs;
                item.GetAttributes((NativeConstants.SFGAO)0xffffffff, out sfgaoAttribs);

                if ((sfgaoAttribs & NativeConstants.SFGAO.SFGAO_FILESYSTEM) == NativeConstants.SFGAO.SFGAO_FILESYSTEM)
                {
                    string pathName = null;
                    item.GetDisplayName(NativeConstants.SIGDN.SIGDN_FILESYSPATH, out pathName);

                    localPathNames.Add(pathName);
                }
                else if ((sfgaoAttribs & NativeConstants.SFGAO.SFGAO_STREAM) == NativeConstants.SFGAO.SFGAO_STREAM)
                {
                    needLocalCopy.Add(item);
                }
                else
                {
                    cannotCopy.Add(item);
                }
            }

            Marshal.ReleaseComObject(results);
            results = null;

            if (needLocalCopy.Count > 0)
            {
                IntPtr hwnd = IntPtr.Zero;
                NativeInterfaces.IOleWindow oleWindow = (NativeInterfaces.IOleWindow)pfd;
                oleWindow.GetWindow(out hwnd);
                Win32Window win32Window = new Win32Window(hwnd, oleWindow);

                IFileTransferProgressEvents progressEvents = this.FileDialogUICallbacks.CreateFileTransferProgressEvents();

                ThreadStart copyThreadProc =
                    delegate()
                    {
                        try
                        {
                            progressEvents.SetItemCount(needLocalCopy.Count);

                            for (int i = 0; i < needLocalCopy.Count; ++i)
                            {
                                NativeInterfaces.IShellItem item = needLocalCopy[i];

                                string pathName = null;

                                progressEvents.SetItemOrdinal(i);
                                CopyResult result = CreateLocalCopy(item, progressEvents, out pathName);

                                if (result == CopyResult.Success)
                                {
                                    localPathNames.Add(pathName);
                                }
                                else if (result == CopyResult.Skipped)
                                {
                                    // do nothing
                                }
                                else if (result == CopyResult.CancelOperation)
                                {
                                    hr = NativeConstants.S_FALSE;
                                    break;
                                }
                                else
                                {
                                    throw new InvalidEnumArgumentException();
                                }
                            }
                        }

                        finally
                        {
                            OperationResult result;

                            if (hr == NativeConstants.S_OK)
                            {
                                result = OperationResult.Finished;
                            }
                            else
                            {
                                result = OperationResult.Canceled;
                            }

                            progressEvents.EndOperation(result);
                        }
                    };

                Thread copyThread = new Thread(copyThreadProc);
                copyThread.SetApartmentState(ApartmentState.STA);

                EventHandler onUIShown =
                    delegate(object sender, EventArgs e)
                    {
                        copyThread.Start();
                    };

                this.cancelSink = new CancelableTearOff();
                progressEvents.BeginOperation(win32Window, onUIShown, cancelSink);
                this.cancelSink = null;
                copyThread.Join();

                Marshal.ReleaseComObject(oleWindow);
                oleWindow = null;
            }

            this.FileNames = localPathNames.ToArray();

            // If they selected a bunch of files, and then they all errored or something, then don't proceed.
            if (this.FileNames.Length == 0)
            {
                hr = NativeConstants.S_FALSE;
            }

            foreach (NativeInterfaces.IShellItem item in items)
            {
                Marshal.ReleaseComObject(item);
            }

            items.Clear();
            items = null;

            GC.KeepAlive(pfd);
            return hr;
        }
コード例 #9
0
            private WorkItemFailureAction ShowFileTransferFailedDialog(Exception ex)
            {
                WorkItemFailureAction result;
                Icon formIcon = this.progressDialog.Icon;

                string formTitle = PdnResources.GetString("DocumentWorkspace.ShowFileDialog.ItemFailureDialog.Title");

                Image taskImage = PdnResources.GetImageResource("Icons.WarningIcon.png").Reference;

                string introTextFormat = PdnResources.GetString("DocumentWorkspace.ShowFileDialog.ItemFailureDialog.IntroText.Format");
                string introText = string.Format(introTextFormat, ex.Message);

                TaskButton retryTB = new TaskButton(
                    PdnResources.GetImageResource("Icons.MenuImageRotate90CWIcon.png").Reference,
                    PdnResources.GetString("DocumentWorkspace.ShowFileDialog.RetryTB.ActionText"),
                    PdnResources.GetString("DocumentWorkspace.ShowFileDialog.RetryTB.ExplanationText"));

                TaskButton skipTB = new TaskButton(
                    PdnResources.GetImageResource("Icons.HistoryFastForwardIcon.png").Reference,
                    PdnResources.GetString("DocumentWorkspace.ShowFileDialog.SkipTB.ActionText"),
                    PdnResources.GetString("DocumentWorkspace.ShowFileDialog.SkipTB.ExplanationText"));

                TaskButton cancelTB = new TaskButton(
                    PdnResources.GetImageResource("Icons.CancelIcon.png").Reference,
                    PdnResources.GetString("DocumentWorkspace.ShowFileDialog.CancelTB.ActionText"),
                    PdnResources.GetString("DocumentWorkspace.ShowFileDialog.CancelTB.ExplanationText"));

                List<TaskButton> taskButtons = new List<TaskButton>();
                taskButtons.Add(retryTB);

                // Only have the Skip button if there is more than 1 item being transferred.
                // If only 1 item is begin transferred, Skip and Cancel are essentially synonymous.
                if (this.itemCount > 1)
                {
                    taskButtons.Add(skipTB);
                }

                taskButtons.Add(cancelTB);

                int width96 = (TaskDialog.DefaultPixelWidth96Dpi * 4) / 3; // 33% wider

                TaskButton clickedTB = TaskDialog.Show(
                    this.progressDialog,
                    formIcon,
                    formTitle,
                    taskImage,
                    true,
                    introText,
                    taskButtons.ToArray(),
                    retryTB,
                    cancelTB,
                    width96);

                if (clickedTB == retryTB)
                {
                    result = WorkItemFailureAction.RetryItem;
                }
                else if (clickedTB == skipTB)
                {
                    result = WorkItemFailureAction.SkipItem;
                }
                else
                {
                    result = WorkItemFailureAction.CancelOperation;
                }

                return result;
            }
コード例 #10
0
ファイル: ToolConfigStrip.cs プロジェクト: Yaro77/paint.net
        private void PenDashStyleButton_DropDownOpening(object sender, EventArgs e)
        {
            List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();

            foreach (DashStyle dashStyle in this.dashStyles)
            {
                ToolStripMenuItem mi = new ToolStripMenuItem(
                    this.dashStyleLocalizer.EnumValueToLocalizedName(dashStyle),
                    GetDashStyleImage(dashStyle),
                    delegate(object sender2, EventArgs e2)
                    {
                        ToolStripMenuItem tsmi = (ToolStripMenuItem)sender2;
                        DashStyle newDashStyle = (DashStyle)tsmi.Tag;

                        PenInfo newPenInfo = PenInfo.Clone();
                        newPenInfo.DashStyle = newDashStyle;
                        PenInfo = newPenInfo;
                    });

                mi.ImageScaling = ToolStripItemImageScaling.None;

                if (dashStyle == PenInfo.DashStyle)
                {
                    mi.Checked = true;
                }

                mi.Tag = dashStyle;
                menuItems.Add(mi);
            }

            this.penDashStyleSplitButton.DropDownItems.Clear();
            this.penDashStyleSplitButton.DropDownItems.AddRange(menuItems.ToArray());
        }
コード例 #11
0
ファイル: ColorsForm.cs プロジェクト: metadeta96/openpdn
        private void SwatchControl_ColorClicked(object sender, EventArgs<Pair<int, MouseButtons>> e)
        {
            List<ColorBgra> colors = new List<ColorBgra>(this.swatchControl.Colors);

            if (this.colorAddButton.Checked)
            {
                colors[e.Data.First] = GetColorFromUpDowns();
                this.swatchControl.Colors = colors.ToArray();
                this.colorAddButton.Checked = false;
                this.swatchControl.BlinkHighlight = false;
            }
            else
            {
                ColorBgra color = colors[e.Data.First];

                if (e.Data.Second == MouseButtons.Right)
                {
                    SetUserColors(UserPrimaryColor, color);
                }
                else
                {
                    switch (this.WhichUserColor)
                    {
                        case WhichUserColor.Primary:
                            this.UserPrimaryColor = color;
                            break;

                        case WhichUserColor.Secondary:
                            this.UserSecondaryColor = color;
                            break;

                        default:
                            throw new InvalidEnumArgumentException();
                    }
                }
            }

            OnRelinquishFocus();
        }
コード例 #12
0
        internal Rectangle[] SliceRectangles(Rectangle[] rois)
        {
            if (rois.Length == 0 || (this.MaximumRegionHeight == 0 && this.MaximumRegionWidth == 0))
                return rois;

            // Re-slice regions
            List<Rectangle> sizedRegions = new List<Rectangle>();
            Rectangle[] rectCopy = rois;

            // Resize width
            foreach (Rectangle rect in rectCopy)
            {
                if (this.MaximumRegionWidth > 0 && rect.Width > this.MaximumRegionWidth)
                {
                    int sliceCount = (int)Math.Ceiling((double)rect.Width / (double)this.MaximumRegionWidth);

                    for (int i = 0; i < sliceCount; i++)
                    {
                        if (i < sliceCount - 1)
                        {
                            sizedRegions.Add(new Rectangle(rect.X + (this.MaximumRegionWidth * i), rect.Y, this.MaximumRegionWidth, rect.Height));
                        }
                        else
                        {
                            int remainingWidth = rect.Width - this.MaximumRegionWidth * (sliceCount - 1);
                            sizedRegions.Add(new Rectangle(rect.Right - remainingWidth, rect.Y, remainingWidth, rect.Height));
                        }
                    }
                }
                else
                {
                    sizedRegions.Add(rect);
                }
            }

            rectCopy = sizedRegions.ToArray();
            sizedRegions.Clear();

            // Resize height
            foreach (Rectangle rect in rectCopy)
            {
                if (this.MaximumRegionHeight > 0 && rect.Height > this.MaximumRegionHeight)
                {
                    int sliceCount = (int)Math.Ceiling((double)rect.Height / (double)this.MaximumRegionHeight);

                    for (int i = 0; i < sliceCount; i++)
                    {
                        if (i < sliceCount - 1)
                        {
                            sizedRegions.Add(new Rectangle(rect.X, rect.Y + (this.MaximumRegionHeight * i), rect.Width, this.MaximumRegionHeight));
                        }
                        else
                        {
                            int remainingHeight = rect.Height - this.MaximumRegionHeight * (sliceCount - 1);
                            sizedRegions.Add(new Rectangle(rect.X, rect.Bottom - remainingHeight, rect.Width, remainingHeight));
                        }
                    }
                }
                else
                {
                    sizedRegions.Add(rect);
                }
            }

            return sizedRegions.ToArray();
        }
コード例 #13
0
        protected override PropertyCollection OnCreatePropertyCollection()
        {
            List<Property> props = new List<Property>();

            props.Add(new StringProperty(PropertyNames.Amount1, "", 255));
            props.Add(new Int32Property(PropertyNames.Amount2, 100, 1, 1000));
            props.Add(new Int32Property(PropertyNames.Amount3, 12, 6, 250));
            FontFamily[] intstalledFontFamilies = new InstalledFontCollection().Families;
            List<FontFamily> usableFonts = new List<FontFamily>();
            foreach (FontFamily font in intstalledFontFamilies)
            {
                if (font.IsStyleAvailable(FontStyle.Regular))
                    usableFonts.Add(font);
            }
            FontFamily[] Amount4FontFamilies = usableFonts.ToArray();
            props.Add(new StaticListChoiceProperty(PropertyNames.Amount4, Amount4FontFamilies, 0, false));
            props.Add(new BooleanProperty(PropertyNames.Amount5, false));
            props.Add(new BooleanProperty(PropertyNames.Amount6, false));
            props.Add(new BooleanProperty(PropertyNames.Amount7, false));
            props.Add(new BooleanProperty(PropertyNames.Amount8, false));
            props.Add(new DoubleVectorProperty(PropertyNames.Amount9, Pair.Create(0.0, 0.0), Pair.Create(-1.0, -1.0), Pair.Create(+1.0, +1.0)));
            props.Add(new Int32Property(PropertyNames.Amount10, ColorBgra.ToOpaqueInt32(ColorBgra.FromBgra(EnvironmentParameters.PrimaryColor.B, EnvironmentParameters.PrimaryColor.G, EnvironmentParameters.PrimaryColor.R, 255)), 0, 0xffffff));

            return new PropertyCollection(props);
        }
コード例 #14
0
ファイル: PdnResources.cs プロジェクト: nkaligin/paint-mono
        private static string[] GetLocaleDirs()
        {
            const string rootDirName = "Resources";
            string appDir = ResourcesDir;
            string rootDir = Path.Combine(appDir, rootDirName);
            List<string> dirs = new List<string>();

            CultureInfo ci = pdnCulture;

            while (ci.Name != string.Empty)
            {
                string localeDir = Path.Combine(rootDir, ci.Name);

                if (Directory.Exists(localeDir))
                {
                    dirs.Add(localeDir);
                }

                ci = ci.Parent;
            }

            return dirs.ToArray();
        }
コード例 #15
0
ファイル: ToolConfigStrip.cs プロジェクト: Yaro77/paint.net
        private void PenCapSplitButton_DropDownOpening(object sender, EventArgs e)
        {
            ToolStripSplitButton splitButton = (ToolStripSplitButton)sender;
            List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();

            LineCap2 currentLineCap = PenInfo.DefaultLineCap;
            bool isStartCap;

            if (object.ReferenceEquals(splitButton, this.penStartCapSplitButton))
            {
                isStartCap = true;
                currentLineCap = PenInfo.StartCap;
            }
            else if (object.ReferenceEquals(splitButton, this.penEndCapSplitButton))
            {
                isStartCap = false;
                currentLineCap = PenInfo.EndCap;
            }
            else
            {
                throw new InvalidOperationException();
            }

            foreach (LineCap2 lineCap in this.lineCaps)
            {
                ToolStripMenuItem mi = new ToolStripMenuItem(
                    this.lineCapLocalizer.EnumValueToLocalizedName(lineCap),
                    GetLineCapImage(lineCap, isStartCap).Reference,
                    delegate(object sender2, EventArgs e2)
                    {
                        ToolStripMenuItem tsmi = (ToolStripMenuItem)sender2;
                        Pair<ToolStripSplitButton, LineCap2> data = (Pair<ToolStripSplitButton, LineCap2>)tsmi.Tag;

                        PenInfo newPenInfo = PenInfo.Clone();

                        if (object.ReferenceEquals(data.First, this.penStartCapSplitButton))
                        {
                            newPenInfo.StartCap = data.Second;
                        }
                        else if (object.ReferenceEquals(data.First, this.penEndCapSplitButton))
                        {
                            newPenInfo.EndCap = data.Second;
                        }

                        PenInfo = newPenInfo;
                    });

                mi.Tag = Pair.Create(splitButton, lineCap);

                if (lineCap == currentLineCap)
                {
                    mi.Checked = true;
                }

                menuItems.Add(mi);
            }

            splitButton.DropDownItems.Clear();
            splitButton.DropDownItems.AddRange(menuItems.ToArray());
        }
コード例 #16
0
ファイル: MainForm.cs プロジェクト: leejungho2/xynotecgui
        private string[] PruneDirectories(string[] fileNames)
        {
            List<string> result = new List<string>();

            foreach (string fileName in fileNames)
            {
                try
                {
                    FileAttributes fa = File.GetAttributes(fileName);

                    if ((fa & FileAttributes.Directory) == 0)
                    {
                        result.Add(fileName);
                    }
                }

                catch
                {
                }
            }

            return result.ToArray();
        }
コード例 #17
0
        public static FileType[] FilterFileTypeList(FileType[] input, bool excludeCantSave, bool excludeCantLoad)
        {
            List<FileType> filtered = new List<FileType>();

            foreach (FileType fileType in input)
            {
                if (excludeCantSave && !fileType.SupportsSaving)
                {
                    continue;
                }

                if (excludeCantLoad && !fileType.SupportsLoading)
                {
                    continue;
                }

                filtered.Add(fileType);
            }

            return filtered.ToArray();
        }
コード例 #18
0
        public static ColorBgra[] ParsePaletteString(string paletteString)
        {
            List<ColorBgra> palette = new List<ColorBgra>();
            StringReader sr = new StringReader(paletteString);

            while (true)
            {
                string line = sr.ReadLine();

                if (line == null)
                {
                    break;
                }

                ColorBgra color;
                bool gotColor = ParsePaletteLine(line, out color);

                if (gotColor && palette.Count < PaletteColorCount)
                {
                    palette.Add(color);
                }
            }

            return palette.ToArray();
        }
コード例 #19
0
ファイル: PdnGraphicsPath.cs プロジェクト: herbqiao/paint.net
        public unsafe static Point[][] PolygonSetFromStencil(IBitVector2D stencil, Rectangle bounds, int translateX, int translateY)
        {
            List<Point[]> polygons = new List<Point[]>();

            if (!stencil.IsEmpty)
            {
                Point start = bounds.Location;
                List<Point> pts = new List<Point>();
                int count = 0;

                // find all islands
                while (true) 
                {
                    bool startFound = false;

                    while (true)
                    {
                        if (stencil[start])
                        {
                            startFound = true;
                            break;
                        }

                        ++start.X;

                        if (start.X >= bounds.Right)
                        {
                            ++start.Y;
                            start.X = bounds.Left;

                            if (start.Y >= bounds.Bottom)
                            {
                                break;
                            }
                        }
                    }
            
                    if (!startFound)
                    {
                        break;
                    }

                    pts.Clear();
                    Point last = new Point(start.X, start.Y + 1);
                    Point curr = new Point(start.X, start.Y);
                    Point next = curr;
                    Point left = Point.Empty;
                    Point right = Point.Empty;
            
                    // trace island outline
                    while (true)
                    {
                        left.X = ((curr.X - last.X) + (curr.Y - last.Y) + 2) / 2 + curr.X - 1;
                        left.Y = ((curr.Y - last.Y) - (curr.X - last.X) + 2) / 2 + curr.Y - 1;

                        right.X = ((curr.X - last.X) - (curr.Y - last.Y) + 2) / 2 + curr.X - 1;
                        right.Y = ((curr.Y - last.Y) + (curr.X - last.X) + 2) / 2 + curr.Y - 1;

                        if (bounds.Contains(left) && stencil[left])
                        {
                            // go left
                            next.X += curr.Y - last.Y;
                            next.Y -= curr.X - last.X;
                        }
                        else if (bounds.Contains(right) && stencil[right])
                        {
                            // go straight
                            next.X += curr.X - last.X;
                            next.Y += curr.Y - last.Y;
                        }
                        else
                        {
                            // turn right
                            next.X -= curr.Y - last.Y;
                            next.Y += curr.X - last.X;
                        }

                        if (Math.Sign(next.X - curr.X) != Math.Sign(curr.X - last.X) ||
                            Math.Sign(next.Y - curr.Y) != Math.Sign(curr.Y - last.Y))
                        {
                            pts.Add(curr);
                            ++count;
                        }

                        last = curr;
                        curr = next;

                        if (next.X == start.X && next.Y == start.Y)
                        {
                            break;
                        }
                    }

                    Point[] points = pts.ToArray();
                    Scanline[] scans = Utility.GetScans(points);

                    foreach (Scanline scan in scans)
                    {
                        stencil.Invert(scan);
                    }

                    Utility.TranslatePointsInPlace(points, translateX, translateY);
                    polygons.Add(points);
                }
            }

            Point[][] returnVal = polygons.ToArray();
            return returnVal;
        }
コード例 #20
0
ファイル: OctreeQuantizer.cs プロジェクト: metadeta96/openpdn
            /// <summary>
            /// Convert the nodes in the octree to a palette with a maximum of colorCount colors
            /// </summary>
            /// <param name="colorCount">The maximum number of colors</param>
            /// <returns>A list with the palettized colors</returns>
            public List<Color> Palletize(int colorCount)
            {
                while (Leaves > colorCount)
                {
                    Reduce();
                }

                // Now palettize the nodes
                List<Color> palette = new List<Color>(Leaves);
                int paletteIndex = 0;

                _root.ConstructPalette(palette, ref paletteIndex);

                // And return the palette
                this._palette = palette.ToArray();
                this.paletteTable = null;
                
                return palette;
            }
コード例 #21
0
ファイル: HDPhotoFileType.cs プロジェクト: metadeta96/openpdn
        private void CopyMetadataTo(Metadata dst, BitmapMetadata src)
        {
            dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.Software, src.ApplicationName) });

            ReadOnlyCollection<string> authors = src.Author;
            if (authors != null)
            {

                List<PropertyItem> piAuthors = new List<PropertyItem>();
                foreach (string author in authors)
                {
                    PropertyItem piAuthor = Exif.CreateAscii(ExifTagID.Artist, author);
                    piAuthors.Add(piAuthor);
                }

                dst.AddExifValues(piAuthors.ToArray());
            }

            dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.Make, src.CameraManufacturer) });
            dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.Model, src.CameraModel) });
            dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.Copyright, src.Copyright) });
            dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.DateTime, src.DateTaken) });
            dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.ImageDescription, src.Title) });
        }