当前位置: 首页>>代码示例>>C#>>正文


C# PixelFormat.GetColorsLengths方法代码示例

本文整理汇总了C#中PixelFormat.GetColorsLengths方法的典型用法代码示例。如果您正苦于以下问题:C# PixelFormat.GetColorsLengths方法的具体用法?C# PixelFormat.GetColorsLengths怎么用?C# PixelFormat.GetColorsLengths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PixelFormat的用法示例。


在下文中一共展示了PixelFormat.GetColorsLengths方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateTo

        /// <summary>
        /// Generates expression converting and storing one pixel in output format to output buffer (ordering bytes accordingly to endianess) at given position using channels values provided by red/green/blue/alpha variables.
        /// </summary>
        /// <returns>Generated expression.</returns>
        /// <param name="outputFormat">Pixel color format of pixels stored in output buffer.</param>
        /// <param name="endianess">Endianess of output buffer.</param>
        /// <param name="outBuffer">Output buffer.</param>
        /// <param name="outPosition">Position of pixel in output buffer.</param>
        /// <param name="redByte">Variable from which value of red channel should be read.</param>
        /// <param name="greenByte">Variable from which value of green channel should be read.</param>
        /// <param name="blueByte">Variable from which value of blue channel should be read.</param>
        /// <param name="alphaByte">Variable from which value of alpha channel should be read.</param>
        private static Expression GenerateTo(PixelFormat outputFormat, Endianess endianess, Expression outBuffer, Expression outPosition, Expression redByte, Expression greenByte, Expression blueByte, Expression alphaByte)
        {
            byte currentBit = 0;
            byte currentByte = 0;
            var expressions = new List<Expression>();
            
            Expression currentExpression = null;
            
            foreach(var colorDescriptor in outputFormat.GetColorsLengths())
            {
                Expression colorExpression = null; 
                
                switch(colorDescriptor.Key)
                {
                case ColorType.A:
                    colorExpression = alphaByte;
                    break;
                case ColorType.B:
                    colorExpression = blueByte;
                    break;
                case ColorType.G:
                    colorExpression = greenByte;
                    break;
                case ColorType.R:
                    colorExpression = redByte;
                    break;
                case ColorType.X:
                    colorExpression = Expression.Constant((uint)0xFF);
                    break;
                }

                foreach(var transformation in ByteSqueezeAndMove(colorDescriptor.Value, currentBit))
                {
                    Expression currentExpressionFragment = colorExpression;
                
                    if(transformation.MaskBits != 0xFF)
                    {
                        currentExpressionFragment = Expression.And(currentExpressionFragment, Expression.Constant((uint)transformation.MaskBits));
                    }

                    if(transformation.ShiftBits > 0)
                    {
                        currentExpressionFragment = Expression.RightShift(currentExpressionFragment, Expression.Constant((int)transformation.ShiftBits));
                    }
                    else if(transformation.ShiftBits < 0)
                    {
                        currentExpressionFragment = Expression.And(
                            Expression.LeftShift(currentExpressionFragment, Expression.Constant((int)(-transformation.ShiftBits))),
                            Expression.Constant((uint)0xFF));
                                
                    }
                    
                    currentExpression = (currentExpression == null) ? currentExpressionFragment : Expression.Or(currentExpression, currentExpressionFragment);

                    currentBit += transformation.UsedBits;
                    while(currentBit >= 8)
                    {
                        expressions.Add(
                            Expression.Assign(
                                Expression.ArrayAccess(outBuffer, 
                                    Expression.Add(
                                        outPosition, 
                                        Expression.Constant((endianess == Endianess.BigEndian) ? (int) currentByte : (outputFormat.GetColorDepth() - currentByte - 1)))),
                                Expression.Convert(currentExpression, typeof(byte))));

                        currentExpression = null;
                        currentBit -= 8;
                        currentByte++;
                    }
                }
            }

            return Expression.Block(expressions);
        }
开发者ID:bhuvanchandra,项目名称:emul8,代码行数:86,代码来源:PixelManipulationTools.cs

