C++ Bitmap Library  release
Classes | Public Types | Public Member Functions | List of all members
bitmap_image Class Reference

#include <bitmap_image.hpp>

Public Types

enum  channel_mode { rgb_mode = 0, bgr_mode = 1 }
 
enum  color_plane { blue_plane = 0, green_plane = 1, red_plane = 2 }
 

Public Member Functions

 bitmap_image ()
 
 bitmap_image (const std::string &filename)
 
 bitmap_image (const unsigned int width, const unsigned int height)
 
 bitmap_image (const bitmap_image &image)
 
bitmap_imageoperator= (const bitmap_image &image)
 
bool operator! ()
 
void clear (const unsigned char v=0x00)
 
unsigned char red_channel (const unsigned int x, const unsigned int y) const
 
unsigned char green_channel (const unsigned int x, const unsigned int y) const
 
unsigned char blue_channel (const unsigned int x, const unsigned int y) const
 
void red_channel (const unsigned int x, const unsigned int y, const unsigned char value)
 
void green_channel (const unsigned int x, const unsigned int y, const unsigned char value)
 
void blue_channel (const unsigned int x, const unsigned int y, const unsigned char value)
 
unsigned char * row (unsigned int row_index) const
 
void get_pixel (const unsigned int x, const unsigned int y, unsigned char &red, unsigned char &green, unsigned char &blue)
 
template<typename RGB >
void get_pixel (const unsigned int x, const unsigned int y, RGB &colour)
 
void set_pixel (const unsigned int x, const unsigned int y, const unsigned char red, const unsigned char green, const unsigned char blue)
 
template<typename RGB >
void set_pixel (const unsigned int x, const unsigned int y, const RGB &colour)
 
bool copy_from (const bitmap_image &image)
 
bool copy_from (const bitmap_image &source_image, const unsigned int &x_offset, const unsigned int &y_offset)
 
bool region (const unsigned int &x, const unsigned int &y, const unsigned int &width, const unsigned int &height, bitmap_image &dest_image)
 
bool roi_from_center (const unsigned int &cx, const unsigned int &cy, const unsigned int &width, const unsigned int &height, bitmap_image &dest_image)
 
bool set_region (const unsigned int &x, const unsigned int &y, const unsigned int &width, const unsigned int &height, const unsigned char &value)
 
bool set_region (const unsigned int &x, const unsigned int &y, const unsigned int &width, const unsigned int &height, const color_plane color, const unsigned char &value)
 
bool set_region (const unsigned int &x, const unsigned int &y, const unsigned int &width, const unsigned int &height, const unsigned char &red, const unsigned char &green, const unsigned char &blue)
 
void reflective_image (bitmap_image &image, const bool include_diagnols=false)
 
unsigned int width () const
 
unsigned int height () const
 
unsigned int bytes_per_pixel () const
 
unsigned int pixel_count () const
 
void setwidth_height (const unsigned int width, const unsigned int height, const bool clear=false)
 
void save_image (const std::string &file_name) const
 
void set_all_ith_bits_low (const unsigned int bitr_index)
 
void set_all_ith_bits_high (const unsigned int bitr_index)
 
void set_all_ith_channels (const unsigned int &channel, const unsigned char &value)
 
void set_channel (const color_plane color, const unsigned char &value)
 
void ror_channel (const color_plane color, const unsigned int &ror)
 
void set_all_channels (const unsigned char &value)
 
void set_all_channels (const unsigned char &r_value, const unsigned char &g_value, const unsigned char &b_value)
 
void invert_color_planes ()
 
void add_to_color_plane (const color_plane color, const unsigned char &value)
 
void convert_to_grayscale ()
 
const unsigned char * data () const
 
unsigned char * data ()
 
void bgr_to_rgb ()
 
void rgb_to_bgr ()
 
void reverse ()
 
void horizontal_flip ()
 
void vertical_flip ()
 
void export_color_plane (const color_plane color, unsigned char *image)
 
void export_color_plane (const color_plane color, bitmap_image &image)
 
void export_response_image (const color_plane color, double *response_image)
 
void export_gray_scale_response_image (double *response_image) const
 
void export_rgb (double *red, double *green, double *blue) const
 
void export_rgb (float *red, float *green, float *blue) const
 
void export_rgb (unsigned char *red, unsigned char *green, unsigned char *blue) const
 
void export_ycbcr (double *y, double *cb, double *cr)
 
void export_rgb_normal (double *red, double *green, double *blue) const
 
void export_rgb_normal (float *red, float *green, float *blue) const
 
void import_rgb (double *red, double *green, double *blue)
 
void import_rgb (float *red, float *green, float *blue)
 
void import_rgb (unsigned char *red, unsigned char *green, unsigned char *blue)
 
void import_ycbcr (double *y, double *cb, double *cr)
 
void import_gray_scale_clamped (double *gray)
 
void import_rgb_clamped (double *red, double *green, double *blue)
 
void import_rgb_clamped (float *red, float *green, float *blue)
 
void import_rgb_normal (double *red, double *green, double *blue)
 
void import_rgb_normal (float *red, float *green, float *blue)
 
void subsample (bitmap_image &dest)
 
void upsample (bitmap_image &dest)
 
void alpha_blend (const double &alpha, const bitmap_image &image)
 
double psnr (const bitmap_image &image)
 
double psnr (const unsigned int &x, const unsigned int &y, const bitmap_image &image)
 
void histogram (const color_plane color, double hist[256])
 
void histogram_normalized (const color_plane color, double hist[256])
 
unsigned int offset (const color_plane color)
 
void incremental ()
 
void reverse_channels ()
 

Detailed Description

Definition at line 37 of file bitmap_image.hpp.

Member Enumeration Documentation

◆ channel_mode

Enumerator
rgb_mode 
bgr_mode 

Definition at line 41 of file bitmap_image.hpp.

◆ color_plane

Enumerator
blue_plane 
green_plane 
red_plane 

Definition at line 46 of file bitmap_image.hpp.

Constructor & Destructor Documentation

◆ bitmap_image() [1/4]

bitmap_image::bitmap_image ( )
inline

Definition at line 52 of file bitmap_image.hpp.

53  : file_name_(""),
54  width_ (0),
55  height_ (0),
56  row_increment_ (0),
57  bytes_per_pixel_(3),
58  channel_mode_(bgr_mode)
59  {}

◆ bitmap_image() [2/4]

bitmap_image::bitmap_image ( const std::string &  filename)
inline

Definition at line 61 of file bitmap_image.hpp.

62  : file_name_(filename),
63  width_ (0),
64  height_ (0),
65  row_increment_ (0),
66  bytes_per_pixel_(0),
67  channel_mode_(bgr_mode)
68  {
69  load_bitmap();
70  }

◆ bitmap_image() [3/4]

bitmap_image::bitmap_image ( const unsigned int  width,
const unsigned int  height 
)
inline

Definition at line 72 of file bitmap_image.hpp.

73  : file_name_(""),
74  width_ (width ),
75  height_(height),
76  row_increment_ (0),
77  bytes_per_pixel_(3),
78  channel_mode_(bgr_mode)
79  {
80  create_bitmap();
81  }
unsigned int height() const
unsigned int width() const

◆ bitmap_image() [4/4]

bitmap_image::bitmap_image ( const bitmap_image image)
inline

Definition at line 83 of file bitmap_image.hpp.

84  : file_name_(image.file_name_),
85  width_ (image.width_ ),
86  height_ (image.height_ ),
87  row_increment_ (0),
88  bytes_per_pixel_(3),
89  channel_mode_(bgr_mode)
90  {
91  create_bitmap();
92  data_ = image.data_;
93  }

Member Function Documentation

◆ add_to_color_plane()

