Issue 161
[zxing.git] / cpp / core / src / GrayBytesMonochromeBitmapSource.cpp
1 /*
2  *  GrayBytesMonochromeBitmapSource.cpp
3  *  ZXing
4  *
5  *  Created by Christian Brunschen on 03/06/2008.
6  *  Copyright 2008 ZXing authors All rights reserved.
7  *
8  */
9
10 #include "GrayBytesMonochromeBitmapSource.h"
11 #include "ReaderException.h"
12 #include "TransformingMonochromeBitmapSource.h"
13
14 GrayBytesMonochromeBitmapSource::
15 GrayBytesMonochromeBitmapSource(const unsigned char *bytes, 
16                                 size_t width, 
17                                 size_t height,
18                                 size_t bytesPerRow) 
19 : MonochromeBitmapSource(),
20 width_(width), 
21 height_(height),
22 bytes_(bytes), 
23 bytesPerRow_(bytesPerRow) { }
24
25
26 size_t GrayBytesMonochromeBitmapSource::getWidth() {
27   return width_;
28 }
29
30 size_t GrayBytesMonochromeBitmapSource::getHeight() {
31   return height_;
32 }
33
34 unsigned char GrayBytesMonochromeBitmapSource::getPixel(size_t x, size_t y) {
35   if (x >= width_ || y >= height_) {
36     throw new ReaderException("bitmap coordinate out of bounds");
37   }
38   size_t index = y * bytesPerRow_ + x;
39   return bytes_[index];
40 }
41
42 // create a new bitmap source with the same data but rotated counter-clockwise
43 Ref<MonochromeBitmapSource> 
44 GrayBytesMonochromeBitmapSource::rotateCounterClockwise() {
45   Ref<MonochromeBitmapSource> self(this);
46   Ref<MonochromeBitmapSource> result(new TMBS90(self, 1.0));
47   return result;
48 }
49
50 bool GrayBytesMonochromeBitmapSource::isRotateSupported() {
51   return true;
52 }