private void on_ImageThumbView_selection_changed(object obj, EventArgs args) { lock (this.store) { TreePath path; CellRenderer renderer; if (!this.ImageThumbView.GetCursor(out path, out renderer) || path == null) { return; } TreeIter iter; if (!this.store.GetIter(out iter, path)) { return; } if (this.image != null) { this.image.Dispose(); } BooruImage image = (BooruImage)this.store.GetValue(iter, 2); this.imageView.Anim = image.Anim; this.image = image; UpdateTagButton(); SendImage(); } }
public void DownloadImage() //TODO Progresscallback { if (Image == null) { Image = BooruImage.FromURL(ImageURL); } }
private void _ThreadMethod() { for (int i = 0; i < _IDs.Count && _IsRunning; i++) { using (BooruImage image = _UseImages ? _Booru.GetImage(_IDs[i]) : _Booru.GetThumbnail(_IDs[i])) { try { Texture2D texture = CreateTexture(image); lock (_Textures) _Textures.Add(texture); if (NewTextureLoaded != null) { NewTextureLoaded(); } } catch (Exception ex) { if (_IsRunning) { ScreensaverHelper.HandleException(ex); } } } } if (LoadingFinished != null && _IDs.Count == _Textures.Count) { LoadingFinished(); } }
private void AddImage(BooruImage wrapper) { lock (_booruImagesLockObj) { BooruImages.Add(wrapper); } }
private void SetImage(BooruImage booruImage) { //ToDo Probably it works not fine because sometimes it TagsList could contain tags from prev image PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TagsList")); _currentBooruImage = booruImage; Image = booruImage.Image; }
public void EditImage(BooruUser User, ulong PostID, BooruImage Image) { if (User.CanEditPosts) { DataRow postRow = _DB.ExecuteRow(SQLStatements.GetPostByID, PostID); BooruPost post = BooruPost.FromRow(postRow); if (post != null) { //Maybe Width + Height checks? string thumbPath = Path.Combine(ThumbFolder, "thumb" + PostID); string imagePath = Path.Combine(ImageFolder, "image" + PostID); using (BooruImage thumbImage = Image.CreateThumbnail(BooruInfo.ThumbnailSize, false)) thumbImage.Save(thumbPath, BooruInfo.ThumbnailQuality); Image.Save(imagePath); _ImgOptimizer.Optimize(thumbPath); _ImgOptimizer.Optimize(imagePath); post.Width = (uint)Image.Bitmap.Width; post.Height = (uint)Image.Bitmap.Height; post.ImageHash = Image.CalculateImageHash(); _DB.ExecuteNonQuery(SQLStatements.DeletePostByID, PostID); _DB.ExecuteInsert("posts", post.ToDictionary(true)); } else { throw new BooruException(BooruException.ErrorCodes.ResourceNotFound); } } else { throw new BooruException(BooruException.ErrorCodes.NoPermission); } }
public ulong AddPost(BooruUser User, BooruPost PostWithImage) { if (User.CanAddPosts) { if (!User.AdvancePostControl) { PostWithImage.EditCount = 0; PostWithImage.CreationDate = DateTime.Now; PostWithImage.ViewCount = 0; PostWithImage.User = User.Username; } else if (string.IsNullOrWhiteSpace(PostWithImage.User)) { PostWithImage.User = User.Username; } PostWithImage.Width = (uint)PostWithImage.Image.Bitmap.Width; PostWithImage.Height = (uint)PostWithImage.Image.Bitmap.Height; PostWithImage.ImageHash = PostWithImage.Image.CalculateImageHash(); PostWithImage.ID = (uint)_DB.ExecuteInsert("posts", PostWithImage.ToDictionary(false)); //Maybe Width + Height checks? string thumbPath = Path.Combine(ThumbFolder, "thumb" + PostWithImage.ID); string imagePath = Path.Combine(ImageFolder, "image" + PostWithImage.ID); using (BooruImage thumbImage = PostWithImage.Image.CreateThumbnail(BooruInfo.ThumbnailSize, false)) thumbImage.Save(thumbPath, BooruInfo.ThumbnailQuality); PostWithImage.Image.Save(imagePath); _ImgOptimizer.Optimize(thumbPath); _ImgOptimizer.Optimize(imagePath); CheckAndAddPostTags(ref PostWithImage); return(PostWithImage.ID); } else { throw new BooruException(BooruException.ErrorCodes.NoPermission); } }
public BooruImage GetThumbnail(BooruUser User, ulong PostID) { DataRow postRow = _DB.ExecuteRow(SQLStatements.GetPostByID, PostID); BooruPost post = BooruPost.FromRow(postRow); if (post != null) { string path = Path.Combine(ThumbFolder, "thumb" + PostID); if (User == null) { return(BooruImage.FromFile(path)); } else if (post.Rating <= User.MaxRating && IsPrivacyAllowed(post, User)) { return(BooruImage.FromFile(path)); } else { throw new BooruException(BooruException.ErrorCodes.NoPermission); } } else { throw new BooruException(BooruException.ErrorCodes.ResourceNotFound); } }
//Todo navigation param toggles nav buttons //ToDo Respect tags public void Init( BooruImage openedBooruImage, BooruPostsProvider provider) { _fullImageViewer.Init(provider, openedBooruImage); _currentBooruImage = openedBooruImage; Image = openedBooruImage.Image; }
public OpenFullImageMessage(object sender, BooruImage booruImage, BooruPostsProvider provider) : base(sender) { Provider = provider; BooruImage = booruImage; }
protected void on_TagEntry_activate(object sender, EventArgs args) { if (this.findThread != null) { this.stopThread = true; this.findThread.Join(); this.findThread = null; } this.store.Clear(); this.stopThread = false; this.store = new ListStore(typeof(string), typeof(Gdk.Pixbuf), typeof(BooruImage), typeof(float)); //store.SetSortColumnId(3, SortType.Descending); this.ImageThumbView.Model = store; this.Spinner.Active = true; System.IO.Directory.CreateDirectory("/home/kolrabi/x/extract/" + TagEntry.Text); var start = new ThreadStart(() => { var reader = this.db.QueryImagesWithTags(TagEntry.Text.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); var readerColumns = new Dictionary <string, int> (); for (int i = 0; i < reader.FieldCount; i++) { readerColumns [reader.GetName(i)] = i; } while (reader.Read() && !this.stopThread) { string path = reader.GetString(readerColumns ["path"]); object md5obj = reader.GetValue(readerColumns ["md5sum"]); float elo = reader.GetFloat(readerColumns ["elo"]); int votes = reader.GetInt32(readerColumns ["votes"]); byte[] md5blob = (byte[])md5obj; var data = new BooruImageData(MD5Helper.BlobToMD5(md5blob), path, elo, votes); var image = new BooruImage(data, this.db); try { var info = new Mono.Unix.UnixFileInfo(data.Path); info.CreateSymbolicLink("/home/kolrabi/x/extract/" + TagEntry.Text + "/" + data.MD5 + System.IO.Path.GetExtension(data.Path)); //System.IO.File.Copy(data.Path, "/home/kolrabi/x/extract/" + TagEntry.Text + "/"+data.MD5+System.IO.Path.GetExtension(data.Path)); } catch (Exception ex) { Console.WriteLine("Could not copy " + data.Path + ": " + ex.Message); } Gtk.Application.Invoke((s, a) => { this.store.AppendValues(data.Path + "\n" + string.Join(" ", image.Tags), null, image, data.ELO); }); } Gtk.Application.Invoke((s, a) => { this.Spinner.Active = false; }); }); this.findThread = new Thread(start); this.findThread.Start(); }
private Texture2D CreateTexture(BooruImage Image) { double sideLength = 0; lock (_R) sideLength = _MaxSideLength * (_R.NextDouble() + 0.5) + 0.5; using (BooruImage smallImage = Image.CreateThumbnail((int)sideLength, false)) return(ScreensaverHelper.Texture2DFromBitmap(_GD, smallImage.Bitmap)); }
public void SetBooruImage(GraphicsDevice GD, BooruImage Image) { Dispose(); _Texture = ScreensaverHelper.Texture2DFromBytes(GD, Image.Bytes); float num = Math.Max(_Screen.X / _Texture.Width, _Screen.Y / _Texture.Height); Vector2 resultSize = new Vector2(_Texture.Width * num, _Texture.Height * num); _DrawRectangle = new Rectangle( 0 - (int)((resultSize.X - _Screen.X) / 2 + 0.5), 0 - (int)((resultSize.Y - _Screen.Y) / 2 + 0.5), (int)resultSize.X, (int)resultSize.Y); }
private async Task AddBooruImage(IBooruPost post, Action <BooruImage> addImageCallback, CancellationToken cancellationToken) { var image = await _imageFetcherService.FetchImageAsync( post, ImageSizeType.Preview, caching : false, cancellationToken : cancellationToken).ConfigureAwait(false); var booruImage = new BooruImage { Hash = post.Hash, Image = image }; addImageCallback.Invoke(booruImage); BooruPreviewImages.Add(booruImage); }
private static ProcessStartInfo GetPSI(string File) { using (BooruImage img = BooruImage.FromFile(File)) { if (img.ImageFormat == ImageFormat.Png) { return(GetPSI2(OPTI_PNG_EXE, OPTI_PNG_ARGS, File)); } else if (img.ImageFormat == ImageFormat.Jpeg) { return(GetPSI2(OPTI_JPG_EXE, OPTI_JPG_ARGS, File)); } else if (img.ImageFormat == ImageFormat.Gif) { return(GetPSI2(OPTI_GIF_EXE, OPTI_GIF_ARGS, File)); } else { throw new BadImageFormatException("Optimization not supported for this ImageFormat"); } } }
public BooruImage GetImage(BooruUser User, ulong PostID) { DataRow postRow = _DB.ExecuteRow(SQLStatements.GetPostByID, PostID); BooruPost post = BooruPost.FromRow(postRow); if (post != null) { if (User == null || (post.Rating <= User.MaxRating && IsPrivacyAllowed(post, User))) { BooruImage image = BooruImage.FromFile(Path.Combine(ImageFolder, "image" + PostID)); _DB.ExecuteNonQuery(SQLStatements.UpdateIncrementViewCount, PostID); return(image); } else { throw new BooruException(BooruException.ErrorCodes.NoPermission); } } else { throw new BooruException(BooruException.ErrorCodes.ResourceNotFound); } }
public async Task <List <BooruImage> > GetImagesAsync( BooruSiteType booruSiteType, ImageSizeType imageType, ICollection <IBooruPost> collection, CancellationToken cancellationToken = default) { var images = new List <BooruImage>(); foreach (var booruImage in collection) { if (cancellationToken.IsCancellationRequested) { cancellationToken.ThrowIfCancellationRequested(); } //Todo research why hash may be empty if (string.IsNullOrEmpty(booruImage.Hash)) { continue; } var imageFile = await _imageFetcherService.FetchImageAsync( booruImage, imageType, cancellationToken : cancellationToken); if (imageFile == null) { continue; } var booruImageWrapper = new BooruImage(); booruImageWrapper.Hash = booruImage.Hash; booruImageWrapper.Image = imageFile; images.Add(booruImageWrapper); } return(images); }
protected EditTagsWindow(Builder builder, IntPtr handle, BooruImage image) : base(handle) { builder.Autoconnect(this); var db = image.db; List <string> tags = db.GetAllTags(); tags.Sort(); if (completion == null) { var completionStore = new Gtk.ListStore(typeof(string)); foreach (var tag in tags) { completionStore.AppendValues(tag); completionStore.AppendValues("-" + tag); } completion = new Gtk.EntryCompletion(); completion.Model = completionStore; completion.TextColumn = 0; completion.MinimumKeyLength = 3; } TagEntry.Completion = completion; this.image = image; this.imageView = new ImageViewWidget(); this.imageView.Drawn += (System.Object o, Gtk.DrawnArgs args) => { BooruImageWidget.ImageViewTagsOverlay(args.Cr, this.image, this.imageView); }; this.ImageViewBox.PackStart(this.imageView, true, true, 2); this.imageView.Anim = image.Anim; this.Maximize(); }
private void _ClientHandlerStage3(RequestCode RQ, ReaderWriter RW, ref BooruUser User) { switch (RQ) { default: throw new NotSupportedException("Unknown request code"); case RequestCode.Get_Post: { ulong id = RW.ReadULong(); using (var post = _Booru.GetPost(User, id, false)) post.ToWriter(RW); } break; case RequestCode.Get_Thumb: { ulong id = RW.ReadULong(); using (var thumb = _Booru.GetThumbnail(User, id)) thumb.ToWriter(RW); } break; case RequestCode.Get_Image: { ulong id = RW.ReadULong(); using (var image = _Booru.GetImage(User, id)) image.ToWriter(RW); } break; case RequestCode.Get_Tag: { ulong id = RW.ReadULong(); _Booru.GetTag(User, id).ToWriter(RW); } break; case RequestCode.Get_Info: _Booru.BooruInfo.ToWriter(RW); break; case RequestCode.Get_AllTags: { List <string> tags = _Booru.GetAllTags(); RW.Write((uint)tags.Count); foreach (string tag in tags) { RW.Write(tag, true); } } break; case RequestCode.Get_PostTags: { ulong id = RW.ReadULong(); using (var post = _Booru.GetPost(User, id, false)) post.Tags.ToWriter(RW); } break; case RequestCode.Get_User: User.ToWriter(RW); break; case RequestCode.Get_PostCount: RW.Write(_Booru.GetPostCount()); break; case RequestCode.Search_String: //User limitations? { string pattern = RW.ReadString(); List <ulong> ids = _Booru.Search(User, pattern); RW.Write((uint)ids.Count); foreach (ulong id in ids) { RW.Write(id); } } break; case RequestCode.Search_Image: throw new NotImplementedException(); //TODO Implement case RequestCode.Login: { string username = RW.ReadString(); string password = RW.ReadString(); User = _Booru.Login(User, username, password); } break; case RequestCode.Logout: User = _Booru.DefaultUser; break; case RequestCode.Search_Tags: { string term = RW.ReadString(); byte limit = RW.ReadByte(); _Booru.SearchTags(term, limit).ToWriter(RW); } break; case RequestCode.Start_GC: if (!User.IsAdmin) { throw new BooruException(BooruException.ErrorCodes.NoPermission); } else { GC.Collect(); } break; case RequestCode.Add_Post: using (var post = BooruPost.FromReader(RW)) { post.Tags = BooruTagList.FromReader(RW); post.Image = BooruImage.FromReader(RW); ulong id = _Booru.AddPost(User, post); RW.Write(id); if (_MN != null) { using (var thumb = _Booru.GetThumbnail(null, id)) _MN.NotificatePostAdded(id, post, thumb); } } break; case RequestCode.Edit_Post: { using (var post = BooruPost.FromReader(RW)) { post.Tags = BooruTagList.FromReader(RW); _Booru.EditPost(User, post); } } break; case RequestCode.Edit_Image: { ulong id = RW.ReadULong(); using (var image = BooruImage.FromReader(RW)) _Booru.EditImage(User, id, image); } break; case RequestCode.Delete_Post: { ulong id = RW.ReadULong(); _Booru.DeletePost(User, id); } break; } }
public override object Invoke(object[] args) { byte[] hash1 = Convert.FromBase64String(Convert.ToString(args[0])); byte[] hash2 = Convert.FromBase64String(Convert.ToString(args[1])); return(BooruImage.CompareImageHashes(hash1, hash2)); }
public IBooruPost GetBooruPost(BooruImage booruImage) { return(Posts.FirstOrDefault(p => p.Hash == booruImage.Hash)); }
public static EditTagsWindow Create(BooruImage image, Gtk.Window parent) { Builder builder = new Builder(null, "Booru.interfaces.EditTagsWindow.glade", null); return(new EditTagsWindow(builder, builder.GetObject("dialog1").Handle, image)); }