public RepositoryPeopleHobbies(DecodeContext decodeContext) : base(decodeContext) { _decodeContext = decodeContext; }
public static Func <IExtractContext, string[]> Apply( IFieldInformation field, DecodeContext decodeContext) { var siValue = decodeContext.PopStack(); var siReference = decodeContext.PopStack(); if (siReference.TargetType.IsByReference) { var dereferencedType = siReference.TargetType.ElementType; if (field.DeclaringType.IsAssignableFrom(dereferencedType) == false) { throw new InvalidProgramSequenceException( "Invalid managed reference: Location={0}, StackType={1}, Name={2}", decodeContext.CurrentCode.RawLocation, siReference.TargetType.FriendlyName, field.FriendlyName); } } else if (siReference.TargetType.IsValueType == false) { if (field.DeclaringType.IsAssignableFrom(siReference.TargetType) == false) { throw new InvalidProgramSequenceException( "Invalid object reference: Location={0}, StackType={1}, Name={2}", decodeContext.CurrentCode.RawLocation, siReference.TargetType.FriendlyName, field.FriendlyName); } } else { throw new InvalidProgramSequenceException( "Invalid type at stack: Location={0}, StackType={1}", decodeContext.CurrentCode.RawLocation, siReference.TargetType.FriendlyName); } var codeInformation = decodeContext.CurrentCode; // Register referenced field type (at the file scope). decodeContext.PrepareContext.RegisterType(field.FieldType, decodeContext.Method); return(extractContext => { var rightExpression = extractContext.GetRightExpression( field.FieldType, siValue); if (rightExpression == null) { throw new InvalidProgramSequenceException( "Invalid store operation: Location={0}, StackType={1}, FieldType={2}", codeInformation.RawLocation, siValue.TargetType.FriendlyName, field.FieldType.FriendlyName); } return new[] { string.Format( "{0}->{1} = {2}", extractContext.GetSymbolName(siReference), field.MangledName, rightExpression) }; }); }
public override Func <IExtractContext, string[]> Apply( IMethodInformation ctor, DecodeContext decodeContext) { if (!ctor.IsConstructor) { throw new InvalidProgramSequenceException( "Invalid new object constructor: Location={0}, Method={1}", decodeContext.CurrentCode.RawLocation, ctor.FriendlyName); } // Generate the constructor's argument expressions. var type = ctor.DeclaringType; ILocalVariableInformation thisSymbol = null; var pairParameters = new LinkedList <Utilities.RightExpressionGivenParameter>(); foreach (var parameter in ctor.Parameters.Reverse()) { // Except this parameter if (pairParameters.Count < (ctor.Parameters.Length) - 1) { pairParameters.AddFirst(new Utilities.RightExpressionGivenParameter( parameter.TargetType, decodeContext.PopStack())); } // "this" parameter else { Debug.Assert(thisSymbol == null); // Instance from get_uninitialized_object thisSymbol = decodeContext.PushStack(type, ctor); pairParameters.AddFirst(new Utilities.RightExpressionGivenParameter( type, thisSymbol)); } } Debug.Assert(thisSymbol != null); var codeInformation = decodeContext.CurrentCode; // Specialized the delegate type: // We can use for instantiate the delegate instance with "il2c_new_delegate()." if (type.IsDelegate) { if (type.IsAbstract || type.IsDelegateType || type.IsMulticastDelegateType) { throw new InvalidProgramSequenceException( "Invalid delegate type: Location={0}, Method={1}", codeInformation.RawLocation, type.FriendlyName); } if (!(ctor.Parameters.Length == 2) && (ctor.Parameters[0].TargetType.IsObjectType) && (ctor.Parameters[0].TargetType.IsIntPtrType)) { throw new InvalidProgramSequenceException( "Invalid delegate constructor: Location={0}, Method={1}", codeInformation.RawLocation, ctor.FriendlyName); } return(extractContext => { var parameterString = Utilities.GetGivenParameterDeclaration( pairParameters.Skip(1).ToArray(), extractContext, codeInformation); return new[] { string.Format( "{0} = il2c_new_delegate({1}, {2})", extractContext.GetSymbolName(thisSymbol), type.MangledName, parameterString) }; }); } var overloadIndex = ctor.OverloadIndex; return(extractContext => { var parameterString = Utilities.GetGivenParameterDeclaration( pairParameters.ToArray(), extractContext, codeInformation); // newobj opcode can handle value type with parameter applied constructor. if (type.IsValueType) { // If constructor's arguments greater than or equal 2 (this and others) if (pairParameters.Count >= 2) { var typeName = type.CLanguageTypeName; return new[] { string.Format( "memset(&{0}, 0x00, {1})", extractContext.GetSymbolName(thisSymbol), type.CLanguageStaticSizeOfExpression), (overloadIndex >= 1) ? string.Format( "{0}__ctor_{1}(&{2})", typeName, overloadIndex, parameterString) : string.Format( "{0}__ctor(&{1})", typeName, parameterString) }; } else { // ValueType's default constructor not declared. return new[] { string.Format( "memset(&{0}, 0x00, {1})", extractContext.GetSymbolName(thisSymbol), type.CLanguageStaticSizeOfExpression) }; } } // Object reference types. else { var get = new[] { string.Format( "{0} = il2c_get_uninitialized_object({1})", extractContext.GetSymbolName(thisSymbol), type.MangledName) }; var callCtor = new[] { (overloadIndex >= 1) ? string.Format( "{0}__ctor_{1}({2})", type.MangledName, overloadIndex, parameterString) : string.Format( "{0}__ctor({1})", type.MangledName, parameterString) }; return get. Concat(callCtor). ToArray(); } }); }
public override Func <IExtractContext, string[]> Apply( MethodReference method, DecodeContext decodeContext) { var md = method.Resolve(); if (!md.IsConstructor) { throw new InvalidProgramSequenceException( "Invalid new object constructor: Offset={0}, Method={1}", decodeContext.Current.Offset, md.GetFullMemberName()); } var pairParameters = md.Parameters .Reverse() .Select(parameter => new Utilities.RightExpressionGivenParameter( parameter.ParameterType, decodeContext.PopStack())) .Reverse() .ToList(); var overloadIndex = method.GetMethodOverloadIndex(); var type = md.DeclaringType; var thisSymbolName = decodeContext.PushStack(type); // Insert this reference. pairParameters.Insert(0, new Utilities.RightExpressionGivenParameter( type, new SymbolInformation(thisSymbolName, type))); var offset = decodeContext.Current.Offset; return(extractContext => { var parameterString = Utilities.GetGivenParameterDeclaration( pairParameters.ToArray(), extractContext, offset); // newobj opcode can handle value type with parameter applied constructor. if (type.IsValueType) { var typeName = extractContext.GetCLanguageTypeName( type); // If constructor's arguments greater than or equal 2 (this and others) if (pairParameters.Count >= 2) { return new[] { string.Format( "memset(&{0}, 0x00, sizeof({1}))", thisSymbolName, typeName), (overloadIndex >= 1) ? string.Format( "{0}__ctor_{1}(&{2})", typeName, overloadIndex, parameterString) : string.Format( "{0}__ctor(&{1})", typeName, parameterString) }; } else { // ValueType's default constructor not declared. return new[] { string.Format( "memset(&{0}, 0x00, sizeof({1}))", thisSymbolName, typeName) }; } } // Object reference types. else { var dereferencedTypeName = extractContext.GetCLanguageTypeName( type, TypeNameFlags.Dereferenced); var get = new[] { string.Format( "{0} = il2c_get_uninitialized_object(il2c_typeof({1}))", thisSymbolName, dereferencedTypeName) }; // Setup vptr from vtables. var vptr = new[] { // Instance's vptr string.Format( "{0}->vptr0__ = &__{1}_VTABLE__", thisSymbolName, dereferencedTypeName) }.Concat(type.Interfaces.Select(interfaceImpl => { // Interface's vptr: // These are unique tables by pair of instance type and interface type. // Because vtable has function pointers from unique adjustor thunk by instance type layout offset. var tn = extractContext.GetCLanguageTypeName( interfaceImpl.InterfaceType, TypeNameFlags.Dereferenced); return string.Format( "{0}->vptr_{1}__ = &__{2}_{1}_VTABLE__", thisSymbolName, tn, dereferencedTypeName); })); var ctor = new[] { (overloadIndex >= 1) ? string.Format( "{0}__ctor_{1}({2})", dereferencedTypeName, overloadIndex, parameterString) : string.Format( "{0}__ctor({1})", dereferencedTypeName, parameterString) }; return get .Concat(vptr) .Concat(ctor) .ToArray(); } }); }
public sealed override Func <IExtractContext, string[]> Apply(object operand, DecodeContext decodeContext) { Debug.Assert(operand == null); return(this.Apply(decodeContext)); }
public override Func <IExtractContext, string[]> Apply(DecodeContext decodeContext) { return(LdcConverterUtilities.Apply(6, decodeContext)); }
public override ExpressionEmitter Prepare( IMethodInformation ctor, DecodeContext decodeContext) { if (!ctor.IsConstructor) { throw new InvalidProgramSequenceException( "Invalid new object constructor: Location={0}, Method={1}", decodeContext.CurrentCode.RawLocation, ctor.FriendlyName); } // Generate the constructor's argument expressions. var type = ctor.DeclaringType; ILocalVariableInformation thisSymbol = null; var pairParameters = new LinkedList <Utilities.RightExpressionGivenParameter>(); foreach (var parameter in ctor.Parameters.Reverse()) { // Except this parameter if (pairParameters.Count < (ctor.Parameters.Length) - 1) { pairParameters.AddFirst(new Utilities.RightExpressionGivenParameter( parameter.TargetType, decodeContext.PopStack())); } // "this" parameter else { Debug.Assert(thisSymbol == null); // Instance from get_uninitialized_object thisSymbol = decodeContext.PushStack(type, ctor); pairParameters.AddFirst(new Utilities.RightExpressionGivenParameter( type, thisSymbol)); } } Debug.Assert(thisSymbol != null); var codeInformation = decodeContext.CurrentCode; // Register target constructor declaring type (at the file scope). decodeContext.PrepareContext.RegisterType(type, decodeContext.Method); // Specialized the delegate type: // We can use for instantiate the delegate instance with "il2c_new_delegate()." if (type.IsDelegate) { if (type.IsAbstract || type.IsDelegateType || type.IsMulticastDelegateType) { throw new InvalidProgramSequenceException( "Invalid delegate type: Location={0}, Method={1}", codeInformation.RawLocation, type.FriendlyName); } if ((ctor.Parameters.Length != 3) || !ctor.Parameters[1].TargetType.IsObjectType || !ctor.Parameters[2].TargetType.IsIntPtrType) { throw new InvalidProgramSequenceException( "Invalid delegate constructor: Location={0}, Method={1}", codeInformation.RawLocation, ctor.FriendlyName); } return((extractContext, _) => { var parameterString = Utilities.GetGivenParameterDeclaration( pairParameters.Skip(1).ToArray(), extractContext, codeInformation); return new[] { string.Format( "{0} = il2c_new_delegate({1}, {2})", extractContext.GetSymbolName(thisSymbol), type.MangledUniqueName, parameterString) }; }); } // Specialized the thread type: if (type.UniqueName == "System.Threading.Thread") { if (!type.IsClass || !type.IsSealed) { throw new InvalidProgramSequenceException( "Invalid thread type: Location={0}, Method={1}", codeInformation.RawLocation, type.FriendlyName); } if ((ctor.Parameters.Length != 2) || ((ctor.Parameters[1].TargetType.UniqueName != "System.Threading.ThreadStart") && (ctor.Parameters[1].TargetType.UniqueName != "System.Threading.ParameterizedThreadStart"))) { throw new InvalidProgramSequenceException( "Invalid thread constructor: Location={0}, Method={1}", codeInformation.RawLocation, ctor.FriendlyName); } return((extractContext, _) => { var parameterString = Utilities.GetGivenParameterDeclaration( pairParameters.Skip(1).ToArray(), extractContext, codeInformation); return new[] { string.Format( "{0} = il2c_new_thread({1})", extractContext.GetSymbolName(thisSymbol), parameterString) }; }); } // TODO: overloadIndex var overloadIndex = ctor.OverloadIndex; return((extractContext, _) => { var parameterString = Utilities.GetGivenParameterDeclaration( pairParameters.ToArray(), extractContext, codeInformation); // newobj opcode can handle value type with parameter applied constructor. if (type.IsValueType) { // IL2C can't understand the native type size. // So, the expression will make calculation at the C compiler. var memsetExpression = (type.NativeType != null) ? "memset(&{0}, 0x00, sizeof {0})" : "memset(&{0}, 0x00, {1})"; // If constructor's arguments greater than or equal 2 (this and others) if (pairParameters.Count >= 2) { var typeName = type.CLanguageTypeName; return new[] { string.Format( memsetExpression, extractContext.GetSymbolName(thisSymbol), type.CLanguageStaticSizeOfExpression), string.Format( "{0}(&{1})", ctor.CLanguageFunctionFullName, parameterString) }; } else { // ValueType's default constructor not declared. return new[] { string.Format( memsetExpression, extractContext.GetSymbolName(thisSymbol), type.MangledUniqueName) }; } } // Object reference types. else { var get = new[] { string.Format( "{0} = il2c_get_uninitialized_object({1})", extractContext.GetSymbolName(thisSymbol), type.MangledUniqueName) }; var callCtor = new[] { string.Format( "{0}({1})", ctor.CLanguageFunctionFullName, parameterString) }; return get. Concat(callCtor). ToArray(); } }); }
/////////////////////////////////////////////////////////////////////////////// // // The color-conversion formulas come from the Colour Space Conversions FAQ: // http://www.poynton.com/PDFs/coloureq.pdf // // RGB --> CMYK CMYK --> RGB // --------------------------------------- -------------------------------------------- // Black = minimum(1-Red,1-Green,1-Blue) Red = 1-minimum(1,Cyan*(1-Black)+Black) // Cyan = (1-Red-Black)/(1-Black) Green = 1-minimum(1,Magenta*(1-Black)+Black) // Magenta = (1-Green-Black)/(1-Black) Blue = 1-minimum(1,Yellow*(1-Black)+Black) // Yellow = (1-Blue-Black)/(1-Black) // /////////////////////////////////////////////////////////////////////////////// private static void SetPDNRowCmyk(int pDestStart, int pDestEnd, int width, NativeArray <Color32> color, int idxSrc, DecodeContext context) { while (pDestStart < pDestEnd) { // CMYK values are stored as complements, presumably to allow for some // measure of compatibility with RGB-only applications. var C = 255 - context.Channels[0].ImageData[idxSrc]; var M = 255 - context.Channels[1].ImageData[idxSrc]; var Y = 255 - context.Channels[2].ImageData[idxSrc]; var K = 255 - context.Channels[3].ImageData[idxSrc]; int nRed = 255 - Math.Min(255, C * (255 - K) / 255 + K); int nGreen = 255 - Math.Min(255, M * (255 - K) / 255 + K); int nBlue = 255 - Math.Min(255, Y * (255 - K) / 255 + K); var c = color[pDestStart]; c.r = (byte)nRed; c.g = (byte)nGreen; c.b = (byte)nBlue; color[pDestStart] = c; pDestStart++; idxSrc += context.ByteDepth; } }
private static void SetPDNRowBitmap(int pDestStart, int pDestEnd, int width, NativeArray <Color32> color, int idxSrc, DecodeContext context) { var bitmap = context.Channels[0].ImageData; while (pDestStart < pDestEnd) { byte mask = (byte)(0x80 >> (idxSrc % 8)); byte bwValue = (byte)(bitmap[idxSrc / 8] & mask); bwValue = (bwValue == 0) ? (byte)255 : (byte)0; var c = color[pDestStart]; c.r = bwValue; c.g = bwValue; c.b = bwValue; color[pDestStart] = c; pDestStart++; idxSrc += context.ByteDepth; } }
/////////////////////////////////////////////////////////////////////////// #region Decode 32-bit HDR channels private static void SetPDNRowRgb32(int pDestStart, int pDestEnd, int width, NativeArray <Color32> color, int idxSrc, DecodeContext context) { NativeArray <float> redChannel = context.Channels[0].ImageData.Reinterpret <float>(1); NativeArray <float> greenChannel = context.Channels[1].ImageData.Reinterpret <float>(1); NativeArray <float> blueChannel = context.Channels[2].ImageData.Reinterpret <float>(1); { while (pDestStart < pDestEnd) { var c = color[pDestStart]; c.r = RGBByteFromHDRFloat(redChannel[idxSrc / 4]); c.g = RGBByteFromHDRFloat(greenChannel[idxSrc / 4]); c.b = RGBByteFromHDRFloat(blueChannel[idxSrc / 4]); color[pDestStart] = c; pDestStart++; idxSrc += 4; } } }
private static void SetPDNRowGrayscale32(int pDestStart, int pDestEnd, int width, NativeArray <Color32> color, int idxSrc, DecodeContext context) { NativeArray <float> channel = context.Channels[0].ImageData.Reinterpret <float>(1); { while (pDestStart < pDestEnd) { byte rgbValue = RGBByteFromHDRFloat(channel[idxSrc / 4]); var c = color[pDestStart]; c.r = rgbValue; c.g = rgbValue; c.b = rgbValue; color[pDestStart] = c; pDestStart++; idxSrc += 4; } } }
/// <summary> /// Decode image from Photoshop's channel-separated formats to BGRA, /// using the specified decode delegate on each row. /// </summary> private static void DecodeImage(BitmapLayer pdnLayer, DecodeContext decodeContext, DecodeDelegate decoder) { var psdLayer = decodeContext.Layer; var surface = pdnLayer.Surface; var rect = decodeContext.Rectangle; // Convert rows from the Photoshop representation, writing the // resulting ARGB values to to the Paint.NET Surface. for (int y = rect.Top; y < rect.Bottom; y++) { // Calculate index into ImageData source from row and column. int idxSrcPixel = (y - psdLayer.Rect.Top) * psdLayer.Rect.Width + (rect.Left - psdLayer.Rect.Left); int idxSrcByte = idxSrcPixel * decodeContext.ByteDepth; // Calculate pointers to destination Surface. //var pDestRow = surface.GetRowAddress(y); //var pDestStart = pDestRow + decodeContext.Rectangle.Left; //var pDestEnd = pDestRow + decodeContext.Rectangle.Right; var pDestStart = y * surface.width + decodeContext.Rectangle.Left; var pDestEnd = y * surface.width + decodeContext.Rectangle.Right; // For 16-bit images, take the higher-order byte from the image // data, which is now in little-endian order. if (decodeContext.ByteDepth == 2) { idxSrcByte++; } // Decode the color and alpha channels decoder(pDestStart, pDestEnd, surface.width, surface.color, idxSrcByte, decodeContext); } // Mask and Alpha. int userMaskContextSize = decodeContext.UserMaskContext != null ? decodeContext.Rectangle.Width : 1; int layerMaskContextSize = decodeContext.LayerMaskContext != null ? decodeContext.Rectangle.Width : 1; var userAlphaMask = new NativeArray <byte>(userMaskContextSize, Allocator.TempJob); var layerAlphaMask = new NativeArray <byte>(layerMaskContextSize, Allocator.TempJob); for (int y = rect.Top; y < rect.Bottom; y++) { // Calculate index into ImageData source from row and column. int idxSrcPixel = (y - psdLayer.Rect.Top) * psdLayer.Rect.Width + (rect.Left - psdLayer.Rect.Left); int idxSrcByte = idxSrcPixel * decodeContext.ByteDepth; // Calculate pointers to destination Surface. //var pDestRow = surface.GetRowAddress(y); //var pDestStart = pDestRow + decodeContext.Rectangle.Left; //var pDestEnd = pDestRow + decodeContext.Rectangle.Right; var pDestStart = y * surface.width + decodeContext.Rectangle.Left; var pDestEnd = y * surface.width + decodeContext.Rectangle.Right; // For 16-bit images, take the higher-order byte from the image // data, which is now in little-endian order. if (decodeContext.ByteDepth == 2) { idxSrcByte++; } // Decode the color and alpha channels SetPDNAlphaRow(pDestStart, pDestEnd, surface.width, surface.color, idxSrcByte, decodeContext.ByteDepth, decodeContext.HasAlphaChannel, decodeContext.AlphaChannel); // Apply layer masks(s) to the alpha channel GetMaskAlphaRow(y, decodeContext, decodeContext.LayerMaskContext, ref layerAlphaMask); GetMaskAlphaRow(y, decodeContext, decodeContext.UserMaskContext, ref userAlphaMask); ApplyPDNMask(pDestStart, pDestEnd, surface.width, surface.color, layerAlphaMask, userAlphaMask); } userAlphaMask.Dispose(); layerAlphaMask.Dispose(); }
/// <summary> /// Decode image from Photoshop's channel-separated formats to BGRA, /// using the specified decode delegate on each row. /// </summary> private static JobHandle DecodeImage(BitmapLayer pdnLayer, DecodeContext decodeContext, DecodeType decoderType, JobHandle inputDeps) { var psdLayer = decodeContext.Layer; var surface = pdnLayer.Surface; var rect = decodeContext.Rectangle; // Convert rows from the Photoshop representation, writing the // resulting ARGB values to to the Paint.NET Surface. int jobCount = Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerMaximumCount; int execCount = (rect.Bottom - rect.Top); int sliceCount = execCount / jobCount; PDNDecoderJob decoderJob = new PDNDecoderJob(); decoderJob.Data.Rect = rect; decoderJob.Data.LayerRect = psdLayer.Rect; decoderJob.Data.ClippedRect = rect; decoderJob.Data.SurfaceWidth = surface.width; decoderJob.Data.SurfaceHeight = surface.height; decoderJob.Data.SurfaceByteDepth = decodeContext.ByteDepth; decoderJob.Data.DecoderType = decoderType; decoderJob.Data.ColorChannel0 = decodeContext.Channels[0].ImageData; decoderJob.Data.ColorChannel1 = decodeContext.Channels.Length > 1 ? decodeContext.Channels[1].ImageData : decodeContext.Channels[0].ImageData; decoderJob.Data.ColorChannel2 = decodeContext.Channels.Length > 2 ? decodeContext.Channels[2].ImageData : decodeContext.Channels[0].ImageData; decoderJob.Data.ColorChannel3 = decodeContext.Channels.Length > 3 ? decodeContext.Channels[3].ImageData : decodeContext.Channels[0].ImageData; decoderJob.Data.ColorModeData = decodeContext.ColorModeData; decoderJob.Data.DecodedImage = surface.color; // Schedule the job, returns the JobHandle which can be waited upon later on JobHandle jobHandle = decoderJob.Schedule(execCount, sliceCount, inputDeps); // Mask and Alpha. int userMaskContextSize = decodeContext.UserMaskContext != null ? decodeContext.Rectangle.Width : 1; int layerMaskContextSize = decodeContext.LayerMaskContext != null ? decodeContext.Rectangle.Width : 1; var userAlphaMask = new NativeArray <byte>(userMaskContextSize, Allocator.TempJob); var layerAlphaMask = new NativeArray <byte>(layerMaskContextSize, Allocator.TempJob); var userAlphaMaskEmpty = new NativeArray <byte>(rect.Bottom, Allocator.TempJob); var layerAlphaMaskEmpty = new NativeArray <byte>(rect.Bottom, Allocator.TempJob); PDNAlphaMaskJob alphaMaskJob = new PDNAlphaMaskJob(); for (int y = rect.Top; y < rect.Bottom; ++y) { if (decodeContext.UserMaskContext != null) { userAlphaMaskEmpty[y] = decodeContext.UserMaskContext.IsRowEmpty(y) ? (byte)1 : (byte)0; } if (decodeContext.LayerMaskContext != null) { layerAlphaMaskEmpty[y] = decodeContext.LayerMaskContext.IsRowEmpty(y) ? (byte)1 : (byte)0; } } alphaMaskJob.Data.Rect = rect; alphaMaskJob.Data.LayerRect = psdLayer.Rect; alphaMaskJob.Data.ClippedRect = rect; alphaMaskJob.Data.SurfaceWidth = surface.width; alphaMaskJob.Data.SurfaceHeight = surface.height; alphaMaskJob.Data.SurfaceByteDepth = decodeContext.ByteDepth; alphaMaskJob.Data.HasAlphaChannel = decodeContext.HasAlphaChannel; alphaMaskJob.Data.HasUserAlphaMask = decodeContext.UserMaskContext != null ? 1 : 0; alphaMaskJob.Data.UserMaskInvertOnBlend = decodeContext.UserMaskContext != null ? (decodeContext.UserMaskContext.Mask.InvertOnBlend ? 1 : 0) : 0; alphaMaskJob.Data.UserMaskRect = decodeContext.UserMaskContext != null ? decodeContext.UserMaskContext.Mask.Rect : rect; alphaMaskJob.Data.UserMaskContextRect = decodeContext.UserMaskContext != null ? decodeContext.UserMaskContext.Rectangle : rect; alphaMaskJob.Data.HasLayerAlphaMask = decodeContext.LayerMaskContext != null ? 1 : 0; alphaMaskJob.Data.LayerMaskInvertOnBlend = decodeContext.LayerMaskContext != null ? (decodeContext.LayerMaskContext.Mask.InvertOnBlend ? 1 : 0) : 0; alphaMaskJob.Data.LayerMaskRect = decodeContext.LayerMaskContext != null ? decodeContext.LayerMaskContext.Mask.Rect : rect; alphaMaskJob.Data.LayerMaskContextRect = decodeContext.LayerMaskContext != null ? decodeContext.LayerMaskContext.Rectangle : rect; alphaMaskJob.Data.AlphaChannel0 = decodeContext.AlphaChannel; alphaMaskJob.Data.UserMask = decodeContext.UserMaskContext != null ? decodeContext.UserMaskContext.Mask.ImageData : decodeContext.AlphaChannel; alphaMaskJob.Data.UserAlphaMask = userAlphaMask; alphaMaskJob.Data.UserAlphaMaskEmpty = userAlphaMaskEmpty; alphaMaskJob.Data.LayerMask = decodeContext.LayerMaskContext != null ? decodeContext.LayerMaskContext.Mask.ImageData : decodeContext.AlphaChannel; alphaMaskJob.Data.LayerAlphaMask = layerAlphaMask; alphaMaskJob.Data.LayerAlphaMaskEmpty = layerAlphaMaskEmpty; alphaMaskJob.Data.DecodedImage = surface.color; alphaMaskJob.Data.UserMaskBackgroundColor = decodeContext.UserMaskContext != null ? decodeContext.UserMaskContext.Mask.BackgroundColor : (byte)0; alphaMaskJob.Data.LayerMaskBackgroundColor = decodeContext.LayerMaskContext != null ? decodeContext.LayerMaskContext.Mask.BackgroundColor : (byte)0; jobHandle = alphaMaskJob.Schedule(jobHandle); return(jobHandle); }
public RepositoryPerson(DecodeContext decodeContext) : base(decodeContext) { _decodeContext = decodeContext; }
public override Func <IExtractContext, string[]> Apply(DecodeContext decodeContext) { return(ArithmeticalConverterUtilities.Apply( ArithmeticalConverterUtilities.BinaryOperators.Rem, decodeContext)); }
private static void SetPDNRowGrayscale(int pDestStart, int pDestEnd, int width, NativeArray <Color32> color, int idxSrc, DecodeContext context) { while (pDestStart < pDestEnd) { var level = context.Channels[0].ImageData[idxSrc]; var c = color[pDestStart]; c.r = level; c.g = level; c.b = level; color[pDestStart] = c; pDestStart++; idxSrc += context.ByteDepth; } }
public static Func <IExtractContext, string[]> Apply( int value, DecodeContext decodeContext) { return(Apply(decodeContext.PrepareContext.MetadataContext.Int32Type, value, decodeContext)); }
private static void SetPDNRowIndexed(int pDestStart, int pDestEnd, int width, NativeArray <Color32> color, int idxSrc, DecodeContext context) { while (pDestStart < pDestEnd) { int index = (int)context.Channels[0].ImageData[idxSrc]; var c = color[pDestStart]; c.r = (byte)context.ColorModeData[index]; c.g = context.ColorModeData[index + 256]; c.b = context.ColorModeData[index + 2 * 256]; color[pDestStart] = c; pDestStart++; idxSrc += context.ByteDepth; } }
public override Func <IExtractContext, string[]> Apply( FieldReference field, DecodeContext decodeContext) { var siReference = decodeContext.PopStack(); var oper = "->"; if (siReference.TargetType.IsByReference) { var dereferencedType = siReference.TargetType.GetElementType(); if (field.DeclaringType.IsAssignableFrom(dereferencedType) == false) { throw new InvalidProgramSequenceException( "Invalid managed reference: Offset={0}, StackType={1}, Name={2}", decodeContext.Current.Offset, siReference.TargetType.FullName, field.GetFullMemberName()); } } else if (!siReference.TargetType.IsValueType) { Debug.Assert(siReference.TargetType.Resolve().IsClass || siReference.TargetType.Resolve().IsInterface); if (field.DeclaringType.IsAssignableFrom(siReference.TargetType) == false) { throw new InvalidProgramSequenceException( "Invalid object reference: Offset={0}, StackType={1}, Name={2}", decodeContext.Current.Offset, siReference.TargetType.FullName, field.GetFullMemberName()); } } else if (!siReference.TargetType.IsPrimitive) { Debug.Assert(siReference.TargetType.IsValueType); if (field.DeclaringType.IsAssignableFrom(siReference.TargetType) == false) { throw new InvalidProgramSequenceException( "Invalid managed reference: Offset={0}, StackType={1}, Name={2}", decodeContext.Current.Offset, siReference.TargetType.FullName, field.GetFullMemberName()); } oper = "."; } else { throw new InvalidProgramSequenceException( "Invalid type at stack: Offset={0}, StackType={1}", decodeContext.Current.Offset, siReference.TargetType.FullName); } var targetType = field.FieldType.GetStackableType(); var resultName = decodeContext.PushStack(targetType); var offset = decodeContext.Current.Offset; return(extractContext => { var rightExpression = extractContext.GetRightExpression( targetType, field.FieldType, siReference.SymbolName + oper + field.Name); if (rightExpression == null) { throw new InvalidProgramSequenceException( "Invalid load operation: Offset={0}, StackType={1}, FieldType={2}", offset, targetType.FullName, field.FieldType.FullName); } return new[] { string.Format( "{0} = {1}", resultName, rightExpression) }; }); }
private static void SetPDNRowLab(int pDestStart, int pDestEnd, int width, NativeArray <Color32> color, int idxSrc, DecodeContext context) { while (pDestStart < pDestEnd) { double exL, exA, exB; exL = (double)context.Channels[0].ImageData[idxSrc]; exA = (double)context.Channels[1].ImageData[idxSrc]; exB = (double)context.Channels[2].ImageData[idxSrc]; int L = (int)(exL / 2.55); int a = (int)(exA - 127.5); int b = (int)(exB - 127.5); // First, convert from Lab to XYZ. // Standards used Observer = 2, Illuminant = D65 const double ref_X = 95.047; const double ref_Y = 100.000; const double ref_Z = 108.883; double var_Y = ((double)L + 16.0) / 116.0; double var_X = (double)a / 500.0 + var_Y; double var_Z = var_Y - (double)b / 200.0; double var_X3 = var_X * var_X * var_X; double var_Y3 = var_Y * var_Y * var_Y; double var_Z3 = var_Z * var_Z * var_Z; if (var_Y3 > 0.008856) { var_Y = var_Y3; } else { var_Y = (var_Y - 16 / 116) / 7.787; } if (var_X3 > 0.008856) { var_X = var_X3; } else { var_X = (var_X - 16 / 116) / 7.787; } if (var_Z3 > 0.008856) { var_Z = var_Z3; } else { var_Z = (var_Z - 16 / 116) / 7.787; } double X = ref_X * var_X; double Y = ref_Y * var_Y; double Z = ref_Z * var_Z; // Then, convert from XYZ to RGB. // Standards used Observer = 2, Illuminant = D65 // ref_X = 95.047, ref_Y = 100.000, ref_Z = 108.883 double var_R = X * 0.032406 + Y * (-0.015372) + Z * (-0.004986); double var_G = X * (-0.009689) + Y * 0.018758 + Z * 0.000415; double var_B = X * 0.000557 + Y * (-0.002040) + Z * 0.010570; if (var_R > 0.0031308) { var_R = 1.055 * (Math.Pow(var_R, 1 / 2.4)) - 0.055; } else { var_R = 12.92 * var_R; } if (var_G > 0.0031308) { var_G = 1.055 * (Math.Pow(var_G, 1 / 2.4)) - 0.055; } else { var_G = 12.92 * var_G; } if (var_B > 0.0031308) { var_B = 1.055 * (Math.Pow(var_B, 1 / 2.4)) - 0.055; } else { var_B = 12.92 * var_B; } int nRed = (int)(var_R * 256.0); int nGreen = (int)(var_G * 256.0); int nBlue = (int)(var_B * 256.0); if (nRed < 0) { nRed = 0; } else if (nRed > 255) { nRed = 255; } if (nGreen < 0) { nGreen = 0; } else if (nGreen > 255) { nGreen = 255; } if (nBlue < 0) { nBlue = 0; } else if (nBlue > 255) { nBlue = 255; } var c = color[pDestStart]; c.r = (byte)nRed; c.g = (byte)nGreen; c.b = (byte)nBlue; color[pDestStart] = c; pDestStart++; idxSrc += context.ByteDepth; } }
public RepositoryBase(DecodeContext decodeContext) { _decodeContext = decodeContext; }
public override ExpressionEmitter Prepare(DecodeContext decodeContext) { return(LdindConverterUtilities.Prepare(decodeContext)); }
public RepositoryHobby(DecodeContext decodeContext) : base(decodeContext) { _decodeContext = decodeContext; }
public abstract Func <IExtractContext, string[]> Apply(object operand, DecodeContext decodeContext);
public abstract Func <IExtractContext, string[]> Apply(DecodeContext decodeContext);
public override ExpressionEmitter Prepare( ITypeInformation operand, DecodeContext decodeContext) { var si = decodeContext.PopStack(); if (!(si.TargetType.IsValueType && // We have to value type (operand.Equals(si.TargetType) || // Same type (operand.IsInt32StackFriendlyType && si.TargetType.IsInt32StackFriendlyType) || // Same size or implicit expanders (operand.IsInt64StackFriendlyType && si.TargetType.IsInt64StackFriendlyType) || // Same size (operand.IsIntPtrStackFriendlyType && si.TargetType.IsIntPtrStackFriendlyType)))) // Same size { throw new InvalidProgramSequenceException( "Invalid type at stack: Location={0}, TokenType={1}, StackType={2}", decodeContext.CurrentCode.RawLocation, operand.FriendlyName, si.TargetType.FriendlyName); } // NOTE: The 'O' type means System.Object, but we have to push the System.ValueType (BoxedValueTypeInformation). // Because the boxed value types can implicit cast to both types. // The upcast can be inlining (System.ValueType --> System.Object), // but downcast requires runtime cast operator (System.Object --> System.ValueType). var symbol = decodeContext.PushStack( new BoxedValueTypeInformation(si.TargetType)); // Register target type (at the file scope). decodeContext.PrepareContext.RegisterType(operand, decodeContext.Method); // NOTE: The IL2C strict type infers the evaluation stack. // The unbox operator is handling by the pointer. // So, we have to simulate implicitly conversion from little size value to large size value. // (It's only 8/16 --> 32bit. See ECMA-335 III.1.1.1 Numeric data types) // We can use conversion with the "il2c_box2" function in this case. // For example: // // object value = (byte)123; // ldc.i4.s 123 // int32_t // box [mscorlib]System.Byte // int32_t --> objref(uint8_t) // size[4] --> size[1] if (operand.InternalStaticSizeOfValue == si.TargetType.InternalStaticSizeOfValue) { return((extractContext, _) => { return new[] { string.Format( "{0} = il2c_box(&{1}, {2})", extractContext.GetSymbolName(symbol), extractContext.GetSymbolName(si), operand.MangledUniqueName) }; }); } else { return((extractContext, _) => { return new[] { string.Format( "{0} = il2c_box2(&{1}, {2}, {3})", extractContext.GetSymbolName(symbol), extractContext.GetSymbolName(si), operand.MangledUniqueName, si.TargetType.MangledUniqueName) }; }); } }
public override Func <IExtractContext, string[]> Apply( IFieldInformation field, DecodeContext decodeContext) { return(StfldConverterUtilities.Apply(field, decodeContext)); }
public static Func <IExtractContext, string[]> Apply(BinaryOperators binaryOperator, DecodeContext decodeContext) { var si1 = decodeContext.PopStack(); var si0 = decodeContext.PopStack(); char opChar; switch (binaryOperator) { case BinaryOperators.Add: opChar = '+'; break; case BinaryOperators.Sub: opChar = '-'; break; case BinaryOperators.Mul: opChar = '*'; break; case BinaryOperators.Div: opChar = '/'; break; case BinaryOperators.Rem: opChar = '%'; break; default: throw new Exception(); } // See also: ECMA-335: III.1.5 Operand type table - Binary Numeric Operations // Int32 = (Int32) op (Int32) if (si0.TargetType.IsInt32StackFriendlyType && si1.TargetType.IsInt32StackFriendlyType) { var result = decodeContext.PushStack(decodeContext.PrepareContext.MetadataContext.Int32Type); return(extractContext => new[] { string.Format( "{0} = {1} {2} {3}", extractContext.GetSymbolName(result), extractContext.GetSymbolName(si0), opChar, extractContext.GetSymbolName(si1)) }); } // Int64 = (Int64) op (Int64) if (si0.TargetType.IsInt64StackFriendlyType && si1.TargetType.IsInt64StackFriendlyType) { var result = decodeContext.PushStack(decodeContext.PrepareContext.MetadataContext.Int64Type); return(extractContext => new[] { string.Format( "{0} = {1} {2} {3}", extractContext.GetSymbolName(result), extractContext.GetSymbolName(si0), opChar, extractContext.GetSymbolName(si1)) }); } // Double = (Float) % (Float) if (si0.TargetType.IsFloatStackFriendlyType && si1.TargetType.IsFloatStackFriendlyType && (binaryOperator == BinaryOperators.Rem)) { var result = decodeContext.PushStack(decodeContext.PrepareContext.MetadataContext.DoubleType); // Use special runtime function. return(extractContext => new[] { string.Format( "{0} = il2c_fmod({1}, {2})", extractContext.GetSymbolName(result), extractContext.GetSymbolName(si0), extractContext.GetSymbolName(si1)) }); } // Double = (Float) op (Float) if (si0.TargetType.IsFloatStackFriendlyType && si1.TargetType.IsFloatStackFriendlyType) { var result = decodeContext.PushStack(decodeContext.PrepareContext.MetadataContext.DoubleType); return(extractContext => new[] { string.Format( "{0} = (double){1} {2} (double){3}", extractContext.GetSymbolName(result), extractContext.GetSymbolName(si0), opChar, extractContext.GetSymbolName(si1)) }); } // ByRef = (Int32) + (ByRef) if (si0.TargetType.IsInt32StackFriendlyType && si1.TargetType.IsByReference && (binaryOperator == BinaryOperators.Add)) { var result = decodeContext.PushStack(si1.TargetType); return(extractContext => new[] { string.Format( "{0} = ({1})((intptr_t){2} + (intptr_t){3})", extractContext.GetSymbolName(result), si1.TargetType.CLanguageTypeName, extractContext.GetSymbolName(si0), extractContext.GetSymbolName(si1)) }); } // ByRef = (IntPtr) + (ByRef) if (si0.TargetType.IsIntPtrStackFriendlyType && si1.TargetType.IsByReference && (binaryOperator == BinaryOperators.Add)) { var result = decodeContext.PushStack(si1.TargetType); return(extractContext => new[] { string.Format( "{0} = ({1})((intptr_t){2} + (intptr_t){3})", extractContext.GetSymbolName(result), si1.TargetType.CLanguageTypeName, extractContext.GetSymbolName(si0), extractContext.GetSymbolName(si1)) }); } // ByRef = (ByRef) +/- (Int32|IntPtr) if (si0.TargetType.IsByReference && (si1.TargetType.IsInt32StackFriendlyType || si1.TargetType.IsIntPtrStackFriendlyType) && ((binaryOperator == BinaryOperators.Add) || (binaryOperator == BinaryOperators.Sub))) { var result = decodeContext.PushStack(si0.TargetType); return(extractContext => new[] { string.Format( "{0} = ({1})((intptr_t){2} {3} (intptr_t){4})", extractContext.GetSymbolName(result), si0.TargetType.CLanguageTypeName, extractContext.GetSymbolName(si0), opChar, extractContext.GetSymbolName(si1)) }); } // ByRef = (ByRef) - (ByRef) if (si0.TargetType.IsByReference && si1.TargetType.IsByReference && (binaryOperator == BinaryOperators.Sub)) { var result = decodeContext.PushStack(si0.TargetType); return(extractContext => new[] { string.Format( "{0} = ({1})((intptr_t){2} - (intptr_t){3})", extractContext.GetSymbolName(result), si0.TargetType.CLanguageTypeName, extractContext.GetSymbolName(si0), extractContext.GetSymbolName(si1)) }); } // IntPtr = (Int32|IntPtr) op (Int32|IntPtr) if ((si0.TargetType.IsInt32StackFriendlyType || si0.TargetType.IsIntPtrStackFriendlyType) && (si1.TargetType.IsInt32StackFriendlyType || si1.TargetType.IsIntPtrStackFriendlyType)) { var result = decodeContext.PushStack(decodeContext.PrepareContext.MetadataContext.IntPtrType); return(extractContext => new[] { string.Format( "{0} = (intptr_t){1} {2} (intptr_t){3}", extractContext.GetSymbolName(result), extractContext.GetSymbolName(si0), opChar, extractContext.GetSymbolName(si1)) }); } throw new InvalidProgramSequenceException( "Unknown arithmetical operation: Location={0}, Op={1}, Type0={2}, Type1={3}", decodeContext.CurrentCode.RawLocation, binaryOperator, si0.TargetType.FriendlyName, si1.TargetType.FriendlyName); }
public override Func <IExtractContext, string[]> Apply( ICodeInformation operand, DecodeContext decodeContext) { return(BranchExpressionUtilities.ApplyFalse(operand, "!=", decodeContext)); }
public override Func <IExtractContext, string[]> Apply( VariableReference operand, DecodeContext decodeContext) { return(LdlocConverterUtilities.Apply(operand, decodeContext, true)); }