예제 #1
0
        private unsafe static UnsafeColor[] ComputeColors(Color color, int height, double[] shadows)
        {
            if (height < 0)
            {
                throw new ArgumentOutOfRangeException("height");
            }
            if (shadows == null)
            {
                throw new ArgumentNullException("shadows");
            }

            UnsafeColor[] colors = new UnsafeColor[height];
            fixed(UnsafeColor *ptrColors = &colors[0])
            {
                UnsafeColor unsafeColor;

                for (int n = 0; n < shadows.Length; n++)
                {
                    unsafeColor  = new UnsafeColor((byte)(color.R * shadows[n] + 0.5), (byte)(color.G * shadows[n] + 0.5), (byte)(color.B * shadows[n] + 0.5));
                    ptrColors[n] = unsafeColor;
                    ptrColors[colors.Length - n - 1] = unsafeColor;
                }
            }

            return(colors);
        }
예제 #2
0
 public ComponentPadding(CanvasContext ctx, JObject cfg) : base(ctx)
 {
     height = UtilReadConfigValue(cfg, "height", 200);
     color  = new UnsafeColor(
         UtilReadConfigValue <byte>(cfg, "r", 0),
         UtilReadConfigValue <byte>(cfg, "g", 0),
         UtilReadConfigValue <byte>(cfg, "b", 0)
         );
 }
        public SpectrumVideoCanvas(SpectrumVideoSource source, SpectrumVideoCanvasConfig config, IOutputProvider outputProvider)
        {
            //Set
            width               = config.video_output.width;
            label               = config.label;
            decimation          = config.baseband.decimation;
            frameRate           = config.video_output.frameRate;
            this.outputProvider = outputProvider;
            this.source         = source;

            //Create IQ decimator and oscilator
            oscillator = new Oscillator(SampleRate, config.baseband.freqOffset);
            decimator  = new ComplexDecimator(SampleRate, DecimatedSampleRate, config.baseband.decimation, config.baseband.decimationAttenuation, DecimatedSampleRate * config.baseband.decimationTransitionRatio);

            //Create all audio resources
            foreach (var o in config.audio_outputs)
            {
                AddResource(new AudioResource(o, this));
            }

            //Create all components
            components       = new SpectrumVideoComponent[config.components.Count];
            componentOffsets = new int[config.components.Count];
            for (int i = 0; i < components.Length; i++)
            {
                components[i] = ComponentFactory.MakeComponent(this, config.components[i]);
            }

            //Get the image dimensions by calculating the total height
            height = 0;
            for (int i = 0; i < components.Length; i++)
            {
                componentOffsets[i] = height * ImageWidth;
                height += components[i].Height;
            }

            //Create misc
            videoOutput   = outputProvider.GetVideoOutput(config.video_output.filename, ImageWidth, ImageHeight, config.video_output.frameRate, BufferSize);
            frameBuffer   = UnsafeBuffer.Create(ImageWidth * ImageHeight, out frameBufferPtr);
            buffer        = UnsafeBuffer.Create(BufferSize, out bufferPtr);
            textGenerator = FontStore.CreateRenderer(ImageWidth, ImageHeight);

            //Fill the entire canvas with black
            for (int i = 0; i < ImageWidth * ImageHeight; i++)
            {
                frameBufferPtr[i] = new UnsafeColor(0, 0, 0);
            }

            //Init all components
            for (int i = 0; i < components.Length; i++)
            {
                components[i].Init();
                components[i].InitFrame(frameBufferPtr + componentOffsets[i]);
            }
        }
예제 #4
0
 protected override void DrawableViewReset(int width, int height)
 {
     //Fill with black
     for (int y = 0; y < height; y++)
     {
         UnsafeColor *lnDst = pixels + (y * width);
         for (int x = 0; x < width; x++)
         {
             lnDst[x] = new UnsafeColor(0, 0, 0);
         }
     }
 }
예제 #5
0
        public unsafe void RenderCharacter(UnsafeColor *ptr, int canvasWidth, char character, UnsafeColor color)
        {
            //Try to find character data
            if (character == (char)0x00 || character == '\n' || character == '\r')
            {
                //Ignore. This is a null or invisible character
            }
            else if (characters.ContainsKey(character))
            {
                //Copy pixel data
                var cha = characters[character];
                for (int i = 0; i < width * fullHeight; i++)
                {
                    //Check if this is black to save CPU
                    if (cha.payload[i] == 0)
                    {
                        continue;
                    }

                    //Get location in memory
                    UnsafeColor *pxl = ptr + (canvasWidth * (i / width)) + (i % width);

                    //Update
                    if (cha.payload[i] == byte.MaxValue)
                    {
                        //Full brightness. Cheat
                        *pxl = color;
                    }
                    else
                    {
                        //Mix
                        float scale  = (float)cha.payload[i] / 256;
                        float scaleR = 1 - scale;
                        *     pxl    = new UnsafeColor(
                            (byte)(((*pxl).r * scaleR) + (color.r * scale)),
                            (byte)(((*pxl).g * scaleR) + (color.g * scale)),
                            (byte)(((*pxl).b * scaleR) + (color.b * scale))
                            );
                    }
                }
            }
            else
            {
                //Write a blank spot, as this character isn't found
            }
        }
예제 #6
0
 public unsafe void RenderLine(UnsafeColor *ptr, int canvasWidth, int x, int y, char[] chars, int count, UnsafeColor color)
 {
     RenderLine(ptr + (y * canvasWidth) + x, canvasWidth, chars, count, color);
 }
예제 #7
0
 public unsafe void RenderLine(UnsafeColor *ptr, int canvasWidth, char[] chars, int count, UnsafeColor color)
 {
     for (int i = 0; i < Math.Min(chars.Length, count); i++)
     {
         RenderCharacter(ptr, canvasWidth, chars[i], color);
         ptr += width + 1;
     }
 }
예제 #8
0
        private static unsafe UnsafeColor[] ComputeColors(Color color, int height, double[] shadows)
        {
            if (height < 0)
                throw new ArgumentOutOfRangeException("height");
            if (shadows == null)
                throw new ArgumentNullException("shadows");

            UnsafeColor[] colors = new UnsafeColor[height];
            fixed (UnsafeColor* ptrColors = &colors[0])
            {
                UnsafeColor unsafeColor;
                for (int n = 0; n < shadows.Length; n++)
                {
                    unsafeColor = new UnsafeColor((byte)(color.R * shadows[n] + 0.5), (byte)(color.G * shadows[n] + 0.5), (byte)(color.B * shadows[n] + 0.5));
                    ptrColors[n] = unsafeColor;
                    ptrColors[colors.Length - n - 1] = unsafeColor;
                }
            }
            return colors;
        }