private void Configure(ImageData baseImage, IRaster raster)
 {
     _baseImage = baseImage;
     LegendText = Path.GetFileNameWithoutExtension(raster.Filename);
     base.OnItemChanged();
 }
 /// <summary>
 /// Creates a new instance of a MapRasterLayer and the specified image data to use for rendering it.
 /// </summary>
 public MapRasterLayer(IRaster baseRaster, ImageData baseImage):base(baseRaster)
 {
     Configure(baseImage, baseRaster);
 }
        /// <summary>
        /// Creates a new instance of a Raster layer, and will create a "FallLeaves" image based on the
        /// raster values.
        /// </summary>
        /// <param name="raster">The raster to use</param>
        public MapRasterLayer(IRaster raster):base(raster)
        {
            string imageFile = Path.ChangeExtension(raster.Filename, ".bmp");
            if (File.Exists(imageFile)) File.Delete(imageFile);

            IRasterSymbolizer rs = new RasterSymbolizer();
            rs.Raster = raster;
            rs.Scheme.ApplyScheme(ColorSchemes.FallLeaves, raster);
            Bitmap bmp = new Bitmap(raster.NumColumns, raster.NumRows);
            bmp.Save(imageFile);
            raster.PaintColorSchemeToBitmap(rs, bmp, raster.ProgressHandler);
            bmp.Save(imageFile);
            bmp.Dispose();

            ImageData id = new ImageData(imageFile);
            id.Bounds.AffineCoefficients = raster.Bounds.AffineCoefficients;
            id.WorldFile.Affine = raster.Bounds.AffineCoefficients;
            Configure(id, raster);
        }
        private void ReadPaletteBuffered()
        {
            ColorTable ct = _red.GetRasterColorTable();
            if (ct == null)
            {
                throw new GdalException("Image was stored with a palette interpretation but has no color table.");
            }
            if (ct.GetPaletteInterpretation() != PaletteInterp.GPI_RGB)
            {
                throw new GdalException("Only RGB palette interpreation is currently supported by this plugin, " + ct.GetPaletteInterpretation() + " is not supported.");
            }


            int tw = TileCollection.TileWidth;
            int th = TileCollection.TileHeight;
            for(int row = 0; row < TileCollection.NumTilesTall(); row++)
            {
                for(int col = 0; col < TileCollection.NumTilesWide(); col++)
                {
                    // takes into account that right and bottom tiles might be smaller.
                    int width = TileCollection.GetTileWidth(col); 
                    int height = TileCollection.GetTileHeight(row);
                    ImageData id = new ImageData();
                    byte[] red = new byte[width * height];
                    _red.ReadRaster(col * tw, row * th, width, height, red, width, height, 0, 0);
                    Bitmap image = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                    BitmapData bData = image.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                    Stride = bData.Stride;
                    image.UnlockBits(bData);

                    const int bpp = 4;
                    int stride = Stride;
                    byte[] vals = new byte[width * height * 4];
                    byte[][] colorTable = new byte[256][];
                    for (int i = 0; i < 255; i++)
                    {
                        ColorEntry ce = ct.GetColorEntry(i);
                        colorTable[i] = new[] { (byte)ce.c3, (byte)ce.c2, (byte)ce.c1, (byte)ce.c4 };
                    }
                    for (int r = 0; r < height; r++)
                    {
                        for (int c = 0; c < width; col++)
                        {
                            Array.Copy(colorTable[red[c + r * width]], 0, vals, row * stride + col * bpp, 4);
                        }
                    }
                    id.Values = vals;
                    id.WriteBytes();
                    TileCollection.Tiles[row, col] = id;


                }
            }
            SetTileBounds(Bounds.AffineCoefficients);
           
            
            
            

            
            
            
            
           
        }