00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <vips/vips>
00029 #include <vips/vips.h>
00030
00031 #include <vigra/impex.hxx>
00032
00033 #include <string>
00034 #include <common/utils.h>
00035 #include <unistd.h>
00036
00037 using namespace vips;
00038 using namespace std;
00039 using namespace utils;
00040 using namespace vigra;
00041
00042 void
00043 convert_file (const char *filename)
00044 {
00045 ImageImportInfo inFile(filename);
00046 int bands = inFile.numBands();
00047 if (inFile.getPixelType() == std::string("FLOAT") && bands == 4)
00048 {
00049 cout << "Reading " << filename << " ... " << std::flush;
00050 BasicImage<TinyVector<float,4> > img(inFile.size());
00051 importImage(inFile, destImage(img));
00052 cout << " done. " << std::flush;
00053 void *data = &(img(0,0));
00054 VImage viout (data, img.size().x, img.size().y, bands, VImage::FMTFLOAT);
00055
00056 viout.image()->Xoffset = inFile.getPosition().x;
00057 viout.image()->Yoffset = inFile.getPosition().y;
00058 std::string outfile(utils::stripExtension(filename));
00059 outfile += ".v";
00060 cout << " Writing " << outfile << std::endl;
00061 viout.write (outfile.c_str());
00062 } else {
00063 throw VError("Fatal error: unsupported input file format (only RGB float with alpha supported right now)");
00064 }
00065 }
00066
00067 int
00068 main (int argc, char **argv)
00069 {
00070 try
00071 {
00072
00073 if (argc < 1)
00074 throw VError ("usage: in1 (in2) ...\n");
00075
00076 int nin = argc - 1;
00077 for (int i = 0; i < nin; i++) {
00078 convert_file (argv[i + 1]);
00079 }
00080 }
00081 catch (VError err)
00082 {
00083 err.perror (argv[0]);
00084 }
00085
00086 return (0);
00087 }