core/vil/vil_file_format.cxx
Go to the documentation of this file.
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 #if HAS_OPENJPEG2
00075 #include <vil/file_formats/vil_openjpeg.h>
00076 #endif
00077 
00078 const unsigned MAX_FILE_FORMATS=256;
00079 //: Local class to hold file format list
00080 // Clears list on deletion.
00081 struct vil_file_format_storage
00082 {
00083   vil_file_format** l;
00084   vil_file_format_storage(): l(new vil_file_format*[MAX_FILE_FORMATS])
00085   {
00086     unsigned c=0;
00087 #if HAS_JPEG
00088     l[c++] = new vil_jpeg_file_format;
00089 #endif
00090 #if HAS_PNG
00091     l[c++] = new vil_png_file_format;
00092 #endif
00093 #if HAS_PNM
00094     l[c++] = new vil_pnm_file_format;
00095     l[c++] = new vil_pbm_file_format;
00096     l[c++] = new vil_pgm_file_format;
00097     l[c++] = new vil_ppm_file_format;
00098 #endif
00099 #if HAS_IRIS
00100     l[c++] = new vil_iris_file_format;
00101 #endif
00102 #if HAS_MIT
00103     l[c++] = new vil_mit_file_format;
00104 #endif
00105 #if HAS_VIFF
00106     l[c++] = new vil_viff_file_format;
00107 #endif
00108 #if HAS_BMP
00109     l[c++] = new vil_bmp_file_format;
00110 #endif
00111 #if HAS_GIF
00112     l[c++] = new vil_gif_file_format;
00113 #endif
00114 #if HAS_RAS
00115     l[c++] = new vil_ras_file_format;
00116 #endif
00117 #if HAS_GEN
00118     l[c++] = new vil_gen_file_format;
00119 #endif
00120 // the DCMTK based reader is more complete, so use try that
00121 // before the vil implementation
00122 #if HAS_DCMTK
00123     l[c++] = new vil_dicom_file_format;
00124 #endif
00125 
00126 #if HAS_NITF
00127   l[c++] = new vil_nitf2_file_format;
00128 #endif
00129 
00130 #if HAS_J2K
00131   l[c++] = new vil_j2k_file_format;
00132 #endif
00133 
00134 #if HAS_OPENJPEG2
00135   l[c++] = new vil_openjpeg_jp2_file_format;
00136   //l[c++] = new vil_openjpeg_jpt_file_format;
00137   l[c++] = new vil_openjpeg_j2k_file_format;
00138 #endif
00139 
00140 #if HAS_TIFF
00141     l[c++] = new vil_tiff_file_format;
00142     l[c++] = new vil_pyramid_image_list_format;
00143 #endif
00144     l[c++] = 0;
00145   }
00146 
00147   ~vil_file_format_storage()
00148   {
00149     unsigned c=0;
00150     while (l[c]!=0)
00151       delete l[c++];
00152     delete [] l;
00153     l=0;
00154   }
00155 };
00156 
00157 //: The function will take ownership of ff;
00158 void vil_file_format::add_file_format(vil_file_format* ff)
00159 {
00160   vil_file_format** l=all();
00161   unsigned c=0;
00162   while (c<MAX_FILE_FORMATS-1u && l[c]!=0) ++c;
00163   if (l[c]!=0)
00164   {
00165     vil_exception_warning(vcl_logic_error(
00166       "vil_file_format::add_file_format Unable to add any more file formats" ));
00167     vcl_cerr << "ERROR vil_file_format::add_file_format Unable to add any more file formats\n";
00168     return;
00169   }
00170   l[c] = ff;
00171   l[c+1] = 0;
00172 }
00173 
00174 
00175 vil_file_format** vil_file_format::all()
00176 {
00177   static vil_file_format_storage storage;
00178   return storage.l;
00179 }