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;
}
extern "C" void abort();
Ref<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise() {
Ref<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise() const {
// Intentionally flip the left, top, width, and height arguments as
// needed. dataWidth and dataHeight are always kept unrotated.
Ref<LuminanceSource> result (
new GreyscaleRotatedLuminanceSource(greyData_,
dataWidth_, dataHeight_,
top_, left_, getHeight(), getWidth())
);
new GreyscaleRotatedLuminanceSource(greyData_,
dataWidth_, dataHeight_,
top_, left_, getHeight(), getWidth()));
return result;
}

View file

@ -45,8 +45,7 @@ public:
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> getMatrix() const;
bool isRotateSupported() const {
return false;
}
};
}

View file

@ -13,6 +13,7 @@
3B5A493617091826004E112F /* CodaBarReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B5A493217091826004E112F /* CodaBarReader.h */; };
3B5A493717091826004E112F /* Code93Reader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B5A493317091826004E112F /* Code93Reader.cpp */; };
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 */; };
3B83EA63158E679000A3B31F /* AztecDetectorResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B83E9A4158E679000A3B31F /* AztecDetectorResult.cpp */; };
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>"; };
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>"; };
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; };
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>"; };
@ -419,6 +421,7 @@
3B83E9A2158E679000A3B31F /* zxing */ = {
isa = PBXGroup;
children = (
3B6AA6701710C83200DF84C0 /* InvertedLuminanceSource.cpp */,
3B5A492D17091807004E112F /* ChecksumException.cpp */,
3B5A492E17091807004E112F /* ChecksumException.h */,
3B83E9A3158E679000A3B31F /* aztec */,
@ -980,6 +983,7 @@
3B5A492F17091807004E112F /* ChecksumException.cpp in Sources */,
3B5A493517091826004E112F /* CodaBarReader.cpp in Sources */,
3B5A493717091826004E112F /* Code93Reader.cpp in Sources */,
3B6AA6711710C83200DF84C0 /* InvertedLuminanceSource.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -141,6 +141,8 @@
3B27C5E2144735E6005157C4 /* CharacterSetECI.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B27C5DC144735E6005157C4 /* CharacterSetECI.h */; };
3B27C5E5144735E6005157C4 /* StringUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B27C5DF144735E6005157C4 /* StringUtils.cpp */; };
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 */; };
3B6C805817090ED300D22AB2 /* CodaBarReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B6C805417090ED300D22AB2 /* CodaBarReader.h */; };
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>"; };
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>"; };
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>"; };
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>"; };
@ -754,6 +758,8 @@
E53458B411987396000CB77F /* zxing */ = {
isa = PBXGroup;
children = (
3B6AA66A1710C34600DF84C0 /* InvertedLuminanceSource.cpp */,
3B6AA66B1710C34600DF84C0 /* InvertedLuminanceSource.h */,
3B6C805B17090EFC00D22AB2 /* ChecksumException.cpp */,
3B6C805C17090EFC00D22AB2 /* ChecksumException.h */,
3B248F8314EF3A980065F0DA /* aztec */,
@ -1226,6 +1232,7 @@
3B6C805817090ED300D22AB2 /* CodaBarReader.h in Headers */,
3B6C805A17090ED300D22AB2 /* Code93Reader.h in Headers */,
3B6C805E17090EFC00D22AB2 /* ChecksumException.h in Headers */,
3B6AA66D1710C34600DF84C0 /* InvertedLuminanceSource.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -1474,6 +1481,7 @@
3B6C805717090ED300D22AB2 /* CodaBarReader.cpp in Sources */,
3B6C805917090ED300D22AB2 /* Code93Reader.cpp in Sources */,
3B6C805D17090EFC00D22AB2 /* ChecksumException.cpp in Sources */,
3B6AA66C1710C34600DF84C0 /* InvertedLuminanceSource.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

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

View file

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

View file

@ -78,7 +78,7 @@
}
- (id)initWithBuffer:(CVPixelBufferRef)buffer {
self = [super initWithNative:new zxing::CGImageLuminanceSource(buffer)];
self = [super initWithNative:zxing::CGImageLuminanceSource::create(buffer)];
return self;
}
@ -88,12 +88,4 @@
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

View file

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