Example #1
0
        public void SetupHueBrightnessGradient(float saturation = 1.0f, int accuracy = 256)
        {
            ColorBlend blendX = new ColorBlend();

            blendX.Colors = new Color[] {
                ExtMethodsSystemDrawingColor.ColorFromHSV(0.0f, saturation, 1.0f),
                ExtMethodsSystemDrawingColor.ColorFromHSV(1.0f / 6.0f, saturation, 1.0f),
                ExtMethodsSystemDrawingColor.ColorFromHSV(2.0f / 6.0f, saturation, 1.0f),
                ExtMethodsSystemDrawingColor.ColorFromHSV(3.0f / 6.0f, saturation, 1.0f),
                ExtMethodsSystemDrawingColor.ColorFromHSV(4.0f / 6.0f, saturation, 1.0f),
                ExtMethodsSystemDrawingColor.ColorFromHSV(5.0f / 6.0f, saturation, 1.0f),
                ExtMethodsSystemDrawingColor.ColorFromHSV(1.0f, saturation, 1.0f)
            };
            blendX.Positions = new float[] {
                0.0f,
                1.0f / 6.0f,
                2.0f / 6.0f,
                3.0f / 6.0f,
                4.0f / 6.0f,
                5.0f / 6.0f,
                1.0f
            };

            ColorBlend blendY = new ColorBlend();

            blendY.Colors = new Color[] {
                Color.FromArgb(0, 0, 0),
                Color.Transparent
            };
            blendY.Positions = new float[] {
                0.0f,
                1.0f
            };
            this.SetupXYGradient(blendX, blendY, accuracy);
        }
Example #2
0
        public void SetupHueSaturationGradient(float brightness = 1.0f, int accuracy = 256)
        {
            ColorBlend blendX = new ColorBlend();

            blendX.Colors = new Color[] {
                ExtMethodsSystemDrawingColor.ColorFromHSV(0.0f, 1.0f, brightness),
                ExtMethodsSystemDrawingColor.ColorFromHSV(1.0f / 6.0f, 1.0f, brightness),
                ExtMethodsSystemDrawingColor.ColorFromHSV(2.0f / 6.0f, 1.0f, brightness),
                ExtMethodsSystemDrawingColor.ColorFromHSV(3.0f / 6.0f, 1.0f, brightness),
                ExtMethodsSystemDrawingColor.ColorFromHSV(4.0f / 6.0f, 1.0f, brightness),
                ExtMethodsSystemDrawingColor.ColorFromHSV(5.0f / 6.0f, 1.0f, brightness),
                ExtMethodsSystemDrawingColor.ColorFromHSV(1.0f, 1.0f, brightness)
            };
            blendX.Positions = new float[] {
                0.0f,
                1.0f / 6.0f,
                2.0f / 6.0f,
                3.0f / 6.0f,
                4.0f / 6.0f,
                5.0f / 6.0f,
                1.0f
            };

            ColorBlend blendY = new ColorBlend();

            blendY.Colors = new Color[] {
                Color.FromArgb((int)Math.Round(255.0f * brightness), (int)Math.Round(255.0f * brightness), (int)Math.Round(255.0f * brightness)),
                Color.Transparent
            };
            blendY.Positions = new float[] {
                0.0f,
                1.0f
            };
            this.SetupXYGradient(blendX, blendY, accuracy);
        }
Example #3
0
        public override void Perform(AudioData audio, PreviewImageQuery query)
        {
            int     desiredWidth  = query.DesiredWidth;
            int     desiredHeight = query.DesiredHeight;
            int     oggHash       = audio.OggVorbisData.GetCombinedHashCode();
            int     oggLen        = audio.OggVorbisData.Length;
            PcmData pcm           = OggVorbis.LoadChunkFromMemory(audio.OggVorbisData, 500000);

            short[] sdata  = pcm.data;
            short   maxVal = 1;

            for (int i = 0; i < pcm.dataLength; i++)
            {
                maxVal = Math.Max(maxVal, Math.Abs(pcm.data[i]));
            }

            Bitmap    result        = new Bitmap(desiredWidth, desiredHeight);
            int       channelLength = pcm.dataLength / pcm.channelCount;
            int       yMid          = result.Height / 2;
            int       stepWidth     = (channelLength / (2 * result.Width)) - 1;
            const int samples       = 10;

            using (Graphics g = Graphics.FromImage(result))
            {
                Color baseColor = ExtMethodsSystemDrawingColor.ColorFromHSV(
                    (float)(oggHash % 90) * (float)(oggLen % 4) / 360.0f,
                    0.5f,
                    1f);
                Pen linePen = new Pen(Color.FromArgb(MathF.RoundToInt(255.0f / MathF.Pow((float)samples, 0.65f)), baseColor));
                g.Clear(Color.Transparent);
                for (int x = 0; x < result.Width; x++)
                {
                    float invMaxVal      = 2.0f / ((float)maxVal + (float)short.MaxValue);
                    float timePercentage = (float)x / (float)result.Width;
                    int   i = MathF.RoundToInt(timePercentage * channelLength);
                    float left;
                    float right;
                    short channel1;
                    short channel2;

                    for (int s = 0; s <= samples; s++)
                    {
                        int offset = stepWidth * s / samples;
                        channel1 = sdata[(i + offset) * pcm.channelCount + 0];
                        channel2 = sdata[(i + offset) * pcm.channelCount + 1];
                        left     = (float)Math.Abs(channel1) * invMaxVal;
                        right    = (float)Math.Abs(channel2) * invMaxVal;
                        g.DrawLine(linePen, x, yMid, x, yMid + MathF.RoundToInt(left * yMid));
                        g.DrawLine(linePen, x, yMid, x, yMid - MathF.RoundToInt(right * yMid));
                    }
                }
            }

            query.Result = result;
        }
