Пример #1
0
        public static int CalculateStride(int width, CpuBlit.Imaging.PixelFormat format, out int bitDepth, out int bytesPerPixel)
        {
            //stride calcuation helper

            switch (format)
            {
                case CpuBlit.Imaging.PixelFormat.ARGB32:
                    {
                        bitDepth = 32;
                        bytesPerPixel = (bitDepth + 7) / 8;
                        return width * (32 / 8);
                    }
                case CpuBlit.Imaging.PixelFormat.GrayScale8:
                    {
                        bitDepth = 8; //bit per pixel
                        bytesPerPixel = (bitDepth + 7) / 8;
                        return 4 * ((width * bytesPerPixel + 3) / 4);
                    }
                case CpuBlit.Imaging.PixelFormat.RGB24:
                    {
                        bitDepth = 24; //bit per pixel
                        bytesPerPixel = (bitDepth + 7) / 8;
                        return 4 * ((width * bytesPerPixel + 3) / 4);
                    }
                default:
                    throw new NotSupportedException();
            }
        }
Пример #2
0
        public ActualBitmap(int width, int height, int[] orgBuffer)
        {
            //width and height must >0
            this.width  = width;
            this.height = height;
            int bytesPerPixel;

            this.stride = CalculateStride(width,
                                          this.pixelFormat = CpuBlit.Imaging.PixelFormat.ARGB32, //***
                                          out bitDepth,
                                          out bytesPerPixel);
            //alloc mem

            this.pixelBuffer = orgBuffer;
        }
Пример #3
0
        public MemBitmap(int width, int height, IntPtr externalNativeInt32Ptr)
        {
            //width and height must >0 
            _width = width;
            _height = height;
            _strideBytes = CalculateStride(width,
                _pixelFormat = CpuBlit.Imaging.PixelFormat.ARGB32, //***
                out _bitDepth,
                out int bytesPerPixel);

            _pixelBufferInBytes = width * height * 4;
            _pixelBufferFromExternalSrc = true; //*** we receive ptr from external ***
            _pixelBuffer = externalNativeInt32Ptr;

#if DEBUG
            dbugMemBitmapMonitor.dbugRegisterMemBitmap(this, width + "x" + height + ": " + DateTime.Now.ToString("u"));
#endif
        }
Пример #4
0
 public static int CalculateStride(int width, CpuBlit.Imaging.PixelFormat format)
 {
     int bitDepth, bytesPerPixel;
     return CalculateStride(width, format, out bitDepth, out bytesPerPixel);
 }