2 * GreyscaleRotatedLuminanceSource.cpp
5 * Copyright 2010 ZXing authors All rights reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <zxing/common/GreyscaleRotatedLuminanceSource.h>
22 #include <zxing/common/IllegalArgumentException.h>
26 // Note that dataWidth and dataHeight are not reversed, as we need to be able to traverse the
27 // greyData correctly, which does not get rotated.
28 GreyscaleRotatedLuminanceSource::GreyscaleRotatedLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight,
29 int left, int top, int width, int height) : greyData_(greyData), dataWidth_(dataWidth), dataHeight_(dataHeight),
30 left_(left), top_(top), width_(width), height_(height) {
32 // Intentionally comparing to the opposite dimension since we're rotated.
33 if (left + width > dataHeight || top + height > dataWidth) {
34 throw IllegalArgumentException("Crop rectangle does not fit within image data.");
38 // The API asks for rows, but we're rotated, so we return columns.
39 unsigned char* GreyscaleRotatedLuminanceSource::getRow(int y, unsigned char* row) {
40 if (y < 0 || y >= getHeight()) {
41 throw IllegalArgumentException("Requested row is outside the image: " + y);
43 int width = getWidth();
44 // TODO(flyashi): determine if row has enough size.
46 row = new unsigned char[width];
48 int offset = (left_ * dataWidth_) + (dataWidth_ - (y + top_));
49 for (int x = 0; x < width; x++) {
50 row[x] = greyData_[offset];
56 unsigned char* GreyscaleRotatedLuminanceSource::getMatrix() {
57 // FIXME(flyashi): fine for 1D scanning, need to implement for 2D scanning