public void SetSelection(ImageSelection selection)
 {
     SetUniform1("x0", selection.X0);
     SetUniform1("x1", selection.X1);
     SetUniform1("y0", selection.Y0);
     SetUniform1("y1", selection.Y1);
 }
Example #2
0
        /// <inheritdoc/>
        public override void Remove()
        {
            base.Remove();

            _selection.Remove();
            _selection = null;
        }
Example #3
0
 public override void ClearImagesColors()
 {
     for (int i = 0; i < images[this.currentChallenge].Length; i++)
     {
         ImageSelection.SetSingleImageColor(i, new Color(255, 255, 255, 255));
     }
 }
Example #4
0
    public override void SetupMiniGame()
    {
        progress.gameObject.SetActive(true);
        ImageSelection.selectedImages = new LinkedList <int>();
        int i = 0;

        while (i < images[this.currentChallenge].Length)
        {
            sceneElement.Find("MiniGame/image" + i).gameObject.SetActive(true);
            sceneElement.Find("MiniGame/image" + i).GetComponent <Image>().sprite = images[this.currentChallenge][i].image;
            ImageSelection.SetSingleImageHighlightColor(i, new Color32(255, 255, 255, 255));
            i++;
        }
        while (i < 12)
        {
            sceneElement.Find("MiniGame/image" + i).gameObject.SetActive(false);
            i++;
        }

        int k = 0;

        while (k <= this.currentChallenge)
        {
            progress.Find("p" + k).GetComponent <Image>().sprite = PlayerInfo.miniGameDoneImg;
            k++;
        }
        while (k < images.Length)
        {
            progress.Find("p" + k).GetComponent <Image>().sprite = PlayerInfo.miniGameToDoImg;
            k++;
        }
    }
Example #5
0
 private static void BuildCategoriesForRegionSourcesForHubs(string region, string where)
 {
     ImageSelection.BuildCategoryImagesForHub(region);
     foreach (var id in Utils.GetIdsForRegion(region))
     {
         ImageSelection.BuildSourceImagesForHub(id);
     }
 }
Example #6
0
 internal static void MakeImageSelectionValid(ImageSelection item)
 {
     Assert.IsTrue(item.AllImages.Count > 0);
     foreach (var currItem in item.AllImages)
     {
         currItem.IsSelected = true;
     }
     Assert.IsTrue(String.IsNullOrWhiteSpace(item.Error));
 }
Example #7
0
 internal static void MakeImageSelectionInvalidNoSelectedImages(ImageSelection item)
 {
     Assert.IsTrue(item.AllImages.Count > 0);
     foreach (var currItem in item.AllImages)
     {
         currItem.IsSelected = false;
     }
     Assert.IsTrue(!String.IsNullOrWhiteSpace(item.Error));
 }