示例2: GenerateFrom

        /// <summary>
        /// Generates expression reading one pixel encoded in given format from input buffer (with bytes ordered accordingly to endianess) at given position 
        /// and storing each channel in separate variable expression.
        /// </summary>
        /// <returns>Generated expression.</returns>
        /// <param name="inputFormat">Pixel color format of pixels in input buffer.</param>
        /// <param name="endianess">Endianess of input buffer.</param>
        /// <param name="inBuffer">Input buffer.</param>
        /// <param name="inPosition">Position of pixel in buffer.</param>
        /// <param name="redByte">Variable to which value of red channel should be stored.</param>
        /// <param name="greenByte">Variable to which value of green channel should be stored.</param>
        /// <param name="blueByte">Variable to which value of blue channel should be stored.</param>
        /// <param name="alphaByte">Variable to which value of alpha channel should be stored.</param>
        private static Expression GenerateFrom(PixelFormat inputFormat, Endianess endianess, Expression inBuffer, Expression inPosition, Expression redByte, Expression greenByte, Expression blueByte, Expression alphaByte)
        {
            byte currentBit = 0;
            byte currentByte = 0;
            bool isAlphaSet = false;
            
            var expressions = new List<Expression>();
            var inputBytes = new ParameterExpression[inputFormat.GetColorDepth()];
            for(int i = 0; i < inputBytes.Length; i++)
            {
                inputBytes[i] = Expression.Variable(typeof(uint));
                
                expressions.Add(
                    Expression.Assign(
                        inputBytes[i], 
                        Expression.Convert(
                            Expression.ArrayIndex(
                                inBuffer,
                                Expression.Add(
                                    inPosition, 
                                    Expression.Constant((endianess == Endianess.BigEndian) ? i : inputBytes.Length - i - 1))),
                            typeof(uint))));
            }

            foreach(var colorDescriptor in inputFormat.GetColorsLengths())
            {
                Expression colorExpression = null; 
                
                foreach(var transformation in ByteInflate(colorDescriptor.Value, currentBit))
                {
                    Expression currentExpressionFragment = inputBytes[currentByte];
                    
                    if(transformation.MaskBits != 0xFF)
                    {
                        currentExpressionFragment = Expression.And(currentExpressionFragment, Expression.Constant((uint)transformation.MaskBits));
                    }
                    
                    if(transformation.ShiftBits > 0)
                    {
                        currentExpressionFragment = Expression.RightShift(currentExpressionFragment, Expression.Constant((int)transformation.ShiftBits));
                    }
                    else if(transformation.ShiftBits < 0)
                    {
                        currentExpressionFragment = Expression.And(
                            Expression.LeftShift(currentExpressionFragment, Expression.Constant((int)(-transformation.ShiftBits))),
                            Expression.Constant((uint)0xFF));
                    }
                    
                    currentBit += transformation.UsedBits;
                    if(currentBit >= 8)
                    {
                        currentBit -= 8;
                        currentByte++;
                    }
                    
                    colorExpression = (colorExpression == null) ? currentExpressionFragment : Expression.Or(colorExpression, currentExpressionFragment);
                }

                if(colorDescriptor.Key == ColorType.X)
                {
                    continue;
                }

                Expression currentColor = null;
                switch(colorDescriptor.Key)
                {
                case ColorType.A:
                    currentColor = alphaByte;
                    isAlphaSet = true;
                    break;
                case ColorType.B:
                    currentColor = blueByte;
                    break;
                case ColorType.G:
                    currentColor = greenByte;
                    break;
                case ColorType.R:
                    currentColor = redByte;
                    break;
                }
                
                expressions.Add(Expression.Assign(currentColor, colorExpression));
                
                // filling lsb '0'-bits with copy of msb pattern
                var numberOfBits = colorDescriptor.Value;
                var zeroBits = 8 - numberOfBits;
                while(zeroBits > 0)
//.........这里部分代码省略.........
开发者ID:bhuvanchandra,项目名称:emul8,代码行数:101,代码来源:PixelManipulationTools.cs


注:本文中的PixelFormat.GetColorsLengths方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。