Example #1
0
 /// <summary>
 /// Sets the color of the RGBLed toy. <br/>
 /// The Alpha part of the RGBAColor is ignored.
 /// </summary>
 /// <param name="Color">RGBAColor object containg the brightness values for the color.</param>
 public void SetColor(RGBAColor Color)
 {
     SetColor(Color.Red, Color.Green, Color.Blue);
 }
Example #2
0
 public PenLineViewModel(IObservable <Rectangle> sceneBoundsObservable, Position from, Position to, double thickness, RGBAColor color)
 {
     x1        = sceneBoundsObservable.Select(p => from.X - p.Left).ToProperty(this, p => p.X1);
     y1        = sceneBoundsObservable.Select(p => p.Top - from.Y).ToProperty(this, p => p.Y1);
     x2        = sceneBoundsObservable.Select(p => to.X - p.Left).ToProperty(this, p => p.X2);
     y2        = sceneBoundsObservable.Select(p => p.Top - to.Y).ToProperty(this, p => p.Y2);
     Thickness = thickness;
     Color     = System.Windows.Media.Color.FromArgb(color.Alpha, color.Red, color.Green, color.Blue);
     Brush     = new SolidColorBrush(Color);
     Brush.Freeze();
 }
Example #3
0
 public void GetColor(int Index, out RGBAColor Value)
 {
     Value = FValues[Index % FSliceCount];
 }
        public void Evaluate(int SpreadMax)
        {
            COLLADAUtil.Logger = new LoggerWrapper(FLogger);

            try
            {
                //if any of the inputs has changed
                //recompute the outputs
                if (FColladaModelIn.IsChanged || FIndex.IsChanged || FBinSize.IsChanged)
                {
                    FSelectedInstanceMeshes.Clear();
                    FMeshNameOutput.SliceCount = 0;
                    FMeshPathOutput.SliceCount = 0;
                    FColladaModel = FColladaModelIn.SliceCount > 0 ? FColladaModelIn[0] : null;

                    if (FColladaModel == null)
                    {
                        FMyMeshOutput.SliceCount       = 0;
                        FMaterialNameOutput.SliceCount = 0;
//	                    FFxIdOutput.SliceCount = 0;
                        FTextureFileNameOutput.SliceCount = 0;
                        FEmissiveColorOut.SliceCount      = 0;
                        FDiffuseColorOut.SliceCount       = 0;
                        FSpecularColorOut.SliceCount      = 0;
                        FShininessOut.SliceCount          = 0;
                        FOpaqueOut.SliceCount             = 0;
                    }
                    else
                    {
                        //make negative bin sizes ok
                        int binSize = FBinSize[0];
                        if (binSize < 0)
                        {
                            binSize = FColladaModel.InstanceMeshes.Count / Math.Abs(binSize);
                        }

                        List <Model.BasicMaterial> materialList = new List <Model.BasicMaterial>();
//						FFxIdOutput.SliceCount = 0;
                        for (int i = 0; i < FIndex.SliceCount; i++)
                        {
                            int index = FIndex[i] * binSize;
                            index = ((index % FColladaModel.InstanceMeshes.Count) + FColladaModel.InstanceMeshes.Count) % FColladaModel.InstanceMeshes.Count;
                            for (int j = index; j < index + binSize; j++)
                            {
                                Model.InstanceMesh instanceMesh = FColladaModel.InstanceMeshes[j % FColladaModel.InstanceMeshes.Count];
                                FSelectedInstanceMeshes.Add(instanceMesh);
                                FLogger.Log(LogType.Debug, "Instance of mesh '" + instanceMesh + "' loaded.");

                                string name = instanceMesh.ParentBone.NodeName;
                                string path = name;
                                var    bone = instanceMesh.ParentBone;
                                while (bone.Parent.NodeType == "NODE")
                                {
                                    path = bone.Parent.NodeName + "/" + path;
                                    bone = bone.Parent;
                                }

                                foreach (Document.Primitive primitive in instanceMesh.Mesh.Primitives)
                                {
                                    Model.BasicMaterial material;
                                    string bindedMaterialId;
                                    if (!instanceMesh.MaterialBinding.TryGetValue(primitive.material, out bindedMaterialId))
                                    {
                                        bindedMaterialId = primitive.material;
                                    }

                                    if (FColladaModel.BasicMaterialsBinding.TryGetValue(bindedMaterialId, out material))
                                    {
                                        materialList.Add(material);
//										FFxIdOutput.Add(bindedMaterialId);
                                    }
                                    else
                                    {
                                        materialList.Add(FNoMaterial);
//										FFxIdOutput.Add(bindedMaterialId);
                                    }

                                    FMeshNameOutput.Add(name);                                     //add name of the mesh
                                    FMeshPathOutput.Add(path);                                     //and prepend the group names it's in
                                }
                            }
                        }

                        FMaterialNameOutput.SliceCount    = materialList.Count;
                        FTextureFileNameOutput.SliceCount = materialList.Count;
                        FEmissiveColorOut.SliceCount      = materialList.Count;
                        FDiffuseColorOut.SliceCount       = materialList.Count;
                        FSpecularColorOut.SliceCount      = materialList.Count;
                        FShininessOut.SliceCount          = materialList.Count;
                        FOpaqueOut.SliceCount             = materialList.Count;
                        for (int j = 0; j < materialList.Count; j++)
                        {
                            Model.BasicMaterial material = materialList[j];
                            FMaterialNameOutput[j]    = material.Name;
                            FTextureFileNameOutput[j] = material.Texture;
                            if (material.EmissiveColor.HasValue)
                            {
                                FEmissiveColorOut[j] = new RGBAColor(material.EmissiveColor.Value.X, material.EmissiveColor.Value.Y, material.EmissiveColor.Value.Z, 1.0);
                            }
                            else
                            {
                                FEmissiveColorOut[j] = VColor.Black;
                            }
                            if (material.DiffuseColor.HasValue)
                            {
                                FDiffuseColorOut[j] = new RGBAColor(material.DiffuseColor.Value.X, material.DiffuseColor.Value.Y, material.DiffuseColor.Value.Z, 1.0);
                            }
                            else
                            {
                                FDiffuseColorOut[j] = VColor.White;
                            }
                            if (material.SpecularColor.HasValue)
                            {
                                FSpecularColorOut[j] = new RGBAColor(material.SpecularColor.Value.X, material.SpecularColor.Value.Y, material.SpecularColor.Value.Z, 1.0);
                            }
                            else
                            {
                                FSpecularColorOut[j] = VColor.Black;
                            }
                            if (material.SpecularPower.HasValue)
                            {
                                FShininessOut[j] = material.SpecularPower.Value;
                            }
                            else
                            {
                                FShininessOut[j] = 25.0;
                            }
                            // as of FCollada 3.03 opaque = 1.0, before opaque = 0.0
                            double alpha = 1.0;
                            if (material.Alpha.HasValue)
                            {
                                alpha = material.Alpha.Value;
                            }
                            if (!FOpaqueIsOne)
                            {
                                FOpaqueOut[j] = 1 - alpha;
                            }
                            else
                            {
                                FOpaqueOut[j] = alpha;
                            }
                        }

                        FMyMeshOutput.SliceCount = materialList.Count;
                        FMyMeshOutput.MarkPinAsChanged();

                        foreach (Mesh m in FDeviceMeshes.Values)
                        {
                            FLogger.Log(LogType.Debug, "Destroying Resource...");
                            m.Dispose();
                        }
                        FDeviceMeshes.Clear();
                    }
                }

                if (FColladaModelIn.IsChanged || FIndex.IsChanged || FBinSize.IsChanged || FTimeInput.IsChanged)
                {
                    int maxCount              = Math.Max(FTimeInput.SliceCount, FSelectedInstanceMeshes.Count);
                    var transforms            = new List <Matrix>();
                    var skinningTransforms    = new List <Matrix>();
                    var bindShapeTransforms   = new List <Matrix>();
                    var invBindPoseTransforms = new List <Matrix>();
                    var boneNames             = new List <string>();
                    for (int i = 0; i < maxCount && FSelectedInstanceMeshes.Count > 0; i++)
                    {
                        int   meshIndex    = i % FSelectedInstanceMeshes.Count;
                        var   instanceMesh = FSelectedInstanceMeshes[meshIndex];
                        float time         = FTimeInput[i];
                        var   m            = instanceMesh.ParentBone.GetAbsoluteTransformMatrix(time) * FColladaModel.ConversionMatrix;

                        for (int j = 0; j < instanceMesh.Mesh.Primitives.Count; j++)
                        {
                            transforms.Add(m);
                        }

                        // Skinning
                        if (instanceMesh is Model.SkinnedInstanceMesh)
                        {
                            var skinnedInstanceMesh = instanceMesh as Model.SkinnedInstanceMesh;
                            skinningTransforms.AddRange(skinnedInstanceMesh.GetSkinningMatrices(time));                              // am i right, that this whole thing will only work with 1 selected mesh?
                            bindShapeTransforms.Add(skinnedInstanceMesh.BindShapeMatrix);
                            for (int j = 0; j < skinnedInstanceMesh.InvBindMatrixList.Count; j++)
                            {
                                invBindPoseTransforms.Add(skinnedInstanceMesh.InvBindMatrixList[j]);
                            }
                            boneNames.AddRange(skinnedInstanceMesh.Bones.Select(b => b.Name));
                        }
                    }


                    FTransformOutput.SliceCount = transforms.Count;
                    for (int j = 0; j < transforms.Count; j++)
                    {
                        FTransformOutput.SetMatrix(j, transforms[j].ToMatrix4x4());
                    }

                    FSkinningTransformOutput.SliceCount = skinningTransforms.Count;
                    for (int j = 0; j < skinningTransforms.Count; j++)
                    {
                        FSkinningTransformOutput.SetMatrix(j, skinningTransforms[j].ToMatrix4x4());
                    }

                    FBindShapeTransformOutput.SliceCount = bindShapeTransforms.Count;
                    for (int j = 0; j < bindShapeTransforms.Count; j++)
                    {
                        FBindShapeTransformOutput.SetMatrix(j, bindShapeTransforms[j].ToMatrix4x4());
                    }

                    FInvBindPoseTransformOutput.SliceCount = invBindPoseTransforms.Count;
                    for (int j = 0; j < invBindPoseTransforms.Count; j++)
                    {
                        FInvBindPoseTransformOutput.SetMatrix(j, invBindPoseTransforms[j].ToMatrix4x4());
                    }

                    FBoneNamesOutput.AssignFrom(boneNames);
                }
            }
            catch (Exception e)
            {
                FLogger.Log(e);
            }
        }
