Exemple #1
0
        //this is a pixelshader like method, which we pass to the fill function
        private unsafe void FillTexure(uint *data, int row, int col, int width, int height)
        {
            int  index = (width * (height - row - 1) + col) * 4;
            byte R     = texBytes[curSlice][index + 2];
            byte G     = texBytes[curSlice][index + 1];
            byte B     = texBytes[curSlice][index];
            byte A     = 255;

            // trasparency

/*
 *                      byte bgR = 255;
 *          byte bgG = 255;
 *          byte bgB = 255;
 *          int precision = 15;
 *
 *          if ((Math.Abs(R - bgR) < precision) &&
 *              (Math.Abs(G - bgG) < precision) &&
 *              (Math.Abs(B - bgB) < precision))
 *              A = 0;
 */

            var pixel = UInt32Utils.fromARGB(A, R, G, B);

            TextureUtils.SetPtrVal2D(data, pixel, row, col, width);
        }
        //this is a pixelshader like method, which we pass to the fill function
        unsafe void FillTexure(uint *data, int row, int col, int width, int height, Info info)
        {
            //crate position in texture in the range [0..1]
            var x = (double)row / height;
            var y = (double)col / width;

            //make some waves in the range [0..255]
            var wave = (byte)(255 * ((Math.Sin(x * y * info.WaveCount * 10) + 1) / 2.0));

            //a pixel is just a 32-bit unsigned int value
            var pixel = UInt32Utils.fromARGB(255, wave, wave, wave);

            //copy pixel into texture
            TextureUtils.SetPtrVal2D(data, pixel, row, col, width);
        }
        //this is a pixelshader like method, which we pass to the fill function
        unsafe void FillTexure(uint *data, int row, int col, int width, int height, Info info)
        {
            var pos = row * info.Stride + Math.Min(info.Width - 1, col) * info.ChannelCount;

            if (info.Pixels.Length > pos)
            {
                var src = info.Pixels;

                //a pixel is just a 32-bit unsigned int value

                uint pixel = 0;

                switch (info.ChannelCount)
                {
                //1 channel
                case 1:
                    pixel = UInt32Utils.fromARGB(0, src[pos], src[pos], src[pos]);
                    break;

                //3 channels
                case 3:
                    pixel = UInt32Utils.fromARGB(0, src[pos], src[pos + 1], src[pos + 2]);
                    break;

                //4 channels
                case 4:
                    pixel = UInt32Utils.fromARGB(src[pos], src[pos + 1], src[pos + 2], src[pos + 3]);
                    break;

                default:
                    pixel = UInt32Utils.fromARGB(0, 0, 0, 0);
                    break;
                }

                //copy pixel into texture
                TextureUtils.SetPtrVal2D(data, pixel, row, col, width);
            }
        }
Exemple #4
0
            //this is a pixelshader like method, which we pass to the fill function
            unsafe void FillTexture(uint *data, int row, int col, int width, int height, Info info)
            {
                // this method called per pixel
                // row(vertical) & col(horizonal) are each pixel's position and width & height are texture size
                // when 640x480, max row is 479 & max col is 639.

                // sometimes col or row over width & height depends on enviroment, so ignore that
                if (col >= info.Width || row >= info.Height)
                {
                    return;
                }

                // GL.getPixels results is flipped vertically, so flip by (info.Height - row - 1)
                int r = (col * 4) + ((info.Height - row - 1) * info.Width * 4); // 4 means R,G,B,A

                //a pixel is just a 32-bit unsigned int value
                uint pixel;

                // from BGRA to ARGB
                pixel = UInt32Utils.fromARGB(pixelBuffer[r + 3], pixelBuffer[r], pixelBuffer[r + 1], pixelBuffer[r + 2]);

                //copy pixel into texture
                TextureUtils.SetPtrVal2D(data, pixel, row, col, width);
            }