public virtual void addListener(ImageListener listener, ImageErrorListener onError = null)
        {
            this._listeners.Add(new _ImageListenerPair {
                listener = listener, errorListener = onError
            });

            if (this.currentImage != null)
            {
                try {
                    listener(this.currentImage, true);
                }
                catch (Exception ex) {
                    this.reportError(
                        context: "by a synchronously-called image listener",
                        exception: ex
                        );
                }
            }

            if (this.currentError != null && onError != null)
            {
                try {
                    onError(this.currentError.exception);
                }
                catch (Exception ex) {
                    UIWidgetsError.reportError(
                        new UIWidgetsErrorDetails(
                            exception: ex,
                            library: "image resource service",
                            context: "when reporting an error to an image listener"
                            )
                        );
                }
            }
        }
예제 #2
0
        public ImageStreamCompleter putIfAbsent(object key, Func <ImageStreamCompleter> loader)
        {
            D.assert(key != null);
            D.assert(loader != null);

            if (this._pendingImages.TryGetValue(key, out var result))
            {
                return(result);
            }

            if (this._cache.TryGetValue(key, out var image))
            {
                // put to the MRU position
                this._lruKeys.Remove(image.node);
                image.node = this._lruKeys.AddLast(key);
                return(image.completer);
            }

            result = loader();

            if (this._maximumSize > 0 && this._maximumSizeBytes > 0)
            {
                D.assert(!this._pendingImages.ContainsKey(key));
                this._pendingImages[key] = result;

                ImageListener listener = null;
                listener = (info, syncCall) => {
                    result.removeListener(listener);

                    D.assert(this._pendingImages.ContainsKey(key));
                    this._pendingImages.Remove(key);

                    int          imageSize   = info?.image == null ? 0 : info.image.width & (info.image.height * 4);
                    _CachedImage cachedImage = new _CachedImage {
                        completer = result,
                        sizeBytes = imageSize,
                    };

                    // If the image is bigger than the maximum cache size, and the cache size
                    // is not zero, then increase the cache size to the size of the image plus
                    // some change.
                    if (this._maximumSizeBytes > 0 && imageSize > this._maximumSizeBytes)
                    {
                        this._maximumSizeBytes = imageSize + 1000;
                    }

                    this._currentSizeBytes += imageSize;

                    D.assert(!this._cache.ContainsKey(key));
                    this._cache[key] = cachedImage;
                    cachedImage.node = this._lruKeys.AddLast(key);

                    this._checkCacheSize();
                };
                result.addListener(listener);
            }

            return(result);
        }
예제 #3
0
 public _PendingImage(
     ImageStreamCompleter completer,
     ImageListener listener
     )
 {
     this.completer = completer;
     this.listener  = listener;
 }
 public override void removeListener(ImageListener listener)
 {
     base.removeListener(listener);
     if (!this.hasListeners)
     {
         this._timer?.cancel();
         this._timer = null;
     }
 }
        public override void addListener(ImageListener listener, ImageErrorListener onError = null)
        {
            if (!this.hasListeners && this._codec != null)
            {
                this._decodeNextFrameAndSchedule();
            }

            base.addListener(listener, onError: onError);
        }
 public virtual void removeListener(ImageListener listener)
 {
     for (int i = 0; i < this._listeners.Count; i++)
     {
         if (this._listeners[i].listener == listener)
         {
             this._listeners.RemoveAt(i);
             break;
         }
     }
 }
예제 #7
0
 public ImageStreamListener(
     ImageListener onImage,
     ImageChunkListener onChunk = null,
     ImageErrorListener onError = null
     )
 {
     D.assert(onImage != null);
     this.onImage = onImage;
     this.onChunk = onChunk;
     this.onError = onError;
 }
예제 #8
0
        public EmotionRecognizer(ImageListener listener)
        {
            detector = new PhotoDetector(3, FaceDetectorMode.SMALL_FACES);
            var classifierPath = @"D:\dev\AffdexSDK\data";

            detector.setClassifierPath(classifierPath);
            detector.setDetectAllEmotions(true);

            detector.setImageListener(listener);

            detector.start();
        }
        public void addListener(ImageListener listener, ImageErrorListener onError = null)
        {
            if (this._completer != null)
            {
                this._completer.addListener(listener, onError);
                return;
            }

            if (this._listeners == null)
            {
                this._listeners = new List <_ImageListenerPair>();
            }

            this._listeners.Add(new _ImageListenerPair {
                listener = listener, errorListener = onError
            });
        }
예제 #10
0
        public void removeListener(ImageListener listener)
        {
            if (this._completer != null)
            {
                this._completer.removeListener(listener);
                return;
            }

            D.assert(this._listeners != null);
            for (int i = 0; i < this._listeners.Count; i++)
            {
                if (this._listeners[i].listener == listener)
                {
                    this._listeners.RemoveAt(i);
                    break;
                }
            }
        }
예제 #11
0
        public ImageModuleData([NotNull] ModuleDataConstructor constructor) :
            base(constructor.GetConfiguration <ImageConfiguration>()?.Topic ?? constructor.Topic,
                 constructor.GetConfiguration <ImageConfiguration>()?.Type ?? constructor.Type)
        {
            panel    = DataPanelManager.GetPanelByResourceType <ImagePanelContents>(ModuleType.Image);
            listener = new ImageListener(this);
            if (constructor.Configuration != null)
            {
                listener.Config = (ImageConfiguration)constructor.Configuration;
            }
            else
            {
                listener.Config.Topic = Topic;
                listener.Config.Type  = Type;
            }

            listener.StartListening();
            UpdateModuleButton();
        }
예제 #12
0
        private static async Task <Bitmap> InnerLoadImageAsync(CancellationToken ct, string uri, ImageView imageView, Size?targetSize, DisplayImageOptions options)
        {
            TaskCompletionSource <Bitmap> source = new TaskCompletionSource <Bitmap>();


            options = options ?? new DisplayImageOptions.Builder()
                      .CacheInMemory(true)
                      .CacheOnDisk(true)
                      .Build();

            // Propagate cancellation to the managed TCS, even though we don't propagate it to Universal Image Loader. This is because UIL has
            // the air of cancelling downloads itself if another uri is requested for the same ImageView, leading us to wait on a task that
            // will never complete (thanks to the concurrency logic reusing existing tasks).
            using (ct.Register(() => source.TrySetCanceled()))
            {
                using (var aware =
                           imageView != null
                                                ? new ImageViewAwareCancellable(imageView, ct)
                                                : null
                       )
                {
                    using (var listener = new ImageListener(source))
                    {
                        if (targetSize != null && imageView != null)
                        {
                            imageView.SetMaxHeight(targetSize.Value.Height);
                            imageView.SetMaxWidth(targetSize.Value.Width);

                            ImageLoader.Instance.DisplayImage(
                                uri,
                                aware,
                                options,
                                listener
                                );
                        }
                        else if (targetSize != null && imageView == null)
                        {
                            var targetImageSize = new ImageSize(targetSize.Value.Width, targetSize.Value.Height);

                            ImageLoader.Instance.LoadImage(
                                uri,
                                targetImageSize,
                                options,
                                listener
                                );
                        }
                        else
                        {
                            ImageLoader.Instance.LoadImage(
                                uri,
                                options,
                                listener
                                );
                        }

                        var target = await source.Task;

                        return(target);
                    }
                }
            }
        }