C++ Bitmap Library  release
Macros | Functions
bitmap_test.cpp File Reference
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include "bitmap_image.hpp"
Include dependency graph for bitmap_test.cpp:

Go to the source code of this file.

Macros

#define log2(x)   (std::log(1.0 * x) / std::log(2.0))
 

Functions

void test01 ()
 
void test02 ()
 
void test03 ()
 
void test04 ()
 
void test05 ()
 
void test06 ()
 
void test07 ()
 
void test08 ()
 
void test09 ()
 
void test10 ()
 
void test11 ()
 
void test12 ()
 
void test13 ()
 
void test14 ()
 
void test15 ()
 
void test16 ()
 
void test17 ()
 
void test18 ()
 
void test19 ()
 
void test20 ()
 
int main ()
 

Macro Definition Documentation

◆ log2

#define log2 (   x)    (std::log(1.0 * x) / std::log(2.0))

Referenced by test20().

Function Documentation

◆ main()

int main ( )

Definition at line 730 of file bitmap_test.cpp.

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

731 {
732  test01();
733  test02();
734  test03();
735  test04();
736  test05();
737  test06();
738  test07();
739  test08();
740  test09();
741  test10();
742  test11();
743  test12();
744  test13();
745  test14();
746  test15();
747  test16();
748  test17();
749  test18();
750  test19();
751  test20();
752  return 0;
753 }
void test12()
void test05()
void test08()
void test07()
void test06()
void test03()
Definition: bitmap_test.cpp:68
void test09()
void test17()
void test18()
void test10()
void test13()
void test11()
void test01()
Definition: bitmap_test.cpp:31
void test16()
void test20()
void test04()
Definition: bitmap_test.cpp:94
void test02()
Definition: bitmap_test.cpp:46
void test14()
void test19()
void test15()
Here is the call graph for this function:

◆ test01()

void test01 ( )

Definition at line 31 of file bitmap_test.cpp.

References bitmap_image::save_image().

Referenced by main().