Example #5
0
 public override void Write(RGBAColor value, int stride)
 {
     Debug.Assert(!Eos);
     FPDst[Position] = value;
     Position       += stride;
 }
Example #6
0
 public OutlineStyle(RGBAColor color, bool isEnabled, uint thickness)
     : base(color, isEnabled)
 {
     _thickness = thickness;
 }
Example #7
0
 public Style(RGBAColor color, bool isEnabled)
 {
     _color     = color;
     _isEnabled = isEnabled;
 }
 private protected sealed override RGBAColor ProcessCoordinate(int x, int y, int w, int h, RGBAColor source) =>
 RGBAColor.Blend(source, ProcessCoordinate(x, y, w, h), Blending);
 public static void DrawGradientLine(this Graphics g, float start_x, float start_y, float end_x, float end_y, RGBAColor start_color, RGBAColor end_color, Scalar thickness) =>
 g.DrawGradientLine(new(start_x, start_y), new(end_x, end_y), start_color, end_color);
Example #10
0
        private void Compute(out Hash64Bit hash, Image source)
        {
            // Get a copy of the image we need to compute the hash on
            // but resized to a default dimension Size
            // Attention: this will alter the proportions, but it is fine
            Image resizedImage = source.Resize(Size, Size);

            // Define quantities
            double[]   row  = new double[Size];
            double[][] rows = new double[Size][];

            // Calculate LUMA from RGB and DCT for each row
            for (int y = 0; y < Size; y++)
            {
                for (int x = 0; x < Size; x++)
                {
                    RGBAColor color = Color2RGBAColor(resizedImage.ColorAt(x, y));
                    row[x] = Math.Floor(
                        color.Red * RedLUMAFactor +
                        color.Green * GreenLUMAFactor +
                        color.Blue * BlueLUMAFactor);
                }
                rows[y] = DiscreteCosineTransform1Dimension(row);
            }

            // We need the resized matrix and image no more
            resizedImage.Dispose();
            resizedImage = null;

            // More quantities
            double[]   col    = new double[Size];
            double[][] matrix = new double[Size][];

            // Calculate the DCT for each column
            for (int x = 0; x < Size; x++)
            {
                for (int y = 0; y < Size; y++)
                {
                    col[y] = rows[y][x];
                }
                matrix[x] = DiscreteCosineTransform1Dimension(col);
            }

            // Extract top SubSize x SubSize pixels into a linear array
            double[] pixels = new double[SubSize * SubSize];
            for (int y = 0, i = 0; y < SubSize; y++)
            {
                for (int x = 0; x < SubSize; x++)
                {
                    pixels[i++] = matrix[y][x];
                }
            }

            // Calculate median
            double median = MedianFilter(pixels);

            // Calculate final hash
            ulong rawHash = 0;
            ulong one     = 1;

            for (int i = 0; i < pixels.Length; i++)
            {
                double pixel = pixels[i];
                if (pixel > median)
                {
                    rawHash |= one;
                }
                one = one << 1;
            }

            hash = new Hash64Bit(rawHash);
        }
 public static void DrawGradientLine(this Graphics g, float start_x, float start_y, float end_x, float end_y, RGBAColor start_color, RGBAColor end_color) =>
 g.DrawGradientLine(start_x, end_x, start_y, end_y, start_color, end_color, Scalar.One);
    public static void DrawGradientLine(this Graphics g, Vector2 start_pos, Vector2 end_pos, RGBAColor start_color, RGBAColor end_color, Scalar thickness)
    {
        using LinearGradientBrush brush = new(start_pos, end_pos, start_color, end_color);
        using Pen pen = new(brush, thickness);

        g.DrawLine(pen, start_pos, end_pos);
    }
 public static void DrawGradientLine(this Graphics g, Vector2 start_pos, Vector2 end_pos, RGBAColor start_color, RGBAColor end_color) =>
 g.DrawGradientLine(start_pos, end_pos, start_color, end_color, Scalar.One);
Example #14
0
 public void SetFillColor(RGBAColor color)
 {
     throw new NotImplementedException();
 }
Example #15
0
 public void SetColor(RGBAColor color)
 {
     _color = color;
 }
 public void SetColor(uint rgbColor)
 {
     _rgbaColor = RGBAConverter.Convert(rgbColor);
 }
Example #17
0
        public override void Evaluate(double CurrentTime)
        {
            base.Evaluate(CurrentTime);

            if (FKeyFrames.Count == 0)
            {
                FOutput = VColor.Black;
            }
            else
            {
                TLColorKeyFrame from = (TLColorKeyFrame)FKeyFrames.FindLast(delegate(TLBaseKeyFrame k) { return(k.Time <= CurrentTime); });
                TLColorKeyFrame to   = (TLColorKeyFrame)FKeyFrames.Find(delegate(TLBaseKeyFrame k) { return(k.Time > CurrentTime); });

                if (from == null)
                {
                    from = to;
                }
                if (to == null)
                {
                    to = from;
                }

                /*
                 *
                 * int a1, r1, g1, b1, a2, r2, g2, b2;
                 * a1 = from.Color.A;
                 * a2 = to.Color.A;
                 * r1 = from.Color.R;
                 * r2 = to.Color.R;
                 * g1 = from.Color.G;
                 * g2 = to.Color.G;
                 * b1 = from.Color.B;
                 * b2 = to.Color.B;
                 *
                 * double tSpan, f, tCurrent;
                 * tSpan = to.Time - from.Time;
                 * tCurrent = CurrentTime - from.Time;
                 *
                 * if (tSpan == 0)
                 *      f = 0;
                 * else
                 *      f = tCurrent / tSpan;
                 *
                 * ;
                 *
                 * int a, r, g, b;
                 *
                 * a = (int) Math.Round(a2 * f + a1 * (1-f));
                 * r = (int) Math.Round(r2 * f + r1 * (1-f));
                 * g = (int) Math.Round(g2 * f + g1 * (1-f));
                 * b = (int) Math.Round(b2 * f + b1 * (1-f));
                 */

                double tSpan, f, tCurrent;
                tSpan    = to.Time - from.Time;
                tCurrent = CurrentTime - from.Time;

                if (tSpan == 0)
                {
                    f = 0;
                }
                else
                {
                    f = tCurrent / tSpan;
                }
                FOutput = VColor.LerpRGBA(from.RGBAColor, to.RGBAColor, f);
            }

            double h, s, v, a;

            VColor.RGBtoHSV(FOutput.R, FOutput.G, FOutput.B, out h, out s, out v);
            a = FOutput.A;

            OutputAsString = "H: " + h.ToString("f2") + " S: " + s.ToString("f2") + " V: " + v.ToString("f2") + " A: " + a.ToString("f2");
        }
