private int GetBandCount(LDataType dataType) { switch (dataType) { case LDataType.L_RGB: return(3); case LDataType.L_ARGB: return(4); default: throw new NotSupportedException("不支持的数据类型\"" + dataType + "\"!"); } }
public static extern void CreateLCompress(ref IntPtr lc, LCompressFormat format, LDataType dataType, int band);
public static extern unsafe int GDALDatasetRasterIO( IntPtr hDS, LFRWFlag eRWFlag, int nDSXOff, int nDSYOff, int nDSXSize, int nDSYSize, void *pBuffer, int nBXSize, int nBYSize, LDataType eBDataType, int nBandCount, int[] panBandCount, int nPixelSpace, int nLineSpace, int nBandSpace);
public static extern unsafe int GDALRasterIO(IntPtr hRBand, LFRWFlag eRWFlag, int nDSXOff, int nDSYOff, int nDSXSize, int nDSYSize, void *pBuffer, int nBXSize, int nBYSize, LDataType eBDataType, int nPixelSpace, int nLineSpace);
public static extern IntPtr GDALCreate(IntPtr hDriver, string name, int width, int height, int nBands, LDataType tyoe, ref string papszOptions);
public static extern void ReadImgDataType(IntPtr img, ref LDataType dataType);
private static unsafe void Convert16To8(byte[] src, int width, int height, int bands, LDataType dataType, byte[] dst) { int[] minPixel = new int[bands]; int[] maxPixel = new int[bands]; int size = width * height; for (int i = 0; i < bands; i++) { int[] hist = new int[65536]; float tt = 0; fixed(void *p = src) { int m_min = 65535000; int m_max = -65535000; switch (dataType) { case LDataType.L_Int16: Int16 *fp = (Int16 *)p; for (int k = 0; k < size; k++) { tt = fp[bands * k + i]; hist[(int)tt]++; if (m_min > tt) { m_min = (int)tt; } if (m_max < tt) { m_max = (int)tt; } } break; case LDataType.L_UInt16: UInt16 *fp1 = (UInt16 *)p; for (int k = 0; k < size; k++) { tt = fp1[bands * k + i]; hist[(int)tt]++; if (m_min > tt) { m_min = (int)tt; } if (m_max < tt) { m_max = (int)tt; } } break; default: break; } int sum = 0; int sminSize = (int)((size - hist[0] - hist[65535]) * 0.015); int low = 0; for (low = m_min + 1; low < m_max; low++) { sum += hist[low]; if (sum > sminSize) { break; } } minPixel[i] = low - 1; sum = 0; int j = 0; for (j = m_max - 1; j > m_min; j--) { sum += hist[j]; if (sum > sminSize) { break; } } maxPixel[i] = j + 1; } } #region 量化 for (int i = 0; i < size; i++) { for (int j = 0; j < bands; j++) { ushort t = (ushort)((short)(src[i * bands * 2 + j * 2 + 1] << 8) + src[i * bands * 2 + j * 2]); byte b = Clamp(t, minPixel[j], maxPixel[j]); dst[i * bands + j] = b; } } #endregion }
public static void ConvertTo8bits(byte[] src, int width, int height, int bands, LDataType dataType, byte[] dst) { switch (dataType) { case LDataType.L_Int16: case LDataType.L_UInt16: Convert16To8(src, width, height, bands, dataType, dst); break; case LDataType.L_Int32: break; default: break; } }
public static extern CPLErr GDALGridCreateTIF(GDALGridAlgorithm alg, IntPtr poOptions, UInt32 nPoints, double[] padfX, double[] padfY, double[] padfZ, double dfXMin, double dfXMax, double dfYMin, double dfYMax, UInt32 nXSize, UInt32 nYSize, LDataType eType, string outFileName, GDALProgressFunc pfnProgress, IntPtr pProgressArg);