예제 #1
0
        void DrawXAxis(ImageData image)
        {
            var xmin = Settings.Viewport.XMin;
            var xmax = Settings.Viewport.XMax;
            var ymin = Settings.Viewport.YMin;
            var ymax = Settings.Viewport.YMax;
            var step = Settings.StepX;

            for (double x = xmin; x <= xmax; x += 0.01)
            {
                var point = new Point { X = x, Y = 0 };
                var pointFromPlain = FromPointOnPlain(point, xmin, xmax, ymin, ymax, Canvas.Height, Canvas.Width);
                SetPixel(image, (int)pointFromPlain.X, (int)pointFromPlain.Y, new Color { Red = 0, Blue = 0, Green = 0 });
            }
        }
예제 #2
0
        void DrawCurve(Curve curve, ImageData image)
        {
            var xmin = Settings.Viewport.XMin;
            var xmax = Settings.Viewport.XMax;
            var ymin = Settings.Viewport.YMin;
            var ymax = Settings.Viewport.YMax;
            var step = Settings.StepX;

            for (double x = xmin; x <= xmax; x += step)
            {
                var y = curve.Map(x);
                if (y < ymin || y > ymax || double.IsNaN(y)) // off bounds or undefined
                    continue;

                var point = new Point { X = x, Y = y };
                var pointFromPlain = FromPointOnPlain(point, xmin, xmax, ymin, ymax, Canvas.Height, Canvas.Width);
                SetPixel(image, (int)pointFromPlain.X, (int)pointFromPlain.Y, curve.Color);
            }
        }
예제 #3
0
 void SetPixel(ImageData img, int x, int y, Color color)
 {
     int index = (x + y * (int)img.Width) * 4;
     img.Data[index] = color.Red;
     img.Data[index + 1] = color.Green;
     img.Data[index + 2] = color.Blue;
     img.Data[index + 3] = 255; // alpha
 }
예제 #4
0
        void DrawYAxis(ImageData image)
        {
            var xmin = Settings.XMin;
            var xmax = Settings.XMax;
            var ymin = Settings.YMin;
            var ymax = Settings.YMax;
            var step = Settings.DeltaX;

            for (double y = ymin; y <= ymax; y += 0.01)
            {
                var point = new Point { X = 0, Y = y };
                var pointFromPlain = FromPointOnPlain(point, xmin, xmax, ymin, ymax, Canvas.Height, Canvas.Width);
                SetPixel(image, (int)pointFromPlain.X, (int)pointFromPlain.Y, new Color { Red = 0, Blue = 0, Green = 0 });
            }
        }
예제 #5
0
 /// <summary>
 /// Paints data from the given ImageData object onto the bitmap. If a dirty rectangle is provided,
 /// only the pixels from that rectangle are painted.
 /// </summary>
 /// <param name="imagedata">An imageData object containing the array of pixel values.</param>
 /// <param name="dx">
 /// Position offset in the target canvas context of the rectangle to be painted, relative to the
 /// rectangle in the origin image data.
 /// </param>
 /// <param name="dy">
 /// Position offset in the target canvas context of the rectangle to be painted, relative to the
 /// rectangle in the origin image data.
 /// </param>
 /// <param name="dirtyX">
 /// Position of the top left point of the rectangle to be painted, in the origin image data.
 /// Defaults to the top left of the whole image data.
 /// </param>
 /// <param name="dirtyY">
 /// Position of the top left point of the rectangle to be painted, in the origin image data.
 /// Defaults to the top left of the whole image data.
 /// </param>
 /// <param name="dirtyWidth">
 /// Width of the rectangle to be painted, in the origin image data. Defaults to the width of the image data.
 /// </param>
 /// <param name="dirtyHeight">
 /// Height of the rectangle to be painted, in the origin image data. Defaults to the height of the image data.
 /// </param>
 public virtual void PutImageData(ImageData imagedata, int dx, int dy, 
                                  Any<uint?, int?> dirtyX, Any<uint?, int?> dirtyY, 
                                  Any<uint?, int?> dirtyWidth, Any<uint?, int?> dirtyHeight)
 {
     return;
 }
예제 #6
0
 /// <summary>
 /// Paints data from the given ImageData object onto the bitmap. If a dirty rectangle is provided,
 /// only the pixels from that rectangle are painted.
 /// </summary>
 /// <param name="imagedata">An imageData object containing the array of pixel values.</param>
 /// <param name="dx">
 /// Position offset in the target canvas context of the rectangle to be painted, relative to the
 /// rectangle in the origin image data.
 /// </param>
 /// <param name="dy">
 /// Position offset in the target canvas context of the rectangle to be painted, relative to the
 /// rectangle in the origin image data.
 /// </param>
 public virtual void PutImageData(ImageData imagedata, int dx, int dy)
 {
     return;
 }
예제 #7
0
 /// <summary>
 /// Creates a new, blank ImageData object with the specified dimensions. All of the pixels in the
 /// new object are transparent black.
 /// </summary>
 /// <param name="imagedata">
 /// An existing ImageData object from which to copy the width and height. The image itself is not copied.
 /// </param>
 /// <returns>
 /// A new ImageData object with the specified width and height. The new object is filled with
 /// transparent black pixels.
 /// </returns>
 public virtual ImageData CreateImageData(ImageData imagedata)
 {
     return null;
 }
예제 #8
0
파일: Drawer.cs 프로젝트: Zaid-Ajaj/Demos
        private void GetImageData(HTMLCanvasElement canvas)
        {
            int height = canvas.Height;
            int width = canvas.Width;

            if (CanvasRenderingContext == null)
            {
                CanvasRenderingContext = canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            }

            if (Image == null)
            {
                // the data to manipulate
                Image = CanvasRenderingContext.CreateImageData(width, height);
            }
            else
            {
                //var color = new Color() { Red = 0, Green = 0, Blue = 0 };

                //for (int y = 0; y < height; y++)
                //{
                //    for (int x = 0; x < width; x++)
                //    {
                //        Image.SetPixel(x, y, color);
                //    }
                //}
            }
        }
 /// <summary>
 /// Replaces a portion of an existing 2D texture image with all of another image.
 ///
 /// Errors:
 ///     gl.SECURITY_ERR         Occurs if an image or canvas is supplied and doesn't have the same origin of the canvas associated with the WebGLRenderingContext.
 ///
 ///     gl.INVALID_VALUE        If pixels is null.
 ///                             If level is &lt; 0, or greater than maximum allowable value.
 ///                             If xoffset is greater than the width of the texture image.
 ///                             If yoffset is greater than the height of the texture image.
 ///
 ///     gl.INVALID_OPERATION    If called without a currently bound texture.
 ///                             The type doesn't match the type originally defined for the texture.
 ///                             If type and format aren't compatible values.
 ///
 ///     gl.INVALID_ENUM            If target, format, or type aren't one of the listed values.
 ///
 /// </summary>
 /// <param name="target">The target texture of the active texture unit. Must be one of the following:
 ///     gl.TEXTURE_2D                       Uses a 2D image.
 ///     gl.TEXTURE_CUBE_MAP_POSITIVE_X      Image for the positive X face of the cube map.
 ///     gl.TEXTURE_CUBE_MAP_NEGATIVE_X      Image for the negative X face of the cube map.
 ///     gl.TEXTURE_CUBE_MAP_POSITIVE_Y      Image for the positive Y face of the cube map.
 ///     gl.TEXTURE_CUBE_MAP_NEGATIVE_Y      Image for the negative Y face of the cube map.
 ///     gl.TEXTURE_CUBE_MAP_POSITIVE_Z      Image for the positive Z face of the cube map.
 ///     gl.TEXTURE_CUBE_MAP_NEGATIVE_Z      Image for the negative Z face of the cube map.
 /// </param>
 /// <param name="level">The level of detail to use with the texture.</param>
 /// <param name="xOffset">The x (horizontal) offset within the texture image.</param>
 /// <param name="yOffset">The y (vertical) offset within the texture image.</param>
 /// <param name="width">Width of texture sub-image. Value used only when UInt8Array or Float32Array for pixels is specified. </param>
 /// <param name="height">Height of texture sub-image. Value used only when UInt8Array or Float32Array for pixels is specified. </param>
 /// <param name="format">The format of the source pixel data.
 ///     gl.ALPHA                Each element is a single alpha component. The system converts it to floating point, clamped to the range [0, 1], and assembles it into an RGBA element by placing attaching 0.0 to the red, green and blue channels.
 ///     gl.LUMINANCE            Each element is a single luminance component. The system converts it to floating point value, clamped to the range [0, 1], and assembles it into an RGBA element by placing the luminance value in the red, green and blue channels, and attaching 1.0 to the alpha channel.
 ///     gl.LUMINANCE_ALPHA      Each element is an luminance/alpha double. The systems converts each component to floating point, clamped to the range [0, 1], and assembles them into an RGBA element by placing the luminance value in the red, green and blue channels.
 ///     gl.RGB                  Red, green, and blue channels.
 ///     gl.RGBA                 Red, green, blue, and alpha (transparency) channels.
 /// </param>
 /// <param name="type">The data type of the pixel data.
 ///     gl.UNSIGNED_BYTE
 ///     gl.FLOAT            Call getExtension("gl.OES_texture_float") first to enable. This creates 128bit-per-pixel textures instead of 32bit-per-pixel for the image. </param>
 /// <param name="pixels">The ImageData array to use for the texture.</param>
 public virtual void TexSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int type, ImageData pixels) { }
 /// <summary>
 /// Loads the supplied pixel data into a texture.
 ///
 /// Images that are used as textures are not allowed if the origin of the image isn't the same as the origin of the canvas element. Images are also blocked if they are from a canvas whose origin-clean flag set to false.
 ///
 /// Errors:
 ///     gl.SECURITY_ERR             Occurs if an image or canvas is supplied as the pixel data source and isn't the same origin (same domain) of the canvas associated with the WebGLRenderingContext.
 ///
 ///     gl.INVALID_OPERATION        If the ArrayBufferView doesn't have enough data to fill the specified rectangle.
 ///                                 If format and internalformat don't match.
 ///                                 No texture is bound to target.
 ///                                 If type is gl.UNSIGNED_SHORT_5_6_5 and format isn't gl.RGB.
 ///                                 If type is gl.UNSIGNED_SHORT_4_4_4_4 or gl.UNSIGNED_SHORT_5_5_5_1 and the format isn't gl.RGBA
 ///
 ///     gl.INVALID_VALUE            target is a cube map target and width and height aren't equal.
 ///                                 If pixels is null for any of the non-ArrayBuffer overloads.
 ///                                 The incoming ArrayBufferView or image is bigger than max texture size. Max texture can be retrieved by calling getParameter and using the gl.MAX_CUBE_MAP_TEXTURE_SIZE and gl.MAX_TEXTURE_SIZE enums.
 ///                                 If level, width, or height is a negative value.
 ///                                 If level is greater than log 2(max), where max is the value of gl.MAX_TEXTURE_SIZE when target is gl.TEXTURE_2D.
 ///                                 If width or height are greater than the value of gl.MAX_TEXTURE_SIZE when target is gl.TEXTURE_2D.
 ///                                 If level is greater than log 2(max), where max is the value of gl.MAX_CUBE_MAP_TEXTURE_SIZE when target is not gl.TEXTURE_2D.
 ///                                 If width or height are greater than the value of gl.MAX_CUBE_MAP_TEXTURE_SIZE when target is not a cube map texture target.
 ///
 ///     gl.INVALID_ENUM                If target, format, internalformat, or type aren't one of the listed values.
 /// </summary>
 /// <param name="target">The target texture of the active texture unit. Must be one of the following:
 ///     gl.TEXTURE_2D                       Uses a 2D image.
 ///     gl.TEXTURE_CUBE_MAP_POSITIVE_X      Image for the positive X face of the cube map.
 ///     gl.TEXTURE_CUBE_MAP_NEGATIVE_X      Image for the negative X face of the cube map.
 ///     gl.TEXTURE_CUBE_MAP_POSITIVE_Y      Image for the positive Y face of the cube map.
 ///     gl.TEXTURE_CUBE_MAP_NEGATIVE_Y      Image for the negative Y face of the cube map.
 ///     gl.TEXTURE_CUBE_MAP_POSITIVE_Z      Image for the positive Z face of the cube map.
 ///     gl.TEXTURE_CUBE_MAP_NEGATIVE_Z      Image for the negative Z face of the cube map.
 /// </param>
 /// <param name="level">The level of detail value. </param>
 /// <param name="internalFormat">
 ///     gl.ALPHA                Each element is a single alpha component. The system converts it to floating point, clamped to the range [0, 1], and assembles it into an RGBA element by placing attaching 0.0 to the red, green and blue channels.
 ///     gl.LUMINANCE            Each element is a single luminance component. The system converts it to floating point value, clamped to the range [0, 1], and assembles it into an RGBA element by placing the luminance value in the red, green and blue channels, and attaching 1.0 to the alpha channel.
 ///     gl.LUMINANCE_ALPHA      Each element is an luminance/alpha double. The systems converts each component to floating point, clamped to the range [0, 1], and assembles them into an RGBA element by placing the luminance value in the red, green and blue channels.
 ///     gl.RGB                  Red, green, and blue channels.
 ///     gl.RGBA                 Red, green, blue, and alpha (transparency) channels.
 /// </param>
 /// <param name="format">Contains the format for the source pixel data. Must match internalformat. </param>
 /// <param name="type">The type of texture data.
 ///     gl.UNSIGNED_BYTE                Provides 8 bits per channel for gl.RGBA.
 ///     gl.FLOAT                        Call getExtension("gl.OES_texture_float") first to enable. This creates 128 bit-per-pixel textures instead of 32 bit-per-pixel for the image.
 ///     gl.UNSIGNED_SHORT_5_6_5         Represents colors in a Uint16Array where red = 5 bits, green=6 bits, and blue=5 bits.
 ///     gl.UNSIGNED_SHORT_4_4_4_4       Represents colors in a Uint16Array where red = 4 bits, green=4 bits, blue=4 bits, and alpha=4 bits.
 ///     gl.UNSIGNED_SHORT_5_5_5_1       Represents colors in a Uint16Array where red = 5 bits, green=5 bits, blue=5 bits and alpha=1 bit.</param>
 /// <param name="pixels">The ImageData array to use as a data source for the texture. A buffer of sufficient size is automatically allocated and its contents is initialized to 0 if pixels is null.</param>
 public virtual void TexImage2D(int target, int level, int internalFormat, int format, int type, ImageData pixels) { }
예제 #11
0
 /// <summary>
 /// Paints data from the given ImageData object onto the bitmap. If a dirty rectangle is provided,
 /// only the pixels from that rectangle are painted.
 /// </summary>
 /// <param name="imagedata">An imageData object containing the array of pixel values.</param>
 /// <param name="dx">
 /// Position offset in the target canvas context of the rectangle to be painted, relative to the
 /// rectangle in the origin image data.
 /// </param>
 /// <param name="dy">
 /// Position offset in the target canvas context of the rectangle to be painted, relative to the
 /// rectangle in the origin image data.
 /// </param>
 /// <param name="dirtyX">
 /// Position of the top left point of the rectangle to be painted, in the origin image data.
 /// Defaults to the top left of the whole image data.
 /// </param>
 /// <param name="dirtyY">
 /// Position of the top left point of the rectangle to be painted, in the origin image data.
 /// Defaults to the top left of the whole image data.
 /// </param>
 /// <param name="dirtyWidth">
 /// Width of the rectangle to be painted, in the origin image data. Defaults to the width of the image data.
 /// </param>
 /// <param name="dirtyHeight">
 /// Height of the rectangle to be painted, in the origin image data. Defaults to the height of the image data.
 /// </param>
 public virtual void PutImageData(ImageData imagedata, int dx, int dy, Any<uint?, int?> dirtyX = null,
                                  Any<uint?, int?> dirtyY = null, Any<uint?, int?> dirtyWidth = null,
                                  Any<uint?, int?> dirtyHeight = null)
 {
     return;
 }
예제 #12
0
 /// <summary>
 /// Creates a new, blank ImageData object with the specified dimensions. All of the pixels in the
 /// new object are transparent black.
 /// </summary>
 /// <param name="imagedata">
 /// An existing ImageData object from which to copy the width and height. The image itself is not copied.
 /// </param>
 /// <returns>
 /// A new ImageData object with the specified width and height. The new object is filled with
 /// transparent black pixels.
 /// </returns>
 public virtual extern ImageData CreateImageData(ImageData imagedata);