const-ness and iphone/objc fixes

git-svn-id: https://zxing.googlecode.com/svn/trunk@2628 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
smparkes@smparkes.net 2013-04-06 21:30:17 +00:00
parent 0c7e4d5fcc
commit 12387c2f81
9 changed files with 70 additions and 93 deletions

View file

@ -69,15 +69,12 @@ ArrayRef<char> GreyscaleLuminanceSource::getMatrix() const {
return result; return result;
} }
extern "C" void abort(); Ref<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise() const {
Ref<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise() {
// Intentionally flip the left, top, width, and height arguments as // Intentionally flip the left, top, width, and height arguments as
// needed. dataWidth and dataHeight are always kept unrotated. // needed. dataWidth and dataHeight are always kept unrotated.
Ref<LuminanceSource> result ( Ref<LuminanceSource> result (
new GreyscaleRotatedLuminanceSource(greyData_, new GreyscaleRotatedLuminanceSource(greyData_,
dataWidth_, dataHeight_, dataWidth_, dataHeight_,
top_, left_, getHeight(), getWidth()) top_, left_, getHeight(), getWidth()));
);
return result; return result;
} }

View file

@ -45,8 +45,7 @@ public:
return true; return true;
} }
Ref<LuminanceSource> rotateCounterClockwise(); Ref<LuminanceSource> rotateCounterClockwise() const;
}; };
} }

View file

@ -39,10 +39,6 @@ public:
ArrayRef<char> getRow(int y, ArrayRef<char> row) const; ArrayRef<char> getRow(int y, ArrayRef<char> row) const;
ArrayRef<char> getMatrix() const; ArrayRef<char> getMatrix() const;
bool isRotateSupported() const {
return false;
}
}; };
} }

View file

