img2vips.cpp

Go to the documentation of this file.
00001 /*
00002  *  @common Convert an image to a vips file, keeping the canvas position.
00003  *
00004  *  @author Pablo d'Angelo <pablo.dangelo@web.de>
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2 of the License, or (at your option) any later version.
00010  *
00011  *  This software is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public
00017  *  License along with this software; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 /* compile with
00023 
00024         g++ -g -Wall blend.cc `pkg-config vipsCC-7.11 --cflags --libs`
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       // copy position field
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     // 1 is the output image, the other args are input
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 }

Generated on Thu Apr 24 01:25:37 2014 for Hugintrunk by  doxygen 1.3.9.1