Exemplo n.º 1
0
 /// <summary>
 /// Adds a thumb to the list
 /// </summary>
 /// <param name="thumb">The thumb to be added</param>
 public void AddThumb(BitmapEx thumb)
 {
     if (MainStream.CanWrite)
     {
         if (thumb.IsPinned)
         {
             thumb.UnlockBits();
         }
         MainStream.Position = MainStream.Length;
         long begin = MainStream.Length;
         formatter.Serialize(MainStream, thumb);
         Entries.Add(new DataEntry(begin, MainStream.Length));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Resizes this image to a new size with bi-cubic interpolation
        /// </summary>
        /// <param name="nWidth">New Width</param>
        /// <param name="nHeight">New Height</param>
        /// <returns>The resized image</returns>
        public BitmapEx Scale(uint nWidth, uint nHeight)
        {
            if (nWidth == Width && nHeight == Height)
            {
                return(this.Clone());
            }

            BitmapEx bmpN = new BitmapEx(nWidth, nHeight, this.BitDepth);

            try
            {
                this.LockBits();
                bmpN.LockBits();

                switch (this.BitDepth)
                {
                case ImageType.RGB8:
                case ImageType.RGBA8:
                    DoScale8(bmpN, nWidth, nHeight);
                    break;

                case ImageType.RGB16:
                case ImageType.RGBA16:
                    DoScale16(bmpN, nWidth, nHeight);
                    break;

                case ImageType.RGB32:
                case ImageType.RGBA32:
                    DoScale32(bmpN, nWidth, nHeight);
                    break;

                case ImageType.RGB64:
                case ImageType.RGBA64:
                    DoScale64(bmpN, nWidth, nHeight);
                    break;

                default:
                    throw new ArgumentException("Bitdepth not supported");
                }
            }
            finally
            {
                this.UnlockBits();
                bmpN.UnlockBits();
            }

            return(bmpN);
        }
Exemplo n.º 3
0
        public static Pixbuf ConvertToPixbuf(BitmapEx bmpEx)
        {
            int bitspersample;
            bool HasAlpha;

            if (bmpEx.BitDepth == ImageType.RGB8) { bitspersample = 8; HasAlpha = false; }
            else if (bmpEx.BitDepth == ImageType.RGBA8) { bitspersample = 8; HasAlpha = true; }
            else if (bmpEx.BitDepth == ImageType.RGB16) { bitspersample = 16; HasAlpha = false; }
            else if (bmpEx.BitDepth == ImageType.RGBA16) { bitspersample = 16; HasAlpha = true; }
            else throw new ArgumentException("Bitdepth not supported");

            byte[] data = new byte[bmpEx.Height * bmpEx.Stride];
            bmpEx.LockBits();
            unsafe { System.Runtime.InteropServices.Marshal.Copy(bmpEx.Scan0, data, 0, data.Length); }
            bmpEx.UnlockBits();

            return new Pixbuf(data, HasAlpha, bitspersample, (int)bmpEx.Width, (int)bmpEx.Height, (int)bmpEx.Stride);
        }
Exemplo n.º 4
0
        public static Bitmap ConvertToBitmap(BitmapEx bmpEx)
        {
            uint depth = 0;
            bool HasAlpha;
            PixelFormat format;
            if (bmpEx.BitDepth == ImageType.RGB8) { format = PixelFormat.Format24bppRgb; depth = 3; HasAlpha = false; }
            else if (bmpEx.BitDepth == ImageType.RGBA8) { format = PixelFormat.Format32bppArgb; depth = 4; HasAlpha = true; }
            else if (bmpEx.BitDepth == ImageType.RGB16) { format = PixelFormat.Format48bppRgb; depth = 6; HasAlpha = false; }
            else if (bmpEx.BitDepth == ImageType.RGBA16) { format = PixelFormat.Format64bppArgb; depth = 8; HasAlpha = true; }
            else throw new ArgumentException("Bitdepth not supported");

            Bitmap outBmp = new Bitmap((int)bmpEx.Width, (int)bmpEx.Height, format);
            BitmapData bmd = outBmp.LockBits(new System.Drawing.Rectangle(0, 0, outBmp.Width, outBmp.Height), ImageLockMode.WriteOnly, outBmp.PixelFormat);
            bmpEx.LockBits();

            unsafe
            {
                byte* pixIn = (byte*)bmpEx.Scan0;
                byte* pixOut = (byte*)bmd.Scan0;
                long idx;
                uint x, y;
                int resV = (int)(bmd.Stride - bmpEx.Stride);
                int res = 0;
                for (y = 0; y < bmd.Height; y++)
                {
                    for (x = 0; x < bmd.Stride; x+=depth)
                    {
                        idx = y * bmd.Stride + x;
                        pixOut[idx + 2] = pixIn[idx - res];
                        pixOut[idx + 1] = pixIn[idx + 1 - res];
                        pixOut[idx] = pixIn[idx + 2 - res];
                        if (HasAlpha) pixOut[idx + 3] = pixIn[idx + 3 - res];
                    }
                    res += resV;
                }
            }
            outBmp.UnlockBits(bmd);
            bmpEx.UnlockBits();

            return outBmp;
        }
Exemplo n.º 5
0
        private void BrCalc_Simple()
        {
            if (SimpleCalculationArea.Height < 0 || SimpleCalculationArea.Width < 0 || SimpleCalculationArea.X < 0 || SimpleCalculationArea.Y < 0 ||
                SimpleCalculationArea.Height > Frames[0].Height || SimpleCalculationArea.Width > Frames[0].Width)
            {
                throw new ArgumentException("Calculation area must be on thumb image");
            }

            for (int f = 0; f < Frames.Count; f++)
            {
                double   Brightness = 0;
                long     index      = 0;
                int      pixcount   = 0;
                BitmapEx bmp        = GetThumb(f, false).Scale(300, 200);

                unsafe
                {
                    bmp.LockBits();
                    byte *pix = (byte *)bmp.Scan0;

                    for (int y = SimpleCalculationArea.X; y < SimpleCalculationArea.Height; y++)
                    {
                        for (int x = SimpleCalculationArea.Y; x < SimpleCalculationArea.Width; x++)
                        {
                            index = y * bmp.Stride + x * bmp.ChannelCount;

                            Brightness += Math.Sqrt(Math.Pow(pix[index], 2) * 0.241 + Math.Pow(pix[index + 1], 2) * 0.691 + Math.Pow(pix[index + 2], 2) * 0.068);
                            pixcount++;
                        }
                    }
                    bmp.UnlockBits();
                }

                Frames[f].OriginalBrightness    = Brightness / pixcount;
                Frames[f].AlternativeBrightness = Frames[f].OriginalBrightness;
                Frames[f].NewBrightness         = Frames[f].OriginalBrightness;
            }
        }
Exemplo n.º 6
0
        public static NSImage ToNSImage(BitmapEx bmpEx)
        {
            bmpEx.LockBits();
            long bufferLength = bmpEx.Width * bmpEx.Height;
            CGDataProvider provider = new CGDataProvider(bmpEx.Scan0, (int)bufferLength);
            int bitsPerComponent, bitsPerPixel, bytesPerRow = (int)bmpEx.Stride;
            CGColorSpace colorSpaceRef = CGColorSpace.CreateDeviceRGB();

            switch (bmpEx.BitDepth)
            {
                case ImageType.RGB16:
                    bitsPerComponent = 16;
                    bitsPerPixel = 48;
                    bufferLength *= 3;
                    break;
                case ImageType.RGBA16:
                    bitsPerComponent = 16;
                    bitsPerPixel = 64;
                    bufferLength *= 4;
                    break;
                case ImageType.RGB8:
                    bitsPerComponent = 8;
                    bitsPerPixel = 24;
                    bufferLength *= 3;
                    break;
                case ImageType.RGBA8:
                    bitsPerComponent = 8;
                    bitsPerPixel = 32;
                    bufferLength *= 4;
                    break;
                case ImageType.RGB32:
                    bitsPerComponent = 32;
                    bitsPerPixel = 96;
                    bufferLength *= 3;
                    break;
                case ImageType.RGBA32:
                    bitsPerComponent = 32;
                    bitsPerPixel = 128;
                    bufferLength *= 4;
                    break;
                case ImageType.RGB64:
                    bitsPerComponent = 64;
                    bitsPerPixel = 192;
                    bufferLength *= 3;
                    break;
                case ImageType.RGBA64:
                    bitsPerComponent = 64;
                    bitsPerPixel = 256;
                    bufferLength *= 4;
                    break;

                default:
                    throw new ArgumentException("Bitdepth not supported");
            }

            CGImage img = new CGImage((int)bmpEx.Width, (int)bmpEx.Height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, CGBitmapFlags.ByteOrderDefault, provider, null, true, CGColorRenderingIntent.Default);

            bmpEx.UnlockBits();

            return new NSImage(img, new SizeF(img.Width, img.Height));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Resizes this image to a new size with bi-cubic interpolation
        /// </summary>
        /// <param name="nWidth">New Width</param>
        /// <param name="nHeight">New Height</param>
        /// <returns>The resized image</returns>
        public BitmapEx Scale(uint nWidth, uint nHeight)
        {
            if (nWidth == Width && nHeight == Height) return this.Clone();

            BitmapEx bmpN = new BitmapEx(nWidth, nHeight, this.BitDepth);

            try
            {
                this.LockBits();
                bmpN.LockBits();

                switch (this.BitDepth)
                {
                    case ImageType.RGB8:
                    case ImageType.RGBA8:
                        DoScale8(bmpN, nWidth, nHeight);
                        break;

                    case ImageType.RGB16:
                    case ImageType.RGBA16:
                        DoScale16(bmpN, nWidth, nHeight);
                        break;

                    case ImageType.RGB32:
                    case ImageType.RGBA32:
                        DoScale32(bmpN, nWidth, nHeight);
                        break;

                    case ImageType.RGB64:
                    case ImageType.RGBA64:
                        DoScale64(bmpN, nWidth, nHeight);
                        break;

                    default:
                        throw new ArgumentException("Bitdepth not supported");
                }
            }
            finally
            {
                this.UnlockBits();
                bmpN.UnlockBits();
            }

            return bmpN;
        }