@ -13,6 +13,7 @@
3B5A493617091826004E112F /* CodaBarReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B5A493217091826004E112F /* CodaBarReader.h */; }; 3B5A493617091826004E112F /* CodaBarReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B5A493217091826004E112F /* CodaBarReader.h */; };
3B5A493717091826004E112F /* Code93Reader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B5A493317091826004E112F /* Code93Reader.cpp */; }; 3B5A493717091826004E112F /* Code93Reader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B5A493317091826004E112F /* Code93Reader.cpp */; };
3B5A493817091826004E112F /* Code93Reader.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B5A493417091826004E112F /* Code93Reader.h */; }; 3B5A493817091826004E112F /* Code93Reader.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B5A493417091826004E112F /* Code93Reader.h */; };
3B6AA6711710C83200DF84C0 /* InvertedLuminanceSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B6AA6701710C83200DF84C0 /* InvertedLuminanceSource.cpp */; };
3B83E992158E66C600A3B31F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B83E991158E66C600A3B31F /* Foundation.framework */; }; 3B83E992158E66C600A3B31F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B83E991158E66C600A3B31F /* Foundation.framework */; };
3B83EA63158E679000A3B31F /* AztecDetectorResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B83E9A4158E679000A3B31F /* AztecDetectorResult.cpp */; }; 3B83EA63158E679000A3B31F /* AztecDetectorResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B83E9A4158E679000A3B31F /* AztecDetectorResult.cpp */; };
3B83EA64158E679000A3B31F /* AztecDetectorResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B83E9A5158E679000A3B31F /* AztecDetectorResult.h */; }; 3B83EA64158E679000A3B31F /* AztecDetectorResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B83E9A5158E679000A3B31F /* AztecDetectorResult.h */; };
@ -196,6 +197,7 @@
3B5A493217091826004E112F /* CodaBarReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CodaBarReader.h; sourceTree = "<group>"; }; 3B5A493217091826004E112F /* CodaBarReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CodaBarReader.h; sourceTree = "<group>"; };
3B5A493317091826004E112F /* Code93Reader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Code93Reader.cpp; sourceTree = "<group>"; }; 3B5A493317091826004E112F /* Code93Reader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Code93Reader.cpp; sourceTree = "<group>"; };
3B5A493417091826004E112F /* Code93Reader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Code93Reader.h; sourceTree = "<group>"; }; 3B5A493417091826004E112F /* Code93Reader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Code93Reader.h; sourceTree = "<group>"; };
3B6AA6701710C83200DF84C0 /* InvertedLuminanceSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InvertedLuminanceSource.cpp; sourceTree = "<group>"; };
3B83E98E158E66C600A3B31F /* libzxing-cpp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libzxing-cpp.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 3B83E98E158E66C600A3B31F /* libzxing-cpp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libzxing-cpp.a"; sourceTree = BUILT_PRODUCTS_DIR; };
3B83E991158E66C600A3B31F /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 3B83E991158E66C600A3B31F /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
3B83E9A4158E679000A3B31F /* AztecDetectorResult.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AztecDetectorResult.cpp; sourceTree = "<group>"; }; 3B83E9A4158E679000A3B31F /* AztecDetectorResult.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AztecDetectorResult.cpp; sourceTree = "<group>"; };
@ -419,6 +421,7 @@
3B83E9A2158E679000A3B31F /* zxing */ = { 3B83E9A2158E679000A3B31F /* zxing */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
3B6AA6701710C83200DF84C0 /* InvertedLuminanceSource.cpp */,
3B5A492D17091807004E112F /* ChecksumException.cpp */, 3B5A492D17091807004E112F /* ChecksumException.cpp */,
3B5A492E17091807004E112F /* ChecksumException.h */, 3B5A492E17091807004E112F /* ChecksumException.h */,
3B83E9A3158E679000A3B31F /* aztec */, 3B83E9A3158E679000A3B31F /* aztec */,
@ -980,6 +983,7 @@
3B5A492F17091807004E112F /* ChecksumException.cpp in Sources */, 3B5A492F17091807004E112F /* ChecksumException.cpp in Sources */,
3B5A493517091826004E112F /* CodaBarReader.cpp in Sources */, 3B5A493517091826004E112F /* CodaBarReader.cpp in Sources */,
3B5A493717091826004E112F /* Code93Reader.cpp in Sources */, 3B5A493717091826004E112F /* Code93Reader.cpp in Sources */,
3B6AA6711710C83200DF84C0 /* InvertedLuminanceSource.cpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View file

@ -141,6 +141,8 @@
3B27C5E2144735E6005157C4 /* CharacterSetECI.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B27C5DC144735E6005157C4 /* CharacterSetECI.h */; }; 3B27C5E2144735E6005157C4 /* CharacterSetECI.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B27C5DC144735E6005157C4 /* CharacterSetECI.h */; };
3B27C5E5144735E6005157C4 /* StringUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B27C5DF144735E6005157C4 /* StringUtils.cpp */; }; 3B27C5E5144735E6005157C4 /* StringUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B27C5DF144735E6005157C4 /* StringUtils.cpp */; };
3B27C5E6144735E6005157C4 /* StringUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B27C5E0144735E6005157C4 /* StringUtils.h */; }; 3B27C5E6144735E6005157C4 /* StringUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B27C5E0144735E6005157C4 /* StringUtils.h */; };
3B6AA66C1710C34600DF84C0 /* InvertedLuminanceSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B6AA66A1710C34600DF84C0 /* InvertedLuminanceSource.cpp */; };
3B6AA66D1710C34600DF84C0 /* InvertedLuminanceSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B6AA66B1710C34600DF84C0 /* InvertedLuminanceSource.h */; };
3B6C805717090ED300D22AB2 /* CodaBarReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B6C805317090ED300D22AB2 /* CodaBarReader.cpp */; }; 3B6C805717090ED300D22AB2 /* CodaBarReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B6C805317090ED300D22AB2 /* CodaBarReader.cpp */; };
3B6C805817090ED300D22AB2 /* CodaBarReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B6C805417090ED300D22AB2 /* CodaBarReader.h */; }; 3B6C805817090ED300D22AB2 /* CodaBarReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B6C805417090ED300D22AB2 /* CodaBarReader.h */; };
3B6C805917090ED300D22AB2 /* Code93Reader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B6C805517090ED300D22AB2 /* Code93Reader.cpp */; }; 3B6C805917090ED300D22AB2 /* Code93Reader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B6C805517090ED300D22AB2 /* Code93Reader.cpp */; };
@ -435,6 +437,8 @@
3B27C5DC144735E6005157C4 /* CharacterSetECI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CharacterSetECI.h; sourceTree = "<group>"; }; 3B27C5DC144735E6005157C4 /* CharacterSetECI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CharacterSetECI.h; sourceTree = "<group>"; };
3B27C5DF144735E6005157C4 /* StringUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringUtils.cpp; sourceTree = "<group>"; }; 3B27C5DF144735E6005157C4 /* StringUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringUtils.cpp; sourceTree = "<group>"; };
3B27C5E0144735E6005157C4 /* StringUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringUtils.h; sourceTree = "<group>"; }; 3B27C5E0144735E6005157C4 /* StringUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringUtils.h; sourceTree = "<group>"; };
3B6AA66A1710C34600DF84C0 /* InvertedLuminanceSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InvertedLuminanceSource.cpp; sourceTree = "<group>"; };
3B6AA66B1710C34600DF84C0 /* InvertedLuminanceSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InvertedLuminanceSource.h; sourceTree = "<group>"; };
3B6C805317090ED300D22AB2 /* CodaBarReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CodaBarReader.cpp; sourceTree = "<group>"; }; 3B6C805317090ED300D22AB2 /* CodaBarReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CodaBarReader.cpp; sourceTree = "<group>"; };
3B6C805417090ED300D22AB2 /* CodaBarReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CodaBarReader.h; sourceTree = "<group>"; }; 3B6C805417090ED300D22AB2 /* CodaBarReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CodaBarReader.h; sourceTree = "<group>"; };
3B6C805517090ED300D22AB2 /* Code93Reader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Code93Reader.cpp; sourceTree = "<group>"; }; 3B6C805517090ED300D22AB2 /* Code93Reader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Code93Reader.cpp; sourceTree = "<group>"; };
@ -754,6 +758,8 @@
E53458B411987396000CB77F /* zxing */ = { E53458B411987396000CB77F /* zxing */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
3B6AA66A1710C34600DF84C0 /* InvertedLuminanceSource.cpp */,
3B6AA66B1710C34600DF84C0 /* InvertedLuminanceSource.h */,
3B6C805B17090EFC00D22AB2 /* ChecksumException.cpp */, 3B6C805B17090EFC00D22AB2 /* ChecksumException.cpp */,
3B6C805C17090EFC00D22AB2 /* ChecksumException.h */, 3B6C805C17090EFC00D22AB2 /* ChecksumException.h */,
3B248F8314EF3A980065F0DA /* aztec */, 3B248F8314EF3A980065F0DA /* aztec */,
@ -1226,6 +1232,7 @@
3B6C805817090ED300D22AB2 /* CodaBarReader.h in Headers */, 3B6C805817090ED300D22AB2 /* CodaBarReader.h in Headers */,
3B6C805A17090ED300D22AB2 /* Code93Reader.h in Headers */, 3B6C805A17090ED300D22AB2 /* Code93Reader.h in Headers */,
3B6C805E17090EFC00D22AB2 /* ChecksumException.h in Headers */, 3B6C805E17090EFC00D22AB2 /* ChecksumException.h in Headers */,
3B6AA66D1710C34600DF84C0 /* InvertedLuminanceSource.h in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -1474,6 +1481,7 @@
3B6C805717090ED300D22AB2 /* CodaBarReader.cpp in Sources */, 3B6C805717090ED300D22AB2 /* CodaBarReader.cpp in Sources */,
3B6C805917090ED300D22AB2 /* Code93Reader.cpp in Sources */, 3B6C805917090ED300D22AB2 /* Code93Reader.cpp in Sources */,
3B6C805D17090EFC00D22AB2 /* ChecksumException.cpp in Sources */, 3B6C805D17090EFC00D22AB2 /* ChecksumException.cpp in Sources */,
3B6AA66C1710C34600DF84C0 /* InvertedLuminanceSource.cpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View file

@ -92,53 +92,52 @@ CGImageRef CGImageLuminanceSource::createImageFromBuffer
(int)CVPixelBufferGetHeight(buffer)); (int)CVPixelBufferGetHeight(buffer));
} }
CGImageLuminanceSource::CGImageLuminanceSource(CVPixelBufferRef buffer) CGImageLuminanceSource* CGImageLuminanceSource::create(CVPixelBufferRef buffer) {
{ // Will leak if there's an exception ...
CGImageRef image = createImageFromBuffer(buffer); CGImageRef image = createImageFromBuffer(buffer);
init(image); CGImageLuminanceSource* source = new CGImageLuminanceSource(image);
CGImageRelease(image); CGImageRelease(image);
return source;
} }
CGImageLuminanceSource::CGImageLuminanceSource CGImageLuminanceSource::CGImageLuminanceSource(CVPixelBufferRef buffer,
(CVPixelBufferRef buffer, int left, int top, int width, int height) int left, int top, int width, int height)
{ : Super(width, height) {
CGImageRef image = createImageFromBuffer(buffer, left, top, width, height); CGImageRef image = createImageFromBuffer(buffer, left, top, width, height);
init(image); init(image);
CGImageRelease(image); CGImageRelease(image);
} }
CGImageLuminanceSource::CGImageLuminanceSource(CGImageRef cgimage) CGImageLuminanceSource::CGImageLuminanceSource(CGImageRef cgimage)
{ : Super((int)CGImageGetWidth(cgimage), (int)CGImageGetHeight(cgimage)) {
init(cgimage); init(cgimage);
} }
CGImageLuminanceSource::CGImageLuminanceSource CGImageLuminanceSource::CGImageLuminanceSource(CGImageRef cgimage,
(CGImageRef cgimage, int left, int top, int width, int height) int left,
{ int top,
init(cgimage, left, top, width, height); int width,
int height)
: Super(width, height) {
init(cgimage, left, top);
} }
void void
CGImageLuminanceSource::init(CGImageRef cgimage) CGImageLuminanceSource::init(CGImageRef cgimage) {
{ init(cgimage, 0, 0);
init(cgimage,
0, 0, (int)CGImageGetWidth(cgimage), (int)CGImageGetHeight(cgimage));
} }
void void
CGImageLuminanceSource::init CGImageLuminanceSource::init(CGImageRef cgimage, int left, int top) {
(CGImageRef cgimage, int left, int top, int width, int height) {
data_ = 0; data_ = 0;
image_ = cgimage; image_ = cgimage;
left_ = left; left_ = left;
top_ = top; top_ = top;
width_ = width;
height_ = height;
dataWidth_ = (int)CGImageGetWidth(image_); dataWidth_ = (int)CGImageGetWidth(image_);
dataHeight_ = (int)CGImageGetHeight(image_); dataHeight_ = (int)CGImageGetHeight(image_);
if (left_ + width_ > dataWidth_ || if (left_ + getWidth() > dataWidth_ ||
top_ + height_ > dataHeight_ || top_ + getHeight() > dataHeight_ ||
top_ < 0 || top_ < 0 ||
left_ < 0) { left_ < 0) {
throw IllegalArgumentException throw IllegalArgumentException
@ -155,28 +154,28 @@ CGImageLuminanceSource::init
CGColorSpaceRef gray = CGColorSpaceCreateDeviceGray(); CGColorSpaceRef gray = CGColorSpaceCreateDeviceGray();
CGContextRef ctx = CGBitmapContextCreate(0, CGContextRef ctx = CGBitmapContextCreate(0,
width, getWidth(),
height, getHeight(),
8, 8,
width, getWidth(),
gray, gray,
kCGImageAlphaNone); kCGImageAlphaNone);
CGColorSpaceRelease(gray); CGColorSpaceRelease(gray);
if (top || left) { if (top || left) {
CGContextClipToRect(ctx, CGRectMake(0, 0, width, height)); CGContextClipToRect(ctx, CGRectMake(0, 0, getWidth(), getHeight()));
} }
CGContextDrawImage(ctx, CGRectMake(-left, -top, width, height), image_); CGContextDrawImage(ctx, CGRectMake(-left, -top, getWidth(), getHeight()), image_);
image_ = CGBitmapContextCreateImage(ctx); image_ = CGBitmapContextCreateImage(ctx);
bytesPerRow_ = width; bytesPerRow_ = getWidth();
top_ = 0; top_ = 0;
left_ = 0; left_ = 0;
dataWidth_ = width; dataWidth_ = getWidth();
dataHeight_ = height; dataHeight_ = getHeight();
CGContextRelease(ctx); CGContextRelease(ctx);
} else { } else {
@ -196,7 +195,7 @@ CGImageLuminanceSource::~CGImageLuminanceSource() {
} }
} }
ArrayRef<char> CGImageLuminanceSource::getRow(int y, ArrayRef<char> row) { ArrayRef<char> CGImageLuminanceSource::getRow(int y, ArrayRef<char> row) const {
if (y < 0 || y >= this->getHeight()) { if (y < 0 || y >= this->getHeight()) {
ostringstream msg; ostringstream msg;
msg << "Requested row is outside the image: " << y; msg << "Requested row is outside the image: " << y;
@ -205,7 +204,7 @@ ArrayRef<char> CGImageLuminanceSource::getRow(int y, ArrayRef<char> row) {
int width = getWidth(); int width = getWidth();
// TODO(flyashi): determine if row has enough size. // TODO(flyashi): determine if row has enough size.
if (!row) { if (!row) {
row = ArrayRef<char>(width_); row = ArrayRef<char>(getWidth());
} }
int offset = (y + top_) * dataWidth_ + left_; int offset = (y + top_) * dataWidth_ + left_;
char* v = &row->values()[0]; char* v = &row->values()[0];
@ -213,26 +212,22 @@ ArrayRef<char> CGImageLuminanceSource::getRow(int y, ArrayRef<char> row) {
return row; return row;
} }
ArrayRef<char> CGImageLuminanceSource::getMatrix() { ArrayRef<char> CGImageLuminanceSource::getMatrix() const {
int size = width_ * height_; int size = getWidth() * getHeight();
ArrayRef<char> result (size); ArrayRef<char> result (size);
if (left_ == 0 && if (left_ == 0 &&
top_ == 0 && top_ == 0 &&
dataWidth_ == width_ && dataWidth_ == getWidth() &&
dataHeight_ == height_) { dataHeight_ == getHeight()) {
char* v = &result->values()[0]; char* v = &result->values()[0];
CFDataGetBytes(data_, CFRangeMake(0, size), (unsigned char*)v); CFDataGetBytes(data_, CFRangeMake(0, size), (unsigned char*)v);
} else { } else {
for (int row = 0; row < height_; row++) { for (int row = 0; row < getHeight(); row++) {
char* v = &result->values()[0]; char* v = &result->values()[0];
CFDataGetBytes(data_, CFDataGetBytes(data_,
CFRangeMake((top_ + row) * dataWidth_ + left_, width_), CFRangeMake((top_ + row) * dataWidth_ + left_, getWidth()),
(unsigned char*)v + row * width_); (unsigned char*)v + row * getWidth());
} }
} }
return result; return result;
} }
Ref<LuminanceSource> CGImageLuminanceSource::rotateCounterClockwise() {
return Ref<LuminanceSource>(0);
}

View file

@ -21,14 +21,12 @@
namespace zxing { namespace zxing {
class CGImageLuminanceSource : public LuminanceSource { class CGImageLuminanceSource : public LuminanceSource {
private: private:
typedef LuminanceSource Super;
CGImageRef image_; CGImageRef image_;
CFDataRef data_; CFDataRef data_;
int left_; int left_;
int top_; int top_;
int width_;
int height_;
int dataWidth_; int dataWidth_;
int dataHeight_; int dataHeight_;
int bytesPerRow_; int bytesPerRow_;
@ -42,12 +40,13 @@ class CGImageLuminanceSource : public LuminanceSource {
int width, int width,
int height); int height);
static CGImageLuminanceSource* create(CVPixelBufferRef buffer);
CGImageLuminanceSource(CVPixelBufferRef buffer, CGImageLuminanceSource(CVPixelBufferRef buffer,
int left, int left,
int top, int top,
int width, int width,
int height); int height);
CGImageLuminanceSource(CVPixelBufferRef buffer);
CGImageLuminanceSource(CGImageRef image, CGImageLuminanceSource(CGImageRef image,
int left, int left,
@ -60,27 +59,12 @@ class CGImageLuminanceSource : public LuminanceSource {
CGImageRef image() { return image_; } CGImageRef image() { return image_; }
CGImageRef image(size_t width, size_t height); CGImageRef image(size_t width, size_t height);
ArrayRef<char> getRow(int y, ArrayRef<char> row); ArrayRef<char> getRow(int y, ArrayRef<char> row) const;
ArrayRef<char> getMatrix(); ArrayRef<char> getMatrix() const;
bool isRotateSupported() const {
return true;
}
int getWidth() const {
return width_;
}
int getHeight() const {
return height_;
}
Ref<LuminanceSource> rotateCounterClockwise();
private: private:
void init(CGImageRef image); void init(CGImageRef image);
void init(CGImageRef image, int left, int top, int width, int height); void init(CGImageRef image, int left, int top);
}; };
} /* namespace */ } /* namespace */

View file

@ -78,7 +78,7 @@
} }
- (id)initWithBuffer:(CVPixelBufferRef)buffer { - (id)initWithBuffer:(CVPixelBufferRef)buffer {
self = [super initWithNative:new zxing::CGImageLuminanceSource(buffer)]; self = [super initWithNative:zxing::CGImageLuminanceSource::create(buffer)];
return self; return self;
} }
@ -88,12 +88,4 @@
return typed->image(); return typed->image();
} }
/*
- (CGImageRef)createImageWithWidth:(size_t)width andHeight:(size_t)height {
zxing::LuminanceSource* source = native;
zxing::CGImageLuminanceSource* typed = (zxing::CGImageLuminanceSource*)source;
return typed->createImage(width, height);
}
*/
@end @end

View file

@ -222,12 +222,14 @@ static bool isIPad();
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA]; NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
NSMutableDictionary* attributes = NSMutableDictionary* attributes =
[NSMutableDictionary dictionaryWithObject:value forKey:key]; [NSMutableDictionary dictionaryWithObject:value forKey:key];
key = (NSString*)kCVPixelBufferWidthKey; ZXQT({
value = [NSNumber numberWithUnsignedLong:width]; key = (NSString*)kCVPixelBufferWidthKey;
[attributes setObject:value forKey:key]; value = [NSNumber numberWithUnsignedLong:width];
key = (NSString*)kCVPixelBufferHeightKey; [attributes setObject:value forKey:key];
value = [NSNumber numberWithUnsignedLong:height]; key = (NSString*)kCVPixelBufferHeightKey;
[attributes setObject:value forKey:key]; value = [NSNumber numberWithUnsignedLong:height];
[attributes setObject:value forKey:key];
});
[output ZXQT(setPixelBufferAttributes:)ZXAV(setVideoSettings:)attributes]; [output ZXQT(setPixelBufferAttributes:)ZXAV(setVideoSettings:)attributes];
} }