33 std::string file_name(
"image.bmp");
39 printf(
"test01() - Error - Failed to open '%s'\n",file_name.c_str());
48 std::string file_name(
"image.bmp");
54 printf(
"test02() - Error - Failed to open '%s'\n",file_name.c_str());
61 image.
save_image(
"test02_saved_vert_flip.bmp");
65 image.
save_image(
"test02_saved_horiz_flip.bmp");
70 std::string file_name(
"image.bmp");
76 printf(
"test03() - Error - Failed to open '%s'\n",file_name.c_str());
85 subsampled_image1.
save_image(
"test03_1xsubsampled_image.bmp");
87 subsampled_image1.
subsample(subsampled_image2);
88 subsampled_image2.
save_image(
"test03_2xsubsampled_image.bmp");
90 subsampled_image2.
subsample(subsampled_image3);
91 subsampled_image3.
save_image(
"test03_3xsubsampled_image.bmp");
96 std::string file_name(
"image.bmp");
102 printf(
"test04() - Error - Failed to open '%s'\n",file_name.c_str());
111 upsampled_image1.
save_image(
"test04_1xupsampled_image.bmp");
113 upsampled_image1.
upsample(upsampled_image2);
114 upsampled_image2.
save_image(
"test04_2xupsampled_image.bmp");
116 upsampled_image2.
upsample(upsampled_image3);
117 upsampled_image3.
save_image(
"test04_3xupsampled_image.bmp");
122 std::string file_name(
"image.bmp");
128 printf(
"test05() - Error - Failed to open '%s'\n",file_name.c_str());
133 image.
save_image(
"test05_lsb0_removed_saved.bmp");
135 image.
save_image(
"test05_lsb01_removed_saved.bmp");
137 image.
save_image(
"test05_lsb012_removed_saved.bmp");
139 image.
save_image(
"test05_lsb0123_removed_saved.bmp");
141 image.
save_image(
"test05_lsb01234_removed_saved.bmp");
143 image.
save_image(
"test05_lsb012345_removed_saved.bmp");
145 image.
save_image(
"test05_lsb0123456_removed_saved.bmp");
150 std::string file_name(
"image.bmp");
156 printf(
"test06() - Error - Failed to open '%s'\n",file_name.c_str());
162 red_channel_image.
save_image(
"test06_red_channel_image.bmp");
166 green_channel_image.
save_image(
"test06_green_channel_image.bmp");
170 blue_channel_image.
save_image(
"test06_blue_channel_image.bmp");
175 std::string file_name(
"image.bmp");
181 printf(
"test07() - Error - Failed to open '%s'\n",file_name.c_str());
186 image.
save_image(
"test07_grayscale_image.bmp");
191 std::string file_name(
"image.bmp");
197 printf(
"test08() - Error - Failed to open '%s'\n",file_name.c_str());
206 unsigned int w = image.
width();
207 unsigned int h = image.
height();
209 if (!image.
region(0,0, w / 2, h / 2,image1))
211 std::cout <<
"ERROR: upper_left_image" << std::endl;
214 if (!image.
region((w - 1) / 2, 0, w / 2, h / 2,image2))
216 std::cout <<
"ERROR: upper_right_image" << std::endl;
219 if (!image.
region(0,(h - 1) / 2, w / 2, h / 2,image3))
221 std::cout <<
"ERROR: lower_left_image" << std::endl;
224 if (!image.
region((w - 1) / 2, (h - 1) / 2, w / 2, h / 2,image4))
226 std::cout <<
"ERROR: lower_right_image" << std::endl;
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");
237 const unsigned int dim = 1000;
241 for (
unsigned int x = 0; x < dim; ++x)
243 for (
unsigned int y = 0; y < dim; ++y)
250 image.
save_image(
"test09_color_map_image.bmp");
255 std::string file_name(
"image.bmp");
261 printf(
"test10() - Error - Failed to open '%s'\n",file_name.c_str());
266 image.
save_image(
"test10_inverted_color_image.bmp");
271 std::string file_name(
"image.bmp");
277 printf(
"test11() - Error - Failed to open '%s'\n",file_name.c_str());
281 for (
unsigned int i = 0; i < 10; ++i)
284 image.
save_image(std::string(
"test11_") + static_cast<char>(48 + i) + std::string(
"_red_inc_image.bmp"));
290 std::string file_name(
"image.bmp");
296 printf(
"test12() - Error - Failed to open '%s'\n",file_name.c_str());
306 for (
unsigned int i = 0; i < image.
pixel_count(); ++i)
321 std::string file_name(
"image.bmp");
327 printf(
"test13() - Error - Failed to open '%s'\n",file_name.c_str());
337 for (
unsigned int j = 0; j < 10; ++j)
339 for (
unsigned int i = 0; i < image.
pixel_count(); ++i)
345 image.
save_image(std::string(
"test13_") + static_cast<char>(48 + j) + std::string(
"_y_image.bmp"));
378 plasma(image,0,0,image.
width(),image.
height(),c1,c2,c3,c4,3.0,
jet_colormap);
384 std::string file_name(
"image.bmp");
390 printf(
"test16() - Error - Failed to open '%s'\n",file_name.c_str());
400 plasma(plasma_image,0,0,plasma_image.width(),plasma_image.height(),c1,c2,c3,c4,3.0,
jet_colormap);
404 temp_image.alpha_blend(0.1, plasma_image);
405 temp_image.save_image(
"test16_alpha_0.1.bmp");
409 temp_image.save_image(
"test16_alpha_0.2.bmp");
413 temp_image.save_image(
"test16_alpha_0.3.bmp");
417 temp_image.save_image(
"test16_alpha_0.4.bmp");
421 temp_image.save_image(
"test16_alpha_0.5.bmp");
425 temp_image.save_image(
"test16_alpha_0.6.bmp");
429 temp_image.save_image(
"test16_alpha_0.7.bmp");
433 temp_image.save_image(
"test16_alpha_0.8.bmp");
437 temp_image.save_image(
"test16_alpha_0.9.bmp");
449 plasma(image,0,0,image.
width(),image.
height(),c1,c2,c3,c4,3.0,
jet_colormap);
454 draw.pen_color(255,0,0);
455 draw.circle(image.
width() / 2 + 100, image.
height() / 2, 100);
458 draw.pen_color(0,255,255);
459 draw.ellipse(image.
width() / 2, image.
height() / 2, 200,350);
462 draw.pen_color(255,255,0);
463 draw.rectangle(50,50,250,400);
465 draw.pen_color(0,255,0);
466 draw.rectangle(450,250,850,880);
476 const rgb_t* colormap[9] = {
488 for (
unsigned int i = 0; i < image.
width(); ++i)
490 for (
unsigned int j = 0; j < 9; ++j)
492 draw.
pen_color(colormap[j][i].red,colormap[j][i].green,colormap[j][i].blue);
505 std::size_t bar_width = image.
width() / palette_colormap_size;
507 for (std::size_t i = 0; i < palette_colormap_size; ++i)
509 for (std::size_t j = 0; j < bar_width; ++j)
516 image.
save_image(
"test18_palette_colormap.bmp");
527 printf(
"test19() - Error - Failed to instantiate cartesian canvas(1000x1000) [1]\n");
539 for (std::size_t i = 0; i < 160; i++)
545 canvas.
circle(0.0, 0.0, 3.0 * i);
552 static const double pi = 3.14159265358979323846264338327950288419716939937510;
558 printf(
"test19() - Error - Failed to instantiate cartesian canvas(1000x1000) [2]\n");
568 for (
double x = -500; x < 500; x += 3, ++i)
574 double radius = std::max(10.0,std::abs(80.0 * std::sin((1.0 / 80.0) * pi * x)));
576 double y = 400.0 * std::sin((1.0 / 200.0) * pi * x);
578 canvas.
circle(x, y, radius);
587 const rgb_t* colormap[4] = {
594 const unsigned int fractal_width = 1200;
595 const unsigned int fractal_height = 800;
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);
603 fractal_hsv .
clear();
604 fractal_jet .
clear();
605 fractal_prism.
clear();
606 fractal_vga .
clear();
612 const unsigned int max_iterations = 1000;
614 for (
unsigned int y = 0; y < fractal_height; ++y)
616 for (
unsigned int x = 0; x < fractal_width; ++x)
618 cr = 1.5 * (2.0 * x / fractal_width - 1.0) - 0.5;
619 ci = (2.0 * y / fractal_height - 1.0);
624 for (
unsigned int i = 0; i < max_iterations; i++)
629 nextr = prevr * prevr - previ * previ + cr;
630 nexti = 2 * prevr * previ + ci;
632 if (((nextr * nextr) + (nexti * nexti)) > 4)
634 if (max_iterations != i)
636 double z = sqrt(nextr * nextr + nexti * nexti);
638 #define log2(x) (std::log(1.0 * x) / std::log(2.0)) 640 unsigned int index =
static_cast<unsigned int> 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];
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" );
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);
673 fractal_hsv .
clear();
674 fractal_jet .
clear();
675 fractal_prism.
clear();
676 fractal_vga .
clear();
678 const unsigned int max_iterations = 300;
680 const double cr = -0.70000;
681 const double ci = 0.27015;
685 for (
unsigned int y = 0; y < fractal_height; ++y)
687 for (
unsigned int x = 0; x < fractal_width; ++x)
689 double nextr = 1.5 * (2.0 * x / fractal_width - 1.0);
690 double nexti = (2.0 * y / fractal_height - 1.0);
692 for (
unsigned int i = 0; i < max_iterations; i++)
697 nextr = prevr * prevr - previ * previ + cr;
698 nexti = 2 * prevr * previ + ci;
700 if (((nextr * nextr) + (nexti * nexti)) > 4)
702 if (max_iterations != i)
704 unsigned int index =
static_cast<int>((1000.0 * i) / max_iterations);
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];
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" );
void export_color_plane(const color_plane color, unsigned char *image)
const rgb_t hot_colormap[1000]
void pen_color(const unsigned char &red, const unsigned char &green, const unsigned char &blue)
bool region(const unsigned int &x, const unsigned int &y, const unsigned int &width, const unsigned int &height, bitmap_image &dest_image)
const rgb_t gray_colormap[1000]
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
void alpha_blend(const double &alpha, const bitmap_image &image)
void import_ycbcr(double *y, double *cb, double *cr)
unsigned int width() const
void set_all_ith_bits_low(const unsigned int bitr_index)
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]
const rgb_t vga_colormap[1000]
const rgb_t palette_colormap[]
void pen_width(const unsigned int &width)
void invert_color_planes()
const rgb_t autumn_colormap[1000]
void subsample(bitmap_image &dest)
const rgb_t prism_colormap[1000]
void vertical_line_segment(int y1, int y2, int x)
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)
void save_image(const std::string &file_name) const
void rectangle(double x1, double y1, double x2, double y2)
const rgb_t copper_colormap[1000]
void line_segment(double x1, double y1, double x2, double y2)
void export_ycbcr(double *y, double *cb, double *cr)
const rgb_t yarg_colormap[1000]
unsigned int pixel_count() const
void add_to_color_plane(const color_plane color, const unsigned char &value)
void horiztonal_line_segment(double x1, double x2, double y)
const bitmap_image & image() const
void convert_to_grayscale()
void upsample(bitmap_image &dest)
const rgb_t hsv_colormap[1000]
void circle(double centerx, double centery, double radius)
void pen_color(const unsigned char &red, const unsigned char &green, const unsigned char &blue)
void clear(const unsigned char v=0x00)
void set_all_channels(const unsigned char &value)