void bitmap_image::add_to_color_plane ( const color_plane  color,
const unsigned char &  value 
)
inline

Definition at line 534 of file bitmap_image.hpp.

References data(), and offset().

Referenced by test11().

535  {
536  for (unsigned char* itr = (data() + offset(color)); itr < end(); itr += bytes_per_pixel_)
537  {
538  (*itr) += value;
539  }
540  }
const unsigned char * data() const
unsigned int offset(const color_plane color)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ alpha_blend()

void bitmap_image::alpha_blend ( const double &  alpha,
const bitmap_image image 
)
inline

Definition at line 1095 of file bitmap_image.hpp.

References data().

Referenced by test16().

1096  {
1097  if (
1098  (image.width_ != width_ ) ||
1099  (image.height_ != height_)
1100  )
1101  {
1102  return;
1103  }
1104 
1105  if ((alpha < 0.0) || (alpha > 1.0))
1106  {
1107  return;
1108  }
1109 
1110  unsigned char* itr1 = data();
1111  unsigned char* itr1_end = end();
1112  const unsigned char* itr2 = image.data();
1113 
1114  double alpha_compliment = 1.0 - alpha;
1115 
1116  while (itr1 != itr1_end)
1117  {
1118  *(itr1) = static_cast<unsigned char>((alpha * (*itr2)) + (alpha_compliment * (*itr1)));
1119  ++itr1;
1120  ++itr2;
1121  }
1122  }
const unsigned char * data() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bgr_to_rgb()

void bitmap_image::bgr_to_rgb ( )
inline

Definition at line 578 of file bitmap_image.hpp.

References bgr_mode, reverse_channels(), and rgb_mode.

579  {
580  if ((bgr_mode == channel_mode_) && (3 == bytes_per_pixel_))
581  {
583  channel_mode_ = rgb_mode;
584  }
585  }
void reverse_channels()
Here is the call graph for this function:

◆ blue_channel() [1/2]

unsigned char bitmap_image::blue_channel ( const unsigned int  x,
const unsigned int  y 
) const
inline

Definition at line 135 of file bitmap_image.hpp.

136  {
137  return data_[(y * row_increment_) + (x * bytes_per_pixel_ + 0)];
138  }

◆ blue_channel() [2/2]

void bitmap_image::blue_channel ( const unsigned int  x,
const unsigned int  y,
const unsigned char  value 
)
inline

Definition at line 150 of file bitmap_image.hpp.

151  {
152  data_[(y * row_increment_) + (x * bytes_per_pixel_ + 0)] = value;
153  }

◆ bytes_per_pixel()

unsigned int bitmap_image::bytes_per_pixel ( ) const
inline

Definition at line 390 of file bitmap_image.hpp.

Referenced by checkered_pattern(), and psnr_region().

391  {
392  return bytes_per_pixel_;
393  }
Here is the caller graph for this function:

◆ clear()

void bitmap_image::clear ( const unsigned char  v = 0x00)
inline

Definition at line 120 of file bitmap_image.hpp.

Referenced by export_color_plane(), reverse_channels(), setwidth_height(), subsample(), test14(), test15(), test20(), and upsample().

121  {
122  std::fill(data_.begin(),data_.end(),v);
123  }
Here is the caller graph for this function:

◆ convert_to_grayscale()

void bitmap_image::convert_to_grayscale ( )
inline

Definition at line 542 of file bitmap_image.hpp.

References data(), and rgb_mode.

Referenced by test07().

543  {
544  double r_scaler = 0.299;
545  double g_scaler = 0.587;
546  double b_scaler = 0.114;
547 
548  if (rgb_mode == channel_mode_)
549  {
550  std::swap(r_scaler, b_scaler);
551  }
552 
553  for (unsigned char* itr = data(); itr < end(); )
554  {
555  unsigned char gray_value = static_cast<unsigned char>
556  (
557  (r_scaler * (*(itr + 2))) +
558  (g_scaler * (*(itr + 1))) +
559  (b_scaler * (*(itr + 0)))
560  );
561 
562  *(itr++) = gray_value;
563  *(itr++) = gray_value;
564  *(itr++) = gray_value;
565  }
566  }
const unsigned char * data() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_from() [1/2]

bool bitmap_image::copy_from ( const bitmap_image image)
inline

Definition at line 199 of file bitmap_image.hpp.

Referenced by reflective_image().

200  {
201  if (
202  (image.height_ != height_) ||
203  (image.width_ != width_ )
204  )
205  {
206  return false;
207  }
208 
209  data_ = image.data_;
210 
211  return true;
212  }
Here is the caller graph for this function:

◆ copy_from() [2/2]

bool bitmap_image::copy_from ( const bitmap_image source_image,
const unsigned int &  x_offset,
const unsigned int &  y_offset 
)
inline

Definition at line 214 of file bitmap_image.hpp.

References row().

217  {
218  if ((x_offset + source_image.width_ ) > width_ ) { return false; }
219  if ((y_offset + source_image.height_) > height_) { return false; }
220 
221  for (unsigned int y = 0; y < source_image.height_; ++y)
222  {
223  unsigned char* itr1 = row(y + y_offset) + x_offset * bytes_per_pixel_;
224  const unsigned char* itr2 = source_image.row(y);
225  const unsigned char* itr2_end = itr2 + source_image.width_ * bytes_per_pixel_;
226 
227  std::copy(itr2,itr2_end,itr1);
228  }
229 
230  return true;
231  }
unsigned char * row(unsigned int row_index) const
Here is the call graph for this function:

◆ data() [1/2]

const unsigned char* bitmap_image::data ( ) const
inline

◆ data() [2/2]

unsigned char* bitmap_image::data ( )
inline

Definition at line 573 of file bitmap_image.hpp.

574  {
575  return const_cast<unsigned char*>(data_.data());
576  }

◆ export_color_plane() [1/2]

void bitmap_image::export_color_plane ( const color_plane  color,
unsigned char *  image 
)
inline

Definition at line 653 of file bitmap_image.hpp.

References data(), and offset().

Referenced by test06().

654  {
655  for (unsigned char* itr = (data() + offset(color)); itr < end(); ++image, itr += bytes_per_pixel_)
656  {
657  (*image) = (*itr);
658  }
659  }
const unsigned char * data() const
unsigned int offset(const color_plane color)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ export_color_plane() [2/2]

void bitmap_image::export_color_plane ( const color_plane  color,
bitmap_image image 
)
inline

Definition at line 661 of file bitmap_image.hpp.

References clear(), data(), offset(), and setwidth_height().

662  {
663  if (
664  (width_ != image.width_ ) ||
665  (height_ != image.height_)
666  )
667  {
668  image.setwidth_height(width_,height_);
669  }
670 
671  image.clear();
672 
673  unsigned char* itr1 = (data() + offset(color));
674  unsigned char* itr1_end = end();
675  unsigned char* itr2 = (image.data() + offset(color));
676 
677  while (itr1 < itr1_end)
678  {
679  (*itr2) = (*itr1);
680 
681  itr1 += bytes_per_pixel_;
682  itr2 += bytes_per_pixel_;
683  }
684  }
const unsigned char * data() const
unsigned int offset(const color_plane color)
void setwidth_height(const unsigned int width, const unsigned int height, const bool clear=false)
void clear(const unsigned char v=0x00)
Here is the call graph for this function:

◆ export_gray_scale_response_image()

void bitmap_image::export_gray_scale_response_image ( double *  response_image) const
inline

Definition at line 696 of file bitmap_image.hpp.

References data().

Referenced by sobel_operator().

