private void AddDetectedFacesToListViewPanel()
        {
            try
            {
                if (its_time_to_pick_perpetrator_faces)
                {
                    if (detected_faces != null && current_frame != null)
                    {
                        ImageListView image_list_view = Singleton.SELECT_PERP_FACES.GetImageListView();

                        for (int i = 0; i < detected_faces.Length; i++)
                        {
                            //get face
                            Image <Bgr, byte> face = FramesManager.CropSelectedFace(detected_faces[i], current_frame.Clone());

                            //resize face
                            face = FramesManager.ResizeColoredImage(face, new Size(120, 120));

                            //add face to image list
                            Singleton.SELECT_PERP_FACES.suspect_faces.TryAdd(count, face);

                            //add face to image list view
                            image_list_view.Invoke(new AddImage(Singleton.SELECT_PERP_FACES.AddImage), new object[] { "face " + count, "face " + count, face.ToBitmap() });

                            //increment id counter
                            count++;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
        /// <summary>
        /// Adds a virtual item to the cache.
        /// </summary>
        /// <param name="guid">The guid representing this item.</param>
        /// <param name="key">The key of this item.</param>
        /// <param name="thumbSize">Requested thumbnail size.</param>
        /// <param name="thumb">Thumbnail image to add to cache.</param>
        /// <param name="useEmbeddedThumbnails">UseEmbeddedThumbnails property of the owner control.</param>
        public void Add(Guid guid, object key, Size thumbSize, Image thumb, UseEmbeddedThumbnails useEmbeddedThumbnails)
        {
            lock (lockObject)
            {
                // Already cached?
                CacheItem item = null;
                if (thumbCache.TryGetValue(guid, out item))
                {
                    if (item.Size == thumbSize && item.UseEmbeddedThumbnails == useEmbeddedThumbnails)
                    {
                        return;
                    }
                    else
                    {
                        item.Dispose();
                        thumbCache.Remove(guid);
                    }
                }
                // Add to cache
                thumbCache.Add(guid, new CacheItem(guid, key, thumbSize, thumb,
                                                   CacheState.Cached, useEmbeddedThumbnails));
            }

            try
            {
                if (mImageListView != null && mImageListView.IsHandleCreated && !mImageListView.IsDisposed)
                {
                    //Call for big pictures??? Not Item thumbs
                    mImageListView.Invoke(new ThumbnailCachedEventHandlerInternal(mImageListView.OnThumbnailCachedInternal), guid, thumb, thumbSize, false, false, false);
                    mImageListView.Invoke(new RefreshDelegateInternal(mImageListView.OnRefreshInternal));
                }
            }
            catch (ObjectDisposedException)
            {
                if (!Stopping)
                {
                    throw;
                }
            }
            catch (InvalidOperationException)
            {
                if (!Stopping)
                {
                    throw;
                }
            }
        }
        /// <summary>
        /// Adds the image to the cache queue.
        /// </summary>
        /// <param name="guid">The guid representing this item.</param>
        /// <param name="filename">Filesystem path to the image file.</param>
        /// <param name="thumbSize">Requested thumbnail size.</param>
        /// <param name="thumb">Thumbnail image to add to cache.</param>
        /// <param name="useEmbeddedThumbnails">UseEmbeddedThumbnails property of the owner control.</param>
        public void Add(Guid guid, string filename, Size thumbSize, Image thumb,
                        UseEmbeddedThumbnails useEmbeddedThumbnails)
        {
            lock (lockObject)
            {
                // Already cached?
                CacheItem item = null;
                if (thumbCache.TryGetValue(guid, out item))
                {
                    if (item.Size == thumbSize && item.UseEmbeddedThumbnails == useEmbeddedThumbnails)
                    {
                        return;
                    }
                }
                // Add to cache
                thumbCache.Add(guid, new CacheItem(guid, filename, thumbSize,
                                                   Utility.ThumbnailFromImage(thumb, thumbSize),
                                                   CacheState.Cached));
            }

            try
            {
                if (mImageListView != null && mImageListView.IsHandleCreated && !mImageListView.IsDisposed)
                {
                    mImageListView.Invoke(new ThumbnailCachedEventHandlerInternal(
                                              mImageListView.OnThumbnailCachedInternal), guid, false);
                    mImageListView.Invoke(new RefreshDelegateInternal(
                                              mImageListView.OnRefreshInternal));
                }
            }
            catch (ObjectDisposedException)
            {
                if (!Stopping)
                {
                    throw;
                }
            }
            catch (InvalidOperationException)
            {
                if (!Stopping)
                {
                    throw;
                }
            }
        }
        /// <summary>
        /// Used by the worker thread to read item data.
        /// </summary>
        private void DoWork()
        {
            while (!Stopping)
            {
                CacheItem item = null;
                lock (lockObject)
                {
                    // Wait until we have items waiting to be cached
                    if (toCache.Count == 0)
                    {
                        Monitor.Wait(lockObject);
                    }

                    // Get an item from the queue
                    if (toCache.Count != 0)
                    {
                        item = toCache.Dequeue();

                        // Is it being edited?
                        if (editCache.ContainsKey(item.Item.Guid))
                        {
                            item = null;
                        }
                    }
                }

                // Read file info
                if (item != null)
                {
                    if (item.IsVirtualItem)
                    {
                        if (mImageListView != null && mImageListView.IsHandleCreated && !mImageListView.IsDisposed)
                        {
                            VirtualItemDetailsEventArgs e = new VirtualItemDetailsEventArgs(item.VirtualItemKey);
                            mImageListView.RetrieveVirtualItemDetailsInternal(e);
                            mImageListView.Invoke(new UpdateVirtualItemDetailsDelegateInternal(
                                                      mImageListView.UpdateItemDetailsInternal), item.Item, e);
                        }
                    }
                    else
                    {
                        Utility.ShellImageFileInfo info = new Utility.ShellImageFileInfo(item.FileName);
                        // Update file info
                        if (!Stopping)
                        {
                            try
                            {
                                if (mImageListView != null && mImageListView.IsHandleCreated && !mImageListView.IsDisposed)
                                {
                                    mImageListView.Invoke(new UpdateItemDetailsDelegateInternal(
                                                              mImageListView.UpdateItemDetailsInternal), item.Item, info);
                                }
                            }
                            catch (ObjectDisposedException)
                            {
                                if (!Stopping)
                                {
                                    throw;
                                }
                            }
                            catch (InvalidOperationException)
                            {
                                if (!Stopping)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                }
            }

            lock (lockObject)
            {
                stopped = true;
            }
        }
예제 #5
0
            /// <summary>
            /// Updates snow flakes at each timer tick.
            /// </summary>
            /// <param name="state">Not used, null.</param>
            private void UpdateTimerCallback(object state)
            {
                if (inTimer)
                {
                    return;
                }
                inTimer = true;

                bool redraw = false;

                lock (lockObject)
                {
                    if (displayBounds.IsEmpty)
                    {
                        inTimer = false;
                        return;
                    }

                    if (flakes == null)
                    {
                        flakes = new List <SnowFlake>();
                    }

                    // Add new snow flakes
                    currentGeneration++;
                    if (currentGeneration == flakeGeneration)
                    {
                        currentGeneration = 0;
                        if (flakes.Count < maxFlakeCount)
                        {
                            SnowFlake snowFlake = new SnowFlake(random.Next(minFlakeSize, maxFlakeSize));
                            snowFlake.Rotation = 360.0 * random.NextDouble();
                            snowFlake.Location = new Point(random.Next(displayBounds.Left, displayBounds.Right), -20);
                            flakes.Add(snowFlake);
                        }
                    }

                    // Move snow flakes
                    for (int i = flakes.Count - 1; i >= 0; i--)
                    {
                        SnowFlake snowFlake = flakes[i];
                        if (snowFlake.Location.Y > displayBounds.Height)
                        {
                            flakes.Remove(snowFlake);
                        }
                        else
                        {
                            snowFlake.Location  = new Point(snowFlake.Location.X, snowFlake.Location.Y + snowFlake.Size * fallSpeed / 10);
                            snowFlake.Rotation += 360.0 / 40.0;
                            if (snowFlake.Rotation > 360.0)
                            {
                                snowFlake.Rotation -= 360.0;
                            }
                        }
                    }

                    // Do we need a refresh?
                    if ((DateTime.Now - lastRedraw).Milliseconds > refreshPeriod)
                    {
                        redraw = true;
                    }
                }

                if (redraw)
                {
                    try
                    {
                        if (ImageListView.InvokeRequired)
                        {
                            ImageListView.Invoke((MethodInvoker) delegate { ImageListView.Refresh(); });
                        }
                        else
                        {
                            ImageListView.Refresh();
                        }
                    }
                    catch
                    {
                        ;
                    }
                }

                inTimer = false;
            }
예제 #6
0
        /// <summary>
        /// Used by the worker thread to read item data.
        /// </summary>
        private void DoWork()
        {
            while (!Stopping)
            {
                CacheItem item = null;
                lock (lockObject)
                {
                    // Wait until we have items waiting to be cached
                    if (toCache.Count == 0)
                    {
                        Monitor.Wait(lockObject);
                    }

                    // Get an item from the queue
                    if (toCache.Count != 0)
                    {
                        item = toCache.Dequeue();

                        // Is it being edited?
                        if (editCache.ContainsKey(item.Item.Guid))
                        {
                            item = null;
                        }
                    }
                }

                // Read file info
                if (item != null)
                {
                    long requestedTickCount = Utility.TickCount();
                    RetrieveItemMetadataDetailsEventArgs e = new RetrieveItemMetadataDetailsEventArgs(item.FileName);
                    mImageListView.RetrieveItemMetadataDetailsInternal(e);


                    Utility.ShellImageFileInfo info;
                    if (e.FileMetadata != null)
                    {
                        info = e.FileMetadata;
                    }
                    else //If not handel outside, try internal
                    {
                        info = new Utility.ShellImageFileInfo(item.FileName);
                    }

                    // Update file info
                    if (!Stopping)
                    {
                        try
                        {
                            if (mImageListView != null && mImageListView.IsHandleCreated && !mImageListView.IsDisposed && mImageListView.Enabled)
                            {
                                mImageListView.Invoke(new UpdateItemDetailsDelegateInternal(mImageListView.UpdateItemDetailsInternal), item.Item, info, requestedTickCount);
                            }
                        }
                        catch (ObjectDisposedException ex)
                        {
                            Logger.Warn("DoWork: " + ex.Message);
                            //if (!stopping) throw;
                        }
                        catch (InvalidOperationException ex)
                        {
                            Logger.Warn("DoWork: " + ex.Message);
                            //if (!stopping) throw;
                        }
                    }
                }
            }

            lock (lockObject)
            {
                stopped = true;
            }
        }