Example #4
0
        private void UpdateColorPanelGradient()
        {
            Color tmp;

            switch (this.primAttrib)
            {
            default:
            case PrimaryAttrib.Hue:
                this.colorPanel.SetupXYGradient(
                    Color.White,
                    ExtMethodsSystemDrawingColor.ColorFromHSV(this.selColor.h, 1.0f, 1.0f),
                    Color.Black,
                    Color.Transparent);
                break;

            case PrimaryAttrib.Saturation:
                this.colorPanel.SetupHueBrightnessGradient(this.selColor.s);
                break;

            case PrimaryAttrib.Brightness:
                this.colorPanel.SetupHueSaturationGradient(this.selColor.v);
                break;

            case PrimaryAttrib.Red:
                tmp = this.selColor.ToColor();
                this.colorPanel.SetupGradient(
                    Color.FromArgb(255, tmp.R, 255, 0),
                    Color.FromArgb(255, tmp.R, 255, 255),
                    Color.FromArgb(255, tmp.R, 0, 0),
                    Color.FromArgb(255, tmp.R, 0, 255),
                    32);
                break;

            case PrimaryAttrib.Green:
                tmp = this.selColor.ToColor();
                this.colorPanel.SetupGradient(
                    Color.FromArgb(255, 255, tmp.G, 0),
                    Color.FromArgb(255, 255, tmp.G, 255),
                    Color.FromArgb(255, 0, tmp.G, 0),
                    Color.FromArgb(255, 0, tmp.G, 255),
                    32);
                break;

            case PrimaryAttrib.Blue:
                tmp = this.selColor.ToColor();
                this.colorPanel.SetupGradient(
                    Color.FromArgb(255, 255, 0, tmp.B),
                    Color.FromArgb(255, 255, 255, tmp.B),
                    Color.FromArgb(255, 0, 0, tmp.B),
                    Color.FromArgb(255, 0, 255, tmp.B),
                    32);
                break;
            }
        }
Example #5
0
        public override void Perform(AudioData audio, PreviewImageQuery query)
        {
            int desiredWidth  = query.DesiredWidth;
            int desiredHeight = query.DesiredHeight;
            int oggHash       = audio.OggVorbisData.GetCombinedHashCode();
            int oggLen        = audio.OggVorbisData.Length;

            Duality.OggVorbis.PcmData pcm = Duality.OggVorbis.OV.LoadFromMemory(audio.OggVorbisData, 1000000);             //41236992
            short[] sdata = new short[pcm.data.Length / 2];
            Buffer.BlockCopy(pcm.data, 0, sdata, 0, pcm.data.Length);

            Bitmap    result        = new Bitmap(desiredWidth, desiredHeight);
            int       channelLength = sdata.Length / pcm.channelCount;
            int       yMid          = result.Height / 2;
            int       stepWidth     = (channelLength / (2 * result.Width)) - 1;
            const int samples       = 10;

            using (Graphics g = Graphics.FromImage(result))
            {
                Color baseColor = ExtMethodsSystemDrawingColor.ColorFromHSV(
                    (float)(oggHash % 90) * (float)(oggLen % 4) / 360.0f,
                    0.5f,
                    1f);
                Pen linePen = new Pen(Color.FromArgb(MathF.RoundToInt(255.0f / MathF.Pow((float)samples, 0.65f)), baseColor));
                g.Clear(Color.Transparent);
                for (int x = 0; x < result.Width; x++)
                {
                    float timePercentage = (float)x / (float)result.Width;
                    int   i = MathF.RoundToInt(timePercentage * channelLength);
                    float left;
                    float right;
                    short channel1;
                    short channel2;

                    for (int s = 0; s <= samples; s++)
                    {
                        int offset = MathF.RoundToInt((float)stepWidth * (float)s / (float)samples);
                        channel1 = sdata[(i + offset) * pcm.channelCount + 0];
                        channel2 = sdata[(i + offset) * pcm.channelCount + 1];
                        left     = (float)Math.Abs((int)channel1) / (float)short.MaxValue;
                        right    = (float)Math.Abs((int)channel2) / (float)short.MaxValue;
                        g.DrawLine(linePen, x, yMid, x, yMid + MathF.RoundToInt(left * yMid));
                        g.DrawLine(linePen, x, yMid, x, yMid - MathF.RoundToInt(right * yMid));
                    }
                }
            }

            query.Result = result;
        }