32 {
33  std::string file_name("image.bmp");
34 
35  bitmap_image image(file_name);
36 
37  if (!image)
38  {
39  printf("test01() - Error - Failed to open '%s'\n",file_name.c_str());
40  return;
41  }
42 
43  image.save_image("test01_saved.bmp");
44 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test02()

void test02 ( )

Definition at line 46 of file bitmap_test.cpp.

References bitmap_image::horizontal_flip(), bitmap_image::save_image(), and bitmap_image::vertical_flip().

Referenced by main().

47 {
48  std::string file_name("image.bmp");
49 
50  bitmap_image image(file_name);
51 
52  if (!image)
53  {
54  printf("test02() - Error - Failed to open '%s'\n",file_name.c_str());
55  return;
56  }
57 
58  image.save_image("test02_saved.bmp");
59 
60  image.vertical_flip();
61  image.save_image("test02_saved_vert_flip.bmp");
62  image.vertical_flip();
63 
64  image.horizontal_flip();
65  image.save_image("test02_saved_horiz_flip.bmp");
66 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test03()

void test03 ( )

Definition at line 68 of file bitmap_test.cpp.

References bitmap_image::save_image(), and bitmap_image::subsample().

Referenced by main().

69 {
70  std::string file_name("image.bmp");
71 
72  bitmap_image image(file_name);
73 
74  if (!image)
75  {
76  printf("test03() - Error - Failed to open '%s'\n",file_name.c_str());
77  return;
78  }
79 
80  bitmap_image subsampled_image1;
81  bitmap_image subsampled_image2;
82  bitmap_image subsampled_image3;
83 
84  image.subsample(subsampled_image1);
85  subsampled_image1.save_image("test03_1xsubsampled_image.bmp");
86 
87  subsampled_image1.subsample(subsampled_image2);
88  subsampled_image2.save_image("test03_2xsubsampled_image.bmp");
89 
90  subsampled_image2.subsample(subsampled_image3);
91  subsampled_image3.save_image("test03_3xsubsampled_image.bmp");
92 }
void subsample(bitmap_image &dest)
void save_image(const std::string &file_name) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test04()

void test04 ( )

Definition at line 94 of file bitmap_test.cpp.

References bitmap_image::save_image(), and bitmap_image::upsample().

Referenced by main().

95 {
96  std::string file_name("image.bmp");
97 
98  bitmap_image image(file_name);
99 
100  if (!image)
101  {
102  printf("test04() - Error - Failed to open '%s'\n",file_name.c_str());
103  return;
104  }
105 
106  bitmap_image upsampled_image1;
107  bitmap_image upsampled_image2;
108  bitmap_image upsampled_image3;
109 
110  image.upsample(upsampled_image1);
111  upsampled_image1.save_image("test04_1xupsampled_image.bmp");
112 
113  upsampled_image1.upsample(upsampled_image2);
114  upsampled_image2.save_image("test04_2xupsampled_image.bmp");
115 
116  upsampled_image2.upsample(upsampled_image3);
117  upsampled_image3.save_image("test04_3xupsampled_image.bmp");
118 }
void save_image(const std::string &file_name) const
void upsample(bitmap_image &dest)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test05()

void test05 ( )

Definition at line 120 of file bitmap_test.cpp.

References bitmap_image::save_image(), and bitmap_image::set_all_ith_bits_low().

Referenced by main().

121 {
122  std::string file_name("image.bmp");
123 
124  bitmap_image image(file_name);
125 
126  if (!image)
127  {
128  printf("test05() - Error - Failed to open '%s'\n",file_name.c_str());
129  return;
130  }
131 
132  image.set_all_ith_bits_low(0);
133  image.save_image("test05_lsb0_removed_saved.bmp");
134  image.set_all_ith_bits_low(1);
135  image.save_image("test05_lsb01_removed_saved.bmp");
136  image.set_all_ith_bits_low(2);
137  image.save_image("test05_lsb012_removed_saved.bmp");
138  image.set_all_ith_bits_low(3);
139  image.save_image("test05_lsb0123_removed_saved.bmp");
140  image.set_all_ith_bits_low(4);
141  image.save_image("test05_lsb01234_removed_saved.bmp");
142  image.set_all_ith_bits_low(5);
143  image.save_image("test05_lsb012345_removed_saved.bmp");
144  image.set_all_ith_bits_low(6);
145  image.save_image("test05_lsb0123456_removed_saved.bmp");
146 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test06()

void test06 ( )

Definition at line 148 of file bitmap_test.cpp.

References bitmap_image::blue_plane, bitmap_image::export_color_plane(), bitmap_image::green_plane, bitmap_image::red_plane, and bitmap_image::save_image().

Referenced by main().

149 {
150  std::string file_name("image.bmp");
151 
152  bitmap_image image(file_name);
153 
154  if (!image)
155  {
156  printf("test06() - Error - Failed to open '%s'\n",file_name.c_str());
157  return;
158  }
159 
160  bitmap_image red_channel_image;
161  image.export_color_plane(bitmap_image::red_plane,red_channel_image);
162  red_channel_image.save_image("test06_red_channel_image.bmp");
163 
164  bitmap_image green_channel_image;
165  image.export_color_plane(bitmap_image::green_plane,green_channel_image);
166  green_channel_image.save_image("test06_green_channel_image.bmp");
167 
168  bitmap_image blue_channel_image;
169  image.export_color_plane(bitmap_image::blue_plane,blue_channel_image);
170  blue_channel_image.save_image("test06_blue_channel_image.bmp");
171 }
void export_color_plane(const color_plane color, unsigned char *image)
void save_image(const std::string &file_name) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test07()

void test07 ( )

Definition at line 173 of file bitmap_test.cpp.

References bitmap_image::convert_to_grayscale(), and bitmap_image::save_image().

Referenced by main().

174 {
175  std::string file_name("image.bmp");
176 
177  bitmap_image image(file_name);
178 
179  if (!image)
180  {
181  printf("test07() - Error - Failed to open '%s'\n",file_name.c_str());
182  return;
183  }
184 
185  image.convert_to_grayscale();
186  image.save_image("test07_grayscale_image.bmp");
187 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test08()

void test08 ( )

Definition at line 189 of file bitmap_test.cpp.

References bitmap_image::height(), bitmap_image::region(), bitmap_image::save_image(), and bitmap_image::width().

Referenced by main().

190 {
191  std::string file_name("image.bmp");
192 
193  bitmap_image image(file_name);
194 
195  if (!image)
196  {
197  printf("test08() - Error - Failed to open '%s'\n",file_name.c_str());
198  return;
199  }
200 
201  bitmap_image image1;
202  bitmap_image image2;
203  bitmap_image image3;
204  bitmap_image image4;
205 
206  unsigned int w = image.width();
207  unsigned int h = image.height();
208 
209  if (!image.region(0,0, w / 2, h / 2,image1))
210  {
211  std::cout << "ERROR: upper_left_image" << std::endl;
212  }
213 
214  if (!image.region((w - 1) / 2, 0, w / 2, h / 2,image2))
215  {
216  std::cout << "ERROR: upper_right_image" << std::endl;
217  }
218 
219  if (!image.region(0,(h - 1) / 2, w / 2, h / 2,image3))
220  {
221  std::cout << "ERROR: lower_left_image" << std::endl;
222  }
223 
224  if (!image.region((w - 1) / 2, (h - 1) / 2, w / 2, h / 2,image4))
225  {
226  std::cout << "ERROR: lower_right_image" << std::endl;
227  }
228 
229  image1.save_image("test08_upper_left_image.bmp");
230  image2.save_image("test08_upper_right_image.bmp");
231  image3.save_image("test08_lower_left_image.bmp");
232  image4.save_image("test08_lower_right_image.bmp");
233 }
unsigned int width() const
void save_image(const std::string &file_name) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test09()

void test09 ( )

Definition at line 235 of file bitmap_test.cpp.

References rgb_t::blue, rgb_t::green, jet_colormap, rgb_t::red, bitmap_image::save_image(), and bitmap_image::set_pixel().

Referenced by main().

236 {
237  const unsigned int dim = 1000;
238 
239  bitmap_image image(dim,dim);
240 
241  for (unsigned int x = 0; x < dim; ++x)
242  {
243  for (unsigned int y = 0; y < dim; ++y)
244  {
245  rgb_t col = jet_colormap[(x + y) % dim];
246  image.set_pixel(x,y,col.red,col.green,col.blue);
247  }
248  }
249 
250  image.save_image("test09_color_map_image.bmp");
251 }
unsigned char red
unsigned char green
const rgb_t jet_colormap[1000]
unsigned char blue
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test10()

void test10 ( )

Definition at line 253 of file bitmap_test.cpp.

References bitmap_image::invert_color_planes(), and bitmap_image::save_image().

Referenced by main().

254 {
255  std::string file_name("image.bmp");
256 
257  bitmap_image image(file_name);
258 
259  if (!image)
260  {
261  printf("test10() - Error - Failed to open '%s'\n",file_name.c_str());
262  return;
263  }
264 
265  image.invert_color_planes();
266  image.save_image("test10_inverted_color_image.bmp");
267 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test11()

void test11 ( )

Definition at line 269 of file bitmap_test.cpp.

References bitmap_image::add_to_color_plane(), bitmap_image::red_plane, and bitmap_image::save_image().

Referenced by main().

270 {
271  std::string file_name("image.bmp");
272 
273  bitmap_image image(file_name);
274 
275  if (!image)
276  {
277  printf("test11() - Error - Failed to open '%s'\n",file_name.c_str());
278  return;
279  }
280 
281  for (unsigned int i = 0; i < 10; ++i)
282  {
283  image.add_to_color_plane(bitmap_image::red_plane,10);
284  image.save_image(std::string("test11_") + static_cast<char>(48 + i) + std::string("_red_inc_image.bmp"));
285  }
286 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test12()

void test12 ( )

Definition at line 288 of file bitmap_test.cpp.

References bitmap_image::export_ycbcr(), bitmap_image::import_ycbcr(), bitmap_image::pixel_count(), and bitmap_image::save_image().

Referenced by main().

289 {
290  std::string file_name("image.bmp");
291 
292  bitmap_image image(file_name);
293 
294  if (!image)
295  {
296  printf("test12() - Error - Failed to open '%s'\n",file_name.c_str());
297  return;
298  }
299 
300  double* y = new double [image.pixel_count()];
301  double* cb = new double [image.pixel_count()];
302  double* cr = new double [image.pixel_count()];
303 
304  image.export_ycbcr(y,cb,cr);
305 
306  for (unsigned int i = 0; i < image.pixel_count(); ++i)
307  {
308  cb[i] = cr[i] = 0.0;
309  }
310 
311  image.import_ycbcr(y,cb,cr);
312  image.save_image("test12_only_y_image.bmp");
313 
314  delete[] y;
315  delete[] cb;
316  delete[] cr;
317 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test13()

void test13 ( )

Definition at line 319 of file bitmap_test.cpp.

References bitmap_image::export_ycbcr(), bitmap_image::import_ycbcr(), bitmap_image::pixel_count(), and bitmap_image::save_image().

Referenced by main().

320 {
321  std::string file_name("image.bmp");
322 
323  bitmap_image image(file_name);
324 
325  if (!image)
326  {
327  printf("test13() - Error - Failed to open '%s'\n",file_name.c_str());
328  return;
329  }
330 
331  double* y = new double [image.pixel_count()];
332  double* cb = new double [image.pixel_count()];
333  double* cr = new double [image.pixel_count()];
334 
335  image.export_ycbcr(y,cb,cr);
336 
337  for (unsigned int j = 0; j < 10; ++j)
338  {
339  for (unsigned int i = 0; i < image.pixel_count(); ++i)
340  {
341  y[i] += 15.0;
342  }
343 
344  image.import_ycbcr(y,cb,cr);
345  image.save_image(std::string("test13_") + static_cast<char>(48 + j) + std::string("_y_image.bmp"));
346  }
347 
348  delete[] y;
349  delete[] cb;
350  delete[] cr;
351 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test14()

void test14 ( )

Definition at line 353 of file bitmap_test.cpp.

References checkered_pattern(), bitmap_image::clear(), bitmap_image::red_plane, and bitmap_image::save_image().

Referenced by main().

354 {
355  bitmap_image image(512,512);
356 
357  image.clear();
359  image.save_image("test14_checkered_01.bmp");
360 
361  image.clear();
362  checkered_pattern(32,64,100,200,50,image);
363  image.save_image("test14_checkered_02.bmp");
364 }
void checkered_pattern(const unsigned int x_width, const unsigned int y_width, const unsigned char value, const bitmap_image::color_plane color, bitmap_image &image)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test15()

void test15 ( )

Definition at line 366 of file bitmap_test.cpp.

References bitmap_image::clear(), bitmap_image::height(), jet_colormap, plasma(), bitmap_image::save_image(), and bitmap_image::width().

Referenced by main().

367 {
368  bitmap_image image(1024,1024);
369 
370  image.clear();
371 
372  double c1 = 0.9;
373  double c2 = 0.5;
374  double c3 = 0.3;
375  double c4 = 0.7;
376 
377  ::srand(0xA5AA5AA5);
378  plasma(image,0,0,image.width(),image.height(),c1,c2,c3,c4,3.0,jet_colormap);
379  image.save_image("test15_plasma.bmp");
380 }
void plasma(bitmap_image &image, const double &x, const double &y, const double &width, const double &height, const double &c1, const double &c2, const double &c3, const double &c4, const double &roughness=3.0, const rgb_t colormap[]=0)
const rgb_t jet_colormap[1000]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test16()

void test16 ( )

Definition at line 382 of file bitmap_test.cpp.

References bitmap_image::alpha_blend(), bitmap_image::height(), jet_colormap, plasma(), and bitmap_image::width().

Referenced by main().

383 {
384  std::string file_name("image.bmp");
385 
386  bitmap_image image(file_name);
387 
388  if (!image)
389  {
390  printf("test16() - Error - Failed to open '%s'\n",file_name.c_str());
391  return;
392  }
393 
394  double c1 = 0.9;
395  double c2 = 0.5;
396  double c3 = 0.3;
397  double c4 = 0.7;
398 
399  bitmap_image plasma_image(image.width(),image.height());
400  plasma(plasma_image,0,0,plasma_image.width(),plasma_image.height(),c1,c2,c3,c4,3.0,jet_colormap);
401 
402  bitmap_image temp_image(image);
403 
404  temp_image.alpha_blend(0.1, plasma_image);
405  temp_image.save_image("test16_alpha_0.1.bmp");
406  temp_image = image;
407 
408  temp_image.alpha_blend(0.2, plasma_image);
409  temp_image.save_image("test16_alpha_0.2.bmp");
410  temp_image = image;
411 
412  temp_image.alpha_blend(0.3, plasma_image);
413  temp_image.save_image("test16_alpha_0.3.bmp");
414  temp_image = image;
415 
416  temp_image.alpha_blend(0.4, plasma_image);
417  temp_image.save_image("test16_alpha_0.4.bmp");
418  temp_image = image;
419 
420  temp_image.alpha_blend(0.5, plasma_image);
421  temp_image.save_image("test16_alpha_0.5.bmp");
422  temp_image = image;
423 
424  temp_image.alpha_blend(0.6, plasma_image);
425  temp_image.save_image("test16_alpha_0.6.bmp");
426  temp_image = image;
427 
428  temp_image.alpha_blend(0.7, plasma_image);
429  temp_image.save_image("test16_alpha_0.7.bmp");
430  temp_image = image;
431 
432  temp_image.alpha_blend(0.8, plasma_image);
433  temp_image.save_image("test16_alpha_0.8.bmp");
434  temp_image = image;
435 
436  temp_image.alpha_blend(0.9, plasma_image);
437  temp_image.save_image("test16_alpha_0.9.bmp");
438 }
void plasma(bitmap_image &image, const double &x, const double &y, const double &width, const double &height, const double &c1, const double &c2, const double &c3, const double &c4, const double &roughness=3.0, const rgb_t colormap[]=0)
const rgb_t jet_colormap[1000]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test17()

void test17 ( )

Definition at line 440 of file bitmap_test.cpp.

References bitmap_image::height(), jet_colormap, plasma(), bitmap_image::save_image(), and bitmap_image::width().

Referenced by main().

441 {
442  bitmap_image image(1024,1024);
443 
444  double c1 = 0.9;
445  double c2 = 0.5;
446  double c3 = 0.3;
447  double c4 = 0.7;
448 
449  plasma(image,0,0,image.width(),image.height(),c1,c2,c3,c4,3.0,jet_colormap);
450 
451  image_drawer draw(image);
452 
453  draw.pen_width(3);
454  draw.pen_color(255,0,0);
455  draw.circle(image.width() / 2 + 100, image.height() / 2, 100);
456 
457  draw.pen_width(2);
458  draw.pen_color(0,255,255);
459  draw.ellipse(image.width() / 2, image.height() / 2, 200,350);
460 
461  draw.pen_width(1);
462  draw.pen_color(255,255,0);
463  draw.rectangle(50,50,250,400);
464 
465  draw.pen_color(0,255,0);
466  draw.rectangle(450,250,850,880);
467 
468  image.save_image("test17_image_drawer.bmp");
469 }
void plasma(bitmap_image &image, const double &x, const double &y, const double &width, const double &height, const double &c1, const double &c2, const double &c3, const double &c4, const double &roughness=3.0, const rgb_t colormap[]=0)
const rgb_t jet_colormap[1000]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test18()

void test18 ( )

Definition at line 471 of file bitmap_test.cpp.

References autumn_colormap, copper_colormap, gray_colormap, bitmap_image::height(), hot_colormap, hsv_colormap, jet_colormap, palette_colormap, image_drawer::pen_color(), prism_colormap, bitmap_image::save_image(), image_drawer::vertical_line_segment(), vga_colormap, bitmap_image::width(), and yarg_colormap.

Referenced by main().

472 {
473  {
474  bitmap_image image(1000,180);
475  image_drawer draw(image);
476  const rgb_t* colormap[9] = {
480  hot_colormap,
481  hsv_colormap,
482  jet_colormap,
484  vga_colormap,
486  };
487 
488  for (unsigned int i = 0; i < image.width(); ++i)
489  {
490  for (unsigned int j = 0; j < 9; ++j)
491  {
492  draw.pen_color(colormap[j][i].red,colormap[j][i].green,colormap[j][i].blue);
493  draw.vertical_line_segment(j * 20, (j + 1) * 20, i);
494  }
495  }
496 
497  image.save_image("test18_color_maps.bmp");
498  }
499 
500  {
501  bitmap_image image(1000,500);
502  image_drawer draw(image);
503 
504  std::size_t palette_colormap_size = sizeof(palette_colormap) / sizeof(rgb_t);
505  std::size_t bar_width = image.width() / palette_colormap_size;
506 
507  for (std::size_t i = 0; i < palette_colormap_size; ++i)
508  {
509  for (std::size_t j = 0; j < bar_width; ++j)
510  {
511  draw.pen_color(palette_colormap[i].red,palette_colormap[i].green,palette_colormap[i].blue);
512  draw.vertical_line_segment(0, image.height(), static_cast<int>(i * bar_width + j));
513  }
514  }
515 
516  image.save_image("test18_palette_colormap.bmp");
517  }
518 }
const rgb_t hot_colormap[1000]
const rgb_t gray_colormap[1000]
const rgb_t jet_colormap[1000]
const rgb_t vga_colormap[1000]
const rgb_t palette_colormap[]
const rgb_t autumn_colormap[1000]
const rgb_t prism_colormap[1000]
const rgb_t copper_colormap[1000]
const rgb_t yarg_colormap[1000]
const rgb_t hsv_colormap[1000]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test19()

void test19 ( )

Definition at line 520 of file bitmap_test.cpp.

References cartesian_canvas::circle(), cartesian_canvas::horiztonal_line_segment(), cartesian_canvas::image(), cartesian_canvas::line_segment(), cartesian_canvas::max_x(), cartesian_canvas::max_y(), cartesian_canvas::min_x(), cartesian_canvas::min_y(), palette_colormap, cartesian_canvas::pen_color(), cartesian_canvas::pen_width(), cartesian_canvas::rectangle(), bitmap_image::save_image(), and bitmap_image::set_all_channels().

Referenced by main().

521 {
522  {
523  cartesian_canvas canvas(1000, 1000);
524 
525  if (!canvas)
526  {
527  printf("test19() - Error - Failed to instantiate cartesian canvas(1000x1000) [1]\n");
528  return;
529  }
530 
531  canvas.rectangle(canvas.min_x(), canvas.min_y(), canvas.max_x(), canvas.max_y());
532 
533  canvas.horiztonal_line_segment(canvas.min_x(), canvas.max_x(), -400.0);
534 
535  canvas.line_segment(-500.0, 600.0, 600.0, -500.0);
536 
537  canvas.pen_width(3);
538 
539  for (std::size_t i = 0; i < 160; i++)
540  {
541  std::size_t c_idx = i % (sizeof(palette_colormap) / sizeof(rgb_t));
542 
543  canvas.pen_color(palette_colormap[c_idx].red, palette_colormap[c_idx].green, palette_colormap[c_idx].blue);
544 
545  canvas.circle(0.0, 0.0, 3.0 * i);
546  }
547 
548  canvas.image().save_image("test19_cartesian_canvas01.bmp");
549  }
550 
551  {
552  static const double pi = 3.14159265358979323846264338327950288419716939937510;
553 
554  cartesian_canvas canvas(1000, 1000);
555 
556  if (!canvas)
557  {
558  printf("test19() - Error - Failed to instantiate cartesian canvas(1000x1000) [2]\n");
559  return;
560  }
561 
562  canvas.image().set_all_channels(0xFF);
563 
564  canvas.pen_width(2);
565 
566  unsigned int i = 0;
567 
568  for (double x = -500; x < 500; x += 3, ++i)
569  {
570  std::size_t c_idx = i % (sizeof(palette_colormap) / sizeof(rgb_t));
571 
572  canvas.pen_color(palette_colormap[c_idx].red, palette_colormap[c_idx].green, palette_colormap[c_idx].blue);
573 
574  double radius = std::max(10.0,std::abs(80.0 * std::sin((1.0 / 80.0) * pi * x)));
575 
576  double y = 400.0 * std::sin((1.0 / 200.0) * pi * x);
577 
578  canvas.circle(x, y, radius);
579  }
580 
581  canvas.image().save_image("test19_cartesian_canvas02.bmp");
582  }
583 }
const rgb_t palette_colormap[]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test20()

void test20 ( )

Definition at line 585 of file bitmap_test.cpp.

References rgb_t::blue, bitmap_image::clear(), rgb_t::green, hsv_colormap, jet_colormap, log2, prism_colormap, rgb_t::red, bitmap_image::save_image(), bitmap_image::set_pixel(), and vga_colormap.

Referenced by main().

586 {
587  const rgb_t* colormap[4] = {
588  hsv_colormap,
589  jet_colormap,
592  };
593 
594  const unsigned int fractal_width = 1200;
595  const unsigned int fractal_height = 800;
596 
597  {
598  bitmap_image fractal_hsv (fractal_width,fractal_height);
599  bitmap_image fractal_jet (fractal_width,fractal_height);
600  bitmap_image fractal_prism(fractal_width,fractal_height);
601  bitmap_image fractal_vga (fractal_width,fractal_height);
602 
603  fractal_hsv .clear();
604  fractal_jet .clear();
605  fractal_prism.clear();
606  fractal_vga .clear();
607 
608  double cr, ci;
609  double nextr, nexti;
610  double prevr, previ;
611 
612  const unsigned int max_iterations = 1000;
613 
614  for (unsigned int y = 0; y < fractal_height; ++y)
615  {
616  for (unsigned int x = 0; x < fractal_width; ++x)
617  {
618  cr = 1.5 * (2.0 * x / fractal_width - 1.0) - 0.5;
619  ci = (2.0 * y / fractal_height - 1.0);
620 
621  nextr = nexti = 0;
622  prevr = previ = 0;
623 
624  for (unsigned int i = 0; i < max_iterations; i++)
625  {
626  prevr = nextr;
627  previ = nexti;
628 
629  nextr = prevr * prevr - previ * previ + cr;
630  nexti = 2 * prevr * previ + ci;
631 
632  if (((nextr * nextr) + (nexti * nexti)) > 4)
633  {
634  if (max_iterations != i)
635  {
636  double z = sqrt(nextr * nextr + nexti * nexti);
637 
638  #define log2(x) (std::log(1.0 * x) / std::log(2.0))
639 
640  unsigned int index = static_cast<unsigned int>
641  (1000.0 * log2(1.75 + i - log2(log2(z))) / log2(max_iterations));
642  #undef log2
643 
644  rgb_t c0 = colormap[0][index];
645  rgb_t c1 = colormap[1][index];
646  rgb_t c2 = colormap[2][index];
647  rgb_t c3 = colormap[3][index];
648 
649  fractal_hsv .set_pixel(x, y, c0.red, c0.green, c0.blue);
650  fractal_jet .set_pixel(x, y, c1.red, c1.green, c1.blue);
651  fractal_prism.set_pixel(x, y, c2.red, c2.green, c2.blue);
652  fractal_vga .set_pixel(x, y, c3.red, c3.green, c3.blue);
653  }
654 
655  break;
656  }
657  }
658  }
659  }
660 
661  fractal_hsv .save_image("test20_mandelbrot_set_hsv.bmp" );
662  fractal_jet .save_image("test20_mandelbrot_set_jet.bmp" );
663  fractal_prism.save_image("test20_mandelbrot_set_prism.bmp");
664  fractal_vga .save_image("test20_mandelbrot_set_vga.bmp" );
665  }
666 
667  {
668  bitmap_image fractal_hsv (fractal_width,fractal_height);
669  bitmap_image fractal_jet (fractal_width,fractal_height);
670  bitmap_image fractal_prism(fractal_width,fractal_height);
671  bitmap_image fractal_vga (fractal_width,fractal_height);
672 
673  fractal_hsv .clear();
674  fractal_jet .clear();
675  fractal_prism.clear();
676  fractal_vga .clear();
677 
678  const unsigned int max_iterations = 300;
679 
680  const double cr = -0.70000;
681  const double ci = 0.27015;
682 
683  double prevr, previ;
684 
685  for (unsigned int y = 0; y < fractal_height; ++y)
686  {
687  for (unsigned int x = 0; x < fractal_width; ++x)
688  {
689  double nextr = 1.5 * (2.0 * x / fractal_width - 1.0);
690  double nexti = (2.0 * y / fractal_height - 1.0);
691 
692  for (unsigned int i = 0; i < max_iterations; i++)
693  {
694  prevr = nextr;
695  previ = nexti;
696 
697  nextr = prevr * prevr - previ * previ + cr;
698  nexti = 2 * prevr * previ + ci;
699 
700  if (((nextr * nextr) + (nexti * nexti)) > 4)
701  {
702  if (max_iterations != i)
703  {
704  unsigned int index = static_cast<int>((1000.0 * i) / max_iterations);
705 
706  rgb_t c0 = colormap[0][index];
707  rgb_t c1 = colormap[1][index];
708  rgb_t c2 = colormap[2][index];
709  rgb_t c3 = colormap[3][index];
710 
711  fractal_hsv .set_pixel(x, y, c0.red, c0.green, c0.blue);
712  fractal_jet .set_pixel(x, y, c1.red, c1.green, c1.blue);
713  fractal_prism.set_pixel(x, y, c2.red, c2.green, c2.blue);
714  fractal_vga .set_pixel(x, y, c3.red, c3.green, c3.blue);
715  }
716 
717  break;
718  }
719  }
720  }
721  }
722 
723  fractal_hsv .save_image("test20_julia_set_hsv.bmp" );
724  fractal_jet .save_image("test20_julia_set_jet.bmp" );
725  fractal_prism.save_image("test20_julia_set_prism.bmp");
726  fractal_vga .save_image("test20_julia_set_vga.bmp" );
727  }
728 }
unsigned char red
unsigned char green
const rgb_t jet_colormap[1000]
const rgb_t vga_colormap[1000]
unsigned char blue
#define log2(x)
const rgb_t prism_colormap[1000]
const rgb_t hsv_colormap[1000]
Here is the call graph for this function:
Here is the caller graph for this function: