예제 #1
0
        private async Task ParseInputStream(IBoundedQueue <MutableByteImage> queue, IBoundedQueue <byte[]> chunksQueue, int width, int height, ChunkedSimpleMemoryStream memoryStream)
        {
            int count = 0;

            while (true)
            {
                try
                {
                    var item = await chunksQueue.DequeueOrDefault();

                    if (item == default)
                    {
                        break;
                    }

                    _logger.NotifyFillstate(++count, "ParsedImages");
                    _logger.NotifyFillstate(chunksQueue.Count, "ChunkedQueue");
                    await queue.Enqueue(_factory.FromBytes(width, height, item));
                }
                catch (Exception e) { _logger.LogException(e); }
            }
            if (memoryStream.HasUnwrittenData)
            {
                _logger.WriteLine("Unwritten data exists after finishing parsings." +
                                  " This indicates a severe issue with frame splitting", Verbosity.Warning);
            }
        }
예제 #2
0
        private async Task DecodeImage(IBoundedQueue <T> queue)
        {
            MemoryStream data;

            while ((data = await dataToParse.DequeueOrDefault()) != null)
            {
                var bmp         = new Bitmap(data);
                var width       = bmp.Width;
                var height      = bmp.Height;
                var pixelFormat = bmp.PixelFormat;

                var bmp1Data = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, pixelFormat);
                var length   = bmp1Data.Stride * bmp1Data.Height;

                byte[] bmp1Bytes = new byte[length];
                Marshal.Copy(bmp1Data.Scan0, bmp1Bytes, 0, length);

                await queue.Enqueue(factory.FromBytes(width, height, bmp1Bytes));

                bmp.UnlockBits(bmp1Data);
                bmp.Dispose();
                data.Dispose();
                logger.NotifyFillstate(dataToParse.Count, "ParseBuffer");
            }
        }
예제 #3
0
        public async Task ReadsAllImages()
        {
            Prepare();
            var reader = Reader;
            var t      = Task.Run(() => reader.Produce(queue));
            int i      = 0;

            while ((await queue.DequeueOrDefault()) != null)
            {
                i++;
            }

            await t;

            i.Should().Be(ImagesCount);
        }