697  {
698  double* resp_itr = response_image;
699 
700  for (const unsigned char* itr = data(); itr < end(); itr += bytes_per_pixel_)
701  {
702  unsigned char gray_value = static_cast<unsigned char>
703  (
704  (0.299 * (*(itr + 2))) +
705  (0.587 * (*(itr + 1))) +
706  (0.114 * (*(itr + 0)))
707  );
708 
709  *(resp_itr++) = (1.0 * gray_value) / 256.0;
710  }
711  }
const unsigned char * data() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ export_response_image()

void bitmap_image::export_response_image ( const color_plane  color,
double *  response_image 
)
inline

Definition at line 686 of file bitmap_image.hpp.

References data(), and offset().

687  {
688  double* resp_itr = response_image;
689 
690  for (unsigned char* itr = (data() + offset(color)); itr < end(); ++response_image, itr += bytes_per_pixel_)
691  {
692  *(resp_itr++) = (1.0 * (*itr)) / 256.0;
693  }
694  }
const unsigned char * data() const
unsigned int offset(const color_plane color)
Here is the call graph for this function:

◆ export_rgb() [1/3]

void bitmap_image::export_rgb ( double *  red,
double *  green,
double *  blue 
) const
inline

Definition at line 713 of file bitmap_image.hpp.

References bgr_mode, and data().

714  {
715  if (bgr_mode != channel_mode_)
716  return;
717 
718  for (const unsigned char* itr = data(); itr < end(); ++red, ++green, ++blue)
719  {
720  (*blue ) = (1.0 * (*(itr++))) / 256.0;
721  (*green) = (1.0 * (*(itr++))) / 256.0;
722  (*red ) = (1.0 * (*(itr++))) / 256.0;
723  }
724  }
const unsigned char * data() const
Here is the call graph for this function:

◆ export_rgb() [2/3]

void bitmap_image::export_rgb ( float *  red,
float *  green,
float *  blue 
) const
inline

Definition at line 726 of file bitmap_image.hpp.

References bgr_mode, and data().

727  {
728  if (bgr_mode != channel_mode_)
729  return;
730 
731  for (const unsigned char* itr = data(); itr < end(); ++red, ++green, ++blue)
732  {
733  (*blue ) = (1.0f * (*(itr++))) / 256.0f;
734  (*green) = (1.0f * (*(itr++))) / 256.0f;
735  (*red ) = (1.0f * (*(itr++))) / 256.0f;
736  }
737  }
const unsigned char * data() const
Here is the call graph for this function:

◆ export_rgb() [3/3]

void bitmap_image::export_rgb ( unsigned char *  red,
unsigned char *  green,
unsigned char *  blue 
) const
inline

Definition at line 739 of file bitmap_image.hpp.

References bgr_mode, and data().

740  {
741  if (bgr_mode != channel_mode_)
742  return;
743 
744  for (const unsigned char* itr = data(); itr < end(); ++red, ++green, ++blue)
745  {
746  (*blue ) = *(itr++);
747  (*green) = *(itr++);
748  (*red ) = *(itr++);
749  }
750  }
const unsigned char * data() const
Here is the call graph for this function:

◆ export_rgb_normal() [1/2]

void bitmap_image::export_rgb_normal ( double *  red,
double *  green,
double *  blue 
) const
inline

Definition at line 769 of file bitmap_image.hpp.

References bgr_mode, and data().

770  {
771  if (bgr_mode != channel_mode_)
772  return;
773 
774  for (const unsigned char* itr = data(); itr < end(); ++red, ++green, ++blue)
775  {
776  (*blue ) = (1.0 * (*(itr++)));
777  (*green) = (1.0 * (*(itr++)));
778  (*red ) = (1.0 * (*(itr++)));
779  }
780  }
const unsigned char * data() const
Here is the call graph for this function:

◆ export_rgb_normal() [2/2]

void bitmap_image::export_rgb_normal ( float *  red,
float *  green,
float *  blue 
) const
inline

Definition at line 782 of file bitmap_image.hpp.

References bgr_mode, and data().

783  {
784  if (bgr_mode != channel_mode_)
785  return;
786 
787  for (const unsigned char* itr = data(); itr < end(); ++red, ++green, ++blue)
788  {
789  (*blue ) = (1.0f * (*(itr++)));
790  (*green) = (1.0f * (*(itr++)));
791  (*red ) = (1.0f * (*(itr++)));
792  }
793  }
const unsigned char * data() const
Here is the call graph for this function:

◆ export_ycbcr()

void bitmap_image::export_ycbcr ( double *  y,
double *  cb,
double *  cr 
)
inline

Definition at line 752 of file bitmap_image.hpp.

References bgr_mode, and data().

Referenced by test12(), and test13().

753  {
754  if (bgr_mode != channel_mode_)
755  return;
756 
757  for (const unsigned char* itr = data(); itr < end(); ++y, ++cb, ++cr)
758  {
759  const double blue = (1.0 * (*(itr++)));
760  const double green = (1.0 * (*(itr++)));
761  const double red = (1.0 * (*(itr++)));
762 
763  ( *y) = clamp<double>( 16.0 + (1.0/256.0) * ( 65.738 * red + 129.057 * green + 25.064 * blue),1.0,254);
764  (*cb) = clamp<double>(128.0 + (1.0/256.0) * (- 37.945 * red - 74.494 * green + 112.439 * blue),1.0,254);
765  (*cr) = clamp<double>(128.0 + (1.0/256.0) * ( 112.439 * red - 94.154 * green - 18.285 * blue),1.0,254);
766  }
767  }
const unsigned char * data() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_pixel() [1/2]

void bitmap_image::get_pixel ( const unsigned int  x,
const unsigned int  y,
unsigned char &  red,
unsigned char &  green,
unsigned char &  blue 
)
inline

Definition at line 160 of file bitmap_image.hpp.

Referenced by get_pixel().

164  {
165  const unsigned int y_offset = y * row_increment_;
166  const unsigned int x_offset = x * bytes_per_pixel_;
167 
168  blue = data_[y_offset + x_offset + 0];
169  green = data_[y_offset + x_offset + 1];
170  red = data_[y_offset + x_offset + 2];
171  }
Here is the caller graph for this function:

◆ get_pixel() [2/2]

template<typename RGB >
void bitmap_image::get_pixel ( const unsigned int  x,
const unsigned int  y,
RGB &  colour 
)
inline

Definition at line 174 of file bitmap_image.hpp.

References get_pixel().

176  {
177  get_pixel(x, y, colour.red, colour.green, colour.blue);
178  }
void get_pixel(const unsigned int x, const unsigned int y, unsigned char &red, unsigned char &green, unsigned char &blue)
Here is the call graph for this function:

◆ green_channel() [1/2]

unsigned char bitmap_image::green_channel ( const unsigned int  x,
const unsigned int  y 
) const
inline

Definition at line 130 of file bitmap_image.hpp.

131  {
132  return data_[(y * row_increment_) + (x * bytes_per_pixel_ + 1)];
133  }

◆ green_channel() [2/2]

void bitmap_image::green_channel ( const unsigned int  x,
const unsigned int  y,
const unsigned char  value 
)
inline

Definition at line 145 of file bitmap_image.hpp.

146  {
147  data_[(y * row_increment_) + (x * bytes_per_pixel_ + 1)] = value;
148  }

◆ height()

unsigned int bitmap_image::height ( ) const
inline

Definition at line 385 of file bitmap_image.hpp.

Referenced by checkered_pattern(), convert_rsp_to_image(), hierarchical_psnr(), plasma(), psnr(), psnr_region(), region(), reverse_channels(), set_region(), setwidth_height(), sobel_operator(), test08(), test15(), test16(), test17(), test18(), and upsample().

386  {
387  return height_;
388  }
Here is the caller graph for this function:

◆ histogram()

void bitmap_image::histogram ( const color_plane  color,
double  hist[256] 
)
inline