Example #8
0
        public override void PopulateToolstrip(ToolStrip toolStrip)
        {
            _selectionDropdown = new ToolStripComboBox("Selection");
            _selectionDropdown.Items.AddRange(new[] { _newSelection }.Concat(AvailableSelections).Select(s => (object)s).ToArray());
            _selectionDropdown.DropDownStyle         = ComboBoxStyle.DropDownList;
            _selectionDropdown.SelectedItem          = _currentSelection;
            _selectionDropdown.SelectedIndexChanged += (sender, args) =>
            {
                _currentSelection            = (ImageSelection)_selectionDropdown.SelectedItem;
                _saveSelectionButton.Enabled = _currentSelection.Name == NewSelectionName;
                _drawable.Selection          = _currentSelection;
                _drawable.SelectionUpdate();
            };

            _selectionModeDropdown = new ToolStripComboBox("Selection Mode");
            _selectionModeDropdown.Items.AddRange(EnumExtensions.GetValues <SelectionMode>().Select(v => (object)v).ToArray());
            _selectionModeDropdown.DropDownStyle         = ComboBoxStyle.DropDownList;
            _selectionModeDropdown.SelectedItem          = _currentSelectionMode;
            _selectionModeDropdown.SelectedIndexChanged += (sender, args) =>
            {
                _currentSelectionMode = (SelectionMode)_selectionModeDropdown.SelectedItem;

                int size = 2048;
                if (_currentSelectionMode == SelectionMode.Square512X512)
                {
                    size = 512;
                }
                else if (_currentSelectionMode == SelectionMode.Square1024X1024)
                {
                    size = 1024;
                }

                _currentSelection.Width  = size;
                _currentSelection.Height = size;
                _drawable.SelectionUpdate();
            };

            _saveSelectionButton = new ToolStripButton("Сохранить")
            {
                Enabled = _currentSelection.Name == NewSelectionName
            };
            _saveSelectionButton.Click += (sender, args) =>
            {
                var imageName = _renderer.ImageHandler?.GetTitle() ?? "Область";
                _currentSelection.Name = $"{imageName} {AvailableSelections.Count(s => s.Name.StartsWith(imageName)) + 1}";
                Singleton.Get <ImageSelectionManager>().SetSelection(_renderer.ImageHandler, _currentSelection);
                _saveSelectionButton.Enabled    = false;
                _selectionDropdown.SelectedItem = _currentSelection;
            };

            _selectionInfoLabel = new ToolStripLabel();

            toolStrip.Items.Add(_selectionDropdown);
            toolStrip.Items.Add(_selectionModeDropdown);
            toolStrip.Items.Add(_saveSelectionButton);
            toolStrip.Items.Add(_selectionInfoLabel);
        }
Example #9
0
 public override void ClearImagesColors()
 {
     for (int i = 0; i < 2; i++)
     {
         for (int j = 0; j < images[this.currentChallenge][i].Length; j++)
         {
             ImageSelection.SetImageOfMultiplesColor(i, j, new Color(255, 255, 255, 255));
         }
     }
 }
Example #10
0
		public static void ProcessRegion(string region)
		{
			if ( ! Utils.IsRegion (region) )
				throw new Exception(String.Format("ProcessRegion called erroneously for {0}", region));

			GenUtils.LogMsg("status", "worker starting on region tasks for " + region, null);

			var calinfo = Utils.AcquireCalinfo(region);

			try
			{
				var es_region = new ZonelessEventStore(calinfo);

				var ids = Utils.GetIdsForRegion(region);

				Parallel.ForEach(source: ids, body: (id) =>
				{
					var uri = BlobStorage.MakeAzureBlobUri(id, id + ".zoneless.obj", false);
					var es = (ZonelessEventStore)BlobStorage.DeserializeObjectFromUri(uri);
					foreach (var evt in es.events)
					{
						evt.categories += "," + id.ToLower();  // so tag viewer can slice region by hub name
						lock (es_region)
						{
							es_region.events.Add(evt);
						}
					}
				}
				);

				Utils.UpdateFeedCountForId(region);

				ZonelessEventStore.Finalize(calinfo, es_region);

				CacheUtils.MarkBaseCacheEntryForRemoval(Utils.MakeBaseZonelessUrl(region), Convert.ToInt32(settings["webrole_instance_count"]));

				RenderTags(region);

				Utils.TagsByHub(region, authorized: true);
				Utils.TagsByHub(region, authorized: false);

				SaveRegionStats(region);

				ImageSelection.BuildCategoryImagesForHub(region);

				Utils.SaveQuickStatsForRegion(region);
			}
			catch (Exception e)
			{
				var msg = "process region: " + region;
				var data = e.Message + e.StackTrace;
				GenUtils.PriorityLogMsg("exception", msg, data);
			}
			GenUtils.LogMsg("status", "worker done processing region " + region, null);
		}
Example #11
0
		public static void FinalizeHub(string id)
		{
			if (Utils.IsRegion(id))
				throw new Exception(String.Format("FinalizeHub called erroneously for {0}", id));

			GenUtils.LogMsg("status", "worker finalizing hub: " + id, null);

			Utils.UpdateFeedCountForId(id);

			var calinfo = Utils.AcquireCalinfo(id);

			EventStore.CombineZonedEventStoresToZonelessEventStore(id, settings); 

			// Create or update an entry in the cacheurls table for the base object. 
			// key is http://elmcity.blob.core.windows.net/ID/ID.zoneless.obj
			// value is # of webrole instances that could be holding this in cache
			// each instance will check this table periodically. if value is nonzero and url in cache, it'll evict the object
			// and decrement the count

			// note when removal occurs it also triggers a purge of dependencies, so if the base entry is
			// http://elmcity.blob.core.windows.net/a2cal/a2cal.zoneless.obj
			// then dependencies also ousted from cache include:
			// /services/a2cal/html?view=&count=0
			// /services/a2cal/rss?view=government
			// /services/a2cal/xml?view=music&count=10    ... etc.

			CacheUtils.MarkBaseCacheEntryForRemoval(Utils.MakeBaseZonelessUrl(id), Convert.ToInt32(settings["webrole_instance_count"]));

			RenderTags(id);  // static renderings, mainly for debugging now that GetEvents uses dynamic rendering

			var fr = new FeedRegistry(id);
			fr.LoadFeedsFromAzure(FeedLoadOption.all);

			if (calinfo.hub_enum == HubType.where)
			{
				SaveWhereStats(fr, calinfo);
				Utils.SaveMeetupLocations(calinfo, settings);
			}

			if (calinfo.hub_enum == CalendarAggregator.HubType.what)
				SaveWhatStats(fr, calinfo);

			//if (!Utils.IsRegion(id))
			//	MergeIcs(calinfo);
			// else  
			// todo: create MergeRegionIcs

			Utils.VisualizeTagSources(id);

			ImageSelection.BuildCategoryImagesForHub(id);

			GenUtils.LogMsg("status", "worker done finalizing hub " + id, null);
		}
        private async void Photograph(object obj)
        {
            ImageSelection selection = await SelectionMode();

            MediaFile file = await PictureService.ChoixImage(selection);

            if (file != null)
            {
                ApiClient client = new ApiClient();
                image = await client.PublishImage(file);
            }
        }
Example #13
0
        /// <inheritdoc/>
        public override void ToStateOne()
        {
            base.ToStateOne();

            _selection = new ImageSelection(
                _editor.Project.CurrentContainer.HelperLayer,
                _image,
                _editor.Project.Options.HelperStyle,
                _editor.Project.Options.PointShape);

            _selection.ToStateOne();
        }
Example #14
0
 public Server(String address, ImageSelection selection, String imagesBaseURL,
               int frameRate, ILogger <Server> logger, OpenTracing.ITracer tracer)
 {
     this.frameRate       = frameRate;
     this.imagesBaseURL   = imagesBaseURL;
     this.address         = address;
     this.webSocketServer = new WebSocketServer(this.address);
     this.allSockets      = new List <IWebSocketConnection>();
     this.selection       = selection;
     this.allImages       = getSelectedImageList(selection, imagesBaseURL);
     this.source          = new CancellationTokenSource();
     this.token           = source.Token;
     this._logger         = logger;
     this._tracer         = tracer;
 }
Example #15
0
        public async Task <AnalysisResult[]> SubmitSelection(ImageSelection selection)
        {
            // Proof of concept - receives selection and extracts section of base image.
            var image = await _imageRetriever.RetrieveImage(selection.BaseImagePath);

            Bitmap     baseBmp      = new Bitmap(image);
            RectangleF cropRegion   = new RectangleF((float)selection.X, (float)selection.Y, (float)selection.Width, (float)selection.Height);
            var        outputBitmap = new Bitmap((int)selection.Width, (int)selection.Height);
            Graphics   selectedArea = Graphics.FromImage(outputBitmap);

            selectedArea.DrawImage(baseBmp, 0, 0, cropRegion, GraphicsUnit.Pixel);

            // Result of DrawImage can be used in further processing/analysis
            return(await _imageAnalyser.Analyse(outputBitmap));
        }