Example #18
0
        public override byte[] DecodeFrameSync(Stream dataSource, uint width, uint height)
        {
            var compressedData = new byte[GetDataSize(width, height, BlockSize)];

            var readCount = dataSource.Read(compressedData, 0, compressedData.Length);

            if (readCount != compressedData.Length)
            {
                throw new IOException("Not enough data!");
            }

            var scanlineSize = width * BytesPerPixel;

            var frameData = new byte[scanlineSize * height];

            Parallel.ForEach(RangeEnumerable.Range(0, (int)height, 4), new ParallelOptions(), y =>
            {
                var colors  = new RGBAColor[4];
                colors[0].a = 0xFF;
                colors[1].a = 0xFF;
                colors[2].a = 0xFF;

                var offset = (int)((y / 4) * (width / 4) * BlockSize);

                for (var x = 0; x < width; x += 4, offset += BlockSize)
                {
                    var color0 = BitConverter.ToUInt16(compressedData, offset);
                    var color1 = BitConverter.ToUInt16(compressedData, offset + 2);

                    var bitmask = BitConverter.ToUInt32(compressedData, offset + 4);

                    colors[0] = GetDXTColor(color0);
                    colors[1] = GetDXTColor(color1);

                    if (color0 > color1)
                    {
                        // Four-color block: derive the other two colors.
                        // 00 = color_0, 01 = color_1, 10 = color_2, 11 = color_3
                        // These 2-bit codes correspond to the 2-bit fields
                        // stored in the 64-bit block.
                        colors[2].b = (byte)((2 * colors[0].b + colors[1].b + 1) / 3);
                        colors[2].g = (byte)((2 * colors[0].g + colors[1].g + 1) / 3);
                        colors[2].r = (byte)((2 * colors[0].r + colors[1].r + 1) / 3);
                        //colours[2].a = 0xFF;

                        colors[3].b = (byte)((colors[0].b + 2 * colors[1].b + 1) / 3);
                        colors[3].g = (byte)((colors[0].g + 2 * colors[1].g + 1) / 3);
                        colors[3].r = (byte)((colors[0].r + 2 * colors[1].r + 1) / 3);
                        colors[3].a = 0xFF;
                    }
                    else
                    {
                        // Three-color block: derive the other color.
                        // 00 = color_0,  01 = color_1,  10 = color_2,
                        // 11 = transparent.
                        // These 2-bit codes correspond to the 2-bit fields
                        // stored in the 64-bit block.
                        colors[2].b = (byte)((colors[0].b + colors[1].b) / 2);
                        colors[2].g = (byte)((colors[0].g + colors[1].g) / 2);
                        colors[2].r = (byte)((colors[0].r + colors[1].r) / 2);
                        //colours[2].a = 0xFF;

                        colors[3].b = (byte)((colors[0].b + 2 * colors[1].b + 1) / 3);
                        colors[3].g = (byte)((colors[0].g + 2 * colors[1].g + 1) / 3);
                        colors[3].r = (byte)((colors[0].r + 2 * colors[1].r + 1) / 3);
                        colors[3].a = 0x00;
                    }

                    var k = 0;
                    for (var j = 0; j < 4; j++)
                    {
                        for (var i = 0; i < 4; i++, k++)
                        {
                            // Complicated way of saying get the two bits at index k * 2 in bitmask
                            var select = (uint)((bitmask & (0x03 << k * 2)) >> k * 2);
                            var col    = colors[select];

                            if (((x + i) >= width) || ((y + j) >= height))
                            {
                                continue;
                            }

                            var dataOffset            = (y + j) * scanlineSize + (x + i) * BytesPerPixel;
                            frameData[dataOffset + 0] = col.b;
                            frameData[dataOffset + 1] = col.g;
                            frameData[dataOffset + 2] = col.r;
                            frameData[dataOffset + 3] = col.a;
                        }
                    }
                }
            });

            return(frameData);
        }
Example #19
0
        public override async Task <byte[]> DecodeFrame(Stream dataSource, uint width, uint height)
        {
            var compressedData = new byte[GetDataSize(width, height, BlockSize)];

            var readCount = await dataSource.ReadAsync(compressedData, 0, compressedData.Length);

            if (readCount != compressedData.Length)
            {
                throw new IOException("Not enough data!");
            }

            var scanlineSize = width * BytesPerPixel;

            var frameData = new byte[scanlineSize * height];

            Parallel.ForEach(RangeEnumerable.Range(0, (int)width, 4), new ParallelOptions(), y =>
            {
                var colors = new RGBAColor[4];

                var offset = (int)((y / 4) * (width / 4) * BlockSize);

                for (var x = 0; x < width; x += 4, offset += BlockSize)
                {
                    var color0 = BitConverter.ToUInt16(compressedData, offset + 8);
                    var color1 = BitConverter.ToUInt16(compressedData, offset + 10);

                    var bitmask = BitConverter.ToUInt32(compressedData, offset + 12);

                    colors[0] = GetDXTColor(color0);
                    colors[1] = GetDXTColor(color1);

                    colors[2].b = (byte)((2 * colors[0].b + colors[1].b + 1) / 3);
                    colors[2].g = (byte)((2 * colors[0].g + colors[1].g + 1) / 3);
                    colors[2].r = (byte)((2 * colors[0].r + colors[1].r + 1) / 3);

                    colors[3].b = (byte)((colors[0].b + 2 * colors[1].b + 1) / 3);
                    colors[3].g = (byte)((colors[0].g + 2 * colors[1].g + 1) / 3);
                    colors[3].r = (byte)((colors[0].r + 2 * colors[1].r + 1) / 3);

                    var k = 0;
                    for (var j = 0; j < 4; ++j)
                    {
                        for (var i = 0; i < 4; ++i, ++k)
                        {
                            var select  = (bitmask & (0x03 << k * 2)) >> k * 2;
                            var current = colors[select];

                            if (((x + i) >= width) || ((y + j) >= height))
                            {
                                continue;
                            }

                            var dataOffset            = (y + j) * scanlineSize + (x + i) * BytesPerPixel;
                            frameData[dataOffset + 0] = current.b;
                            frameData[dataOffset + 1] = current.g;
                            frameData[dataOffset + 2] = current.r;
                        }
                    }

                    for (var j = 0; j < 4; ++j)
                    {
                        var word = compressedData[offset + 2 * j] + 256 * compressedData[offset + 2 * j + 1];
                        for (var i = 0; i < 4; ++i)
                        {
                            if (((x + i) < width) && ((y + j) < height))
                            {
                                var dataOffset        = (y + j) * scanlineSize + (x + i) * BytesPerPixel + 3;
                                frameData[dataOffset] = (byte)(word & 0x0F);
                                frameData[dataOffset] = (byte)(frameData[dataOffset] | (frameData[dataOffset] << 4));
                            }

                            word >>= 4;
                        }
                    }
                }
            });

            return(frameData);
        }
Example #20
0
 public TriggerEvent(MpqFileStream stream)
 {
     I0 = stream.ReadValueS32();
     TriggerConditions = new TriggerConditions(stream);
     I1 = stream.ReadValueS32();
     SNOHandle = new SNOHandle(stream);
     I2 = stream.ReadValueS32();
     I3 = stream.ReadValueS32();
     RuneType = stream.ReadValueS32();
     UseRuneType = stream.ReadValueS32();
     HardPointLinks = new HardPointLink[2];
     HardPointLinks[0] = new HardPointLink(stream);
     HardPointLinks[1] = new HardPointLink(stream);
     this.LookLink = stream.ReadString(64, true);
     this.ConstraintLink = stream.ReadString(64, true);
     I4 = stream.ReadValueS32();
     F0 = stream.ReadValueF32();
     I5 = stream.ReadValueS32();
     I6 = stream.ReadValueS32();
     I7 = stream.ReadValueS32();
     I8 = stream.ReadValueS32();
     I9 = stream.ReadValueS32();
     F1 = stream.ReadValueF32();
     F2 = stream.ReadValueF32();
     I10 = stream.ReadValueS32();
     F3 = stream.ReadValueF32();
     I11 = stream.ReadValueS32();
     Velocity = stream.ReadValueF32();
     I12 = stream.ReadValueS32();
     Ticks1 = stream.ReadValueS32();
     Color1 = new RGBAColor(stream);
     I14 = stream.ReadValueS32();
     Color2 = new RGBAColor(stream);
     I15 = stream.ReadValueS32();
 }
