基本信息
在GDAL的Tutorial中开篇即提到GDALAllRegister函数,它会注册所有已知的驱动,包括动态库自动加载的驱动。最关键是这句话:
If for some applications it is necessary to limit the set of drivers it may be helpful to review the code from gdalallregister.cpp.
我就是要精简GDAL的源代码,所以从分析GDALAllRegister函数开始是个好主意。
看之前已经有了几个问题:
第一,register具体指什么?
第二,已知的驱动,通过什么找到这些驱动?
这两个问题答案在 Inside GDALAllRegister之三: 注册指定驱动
第三,动态库自动加载的驱动又是什么?
答案在:Inside GDALAllRegister之二: 自动加载驱动
函数文档在这里:http://www.gdal.org/gdal_8h.html#a9d40bc998bd6ed07ccde96028e85ae26,没有太多信息。这个函数一般在程序中最开头的地方调用一次。
函数的五大部分
进入frmts/gdalallregister.cpp文件,看到这个函数,很长很长。可见支持的驱动非常之多。整个文件就只有这个函数的实现。这个函数主要分成若干部分:
第一部分,自动加载驱动:
GetGDALDriverManager()->AutoLoadDrivers();
第二部分,根据预编译指令注册特定的驱动
这里有很多,下面只列出两个:
#ifdef FRMT_vrt GDALRegister_VRT(); #endif #ifdef FRMT_gdb GDALRegister_GDB(); #endif
第三部分,注册一些raw formats
这里有很多,同样列出两个:
/* -------------------------------------------------------------------- */ /* Put raw formats at the end of the list. These drivers support */ /* various ASCII-header labeled formats, so the driver could be */ /* confused if you have files in some of above formats and such */ /* ASCII-header in the same directory. */ /* -------------------------------------------------------------------- */ #ifdef FRMT_raw GDALRegister_PNM(); GDALRegister_DOQ1(); ... #endif
第四部分,是注册未充分测试的驱动
放到了最后,我全部列出来,用到这写驱动要十分小心。
/* -------------------------------------------------------------------- */ /* Our test for the following is weak or expensive so we try */ /* them last. */ /* -------------------------------------------------------------------- */ #ifdef FRMT_rik GDALRegister_RIK(); #endif #ifdef FRMT_usgsdem GDALRegister_USGSDEM(); #endif #ifdef FRMT_gxf GDALRegister_GXF(); #endif #ifdef FRMT_grass GDALRegister_GRASS(); #endif #ifdef FRMT_dods GDALRegister_DODS(); #endif #ifdef FRMT_wcs GDALRegister_HTTP(); #endif #ifdef FRMT_hdf5 GDALRegister_BAG(); GDALRegister_HDF5(); GDALRegister_HDF5Image(); #endif #ifdef FRMT_northwood GDALRegister_NWT_GRD(); GDALRegister_NWT_GRC(); #endif #ifdef FRMT_adrg GDALRegister_ADRG(); GDALRegister_SRP(); #endif #ifdef FRMT_blx GDALRegister_BLX(); #endif #ifdef FRMT_pgchip GDALRegister_PGCHIP(); #endif #ifdef FRMT_georaster GDALRegister_GEOR(); #endif #ifdef FRMT_rasterlite GDALRegister_Rasterlite(); #endif #ifdef FRMT_epsilon GDALRegister_EPSILON(); #endif #ifdef FRMT_postgisraster GDALRegister_PostGISRaster(); #endif #ifdef FRMT_saga GDALRegister_SAGA(); #endif #ifdef FRMT_kmlsuperoverlay GDALRegister_KMLSUPEROVERLAY(); #endif #ifdef FRMT_xyz GDALRegister_XYZ(); #endif #ifdef FRMT_hf2 GDALRegister_HF2(); #endif #ifdef FRMT_pdf GDALRegister_PDF(); #endif #ifdef FRMT_jpegls GDALRegister_JPEGLS(); #endif #ifdef FRMT_ozi GDALRegister_OZI(); #endif
第五部分,将那些在环境变量GDAL_SKIP被明显标为不支持的驱动反注册
/* -------------------------------------------------------------------- */ /* Deregister any drivers explicitly marked as supressed by the */ /* GDAL_SKIP environment variable. */ /* -------------------------------------------------------------------- */ GetGDALDriverManager()->AutoSkipDrivers();
由于涉及的内容太多,一篇太长,还是分到几篇具体分析吧。