/*
    This file is part of Page Layout Detection Tools.

    This code is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This code is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this code; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include <formats/pbmfact.h>
#include <raster/deskewer.h>

#include <iostream>

using namespace pagetools;

using namespace std;

int main(int argc, char *argv[]){
    if(argc!=2){
        cerr<<"Usage: "<<argv[0]<<" pbm_file.pbm\n";
        return 1; 
    }
    const char* fname=argv[1];
    PBMFactory pf(fname);
    CntPtr<BWImage> b=pf.create();
    if(b){
        double alpha=Deskewer::findSkew(*b);
        // Convert radians to degrees and change the sign:
        cout<<-57.295779513082320876798154814105*alpha<<endl;
    }else{
        cout<<"Cannot open "<<fname<<endl;
    }
    
    return 0;

}