Definition at line 1198 of file bitmap_image.hpp.

References data(), and offset().

Referenced by histogram_normalized().

1199  {
1200  std::fill(hist,hist + 256,0.0);
1201 
1202  for (unsigned char* itr = (data() + offset(color)); itr < end(); itr += bytes_per_pixel_)
1203  {
1204  ++hist[(*itr)];
1205  }
1206  }
const unsigned char * data() const
unsigned int offset(const color_plane color)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ histogram_normalized()

void bitmap_image::histogram_normalized ( const color_plane  color,
double  hist[256] 
)
inline

Definition at line 1208 of file bitmap_image.hpp.

References histogram(), and pixel_count().

1209  {
1210  histogram(color,hist);
1211 
1212  double* h_itr = hist;
1213  const double* h_end = hist + 256;
1214  const double pixel_count = static_cast<double>(width_ * height_);
1215 
1216  while (h_end != h_itr)
1217  {
1218  *(h_itr++) /= pixel_count;
1219  }
1220  }
void histogram(const color_plane color, double hist[256])
unsigned int pixel_count() const
Here is the call graph for this function:

◆ horizontal_flip()

void bitmap_image::horizontal_flip ( )
inline

Definition at line 616 of file bitmap_image.hpp.

References row().

Referenced by reflective_image(), and test02().

617  {
618  for (unsigned int y = 0; y < height_; ++y)
619  {
620  unsigned char* itr1 = row(y);
621  unsigned char* itr2 = itr1 + row_increment_ - bytes_per_pixel_;
622 
623  while (itr1 < itr2)
624  {
625  for (unsigned int i = 0; i < bytes_per_pixel_; ++i)
626  {
627  unsigned char* p1 = (itr1 + i);
628  unsigned char* p2 = (itr2 + i);
629 
630  std::swap(*p1,*p2);
631  }
632 
633  itr1 += bytes_per_pixel_;
634  itr2 -= bytes_per_pixel_;
635  }
636  }
637  }
unsigned char * row(unsigned int row_index) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ import_gray_scale_clamped()

void bitmap_image::import_gray_scale_clamped ( double *  gray)
inline

Definition at line 851 of file bitmap_image.hpp.

References bgr_mode, and data().

Referenced by sobel_operator().

852  {
853  if (bgr_mode != channel_mode_)
854  return;
855 
856  for (unsigned char* itr = data(); itr < end(); ++gray)
857  {
858  unsigned char c = static_cast<unsigned char>(clamp<double>(256.0 * (*gray),0.0,255.0));
859 
860  *(itr + 0) = c;
861  *(itr + 1) = c;
862  *(itr + 2) = c;
863 
864  itr += 3;
865  }
866  }
const unsigned char * data() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ import_rgb() [1/3]

void bitmap_image::import_rgb ( double *  red,
double *  green,
double *  blue 
)
inline

Definition at line 795 of file bitmap_image.hpp.

References bgr_mode, and data().

796  {
797  if (bgr_mode != channel_mode_)
798  return;
799 
800  for (unsigned char* itr = data(); itr < end(); ++red, ++green, ++blue)
801  {
802  *(itr++) = static_cast<unsigned char>(256.0 * (*blue ));
803  *(itr++) = static_cast<unsigned char>(256.0 * (*green));
804  *(itr++) = static_cast<unsigned char>(256.0 * (*red ));
805  }
806  }
const unsigned char * data() const
Here is the call graph for this function:

◆ import_rgb() [2/3]

void bitmap_image::import_rgb ( float *  red,
float *  green,
float *  blue 
)
inline

Definition at line 808 of file bitmap_image.hpp.

References bgr_mode, and data().

809  {
810  if (bgr_mode != channel_mode_)
811  return;
812 
813  for (unsigned char* itr = data(); itr < end(); ++red, ++green, ++blue)
814  {
815  *(itr++) = static_cast<unsigned char>(256.0f * (*blue ));
816  *(itr++) = static_cast<unsigned char>(256.0f * (*green));
817  *(itr++) = static_cast<unsigned char>(256.0f * (*red ));
818  }
819  }
const unsigned char * data() const
Here is the call graph for this function:

◆ import_rgb() [3/3]

void bitmap_image::import_rgb ( unsigned char *  red,
unsigned char *  green,
unsigned char *  blue 
)
inline

Definition at line 821 of file bitmap_image.hpp.

References bgr_mode, and data().

822  {
823  if (bgr_mode != channel_mode_)
824  return;
825 
826  for (unsigned char* itr = data(); itr < end(); ++red, ++green, ++blue)
827  {
828  *(itr++) = (*blue );
829  *(itr++) = (*green);
830  *(itr++) = (*red );
831  }
832  }
const unsigned char * data() const
Here is the call graph for this function:

◆ import_rgb_clamped() [1/2]

void bitmap_image::import_rgb_clamped ( double *  red,
double *  green,
double *  blue 
)
inline

Definition at line 868 of file bitmap_image.hpp.

References bgr_mode, and data().

869  {
870  if (bgr_mode != channel_mode_)
871  return;
872 
873  for (unsigned char* itr = data(); itr < end(); ++red, ++green, ++blue)
874  {
875  *(itr++) = static_cast<unsigned char>(clamp<double>(256.0 * (*blue ),0.0,255.0));
876  *(itr++) = static_cast<unsigned char>(clamp<double>(256.0 * (*green),0.0,255.0));
877  *(itr++) = static_cast<unsigned char>(clamp<double>(256.0 * (*red ),0.0,255.0));
878  }
879  }
const unsigned char * data() const
Here is the call graph for this function:

◆ import_rgb_clamped() [2/2]

void bitmap_image::import_rgb_clamped ( float *  red,
float *  green,
float *  blue 
)
inline

Definition at line 881 of file bitmap_image.hpp.

References bgr_mode, and data().

882  {
883  if (bgr_mode != channel_mode_)
884  return;
885 
886  for (unsigned char* itr = data(); itr < end(); ++red, ++green, ++blue)
887  {
888  *(itr++) = static_cast<unsigned char>(clamp<double>(256.0f * (*blue ),0.0,255.0));
889  *(itr++) = static_cast<unsigned char>(clamp<double>(256.0f * (*green),0.0,255.0));
890  *(itr++) = static_cast<unsigned char>(clamp<double>(256.0f * (*red ),0.0,255.0));
891  }
892  }
const unsigned char * data() const
Here is the call graph for this function:

◆ import_rgb_normal() [1/2]

void bitmap_image::import_rgb_normal ( double *  red,
double *  green,
double *  blue 
)
inline

Definition at line 894 of file bitmap_image.hpp.

References bgr_mode, and data().

895  {
896  if (bgr_mode != channel_mode_)
897  return;
898 
899  for (unsigned char* itr = data(); itr < end(); ++red, ++green, ++blue)
900  {
901  *(itr++) = static_cast<unsigned char>(*blue );
902  *(itr++) = static_cast<unsigned char>(*green);
903  *(itr++) = static_cast<unsigned char>(*red );
904  }
905  }
const unsigned char * data() const
Here is the call graph for this function:

◆ import_rgb_normal() [2/2]

void bitmap_image::import_rgb_normal ( float *  red,
float *  green,
float *  blue 
)
inline

Definition at line 907 of file bitmap_image.hpp.

References bgr_mode, and data().

908  {
909  if (bgr_mode != channel_mode_)
910  return;
911 
912  for (unsigned char* itr = data(); itr < end(); ++red, ++green, ++blue)
913  {
914  *(itr++) = static_cast<unsigned char>(*blue );
915  *(itr++) = static_cast<unsigned char>(*green);
916  *(itr++) = static_cast<unsigned char>(*red );
917  }
918  }
const unsigned char * data() const
Here is the call graph for this function:

◆ import_ycbcr()

void bitmap_image::import_ycbcr ( double *  y,
double *  cb,
double *  cr 
)
inline

Definition at line 834 of file bitmap_image.hpp.

References bgr_mode, and data().

Referenced by test12(), and test13().

835  {
836  if (bgr_mode != channel_mode_)
837  return;
838 
839  for (unsigned char* itr = data(); itr < end(); ++y, ++cb, ++cr)
840  {
841  double y_ = (*y);
842  double cb_ = (*cb);
843  double cr_ = (*cr);
844 
845  *(itr++) = static_cast<unsigned char>(clamp((298.082 * y_ + 516.412 * cb_ ) / 256.0 - 276.836,0.0,255.0));
846  *(itr++) = static_cast<unsigned char>(clamp((298.082 * y_ - 100.291 * cb_ - 208.120 * cr_ ) / 256.0 + 135.576,0.0,255.0));
847  *(itr++) = static_cast<unsigned char>(clamp((298.082 * y_ + 408.583 * cr_ ) / 256.0 - 222.921,0.0,255.0));
848  }
849  }
const unsigned char * data() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ incremental()

void bitmap_image::incremental ( )
inline

Definition at line 1250 of file bitmap_image.hpp.

References data().

1251  {
1252  unsigned char current_color = 0;
1253 
1254  for (unsigned char* itr = data(); itr < end();)
1255  {
1256  (*itr++) = (current_color);
1257  (*itr++) = (current_color);
1258  (*itr++) = (current_color);
1259 
1260  ++current_color;
1261  }
1262  }
const unsigned char * data() const
Here is the call graph for this function:

◆ invert_color_planes()

void bitmap_image::invert_color_planes ( )
inline

Definition at line 529 of file bitmap_image.hpp.

References data().

Referenced by test10().

530  {
531  for (unsigned char* itr = data(); itr < end(); *itr = ~(*itr), ++itr);
532  }
const unsigned char * data() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ offset()

unsigned int bitmap_image::offset ( const color_plane  color)
inline

Definition at line 1222 of file bitmap_image.hpp.

References bgr_mode, blue_plane, green_plane, red_plane, and rgb_mode.

Referenced by add_to_color_plane(), checkered_pattern(), export_color_plane(), export_response_image(), histogram(), ror_channel(), set_channel(), and set_region().

1223  {
1224  switch (channel_mode_)
1225  {
1226  case rgb_mode : {
1227  switch (color)
1228  {
1229  case red_plane : return 0;
1230  case green_plane : return 1;
1231  case blue_plane : return 2;
1232  default : return std::numeric_limits<unsigned int>::max();
1233  }
1234  }
1235 
1236  case bgr_mode : {
1237  switch (color)
1238  {
1239  case red_plane : return 2;
1240  case green_plane : return 1;
1241  case blue_plane : return 0;
1242  default : return std::numeric_limits<unsigned int>::max();
1243  }
1244  }
1245 
1246  default : return std::numeric_limits<unsigned int>::max();
1247  }
1248  }
Here is the caller graph for this function:

◆ operator!()

bool bitmap_image::operator! ( )
inline

Definition at line 112 of file bitmap_image.hpp.

113  {
114  return (data_.size() == 0) ||
115  (width_ == 0) ||
116  (height_ == 0) ||
117  (row_increment_ == 0);
118  }

◆ operator=()

bitmap_image& bitmap_image::operator= ( const bitmap_image image)
inline

Definition at line 95 of file bitmap_image.hpp.

Referenced by cartesian_canvas::fill_triangle(), cartesian_canvas::max_y(), and image_drawer::pen_color().

96  {
97  if (this != &image)
98  {
99  file_name_ = image.file_name_;
100  bytes_per_pixel_ = image.bytes_per_pixel_;
101  width_ = image.width_;
102  height_ = image.height_;
103  row_increment_ = 0;
104  channel_mode_ = image.channel_mode_;
105  create_bitmap();
106  data_ = image.data_;
107  }
108 
109  return *this;
110  }
Here is the caller graph for this function:

◆ pixel_count()

unsigned int bitmap_image::pixel_count ( ) const
inline

Definition at line 395 of file bitmap_image.hpp.

Referenced by histogram_normalized(), test12(), and test13().

396  {
397  return width_ * height_;
398  }
Here is the caller graph for this function:

◆ psnr() [1/2]

double bitmap_image::psnr ( const bitmap_image image)
inline

Definition at line 1124 of file bitmap_image.hpp.

References data().

Referenced by hierarchical_psnr(), and hierarchical_psnr_r().

1125  {
1126  if (
1127  (image.width_ != width_ ) ||
1128  (image.height_ != height_)
1129  )
1130  {
1131  return 0.0;
1132  }
1133 
1134  unsigned char* itr1 = data();
1135  const unsigned char* itr2 = image.data();
1136 
1137  double mse = 0.0;
1138 
1139  while (itr1 != end())
1140  {
1141  const double v = (static_cast<double>(*itr1) - static_cast<double>(*itr2));
1142 
1143  mse += v * v;
1144  ++itr1;
1145  ++itr2;
1146  }
1147 
1148  if (mse <= 0.0000001)
1149  {
1150  return 1000000.0;
1151  }
1152  else
1153  {
1154  mse /= (3.0 * width_ * height_);
1155 
1156  return 20.0 * std::log10(255.0 / std::sqrt(mse));
1157  }
1158  }
const unsigned char * data() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ psnr() [2/2]

double bitmap_image::psnr ( const unsigned int &  x,
const unsigned int &  y,
const bitmap_image image 
)
inline

Definition at line 1160 of file bitmap_image.hpp.

References height(), row(), and width().

1163  {
1164  if ((x + image.width() ) > width_ ) { return 0.0; }
1165  if ((y + image.height()) > height_) { return 0.0; }
1166 
1167  double mse = 0.0;
1168 
1169  const unsigned int height = image.height();
1170  const unsigned int width = image.width();
1171 
1172  for (unsigned int r = 0; r < height; ++r)
1173  {
1174  unsigned char* itr1 = row(r + y) + x * bytes_per_pixel_;
1175  unsigned char* itr1_end = itr1 + (width * bytes_per_pixel_);
1176  const unsigned char* itr2 = image.row(r);
1177 
1178  while (itr1 != itr1_end)
1179  {
1180  double v = (static_cast<double>(*itr1) - static_cast<double>(*itr2));
1181  mse += v * v;
1182  ++itr1;
1183  ++itr2;
1184  }
1185  }
1186 
1187  if (mse <= 0.0000001)
1188  {
1189  return 1000000.0;
1190  }
1191  else
1192  {
1193  mse /= (3.0 * image.width() * image.height());
1194  return 20.0 * std::log10(255.0 / std::sqrt(mse));
1195  }
1196  }
unsigned int height() const
unsigned int width() const
unsigned char * row(unsigned int row_index) const
Here is the call graph for this function:

◆ red_channel() [1/2]

unsigned char bitmap_image::red_channel ( const unsigned int  x,
const unsigned int  y 
) const
inline

Definition at line 125 of file bitmap_image.hpp.

126  {
127  return data_[(y * row_increment_) + (x * bytes_per_pixel_ + 2)];
128  }

◆ red_channel() [2/2]

void bitmap_image::red_channel ( const unsigned int  x,
const unsigned int  y,
const unsigned char  value 
)
inline

Definition at line 140 of file bitmap_image.hpp.

141  {
142  data_[(y * row_increment_) + (x * bytes_per_pixel_ + 2)] = value;
143  }

◆ reflective_image()

void bitmap_image::reflective_image ( bitmap_image image,
const bool  include_diagnols = false 
)
inline

Definition at line 347 of file bitmap_image.hpp.

References copy_from(), horizontal_flip(), setwidth_height(), and vertical_flip().

348  {
349  image.setwidth_height(3 * width_, 3 * height_, true);
350 
351  image.copy_from(*this, width_, height_);
352 
353  vertical_flip();
354 
355  image.copy_from(*this, width_, 0);
356  image.copy_from(*this, width_, 2 * height_);
357 
358  vertical_flip();
359  horizontal_flip();
360 
361  image.copy_from(*this, 0, height_);
362  image.copy_from(*this, 2 * width_, height_);
363 
364  horizontal_flip();
365 
366  if (include_diagnols)
367  {
368  bitmap_image tile = *this;
369 
370  tile.vertical_flip();
371  tile.horizontal_flip();
372 
373  image.copy_from(tile, 0, 0);
374  image.copy_from(tile, 2 * width_, 0);
375  image.copy_from(tile, 2 * width_, 2 * height_);
376  image.copy_from(tile, 0 , 2 * height_);
377  }
378  }
void vertical_flip()
void horizontal_flip()
bool copy_from(const bitmap_image &image)
void setwidth_height(const unsigned int width, const unsigned int height, const bool clear=false)
Here is the call graph for this function:

◆ region()

bool bitmap_image::region ( const unsigned int &  x,
const unsigned int &  y,
const unsigned int &  width,
const unsigned int &  height,
bitmap_image dest_image 
)
inline

Definition at line 233 of file bitmap_image.hpp.

References height(), row(), and setwidth_height().

Referenced by roi_from_center(), and test08().

238  {
239  if ((x + width ) > width_ ) { return false; }
240  if ((y + height) > height_) { return false; }
241 
242  if (
243  (dest_image.width_ < width_ ) ||
244  (dest_image.height_ < height_)
245  )
246  {
247  dest_image.setwidth_height(width,height);
248  }
249 
250  for (unsigned int r = 0; r < height; ++r)
251  {
252  unsigned char* itr1 = row(r + y) + x * bytes_per_pixel_;
253  unsigned char* itr1_end = itr1 + (width * bytes_per_pixel_);
254  unsigned char* itr2 = dest_image.row(r);
255 
256  std::copy(itr1,itr1_end,itr2);
257  }
258 
259  return true;
260  }
unsigned int height() const
unsigned int width() const
unsigned char * row(unsigned int row_index) const
void setwidth_height(const unsigned int width, const unsigned int height, const bool clear=false)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reverse()

void bitmap_image::reverse ( )
inline

Definition at line 596 of file bitmap_image.hpp.

References data().

597  {
598  unsigned char* itr1 = data();
599  unsigned char* itr2 = end() - bytes_per_pixel_;
600 
601  while (itr1 < itr2)
602  {
603  for (std::size_t i = 0; i < bytes_per_pixel_; ++i)
604  {
605  unsigned char* citr1 = itr1 + i;
606  unsigned char* citr2 = itr2 + i;
607 
608  std::swap(*citr1,*citr2);
609  }
610 
611  itr1 += bytes_per_pixel_;
612  itr2 -= bytes_per_pixel_;
613  }
614  }
const unsigned char * data() const
Here is the call graph for this function:

◆ reverse_channels()

void bitmap_image::reverse_channels ( )
inline

Definition at line 1264 of file bitmap_image.hpp.

References clear(), data(), height(), row(), and width().

Referenced by bgr_to_rgb(), and rgb_to_bgr().

1265  {
1266  if (3 != bytes_per_pixel_)
1267  return;
1268 
1269  for (unsigned char* itr = data(); itr < end(); itr += bytes_per_pixel_)
1270  {
1271  std::swap(*(itr + 0),*(itr + 2));
1272  }
1273  }
const unsigned char * data() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rgb_to_bgr()

void bitmap_image::rgb_to_bgr ( )
inline

Definition at line 587 of file bitmap_image.hpp.

References bgr_mode, reverse_channels(), and rgb_mode.

588  {
589  if ((rgb_mode == channel_mode_) && (3 == bytes_per_pixel_))
590  {
592  channel_mode_ = bgr_mode;
593  }
594  }
void reverse_channels()
Here is the call graph for this function:

◆ roi_from_center()

bool bitmap_image::roi_from_center ( const unsigned int &  cx,
const unsigned int &  cy,
const unsigned int &  width,
const unsigned int &  height,
bitmap_image dest_image 
)
inline

Definition at line 262 of file bitmap_image.hpp.

References region().

267  {
268  return region(cx - (width / 2), cy - (height / 2),
269  width, height,
270  dest_image);
271  }
bool region(const unsigned int &x, const unsigned int &y, const unsigned int &width, const unsigned int &height, bitmap_image &dest_image)
unsigned int height() const
unsigned int width() const
Here is the call graph for this function:

◆ ror_channel()

void bitmap_image::ror_channel ( const color_plane  color,
const unsigned int &  ror 
)
inline

Definition at line 501 of file bitmap_image.hpp.

References data(), and offset().

502  {
503  for (unsigned char* itr = (data() + offset(color)); itr < end(); itr += bytes_per_pixel_)
504  {
505  *itr = static_cast<unsigned char>(((*itr) >> ror) | ((*itr) << (8 - ror)));
506  }
507  }
const unsigned char * data() const
unsigned int offset(const color_plane color)
Here is the call graph for this function:

◆ row()

unsigned char* bitmap_image::row ( unsigned int  row_index) const
inline

Definition at line 155 of file bitmap_image.hpp.

Referenced by checkered_pattern(), copy_from(), horizontal_flip(), psnr(), psnr_region(), region(), reverse_channels(), set_region(), and vertical_flip().

156  {
157  return const_cast<unsigned char*>(&data_[(row_index * row_increment_)]);
158  }
Here is the caller graph for this function:

◆ save_image()

void bitmap_image::save_image ( const std::string &  file_name) const
inline

Definition at line 416 of file bitmap_image.hpp.

Referenced by test01(), test02(), test03(), test04(), test05(), test06(), test07(), test08(), test09(), test10(), test11(), test12(), test13(), test14(), test15(), test17(), test18(), test19(), and test20().

417  {
418  std::ofstream stream(file_name.c_str(),std::ios::binary);
419 
420  if (!stream)
421  {
422  std::cerr << "bitmap_image::save_image(): Error - Could not open file " << file_name << " for writing!" << std::endl;
423  return;
424  }
425 
426  bitmap_information_header bih;
427 
428  bih.width = width_;
429  bih.height = height_;
430  bih.bit_count = static_cast<unsigned short>(bytes_per_pixel_ << 3);
431  bih.clr_important = 0;
432  bih.clr_used = 0;
433  bih.compression = 0;
434  bih.planes = 1;
435  bih.size = bih.struct_size();
436  bih.x_pels_per_meter = 0;
437  bih.y_pels_per_meter = 0;
438  bih.size_image = (((bih.width * bytes_per_pixel_) + 3) & 0x0000FFFC) * bih.height;
439 
440  bitmap_file_header bfh;
441 
442  bfh.type = 19778;
443  bfh.size = bfh.struct_size() + bih.struct_size() + bih.size_image;
444  bfh.reserved1 = 0;
445  bfh.reserved2 = 0;
446  bfh.off_bits = bih.struct_size() + bfh.struct_size();
447 
448  write_bfh(stream,bfh);
449  write_bih(stream,bih);
450 
451  unsigned int padding = (4 - ((3 * width_) % 4)) % 4;
452  char padding_data[4] = { 0x00, 0x00, 0x00, 0x00 };
453 
454  for (unsigned int i = 0; i < height_; ++i)
455  {
456  const unsigned char* data_ptr = &data_[(row_increment_ * (height_ - i - 1))];
457 
458  stream.write(reinterpret_cast<const char*>(data_ptr), sizeof(unsigned char) * bytes_per_pixel_ * width_);
459  stream.write(padding_data,padding);
460  }
461 
462  stream.close();
463  }
Here is the caller graph for this function:

◆ set_all_channels() [1/2]

void bitmap_image::set_all_channels ( const unsigned char &  value)
inline

Definition at line 509 of file bitmap_image.hpp.

References data().

Referenced by test19().

510  {
511  for (unsigned char* itr = data(); itr < end(); )
512  {
513  *(itr++) = value;
514  }
515  }
const unsigned char * data() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_all_channels() [2/2]

void bitmap_image::set_all_channels ( const unsigned char &  r_value,
const unsigned char &  g_value,
const unsigned char &  b_value 
)
inline

Definition at line 517 of file bitmap_image.hpp.

References data().

520  {
521  for (unsigned char* itr = (data() + 0); itr < end(); itr += bytes_per_pixel_)
522  {
523  *(itr + 0) = b_value;
524  *(itr + 1) = g_value;
525  *(itr + 2) = r_value;
526  }
527  }
const unsigned char * data() const
Here is the call graph for this function:

◆ set_all_ith_bits_high()

void bitmap_image::set_all_ith_bits_high ( const unsigned int  bitr_index)
inline

Definition at line 475 of file bitmap_image.hpp.

References data().

476  {
477  unsigned char mask = static_cast<unsigned char>(1 << bitr_index);
478 
479  for (unsigned char* itr = data(); itr != end(); ++itr)
480  {
481  *itr |= mask;
482  }
483  }
const unsigned char * data() const
Here is the call graph for this function:

◆ set_all_ith_bits_low()

void bitmap_image::set_all_ith_bits_low ( const unsigned int  bitr_index)
inline

Definition at line 465 of file bitmap_image.hpp.

References data().

Referenced by test05().

466  {
467  unsigned char mask = static_cast<unsigned char>(~(1 << bitr_index));
468 
469  for (unsigned char* itr = data(); itr != end(); ++itr)
470  {
471  *itr &= mask;
472  }
473  }
const unsigned char * data() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_all_ith_channels()

void bitmap_image::set_all_ith_channels ( const unsigned int &  channel,
const unsigned char &  value 
)
inline

Definition at line 485 of file bitmap_image.hpp.

References data().

486  {
487  for (unsigned char* itr = (data() + channel); itr < end(); itr += bytes_per_pixel_)
488  {
489  *itr = value;
490  }
491  }
const unsigned char * data() const
Here is the call graph for this function:

◆ set_channel()

void bitmap_image::set_channel ( const color_plane  color,
const unsigned char &  value 
)
inline

Definition at line 493 of file bitmap_image.hpp.

References data(), and offset().

494  {
495  for (unsigned char* itr = (data() + offset(color)); itr < end(); itr += bytes_per_pixel_)
496  {
497  *itr = value;
498  }
499  }
const unsigned char * data() const
unsigned int offset(const color_plane color)
Here is the call graph for this function:

◆ set_pixel() [1/2]

void bitmap_image::set_pixel ( const unsigned int  x,
const unsigned int  y,
const unsigned char  red,
const unsigned char  green,
const unsigned char  blue 
)
inline

Definition at line 180 of file bitmap_image.hpp.

Referenced by convert_rsp_to_image(), plasma(), set_pixel(), test09(), and test20().

184  {
185  const unsigned int y_offset = y * row_increment_;
186  const unsigned int x_offset = x * bytes_per_pixel_;
187 
188  data_[y_offset + x_offset + 0] = blue;
189  data_[y_offset + x_offset + 1] = green;
190  data_[y_offset + x_offset + 2] = red;
191  }
Here is the caller graph for this function:

◆ set_pixel() [2/2]

template<typename RGB >
void bitmap_image::set_pixel ( const unsigned int  x,
const unsigned int  y,
const RGB &  colour 
)
inline

Definition at line 194 of file bitmap_image.hpp.

References set_pixel().

195  {
196  set_pixel(x, y, colour.red, colour.green, colour.blue);
197  }
void set_pixel(const unsigned int x, const unsigned int y, const unsigned char red, const unsigned char green, const unsigned char blue)
Here is the call graph for this function:

◆ set_region() [1/3]

bool bitmap_image::set_region ( const unsigned int &  x,
const unsigned int &  y,
const unsigned int &  width,
const unsigned int &  height,
const unsigned char &  value 
)
inline

Definition at line 273 of file bitmap_image.hpp.

References height(), and row().

Referenced by hierarchical_psnr_r().

278  {
279  if ((x + width ) > width_ ) { return false; }
280  if ((y + height) > height_) { return false; }
281 
282  for (unsigned int r = 0; r < height; ++r)
283  {
284  unsigned char* itr = row(r + y) + x * bytes_per_pixel_;
285  unsigned char* itr_end = itr + (width * bytes_per_pixel_);
286 
287  std::fill(itr,itr_end,value);
288  }
289 
290  return true;
291  }
unsigned int height() const
unsigned int width() const
unsigned char * row(unsigned int row_index) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_region() [2/3]

bool bitmap_image::set_region ( const unsigned int &  x,
const unsigned int &  y,
const unsigned int &  width,
const unsigned int &  height,
const color_plane  color,
const unsigned char &  value 
)
inline

Definition at line 293 of file bitmap_image.hpp.

References height(), offset(), and row().

299  {
300  if ((x + width ) > width_ ) { return false; }
301  if ((y + height) > height_) { return false; }
302 
303  const unsigned int color_plane_offset = offset(color);
304 
305  for (unsigned int r = 0; r < height; ++r)
306  {
307  unsigned char* itr = row(r + y) + x * bytes_per_pixel_ + color_plane_offset;
308  unsigned char* itr_end = itr + (width * bytes_per_pixel_);
309 
310  while (itr != itr_end)
311  {
312  *itr = value;
313  itr += bytes_per_pixel_;
314  }
315  }
316 
317  return true;
318  }
unsigned int height() const
unsigned int width() const
unsigned char * row(unsigned int row_index) const
unsigned int offset(const color_plane color)
Here is the call graph for this function:

◆ set_region() [3/3]

bool bitmap_image::set_region ( const unsigned int &  x,
const unsigned int &  y,
const unsigned int &  width,
const unsigned int &  height,
const unsigned char &  red,
const unsigned char &  green,
const unsigned char &  blue 
)
inline

Definition at line 320 of file bitmap_image.hpp.

References height(), and row().

327  {
328  if ((x + width ) > width_ ) { return false; }
329  if ((y + height) > height_) { return false; }
330 
331  for (unsigned int r = 0; r < height; ++r)
332  {
333  unsigned char* itr = row(r + y) + x * bytes_per_pixel_;
334  unsigned char* itr_end = itr + (width * bytes_per_pixel_);
335 
336  while (itr != itr_end)
337  {
338  *(itr++) = blue;
339  *(itr++) = green;
340  *(itr++) = red;
341  }
342  }
343 
344  return true;
345  }
unsigned int height() const
unsigned int width() const
unsigned char * row(unsigned int row_index) const
Here is the call graph for this function:

◆ setwidth_height()

void bitmap_image::setwidth_height ( const unsigned int  width,
const unsigned int  height,
const bool  clear = false 
)
inline

Definition at line 400 of file bitmap_image.hpp.

References clear(), height(), and width().

Referenced by export_color_plane(), reflective_image(), region(), sobel_operator(), subsample(), and upsample().

403  {
404  data_.clear();
405  width_ = width;
406  height_ = height;
407 
408  create_bitmap();
409 
410  if (clear)
411  {
412  std::fill(data_.begin(),data_.end(),0x00);
413  }
414  }
unsigned int height() const
unsigned int width() const
void clear(const unsigned char v=0x00)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ subsample()

void bitmap_image::subsample ( bitmap_image dest)
inline

Definition at line 920 of file bitmap_image.hpp.

References clear(), data(), and setwidth_height().

Referenced by test03().

921  {
922  /*
923  Half sub-sample of original image.
924  */
925  unsigned int w = 0;
926  unsigned int h = 0;
927 
928  bool odd_width = false;
929  bool odd_height = false;
930 
931  if (0 == (width_ % 2))
932  w = width_ / 2;
933  else
934  {
935  w = 1 + (width_ / 2);
936  odd_width = true;
937  }
938 
939  if (0 == (height_ % 2))
940  h = height_ / 2;
941  else
942  {
943  h = 1 + (height_ / 2);
944  odd_height = true;
945  }
946 
947  unsigned int horizontal_upper = (odd_width) ? (w - 1) : w;
948  unsigned int vertical_upper = (odd_height) ? (h - 1) : h;
949 
950  dest.setwidth_height(w,h);
951  dest.clear();
952 
953  unsigned char* s_itr[3];
954  const unsigned char* itr1[3];
955  const unsigned char* itr2[3];
956 
957  s_itr[0] = dest.data() + 0;
958  s_itr[1] = dest.data() + 1;
959  s_itr[2] = dest.data() + 2;
960 
961  itr1[0] = data() + 0;
962  itr1[1] = data() + 1;
963  itr1[2] = data() + 2;
964 
965  itr2[0] = data() + row_increment_ + 0;
966  itr2[1] = data() + row_increment_ + 1;
967  itr2[2] = data() + row_increment_ + 2;
968 
969  unsigned int total = 0;
970 
971  for (unsigned int j = 0; j < vertical_upper; ++j)
972  {
973  for (unsigned int i = 0; i < horizontal_upper; ++i)
974  {
975  for (unsigned int k = 0; k < bytes_per_pixel_; s_itr[k] += bytes_per_pixel_, ++k)
976  {
977  total = 0;
978  total += *(itr1[k]);
979  total += *(itr1[k]);
980  total += *(itr2[k]);
981  total += *(itr2[k]);
982 
983  itr1[k] += bytes_per_pixel_;
984  itr1[k] += bytes_per_pixel_;
985  itr2[k] += bytes_per_pixel_;
986  itr2[k] += bytes_per_pixel_;
987 
988  *(s_itr[k]) = static_cast<unsigned char>(total >> 2);
989  }
990  }
991 
992  if (odd_width)
993  {
994  for (unsigned int k = 0; k < bytes_per_pixel_; s_itr[k] += bytes_per_pixel_, ++k)
995  {
996  total = 0;
997  total += *(itr1[k]);
998  total += *(itr2[k]);
999 
1000  itr1[k] += bytes_per_pixel_;
1001  itr2[k] += bytes_per_pixel_;
1002 
1003  *(s_itr[k]) = static_cast<unsigned char>(total >> 1);
1004  }
1005  }
1006 
1007  for (unsigned int k = 0; k < bytes_per_pixel_; ++k)
1008  {
1009  itr1[k] += row_increment_;
1010  }
1011 
1012  if (j != (vertical_upper - 1))
1013  {
1014  for (unsigned int k = 0; k < bytes_per_pixel_; ++k)
1015  {
1016  itr2[k] += row_increment_;
1017  }
1018  }
1019  }
1020 
1021  if (odd_height)
1022  {
1023  for (unsigned int i = 0; i < horizontal_upper; ++i)
1024  {
1025  for (unsigned int k = 0; k < bytes_per_pixel_; s_itr[k] += bytes_per_pixel_, ++k)
1026  {
1027  total = 0;
1028  total += *(itr1[k]);
1029  total += *(itr2[k]);
1030 
1031  itr1[k] += bytes_per_pixel_;
1032  itr2[k] += bytes_per_pixel_;
1033 
1034  *(s_itr[k]) = static_cast<unsigned char>(total >> 1);
1035  }
1036  }
1037 
1038  if (odd_width)
1039  {
1040  for (unsigned int k = 0; k < bytes_per_pixel_; ++k)
1041  {
1042  (*(s_itr[k])) = *(itr1[k]);
1043  }
1044  }
1045  }
1046  }
const unsigned char * data() const
void setwidth_height(const unsigned int width, const unsigned int height, const bool clear=false)
void clear(const unsigned char v=0x00)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ upsample()

void bitmap_image::upsample ( bitmap_image dest)
inline

Definition at line 1048 of file bitmap_image.hpp.

References clear(), data(), and setwidth_height().

Referenced by test04().

1049  {
1050  /*
1051  2x up-sample of original image.
1052  */
1053 
1054  dest.setwidth_height(2 * width_ ,2 * height_);
1055  dest.clear();
1056 
1057  const unsigned char* s_itr[3];
1058  unsigned char* itr1[3];
1059  unsigned char* itr2[3];
1060 
1061  s_itr[0] = data() + 0;
1062  s_itr[1] = data() + 1;
1063  s_itr[2] = data() + 2;
1064 
1065  itr1[0] = dest.data() + 0;
1066  itr1[1] = dest.data() + 1;
1067  itr1[2] = dest.data() + 2;
1068 
1069  itr2[0] = dest.data() + dest.row_increment_ + 0;
1070  itr2[1] = dest.data() + dest.row_increment_ + 1;
1071  itr2[2] = dest.data() + dest.row_increment_ + 2;
1072 
1073  for (unsigned int j = 0; j < height_; ++j)
1074  {
1075  for (unsigned int i = 0; i < width_; ++i)
1076  {
1077  for (unsigned int k = 0; k < bytes_per_pixel_; s_itr[k] += bytes_per_pixel_, ++k)
1078  {
1079  *(itr1[k]) = *(s_itr[k]); itr1[k] += bytes_per_pixel_;
1080  *(itr1[k]) = *(s_itr[k]); itr1[k] += bytes_per_pixel_;
1081 
1082  *(itr2[k]) = *(s_itr[k]); itr2[k] += bytes_per_pixel_;
1083  *(itr2[k]) = *(s_itr[k]); itr2[k] += bytes_per_pixel_;
1084  }
1085  }
1086 
1087  for (unsigned int k = 0; k < bytes_per_pixel_; ++k)
1088  {
1089  itr1[k] += dest.row_increment_;
1090  itr2[k] += dest.row_increment_;
1091  }
1092  }
1093  }
const unsigned char * data() const
void setwidth_height(const unsigned int width, const unsigned int height, const bool clear=false)
void clear(const unsigned char v=0x00)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vertical_flip()

void bitmap_image::vertical_flip ( )
inline

Definition at line 639 of file bitmap_image.hpp.

References row().

Referenced by reflective_image(), and test02().

640  {
641  for (unsigned int y = 0; y < (height_ / 2); ++y)
642  {
643  unsigned char* itr1 = row(y);
644  unsigned char* itr2 = row(height_ - y - 1);
645 
646  for (std::size_t x = 0; x < row_increment_; ++x)
647  {
648  std::swap(*(itr1 + x),*(itr2 + x));
649  }
650  }
651  }
unsigned char * row(unsigned int row_index) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ width()

unsigned int bitmap_image::width ( ) const
inline

Definition at line 380 of file bitmap_image.hpp.

Referenced by checkered_pattern(), convert_rsp_to_image(), hierarchical_psnr(), image_drawer::pen_width(), plasma(), psnr(), psnr_region(), reverse_channels(), setwidth_height(), sobel_operator(), subsample(), test08(), test15(), test16(), test17(), test18(), and upsample().

381  {
382  return width_;
383  }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: