ext/qrscanner/zxing/magick/src/qrscanner.cpp in qrscanner-0.3.1 vs ext/qrscanner/zxing/magick/src/qrscanner.cpp in qrscanner-0.4
- old
+ new
@@ -16,10 +16,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <iostream>
+#include <cstdio>
#include <fstream>
#include <string>
#include <Magick++.h>
#include "MagickBitmapSource.h"
#include <zxing/common/Counted.h>
@@ -56,31 +57,35 @@
Ref<Reader> reader(new MultiFormatReader);
return reader->decode(image, hints);
}
-extern "C" char *decode_qr_image(const char *fname) {
+extern "C" char *decode_qr_image(const char *fname, int dpi, int blur) {
string cell_result;
int res = -1;
Ref<BitMatrix> matrix(NULL);
Ref<Binarizer> binarizer(NULL);
const char* result_format = "";
-
- Image image;
- image.density(Geometry(300,300)); // for PDFs or vector input with low, incorrect DPI set eg. some Canon scanners
- try {
- image.read(fname);
- image.blur(2, 0.5);
- } catch (exception& e) {
- cerr << "exception: ";
- cerr << string(e.what()) << endl;
- } catch (...) {
- cerr << "Unable to open image" << endl;
- return(NULL);
+
+ Image image;
+ if(dpi) {
+ image.density(Geometry(dpi,dpi));
+ }
+ try {
+ image.read(fname);
+ if(blur) {
+ image.blur(2, ((double)blur)/10.0);
}
+ } catch (exception& e) {
+ cerr << "exception: ";
+ cerr << string(e.what()) << endl;
+ } catch (...) {
+ cerr << "Unable to open image" << endl;
+ return(NULL);
+ }
try {
Ref<MagickBitmapSource> source(new MagickBitmapSource(image));
@@ -93,12 +98,16 @@
Ref<Result> result(decode(binary, hints));
cell_result = result->getText()->getText();
result_format = barcodeFormatNames[result->getBarcodeFormat()];
res = 0;
} catch (ReaderException e) {
- cell_result = "zxing::ReaderException: " + string(e.what());
- res = -2;
+ if(strlen(e.what())==0) {
+ cell_result = "";
+ } else {
+ cell_result = "zxing::ReaderException: " + string(e.what());
+ res = -2;
+ }
} catch (zxing::IllegalArgumentException& e) {
cell_result = "zxing::IllegalArgumentException: " + string(e.what());
res = -3;
} catch (zxing::Exception& e) {
cell_result = "zxing::Exception: " + string(e.what());
@@ -107,10 +116,11 @@
cell_result = "std::exception: " + string(e.what());
res = -5;
}
if(res<0) {
- cerr << cell_result << endl;
+ if(cell_result.length() > 0)
+ cerr << cell_result << endl;
return(NULL);
}
return(strdup(cell_result.c_str()));
}