コード例 #1
0
        private PinnedBuffer CheckOutBuffer(long size)
        {
            var buffer = FirstAvailableBuffer(size);

            if (buffer == null)
            {
                buffer = new PinnedBuffer(size);
                _buffers.Add(buffer);
            }
            buffer.Reserve(); //todo: improve encapsulation here
            Log.Debug(Name + " Buffer of size " + size +
                      " checked out - there are now " + Count(b => b.Length == size) +
                      " buffers of that size, " + Count(b => b.Length == size && b.Available) + " available.");
            return(buffer);
        }
コード例 #2
0
        /// <summary>
        /// Finds the first available buffer or returns null. Calls to linq
        /// like FirstOrDefault are not thread safe and blow up if the underlying
        /// iterator changes.
        /// </summary>
        private PinnedBuffer FirstAvailableBuffer(long size)
        {
            PinnedBuffer buffer = null;

            // This implementation assumes that we add to _buffers, but don't remove
            for (int i = 0; i < _buffers.Count; i++)
            {
                var b = _buffers[i];
                if (b != null && b.Length == size && b.Available)
                {
                    buffer = b;
                    break;
                }
            }

            return(buffer);
        }
コード例 #3
0
        public unsafe WrappedSquareImage(BufferManager manager, PinnedBuffer buffer, int dimension, int bytesPerPixel) :
            base(manager, buffer)
        {
            switch (dimension)
            {
            case 128:
                InnerImage = new TwoByte128X128Image(buffer.Buffer);
                break;

            case 256:
                InnerImage = new TwoByte256X256Image(buffer.Buffer);
                break;

            case 512:
                InnerImage = new TwoByte512X512Image(buffer.Buffer);
                break;

            case 1024:
            {
                if (bytesPerPixel == 2)
                {
                    InnerImage = new TwoByte1024X1024Image(buffer.Buffer);
                }
                else if (bytesPerPixel == 3)
                {
                    InnerImage = new ThreeByte1024X1024Image(buffer.Buffer);
                }
                else
                {
                    throw new Exception($"Invalid bytes per pixel requested for new WrappedSquareImage: {bytesPerPixel}");
                }

                break;
            }

            default:
                throw new Exception($"Invalid image size requested for new WrappedSquareImage: {dimension}");
            }

            ImagePixelHeight = dimension;
            ImagePixelWidth  = dimension;
            BytesPerPixel    = bytesPerPixel;
        }
コード例 #4
0
 public WrappedBuffer(BufferManager manager, PinnedBuffer buffer)
 {
     _manager = manager;
     _buffer  = buffer;
 }
コード例 #5
0
 internal void Return(PinnedBuffer buffer)
 {
     buffer.Release(); //todo: improve encapsulation here
     Log.Debug(Name + " Buffer returned.");
 }
コード例 #6
0
 public unsafe WrappedImage(BufferManager manager, PinnedBuffer buffer) :
     base(manager, buffer)
 {
     Frame = new T();
     Frame.SetBuffer(buffer.Buffer, (int)buffer.Length);
 }