提交 0c62a595 authored 作者: tobyfan1980's avatar tobyfan1980

Merge commit 'cd4070b1' as 'vendor/qr-code-zxing'

.DS_Store
/.idea/
/build/
language: cpp
script: mkdir build && cd build && cmake -G "Unix Makefiles" .. && make
This project consists of contributions from several people, recognized here for convenience,
in alphabetical order.
Agustín Delgado (Servinform S.A.)
Aitor Almeida (University of Deusto)
Alasdair Mackintosh (Google)
Alex Dupre
Alexander Martin (Haase & Martin GmbH)
Alexander Schmidt
Anders Borg
Andreas Pillath
Andrew Walbran (Google)
Andrey Sitnik
Androida.hu / http://www.androida.hu/
Antonio Manuel Benjumea (Servinform S.A.)
Asier Iturralde
Asmuri Anwar
atereshchuk
Betaminos
Brian Brown (Google)
Bruce Allen
Chang Hyun Park
Christian Brunschen (Google)
Christoph Schulz (creatale GmbH)
crowdin.net
Daniel Switkin (Google)
Dave MacLachlan (Google)
David Phillip Oster (Google)
David Albert (Bug Labs)
David Olivier
David Walker (Google)
Diego Pierotto
Dion Hardy
drejc83
Eduardo Castillejo (University of Deusto)
Emanuele Aina
Eric Kobrin (Velocitude)
evansepdx
Erik Barbara
Francois B. (Google)
Frank Yellin
Fred Lin (Anobiit)
gcstang
Guenther Grau
Guillaume Le Biller
Hannes Erven
Hartmut Neubauer (Schweers Informationstechnologie GmbH)
hosigumayuugi
hypest (Barcorama project)
Ian W. Davis
Isaac Potoczny-Jones
Jacob Haynes (Google)
Jeff Breidenbach (Google)
Joan Montané (Softcatalà.cat)
John Connolly (Bug Labs)
Jonas Petersson (Prisjakt)
Joseph Wain (Google)
Juha Kuitunen
Juho Mikkonen
Jukka Nurmi
jwicks
Kamil Kaczmarczyk
Kazuki Nishiura
Kevin O'Sullivan (SITA)
Kevin Xue (NetDragon Websoft Inc., China)
Lachezar Dobrev
Loránt Gerencsér
Luiz Silva
Luka Finžgar
Łukasz Stefaniak
Malte Starostik
Manuel Kasten
Marcelo
Mateusz Jędrasik
Matthew Schulkind (Google)
Matt York (LifeMarks)
mike32767
mikej06
Mohamad Fairol
Morgan Courbet
Nikolaos Ftylitakis
Nikolaus Huber
Olli
Pablo Orduña (University of Deusto)
Paul Hackenberger
perennialmind
Radu Silaghi
Ralf Kistner
Randy Shen (Acer)
Rasmus Schrøder Sørensen
Richard Hřivňák
Romain Pechayre
Roman Nurik (Google)
Rustam Abdullaev
Ryan Alford
Sanford Squires
Satoshi Kametaya
Shachar Shemesh
Sean Owen (Google)
Shiyuan Guo / 郭世元
ShumovichY
Simon Flannery (Ericsson)
Stephen Furlani
Steven Parkes
stoty74
Suraj Supekar
Sven Klinkhamer
taku0
techinstantdx
Thomas Gerbet
Tim Gernat
v.anestis
Vince Francis (LifeMarks)
Wolfgang Jung
Yakov Okshtein (Google)
cmake_minimum_required(VERSION 3.0)
project(zxing)
option(BUILD_TESTING "Enable generation of test targets" OFF)
#set(CMAKE_LIBRARY_PATH /opt/local/lib ${CMAKE_LIBRARY_PATH})
# Check for polluted source tree.
# if(EXISTS ${CMAKE_SOURCE_DIR}/CMakeCache.txt OR
# EXISTS ${CMAKE_SOURCE_DIR}/CMakeFiles)
# message(FATAL_ERROR
# "Source directory is polluted:"
# "\n * remove CMakeCache.txt"
# "\n * remove CMakeFiles directory")
# endif()
# Suppress in-source builds.
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR
"CMake generation is not allowed within the source directory:"
"\n * mkdir build"
"\n * cd build"
"\n * Unix-like: cmake -G \"Unix Makefiles\" .."
"\n * Windows: cmake -G \"Visual Studio 10\" ..")
endif()
# Adjust CMake's module path.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/FindModules)
# Suppress MSVC CRT warnings.
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(/Za)
add_definitions(/MP) # multi-core builds
endif()
include(source_files.cmake)
if(WIN32)
include_directories(core/lib/win32)
set(CMAKE_DEBUG_POSTFIX -debug)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
# OpenCV classes
# find_package(OpenCV)
# if(OpenCV_FOUND)
# list(APPEND LIBZXING_FILES
# opencv/src/zxing/MatSource.cpp
# opencv/src/zxing/MatSource.h
# )
# include_directories(${OpenCV_INCLUDE_DIRS})
# include_directories(opencv/src)
# endif()
include_directories(core/src)
add_library(libzxing ${LIBZXING_FILES})
set_target_properties(libzxing PROPERTIES PREFIX "")
# find_package(Iconv)
# if(ICONV_FOUND)
# include_directories(${ICONV_INCLUDE_DIR})
# target_link_libraries(libzxing ${ICONV_LIBRARIES})
# else()
add_definitions(-DNO_ICONV=1)
# endif()
# Add OpenCV cli executable
# if(OpenCV_FOUND)
# file(GLOB_RECURSE OPENCV_ZXING_FILES
# "./opencv-cli/src/*.cpp"
# "./opencv-cli/src/*.h"
# )
# add_executable(zxing-cv ${OPENCV_ZXING_FILES})
# target_link_libraries(zxing-cv libzxing ${OpenCV_LIBRARIES})
# endif()
# Add cli executable.
file(GLOB_RECURSE ZXING_FILES
"./cli/src/*.cpp"
"./cli/src/*.h"
)
link_directories(/usr/lib/)
add_executable(zxing ${ZXING_FILES})
target_link_libraries(zxing libzxing)
install(TARGETS zxing libzxing EXPORT zxing-targets
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
INCLUDES DESTINATION include
)
install(EXPORT zxing-targets DESTINATION lib/zxing/cmake NAMESPACE zxing::)
install(
DIRECTORY core/src/zxing/
DESTINATION include/zxing
FILES_MATCHING PATTERN "*.h"
)
# if(OpenCV_FOUND)
# install(
# DIRECTORY opencv/src/zxing/
# DESTINATION include/zxing
# FILES_MATCHING PATTERN "*.h"
# )
# endif()
configure_file(cmake/zxing-config.cmake.in zxing-config.cmake @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/zxing-config.cmake DESTINATION lib/zxing/cmake)
# if(BUILD_TESTING)
# # Add testrunner executable.
# find_package(CPPUNIT)
# if(CPPUNIT_FOUND)
# file(GLOB_RECURSE TESTRUNNER_FILES
# "./core/tests/src/*.cpp"
# "./core/tests/src/*.h"
# )
# add_executable(testrunner ${TESTRUNNER_FILES})
# include_directories(${CPPUNIT_INCLUDE_DIR})
# target_link_libraries(testrunner libzxing ${CPPUNIT_LIBRARIES})
# endif()
# endif()
差异被折叠。
--------------------------------------------------------------------------------
NOTICES FOR ISO C9x compliant stdint.h for Microsoft Visual Studio
--------------------------------------------------------------------------------
Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
Copyright (c) 2006-2008 Alexander Chemeris
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
NOTICES FOR LodePNG
--------------------------------------------------------------------------------
Copyright (c) 2005-2013 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
--------------------------------------------------------------------------------
NOTICES FOR C++ Big Integer Library
--------------------------------------------------------------------------------
I, Matt McCutchen, the sole author of the original Big Integer
Library, waive my copyright to it, placing it in the public domain.
The library comes with absolutely no warranty.
# ZXing C++ Port
[![Build Status](https://travis-ci.org/glassechidna/zxing-cpp.svg?branch=master)](https://travis-ci.org/glassechidna/zxing-cpp)
[ZXing](https://github.com/zxing/zxing) is/was a Java library.
At some point a complete C++ port/rewrite was created and maintained in the official [ZXing](https://github.com/zxing/zxing) repo. However, at the time of writing the C++ port is no longer maintained and has been removed from the official ZXing repo.
This project was forked from the [last ZXing commit](https://github.com/zxing/zxing/commit/00f6340) to contain the C++ project, with the following exceptions
* scons (Python) build system has been deleted.
* Deleted black box tests, because they refer to a large test data in ZXing repo.
* Added appropriate copyright/licensing details (based on those in the ZXing repo).
* Updated README.md
Removal of build systems was done to minimise maintenance burden.
If tests and XCode projects (other than those produced automatically be CMake) are desired, then another repo should be created and this repo referenced as a submodule.
# Building using CMake
CMake is a tool, that generates native makefiles and workspaces. It integrates well with a number of IDEs including Qt Creator and Visual Studio.
Usage with CLion or Qt Creator:
1. Simply open `CMakeLists.txt` as a new project
2. Additional command line arguments can be specified (see below)
Usage with Makefiles, Visual Studio, etc. (see `cmake --help` for a complete list of generators):
1. `mkdir build`
2. `cd` to `build`
3. Unix: run `cmake -G "Unix Makefiles" ..`
3. Windows: run `cmake -G "Visual Studio 10" ..`
You can switch between build modes by specifying:
- `-DCMAKE_BUILD_TYPE=Debug` or
- `-DCMAKE_BUILD_TYPE=Release`
# OpenCV integration
When build on a system where opencv is installed the open cv bridge classes and executable will be built too.
# Development tips
To profile the code (very useful to optimize the code):
1. Install Valgrind
2. Run `valgrind --tool=callgrind build/zxing - path/to/test/data/*.jpg > report.html`
3. Analyze output using KCachegrind
/*
* Copyright 2010-2011 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ImageReaderSource.h"
#include <zxing/common/IllegalArgumentException.h>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include "lodepng.h"
#include "jpgd.h"
using std::string;
using std::ostringstream;
using zxing::Ref;
using zxing::ArrayRef;
using zxing::LuminanceSource;
inline char ImageReaderSource::convertPixel(char const* pixel_) const {
unsigned char const* pixel = (unsigned char const*)pixel_;
if (comps == 1 || comps == 2) {
// Gray or gray+alpha
return pixel[0];
} if (comps == 3 || comps == 4) {
// Red, Green, Blue, (Alpha)
// We assume 16 bit values here
// 0x200 = 1<<9, half an lsb of the result to force rounding
return (char)((306 * (int)pixel[0] + 601 * (int)pixel[1] +
117 * (int)pixel[2] + 0x200) >> 10);
} else {
throw zxing::IllegalArgumentException("Unexpected image depth");
}
}
ImageReaderSource::ImageReaderSource(ArrayRef<char> image_, int width, int height, int comps_)
: Super(width, height), image(image_), comps(comps_) {}
Ref<LuminanceSource> ImageReaderSource::create(string const& filename) {
string extension = filename.substr(filename.find_last_of(".") + 1);
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
int width, height;
int comps = 0;
zxing::ArrayRef<char> image;
if (extension == "png") {
std::vector<unsigned char> out;
{ unsigned w, h;
unsigned error = lodepng::decode(out, w, h, filename);
if (error) {
ostringstream msg;
msg << "Error while loading '" << lodepng_error_text(error) << "'";
throw zxing::IllegalArgumentException(msg.str().c_str());
}
width = w;
height = h;
}
comps = 4;
image = zxing::ArrayRef<char>(4 * width * height);
memcpy(&image[0], &out[0], image->size());
} else if (extension == "jpg" || extension == "jpeg") {
char *buffer = reinterpret_cast<char*>(jpgd::decompress_jpeg_image_from_file(
filename.c_str(), &width, &height, &comps, 4));
image = zxing::ArrayRef<char>(buffer, 4 * width * height);
free(buffer);
}
if (!image) {
ostringstream msg;
msg << "Loading \"" << filename << "\" failed.";
throw zxing::IllegalArgumentException(msg.str().c_str());
}
return Ref<LuminanceSource>(new ImageReaderSource(image, width, height, comps));
}
zxing::ArrayRef<char> ImageReaderSource::getRow(int y, zxing::ArrayRef<char> row) const {
const char* pixelRow = &image[0] + y * getWidth() * 4;
if (!row) {
row = zxing::ArrayRef<char>(getWidth());
}
for (int x = 0; x < getWidth(); x++) {
row[x] = convertPixel(pixelRow + (x * 4));
}
return row;
}
/** This is a more efficient implementation. */
zxing::ArrayRef<char> ImageReaderSource::getMatrix() const {
const char* p = &image[0];
zxing::ArrayRef<char> matrix(getWidth() * getHeight());
char* m = &matrix[0];
for (int y = 0; y < getHeight(); y++) {
for (int x = 0; x < getWidth(); x++) {
*m = convertPixel(p);
m++;
p += 4;
}
}
return matrix;
}
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
#ifndef __IMAGE_READER_SOURCE_H_
#define __IMAGE_READER_SOURCE_H_
/*
* Copyright 2010-2011 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <zxing/LuminanceSource.h>
class ImageReaderSource : public zxing::LuminanceSource {
private:
typedef LuminanceSource Super;
const zxing::ArrayRef<char> image;
const int comps;
char convertPixel(const char* pixel) const;
public:
static zxing::Ref<LuminanceSource> create(std::string const& filename);
ImageReaderSource(zxing::ArrayRef<char> image, int width, int height, int comps);
zxing::ArrayRef<char> getRow(int y, zxing::ArrayRef<char> row) const;
zxing::ArrayRef<char> getMatrix() const;
};
#endif /* __IMAGE_READER_SOURCE_H_ */
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
/*
* Copyright 2010-2011 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <iostream>
#include <fstream>
#include <string>
#include "ImageReaderSource.h"
#include <zxing/common/Counted.h>
#include <zxing/Binarizer.h>
#include <zxing/MultiFormatReader.h>
#include <zxing/Result.h>
#include <zxing/ReaderException.h>
#include <zxing/common/GlobalHistogramBinarizer.h>
#include <zxing/common/HybridBinarizer.h>
#include <exception>
#include <zxing/Exception.h>
#include <zxing/common/IllegalArgumentException.h>
#include <zxing/BinaryBitmap.h>
#include <zxing/DecodeHints.h>
#include <zxing/qrcode/QRCodeReader.h>
#include <zxing/multi/qrcode/QRCodeMultiReader.h>
#include <zxing/multi/ByQuadrantReader.h>
#include <zxing/multi/MultipleBarcodeReader.h>
#include <zxing/multi/GenericMultipleBarcodeReader.h>
using namespace std;
using namespace zxing;
using namespace zxing::multi;
using namespace zxing::qrcode;
namespace {
bool more = false;
bool test_mode = false;
bool try_harder = false;
bool search_multi = false;
bool use_hybrid = false;
bool use_global = false;
bool verbose = false;
}
vector<Ref<Result> > decode(Ref<BinaryBitmap> image, DecodeHints hints) {
Ref<Reader> reader(new MultiFormatReader);
return vector<Ref<Result> >(1, reader->decode(image, hints));
}
vector<Ref<Result> > decode_multi(Ref<BinaryBitmap> image, DecodeHints hints) {
MultiFormatReader delegate;
GenericMultipleBarcodeReader reader(delegate);
return reader.decodeMultiple(image, hints);
}
int read_image(Ref<LuminanceSource> source, bool hybrid, string expected) {
vector<Ref<Result> > results;
string cell_result;
int res = -1;
try {
Ref<Binarizer> binarizer;
if (hybrid) {
binarizer = new HybridBinarizer(source);
} else {
binarizer = new GlobalHistogramBinarizer(source);
}
// we use default hint as QR code
// but it can alse decode barcode
// DecodeHints hints(DecodeHints::QR_CODE_HINT);
DecodeHints hints(DecodeHints::DEFAULT_HINT);
hints.setTryHarder(try_harder);
Ref<BinaryBitmap> binary(new BinaryBitmap(binarizer));
if (search_multi) {
results = decode_multi(binary, hints);
} else {
results = decode(binary, hints);
}
res = 0;
} catch (const ReaderException& e) {
cell_result = "zxing::ReaderException: " + string(e.what());
res = -2;
} catch (const zxing::IllegalArgumentException& e) {
cell_result = "zxing::IllegalArgumentException: " + string(e.what());
res = -3;
} catch (const zxing::Exception& e) {
cell_result = "zxing::Exception: " + string(e.what());
res = -4;
} catch (const std::exception& e) {
cell_result = "std::exception: " + string(e.what());
res = -5;
}
if (test_mode && results.size() == 1) {
std::string result = results[0]->getText()->getText();
if (expected.empty()) {
cout << " Expected text or binary data for image missing." << endl
<< " Detected: " << result << endl;
res = -6;
} else {
if (expected.compare(result) != 0) {
cout << " Expected: " << expected << endl
<< " Detected: " << result << endl;
cell_result = "data did not match";
res = -6;
}
}
}
if (res != 0 && (verbose || (use_global ^ use_hybrid))) {
cout << (hybrid ? "Hybrid" : "Global")
<< " binarizer failed: " << cell_result << endl;
} else if (!test_mode) {
if (verbose) {
cout << (hybrid ? "Hybrid" : "Global")
<< " binarizer succeeded: " << endl;
}
for (size_t i = 0; i < results.size(); i++) {
if (more) {
cout << " Format: "
<< BarcodeFormat::barcodeFormatNames[results[i]->getBarcodeFormat()]
<< endl;
for (int j = 0; j < results[i]->getResultPoints()->size(); j++) {
cout << " Point[" << j << "]: "
<< results[i]->getResultPoints()[j]->getX() << " "
<< results[i]->getResultPoints()[j]->getY() << endl;
}
}
if (verbose) {
cout << " ";
}
cout << results[i]->getText()->getText() << endl;
}
}
return res;
}
// this is for testing perpose
string read_expected(string imagefilename) {
string textfilename = imagefilename;
string::size_type dotpos = textfilename.rfind(".");
textfilename.replace(dotpos + 1, textfilename.length() - dotpos - 1, "txt");
ifstream textfile(textfilename.c_str(), ios::binary);
textfilename.replace(dotpos + 1, textfilename.length() - dotpos - 1, "bin");
ifstream binfile(textfilename.c_str(), ios::binary);
ifstream *file = 0;
if (textfile.is_open()) {
file = &textfile;
} else if (binfile.is_open()) {
file = &binfile;
} else {
return std::string();
}
file->seekg(0, ios_base::end);
size_t size = size_t(file->tellg());
file->seekg(0, ios_base::beg);
if (size == 0) {
return std::string();
}
char* data = new char[size + 1];
file->read(data, size);
data[size] = '\0';
string expected(data);
delete[] data;
return expected;
}
int main(int argc, char** argv) {
if (argc <= 1) {
cout << "Usage: " << argv[0] << " [OPTION]... <IMAGE>..." << endl
<< "Read barcodes from each IMAGE file." << endl
<< endl
<< "Options:" << endl
<< " (-h|--hybrid) use the hybrid binarizer (default)" << endl
<< " (-g|--global) use the global binarizer" << endl
<< " (-v|--verbose) chattier results printing" << endl
<< " --more display more information about the barcode" << endl
<< " --test-mode compare IMAGEs against text files" << endl
<< " --try-harder spend more time to try to find a barcode" << endl
<< " --search-multi search for more than one bar code" << endl
<< endl
<< "Example usage:" << endl
<< " zxing --test-mode *.jpg" << endl
<< endl;
return 1;
}
int total = 0;
int gonly = 0;
int honly = 0;
int both = 0;
int neither = 0;
for (int i = 1; i < argc; i++) {
string filename = argv[i];
if (filename.compare("--verbose") == 0 ||
filename.compare("-v") == 0) {
verbose = true;
continue;
}
if (filename.compare("--hybrid") == 0 ||
filename.compare("-h") == 0) {
use_hybrid = true;
continue;
}
if (filename.compare("--global") == 0 ||
filename.compare("-g") == 0) {
use_global = true;
continue;
}
if (filename.compare("--more") == 0) {
more = true;
continue;
}
if (filename.compare("--test-mode") == 0) {
test_mode = true;
continue;
}
if (filename.compare("--try-harder") == 0) {
try_harder = true;
continue;
}
if (filename.compare("--search-multi") == 0){
search_multi = true;
continue;
}
if (filename.length() > 3 &&
(filename.substr(filename.length() - 3, 3).compare("txt") == 0 ||
filename.substr(filename.length() - 3, 3).compare("bin") == 0)) {
continue;
}
if (!use_global && !use_hybrid) {
use_global = use_hybrid = true;
}
if (test_mode) {
cerr << "Testing: " << filename << endl;
}
Ref<LuminanceSource> source;
try {
source = ImageReaderSource::create(filename);
} catch (const zxing::IllegalArgumentException &e) {
cerr << e.what() << " (ignoring)" << endl;
continue;
}
string expected = read_expected(filename);
int gresult = 1;
int hresult = 1;
if (use_hybrid) {
hresult = read_image(source, true, expected);
}
if (use_global && (verbose || hresult != 0)) {
gresult = read_image(source, false, expected);
if (!verbose && gresult != 0) {
cout << "decoding failed" << endl;
}
}
gresult = gresult == 0;
hresult = hresult == 0;
gonly += gresult && !hresult;
honly += hresult && !gresult;
both += gresult && hresult;
neither += !gresult && !hresult;
total = total + 1;
}
if (test_mode) {
cout << endl
<< "Summary:" << endl
<< " " << total << " images tested total," << endl
<< " " << (honly + both) << " passed hybrid, " << (gonly + both)
<< " passed global, " << both << " pass both, " << endl
<< " " << honly << " passed only hybrid, " << gonly
<< " passed only global, " << neither << " pass neither." << endl;
}
return 0;
}
#
# Find the CppUnit includes and library
#
# This module defines
# CPPUNIT_INCLUDE_DIR, where to find tiff.h, etc.
# CPPUNIT_LIBRARIES, the libraries to link against to use CppUnit.
# CPPUNIT_FOUND, If false, do not try to use CppUnit.
# also defined, but not for general use are
# CPPUNIT_LIBRARY, where to find the CppUnit library.
# CPPUNIT_DEBUG_LIBRARY, where to find the CppUnit library in debug
# mode.
SET(CPPUNIT_FOUND "NO")
FIND_PATH(CPPUNIT_INCLUDE_DIR cppunit/TestCase.h /usr/local/include /usr/include)
# With Win32, important to have both
IF(WIN32)
FIND_LIBRARY(CPPUNIT_LIBRARY cppunit
${CPPUNIT_INCLUDE_DIR}/../lib
/usr/local/lib
/usr/lib)
FIND_LIBRARY(CPPUNIT_DEBUG_LIBRARY cppunitd
${CPPUNIT_INCLUDE_DIR}/../lib
/usr/local/lib
/usr/lib)
ELSE(WIN32)
# On unix system, debug and release have the same name
FIND_LIBRARY(CPPUNIT_LIBRARY cppunit
${CPPUNIT_INCLUDE_DIR}/../lib
/usr/local/lib
/usr/lib)
FIND_LIBRARY(CPPUNIT_DEBUG_LIBRARY cppunit
${CPPUNIT_INCLUDE_DIR}/../lib
/usr/local/lib
/usr/lib)
ENDIF(WIN32)
IF(CPPUNIT_INCLUDE_DIR)
IF(CPPUNIT_LIBRARY)
SET(CPPUNIT_FOUND "YES")
SET(CPPUNIT_LIBRARIES ${CPPUNIT_LIBRARY} ${CMAKE_DL_LIBS})
SET(CPPUNIT_DEBUG_LIBRARIES ${CPPUNIT_DEBUG_LIBRARY} ${CMAKE_DL_LIBS})
ELSE (CPPUNIT_LIBRARY)
IF (CPPUNIT_FIND_REQUIRED)
MESSAGE(SEND_ERROR "Could not find library CppUnit.")
ENDIF (CPPUNIT_FIND_REQUIRED)
ENDIF(CPPUNIT_LIBRARY)
ELSE(CPPUNIT_INCLUDE_DIR)
IF (CPPUNIT_FIND_REQUIRED)
MESSAGE(SEND_ERROR "Could not find library CppUnit.")
ENDIF(CPPUNIT_FIND_REQUIRED)
ENDIF(CPPUNIT_INCLUDE_DIR)
function(_iconv_find)
if(ICONV_ROOT)
list(APPEND iconv_roots ${ICONV_ROOT})
else()
if(NOT "$ENV{ICONV_ROOT}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{ICONV_ROOT}" NATIVE_PATH)
list(APPEND iconv_roots "${NATIVE_PATH}")
set(ICONV_ROOT "${NATIVE_PATH}"
CACHE PATH "Location of the Iconv installation" FORCE)
endif()
endif()
list(APPEND iconv_library_suffixes "lib")
list(APPEND iconv_include_suffixes "include")
find_path(ICONV_INCLUDE_DIR
NAMES "iconv.h"
HINTS ${iconv_roots}
PATH_SUFFIXES ${iconv_include_suffixes}
DOC "Iconv include directory")
set(ICONV_INCLUDE_DIR "${ICONV_INCLUDE_DIR}" PARENT_SCOPE)
find_library(ICONV_LIBRARIES
NAMES
iconv
libiconv
libiconv2
HINTS ${iconv_roots}
PATH_SUFFIXES ${iconv_library_suffixes}
DOC "Iconv library")
set(ICONV_LIBRARIES "${ICONV_LIBRARIES}" PARENT_SCOPE)
if(ICONV_INCLUDE_DIR AND NOT ICONV_LIBRARIES)
include(CheckFunctionExists)
check_function_exists(iconv HAVE_ICONV_IN_LIBC)
if(HAVE_ICONV_IN_LIBC)
set(HAVE_ICONV_IN_LIBC "${HAVE_ICONV_IN_LIBC}" PARENT_SCOPE)
set(ICONV_LIBRARIES "integrated in standard library" PARENT_SCOPE)
endif()
endif()
if(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
set(ICONV_FOUND ON PARENT_SCOPE)
endif()
endfunction()
_iconv_find()
if(ICONV_FOUND)
if(NOT ICONV_FIND_QUIETLY)
message(STATUS "Found iconv library: ${ICONV_LIBRARY}")
endif()
if(HAVE_ICONV_IN_LIBC)
set(_lib_type INTERFACE)
else()
set(_lib_type UNKNOWN)
endif()
add_library(Iconv::Iconv ${_lib_type} IMPORTED)
set_target_properties(Iconv::Iconv PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ICONV_INCLUDE_DIR}")
if(NOT HAVE_ICONV_IN_LIBC)
set_target_properties(Iconv::Iconv PROPERTIES
IMPORTED_LOCATION "${ICONV_LIBRARIES}")
endif()
unset(_lib_type)
else()
if(ICONV_FIND_REQUIRED)
message(FATAL_ERROR "Could NOT find iconv library")
endif()
endif()
mark_as_advanced(ICONV_LIBRARIES ICONV_INCLUDE_DIR)
include(${CMAKE_CURRENT_LIST_DIR}/zxing-targets.cmake)
*.o
sample
testsuite
testsuite.expected
testsuite.out
testsuite.err
#ifndef BIGINTEGER_H
#define BIGINTEGER_H
#include "BigUnsigned.hh"
/* A BigInteger object represents a signed integer of size limited only by
* available memory. BigUnsigneds support most mathematical operators and can
* be converted to and from most primitive integer types.
*
* A BigInteger is just an aggregate of a BigUnsigned and a sign. (It is no
* longer derived from BigUnsigned because that led to harmful implicit
* conversions.) */
class BigInteger {
public:
typedef BigUnsigned::Blk Blk;
typedef BigUnsigned::Index Index;
typedef BigUnsigned::CmpRes CmpRes;
static const CmpRes
less = BigUnsigned::less ,
equal = BigUnsigned::equal ,
greater = BigUnsigned::greater;
// Enumeration for the sign of a BigInteger.
enum Sign { negative = -1, zero = 0, positive = 1 };
protected:
Sign sign;
BigUnsigned mag;
public:
// Constructs zero.
BigInteger() : sign(zero), mag() {}
// Copy constructor
BigInteger(const BigInteger &x) : sign(x.sign), mag(x.mag) {};
// Assignment operator
void operator=(const BigInteger &x);
// Constructor that copies from a given array of blocks with a sign.
BigInteger(const Blk *b, Index blen, Sign s);
// Nonnegative constructor that copies from a given array of blocks.
BigInteger(const Blk *b, Index blen) : mag(b, blen) {
sign = mag.isZero() ? zero : positive;
}
// Constructor from a BigUnsigned and a sign
BigInteger(const BigUnsigned &x, Sign s);
// Nonnegative constructor from a BigUnsigned
BigInteger(const BigUnsigned &x) : mag(x) {
sign = mag.isZero() ? zero : positive;
}
// Constructors from primitive integer types
BigInteger(unsigned long x);
BigInteger( long x);
BigInteger(unsigned int x);
BigInteger( int x);
BigInteger(unsigned short x);
BigInteger( short x);
/* Converters to primitive integer types
* The implicit conversion operators caused trouble, so these are now
* named. */
unsigned long toUnsignedLong () const;
long toLong () const;
unsigned int toUnsignedInt () const;
int toInt () const;
unsigned short toUnsignedShort() const;
short toShort () const;
protected:
// Helper
template <class X> X convertToUnsignedPrimitive() const;
template <class X, class UX> X convertToSignedPrimitive() const;
public:
// ACCESSORS
Sign getSign() const { return sign; }
/* The client can't do any harm by holding a read-only reference to the
* magnitude. */
const BigUnsigned &getMagnitude() const { return mag; }
// Some accessors that go through to the magnitude
Index getLength() const { return mag.getLength(); }
Index getCapacity() const { return mag.getCapacity(); }
Blk getBlock(Index i) const { return mag.getBlock(i); }
bool isZero() const { return sign == zero; } // A bit special
// COMPARISONS
// Compares this to x like Perl's <=>
CmpRes compareTo(const BigInteger &x) const;
// Ordinary comparison operators
bool operator ==(const BigInteger &x) const {
return sign == x.sign && mag == x.mag;
}
bool operator !=(const BigInteger &x) const { return !operator ==(x); };
bool operator < (const BigInteger &x) const { return compareTo(x) == less ; }
bool operator <=(const BigInteger &x) const { return compareTo(x) != greater; }
bool operator >=(const BigInteger &x) const { return compareTo(x) != less ; }
bool operator > (const BigInteger &x) const { return compareTo(x) == greater; }
// OPERATORS -- See the discussion in BigUnsigned.hh.
void add (const BigInteger &a, const BigInteger &b);
void subtract(const BigInteger &a, const BigInteger &b);
void multiply(const BigInteger &a, const BigInteger &b);
/* See the comment on BigUnsigned::divideWithRemainder. Semantics
* differ from those of primitive integers when negatives and/or zeros
* are involved. */
void divideWithRemainder(const BigInteger &b, BigInteger &q);
void negate(const BigInteger &a);
/* Bitwise operators are not provided for BigIntegers. Use
* getMagnitude to get the magnitude and operate on that instead. */
BigInteger operator +(const BigInteger &x) const;
BigInteger operator -(const BigInteger &x) const;
BigInteger operator *(const BigInteger &x) const;
BigInteger operator /(const BigInteger &x) const;
BigInteger operator %(const BigInteger &x) const;
BigInteger operator -() const;
void operator +=(const BigInteger &x);
void operator -=(const BigInteger &x);
void operator *=(const BigInteger &x);
void operator /=(const BigInteger &x);
void operator %=(const BigInteger &x);
void flipSign();
// INCREMENT/DECREMENT OPERATORS
void operator ++( );
void operator ++(int);
void operator --( );
void operator --(int);
};
// NORMAL OPERATORS
/* These create an object to hold the result and invoke
* the appropriate put-here operation on it, passing
* this and x. The new object is then returned. */
inline BigInteger BigInteger::operator +(const BigInteger &x) const {
BigInteger ans;
ans.add(*this, x);
return ans;
}
inline BigInteger BigInteger::operator -(const BigInteger &x) const {
BigInteger ans;
ans.subtract(*this, x);
return ans;
}
inline BigInteger BigInteger::operator *(const BigInteger &x) const {
BigInteger ans;
ans.multiply(*this, x);
return ans;
}
inline BigInteger BigInteger::operator /(const BigInteger &x) const {
if (x.isZero()) throw "BigInteger::operator /: division by zero";
BigInteger q, r;
r = *this;
r.divideWithRemainder(x, q);
return q;
}
inline BigInteger BigInteger::operator %(const BigInteger &x) const {
if (x.isZero()) throw "BigInteger::operator %: division by zero";
BigInteger q, r;
r = *this;
r.divideWithRemainder(x, q);
return r;
}
inline BigInteger BigInteger::operator -() const {
BigInteger ans;
ans.negate(*this);
return ans;
}
/*
* ASSIGNMENT OPERATORS
*
* Now the responsibility for making a temporary copy if necessary
* belongs to the put-here operations. See Assignment Operators in
* BigUnsigned.hh.
*/
inline void BigInteger::operator +=(const BigInteger &x) {
add(*this, x);
}
inline void BigInteger::operator -=(const BigInteger &x) {
subtract(*this, x);
}
inline void BigInteger::operator *=(const BigInteger &x) {
multiply(*this, x);
}
inline void BigInteger::operator /=(const BigInteger &x) {
if (x.isZero()) throw "BigInteger::operator /=: division by zero";
/* The following technique is slightly faster than copying *this first
* when x is large. */
BigInteger q;
divideWithRemainder(x, q);
// *this contains the remainder, but we overwrite it with the quotient.
*this = q;
}
inline void BigInteger::operator %=(const BigInteger &x) {
if (x.isZero()) throw "BigInteger::operator %=: division by zero";
BigInteger q;
// Mods *this by x. Don't care about quotient left in q.
divideWithRemainder(x, q);
}
// This one is trivial
inline void BigInteger::flipSign() {
sign = Sign(-sign);
}
#endif
#include "BigIntegerAlgorithms.hh"
BigUnsigned gcd(BigUnsigned a, BigUnsigned b) {
BigUnsigned trash;
// Neat in-place alternating technique.
for (;;) {
if (b.isZero())
return a;
a.divideWithRemainder(b, trash);
if (a.isZero())
return b;
b.divideWithRemainder(a, trash);
}
}
void extendedEuclidean(BigInteger m, BigInteger n,
BigInteger &g, BigInteger &r, BigInteger &s) {
if (&g == &r || &g == &s || &r == &s)
throw "BigInteger extendedEuclidean: Outputs are aliased";
BigInteger r1(1), s1(0), r2(0), s2(1), q;
/* Invariants:
* r1*m(orig) + s1*n(orig) == m(current)
* r2*m(orig) + s2*n(orig) == n(current) */
for (;;) {
if (n.isZero()) {
r = r1; s = s1; g = m;
return;
}
// Subtract q times the second invariant from the first invariant.
m.divideWithRemainder(n, q);
r1 -= q*r2; s1 -= q*s2;
if (m.isZero()) {
r = r2; s = s2; g = n;
return;
}
// Subtract q times the first invariant from the second invariant.
n.divideWithRemainder(m, q);
r2 -= q*r1; s2 -= q*s1;
}
}
BigUnsigned modinv(const BigInteger &x, const BigUnsigned &n) {
BigInteger g, r, s;
extendedEuclidean(x, n, g, r, s);
if (g == 1)
// r*x + s*n == 1, so r*x === 1 (mod n), so r is the answer.
return (r % n).getMagnitude(); // (r % n) will be nonnegative
else
throw "BigInteger modinv: x and n have a common factor";
}
BigUnsigned modexp(const BigInteger &base, const BigUnsigned &exponent,
const BigUnsigned &modulus) {
BigUnsigned ans = 1, base2 = (base % modulus).getMagnitude();
BigUnsigned::Index i = exponent.bitLength();
// For each bit of the exponent, most to least significant...
while (i > 0) {
i--;
// Square.
ans *= ans;
ans %= modulus;
// And multiply if the bit is a 1.
if (exponent.getBit(i)) {
ans *= base2;
ans %= modulus;
}
}
return ans;
}
#ifndef BIGINTEGERALGORITHMS_H
#define BIGINTEGERALGORITHMS_H
#include "BigInteger.hh"
/* Some mathematical algorithms for big integers.
* This code is new and, as such, experimental. */
// Returns the greatest common divisor of a and b.
BigUnsigned gcd(BigUnsigned a, BigUnsigned b);
/* Extended Euclidean algorithm.
* Given m and n, finds gcd g and numbers r, s such that r*m + s*n == g. */
void extendedEuclidean(BigInteger m, BigInteger n,
BigInteger &g, BigInteger &r, BigInteger &s);
/* Returns the multiplicative inverse of x modulo n, or throws an exception if
* they have a common factor. */
BigUnsigned modinv(const BigInteger &x, const BigUnsigned &n);
// Returns (base ^ exponent) % modulus.
BigUnsigned modexp(const BigInteger &base, const BigUnsigned &exponent,
const BigUnsigned &modulus);
#endif
// This header file includes all of the library header files.
#include "NumberlikeArray.hh"
#include "BigUnsigned.hh"
#include "BigInteger.hh"
#include "BigIntegerAlgorithms.hh"
#include "BigUnsignedInABase.hh"
#include "BigIntegerUtils.hh"
差异被折叠。
差异被折叠。
差异被折叠。
#ifndef _LIBICONV_H
#define _LIBICONV_H
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void* iconv_t;
iconv_t iconv_open(const char *tocode, const char *fromcode);
int iconv_close(iconv_t cd);
size_t iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
#ifdef __cplusplus
}
#endif
#endif//_LIBICONV_H
\ No newline at end of file
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论