Beispiel #1
0
        // requires: 0 <= id < NumLayers
        // effects: scales the layer with id uniformly by size;
        //     updates the composite image; and invokes composite image cbs
        public void ScaleLayer(int id, double size)
        {
            Layer currentLayer = _layerList[id];

            currentLayer.Size = size;
            _compImage        = _baseImage.Copy();
            foreach (var layer in _layerList)
            {
                layer.Apply(_compImage);
            }
            InvokeCompositeChangeCallbacks();
        }
Beispiel #2
0
 // requires: nothing
 // effects: Sets the base image with the given filename.
 //     Initializes the compoiste image.
 //     Returns true if successful; false otehrwise.
 public bool LoadBaseImage(string filename)
 {
     _layerList = new List <Layer>();
     try
     {
         Gdk.Pixbuf newImage = new Gdk.Pixbuf(filename);
         _baseImage = newImage.Copy();
         _compImage = newImage.Copy();
     }
     catch
     {
         return(false);
     }
     return(true);
 }
        private void MarkImage(Token t)
        {
            if (t == null)
            {
                originalImageArea.Image = originalImage;
                return;
            }

            Gdk.Pixbuf originalMarked = originalImage.Copy();

            // We tint the copy in red.
            originalMarked =
                originalMarked.CompositeColorSimple(originalMarked.Width,
                                                    originalMarked.Height,
                                                    Gdk.InterpType.Bilinear,
                                                    100, 1,
                                                    0xAAAAAA, 0xAAAAAA);

            // Over the red tinted copy, we place the piece we want to be
            // normal.
            originalImage.CopyArea(t.Left,
                                   t.Top,
                                   t.Width,
                                   t.Height,
                                   originalMarked,
                                   t.Left,
                                   t.Top);


            originalImageArea.Image = originalMarked;
        }
Beispiel #4
0
        public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon)
        {
            ProjectFile file = (ProjectFile)dataObject;

            label = GLib.Markup.EscapeText(file.Link.IsNullOrEmpty ? file.FilePath.FileName : file.Link.FileName);
            if (!File.Exists(file.FilePath))
            {
                label = "<span foreground='red'>" + label + "</span>";
            }

            icon = DesktopService.GetPixbufForFile(file.FilePath, Gtk.IconSize.Menu);

            if (file.IsLink && icon != null)
            {
                var overlay = ImageService.GetPixbuf("md-link-overlay", Gtk.IconSize.Menu);
                var cached  = Context.GetComposedIcon(icon, overlay);
                if (cached != null)
                {
                    icon = cached;
                }
                else
                {
                    var res = icon.Copy();
                    overlay.Composite(res,
                                      0, 0,
                                      icon.Width, icon.Width,
                                      0, 0,
                                      1, 1, Gdk.InterpType.Bilinear, 255);
                    Context.CacheComposedIcon(icon, overlay, res);
                    icon = res;
                }
            }
        }
 public static Gdk.Pixbuf MakeInverted(Gdk.Pixbuf icon)
 {
     if (icon.BitsPerSample != 8)
     {
         throw new NotSupportedException();
     }
     Gdk.Pixbuf copy = icon.Copy();
     unsafe {
         byte *pix      = (byte *)copy.Pixels;
         bool  hasAlpha = copy.HasAlpha;
         for (int y = 0; y < copy.Height; y++)
         {
             var start = pix;
             for (int x = 0; x < copy.Width; x++)
             {
                 pix [0] = (byte)~pix [0];
                 pix [1] = (byte)~pix [1];
                 pix [2] = (byte)~pix [2];
                 pix    += hasAlpha ? 4 : 3;
             }
             pix = start + copy.Rowstride;
         }
     }
     return(copy);
 }
        public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon)
        {
            ProjectFile file = (ProjectFile)dataObject;

            label = GLib.Markup.EscapeText(file.Link.IsNullOrEmpty ? file.FilePath.FileName : file.Link.FileName);
            if (!File.Exists(file.FilePath))
            {
                label = "<span foreground='red'>" + label + "</span>";
            }

            icon = DesktopService.GetPixbufForFile(file.FilePath, Gtk.IconSize.Menu);

            if (file.IsLink && icon != null)
            {
                icon = icon.Copy();
                using (Gdk.Pixbuf overlay = Gdk.Pixbuf.LoadFromResource("Icons.16x16.LinkOverlay.png"))
                {
                    overlay.Composite(icon,
                                      0, 0,
                                      icon.Width, icon.Width,
                                      0, 0,
                                      1, 1, Gdk.InterpType.Bilinear, 255);
                }
            }
        }
