00001 // This is core/vil/vil_file_format.cxx 00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00003 #pragma implementation 00004 #endif 00005 //: 00006 // \file 00007 #include "vil_file_format.h" 00008 00009 vil_file_format::~vil_file_format() 00010 { 00011 } 00012 00013 00014 #include <vil/vil_config.h> // for list of configured file formats 00015 #include <vil/vil_exception.h> 00016 00017 #if HAS_PNM 00018 #include <vil/file_formats/vil_pnm.h> 00019 #endif 00020 00021 #if HAS_IRIS 00022 #include <vil/file_formats/vil_iris.h> 00023 #endif 00024 00025 #if HAS_MIT 00026 #include <vil/file_formats/vil_mit.h> 00027 #endif 00028 00029 #if HAS_VIFF 00030 #include <vil/file_formats/vil_viff.h> 00031 #endif 00032 00033 #if HAS_PNG 00034 #include <vil/file_formats/vil_png.h> 00035 #endif 00036 00037 #if HAS_JPEG 00038 #include <vil/file_formats/vil_jpeg.h> 00039 #endif 00040 00041 #if HAS_TIFF 00042 #include <vil/file_formats/vil_tiff.h> 00043 #include <vil/file_formats/vil_pyramid_image_list.h> 00044 #endif 00045 00046 #if HAS_BMP 00047 #include <vil/file_formats/vil_bmp.h> 00048 #endif 00049 00050 #if HAS_GIF 00051 #include <vil/file_formats/vil_gif.h> 00052 #endif 00053 00054 #if HAS_RAS 00055 #include <vil/file_formats/vil_ras.h> 00056 #endif 00057 00058 #if HAS_GEN 00059 #include <vil/file_formats/vil_gen.h> 00060 #endif 00061 00062 #if HAS_DCMTK 00063 #include <vil/file_formats/vil_dicom.h> 00064 #endif 00065 00066 #if HAS_NITF 00067 #include <vil/file_formats/vil_nitf2_image.h> 00068 #endif 00069 00070 #if HAS_J2K 00071 #include <vil/file_formats/vil_j2k_image.h> 00072 #endif 00073 00074 const unsigned MAX_FILE_FORMATS=256; 00075 //: Local class to hold file format list 00076 // Clears list on deletion. 00077 struct vil_file_format_storage 00078 { 00079 vil_file_format** l; 00080 vil_file_format_storage(): l(new vil_file_format*[MAX_FILE_FORMATS]) 00081 { 00082 unsigned c=0; 00083 #if HAS_JPEG 00084 l[c++] = new vil_jpeg_file_format; 00085 #endif 00086 #if HAS_PNG 00087 l[c++] = new vil_png_file_format; 00088 #endif 00089 #if HAS_PNM 00090 l[c++] = new vil_pnm_file_format; 00091 l[c++] = new vil_pbm_file_format; 00092 l[c++] = new vil_pgm_file_format; 00093 l[c++] = new vil_ppm_file_format; 00094 #endif 00095 #if HAS_IRIS 00096 l[c++] = new vil_iris_file_format; 00097 #endif 00098 #if HAS_MIT 00099 l[c++] = new vil_mit_file_format; 00100 #endif 00101 #if HAS_VIFF 00102 l[c++] = new vil_viff_file_format; 00103 #endif 00104 #if HAS_BMP 00105 l[c++] = new vil_bmp_file_format; 00106 #endif 00107 #if HAS_GIF 00108 l[c++] = new vil_gif_file_format; 00109 #endif 00110 #if HAS_RAS 00111 l[c++] = new vil_ras_file_format; 00112 #endif 00113 #if HAS_GEN 00114 l[c++] = new vil_gen_file_format; 00115 #endif 00116 // the DCMTK based reader is more complete, so use try that 00117 // before the vil implementation 00118 #if HAS_DCMTK 00119 l[c++] = new vil_dicom_file_format; 00120 #endif 00121 00122 #if HAS_NITF 00123 l[c++] = new vil_nitf2_file_format; 00124 #endif 00125 00126 #if HAS_J2K 00127 l[c++] = new vil_j2k_file_format; 00128 #endif 00129 00130 #if HAS_TIFF 00131 l[c++] = new vil_tiff_file_format; 00132 l[c++] = new vil_pyramid_image_list_format; 00133 #endif 00134 l[c++] = 0; 00135 } 00136 00137 ~vil_file_format_storage() 00138 { 00139 unsigned c=0; 00140 while (l[c]!=0) 00141 delete l[c++]; 00142 delete [] l; 00143 l=0; 00144 } 00145 }; 00146 00147 //: The function will take ownership of ff; 00148 void vil_file_format::add_file_format(vil_file_format* ff) 00149 { 00150 vil_file_format** l=all(); 00151 unsigned c=0; 00152 while (c<MAX_FILE_FORMATS-1u && l[c]!=0) ++c; 00153 if (l[c]!=0) 00154 { 00155 vil_exception_warning(vcl_logic_error( 00156 "vil_file_format::add_file_format Unable to add any more file formats" )); 00157 vcl_cerr << "ERROR vil_file_format::add_file_format Unable to add any more file formats\n"; 00158 return; 00159 } 00160 l[c] = ff; 00161 l[c+1] = 0; 00162 } 00163 00164 00165 vil_file_format** vil_file_format::all() 00166 { 00167 static vil_file_format_storage storage; 00168 return storage.l; 00169 }
1.5.1