1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| class Image
{
public:
/* il faut connaitre la hauteur et la largeur de l'image */
Image(size_t width, size_t height):width_(width), height_(height)
{
pixels_.reserve(height_*width_);
}
/* pour obtenir la valeur du pixel à la ligne row et à la colonne col */
PixelValue const & pixelAt(size_t row, size_t col) const
{
/* on peut vérifier que row < height_ et que col < width_ ;) */
return pixels_[row* width_ + col];
}
void changePixelAt(size_t row, size_t col, PixelValue const & newValue)
{
/* on peut vérifier que row < height_ et que col < width_ ;) */
pixels_[row* width_ + col] = newValue;
}
private:
size_t width_;
size_t height_;
std::vector<PixelValue> pixels_;
}; |