Example #6
0
        private void UpdateColorSliderGradient()
        {
            Color tmp;

            switch (this.primAttrib)
            {
            default:
            case PrimaryAttrib.Hue:
                this.colorSlider.SetupHueGradient(/*this.selColor.GetHSVSaturation(), this.selColor.GetHSVBrightness()*/);
                break;

            case PrimaryAttrib.Saturation:
                this.colorSlider.SetupGradient(
                    ExtMethodsSystemDrawingColor.ColorFromHSV(this.selColor.h, 0.0f, this.selColor.v),
                    ExtMethodsSystemDrawingColor.ColorFromHSV(this.selColor.h, 1.0f, this.selColor.v));
                break;

            case PrimaryAttrib.Brightness:
                this.colorSlider.SetupGradient(
                    ExtMethodsSystemDrawingColor.ColorFromHSV(this.selColor.h, this.selColor.s, 0.0f),
                    ExtMethodsSystemDrawingColor.ColorFromHSV(this.selColor.h, this.selColor.s, 1.0f));
                break;

            case PrimaryAttrib.Red:
                tmp = this.selColor.ToColor();
                this.colorSlider.SetupGradient(
                    Color.FromArgb(255, 0, tmp.G, tmp.B),
                    Color.FromArgb(255, 255, tmp.G, tmp.B));
                break;

            case PrimaryAttrib.Green:
                tmp = this.selColor.ToColor();
                this.colorSlider.SetupGradient(
                    Color.FromArgb(255, tmp.R, 0, tmp.B),
                    Color.FromArgb(255, tmp.R, 255, tmp.B));
                break;

            case PrimaryAttrib.Blue:
                tmp = this.selColor.ToColor();
                this.colorSlider.SetupGradient(
                    Color.FromArgb(255, tmp.R, tmp.G, 0),
                    Color.FromArgb(255, tmp.R, tmp.G, 255));
                break;
            }
        }
        protected override void OnEditedTypeChanged()
        {
            base.OnEditedTypeChanged();

            System.Drawing.Bitmap iconBitmap = this.EditedType.GetEditorImage() as System.Drawing.Bitmap;
            ColorHsva             avgClr     = iconBitmap != null?
                                               iconBitmap.GetAverageColor().ToHsva() :
                                                   Duality.Drawing.ColorHsva.TransparentWhite;

            if (avgClr.S <= 0.05f)
            {
                avgClr = new ColorHsva(
                    0.001f * (float)(this.EditedType.Name.GetHashCode() % 1000),
                    1.0f,
                    0.5f);
            }

            this.PropertyName = this.EditedType.GetTypeCSCodeName(true);
            this.HeaderIcon   = iconBitmap;
            this.HeaderColor  = ExtMethodsSystemDrawingColor.ColorFromHSV(avgClr.H, 0.2f, 0.8f);
        }
Example #8
0
        public void SetupHueGradient(float saturation = 1.0f, float brightness = 1.0f, int accuracy = 256)
        {
            ColorBlend blend = new ColorBlend();

            blend.Colors = new Color[] {
                ExtMethodsSystemDrawingColor.ColorFromHSV(0.0f, saturation, brightness),
                ExtMethodsSystemDrawingColor.ColorFromHSV(1.0f / 6.0f, saturation, brightness),
                ExtMethodsSystemDrawingColor.ColorFromHSV(2.0f / 6.0f, saturation, brightness),
                ExtMethodsSystemDrawingColor.ColorFromHSV(3.0f / 6.0f, saturation, brightness),
                ExtMethodsSystemDrawingColor.ColorFromHSV(4.0f / 6.0f, saturation, brightness),
                ExtMethodsSystemDrawingColor.ColorFromHSV(5.0f / 6.0f, saturation, brightness),
                ExtMethodsSystemDrawingColor.ColorFromHSV(1.0f, saturation, brightness)
            };
            blend.Positions = new float[] {
                0.0f,
                1.0f / 6.0f,
                2.0f / 6.0f,
                3.0f / 6.0f,
                4.0f / 6.0f,
                5.0f / 6.0f,
                1.0f
            };
            this.SetupGradient(blend, accuracy);
        }
Example #9
0
 public Color ToColor()
 {
     return(Color.FromArgb((int)Math.Round(this.a * 255.0f), ExtMethodsSystemDrawingColor.ColorFromHSV(this.h, this.s, this.v)));
 }