Ejemplo n.º 1
0
        public override void ApplyPalette(Palette palette)
        {
            context.Synchronize();
            mainStream.Synchronize();

            if (palette.Width <= 0 || palette.Height <= 0)
            {
                throw new ArgumentException("palette may not be empty.");
            }

            paletteImage.Free();

            paletteImage = CudaArray.Allocate(palette.Width, palette.Height, CudaArrayFormat.Float, 4);
            HostBuffer2D <Vec4> hostPaletteBuffer = HostBuffer2D <Vec4> .Alloc(palette.Width, palette.Height);

            Color col;

            Vec4 colorVec;

            for (int y = 0; y < palette.Height; y++)
            {
                for (int x = 0; x < palette.Width; x++)
                {
                    col      = palette.GetPixel(x, y);
                    colorVec = new Vec4(
                        (float)col.R / 255.0f,
                        (float)col.G / 255.0f,
                        (float)col.B / 255.0f,
                        1.0f);

                    hostPaletteBuffer[y, x] = colorVec;
                }
            }

            CudaMem.Copy(hostPaletteBuffer, paletteImage);
            hostPaletteBuffer.Free();

            paletteTex.Array = paletteImage;
            paletteTex.SetFormat(CudaArrayFormat.Float, 4);
            paletteTex.AddressModeX = TexAddressMode.Clamp;
            paletteTex.AddressModeY = TexAddressMode.Clamp;
            paletteTex.FilterMode   = TexFilterMode.Linear;
            paletteTex.Flags        = TexFlags.NormalizedCoordinates;

            iterateKernel.SetTexRef(paletteTex);
            context.Synchronize();
        }