protected override Color ConversionFunc(Color key, List <MutableObject> entry)
        {
            var foundValue = NewValue.GetValue(entry);

            float colorH, colorS, colorV;

            ColorUtility.RGBToHSV(key, out colorH, out colorS, out colorV);

            return(ColorUtility.HsvtoRgb(colorH, colorS, foundValue));
        }
Esempio n. 2
0
        protected override MutableObject Mutate(MutableObject mutable)
        {
            foreach (var entry in Scope.GetEntries(mutable))
            {
                var hue        = Hue.GetValue(entry);
                var saturation = Saturation.GetValue(entry);
                var value      = Value.GetValue(entry);

                ColorTarget.SetValue(ColorUtility.HsvtoRgb(hue, saturation, value), entry);
            }
            return(mutable);
        }
Esempio n. 3
0
        protected override MutableObject Mutate(MutableObject mutable)
        {
            foreach (var entry in RGBColor.GetEntries(mutable))
            {
                float outH, outS, outV;
                ColorUtility.RGBToHSV(RGBColor.GetValue(entry), out outH, out outS, out outV);

                HTarget.SetValue(outH, entry);
                STarget.SetValue(outS, entry);
                VTarget.SetValue(outV, entry);
            }

            return(mutable);
        }
Esempio n. 4
0
        public override IEnumerator ReceivePayload(VisualPayload payload)
        {
            foreach (var entry in BitStream.GetEntries(payload.Data))
            {
                var bitstream  = BitStream.GetValue(entry);
                var saturation = Saturation.GetValue(entry);
                var value      = Value.GetValue(entry);

                var bitsToSample = BitsToSample.GetValue(entry);

                var hue = bitstream.ReadInt(bitsToSample) / Mathf.Pow(2f, bitsToSample);

                var newColor = ColorUtility.HsvtoRgb(hue, saturation, value);

                ColorTarget.SetValue(newColor, entry);
            }

            var iterator = Router.TransmitAll(payload);

            while (iterator.MoveNext())
            {
                yield return(null);
            }
        }
        protected override MutableObject Mutate(MutableObject mutable)
        {
            var frequencies = ByteHistogram.GetFirstValue(mutable);

            var saturation = Saturation.GetFirstValue(mutable);
            var value      = Value.GetFirstValue(mutable);

            var frequencyBands = new List <FrequencyBand>();

            var totalSize = (float)frequencies.Sum(f => f);

            var currentPosition = 0f;
            int i = 0;

            foreach (var frequency in frequencies)
            {
                frequencyBands.Add(new FrequencyBand
                {
                    Byte      = i++,
                    Color     = ColorUtility.HsvtoRgb(currentPosition / totalSize, saturation, value),
                    Start     = currentPosition / totalSize,
                    End       = (currentPosition + frequency) / totalSize,
                    Frequency = frequency
                });
                currentPosition = currentPosition + frequency;
            }

            frequencyBands.Sort((a, b) => 0 - a.Frequency.CompareTo(b.Frequency));

            var smoothGradient       = SmoothGradient.GetFirstValue(mutable);
            var numberOfPoints       = Keypoints.GetFirstValue(mutable);
            var edgeWidth            = EdgeWidth.GetFirstValue(mutable);
            var primaryColor         = PrimaryColor.GetFirstValue(mutable);
            var primaryImpactOnBands = PrimaryImpactOnBands.GetFirstValue(mutable);

            var newGradient = new ColorGradient(numberOfPoints * (smoothGradient?1:2));

            frequencyBands = frequencyBands.Take(numberOfPoints).OrderBy(f => f.Start).ToList();

            if (smoothGradient)
            {
                for (var k = 0; k < Mathf.Min(numberOfPoints, frequencyBands.Count); k++)
                {
                    {
                        newGradient.AddColorKey(new GradientColorKey(
                                                    frequencyBands[k].Color,
                                                    (frequencyBands[k].Start + frequencyBands[k].End) / 2f));
                    }
                }
            }
            else
            {
                for (var k = 1; k < Mathf.Min(numberOfPoints, frequencyBands.Count); k++)
                {
                    var k1 = frequencyBands[k - 1].Color;
                    newGradient.AddColorKey(new GradientColorKey(
                                                Color.Lerp(frequencyBands[k - 1].Color,
                                                           primaryColor, primaryImpactOnBands),
                                                frequencyBands[k - 1].Start + edgeWidth / 2f));

                    var k2 = frequencyBands[k - 1].Color;
                    newGradient.AddColorKey(new GradientColorKey(
                                                Color.Lerp(frequencyBands[k - 1].Color,
                                                           primaryColor, primaryImpactOnBands),
                                                frequencyBands[k].Start - edgeWidth / 2f));

                    if (k1 != k2)
                    {
                        throw new Exception("What?  How are these colors not matched?");
                    }
                }
            }


            HistogramGradient.SetValue(newGradient, mutable);

            return(mutable);
        }
        public override IEnumerator ReceivePayload(VisualPayload payload)
        {
            //var outOfBoundsColor = OutOfBoundsColor.GetFirstValue( payload.Data );

            var outOfBoundsReadColor  = OutOfBoundsReadColor.GetFirstValue(payload.Data);
            var outOfBoundsWriteColor = OutOfBoundsWriteColor.GetFirstValue(payload.Data);

            var allocatedAlpha = AllocationAlpha.GetFirstValue(payload.Data);

            var valueStepSize   = ValueStepSize.GetFirstValue(payload.Data);
            var allocationColor = AllocationColor.GetFirstValue(payload.Data);

            float allocH, allocS, allocV;

            ColorUtility.RGBToHSV(allocationColor, out allocH, out allocS, out allocV);


            //var readWriteDifferentiation = ReadWriteDifferentiation.GetFirstValue( payload.Data );

            foreach (var entry in TraceScope.GetEntries(payload.Data))
            {
                var memSpace = new MemorySpace();

                //var saturation = Saturation.GetValue( entry );
                //var hueStep = HueStepSize.GetValue( entry );
                //var value = Value.GetValue( entry );

                int maxIndex = MaxIndex.GetValue(entry);

                // match allocations and frees

                var allocations = new Dictionary <uint, MemorySpacePoint>();
                foreach (var allocation in AllocateScope.GetEntries(entry))
                {
                    var address = AllocateAddress.GetValue(allocation);
                    var size    = AllocateSize.GetValue(allocation);
                    var index   = AllocateIndex.GetValue(allocation);

                    var newPoint = memSpace.AddMemoryAllocation(address, size);

                    newPoint.StartIndex          = index;
                    newPoint.EndPoint.StartIndex = index;
                    newPoint.EndIndex            = maxIndex;
                    newPoint.EndPoint.EndIndex   = maxIndex;

                    allocations.Add(newPoint.Address, newPoint);
                }

                // assign the end indices of any allocates with matched frees
                foreach (var free in FreeScope.GetEntries(entry))
                {
                    var index   = FreeIndex.GetValue(free);
                    var address = FreeAddress.GetValue(free);

                    if (allocations.ContainsKey(address))
                    {
                        var matchedAllocation = allocations[address];

                        matchedAllocation.EndIndex          = index;
                        matchedAllocation.EndPoint.EndIndex = index;
                    }
                }


                // import reads to the memory space
                var readPoints = new Dictionary <int, MemorySpacePoint>();
                foreach (var read in ReadScope.GetEntries(entry))
                {
                    var address = ReadAddress.GetValue(read);
                    var size    = ReadSize.GetValue(read);
                    var index   = ReadIndex.GetValue(read);

                    var readPoint = MemorySpacePoint.GeneratePoint(address, size);
                    readPoint.AllIndices = index;


                    MemorySpacePoint containingPoint;

                    if (memSpace.IsAccessContained(readPoint, readPoint.EndPoint, out containingPoint))
                    {
                        readPoint.ContainingAllocation = containingPoint;
                    }
                    else
                    {
                        var outOfBoundsAlloc = memSpace.AddMemoryAllocation(address, size, 0, maxIndex);
                        outOfBoundsAlloc.IsOutOfBounds = true;

                        readPoint.ContainingAllocation = outOfBoundsAlloc;
                    }

                    readPoints.Add(index, readPoint);
                }

                // import Writes to the memory space
                var writePoints = new Dictionary <int, MemorySpacePoint>();
                foreach (var write in WriteScope.GetEntries(entry))
                {
                    var address = WriteAddress.GetValue(write);
                    var size    = WriteSize.GetValue(write);
                    var index   = WriteIndex.GetValue(write);

                    var writePoint = MemorySpacePoint.GeneratePoint(address, size);
                    writePoint.AllIndices = index;

                    MemorySpacePoint containingPoint;

                    if (memSpace.IsAccessContained(writePoint, writePoint.EndPoint, out containingPoint))
                    {
                        writePoint.ContainingAllocation = containingPoint;
                    }
                    else
                    {
                        var outOfBoundsAlloc = memSpace.AddMemoryAllocation(address, size, 0, maxIndex);
                        outOfBoundsAlloc.IsOutOfBounds = true;

                        writePoint.ContainingAllocation = outOfBoundsAlloc;
                    }

                    writePoints.Add(index, writePoint);
                }


                // generate visual space for memory allocations (include out of bounds allocations)
                memSpace.SetVisualBounding();


                // set colors for memory allocations (inclde out of bounds allocations with special color)
                //var hueRotor = HueStart.GetValue( entry );

                foreach (var allocation in memSpace.RegisteredSpace.Where(s => s.IsStart))
                {
                    Color nextColor = ColorUtility.HsvtoRgb(allocH, allocS, allocV);

                    allocV = .3f + (allocV + valueStepSize) % .7f;

                    /*(allocation.IsOutOfBounds)?
                     * outOfBoundsColor:
                     * ColorUtility.HsvtoRgb(hueRotor, saturation,
                     * value);*/

                    nextColor.a = allocatedAlpha;

                    //if ( !allocation.IsOutOfBounds )
                    //    hueRotor += hueStep;

                    allocation.VisualColor = nextColor;
                }

                // set colors and visual locations for all reads
                foreach (var read in readPoints)
                {
                    if (read.Value.ContainingAllocation == null)
                    {
                        Debug.LogError("Danger will robinson!  Danger!");
                    }
                    read.Value.VisualColor =
                        outOfBoundsReadColor;
                    //           read.Value.ContainingAllocation.VisualColor == outOfBoundsColor?
                    //           outOfBoundsReadColor:
                    //           Color.Lerp(
                    //           read.Value.ContainingAllocation.VisualColor,
                    //       Color.white, readWriteDifferentiation);

                    //read.Value.VisualStart = memSpace.AddressToVisualPosition( read.Value.Address );
                    //read.Value.VisualEnd = memSpace.AddressToVisualPosition( read.Value.EndPoint.Address );
                    read.Value.ComputeVisualPositionsFromContainer();
                }


                // set colors and visual locations for all writes
                foreach (var write in writePoints)
                {
                    if (write.Value.ContainingAllocation == null)
                    {
                        Debug.LogError("Danger will robinson!  Danger!");
                    }
                    write.Value.VisualColor =
                        outOfBoundsWriteColor;
                    //       write.Value.ContainingAllocation.VisualColor == outOfBoundsColor?
                    //       outOfBoundsWriteColor:
                    //       Color.Lerp(
                    //       write.Value.ContainingAllocation.VisualColor,
                    //   Color.black, readWriteDifferentiation);

                    write.Value.ComputeVisualPositionsFromContainer();

                    //write.Value.VisualStart = memSpace.AddressToVisualPosition(write.Value.Address);
                    //write.Value.VisualEnd = memSpace.AddressToVisualPosition(write.Value.EndPoint.Address);
                }

                // FINALLY, write this information into the corresponding targets
                foreach (var allocation in AllocateScope.GetEntries(entry))
                {
                    var targetAddress = AllocateAddress.GetValue(allocation);
                    //var targetIndex = AllocateIndex.GetValue( allocation );

                    if (!allocations.ContainsKey(targetAddress))
                    {
                        throw new Exception("Allocation address not found!");
                    }
                    var foundAllocation = allocations[targetAddress];

                    AllocateColorTarget.SetValue(foundAllocation.VisualColor, allocation);
                    AllocatePositionTarget.SetValue(foundAllocation.VisualStart, allocation);
                    AllocateSizeTarget.SetValue(foundAllocation.VisualEnd - foundAllocation.VisualStart, allocation);
                    AllocateEndIndexTarget.SetValue(foundAllocation.EndIndex, allocation);
                }

                foreach (var read in ReadScope.GetEntries(entry))
                {
                    var targetIndex = ReadIndex.GetValue(read);

                    if (!readPoints.ContainsKey(targetIndex))
                    {
                        throw new Exception("Read index not found!");
                    }
                    var foundRead = readPoints[targetIndex];

                    ReadColorTarget.SetValue(foundRead.VisualColor, read);
                    ReadPositionTarget.SetValue(foundRead.VisualStart, read);
                    ReadSizeTarget.SetValue(foundRead.VisualEnd - foundRead.VisualStart, read);
                }


                foreach (var write in WriteScope.GetEntries(entry))
                {
                    var targetIndex = WriteIndex.GetValue(write);

                    if (!writePoints.ContainsKey(targetIndex))
                    {
                        throw new Exception("Write index not found!");
                        continue;
                    }
                    var foundwrite = writePoints[targetIndex];

                    WriteColorTarget.SetValue(foundwrite.VisualColor, write);
                    WritePositionTarget.SetValue(foundwrite.VisualStart, write);
                    WriteSizeTarget.SetValue(foundwrite.VisualEnd - foundwrite.VisualStart, write);
                }


                // write grid lines
                var  gridLines    = new List <MutableObject>();
                uint priorAddress = memSpace.RegisteredSpace.First().Address;


                gridLines.Add(new MutableObject
                {
                    { "Visual Position", 0f },
                    { "Visual Weight", 1000f }
                });

                foreach (var space in memSpace.RegisteredSpace)
                {
                    if (space.IsEnd)
                    {
                        continue;
                    }
                    var newGridLine = new MutableObject
                    {
                        { "Visual Position", space.VisualStart },
                        { "Visual Weight", (float)(Mathf.Max(0, priorAddress - space.StartPoint.Address) + 1) }
                    };
                    priorAddress = space.EndPoint.Address;
                    gridLines.Add(newGridLine);
                }

                gridLines.Add(new MutableObject
                {
                    { "Visual Position", 1f },
                    { "Visual Weight", 1000f }
                });

                GridLinesTarget.SetValue(gridLines, entry);
            }


            var iterator = Router.TransmitAll(payload);

            while (iterator.MoveNext())
            {
                yield return(null);
            }
        }