Exemple #1
0
        /// <summary>
        /// Filters the plugins (used for reading) by criteria.
        /// </summary>
        /// <returns>
        /// The read plugins.
        /// </returns>
        /// <param name='plugins'>
        /// The actual plugin list.
        /// </param>
        /// <param name='criteria'>
        /// Criteria.
        /// </param>
        /// <exception cref='ArgumentNullException'>
        /// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
        /// </exception>
        protected virtual List <TPlugin> FilterWritePlugins(List <TPlugin> plugins, MediaCodecCriteria criteria)
        {
            if (plugins == null)
            {
                throw new ArgumentNullException("plugins");
            }
            if (criteria == null)
            {
                throw new ArgumentNullException("criteria");
            }

            // Criteria: PluginName
            if (criteria.IsDefined(PluginName))
            {
                plugins = plugins.FindAll(delegate(TPlugin obj) {
                    return(obj.Name == (string)criteria[PluginName]);
                });
            }

            return(plugins);
        }
Exemple #2
0
        /// <summary>
        /// Internal method for creating Image from Bitmap.
        /// </summary>
        /// <param name="bitmap">
        /// A <see cref="Drawing.Bitmap"/> to be converted into an <see cref="Image"/> instance.
        /// </param>
        /// <param name="criteria">
        /// A <see cref="MediaCodecCriteria"/> that specify image conversion criteria.
        /// </param>
        /// <returns>
        /// It returns a <see cref="Image"/> instance that's equivalent to <paramref name="bitmap"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Exception thrown if <paramref name="bitmap"/> or <see cref="criteria"/> is null.
        /// </exception>
        internal static Image LoadFromBitmap(System.Drawing.Bitmap bitmap, MediaCodecCriteria criteria)
        {
            if (bitmap == null)
            {
                throw new ArgumentNullException("bitmap");
            }
            if (criteria == null)
            {
                throw new ArgumentNullException("criteria");
            }

            PixelLayout pType, pConvType;

            // Allocate image raster
            ConvertPixelFormat(bitmap, out pType);

            // Check for hardware/software support
            if (Pixel.IsSupportedInternalFormat(pType) == false)
            {
                if (criteria.IsDefined(ImageCodecCriteria.SoftwareSupport) && ((bool)criteria[ImageCodecCriteria.SoftwareSupport]))
                {
                    // Pixel type not directly supported by hardware... try to guess suitable software conversion
                    pConvType = Pixel.GuessBestSupportedConvertion(pType);
                    if (pConvType == PixelLayout.None)
                    {
                        throw new InvalidOperationException(String.Format("pixel type {0} is not supported by hardware neither software", pType));
                    }
                }
                else
                {
                    throw new InvalidOperationException(String.Format("pixel type {0} is not supported by hardware", pType));
                }
            }
            else
            {
                pConvType = pType;
            }

            Image image = new Image(pType, (uint)bitmap.Width, (uint)bitmap.Height);

            switch (bitmap.PixelFormat)
            {
            case System.Drawing.Imaging.PixelFormat.Format1bppIndexed:
            case System.Drawing.Imaging.PixelFormat.Format4bppIndexed:
            case System.Drawing.Imaging.PixelFormat.Format8bppIndexed:
                if (Runtime.RunningMono)
                {
                    // Bug 676362 - Bitmap Clone does not format return image to requested PixelFormat
                    // https://bugzilla.novell.com/show_bug.cgi?id=676362
                    //
                    // ATM no mono version has resolved the bug; current workaround is performing image
                    // sampling pixel by pixel, using internal conversion routines, even if it is very slow

                    LoadBitmapByPixel(bitmap, image);
                }
                else
                {
                    LoadBitmapByClone(bitmap, image);
                }
                break;

            default:
                LoadBitmapByLockBits(bitmap, image);
                break;
            }

            // ConvertItemType image to supported format, if necessary
            if ((pConvType != PixelLayout.None) && (pConvType != pType))
            {
                image = image.Convert(pConvType);
            }

            return(image);
        }