Example #21
0
        public override byte[] DecodeFrameSync(Stream dataSource, uint width, uint height)
        {
            var compressedData = new byte[GetDataSize(width, height, BlockSize)];

            var readCount = dataSource.Read(compressedData, 0, compressedData.Length);

            if (readCount != compressedData.Length)
            {
                throw new IOException("Not enough data!");
            }

            var scanlineSize = width * BytesPerPixel;

            var frameData = new byte[scanlineSize * height];

            Parallel.ForEach(RangeEnumerable.Range(0, (int)width, 4), new ParallelOptions(), y =>
            {
                var colors = new RGBAColor[4];
                var alphas = new byte[8];

                var offset = (int)((y / 4) * (width / 4) * BlockSize);

                for (var x = 0; x < width; x += 4, offset += BlockSize)
                {
                    alphas[0]          = compressedData[offset];
                    alphas[1]          = compressedData[offset + 1];
                    var alphamaskIndex = offset + 2;

                    colors[0] = GetDXTColor(BitConverter.ToUInt16(compressedData, offset + 8));
                    colors[1] = GetDXTColor(BitConverter.ToUInt16(compressedData, offset + 10));

                    var bitmask = BitConverter.ToUInt32(compressedData, offset + 12);

                    colors[2].b = (byte)((2 * colors[0].b + colors[1].b + 1) / 3);
                    colors[2].g = (byte)((2 * colors[0].g + colors[1].g + 1) / 3);
                    colors[2].r = (byte)((2 * colors[0].r + colors[1].r + 1) / 3);

                    colors[3].b = (byte)((colors[0].b + 2 * colors[1].b + 1) / 3);
                    colors[3].g = (byte)((colors[0].g + 2 * colors[1].g + 1) / 3);
                    colors[3].r = (byte)((colors[0].r + 2 * colors[1].r + 1) / 3);

                    var k = 0;
                    for (var j = 0; j < 4; ++j)
                    {
                        for (var i = 0; i < 4; ++i, ++k)
                        {
                            var select = (bitmask & (0x03 << k * 2)) >> k * 2;
                            var col    = colors[select];

                            // only put pixels out < width or height
                            if (((x + i) >= width) || ((y + j) >= height))
                            {
                                continue;
                            }

                            var dataOffset            = (y + j) * scanlineSize + (x + i) * BytesPerPixel;
                            frameData[dataOffset + 0] = col.b;
                            frameData[dataOffset + 1] = col.g;
                            frameData[dataOffset + 2] = col.r;
                        }
                    }

                    // 8-alpha or 6-alpha block?
                    if (alphas[0] > alphas[1])
                    {
                        // 8-alpha block:  derive the other six alphas.
                        // Bit code 000 = alpha_0, 001 = alpha_1, others are interpolated.
                        alphas[2] = (byte)((6 * alphas[0] + 1 * alphas[1] + 3) / 7); // bit code 010
                        alphas[3] = (byte)((5 * alphas[0] + 2 * alphas[1] + 3) / 7); // bit code 011
                        alphas[4] = (byte)((4 * alphas[0] + 3 * alphas[1] + 3) / 7); // bit code 100
                        alphas[5] = (byte)((3 * alphas[0] + 4 * alphas[1] + 3) / 7); // bit code 101
                        alphas[6] = (byte)((2 * alphas[0] + 5 * alphas[1] + 3) / 7); // bit code 110
                        alphas[7] = (byte)((1 * alphas[0] + 6 * alphas[1] + 3) / 7); // bit code 111
                    }
                    else
                    {
                        // 6-alpha block.
                        // Bit code 000 = alpha_0, 001 = alpha_1, others are interpolated.
                        alphas[2] = (byte)((4 * alphas[0] + 1 * alphas[1] + 2) / 5); // Bit code 010
                        alphas[3] = (byte)((3 * alphas[0] + 2 * alphas[1] + 2) / 5); // Bit code 011
                        alphas[4] = (byte)((2 * alphas[0] + 3 * alphas[1] + 2) / 5); // Bit code 100
                        alphas[5] = (byte)((1 * alphas[0] + 4 * alphas[1] + 2) / 5); // Bit code 101
                        alphas[6] = 0x00;                                            // Bit code 110
                        alphas[7] = 0xFF;                                            // Bit code 111
                    }

                    // Note: Have to separate the next two loops,
                    //	it operates on a 6-byte system.

                    // First three bytes
                    //bits = *((ILint*)alphamask);
                    var bits = (compressedData[alphamaskIndex]) | (compressedData[alphamaskIndex + 1] << 8) |
                               (compressedData[alphamaskIndex + 2] << 16);
                    for (var j = 0; j < 2; ++j)
                    {
                        for (var i = 0; i < 4; ++i)
                        {
                            // only put pixels out < width or height
                            if (((x + i) < width) && ((y + j) < height))
                            {
                                var dataOffset        = (y + j) * scanlineSize + (x + i) * BytesPerPixel + 3;
                                frameData[dataOffset] = alphas[bits & 0x07];
                            }

                            bits >>= 3;
                        }
                    }

                    // Last three bytes
                    //bits = *((ILint*)&alphamask[3]);
                    bits = (compressedData[alphamaskIndex + 3]) | (compressedData[alphamaskIndex + 4] << 8) |
                           (compressedData[alphamaskIndex + 5] << 16);
                    for (var j = 2; j < 4; ++j)
                    {
                        for (var i = 0; i < 4; ++i)
                        {
                            // only put pixels out < width or height
                            if (((x + i) < width) && ((y + j) < height))
                            {
                                var dataOffset        = (y + j) * scanlineSize + (x + i) * BytesPerPixel + 3;
                                frameData[dataOffset] = alphas[bits & 0x07];
                            }
                            bits >>= 3;
                        }
                    }
                }
            });

            return(frameData);
        }
 public void Parse(GameBitBuffer buffer)
 {
     Field0 = new RequiredMessageHeader();
     Field0.Parse(buffer);
     Field1 = buffer.ReadInt(32);
     Field2 = buffer.ReadInt(32);
     Field3 = buffer.ReadInt(32);
     Field4 = new Vector3D();
     Field4.Parse(buffer);
     Field5 = new Vector3D();
     Field5.Parse(buffer);
     Field6 = buffer.ReadFloat32();
     Field7 = buffer.ReadFloat32();
     Field8 = buffer.ReadInt(32);
     Field9 = new RGBAColor();
     Field9.Parse(buffer);
     Field10 = buffer.ReadCharArray(128);
 }
Example #23
0
 //get rgb c# color with full alpha
 protected static Color GetRGB(RGBAColor c)
 {
     return(Color.FromArgb(255, (int)(c.R * 255), (int)(c.G * 255), (int)(c.B * 255)));
 }
Example #24
0
        protected override void SetSlice(int index, Color4 value)
        {
            var dst = new RGBAColor(value.Red, value.Green, value.Blue, value.Alpha);

            FColorConfig.SetColor(index, dst);
        }
 public void Parse(GameBitBuffer buffer)
 {
     Field0 = new DT_VARIABLEARRAY();
     Field0.Parse(buffer);
     serServerData = new SerializeData();
     serServerData.Parse(buffer);
     Field2 = buffer.ReadInt(32);
     Field3 = new DT_VARIABLEARRAY();
     Field3.Parse(buffer);
     serStartLocationNames = new SerializeData();
     serStartLocationNames.Parse(buffer);
     Field5 = buffer.ReadFloat32();
     Field6 = buffer.ReadFloat32();
     Field7 = buffer.ReadFloat32();
     Field8 = buffer.ReadFloat32();
     Field9 = new RGBAColor[400];
     for(int i = 0;i < _Field9.Length;i++)
     {
         _Field9[i] = new RGBAColor();
         _Field9[i].Parse(buffer);
     }
     Field10 = buffer.ReadInt(32);
     Field11 = buffer.ReadFloat32();
     Field12 = buffer.ReadInt(32);
     Field13 = buffer.ReadFloat32();
     Field14 = buffer.ReadFloat32();
     Field15 = buffer.ReadInt(32);
     Field16 = buffer.ReadInt(32);
     Field17 = buffer.ReadFloat32();
     Field18 = buffer.ReadFloat32();
     Field19 = buffer.ReadFloat32();
     Field20 = buffer.ReadInt(32);
     Field21 = new int[4];
     for(int i = 0;i < _Field21.Length;i++) _Field21[i] = buffer.ReadInt(32);
     Field22 = new BannerParams();
     Field22.Parse(buffer);
     Field23 = buffer.ReadInt(32);
     Field24 = buffer.ReadInt(32);
     Field25 = buffer.ReadInt(32);
     Field26 = buffer.ReadInt(32);
     Field27 = buffer.ReadFloat32();
     Field28 = buffer.ReadFloat32();
     Field29 = buffer.ReadFloat32();
     Field30 = buffer.ReadFloat32();
     Field31 = buffer.ReadFloat32();
     Field32 = buffer.ReadFloat32();
     Field33 = buffer.ReadFloat32();
     Field34 = buffer.ReadFloat32();
 }
