/*************************************************************************** * Copyright (C) 2010 by Pierre Marchand * * pierre@oep-h.com * * * * This program 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 program 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 program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "scanimage.h" #include //#include #include #include ScanImage::ScanImage() { sane_status = sane_init(&version_code, NULL); } ScanImage::ScanImage(const QImage& img) :image(img) { } ScanImage::~ScanImage() { sane_exit(); } void ScanImage::run() { if(!image.isNull()) return; // TODO if(ScanError("Sane can't init")) return; const SANE_Device ** dl; sane_status = sane_get_devices(&dl,true); if((ScanError("Sane can't get any device")) || (0 == dl[0])) return; SANE_Handle h; sane_status = sane_open(dl[0]->name, &h); if(ScanError("Sane can't open device")) return; sane_status = sane_get_parameters(h, ¶ms); if(ScanError("Sane can't get parameters")) return; QString bMode("mode"); // unsigned int bModeOptionIdx(0); unsigned int bModeOptionIdx(1); QString binary; unsigned int bModeIndex(0); SANE_Int numOptions = 0; void * optionValue = malloc(sizeof(SANE_Int)); sane_status = sane_control_option(h, 0, SANE_ACTION_GET_VALUE, optionValue, 0); if(ScanError("Sane can't get num options")) return; numOptions = *(static_cast(optionValue)); free(optionValue); for (unsigned int i = 1; i < numOptions; ++i) { const SANE_Option_Descriptor *opt = sane_get_option_descriptor(h, i); optionValue = malloc(opt->size + 1); if(opt->type != SANE_TYPE_GROUP) { QString name(opt->name); QString title(opt->title); qDebug()<<"#"<constraint_type == SANE_CONSTRAINT_STRING_LIST) { for(int si=0; opt->constraint.string_list[si]!=0; si++) { qDebug()<<"\t\t*"<constraint.string_list[si]); } if(name == bMode) { bModeIndex = i; binary = opt->constraint.string_list[bModeOptionIdx]; } } else if(opt->constraint_type == SANE_CONSTRAINT_WORD_LIST) { for (int j=1; j <= opt->constraint.word_list[0]; j++) { qDebug()<<"\t\t*"<< (opt->constraint.word_list[j]); } } else if(opt->constraint_type == SANE_CONSTRAINT_RANGE) { qDebug()<<"\t\t*"<< opt->constraint.range->min << opt->constraint.range->max << opt->constraint.range->quant; } } free(optionValue); } // return; qDebug()<<"Index"<name<title; sane_status = sane_control_option(h,bModeIndex,SANE_ACTION_SET_VALUE, binary.toAscii().data() ,0); if(ScanError("Sane can't set option")) return; sane_status = sane_start(h); if(ScanError("Sane can't start")) return; sane_status = sane_get_parameters(h, ¶ms); int W = params.pixels_per_line; int H = params.lines; qDebug()<<"Width:"<(buffer), len); qDebug()<<"Write"< 128) ? whiteColor : blackColor); dbgS.append((bv < 128) ? "#" : " "); } qDebug()<