本文整理汇总了C#中PixelFormat.GetColorDepth方法的典型用法代码示例。如果您正苦于以下问题:C# PixelFormat.GetColorDepth方法的具体用法?C# PixelFormat.GetColorDepth怎么用?C# PixelFormat.GetColorDepth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PixelFormat
的用法示例。
在下文中一共展示了PixelFormat.GetColorDepth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateBlendMethod
private static BlendDelegate GenerateBlendMethod(PixelFormat backBuffer, Endianess backBufferEndianess, PixelFormat frontBuffer, Endianess frontBufferEndianess, PixelFormat output, Endianess outputEndianess)
{
var vRed = Expression.Variable(typeof(uint), "red");
var vGreen = Expression.Variable(typeof(uint), "green");
var vBlue = Expression.Variable(typeof(uint), "blue");
var vAlpha = Expression.Variable(typeof(uint), "alpha");
var vBackRed = Expression.Variable(typeof(uint), "backRed");
var vBackGreen = Expression.Variable(typeof(uint), "backGreen");
var vBackBlue = Expression.Variable(typeof(uint), "backBlue");
var vBackAlpha = Expression.Variable(typeof(uint), "backAlpha");
var vFrontRed = Expression.Variable(typeof(uint), "frontRed");
var vFrontGreen = Expression.Variable(typeof(uint), "frontGreen");
var vFrontBlue = Expression.Variable(typeof(uint), "frontBlue");
var vFrontAlpha = Expression.Variable(typeof(uint), "frontAlpha");
var vBackgroundColorRed = Expression.Variable(typeof(uint), "backgroundColorRed");
var vBackgroundColorGreen = Expression.Variable(typeof(uint), "backgroundColorGreen");
var vBackgroundColorBlue = Expression.Variable(typeof(uint), "backgroundColorBlue");
var vBackgroundColorAlpha = Expression.Variable(typeof(uint), "backgroundColorAlpha");
var vBackPos = Expression.Variable(typeof(int), "backPos");
var vFrontPos = Expression.Variable(typeof(int), "frontPos");
var vOutPos = Expression.Variable(typeof(int), "outPos");
var vBackStep = Expression.Variable(typeof(int), "backStep");
var vFrontStep = Expression.Variable(typeof(int), "frontStep");
var vOutStep = Expression.Variable(typeof(int), "outStep");
var vLength = Expression.Variable(typeof(int), "length");
var vBackBuffer = Expression.Parameter(typeof(byte[]), "backBuffer");
var vFrontBuffer = Expression.Parameter(typeof(byte[]), "fronBuffer");
var vOutputBuffer = Expression.Parameter(typeof(byte[]).MakeByRefType(), "outputBuffer");
var vBackgroundColor = Expression.Parameter(typeof(Pixel), "backgroundColor");
var vBackBufferAlphaMultiplier = Expression.Parameter(typeof(byte), "backBufferAlphaMultiplier");
var vFrontBufferAlphaMultiplier = Expression.Parameter(typeof(byte), "frontBufferAlphaMultiplier");
var vBackAlphaBlended = Expression.Variable(typeof(uint), "backAlphaBlended");
var vBackgroundColorAlphaBlended = Expression.Variable(typeof(uint), "backgroundColorAlphaBlended");
var outOfLoop = Expression.Label();
var block = Expression.Block(
new [] { vRed, vGreen, vBlue, vAlpha,
vFrontRed, vFrontGreen, vFrontBlue, vFrontAlpha,
vBackRed, vBackGreen, vBackBlue, vBackAlpha,
vBackStep, vFrontStep, vOutStep, vLength, vBackPos, vFrontPos, vOutPos,
vBackgroundColorRed, vBackgroundColorGreen, vBackgroundColorBlue, vBackgroundColorAlpha,
vBackAlphaBlended, vBackgroundColorAlphaBlended
},
Expression.Assign(vBackStep, Expression.Constant(backBuffer.GetColorDepth())),
Expression.Assign(vFrontStep, Expression.Constant(frontBuffer.GetColorDepth())),
Expression.Assign(vOutStep, Expression.Constant(output.GetColorDepth())),
Expression.Assign(vLength, Expression.Property(vBackBuffer, "Length")),
Expression.Assign(vBackPos, Expression.Constant(0x00)),
Expression.Assign(vFrontPos, Expression.Constant(0x00)),
Expression.Assign(vOutPos, Expression.Constant(0x00)),
Expression.Assign(vBackgroundColorAlpha, Expression.Convert(Expression.Property(vBackgroundColor, "Alpha"), typeof(uint))),
Expression.Assign(vBackgroundColorRed, Expression.Convert(Expression.Property(vBackgroundColor, "Red"), typeof(uint))),
Expression.Assign(vBackgroundColorGreen, Expression.Convert(Expression.Property(vBackgroundColor, "Green"), typeof(uint))),
Expression.Assign(vBackgroundColorBlue, Expression.Convert(Expression.Property(vBackgroundColor, "Blue"), typeof(uint))),
Expression.Loop(
Expression.IfThenElse(Expression.LessThan(vBackPos, vLength),
Expression.Block(
GenerateFrom(backBuffer, backBufferEndianess, vBackBuffer, vBackPos, vBackRed, vBackGreen, vBackBlue, vBackAlpha),
GenerateFrom(frontBuffer, frontBufferEndianess, vFrontBuffer, vFrontPos, vFrontRed, vFrontGreen, vFrontBlue, vFrontAlpha),
Expression.Assign(vBackAlpha, Expression.Divide(Expression.Multiply(vBackAlpha, Expression.Convert(vBackBufferAlphaMultiplier, typeof(uint))), Expression.Constant((uint)0xFF))),
Expression.Assign(vFrontAlpha, Expression.Divide(Expression.Multiply(vFrontAlpha, Expression.Convert(vFrontBufferAlphaMultiplier, typeof(uint))), Expression.Constant((uint)0xFF))),
Expression.Block(
// (b_alpha * (0xFF - f_alpha)) / 0xFF
Expression.Assign(
vBackAlphaBlended,
Expression.Divide(
Expression.Multiply(
vBackAlpha,
Expression.Subtract(
Expression.Constant((uint)0xFF),
vFrontAlpha)),
Expression.Constant((uint)0xFF))),
// (c_alpha * (0xFF - (f_alpha + b_alpha * (0xFF - f_alpha)))) / 0xFF
Expression.Assign(
vBackgroundColorAlphaBlended,
Expression.Divide(
Expression.Multiply(
vBackgroundColorAlpha,
Expression.Subtract(
Expression.Constant((uint)0xFF),
Expression.Add(
vFrontAlpha,
vBackAlphaBlended))),
Expression.Constant((uint)0xFF))),
//.........这里部分代码省略.........
示例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)
//.........这里部分代码省略.........
示例3: 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);
}
示例4: GenerateConvertMethod
private static ConvertDelegate GenerateConvertMethod(PixelFormat input, Endianess inputEndianess, PixelFormat output, Endianess outputEndianess)
{
var vRed = Expression.Variable(typeof(uint), "red");
var vGreen = Expression.Variable(typeof(uint), "green");
var vBlue = Expression.Variable(typeof(uint), "blue");
var vAlpha = Expression.Variable(typeof(uint), "alpha");
var vInStep = Expression.Variable(typeof(int), "inStep");
var vOutStep = Expression.Variable(typeof(int), "outStep");
var vLength = Expression.Variable(typeof(int), "length");
var vInputBuffer = Expression.Parameter(typeof(byte[]), "inputBuffer");
var vOutputBuffer = Expression.Parameter(typeof(byte[]).MakeByRefType(), "outputBuffer");
var vInPos = Expression.Variable(typeof(int), "inPos");
var vOutPos = Expression.Variable(typeof(int), "outPos");
var outOfLoop = Expression.Label();
var block = Expression.Block(
new [] { vRed, vGreen, vBlue, vAlpha, vInStep, vOutStep, vLength, vInPos, vOutPos },
Expression.Assign(vInStep, Expression.Constant(input.GetColorDepth())),
Expression.Assign(vOutStep, Expression.Constant(output.GetColorDepth())),
Expression.Assign(vLength, Expression.Property(vInputBuffer, "Length")),
Expression.Assign(vInPos, Expression.Constant(0)),
Expression.Assign(vOutPos, Expression.Constant(0)),
Expression.Loop(
Expression.IfThenElse(Expression.LessThan(vInPos, vLength),
Expression.Block(
GenerateFrom(input, inputEndianess, vInputBuffer, vInPos, vRed, vGreen, vBlue, vAlpha),
GenerateTo(output, outputEndianess, vOutputBuffer, vOutPos, vRed, vGreen, vBlue, vAlpha),
Expression.AddAssign(vInPos, vInStep),
Expression.AddAssign(vOutPos, vOutStep)
),
Expression.Break(outOfLoop)
),
outOfLoop
)
);
return Expression.Lambda<ConvertDelegate>(block, vInputBuffer, vOutputBuffer).Compile();
}