Example #26
0
    public override Bitmap Load(QOIFHeader header, BinaryReader rd)
    {
        Bitmap bitmap = new(header.Width, header.Height, PixelFormat.Format32bppArgb);

        RGBAColor[] indexed   = new RGBAColor[64];
        RGBAColor   previous  = RGBAColor.Black;
        int         end_match = 0;

#if DEBUG_LOG
        StringBuilder sb = new StringBuilder().AppendLine(header.ToString()).AppendLine("DECODING");
#endif
        bitmap.LockRGBAPixels((ptr, w, h) =>
        {
            int index = 0;
#if DEBUG_LOG
            void set_pixel(RGBAColor color, string log)
#else
            void set_pixel(RGBAColor color)
#endif
            {
                if (index < w * h)
                {
                    int cache = GetIndex(color);
#if DEBUG_LOG
                    sb.AppendLine($"I={index,6} X={index % w,5} Y={index / w,5} P={previous,12} C={color,12} (CH={cache,2}) {log}");
#endif
                    indexed[cache] = color;
                    ptr[index++]   = color;

                    if (previous != color)
                    {
                        previous = color;
                    }
                }
#if DEBUG_LOG
                else
                {
                    sb.AppendLine($" <<<< index {index} >= {w}x{h} = {w * h} >>>>");
                }
#endif
            }

            try
            {
                while (index < w * h && end_match < END.Length && rd.ReadByte() is byte @byte)
                {
                    if (@byte is TAG_OP_RGB or TAG_OP_RGBA)
                    {
                        RGBAColor color = new(
                            rd.ReadByte(),
                            rd.ReadByte(),
                            rd.ReadByte()
                            );

                        if (@byte is TAG_OP_RGBA)
                        {
                            color.A = rd.ReadByte();
                        }
#if DEBUG_LOG
                        set_pixel(color, "EXPLICIT");
#else
                        set_pixel(color);
#endif
                    }
                    else
                    {
                        int op    = @byte & MASK_TAG2;
                        byte data = (byte)(@byte & ~MASK_TAG2);

                        if (op is TAG_OP_INDEX)
                        {
#if DEBUG_LOG
                            set_pixel(indexed[data], $"INDEXED  {@byte:x2} I={data}");
#else
                            set_pixel(indexed[data]);
#endif
                            if (@byte == END[end_match])
                            {
                                ++end_match;
                            }
                            else
                            {
                                end_match = 0;
                            }
                        }
                        else if (op is TAG_OP_DIFF)
                        {
                            int dr = (@byte & MASK_DIFF_R) >> SHIFT_DIFF_R;
                            int dg = (@byte & MASK_DIFF_G) >> SHIFT_DIFF_G;
                            int db = @byte & MASK_DIFF_B;

                            RGBAColor color = ComputeFrom2BitDistance(previous, dr, dg, db);
#if DEBUG_LOG
                            set_pixel(color, $"2BITDIFF {@byte:x2} ({dr} {dg} {db})");
#else
                            set_pixel(color);
#endif
                        }
                        else if (op is TAG_OP_LUMA)
                        {
                            @byte = rd.ReadByte();

                            int drg         = (@byte & MASK_LUMA_RG) >> SHIFT_LUMA_RG;
                            int dbg         = @byte & MASK_LUMA_BG;
                            RGBAColor color = ComputeFromLuma(previous, 6, 4, drg, data, dbg);
#if DEBUG_LOG
                            set_pixel(color, $"LUMADIFF {op | data:x2}{@byte:x2} ({data} {drg} {dbg})");
#else
                            set_pixel(color);
#endif
                        }
                        else if (op is TAG_OP_RUN)
                        {
                            for (int i = 0, c = data + 1; i < c && index < w * h; ++i)
#if DEBUG_LOG
                            { set_pixel(previous, $"RUN {@byte:x2} R={data + 1}"); }
#else
                            { set_pixel(previous); }
#endif
                        }
#if DEBUG_LOG
                        else
                        {
                            sb.AppendLine($" <<<< UNKNOWN INSTRUCTION {@byte:x2} >>>>");
                        }
#endif
                    }
                }
            }
 public void Parse(GameBitBuffer buffer)
 {
     Field0 = new RGBAColor[2];
     for(int i = 0;i < _Field0.Length;i++)
     {
         _Field0[i] = new RGBAColor();
         _Field0[i].Parse(buffer);
     }
     Field1 = buffer.ReadCharArray(64);
     Field2 = buffer.ReadInt(32);
     Field3 = buffer.ReadInt(32);
 }
Example #28
0
        public BMP(string fileName)
        {
            FileStream   stream = File.OpenRead(fileName);
            BinaryReader reader = new BinaryReader(stream);

            byte[] header     = reader.ReadBytes(14);
            string headerType = "" + (char)header[0] + (char)header[1];
            ulong  fileSize   = GetULongFromBytesLE(header, 2);
            uint   reserved1  = GetUIntFromBytesLE(header, 6);
            uint   reserved2  = GetUIntFromBytesLE(header, 8);
            ulong  dataOffset = GetULongFromBytesLE(header, 10);

            this.BMPHeader = new BMP.Header(headerType, fileSize, reserved1, reserved2, dataOffset);

            byte[] dibHeaderSizeBytes = reader.ReadBytes(4);
            ulong  dibHeaderSize      = GetULongFromBytesLE(dibHeaderSizeBytes, 0);

            int[] windowsDIBSizes = { 40, 52, 56, 108, 124 };
            if (windowsDIBSizes.Contains((int)dibHeaderSize))
            {
                byte[] dibBytes          = reader.ReadBytes(36);
                ulong  width             = GetULongFromBytesLE(dibBytes, 0);
                ulong  height            = GetULongFromBytesLE(dibBytes, 4);
                uint   colorPlanes       = GetUIntFromBytesLE(dibBytes, 8);
                uint   bpp               = GetUIntFromBytesLE(dibBytes, 10);
                ulong  compressionMethod = GetULongFromBytesLE(dibBytes, 12);
                ulong  imageSize         = GetULongFromBytesLE(dibBytes, 16);
                ulong  horizontalPPM     = GetULongFromBytesLE(dibBytes, 20);
                ulong  verticalPPM       = GetULongFromBytesLE(dibBytes, 24);
                ulong  numberColors      = GetULongFromBytesLE(dibBytes, 28);
                ulong  importantColors   = GetULongFromBytesLE(dibBytes, 32);

                this.BMPHeader.WindowsHeader = new Header.DIBHeaderWindows()
                {
                    Bpp          = bpp, ColorPlanes = colorPlanes, CompressionMethod = compressionMethod,
                    Height       = height, HorizontalPPM = horizontalPPM, ImageSize = imageSize, ImportantColors = importantColors,
                    NumberColors = numberColors, VerticalPPM = verticalPPM, Width = width
                };
            }

            ulong extraBytesLength = dataOffset - (14 + dibHeaderSize);

            byte[] extraBytes = reader.ReadBytes((int)extraBytesLength);

            if (this.BMPHeader.WindowsHeader.Bpp == 8 && extraBytes.Length == 1024)
            {
                this.BMPHeader.Palette = new List <RGBAColor <byte> >();
                int p = 0;
                for (int z = 0; z < 256; z++)
                {
                    RGBAColor <byte> color = new RGBAColor <byte>(extraBytes[p], extraBytes[p + 1], extraBytes[p + 2], 255);
                    this.BMPHeader.Palette.Add(color);
                    p += 4;
                }
            }
            else if (this.BMPHeader.WindowsHeader.Bpp == 4 && extraBytes.Length == 64)
            {
                this.BMPHeader.Palette = new List <RGBAColor <byte> >();
                int p = 0;
                for (int z = 0; z < 16; z++)
                {
                    RGBAColor <byte> color = new RGBAColor <byte>(extraBytes[p], extraBytes[p + 1], extraBytes[p + 2], 255);
                    this.BMPHeader.Palette.Add(color);
                    p += 4;
                }
            }
            else if (this.BMPHeader.WindowsHeader.Bpp == 1 && extraBytes.Length == 8)
            {
                this.BMPHeader.Palette = new List <RGBAColor <byte> >();
                int p = 0;
                for (int z = 0; z < 2; z++)
                {
                    RGBAColor <byte> color = new RGBAColor <byte>(extraBytes[p], extraBytes[p + 1], extraBytes[p + 2], 255);
                    this.BMPHeader.Palette.Add(color);
                    p += 4;
                }
            }

            if (reader.BaseStream.Position == (long)dataOffset)
            {
                if (this.BMPHeader.WindowsHeader != null)
                {
                    if (this.BMPHeader.WindowsHeader.CompressionMethod == 0)
                    {
                        uint width   = (uint)this.BMPHeader.WindowsHeader.Width;
                        uint height  = (uint)this.BMPHeader.WindowsHeader.Height;
                        int  bpp     = (int)this.BMPHeader.WindowsHeader.Bpp;
                        int  rowSize = (int)((this.BMPHeader.WindowsHeader.Bpp * width + 31) / 32 * 4);
                        int  stride  = (int)((((width * bpp) + 31) & ~31) >> 3);

                        //int rowNumber = (int)height - 1;
                        int             rowNumber  = 0;
                        byte[]          pixelBytes = reader.ReadBytes((int)(this.BMPHeader.WindowsHeader.ImageSize));
                        RGBImage <byte> image      = new RGBImage <byte>((uint)width, (uint)height);

                        if (this.BMPHeader.WindowsHeader.Bpp >= 8)
                        {
                            uint bytesPerPixel = this.BMPHeader.WindowsHeader.Bpp / 8;
                            int  p             = 0;
                            for (uint y = 0; y < height; y++)
                            {
                                for (uint x = 0; x < width; x++)
                                {
                                    RGBAColor <byte> color = null;
                                    if (bytesPerPixel == 1)
                                    {
                                        byte r = pixelBytes[p];
                                        color = this.BMPHeader.Palette[r];
                                        p++;
                                    }
                                    else if (bytesPerPixel == 3)
                                    {
                                        byte r = pixelBytes[p];
                                        byte g = pixelBytes[p + 1];
                                        byte b = pixelBytes[p + 2];
                                        color = new RGBAColor <byte>(r, g, b, 255);
                                        p    += 3;
                                    }
                                    else if (bytesPerPixel == 4)
                                    {
                                        byte r = pixelBytes[p];
                                        byte g = pixelBytes[p + 1];
                                        byte b = pixelBytes[p + 2];
                                        byte a = pixelBytes[p + 3];
                                        color = new RGBAColor <byte>(r, g, b, a);
                                        p    += 4;
                                    }
                                    else
                                    {
                                        color = new RGBAColor <byte>(0, 0, 0, 0);
                                    }
                                    image.Colors[x, rowNumber] = color;
                                }
                                rowNumber++;
                                p = (int)y * stride;
                            }
                        }
                        else if (this.BMPHeader.WindowsHeader.Bpp == 4)
                        {
                            int p = 0;
                            for (uint y = 0; y < height; y++)
                            {
                                for (uint x = 0; x < width; x += 2)
                                {
                                    byte             r      = (byte)(pixelBytes[p] & 0xF);
                                    byte             r2     = (byte)(pixelBytes[p] >> 4);
                                    RGBAColor <byte> color  = null;
                                    RGBAColor <byte> color2 = null;
                                    color  = this.BMPHeader.Palette[r];
                                    color2 = this.BMPHeader.Palette[r2];
                                    p++;
                                    image.Colors[x, rowNumber] = color;
                                    if (x + 1 < width)
                                    {
                                        image.Colors[x + 1, rowNumber] = color2;
                                    }
                                }
                                rowNumber++;
                                p = (int)y * stride;
                            }
                        }
                        else if (this.BMPHeader.WindowsHeader.Bpp == 1)
                        {
                            int p = 0;
                            for (uint y = 0; y < height; y++)
                            {
                                for (uint x = 0; x < width; x += 8)
                                {
                                    byte[]             pixels = new byte[8];
                                    RGBAColor <byte>[] color  = new RGBAColor <byte> [8];
                                    for (int c = 0; c < 8; c++)
                                    {
                                        pixels[c] = (byte)((pixelBytes[p] >> c) & 0x1);
                                        if (x + c < width)
                                        {
                                            color[c] = this.BMPHeader.Palette[pixels[c]];
                                            image.Colors[x + c, rowNumber] = color[c];
                                        }
                                    }
                                    p++;
                                }
                                rowNumber++;
                                p = (int)y * stride;
                            }
                        }
                        else
                        {
                        }
                        this.Image = image;
                    }
                }
            }

            reader.Close();
            stream.Close();
        }
 public void Parse(GameBitBuffer buffer)
 {
     Field0 = new RGBAColor();
     Field0.Parse(buffer);
     Field1 = new PostFXParams();
     Field1.Parse(buffer);
     Field2 = buffer.ReadInt(32);
     Field3 = buffer.ReadInt(32);
     Field4 = new UberMaterial();
     Field4.Parse(buffer);
     snoMusic = buffer.ReadInt(32);
     snoCombatMusic = buffer.ReadInt(32);
     snoAmbient = buffer.ReadInt(32);
     snoReverb = buffer.ReadInt(32);
     snoWeather = buffer.ReadInt(32);
     snoIrradianceTex = buffer.ReadInt(32);
     snoIrradianceTexDead = buffer.ReadInt(32);
 }
Example #30
0
        public void AddPenLine(Position from, Position to, double thickness, RGBAColor color)
        {
            var penLine = new PenLineViewModel(this.WhenAnyValue(p => p.SceneBounds), from, to, thickness, color);

            PenLines.Add(penLine);
        }
 public void Parse(GameBitBuffer buffer)
 {
     Field0 = new RGBAColor();
     Field0.Parse(buffer);
     Field1 = new RGBAColor();
     Field1.Parse(buffer);
     Field2 = buffer.ReadFloat32();
 }
Example #32
0
        public Globals(MpqFile file)
        {
            var stream = file.Open();
            this.Header = new Header(stream);
            stream.Position += 8;
            this.ServerData = stream.ReadSerializedData<GlobalServerData>();

            stream.Position += 4;
            this.I0 = stream.ReadValueS32(); //32
            stream.Position += 12;
            this.StartLocationNames = new Dictionary<int, FileFormats.StartLocationName>();
            foreach (var startLocation in stream.ReadSerializedData<StartLocationName>())
                StartLocationNames.Add(startLocation.I0, startLocation);

            this.F0 = stream.ReadValueF32(); //56
            this.F1 = stream.ReadValueF32(); //60
            this.F2 = stream.ReadValueF32(); //64
            this.F3 = stream.ReadValueF32(); //68

            Colors = new RGBAColor[400]; //72
            for (int i = 0; i < 400; i++)
                Colors[i] = new RGBAColor(stream);

            this.I1 = stream.ReadValueS32(); //1672
            this.F4 = stream.ReadValueF32(); //1676
            this.I2 = stream.ReadValueS32(); //1680
            this.F5 = stream.ReadValueF32(); //1684
            this.F6 = stream.ReadValueF32(); //1688
            this.I3 = stream.ReadValueS32(); //1692
            this.I4 = stream.ReadValueS32(); //1696
            this.F7 = stream.ReadValueF32(); //1700
            this.F8 = stream.ReadValueF32(); //1704
            this.F9 = stream.ReadValueF32(); //1708
            this.I5 = stream.ReadValueS32(); //1712
            this.I6 = new int[4]; //1716
            for (int i = 0; i < 4; i++)
                this.I6[i] = stream.ReadValueS32();
            stream.Position += 4;
            this.BannerParams = new BannerParams(stream); //1736
            this.I7 = stream.ReadValueS32(); //1968
            this.I8 = stream.ReadValueS32(); //1972
            this.I9 = stream.ReadValueS32(); //1976
            this.I10 = stream.ReadValueS32(); //1980
            this.F10 = stream.ReadValueF32(); //1984
            this.F11 = stream.ReadValueF32(); //1988
            this.F12 = stream.ReadValueF32(); //1992
            this.F13 = stream.ReadValueF32(); //1996
            this.F14 = stream.ReadValueF32(); //2000
            stream.Close();
        }
 public void Parse(GameBitBuffer buffer)
 {
     Field0 = buffer.ReadInt(32);
     Field1 = new TriggerConditions();
     Field1.Parse(buffer);
     Field2 = buffer.ReadInt(32);
     Field3 = new SNOName();
     Field3.Parse(buffer);
     Field4 = buffer.ReadInt(32);
     Field5 = buffer.ReadInt(32);
     eRuneType = buffer.ReadInt(32);
     bUseRuneType = buffer.ReadInt(32);
     Field8 = new HardpointLink[2];
     for(int i = 0;i < _Field8.Length;i++)
     {
         _Field8[i] = new HardpointLink();
         _Field8[i].Parse(buffer);
     }
     Field9 = new LookLink();
     Field9.Parse(buffer);
     Field10 = new ConstraintLink();
     Field10.Parse(buffer);
     Field11 = buffer.ReadInt(32);
     Field12 = buffer.ReadFloat32();
     Field13 = buffer.ReadInt(32);
     Field14 = buffer.ReadInt(32);
     Field15 = buffer.ReadInt(32);
     Field16 = buffer.ReadInt(32);
     Field17 = buffer.ReadInt(32);
     Field18 = buffer.ReadFloat32();
     Field19 = buffer.ReadFloat32();
     Field20 = buffer.ReadInt(32);
     Field21 = buffer.ReadFloat32();
     Field22 = buffer.ReadInt(32);
     Field23 = buffer.ReadFloat32();
     Field24 = buffer.ReadInt(32);
     Field25 = buffer.ReadInt(32);
     Field26 = new RGBAColor();
     Field26.Parse(buffer);
     Field27 = buffer.ReadInt(32);
     Field28 = new RGBAColor();
     Field28.Parse(buffer);
     Field29 = buffer.ReadInt(32);
 }
Example #34
0
        //update transform
        public virtual void UpdateTransform(Matrix4x4 Transform,
                                            Vector2D Count,
                                            Vector2D Size,
                                            RGBAColor Col,
                                            RGBAColor Over,
                                            RGBAColor Active)

        {
            //copy colors
            ColNorm   = Col;
            ColOver   = Over;
            ColActive = Active;

            //get counts
            int countX     = VMath.Clamp((int)Math.Round(Count.x), 1, 1000);
            int countY     = VMath.Clamp((int)Math.Round(Count.y), 1, 1000);
            int countTotal = countX * countY;

            //calculate controller space
            Matrix4x4 size            = VMath.Scale(Size.x / countX, Size.y / countY, 1);
            Matrix4x4 controllerSpace = Transform;

            //create controllers?
            if (countTotal != FControllers.Length)
            {
                //store old controllers
                T[] temp = FControllers;

                //make new array
                FControllers = new T[countTotal];
                for (int i = 0; i < countTotal; i++)
                {
                    FControllers[i] = new T();

                    //copy data from old array
                    FControllers[i].CopyFrom(temp[i % temp.Length]);
                }
            }

            int slice = 0;

            for (int i = 0; i < countY; i++)
            {
                for (int j = 0; j < countX; j++)
                {
                    //get current controller
                    BasicGui2dController b = FControllers[slice];

                    //calc position in controller space
                    double posX = ((j + 0.5) / countX) - 0.5;
                    double posY = 0.5 - ((i + 0.5) / countY);

                    //build particular controller space
                    b.Transform    = size * VMath.Translate(posX, posY, 0) * controllerSpace;
                    b.InvTransform = !b.Transform;

                    if (b is RotarySlider)
                    {
                        b.Transform = VMath.Scale(-1, 1, 1) * VMath.RotateZ(0.25 * VMath.CycToRad) * b.Transform;
                    }

                    slice++;
                }
            }
        }
 public void Parse(GameBitBuffer buffer)
 {
     Field0 = buffer.ReadCharArray(64);
     Field1 = new RGBAColor();
     Field1.Parse(buffer);
 }
 public ConstantColor(RGBAColor color) => Color = color;
 public void Parse(GameBitBuffer buffer)
 {
     Field0 = buffer.ReadInt(32);
     Field1 = buffer.ReadInt(32);
     Field2 = buffer.ReadInt(32);
     Field3 = buffer.ReadFloat32();
     Field4 = buffer.ReadFloat32();
     Field5 = buffer.ReadInt(32);
     Field6 = buffer.ReadInt(32);
     Field7 = buffer.ReadInt(32);
     Field8 = buffer.ReadInt(32);
     Field9 = buffer.ReadInt(32);
     Field10 = buffer.ReadInt(32);
     Field11 = buffer.ReadInt(32);
     Field12 = buffer.ReadInt(32);
     Field13 = (byte)buffer.ReadInt(8);
     Field14 = buffer.ReadInt(32);
     Field15 = buffer.ReadInt(32);
     Field16 = buffer.ReadInt(32);
     Field17 = buffer.ReadInt(32);
     Field18 = buffer.ReadInt(32);
     Field19 = buffer.ReadInt(32);
     Field20 = buffer.ReadInt(32);
     Field21 = buffer.ReadInt(32);
     Field22 = new RGBAColor();
     Field22.Parse(buffer);
 }
Example #38
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        unsafe public void Evaluate(int SpreadMax)
        {
            if (!ldRunning)
            {
                return;
            }
            else
            {
                PrintStatusMessage("");
            }

            double    tmp;
            double *  px, py;
            int       v, countx, county;
            int       frameOffset = 0;
            int       pointCount  = 0;
            RGBAColor color;

            int[] frames = new int[FFrameIn.SliceCount];

            for (int i = 0; i < frames.Length; i++)
            {
                FFrameIn.GetValue(i, out tmp);
                frames[i] = VMath.Zmod((int)tmp, ldMaxFrames);
            }

            FDoWriteIn.GetValue(0, out tmp);
            if (tmp > 0)
            {
                pointCount = Math.Max(Math.Max(FXIn.SliceCount, FYIn.SliceCount), FColorIn.SliceCount);

                // Setup a mapping of point and its special flags.
                pointFlagMap.Clear();
                int pointId;
                for (int j = 0; j < FCornerIn.SliceCount; j++)
                {
                    FCornerIn.GetValue(j, out tmp);
                    pointId = VMath.Zmod((int)tmp, pointCount);
                    if (pointFlagMap.ContainsKey(pointId))
                    {
                        pointFlagMap[pointId] |= FLAG_CORNER;
                    }
                    else
                    {
                        pointFlagMap[pointId] = FLAG_CORNER;
                    }
                }
                for (int j = 0; j < FTravelBlankIn.SliceCount; j++)
                {
                    FTravelBlankIn.GetValue(j, out tmp);
                    pointId = VMath.Zmod((int)tmp, pointCount);
                    if (pointFlagMap.ContainsKey(pointId))
                    {
                        pointFlagMap[pointId] |= FLAG_TRAVELBLANK;
                    }
                    else
                    {
                        pointFlagMap[pointId] = FLAG_TRAVELBLANK;
                    }
                }

                for (int j = 0; j < frames.Length; j++)
                {
                    LD.SetWorkingFrame(frames[j]);

                    // Get the frame size for this frame
                    FFrameSizeIn.GetValue(j, out tmp);
                    int frameSize = (int)tmp;
                    if (frameSize < 0)
                    {
                        frameSize = pointCount / Math.Abs(frameSize);
                    }
                    if (frameSize > pointBuffer.Length)
                    {
                        PrintStatusMessage("Too many points. Maximum number of points for each frame is: " + pointBuffer.Length);
                        frameSize = pointBuffer.Length;
                    }

                    // Create binSize many points
                    workingFrame           = new FrameEx();
                    workingFrame.NumPoints = frameSize;

                    FXIn.GetValuePointer(out countx, out px);
                    FYIn.GetValuePointer(out county, out py);

                    int flag;
                    for (int i = 0; i < frameSize; i++)
                    {
                        pointId = i + frameOffset;

                        pointBuffer[i] = new Point();
                        v = (int)(*(px + (pointId % countx)) * 8000);
                        pointBuffer[i].X = v;

                        v = (int)(*(py + (pointId % county)) * 8000);
                        pointBuffer[i].Y = v;

                        FColorIn.GetColor(pointId, out color);
                        //swapping r'n'b
                        var r = color.R;
                        color.R = color.B;
                        color.B = r;
                        pointBuffer[i].Color = color.Color.ToArgb();

                        if (pointFlagMap.TryGetValue(pointId, out flag))
                        {
                            if ((flag & FLAG_CORNER) > 0)
                            {
                                pointBuffer[i].VOtype = LD.PT_CORNER;
                            }
                            if ((flag & FLAG_TRAVELBLANK) > 0)
                            {
                                pointBuffer[i].VOtype |= LD.PT_TRAVELBLANK;
                                pointBuffer[i].Color   = 0;
                            }
                        }
                    }

                    // Get projection zone for this frame
                    FZoneIn.GetValue(j, out tmp);
                    workingFrame.PreferredProjectionZone = VMath.Zmod((int)(tmp - 1), 30);

                    // Is this a vector orientated frame?
                    FIsVectorFrameIn.GetValue(j, out tmp);
                    workingFrame.VectorFlag = tmp > 0 ? 1 : 0;

                    // Scan rate for this frame
                    FFrameScanRateIn.GetValue(j, out tmp);
                    workingFrame.ScanRate = (int)tmp;

                    // Set animation count
                    FAnimationCountIn.GetValue(j, out tmp);
                    workingFrame.AnimationCount = (int)tmp;

                    LD.WriteFrameFastEx(ref workingFrame, ref pointBuffer[0]);

                    frameOffset += frameSize;
                }
            }
            else
            {
                List <int> corners = new List <int>();

                for (int j = 0; j < frames.Length; j++)
                {
                    LD.SetWorkingFrame(frames[j]);

                    int numPoints = 0;
                    LD.ReadNumPoints(ref numPoints);

                    pointCount += numPoints;
                }

                FXOut.SliceCount              = pointCount;
                FYOut.SliceCount              = pointCount;
                FColorOut.SliceCount          = pointCount;
                FFrameSizeOut.SliceCount      = frames.Length;
                FFrameScanRateOut.SliceCount  = frames.Length;
                FIsVectorFrameOut.SliceCount  = frames.Length;
                FZoneOut.SliceCount           = frames.Length;
                FAnimationCountOut.SliceCount = frames.Length;

                for (int j = 0; j < frames.Length; j++)
                {
                    LD.SetWorkingFrame(frames[j]);

                    int frameSize = 0;
                    LD.ReadNumPoints(ref frameSize);
                    LD.ReadFrameEx(ref workingFrame, ref pointBuffer[0]);

                    for (int i = 0; i < frameSize; i++)
                    {
                        int slice = i + frameOffset;
                        FXOut.SetValue(slice, ((double)pointBuffer[i].X) / 8000.0);
                        FYOut.SetValue(slice, ((double)pointBuffer[i].Y) / 8000.0);
                        RGBAColor c = new RGBAColor();
                        c.Color = System.Drawing.Color.FromArgb(pointBuffer[i].Color);
                        FColorOut.SetColor(slice, c);

                        // Handle vector orientated flags
                        if ((pointBuffer[i].VOtype & LD.PT_CORNER) > 0)
                        {
                            corners.Add(slice);
                        }
                    }

                    FCornerOut.SliceCount = corners.Count;
                    for (int i = 0; i < corners.Count; i++)
                    {
                        FCornerOut.SetValue(i, corners[i]);
                    }

                    FFrameSizeOut.SetValue(j, frameSize);
                    FFrameScanRateOut.SetValue(j, workingFrame.ScanRate);
                    FIsVectorFrameOut.SetValue(j, workingFrame.VectorFlag != 0 ? 1.0 : 0.0);
                    FZoneOut.SetValue(j, workingFrame.PreferredProjectionZone + 1);
                    FAnimationCountOut.SetValue(j, workingFrame.AnimationCount);

                    frameOffset += frameSize;
                }
            }

            bool vdChanged   = PinsChanged(FVDPins);
            bool skewChanged = PinsChanged(FSkewPins);

            /*
             * bool scannerChanged = FActiveScannerIn.PinIsChanged;
             * if (scannerChanged)
             * {
             *      // Blank out all scanners
             *      LD.SetWorkingScanners(-1);
             *      LD.DisplayFrame(0);
             * }
             * int scannerFrameCount = Math.Max(frames.Length, FActiveScannerIn.SliceCount);
             */
            int scannerFrameCount = Math.Max(frames.Length, FWorkingTrackIn.SliceCount);

            for (int i = 0; i < scannerFrameCount; i++)
            {
                /*
                 * FActiveScannerIn.GetValue(i, out tmp);
                 * int scannerCode = (int) tmp;
                 * scannerCode = VMath.Clamp(scannerCode, -1, MAX_SCANNER_CODE);
                 * if (scannerCode == 0) scannerCode = 1; // 0 is illegal
                 * LD.SetWorkingScanners(scannerCode);
                 */
                FWorkingTrackIn.GetValue(i, out tmp);
                int trackCode = (int)tmp;
                LD.SetWorkingTracks(trackCode);

                LD.DisplayFrame(frames[i % frames.Length]);
                if (vdChanged)
                {
                    int[] arg = PinsAsArgumentList(FVDPins, i);
                    LD.DisplayObjectSettings(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6]);
                }
                if (skewChanged)
                {
                    int[] arg = PinsAsArgumentList(FSkewPins, i);
                    LD.DisplaySkew(4, arg[0], 0);
                }
            }

            /*
             * LD.SetWorkingScanners(-1);
             */
            LD.DisplayUpdate();
        }
 public void Parse(GameBitBuffer buffer)
 {
     Field0 = buffer.ReadInt(32);
     Field1 = new RGBAColor();
     Field1.Parse(buffer);
     Field2 = buffer.ReadFloat32();
     Field3 = buffer.ReadFloat32();
     Field4 = new RGBAColor();
     Field4.Parse(buffer);
     Field5 = buffer.ReadFloat32();
     Field6 = buffer.ReadFloat32();
     snoSunLightScene = buffer.ReadInt(32);
     snoSunLightActor = buffer.ReadInt(32);
     Field9 = buffer.ReadFloat32();
     Field10 = buffer.ReadFloat32();
     snoPlayerLightScene = buffer.ReadInt(32);
     snoPlayerLightActor = buffer.ReadInt(32);
     snoLocalPlayerHeadLight = buffer.ReadInt(32);
 }
Example #40
0
 public void GetColor(int index, out RGBAColor color)
 {
     color = Color;
 }
 public void Parse(GameBitBuffer buffer)
 {
     Field0 = new Vector3D();
     Field0.Parse(buffer);
     Field1 = new RGBAColor();
     Field1.Parse(buffer);
     Field2 = new RGBAColor[2];
     for(int i = 0;i < _Field2.Length;i++)
     {
         _Field2[i] = new RGBAColor();
         _Field2[i].Parse(buffer);
     }
     Field3 = new RGBAColor[2];
     for(int i = 0;i < _Field3.Length;i++)
     {
         _Field3[i] = new RGBAColor();
         _Field3[i].Parse(buffer);
     }
     Field4 = new RGBAColor();
     Field4.Parse(buffer);
     Field5 = new RGBAColor();
     Field5.Parse(buffer);
     Field6 = (ushort)buffer.ReadInt(16);
 }
Example #42
0
 public override void Parse(GameBitBuffer buffer)
 {
     Field0 = buffer.ReadInt(32);
     Field1 = buffer.ReadInt(32);
     Field2 = buffer.ReadInt(32);
     Field3 = new Vector3D();
     Field3.Parse(buffer);
     Field4 = new Vector3D();
     Field4.Parse(buffer);
     Field5 = buffer.ReadFloat32();
     Field6 = buffer.ReadFloat32();
     Field7 = buffer.ReadInt(32);
     Field8 = new RGBAColor();
     Field8.Parse(buffer);
     Field9 = buffer.ReadCharArray(128);
 }
Example #43
0
 public void SetBackgroundColor(RGBAColor color)
 {
     _backgroundColor = color;
 }