zxing/cpp/magick/src/MagickBitmapSource.cpp
ralf.kistner 5472325ffe C++ port:
- Added experimental QR edge detector.
 - Modified pattern finder tolerance levels, as in the Java code.
 - Adjusted the local block binarizer slightly.
 - Added a simple example application.
 - Modified MagickBitmapSource to compute the luminance in the same way as the Java BufferedImageLuminanceSource.


git-svn-id: https://zxing.googlecode.com/svn/trunk@1144 59b500cc-1b3d-0410-9834-0bbf25fbcc57
2009-12-08 21:16:43 +00:00

72 lines
2 KiB
C++

/*
* MagickBitmapSource.cpp
* zxing
*
* Created by Ralf Kistner on 16/10/2009.
* Copyright 2008 ZXing authors All rights reserved.
*
* 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 "MagickBitmapSource.h"
#include <iostream>
using namespace Magick;
MagickBitmapSource::MagickBitmapSource(Image& image) : image_(image) {
width = image.columns();
height = image.rows();
pixel_cache = image.getConstPixels(0, 0, width, height);
}
MagickBitmapSource::~MagickBitmapSource() {
}
int MagickBitmapSource::getWidth() {
return width;
}
int MagickBitmapSource::getHeight() {
return height;
}
unsigned char MagickBitmapSource::getPixel(int x, int y) {
const PixelPacket* p = pixel_cache + y * width + x;
// We assume 16 bit values here
//return (unsigned char)((((int)p->red + (int)p->green + (int)p->blue) >> 8) / 3);
return (unsigned char)((306 * ((int)p->red >> 8) + 601 * ((int)p->green >> 8) + 117 * ((int)p->blue >> 8)) >> 10);
}
/** This is a more efficient implementation. */
unsigned char* MagickBitmapSource::copyMatrix() {
int width = getWidth();
int height = getHeight();
unsigned char* matrix = new unsigned char[width*height];
unsigned char* m = matrix;
const Magick::PixelPacket* p = pixel_cache;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
*m = (unsigned char)((306 * ((int)p->red >> 8) + 601 * ((int)p->green >> 8) + 117 * ((int)p->blue >> 8)) >> 10);
m++;
p++;
}
}
return matrix;
}