tr
Bitmap.cpp
- Committer:
- valavanisalex
- Date:
- 2017-03-08
- Revision:
- 38:92fad278c2c3
- Child:
- 40:c9262294f2e1
File content as of revision 38:92fad278c2c3:
#include "Bitmap.h" #include <iostream> Bitmap::Bitmap(std::vector<int> const &contents, unsigned int const height, unsigned int const width) : _contents(contents), _height(height), _width(width) { // Perform a quick sanity check of the dimensions if (contents.size() != height * height) { std::cerr << "Contents of bitmap has size " << contents.size() << " pixels, but its dimensions were specified as " << width << " * " << height << " = " << width * height; } } int Bitmap::get_pixel(unsigned int const row, unsigned int const column) const { // First check that row and column indices are within bounds if(column >= _width || row >= _height) { std::cerr << "The requested pixel with index " << row << "," << column << "is outside the bitmap dimensions: " << _width << "," << _height; } // Now return the pixel value, using row-major indexing return _contents[row * _width + column]; }