(string[] args)
| 41 | } |
| 42 | |
| 43 | public static void Main(string[] args) |
| 44 | { |
| 45 | |
| 46 | if (args.Length != 2) usage(); |
| 47 | |
| 48 | string file = args[0]; |
| 49 | string file_out = args[1]; |
| 50 | try |
| 51 | { |
| 52 | |
| 53 | /* -------------------------------------------------------------------- */ |
| 54 | /* Register driver(s). */ |
| 55 | /* -------------------------------------------------------------------- */ |
| 56 | Gdal.AllRegister(); |
| 57 | |
| 58 | byte[] buffer; |
| 59 | |
| 60 | /* -------------------------------------------------------------------- */ |
| 61 | /* Open dataset. */ |
| 62 | /* -------------------------------------------------------------------- */ |
| 63 | using (Dataset ds = Gdal.Open(file, Access.GA_ReadOnly)) |
| 64 | using (Band band = ds.GetRasterBand(1)) |
| 65 | using (ColorTable ct = band.GetRasterColorTable()) |
| 66 | { |
| 67 | if (ct != null) |
| 68 | Console.WriteLine("Band has a color table with " + ct.GetCount() + " entries."); |
| 69 | else |
| 70 | { |
| 71 | Console.WriteLine("Data source has no color table"); |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | buffer = new byte[ds.RasterXSize * ds.RasterYSize]; |
| 76 | band.ReadRaster(0, 0, ds.RasterXSize, ds.RasterYSize, buffer, |
| 77 | ds.RasterXSize, ds.RasterYSize, 0, 0); |
| 78 | |
| 79 | /* -------------------------------------------------------------------- */ |
| 80 | /* Get driver */ |
| 81 | /* -------------------------------------------------------------------- */ |
| 82 | Driver dv = Gdal.GetDriverByName("GTiff"); |
| 83 | |
| 84 | using (Dataset ds_out = dv.Create(file_out, ds.RasterXSize, ds.RasterYSize, |
| 85 | ds.RasterCount, band.DataType, new string[] { } |
| 86 | )) |
| 87 | using (Band ba_out = ds_out.GetRasterBand(1)) |
| 88 | using (ColorTable ct_out = new ColorTable(PaletteInterp.GPI_RGB)) |
| 89 | { |
| 90 | ba_out.WriteRaster(0, 0, ds.RasterXSize, ds.RasterYSize, buffer, |
| 91 | ds.RasterXSize, ds.RasterYSize, 0, 0); |
| 92 | |
| 93 | /* -------------------------------------------------------------------- */ |
| 94 | /* Copying the colortable */ |
| 95 | /* -------------------------------------------------------------------- */ |
| 96 | for (int i = 0; i < ct.GetCount(); i++) |
| 97 | { |
| 98 | ColorEntry ce = null, ce_out = null; |
| 99 | |
| 100 | ce = ct.GetColorEntry(i); |
nothing calls this directly
no test coverage detected