C++ Bitmap Library  release
Public Member Functions | List of all members
image_drawer Class Reference

#include <bitmap_image.hpp>

Public Member Functions

 image_drawer (bitmap_image &image)
 
void rectangle (int x1, int y1, int x2, int y2)
 
void triangle (int x1, int y1, int x2, int y2, int x3, int y3)
 
void quadix (int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
 
void line_segment (int x1, int y1, int x2, int y2)
 
void horiztonal_line_segment (int x1, int x2, int y)
 
void vertical_line_segment (int y1, int y2, int x)
 
void ellipse (int centerx, int centery, int a, int b)
 
void circle (int centerx, int centery, int radius)
 
void plot_pen_pixel (int x, int y)
 
void plot_pixel (int x, int y)
 
void pen_width (const unsigned int &width)
 
void pen_color (const unsigned char &red, const unsigned char &green, const unsigned char &blue)
 
template<typename RGB >
void pen_color (const RGB colour)
 

Detailed Description

Definition at line 2096 of file bitmap_image.hpp.

Constructor & Destructor Documentation

◆ image_drawer()

image_drawer::image_drawer ( bitmap_image image)
inline

Definition at line 2100 of file bitmap_image.hpp.

2101  : image_(image),
2102  pen_width_(1),
2103  pen_color_red_ (0),
2104  pen_color_green_(0),
2105  pen_color_blue_ (0)
2106  {}

Member Function Documentation

◆ circle()

void image_drawer::circle ( int  centerx,
int  centery,
int  radius 
)
inline

Definition at line 2275 of file bitmap_image.hpp.

2276  {
2277  int x = 0;
2278  int d = (1 - radius) << 1;
2279 
2280  while (radius >= 0)
2281  {
2282  plot_pen_pixel(centerx + x, centery + radius);
2283  plot_pen_pixel(centerx + x, centery - radius);
2284  plot_pen_pixel(centerx - x, centery + radius);
2285  plot_pen_pixel(centerx - x, centery - radius);
2286 
2287  if ((d + radius) > 0)
2288  d -= ((--radius) << 1) - 1;
2289  if (x > d)
2290  d += ((++x) << 1) + 1;
2291  }
2292  }
void plot_pen_pixel(int x, int y)

◆ ellipse()

void image_drawer::ellipse ( int  centerx,
int  centery,
int  a,
int  b 
)
inline

Definition at line 2196 of file bitmap_image.hpp.

2197  {
2198  int t1 = a * a;
2199  int t2 = t1 << 1;
2200  int t3 = t2 << 1;
2201  int t4 = b * b;
2202  int t5 = t4 << 1;
2203  int t6 = t5 << 1;
2204  int t7 = a * t5;
2205  int t8 = t7 << 1;
2206  int t9 = 0;
2207 
2208  int d1 = t2 - t7 + (t4 >> 1);
2209  int d2 = (t1 >> 1) - t8 + t5;
2210  int x = a;
2211  int y = 0;
2212 
2213  int negative_tx = centerx - x;
2214  int positive_tx = centerx + x;
2215  int negative_ty = centery - y;
2216  int positive_ty = centery + y;
2217 
2218  while (d2 < 0)
2219  {
2220  plot_pen_pixel(positive_tx, positive_ty);
2221  plot_pen_pixel(positive_tx, negative_ty);
2222  plot_pen_pixel(negative_tx, positive_ty);
2223  plot_pen_pixel(negative_tx, negative_ty);
2224 
2225  ++y;
2226 
2227  t9 = t9 + t3;
2228 
2229  if (d1 < 0)
2230  {
2231  d1 = d1 + t9 + t2;
2232  d2 = d2 + t9;
2233  }
2234  else
2235  {
2236  x--;
2237  t8 = t8 - t6;
2238  d1 = d1 + (t9 + t2 - t8);
2239  d2 = d2 + (t9 + t5 - t8);
2240  negative_tx = centerx - x;
2241  positive_tx = centerx + x;
2242  }
2243 
2244  negative_ty = centery - y;
2245  positive_ty = centery + y;
2246  }
2247 
2248  do
2249  {
2250  plot_pen_pixel(positive_tx, positive_ty);
2251  plot_pen_pixel(positive_tx, negative_ty);
2252  plot_pen_pixel(negative_tx, positive_ty);
2253  plot_pen_pixel(negative_tx, negative_ty);
2254 
2255  x--;
2256  t8 = t8 - t6;
2257 
2258  if (d2 < 0)
2259  {
2260  ++y;
2261  t9 = t9 + t3;
2262  d2 = d2 + (t9 + t5 - t8);
2263  negative_ty = centery - y;
2264  positive_ty = centery + y;
2265  }
2266  else
2267  d2 = d2 + (t5 - t8);
2268 
2269  negative_tx = centerx - x;
2270  positive_tx = centerx + x;
2271  }
2272  while (x >= 0);
2273  }
void plot_pen_pixel(int x, int y)

◆ horiztonal_line_segment()

void image_drawer::horiztonal_line_segment ( int  x1,
int  x2,
int  y 
)
inline

Definition at line 2170 of file bitmap_image.hpp.

2171  {
2172  if (x1 > x2)
2173  {
2174  std::swap(x1,x2);
2175  }
2176 
2177  for (int i = 0; i < (x2 - x1); ++i)
2178  {
2179  plot_pen_pixel(x1 + i,y);
2180  }
2181  }
void plot_pen_pixel(int x, int y)

◆ line_segment()

void image_drawer::line_segment ( int  x1,
int  y1,
int  x2,
int  y2 
)
inline

Definition at line 2131 of file bitmap_image.hpp.

2132  {
2133  int steep = 0;
2134  int sx = ((x2 - x1) > 0) ? 1 : -1;
2135  int sy = ((y2 - y1) > 0) ? 1 : -1;
2136  int dx = abs(x2 - x1);
2137  int dy = abs(y2 - y1);
2138 
2139  if (dy > dx)
2140  {
2141  std::swap(x1,y1);
2142  std::swap(dx,dy);
2143  std::swap(sx,sy);
2144 
2145  steep = 1;
2146  }
2147 
2148  int e = 2 * dy - dx;
2149 
2150  for (int i = 0; i < dx; ++i)
2151  {
2152  if (steep)
2153  plot_pen_pixel(y1,x1);
2154  else
2155  plot_pen_pixel(x1,y1);
2156 
2157  while (e >= 0)
2158  {
2159  y1 += sy;
2160  e -= (dx << 1);
2161  }
2162 
2163  x1 += sx;
2164  e += (dy << 1);
2165  }
2166 
2167  plot_pen_pixel(x2,y2);
2168  }
void plot_pen_pixel(int x, int y)

◆ pen_color() [1/2]

void image_drawer::pen_color ( const unsigned char &  red,
const unsigned char &  green,
const unsigned char &  blue 
)
inline

Definition at line 2350 of file bitmap_image.hpp.

Referenced by test18().

2353  {
2354  pen_color_red_ = red;
2355  pen_color_green_ = green;
2356  pen_color_blue_ = blue;
2357  }
Here is the caller graph for this function:

◆ pen_color() [2/2]

template<typename RGB >
void image_drawer::pen_color ( const RGB  colour)
inline

Definition at line 2360 of file bitmap_image.hpp.

References bitmap_image::operator=().

2361  {
2362  pen_color_red_ = colour.red;
2363  pen_color_green_ = colour.green;
2364  pen_color_blue_ = colour.blue;
2365  }
Here is the call graph for this function:

◆ pen_width()

void image_drawer::pen_width ( const unsigned int &  width)
inline

Definition at line 2342 of file bitmap_image.hpp.

References bitmap_image::width().

2343  {
2344  if ((width > 0) && (width < 4))
2345  {
2346  pen_width_ = width;
2347  }
2348  }
Here is the call graph for this function:

◆ plot_pen_pixel()

void image_drawer::plot_pen_pixel ( int  x,
int  y 
)
inline

Definition at line 2294 of file bitmap_image.hpp.

2295  {
2296  switch (pen_width_)
2297  {
2298  case 1 : plot_pixel(x,y);
2299  break;
2300 
2301  case 2 : {
2302  plot_pixel(x , y );
2303  plot_pixel(x + 1, y );
2304  plot_pixel(x + 1, y + 1);
2305  plot_pixel(x , y + 1);
2306  }
2307  break;
2308 
2309  case 3 : {
2310  plot_pixel(x , y - 1);
2311  plot_pixel(x - 1, y - 1);
2312  plot_pixel(x + 1, y - 1);
2313 
2314  plot_pixel(x , y );
2315  plot_pixel(x - 1, y );
2316  plot_pixel(x + 1, y );
2317 
2318  plot_pixel(x , y + 1);
2319  plot_pixel(x - 1, y + 1);
2320  plot_pixel(x + 1, y + 1);
2321  }
2322  break;
2323 
2324  default : plot_pixel(x,y);
2325  break;
2326  }
2327  }
void plot_pixel(int x, int y)

◆ plot_pixel()

void image_drawer::plot_pixel ( int  x,
int  y 
)
inline

Definition at line 2329 of file bitmap_image.hpp.

2330  {
2331  if (
2332  (x < 0) ||
2333  (y < 0) ||
2334  (x >= static_cast<int>(image_.width ())) ||
2335  (y >= static_cast<int>(image_.height()))
2336  )
2337  return;
2338 
2339  image_.set_pixel(x,y,pen_color_red_,pen_color_green_,pen_color_blue_);
2340  }
void set_pixel(const unsigned int x, const unsigned int y, const unsigned char red, const unsigned char green, const unsigned char blue)
unsigned int height() const
unsigned int width() const

◆ quadix()

void image_drawer::quadix ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3,
int  x4,
int  y4 
)
inline

Definition at line 2123 of file bitmap_image.hpp.

2124  {
2125  line_segment(x1,y1,x2,y2);
2126  line_segment(x2,y2,x3,y3);
2127  line_segment(x3,y3,x4,y4);
2128  line_segment(x4,y4,x1,y1);
2129  }
void line_segment(int x1, int y1, int x2, int y2)

◆ rectangle()

void image_drawer::rectangle ( int  x1,
int  y1,
int  x2,
int  y2 
)
inline

Definition at line 2108 of file bitmap_image.hpp.

2109  {
2110  line_segment(x1,y1,x2,y1);
2111  line_segment(x2,y1,x2,y2);
2112  line_segment(x2,y2,x1,y2);
2113  line_segment(x1,y2,x1,y1);
2114  }
void line_segment(int x1, int y1, int x2, int y2)

◆ triangle()

void image_drawer::triangle ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3 
)
inline

Definition at line 2116 of file bitmap_image.hpp.

2117  {
2118  line_segment(x1,y1,x2,y2);
2119  line_segment(x2,y2,x3,y3);
2120  line_segment(x3,y3,x1,y1);
2121  }
void line_segment(int x1, int y1, int x2, int y2)

◆ vertical_line_segment()

void image_drawer::vertical_line_segment ( int  y1,
int  y2,
int  x 
)
inline

Definition at line 2183 of file bitmap_image.hpp.

Referenced by test18().

2184  {
2185  if (y1 > y2)
2186  {
2187  std::swap(y1,y2);
2188  }
2189 
2190  for (int i = 0; i < (y2 - y1); ++i)
2191  {
2192  plot_pen_pixel(x, y1 + i);
2193  }
2194  }
void plot_pen_pixel(int x, int y)
Here is the caller graph for this function:

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