Beispiel #7
0
        public override Gdk.Pixbuf Run(Gdk.Pixbuf buffer)
        {
            Gdk.Pixbuf result = buffer.Copy();
            int        height = buffer.Height;
            int        width  = buffer.Width;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int  firstRandom  = RandomMaker();
                    int  secondRandom = RandomMaker();
                    int  thirdRandom  = RandomMaker();
                    RGB  rgb          = GetPixel(buffer, y, x);
                    int  r            = Math.Clamp(rgb.red + firstRandom, 0, 255);
                    int  g            = Math.Clamp(rgb.green + secondRandom, 0, 255);
                    int  b            = Math.Clamp(rgb.blue + thirdRandom, 0, 255);
                    byte redb         = Convert.ToByte(r);
                    byte greenb       = Convert.ToByte(g);
                    byte blueb        = Convert.ToByte(b);
                    RGB  color        = new RGB(redb, greenb, blueb);
                    SetPixel(result, y, x, color);
                }
            }
            return(result);
        }
 public static Gdk.Pixbuf MakeTransparent(Gdk.Pixbuf icon, double opacity)
 {
     Gdk.Pixbuf result = icon.Copy();
     result.Fill(0);
     result = result.AddAlpha(true, 0, 0, 0);
     icon.Composite(result, 0, 0, icon.Width, icon.Height, 0, 0, 1, 1, Gdk.InterpType.Bilinear, (int)(256 * opacity));
     return(result);
 }
Beispiel #9
0
 public static Gdk.Pixbuf FadeIcon(Gdk.Pixbuf source)
 {
     Gdk.Pixbuf result = source.Copy();
     result.Fill(0);
     result = result.AddAlpha(true, 0, 0, 0);
     source.Composite(result, 0, 0, source.Width, source.Height, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 128);
     return(result);
 }
Beispiel #10
0
 public override object ChangeOpacity(object backend, double opacity)
 {
     Gdk.Pixbuf image  = (Gdk.Pixbuf)backend;
     Gdk.Pixbuf result = image.Copy();
     result.Fill(0);
     result = result.AddAlpha(true, 0, 0, 0);
     image.Composite(result, 0, 0, image.Width, image.Height, 0, 0, 1, 1, Gdk.InterpType.Bilinear, (int)(255 * opacity));
     return(result);
 }
Beispiel #11
0
 private void ComputeCompImage()
 {
     _compImage = _baseImage.Copy();
     foreach (Layer l in _layers)
     {
         l.Apply(_compImage);
     }
     foreach (CallbackFn cb in _compImageCbs)
     {
         cb();
     }
 }
Beispiel #12
0
        /// <summary>
        /// If sequencing, selects the next symbol of the list.
        /// </summary>
        /// <param name="sender">
        /// A <see cref="System.Object"/>
        /// </param>
        /// <param name="args">
        /// A <see cref="EventArgas"/>
        /// </param>
        private void OnControllerNodeBeingProcessed(object sender,
                                                    NodeBeingProcessedArgs _args)
        {
            Application.Invoke(sender, _args,
                               delegate(object resender, EventArgs args)
            {
                NodeBeingProcessedArgs a = args as NodeBeingProcessedArgs;

                if (!sequencingFinished)
                {
                    // We are sequencing.

                    // Selects the new first.
                    symbolsIV.SelectPath(processedPath);
                    symbolsIV.ScrollToPath(processedPath, 1, 0.5f);
                    processedPath.Next();
                }
                else
                {
                    // We are matching
                    SequenceNode node = (SequenceNode)a.Node;

                    node.Select();

                    Token t = Token.Join(node.Sequence, "");

                    sequenceNodeImage = t.Image.CreatePixbuf();

                    sequenceMatchingImageArea.Image = sequenceNodeImage.Copy();

                    sequenceNodeImage =
                        sequenceNodeImage.CompositeColorSimple(sequenceNodeImage.Width,
                                                               sequenceNodeImage.Height,
                                                               Gdk.InterpType.Nearest,
                                                               100, 1,
                                                               0xAAAAAA, 0xAAAAAA);

                    matchingResultLbl.Markup = "-";

                    tokenizingRulesTV.Selection.UnselectAll();

                    tokenizingRulesTV.ScrollToPoint(0, 0);


                    if (controller.StepMode == ControllerStepMode.StepByStep)
                    {
                        tokenizingNextButtonsAlign.Sensitive = true;
                    }
                }
            });
        }
        public CrossfadeIcon(Gdk.Pixbuf primary, Gdk.Pixbuf secondary)
        {
            if (primary == null)
            {
                throw new ArgumentNullException("primary");
            }
            if (secondary == null)
            {
                throw new ArgumentNullException("secondary");
            }

            this.primary   = primary.Copy();
            this.secondary = secondary.Copy();
        }
Beispiel #14
0
        /// <summary>
        /// This creates a new gray scale pixbuf. Note that this pixbuf needs to be disposed.
        /// </summary>
        /// <param name="icon">
        /// A <see cref="Gdk.Pixbuf"/>.
        /// </param>
        /// <returns>
        /// A <see cref="Gdk.Pixbuf"/> gray scale version of "icon".
        /// </returns>
        public static Gdk.Pixbuf MakeGrayscale(Gdk.Pixbuf icon)
        {
            Gdk.Pixbuf copy = icon.Copy();
            copy.SaturateAndPixelate(copy, 0, false);

            var icon2x = Get2xIconVariant(icon);

            if (icon2x != null)
            {
                Set2xIconVariant(copy, MakeGrayscale(icon2x));
            }

            return(copy);
        }
Beispiel #15
0
 public void SaveTagIcon(Tag tag)
 {
     Gdk.Pixbuf icon   = tag.Icon;
     Gdk.Pixbuf scaled = null;
     if (icon.Height != 52 || icon.Width != 52)
     {
         scaled = icon.ScaleSimple(52, 52, Gdk.InterpType.Bilinear);
     }
     else
     {
         scaled = icon.Copy();
     }
     scaled.Save(SubdirPath("tags", TagName(tag)), "png");
     scaled.Dispose();
 }
Beispiel #16
0
        public static Gdk.Pixbuf MakeTransparent(Gdk.Pixbuf icon, double opacity)
        {
            Gdk.Pixbuf result = icon.Copy();
            result.Fill(0);
            result = result.AddAlpha(true, 0, 0, 0);
            icon.Composite(result, 0, 0, icon.Width, icon.Height, 0, 0, 1, 1, Gdk.InterpType.Bilinear, (int)(256 * opacity));

            var icon2x = Get2xIconVariant(icon);

            if (icon2x != null)
            {
                Set2xIconVariant(result, MakeTransparent(icon2x, opacity));
            }

            return(result);
        }
Beispiel #17
0
        public override Gdk.Pixbuf Run(Gdk.Pixbuf buffer)
        {
            Gdk.Pixbuf result = buffer.Copy();
            int        height = buffer.Height;
            int        width  = buffer.Width;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    RGB  rgb   = GetPixel(buffer, y, x);
                    int  gray  = (rgb.red + rgb.green + rgb.blue) / 3;
                    byte grayb = Convert.ToByte(gray);
                    RGB  color = new RGB(grayb, grayb, grayb);
                    SetPixel(result, y, x, color);
                }
            }
            return(result);
        }
Beispiel #18
0
        private void HandlePhotoChanged(PhotoImageView view)
        {
            try {
                if (!view.Item.IsValid)
                {
                    throw new Exception("Invalid Image");
                }

                using (FSpot.ImageFile img = FSpot.ImageFile.Create(((Photo)view.Item.Current).DefaultVersionUri)) {
                    try {
                        image_profile = img.GetProfile();
                    } catch (System.Exception e) {
                        image_profile = null;
                        System.Console.WriteLine(e);
                    }

                    // FIXME fall back to rgb for now
                    if (image_profile == null)
                    {
                        image_profile = Cms.Profile.CreateStandardRgb();
                    }

                    AdjustedPixbuf = img.Load(256, 256);
                    ScaledPixbuf   = AdjustedPixbuf.Copy();
                }

                if (AdjustedPixbuf.HasAlpha)
                {
                    throw new Exception("Unsupported Alpha Channel");
                }

                control_vbox.Sensitive = true;
                ok_button.Sensitive    = true;

                RangeChanged(null, null);
            } catch (System.Exception) {
                control_vbox.Sensitive = false;
                ok_button.Sensitive    = false;
                AdjustedPixbuf         = null;
                ScaledPixbuf           = null;
                image_profile          = null;
            }
        }
Beispiel #19
0
        private static Eto.Drawing.Image PlatformGetFileIcon(string path, bool exists)
        {
            Gdk.Pixbuf icon = null;

            try
            {
                var info  = new GLib.FileInfo(Gtk3Wrapper.g_file_query_info(Gtk3Wrapper.g_file_new_for_path(path), "standard::*", 0, new IntPtr(), new IntPtr()));
                var sicon = info.Icon.ToString().Split(' ');

                for (int i = sicon.Length - 1; i >= 1; i--)
                {
                    try
                    {
                        icon = _theme.LoadIcon(sicon[i], 16, 0);
                        if (icon != null)
                        {
                            break;
                        }
                    }
                    catch { }
                }
            }
            catch { }

            if (icon == null)
            {
                icon = _theme.LoadIcon("text-x-generic", 16, 0);
            }


            if (!exists)
            {
                icon = icon.Copy();
                _iconMissing.Composite(icon, 8, 8, 8, 8, 8, 8, 0.5, 0.5, Gdk.InterpType.Tiles, 255);
            }

            return(new Bitmap(new BitmapHandler(icon)));
        }
Beispiel #20
0
        public override Gdk.Pixbuf Run(Gdk.Pixbuf buffer)
        {
            Gdk.Pixbuf result = buffer.Copy();
            int        height = buffer.Height;
            int        width  = buffer.Width;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    RGB  rgb    = GetPixel(buffer, y, x);
                    int  red    = Math.Clamp(rgb.red - 100, 0, 255);
                    int  green  = Math.Clamp(rgb.green - 100, 0, 255);
                    int  blue   = Math.Clamp(rgb.blue - 100, 0, 255);
                    byte redb   = Convert.ToByte(red);
                    byte greenb = Convert.ToByte(green);
                    byte blueb  = Convert.ToByte(blue);
                    RGB  color  = new RGB(redb, greenb, blueb);
                    SetPixel(result, y, x, color);
                }
            }
            return(result);
        }
		/// <summary>
		/// If sequencing, selects the next symbol of the list.
		/// </summary>
		/// <param name="sender">
		/// A <see cref="System.Object"/>
		/// </param>
		/// <param name="args">
		/// A <see cref="EventArgas"/>
		/// </param>
		private void OnControllerNodeBeingProcessed(object sender, 
		                                            NodeBeingProcessedArgs _args)
		{
			Application.Invoke(sender, _args, 
			                   delegate(object resender, EventArgs args)
			{
				NodeBeingProcessedArgs a =  args as NodeBeingProcessedArgs;
			
				if(!sequencingFinished)
				{
					// We are sequencing.	
					
					// Selects the new first.			
					symbolsIV.SelectPath(processedPath);
					symbolsIV.ScrollToPath(processedPath,1,0.5f);
					processedPath.Next();
					
				}
				else
				{
					// We are matching
					SequenceNode node = (SequenceNode) a.Node;
					
					node.Select();
					
					Token t = Token.Join(node.Sequence, "");
					
					sequenceNodeImage = t.Image.CreatePixbuf();
					
					sequenceMatchingImageArea.Image = sequenceNodeImage.Copy();
					
					sequenceNodeImage = 
						sequenceNodeImage.CompositeColorSimple(sequenceNodeImage.Width,
						                                    sequenceNodeImage.Height,
						                                    Gdk.InterpType.Nearest, 
						                                    100, 1,  
						                                    0xAAAAAA,0xAAAAAA);
					
					matchingResultLbl.Markup = "-";
					
					tokenizingRulesTV.Selection.UnselectAll();
					
					tokenizingRulesTV.ScrollToPoint(0,0);
					
					
					if(controller.StepMode == ControllerStepMode.StepByStep)
					{
						tokenizingNextButtonsAlign.Sensitive = true;
					}
				}
			});
		}
Beispiel #22
0
        // window is the scrolled window; should be named apropriately eventually
        public JsonClass(Gtk.Container window, Gtk.Image image, myListStore myListstore)
        {
            Gdk.Pixbuf tileSet = image.Pixbuf, scaled = image.Pixbuf;


            int height = tileSet.Height, width = tileSet.Width;

            // a treestore so the tiles with subtiles can be expanded, eventually also categories that are expandable
            Gtk.TreeStore myListStore = new Gtk.TreeStore(typeof(string), typeof(int), typeof(string), typeof(Gdk.Pixbuf));

            tile_info_nested tile_info = new tile_info_nested();              // should have a better name eventually

            // should either be chosen by user or maybe the folder where the tileset resides
            StreamReader streamReader = new StreamReader(@"/home/gervinius/Pragramming/Mono/jsonTest/jsonTest/tile_config.json");

            tile_info_nested deserializedJsonFile = JsonConvert.DeserializeObject <tile_info_nested> (streamReader.ReadToEnd());

            streamReader.Close();

            int value, tileWidthHeight = 16;

            if (deserializedJsonFile.tile_info [0].TryGetValue("height", out value))
            {
                tileWidthHeight = value;
                Console.WriteLine(tileWidthHeight);
            }


            scaled = scaled.ScaleSimple(tileWidthHeight, tileWidthHeight, Gdk.InterpType.Bilinear);              // temp solution; should look for a more elegant solution
            //this copies the list from the json object list to another list. Could be a better solution someday
            tile_info.tiles = new List <Json_tile_class> (deserializedJsonFile.tiles);

            //checks if tile has subtiles and adds them to a list
            for (int i = 0; i < tile_info.tiles.Count; i++)
            {
                if (tile_info.tiles [i].multitile == true)
                {
                    //just copy the list with subtiles
                    tile_info.tiles [i].additional_tiles = new List <Json_tile_class> (deserializedJsonFile.tiles[i].additional_tiles);
                }
            }

            //reads the tileset image and copies each individual tile to a pixbuf; should be a seperate method eventually
            for (int i = 0; i < height / tileWidthHeight; i++)
            {
                for (int h = 0; h < width / tileWidthHeight; h++)
                {
                    tile_info.lstPixbuf.Add(scaled.Copy());                      //hack to initialize a empty pixbuf at the correct index in the list, there may be a more performant solution
                    tileSet.CopyArea(h * tileWidthHeight, i * tileWidthHeight, tileWidthHeight, tileWidthHeight,
                                     tile_info.lstPixbuf[i * 16 + h], 0, 0);     //copy the pixels that reperesent one tile to the pixbuf at the lists index
                }
            }

            //checks whether the tile has a bg or fg image (or both)
            for (int i = 0; i < tile_info.tiles.Count; i++)
            {
                Gdk.Pixbuf myListstoreImage = scaled.Copy();                       // initialize a pixbuf with 32x32 pixels;; could be in the class eventually

                if (tile_info.tiles [i].fg != null && tile_info.tiles [i].fg >= 0) // some persons have used the value -1 to mark a nonexisting fg- or bg-image
                {
                    tile_info.tiles[i].fg_image = tile_info.lstPixbuf[tile_info.tiles [i].fg.Value];
                    myListstoreImage            = tile_info.tiles [i].fg_image;
                }

                else if (tile_info.tiles [i].bg != null && tile_info.tiles [i].bg >= 0)
                {
                    tile_info.tiles[i].bg_image = tile_info.lstPixbuf[tile_info.tiles [i].bg.Value];
                    myListstoreImage            = tile_info.tiles [i].bg_image;
                }

                else if (tile_info.tiles [i].fg != null && tile_info.tiles [i].fg >= 0 && tile_info.tiles [i].bg != null && tile_info.tiles [i].bg >= 0)
                {
                    tile_info.tiles[i].fg_image = tile_info.lstPixbuf[tile_info.tiles [i].fg.Value];
                    tile_info.tiles[i].bg_image = tile_info.lstPixbuf[tile_info.tiles [i].bg.Value];

                    // this merges background and foreground
                    tile_info.tiles [i].bg_image.Composite(myListstoreImage, 0, 0, tileWidthHeight, tileWidthHeight, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 1);
                    tile_info.tiles [i].fg_image.Composite(myListstoreImage, 0, 0, tileWidthHeight, tileWidthHeight, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 1);
                }

                // if the tile object has additional tiles ...
                if (tile_info.tiles [i].multitile == true)
                {
                    // create an expandable treeiter
                    Gtk.TreeIter iter = myListStore.AppendValues(tile_info.tiles[i].id);                      // category name is the maintiles name, could be changed later
                    //append the PARENT TILE to the treestore
                    myListStore.AppendValues(iter, tile_info.tiles [i].id, 1,
                                             "test1", myListstoreImage);

                    // look through each subtile and add the foreground or background image to the liststore
                    for (int x = 0; x < tile_info.tiles[i].additional_tiles.Count; x++)
                    {
                        if (tile_info.tiles [i].additional_tiles [x].fg != null && tile_info.tiles [i].additional_tiles [x].fg >= 0)
                        {
                            tile_info.tiles [i].additional_tiles [x].fg_image = tile_info.lstPixbuf [tile_info.tiles [i].additional_tiles [x].fg.Value];
                            myListStore.AppendValues(iter, tile_info.tiles [i].additional_tiles [x].id, "test",
                                                     "test1", tile_info.tiles [i].additional_tiles [x].fg_image);
                        }
                        else if (tile_info.tiles [i].additional_tiles [x].bg != null && tile_info.tiles [i].additional_tiles [x].bg >= 0)
                        {
                            tile_info.tiles [i].additional_tiles [x].bg_image = tile_info.lstPixbuf [tile_info.tiles [i].additional_tiles [x].bg.Value];
                            myListStore.AppendValues(iter, tile_info.tiles [i].additional_tiles [x].id, "test",
                                                     "test1", tile_info.tiles [i].additional_tiles [x].bg_image);
                            // ToDo:: merge fg and bg
                        }
                        else if (tile_info.tiles [i].additional_tiles [x].fg != null && tile_info.tiles [i].additional_tiles [x].fg >= 0 && tile_info.tiles [i].additional_tiles [x].bg != null && tile_info.tiles [i].additional_tiles [x].bg >= 0)
                        {
                            tile_info.tiles [i].additional_tiles [x].fg_image = tile_info.lstPixbuf [tile_info.tiles [i].additional_tiles [x].fg.Value];
                            tile_info.tiles [i].additional_tiles [x].bg_image = tile_info.lstPixbuf [tile_info.tiles [i].additional_tiles [x].bg.Value];
                            myListStore.AppendValues(tile_info.tiles [i].additional_tiles [x].id, "test",
                                                     "test1", tile_info.tiles [i].additional_tiles [x].fg_image);
                        }
                    }
                }
                else
                {
                    // append the tile at index i to the liststore
                    myListStore.AppendValues(tile_info.tiles [i].id, "test",
                                             "test1", myListstoreImage);
                }
            }
            myListstore.returnTV().Model = myListStore;
        }
 /// <summary>
 /// This creates a new gray scale pixbuf. Note that this pixbuf needs to be disposed.
 /// </summary>
 /// <param name="icon">
 /// A <see cref="Gdk.Pixbuf"/>.
 /// </param>
 /// <returns>
 /// A <see cref="Gdk.Pixbuf"/> gray scale version of "icon".
 /// </returns>
 public static Gdk.Pixbuf MakeGrayscale(Gdk.Pixbuf icon)
 {
     Gdk.Pixbuf copy = icon.Copy();
     copy.SaturateAndPixelate(copy, 0, false);
     return(copy);
 }
Beispiel #24
0
        public void Refresh()
        {
            foreach (string i in SearchPath) {Console.WriteLine (i);}

            IconProvider provider = new IconProvider ("");
            string folder = provider.GetTargetFolderPath ();
            string [] files = Directory.GetFiles (folder);

            int [] sizes = {16, 24, 32, 48};

            foreach (string file_path in files) {

                Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (file_path);

                FileInfo file_info = new FileInfo (file_path);

                // Delete the icon if it turns out to be empty
                if (file_info.Length == 0) {
                    File.Delete (file_path);
                    Console.WriteLine ("Deleted: " + file_path);
                }

                for (int i = 0; i < 4; i++) {

                    int size = sizes [i];

                    Gdk.Pixbuf pixbuf_copy = pixbuf.Copy ();

                    if (pixbuf.Width != size || pixbuf.Height != size)
                        pixbuf_copy = pixbuf.ScaleSimple (size, size, Gdk.InterpType.Hyper);

                    string size_folder_path = CombineMore (Path, size + "x" + size, "status");
                    string size_file_path = CombineMore (size_folder_path, System.IO.Path.GetFileName (file_path));

                    Directory.CreateDirectory (size_folder_path);

                    if (File.Exists (size_file_path))
                        File.Delete (size_file_path);

                    pixbuf_copy.Save (size_file_path, "png");

                }

                File.Delete (file_path);

            }

            RescanIfNeeded ();
        }
Beispiel #25
0
 public override Gdk.Pixbuf Run(Gdk.Pixbuf buffer)
 {
     Gdk.Pixbuf result = buffer.Copy();
     return(result);
 }
Beispiel #26
0
        /// <summary>
        /// Handles the controller's SequenceBeingMatched event.
        /// </summary>
        /// <param name="sender">
        /// A <see cref="System.Object"/>
        /// </param>
        /// <param name="quenceBeingMatchedArgs">
        /// A <see cref="Se"/>
        /// </param>
        private void OnControllerSequenceBeingMatched(object sender,
                                                      SequenceBeingMatchedArgs args)
        {
            Application.Invoke(sender,
                               args,
                               delegate(object resender, EventArgs _args)
            {
                SequenceBeingMatchedArgs a = _args as SequenceBeingMatchedArgs;


                Gdk.Pixbuf sequenceImage = a.JoinedToken.Image.CreatePixbuf();

                Gdk.Pixbuf drawnImage = sequenceNodeImage.Copy();

                sequenceImage.CopyArea(0, 0,
                                       sequenceImage.Width, sequenceImage.Height,
                                       drawnImage,
                                       0, 0);

                sequenceMatchingImageArea.Image = drawnImage;

                TreeIter iter;
                tokenizingRulesTV.Model.GetIterFirst(out iter);

                TreePath path = tokenizingRulesTV.Model.GetPath(iter);

                tokenizingRulesTV.Selection.UnselectAll();

                string ruleName;
                do
                {
                    ruleName = tokenizingRulesTV.Model.GetValue(iter, 0) as string;

                    if (ruleName == a.MatchingRule.Name)
                    {
                        tokenizingRulesTV.Selection.SelectPath(path);
                        tokenizingRulesTV.ScrollToCell(path,
                                                       tokenizingRulesTV.Columns[0],
                                                       true,
                                                       0.5f, 0);
                        break;
                    }

                    path.Next();
                }while(tokenizingRulesTV.Model.GetIter(out iter, path));

                if (a.Found)
                {
                    matchingResultLbl.Markup =
                        String.Format("<b>Sí, se le asigna el item «{0}» a la secuencia actual</b>",
                                      a.JoinedToken.Type);
                }
                else
                {
                    matchingResultLbl.Markup =
                        String.Format("<b>No, la regla actual no concuerda con la secuencia</b>");
                }

                // Activate the buttons if necessary.
                if (controller.StepMode == ControllerStepMode.StepByStep)
                {
                    tokenizingNextButtonsAlign.Sensitive = true;
                }
            });
        }
Beispiel #27
0
        /// <summary>
        /// Handles the start of processing of a new node.
        /// </summary>
        /// <param name="sender">
        /// A <see cref="System.Object"/>
        /// </param>
        /// <param name="args">
        /// A <see cref="EventArgs"/>
        /// </param>
        private void OnControllerTokenChecked(object sender,
                                              TokenCheckedArgs args)
        {
            Application.Invoke(sender, args,
                               delegate(object resender, EventArgs _args)
            {
                TokenCheckedArgs a = _args as TokenCheckedArgs;

                if (!sequencingFinished)
                {
                    currentToken = a.CurrentToken;


                    FloatBitmap sequenceImage;

                    if (a.LastSequence != null)
                    {
                        TokenSequence joinSeq =
                            new TokenSequence(a.LastSequence);
                        lastToken = joinSeq.Last;
                        joinSeq.Append(currentToken);
                        Token joinedToken = Token.Join(joinSeq, "");

                        sequenceImage = joinedToken.Image;
                    }
                    else
                    {
                        sequenceImage = currentToken.Image;
                        lastToken     = null;
                    }

                    // We add a border to the orginal image.

                    Gdk.Pixbuf sequencePixbuf = sequenceImage.CreatePixbuf();

                    Gdk.Pixbuf drawnImage =
                        new Gdk.Pixbuf(sequencePixbuf.Colorspace, false, 8,
                                       sequencePixbuf.Width + 10,
                                       sequencePixbuf.Height + 10);

                    drawnImage.Fill(0xFFFFFFFF);

                    sequencePixbuf.CopyArea(0, 0,
                                            sequencePixbuf.Width,
                                            sequencePixbuf.Height,
                                            drawnImage,
                                            5, 5);

                    if (lastToken != null)
                    {
                        uint color;
                        if (currentToken.CloseFollows(lastToken))
                        {
                            color = 0x00FF00;
                            sequencingStepResultLbl.Markup =
                                String.Format("<b>Sí, el símbolo «{0}» se añadirá a la secuencia actual</b>",
                                              currentToken.Text);
                        }
                        else
                        {
                            color = 0xFF0000;
                            sequencingStepResultLbl.Markup =
                                String.Format("<b>No, «{0}» no puede ser considerado parte de la secuencia ({1})</b>",
                                              currentToken.Text,
                                              a.LastSequence.ToString());
                        }


                        Gdk.Pixbuf markedImage = drawnImage.Copy();

                        // We paint the image of the color
                        markedImage =
                            markedImage.CompositeColorSimple(markedImage.Width,
                                                             markedImage.Height,
                                                             Gdk.InterpType.Nearest,
                                                             100, 1, color, color);

                        // We are going to mark the image of the to symbols being considered
                        // with their baselines.
                        int min = int.MaxValue;
                        foreach (Token t in a.LastSequence)
                        {
                            if (t.Top < min)
                            {
                                min = t.Top;
                            }
                        }

                        int offset          = Math.Min(min, currentToken.Top);
                        int lastBaseline    = lastToken.Baseline - offset;
                        int currentBaseline = currentToken.Baseline - offset;

                        markedImage.CopyArea(0, lastBaseline,
                                             markedImage.Width, 5,
                                             drawnImage,
                                             0, lastBaseline);

                        markedImage.CopyArea(0, currentBaseline,
                                             markedImage.Width, 5,
                                             drawnImage,
                                             0, currentBaseline);
                    }


                    baselineImageArea.Image = drawnImage;
                }

                if (controller.StepMode == ControllerStepMode.StepByStep)
                {
                    tokenizingNextButtonsAlign.Sensitive = true;
                }
            });
        }
		/// <summary>
		/// Handles the start of processing of a new node.
		/// </summary>
		/// <param name="sender">
		/// A <see cref="System.Object"/>
		/// </param>
		/// <param name="args">
		/// A <see cref="EventArgs"/>
		/// </param>
		private void OnControllerTokenChecked(object sender, 
		                                            TokenCheckedArgs args)
		{
			Application.Invoke(sender, args,
			                   delegate(object resender, EventArgs _args)
			{
				TokenCheckedArgs a = _args as TokenCheckedArgs;
			
				if(!sequencingFinished)
				{
					currentToken = a.CurrentToken;
					
				
					FloatBitmap sequenceImage;
					
					if(a.LastSequence!= null)
					{
						TokenSequence joinSeq = 
							new TokenSequence(a.LastSequence);
						lastToken = joinSeq.Last;	
						joinSeq.Append(currentToken);
						Token joinedToken =Token.Join(joinSeq, "");
						
						sequenceImage = joinedToken.Image;
						
					}
					else
					{
						sequenceImage = currentToken.Image;					
						lastToken = null;
					}
					
					// We add a border to the orginal image.
					
					Gdk.Pixbuf sequencePixbuf = sequenceImage.CreatePixbuf();
					
					Gdk.Pixbuf drawnImage = 
						new Gdk.Pixbuf(sequencePixbuf.Colorspace,false, 8, 
						               sequencePixbuf.Width+10, 
						               sequencePixbuf.Height+10);
					
					drawnImage.Fill(0xFFFFFFFF);
					
					sequencePixbuf.CopyArea(0, 0, 
				                        sequencePixbuf.Width, 
				                        sequencePixbuf.Height,
				                        drawnImage,
				                        5,5);
					
					if(lastToken!=null)
					{
						uint color;
						if(currentToken.CloseFollows(lastToken))
						{
							color = 0x00FF00;
							sequencingStepResultLbl.Markup = 
								String.Format("<b>Sí, el símbolo «{0}» se añadirá a la secuencia actual</b>",
								              currentToken.Text);
							
						}
						else
						{
							color = 0xFF0000;
							sequencingStepResultLbl.Markup = 
								String.Format("<b>No, «{0}» no puede ser considerado parte de la secuencia ({1})</b>",
								              currentToken.Text,
								              a.LastSequence.ToString());
						}
						
						
						Gdk.Pixbuf markedImage = drawnImage.Copy();
						
						// We paint the image of the color
						markedImage = 
							markedImage.CompositeColorSimple(markedImage.Width, 
							                                 markedImage.Height,
							                                 Gdk.InterpType.Nearest,
							                                 100, 1, color, color);
						
						// We are going to mark the image of the to symbols being considered
						// with their baselines.
						int min = int.MaxValue;
						foreach (Token t in a.LastSequence ) 
						{
							if(t.Top < min)
								min =t.Top;
						}
						
						int offset = Math.Min(min, currentToken.Top);
						int lastBaseline = lastToken.Baseline - offset;
						int currentBaseline = currentToken.Baseline - offset;
						
						markedImage.CopyArea(0, lastBaseline, 
						                     markedImage.Width, 5,
						                     drawnImage, 
						                     0,lastBaseline);
						
						markedImage.CopyArea(0, currentBaseline, 
						                     markedImage.Width,5, 
						                     drawnImage, 
						                     0,currentBaseline);
					}
					
							
					baselineImageArea.Image = drawnImage;
				}
				
				if(controller.StepMode == ControllerStepMode.StepByStep)
					tokenizingNextButtonsAlign.Sensitive = true;
			});
		}
Beispiel #29
0
        public EditTagIconDialog(Db db, Tag t, Gtk.Window parent_window)
            : base("EditTagIconDialog.ui", "edit_tag_icon_dialog")
        {
            this.db = db;
            TransientFor = parent_window;
            Title = String.Format (Catalog.GetString ("Edit Icon for Tag {0}"), t.Name);

            preview_pixbuf = t.Icon;
            Cms.Profile screen_profile;
            if (preview_pixbuf != null && FSpot.ColorManagement.Profiles.TryGetValue (Preferences.Get<string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile)) {
                preview_image.Pixbuf = preview_pixbuf.Copy ();
                ColorManagement.ApplyProfile (preview_image.Pixbuf, screen_profile);
            } else
                preview_image.Pixbuf = preview_pixbuf;

            query = new FSpot.PhotoQuery (db.Photos);

            if (db.Tags.Hidden != null)
                query.Terms = FSpot.OrTerm.FromTags (new Tag [] {t});
            else
                query.Terms = new FSpot.Literal (t);

            image_view = new PhotoImageView (query) {CropHelpers = false};
            image_view.SelectionXyRatio = 1.0;
            image_view.SelectionChanged += HandleSelectionChanged;
            image_view.PhotoChanged += HandlePhotoChanged;

            external_photo_chooser = new Gtk.FileChooserButton (Catalog.GetString ("Select Photo from file"),
                    Gtk.FileChooserAction.Open);

            external_photo_chooser.Filter = new FileFilter();
            external_photo_chooser.Filter.AddPixbufFormats();
                        external_photo_chooser.LocalOnly = false;
            external_photo_chooser_hbox.PackStart (external_photo_chooser);
            external_photo_chooser.Show ();
            external_photo_chooser.SelectionChanged += HandleExternalFileSelectionChanged;

            photo_scrolled_window.Add (image_view);

            if (query.Count > 0) {
                photo_spin_button.Wrap = true;
                photo_spin_button.Adjustment.Lower = 1.0;
                photo_spin_button.Adjustment.Upper = (double) query.Count;
                photo_spin_button.Adjustment.StepIncrement = 1.0;
                photo_spin_button.ValueChanged += HandleSpinButtonChanged;

                image_view.Item.Index = 0;
            } else {
                from_photo_label.Markup = String.Format (Catalog.GetString (
                    "\n<b>From Photo</b>\n" +
                    " You can use one of your library photos as an icon for this tag.\n" +
                    " However, first you must have at least one photo associated\n" +
                    " with this tag. Please tag a photo as '{0}' and return here\n" +
                    " to use it as an icon."), t.Name);
                photo_scrolled_window.Visible = false;
                photo_label.Visible = false;
                photo_spin_button.Visible = false;
            }

            icon_store = new ListStore (typeof (string), typeof (Gdk.Pixbuf));

            icon_view = new Gtk.IconView (icon_store);
            icon_view.PixbufColumn = 1;
            icon_view.SelectionMode = SelectionMode.Single;
            icon_view.SelectionChanged += HandleIconSelectionChanged;

            icon_scrolled_window.Add (icon_view);

            icon_view.Show();

            image_view.Show ();

            FSpot.Delay fill_delay = new FSpot.Delay (FillIconView);
            fill_delay.Start ();
        }
		private void HandlePhotoChanged (PhotoImageView view)
		{
			try {
				if (!view.Item.IsValid)
 					throw new Exception ("Invalid Image");
				
				using (FSpot.ImageFile img = FSpot.ImageFile.Create (((Photo)view.Item.Current).DefaultVersionUri)) {
 					try {
 						image_profile = img.GetProfile ();
 					} catch (System.Exception e) {
 						image_profile = null;
 						System.Console.WriteLine (e);
 					}

					// FIXME fall back to rgb for now
					if (image_profile == null)
						image_profile = Cms.Profile.CreateStandardRgb ();
				
					AdjustedPixbuf = img.Load (256, 256);
					ScaledPixbuf = AdjustedPixbuf.Copy ();			
				}

				if (AdjustedPixbuf.HasAlpha)
					throw new Exception ("Unsupported Alpha Channel");

 				control_vbox.Sensitive = true;
 				ok_button.Sensitive = true;

  				RangeChanged (null, null);
  			} catch (System.Exception) {
 				control_vbox.Sensitive = false;
 				ok_button.Sensitive = false;
 				AdjustedPixbuf = null;
 				ScaledPixbuf = null;
  				image_profile = null;
  			}	
		}