private Bitmap ReadGrayIndex(int xOffset, int yOffset, int xSize, int ySize) { Band firstBand; var disposeBand = false; if (_overview >= 0 && _overviewCount > 0) { firstBand = _band.GetOverview(_overview); disposeBand = true; } else { firstBand = _band; } GdalExtensions.NormalizeSizeToBand(firstBand.XSize, firstBand.YSize, xOffset, yOffset, xSize, ySize, out int width, out int height); byte[] rBuffer = firstBand.ReadBand(xOffset, yOffset, width, height, width, height); if (disposeBand) { firstBand.Dispose(); } Bitmap result = GdalExtensions.GetBitmap(width, height, rBuffer, rBuffer, rBuffer, noDataValue: NoDataValue); rBuffer = null; return(result); }
private Bitmap ReadRgba(int xOffset, int yOffset, int xSize, int ySize) { if (Bands.Count < 4) { throw new GdalException("ARGB Format was indicated but there are only " + Bands.Count + " bands!"); } Band aBand; Band rBand; Band gBand; Band bBand; var disposeBand = false; if (_overview >= 0 && _overviewCount > 0) { rBand = (Bands[0] as GdalRaster <T>)._band.GetOverview(_overview); gBand = (Bands[1] as GdalRaster <T>)._band.GetOverview(_overview); bBand = (Bands[2] as GdalRaster <T>)._band.GetOverview(_overview); aBand = (Bands[3] as GdalRaster <T>)._band.GetOverview(_overview); disposeBand = true; } else { rBand = (Bands[0] as GdalRaster <T>)._band; gBand = (Bands[1] as GdalRaster <T>)._band; bBand = (Bands[2] as GdalRaster <T>)._band; aBand = (Bands[3] as GdalRaster <T>)._band; } GdalExtensions.NormalizeSizeToBand(rBand.XSize, rBand.YSize, xOffset, yOffset, xSize, ySize, out int width, out int height); byte[] aBuffer = aBand.ReadBand(xOffset, yOffset, width, height, width, height); byte[] rBuffer = rBand.ReadBand(xOffset, yOffset, width, height, width, height); byte[] gBuffer = gBand.ReadBand(xOffset, yOffset, width, height, width, height); byte[] bBuffer = bBand.ReadBand(xOffset, yOffset, width, height, width, height); if (disposeBand) { aBand.Dispose(); rBand.Dispose(); gBand.Dispose(); bBand.Dispose(); } Bitmap result = GdalExtensions.GetBitmap(width, height, rBuffer, gBuffer, bBuffer, aBuffer, NoDataValue); rBuffer = null; gBuffer = null; bBuffer = null; aBuffer = null; return(result); }
private Bitmap ReadPaletteBuffered(int xOffset, int yOffset, int xSize, int ySize) { ColorTable ct = _band.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 interpretation is currently supported by this " + " plug-in, " + ct.GetPaletteInterpretation() + " is not supported."); } int count = ct.GetCount(); byte[][] colorTable = new byte[ct.GetCount()][]; for (int i = 0; i < count; i++) { using (ColorEntry ce = ct.GetColorEntry(i)) { colorTable[i] = new[] { (byte)ce.c4, (byte)ce.c1, (byte)ce.c2, (byte)ce.c3 }; } } ct.Dispose(); Band firstBand; bool disposeBand = false; if (_overview >= 0 && _overviewCount > 0) { firstBand = _band.GetOverview(_overview); disposeBand = true; } else { firstBand = _band; } GdalExtensions.NormalizeSizeToBand(firstBand.XSize, firstBand.YSize, xOffset, yOffset, xSize, ySize, out int width, out int height); byte[] indexBuffer = firstBand.ReadBand(xOffset, yOffset, width, height, width, height); if (disposeBand) { firstBand.Dispose(); } byte[] rBuffer = new byte[indexBuffer.Length]; byte[] gBuffer = new byte[indexBuffer.Length]; byte[] bBuffer = new byte[indexBuffer.Length]; byte[] aBuffer = new byte[indexBuffer.Length]; for (int i = 0; i < indexBuffer.Length; i++) { int index = indexBuffer[i]; aBuffer[i] = colorTable[index][0]; rBuffer[i] = colorTable[index][1]; gBuffer[i] = colorTable[index][2]; bBuffer[i] = colorTable[index][3]; } Bitmap result = GdalExtensions.GetBitmap(width, height, rBuffer, gBuffer, gBuffer, aBuffer, NoDataValue); rBuffer = null; gBuffer = null; bBuffer = null; aBuffer = null; return(result); }