Example #16
0
        public SelectImagesViewModel(IDispatcher dispatcher, ISelectImagesView view, ImageSelection model, IFileEnumerator fileEnumerator, ImageInspectViewModel imageInspectViewModel)
            : base(view)
        {
            if (dispatcher == null)
            {
                throw new ArgumentNullException("dispatcher");
            }
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }
            if (fileEnumerator == null)
            {
                throw new ArgumentNullException("fileEnumerator");
            }
            if (imageInspectViewModel == null)
            {
                throw new ArgumentNullException("imageInspectViewModel");
            }

            _dispatcher            = dispatcher;
            _model                 = model ?? new ImageSelection();
            _fileEnumerator        = fileEnumerator;
            _imageInspectViewModel = imageInspectViewModel;

            _selectImageCommand = new DelegateCommand(
                i =>
            {
                var img = i as SelectableImage;
                if (img != null)
                {
                    img.IsSelected = !img.IsSelected;
                }
            });
            _previewImageCommand = new DelegateCommand(
                i =>
            {
                var img = i as SelectableImage;
                if (img != null)
                {
                    _imageInspectViewModel.Model = new ImageInspection {
                        FullPath = img.FullPath
                    };
                    _imageInspectViewModel.ShowView();
                }
            });
        }
Example #17
0
 /*
  * handleOnMassage() handles userinput and acts accordingly
  */
 public void handleOnMassage(IWebSocketConnection socket, String message)
 {
     using (var scope = _tracer.BuildSpan("handleOnMassage").StartActive(true))
     {
         _logger.LogInformation("Function: handleOnMassage(" + message + ")");
         if (message.Equals("exit"))
         {
             socket.Close();
         }
         else if (message.Equals("earth"))
         {
             this.selection       = ImageSelection.Earth;
             this.selectNewImages = true;
         }
         else if (message.Equals("yoda"))
         {
             this.selection       = ImageSelection.Yoda;
             this.selectNewImages = true;
         }
         else if (message.Equals("babyyoda"))
         {
             this.selection       = ImageSelection.BabyYoda;
             this.selectNewImages = true;
         }
         if (this.selectNewImages)
         {
             this.allImages = getSelectedImageList(this.selection, this.imagesBaseURL);
             if (sendImage != null)
             {
                 this.sendImage.Wait();
                 this.taskCompleted = this.sendImage.IsCompleted;
             }
             this.selectNewImages = false;
             this.sendImage       = Task.Factory.StartNew(this.createSendDelayedFramesAction(), CancellationToken.None, TaskCreationOptions.DenyChildAttach,
                                                          TaskScheduler.Default);
         }
         scope.Span.Log(new Dictionary <string, object>
         {
             [OpenTracing.LogFields.Event] = "ImageSelection",
             ["value"] = selection
         });
         Console.WriteLine(message);
     }
 }
Example #18
0
        /*
         * getSelectedImageList() Returns List of Imagedata based on Selection. imagesBaseURL is used as searchpath. imagesBaseURL is Runtimedependent
         */
        private static List <ImageData> getSelectedImageList(ImageSelection selection, String imagesBaseURL)
        {
            List <ImageData> list = new List <ImageData>();

            switch (selection)
            {
            case ImageSelection.Earth:
                imagesBaseURL += "/earth";
                break;

            case ImageSelection.Yoda:
                imagesBaseURL += "/yoda";
                break;

            case ImageSelection.BabyYoda:
                imagesBaseURL += "/babyyoda";
                break;
            }
            Directory.GetFiles(imagesBaseURL).ToList().ForEach(file => list.Add(new ImageData(Path.GetFileName(file), file)));
            return(list);
        }
Example #19
0
      public static async Task <MediaFile> ChoixImage(ImageSelection pictureService)
      {
          await CrossMedia.Current.Initialize();

          if (pictureService == ImageSelection.FROM_GALLERY)
          {
              if (!CrossMedia.Current.IsPickPhotoSupported)
              {
                  IDialogService dialog = DependencyService.Get <IDialogService>();
                  await dialog.DisplayAlertAsync("Error", "No media available", "Close");

                  return(null);
              }

              return(await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions()
                {
                    PhotoSize = PhotoSize.Small,
                }));
          }

          if (pictureService == ImageSelection.FROM_CAMERA)
          {
              if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
              {
                  IDialogService dialog = DependencyService.Get <IDialogService>();
                  await dialog.DisplayAlertAsync("Error", "No media available", "Close");

                  return(null);
              }

              return(await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Sample",
                    Name = "test.jpg",
                    PhotoSize = PhotoSize.Small,
                }));
          }

          return(null);
      }
        public static Bitmap ExtractSelection(Bitmap bmp, ImageSelection selection)
        {
            // TODO: use bmp pixel format
            var extraction = new Bitmap(selection.Width, selection.Height, PixelFormat.Format24bppRgb);

            var srcBitmapData = bmp.LockBits(Rectangle.FromLTRB(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            var dstBitmapData = extraction.LockBits(Rectangle.FromLTRB(0, 0, selection.Width, selection.Height),
                                                    ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
            var length = selection.Width * selection.Height * 3;

            unsafe
            {
                var srcPointer = (byte *)srcBitmapData.Scan0;
                var dstPointer = (byte *)dstBitmapData.Scan0;
                int x;
                int srcCoord, dstCoord;
                for (int y = 0; y < selection.Height; y++)
                {
                    for (x = 0; x < selection.Width; x++)
                    {
                        dstCoord = x + y * selection.Width;
                        srcCoord = x + selection.X0 + (y + selection.Y0) * bmp.Width;
                        dstPointer[dstCoord * 3]     = srcPointer[srcCoord * 3];
                        dstPointer[dstCoord * 3 + 1] = srcPointer[srcCoord * 3 + 1];
                        dstPointer[dstCoord * 3 + 2] = srcPointer[srcCoord * 3 + 2];
                    }
                }
//                for (int i = 0; i < length; i++)
//                {
//                    dstPointer[0] = srcPointer[0];
//                    dstPointer++;
//                    srcPointer++;
//                }
            }

            bmp.UnlockBits(srcBitmapData);
            extraction.UnlockBits(dstBitmapData);

            return(extraction);
        }
Example #21
0
        public SelectionTool(ImageRenderer renderer)
        {
            _renderer   = renderer;
            _buttonInfo = new ToolboxButtonInfo
            {
                Icon = Resources.select,
                Text = "Выделение"
            };

            if (!_renderer.ImageHandler.IsReady() || !Singleton.Get <ImageSelectionManager>().TryGetSelection(_renderer.ImageHandler, out _newSelection))
            {
                _newSelection = new ImageSelection
                {
                    Name = NewSelectionName
                };
                _newSelection.Width  = 2816;
                _newSelection.Height = 2816;
            }

            _currentSelection   = _newSelection;
            _drawable           = new SelectionDrawable();
            _drawable.Selection = _currentSelection;
        }
Example #22
0
    protected void DisplayUserState()
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        string crlf = "\r\n";

        #region UserState
        PictureTrimmerUserState userState = this.InlinePictureTrimmer1.UserState;

        #region Value
        PictureTrimmerValue value = userState.Value;

        #region ImageSelection
        ImageSelection imageSelection = value.ImageSelection;

        #region ImageTransformation
        ImageTransformation imageTransformation = imageSelection.Transformation;

        sb.Length = 0;
        sb.Append("Resize factor:" + imageTransformation.ResizeFactor.ToString(CultureInfo.InvariantCulture) + "%" + crlf);
        sb.Append("Rotation angle:" + imageTransformation.RotationAngle.ToString(CultureInfo.InvariantCulture) + "°" + crlf);
        sb.Append("Flip horizontal:" + (imageTransformation.FlipH ? "yes" : "no") + crlf);
        sb.Append("Flip vertical:" + (imageTransformation.FlipV ? "yes" : "no") + crlf);
        this.txtUserState_Value_ImageSelection_Transformation.Text = sb.ToString();
        #endregion

        #region ImageCrop
        ImageCrop imageCrop = imageSelection.Crop;

        sb.Length = 0;
        sb.Append("Rectangle:" + (imageCrop.Rectangle.HasValue ? imageCrop.Rectangle.Value.ToString() : "Auto") + crlf);
        // Note: in this example imageCrop.CanvasColor is not displayed.
        this.txtUserState_Value_ImageSelection_Crop.Text = sb.ToString();
        #endregion

        #endregion

        #region ImageAdjustments
        ImageAdjustmentsFilter imageAdjustments = value.ImageAdjustments;

        sb.Length = 0;
        sb.Append("Brightness:" + imageAdjustments.Brightness.ToString(CultureInfo.InvariantCulture) + crlf);
        sb.Append("Contrast:" + imageAdjustments.Contrast.ToString(CultureInfo.InvariantCulture) + crlf);
        sb.Append("Hue:" + imageAdjustments.Hue.ToString(CultureInfo.InvariantCulture) + "°" + crlf);
        sb.Append("Saturation:" + imageAdjustments.Saturation.ToString(CultureInfo.InvariantCulture) + crlf);
        this.txtUserState_Value_ImageAdjustments.Text = sb.ToString();
        #endregion

        // Note: In this example value.ImageBackColorApplyMode is not displayed.

        #endregion

        #region UIParams
        PictureTrimmerUIParams uiParams = userState.UIParams;

        sb.Length = 0;
        sb.Append("Zoom factor:" + (uiParams.ZoomFactor.HasValue ? uiParams.ZoomFactor.Value.ToString(CultureInfo.InvariantCulture) + "%" : "auto") + crlf);
        sb.Append("Picture scroll horizontal:" + (uiParams.PictureScrollH.HasValue ? uiParams.PictureScrollH.Value.ToString(CultureInfo.InvariantCulture) : "auto") + crlf);
        sb.Append("Picture scroll vertical:" + (uiParams.PictureScrollH.HasValue ? uiParams.PictureScrollV.Value.ToString(CultureInfo.InvariantCulture) : "auto") + crlf);
        sb.Append("Command panel scroll vertical:" + uiParams.CommandPanelScrollV.ToString(CultureInfo.InvariantCulture) + crlf);
        this.txtUserState_UIParams.Text = sb.ToString();

        #endregion

        #endregion
    }
Example #23
0
        public async Task <AnalysisResult[]> SubmitSelection(ImageSelection selection)
        {
            var response = await httpClient.PostAsJsonAsync($"api/imageservice", selection);

            return(await response.Content.ReadFromJsonAsync <AnalysisResult[]>());
        }
Example #24
0
 public CurveBitmap(Curve curve)
 {
     Curve = curve;
     CurrentImageSelection = ImageSelection.Primary;
     _nextImageSelection = ImageSelection.Secondary;
 }
Example #25
0
 public async Task <AnalysisResult[]> Post(ImageSelection selection)
 {
     return(await _processor.SubmitSelection(selection));
 }
Example #26
0
 public void Flip()
 {
     CurrentImageSelection = _nextImageSelection;
     _nextImageSelection = _nextImageSelection == ImageSelection.Primary
         ? ImageSelection.Secondary
         : ImageSelection.Primary;
 }