QuestionDialog::QuestionDialog(int width, int height, QuestionDialog::IconType type) : Dialog(width, height), yes_button_listener_(NULL, NULL, response_none), no_button_listener_(NULL, NULL, response_none) { if (!icon_question_) { icon_question_ = newimage(); getimage_mem(icon_question_, binary_dialog_icon_question_png, sizeof(binary_dialog_icon_question_png)); } if (!icon_warning_) { icon_warning_ = newimage(); getimage_mem(icon_warning_, binary_dialog_icon_warning_png, sizeof(binary_dialog_icon_warning_png)); } switch (type) { case QuestionDialog::icon_question: dialog_icon_ = icon_question_; break; case QuestionDialog::icon_warning: dialog_icon_ = icon_warning_; break; } if (!yes_button_) { yes_button_ = new Button(button_width_, button_height_); yes_button_->set_text("确定"); static PIMAGE icon_ok = newimage(); getimage_mem(icon_ok, binary_dialog_button_ok_png, sizeof(binary_dialog_button_ok_png)); yes_button_->set_icon(icon_ok); } if (!no_button_) { no_button_ = new Button(button_width_, button_height_); no_button_->set_text("取消"); static PIMAGE icon_cancel = newimage(); getimage_mem(icon_cancel, binary_dialog_button_cancel_png, sizeof(binary_dialog_button_cancel_png)); no_button_->set_icon(icon_cancel); } no_button_->set_position(width_ - button_margin_ - button_width_, height_ - button_margin_ - button_height_); yes_button_->set_position(width_ - button_margin_ * 2 - button_width_ * 2, height_ - button_margin_ - button_height_); text_rect_.left = icon_margin_ + getwidth(dialog_icon_) + text_margin_; text_rect_.top = text_margin_; text_rect_.right = width - text_margin_; text_rect_.bottom = height_ - button_area_height_ - text_margin_; text_ = "A question message."; }
LameImage ImageConverter::resultImage() { LameImage resized = _result.scaleByFactor(_scale); _newframewidth = ceilingMultiple(resized.frameWidth(), 8); _newframeheight = resized.frameHeight(); newwidth = ceilingMultiple(resized.width() * _newframewidth / resized.frameWidth(),8); newheight = ceilingMultiple(resized.height() * _newframeheight / resized.frameHeight(), _newframeheight); LameImage newimage(newwidth, newheight, LameImage::Format_RGB32); newimage.setFrameSize(_newframewidth, _newframeheight); newimage.fill(_transparent); QPainter paint(&newimage); for (int fy = 0; fy < resized.frameCountY(); fy++) { for (int fx = 0; fx < resized.frameCountX(); fx++) { paint.drawImage( fx*_newframewidth, fy*_newframeheight, resized, fx*resized.frameWidth(), fy*resized.frameHeight(), resized.frameWidth(), resized.frameHeight() ); } } paint.end(); newimage = applyColorFilter(newimage); return newimage; }
int main() { PIMAGE img; initgraph(640, 480); //先随便画一些东西 setcolor(EGERGB(0xFF, 0xFF, 0x0)); setfillcolor(EGERGB(0xFF, 0x0, 0x80)); fillellipse(50, 50, 50, 50); img = newimage(); getimage(img, 0, 0, 160, 120); //先画一个非黑色背景,以便于比较 setbkcolor(EGERGB(0x80, 0x80, 0x80)); cleardevice(); //四种贴图比较 putimage(0, 0, img); putimage_alphablend(NULL, img, 160, 0, 0x80); //半透明度为0x80 putimage_transparent(NULL, img, 0, 80, BLACK); //透明贴图,关键色为BLACK,源图为这个颜色的地方会被忽略 putimage_alphatransparent(NULL, img, 160, 80, BLACK, 0xA0); //同时使用透明和半透明 getch(); delimage(img); closegraph(); return 0; }
LameImage ImageConverter::applyColorFilter(LameImage image) { LameImage newimage(image.size(), LameImage::Format_Indexed8); newimage.setFrameSize(image.frameWidth(), image.frameHeight()); newimage.setColorTable(_colors[_colorkey]); for (int y = 0; y < image.height(); y++) { for (int x = 0; x < image.width(); x++) { QColor color = image.pixel(x, y); int lightness = color.lightness(); if (color == _transparent) { newimage.setPixel(x, y, 2); } else { if (lightness >= highbreak) newimage.setPixel(x, y, 1); else if (lightness <= lowbreak) newimage.setPixel(x, y, 0); else newimage.setPixel(x, y, 3); } } } return newimage; }
IMAGE Dilate (IMAGE im, IMAGE p) { IMAGE tmp=0; int i=0,j=0; /* Source image empty? */ if (im==0) max_abort (0, "NULL Image in Dilate."); /* Create a result image */ tmp = newimage (im->info->nr, im->info->nc); if (tmp == 0) max_abort (0, "Out of memory in Dilate."); for (i=0; i<tmp->info->nr; i++) for (j=0; j<tmp->info->nc; j++) tmp->data[i][j] = 0; /* Apply the SE to each black pixel of the input */ for (i=0; i<im->info->nr; i++) for (j=0; j<im->info->nc; j++) if (im->data[i][j] == WHITE) dil_apply (im, p, i, j, tmp); /* Free the result image - it was a temp */ return tmp; }
void lastview( /* return to a previous view */ char *s ) { char buf[128]; char *fname; int success; VIEW nv; /* get parameters from a file */ if (nextword(buf, sizeof(buf), s) != NULL) { nv = stdview; if ((fname = getpath(buf, "", R_OK)) == NULL || (success = viewfile(fname, &nv, NULL)) == -1) { sprintf(errmsg, "cannot open \"%s\"", buf); error(COMMAND, errmsg); return; } if (!success) error(COMMAND, "wrong file format"); else newview(&nv); return; } if (oldview.type == 0) { /* no old view! */ error(COMMAND, "no previous view"); return; } nv = ourview; ourview = oldview; oldview = nv; newimage(NULL); }
int info_scene() { cleardevice(); setcolor(0xFFFFFF); Mira mira(640, 300); auto p_imagetext(newimage(440, 130)); char infostr[] = "欢迎使用Easy Graphics Enginge (EGE) V0.3.8 ,本库是一个面向新手,或者面向快速图形程序开发的图形库,使用方便快捷,容易上手,特别适合于新手学习图形程序设计。本程序为安装程序,如果你要继续安装,请按'y'键继续"; setcolor(0xFFFF, p_imagetext); setfont(18, 0, "宋体", p_imagetext); setbkmode(TRANSPARENT, p_imagetext); for(int i = 0; i < 8; ++i) { outtextrect(5, 5, 440, 280, infostr, p_imagetext); imagefilter_blurring(p_imagetext, 0xF0, 0x100); } setcolor(0xFF, p_imagetext); outtextrect(5, 5, 440, 280, infostr, p_imagetext); for(; kbhit() == 0; delay_fps(60)) { mira.update(); mira.render(0, 480 - 300); putimage(100, 50, p_imagetext); } delimage(p_imagetext); return getch(); }
IMAGE Difference (IMAGE a, IMAGE b) { IMAGE t=0; int i=0, j=0, rmax=0, rmin=0, cmax=0, cmin=0; MinMax (a, b, &rmax, &cmax, &rmin, &cmin); t = newimage (rmax-rmin+1, cmax-cmin+1); t->info->oi = -rmin; t->info->oj = -cmin; if (t == 0) { printf ("Out of storage in Difference!\n"); exit (1); } for (i=rmin; i<rmax; i++) { for (j=cmin; j< cmax; j++) { if (pget(a,i,j)==1 && pget(b,i,j)!=1) pset (t, i, j, 1); else pset (t, i, j, 0); } } return t; }
Mira(int w, int h) { m_a = 0.1 + random(10000) / 10000.0 * 1.6 - 0.8, m_b = 0.99; m_da = 0.0002 * ((int)random(2) * 2 - 1), m_db = 0.0000061 * (int(random(2)) * 2 - 1); m_cr = 0.0; m_tt = random(10000) / 10000.0 * 16.0 + 4; m_zoom = 0.7 / m_tt; pmira = newimage(w, h); m_w = w; m_h = h; }
void NetPlayerInfoView::show() { if (buffer_img_.img) { putimage(buffer_img_.x, buffer_img_.y, buffer_img_.img); delimage(buffer_img_.img); buffer_img_.img = NULL; } calc_view_width_height(); buffer_img_.x = pos_x_; buffer_img_.y = pos_y_; int temp_viewport_left, temp_viewport_right, temp_viewport_top, temp_viewport_bottom; getviewport(&temp_viewport_left, &temp_viewport_top, &temp_viewport_right, &temp_viewport_bottom); setviewport(pos_x_, pos_y_, pos_x_ + view_width_, pos_y_ + view_height_); buffer_img_.img = newimage(view_width_, view_height_); putimage(buffer_img_.img, 0, 0, NULL); setviewport(temp_viewport_left, temp_viewport_top, temp_viewport_right, temp_viewport_bottom); int target_top = pos_y_; if (player_pic_) { player_pic_->show_image_with_alpha(pos_x_ + view_width_ / 2 - player_pic_->get_width() / 2, target_top, 1.0); target_top += player_pic_->get_width() + margin_; } setcolor(WHITE); if (player_name_.length() > 0) { Gobang::set_font(Gobang::font_default, name_font_size_, true); xyprintf(pos_x_ + view_width_ / 2 - textwidth(player_name_.c_str()) / 2, target_top, player_name_.c_str()); target_top += textheight(player_name_.c_str()) + margin_; } if (is_ready_) { Gobang::set_font(Gobang::font_default, ready_font_size_); xyprintf(pos_x_ + view_width_ / 2 - textwidth("Ready!") / 2, target_top, "Ready!"); target_top += textheight("Ready!") + margin_; if (is_playing_) { playing_indicator_->show_image_with_alpha(pos_x_ + view_width_ / 2 - playing_indicator_->get_width() / 2, target_top, 1.0); target_top += playing_indicator_->get_height() + margin_; } } else if (!is_opposite_) { button_ready_->set_position(pos_x_ + view_width_ / 2 - button_ready_->get_width() / 2, target_top); button_ready_->show(); target_top += button_ready_->get_height() + margin_; } }
IMAGE Intersection (IMAGE a, IMAGE b) { IMAGE t=0; int i=0, j=0, rmin=0, rmax=0, cmin=0, cmax=0; MinMax (a, b, &rmax, &cmax, &rmin, &cmin); t = newimage (rmax-rmin, cmax-cmin); t->info->oi = -rmin; t->info->oj = -cmin; for (i=rmin; i<rmax; i++) for (j=cmin; j< cmax; j++) if (pget(a,i,j)==1 && pget(b,i,j)==1) pset(t, i,j,1); else pset (t, i, j, 0); return t; }
MessageDialog::MessageDialog(int width, int height, MessageDialog::IconType type) : Dialog(width, height), ok_listener_(NULL) { if (!icon_infomation_) { icon_infomation_ = newimage(); getimage_mem(icon_infomation_, binary_dialog_icon_information_png, sizeof(binary_dialog_icon_information_png)); } if (!icon_error_) { icon_error_ = newimage(); getimage_mem(icon_error_, binary_dialog_icon_error_png, sizeof(binary_dialog_icon_error_png)); } if (!ok_button_) { ok_button_ = new Button(button_width_, button_height_); ok_button_->set_text("确定"); static PIMAGE icon_ok = newimage(); getimage_mem(icon_ok, binary_dialog_button_ok_png, sizeof(binary_dialog_button_ok_png)); ok_button_->set_icon(icon_ok); } switch (type) { case icon_infomation: dialog_icon_ = icon_infomation_; set_title("提示"); break; case icon_error: dialog_icon_ = icon_error_; set_title("错误"); break; } ok_button_->set_position(width_ - button_margin_ - button_width_, height_ - button_margin_ - button_height_); text_ = "A message."; }
IMAGE NewImage (IMAGE x) { IMAGE t=0; int i=0, j=0; if (x == 0) max_abort (0, "IMAGE is 0 in NewImage."); t = newimage (x->info->nr, x->info->nc); if (t == 0) max_abort (0, "Out of storage."); t->info->oi = x->info->oi; t->info->oj = x->info->oj; for (i=0; i<x->info->nr; i++) for (j=0; j<x->info->nc; j++) t->data[i][j] = 0; return t; }
void newview( /* change viewing parameters */ VIEW *vp ) { char *err; if ((err = setview(vp)) != NULL) { sprintf(errmsg, "view not set - %s", err); error(COMMAND, errmsg); } else if (memcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) { oldview = ourview; ourview = *vp; newimage(NULL); } }
void mainloop() { // x,y记录当前位置,dx,dy记录速度的方向,r记录圆半径 int x = 0, y = 0, dx = 1, dy = 1, r = 100; // alpha记录当前alpha值,da为alpha变化增量 int alpha = 0, da = 1; // 需要借助img实现透明半透明 PIMAGE img; // img 创建为 w=r*2, h=r*2大小 img = newimage(r * 2, r * 2); setcolor(0x00FF00, img); setfillcolor(0xFF0000, img); // 画在img上 fillellipse(r, r, r, r, img); setbkcolor(DARKGRAY); for ( ; is_run(); delay_fps(60) ) { // todo: 逻辑更新 // 当前位置 + 速度 x += dx; y += dy; if (x < 0) dx = 1; //碰左 if (y < 0) dy = 1; //碰上 if (x >= ege::getwidth() - r * 2) dx = -1; //碰右 if (y >= ege::getheight() - r * 2) dy = -1; //碰下 // 改变alpha值,参数范围为 0 ~ 0xFF(255) alpha += da; if (alpha <= 0) da = 1; if (alpha >= 0xFF) da = -1; // todo: 图形更新 cleardevice(); putimage_alphatransparent(NULL, img, x, y, BLACK, (unsigned char)alpha); } // 释放img delimage(img); }
int main() { initgraph( 640, 480 ); setrendermode(RENDER_MANUAL); PIMAGE img = newimage(); getimage(img, "F://Pictures//12264878375.jpg"); double r = 0; fps f; for ( ; is_run(); delay_fps(6000) ) { r += 0.02; if (r > PI * 2) r -= PI * 2; cleardevice(); putimage_rotatezoom(NULL, img, 320, 240, 0.5f, 0.5f, r, 0.5f, 0, -1, 1); } return 0; }
//初始化,设置坐标,速度方向,透明度,创建IMAGE等 void initobj(AniObj* obj) { // random(n) 返回一个 0 到 n 之间的随机整数(unsigned) obj->x = (int)random(getwidth()); obj->y = (int)random(getheight()); obj->r = random(20) + 20; obj->dx = (int)random(2) * 2 - 1; // 生成-1或1 obj->dy = (int)random(2) * 2 - 1; obj->alpha = random(250) + 2; obj->da = (int)random(2) * 2 - 1; obj->img = newimage(obj->r * 2, obj->r * 2); setcolor(0x00FF00, obj->img); setfillcolor(0xFF0000, obj->img); fillellipse(obj->r, obj->r, obj->r, obj->r, obj->img); }
IMAGE Translate (IMAGE b, PIXEL p) { IMAGE t=0; int i=0, j=0; t = newimage (b->info->nr+p->row+b->info->oi, b->info->nc+p->col+b->info->oj); t->info->oi = 0; t->info->oj = 0; for (i=0; i<t->info->nr; i++) for (j=0; j< t->info->nc; j++) t->data[i][j] = 0; for (i=0; i<b->info->nr; i++) for (j=0; j< b->info->nc; j++) if (b->data[i][j] == 1) if (range(t, i+p->row-b->info->oi, j+p->col-b->info->oj)) t->data[i+p->row-b->info->oi][j+p->col-b->info->oj] = 1; return t; }
void CopyVarImage (IMAGE *a, IMAGE *b) { int i=0, j=0; if (a == b) return; if (*a) freeimage (*a); *a = newimage ((*b)->info->nr, (*b)->info->nc); if (*a == 0) max_abort (0, "No more storage.\n"); for (i=0; i<(*b)->info->nr; i++) for (j=0; j< (*b)->info->nc; j++) (*a)->data[i][j] = (*b)->data[i][j]; (*a)->info->oi = (*b)->info->oi; (*a)->info->oj = (*b)->info->oj; (*a)->info->nr = (*b)->info->nr; (*a)->info->nc = (*b)->info->nc; }
int main() { //声明一个img图片对象 PIMAGE img; initgraph(640, 480); //先随便画一些东西 setcolor(EGERGB(0xFF, 0xFF, 0x0)); setfillcolor(EGERGB(0xFF, 0x0, 0x80)); fillellipse(50, 50, 50, 50); //用newimage在initgraph后创建这个对象。但记得要在不使用的时候delimage img = newimage(); //从屏幕上截取(0, 0) - (80, 60)这部分作为img,这个img大小为80*60 //img的尺寸会重设,大小由第三第四个参数决定 //注意,(0,0)这点会被包含在img里,但(80, 60)不包含 getimage(img, 0, 0, 80, 60); //对img设置填充色为绿色 setfillcolor(EGERGB(0x0, 0x70, 0x0), img); //对img画实心矩形 bar(40, 20, 70, 50, img); int x, y; //把img平铺在屏幕上,使用一个二重循环 for (y = 0; y < 8; ++y) { for (x = 0; x < 8; ++x) { //把img整个,画在指定的坐标上,左上角对齐这个坐标 putimage(x * 80, y * 60, img); } } getch(); delimage(img); closegraph(); return 0; }
IMAGE ImageGen (PIXEL p1, PIXEL p2, char *s) { int i=0, j=0, k=0; IMAGE t=0; t = newimage (p1->row, p1->col); t->info->oi = p2->row; t->info->oj = p2->col; k = 0; for (i=0; i<p1->row; i++) for (j=0; j<p1->col; j++) { if (s[k] == '1') t->data[i][j] = 1; else if (s[k] == '2') t->data[i][j] = 2; else t->data[i][j] = 0; k++; } return t; }
//初始化,设置坐标,速度方向,透明度,创建IMAGE等 void initobj(AniObj* obj) { obj->x = myrand((float)getwidth()); obj->y = myrand((float)getheight()); obj->r = random(20) + 20; // 随机速度 obj->dx = myrand(randspeed) + base_speed; obj->dy = myrand(randspeed) + base_speed; // 随机方向 obj->dx = obj->dx * float(random(2) * 2.0 - 1); obj->dy = obj->dy * float(random(2) * 2.0 - 1); // 以上的处理方式用来保证速度不过慢 obj->alpha = random(250) + 2; obj->da = (int)random(2) * 2 - 1; obj->img = newimage(obj->r * 2, obj->r * 2); color_t col = hsv2rgb(myrand(360.0f), 1.0f, 1.0f); setcolor(col, obj->img); setfillcolor(col, obj->img); fillellipse(obj->r, obj->r, obj->r, obj->r, obj->img); }
IMAGE Erode (IMAGE im, IMAGE p) { IMAGE tmp=0; int i=0, j=0; /* Source image empty? */ if (im==0) max_abort (0, "NULL image in ERODE."); /* Create a result image */ tmp = newimage (im->info->nr, im->info->nc); if (tmp == 0) max_abort (0, "Out of memory in Erode."); for (i=0; i<tmp->info->nr; i++) for (j=0; j<tmp->info->nc; j++) tmp->data[i][j] = 0; /* Apply the SE to each black pixel of the input */ for (i=0; i<im->info->nr; i++) for (j=0; j<im->info->nc; j++) erode_apply (im, p, i, j, tmp); return tmp; }
IMAGE SetAPixel (IMAGE a, PIXEL p) { int i=0, j=0, row=0, col=0; int rmin=0, rmax=0, cmin=0, cmax=0; IMAGE t=0; row = ptoi(a, p->row); col = ptoj(a, p->col); if (row > a->info->nr) rmax = row; else rmax = a->info->nr; if (col > a->info->nc) cmax = col; else cmax = a->info->nc; if (row < 0) rmin = row; else rmin = 0; if (col < 0) cmin = col; else cmin = 0; if (range(a, row, col)==0) { t = newimage (rmax-rmin, cmax-cmin); t->info->oi = -rmin; t->info->oj = -cmin; for (i=rmin; i<rmax; i++) for (j=cmin; j<cmax; j++) pset(t, i, j, pget(a, i, j)); pset (t, p->row, p->col, 1); return t; } a->data[row][col] = 1; return a; }
Image::Image(const char* file_path) { image_ = newimage(); getimage(image_, file_path); }
Image::Image() { image_ = newimage(Gobang::WINDOW_WIDTH, Gobang::WINDOW_HEIGHT); putimage(image_, 0, 0, NULL); }
Image::Image(const void* mem_data, long data_size) { image_ = newimage(); //本函数为修改EGE库后新增的函数 getimage_mem(image_, mem_data, data_size); }
IMAGE Input_PBM (char *fn) { int i=0,j=0,k=0,n=0,m=0,bi=0, b=0; unsigned char ucval='\0'; int val=0; char buf1[256]; FILE *f=NULL; IMAGE im=0; strcpy (buf1, fn); if (fn[0] == '$') SubsCmdLine(buf1); f = fopen (buf1, "r"); if (f==NULL) { printf ("Can't open the PBM file named '%s'\n", buf1); return 0; } pbm_getln (f, buf1); if (buf1[0] == 'P') { switch (buf1[1]) { case '1': k=1; break; case '2': k=2; break; case '3': k=3; break; case '4': k=4; break; case '5': k=5; break; case '6': k=6; break; default: printf ("Not a PBM/PGM/PPM file.\n"); return 0; } } bi = 2; get_num_pbm (f, buf1, &bi, &m); /* Number of columns */ get_num_pbm (f, buf1, &bi, &n); /* Number of rows */ if (k!=1 && k!=4) get_num_pbm (f, buf1, &bi, &b); /* Max value */ else b = 1; printf ("\nPBM file class %d size %d columns X %d rows Max=%d\n", k, m, n, b); /* Allocate the image */ if (k==3 || k==6) /* Colour */ max_abort (0, "Colour image."); else { im = (IMAGE) newimage (n, m); im->info->oi = PBM_SE_ORIGIN_ROW; im->info->oj = PBM_SE_ORIGIN_COL; PBM_SE_ORIGIN_ROW = 0; PBM_SE_ORIGIN_COL = 0; for (i=0; i<n; i++) for (j=0; j<m; j++) if (k<3) { fscanf (f, "%d", &val); im->data[i][j] = (unsigned char)val; } else { fscanf (f, "%c", &ucval); im->data[i][j] = ucval; } } fclose (f); return im; }
int main(int argc, char** argv) { if (argc < 2) { std::cout << "Not enough arguments, Usage: ./seamcarver <path_to_image> <number_of_seams_to_carve>" << "\n"; std::cout << "If number of seams to carve is left out, the necessary size for object removal will be used instead" << "\n"; return 1; } std::cout << "Loading image" << "\n"; std::string fname = argv[1]; cimg_library::CImg<unsigned char> image(fname.c_str()); cimg_library::CImg<unsigned char> draw_image(fname.c_str()); //TODO figure out if i can undo the draw without having second copy std::cout << "Calculating luminosity" << "\n"; std::vector<std::vector<double> > luminosity_map = calculate_luminosity(image); std::cout << "Setting energy of image" << "\n"; std::vector<std::vector<int> > energy_map(luminosity_map.size(), std::vector<int>(luminosity_map[0].size(), 0)); cimg_library::CImgDisplay energy(draw_image, "Manually set special energy"); char red[3] = { 255, 0, 0 }; char green[3] = { 0, 255, 0 }; int cursor_size = 1; while (!energy.is_closed()) { energy.wait(); if (energy.button()) { std::vector<char> current_color; int energy_val = 0; if (energy.button() & 1) { // left click if (energy.is_keySPACE()) { flood(draw_image, energy_map, red, -1, energy.mouse_y(), energy.mouse_x()); energy_val = -2; } else { current_color = std::vector<char>(red, red + 3); energy_val = -1; } } else if (energy.button() & 2) { // right click if (energy.is_keySPACE()) { flood(draw_image, energy_map, green, 1, energy.mouse_y(), energy.mouse_x()); energy_val = -2; } else { current_color = std::vector<char>(green, green + 3); energy_val = 1; } } if (energy_val != -2) { for (int i = -cursor_size; i <= cursor_size; i++) { for (int j = -cursor_size; j <= cursor_size; j++) { if (valid_coord(std::pair<int, int>(energy.mouse_y() + i, energy.mouse_x() + j), energy_map[0].size(), energy_map.size())) { energy_map[energy.mouse_y() + i][energy.mouse_x() + j] = energy_val; draw_image.draw_point(energy.mouse_x() + j, energy.mouse_y() + i, ¤t_color[0]); } } } } } draw_image.display(energy); } //TODO //change so im_vec stores only pairs of coords, then we copy directly from image to new image? std::vector<std::vector<std::vector<char> > > im_vec; for (int i = 0; i < image.height(); i++) { std::vector<std::vector<char> > row; for (int j = 0; j < image.width(); j++) { std::vector<char> color; color.push_back(image.atXY(j, i, 0, 0)); color.push_back(image.atXY(j, i, 0, 1)); color.push_back(image.atXY(j, i, 0, 2)); row.push_back(color); } im_vec.push_back(row); } int numseam = 0; if (argc < 3) { // calculate max of max range of x on all y coordinates int maxseam = -1; for (int i = 0; i < energy_map.size(); i++) { int left = 0; int right = energy_map[i].size() - 1; while (right > 0 && left < energy_map[i].size() && (energy_map[i][left] != -1 || energy_map[i][right] != -1)) { if (energy_map[i][left] != -1) left++; if (energy_map[i][right] != -1) right--; } int diff = right - left + 1; if (maxseam < diff) { maxseam = diff; } } numseam = maxseam; } else { numseam = atoi(argv[2]); } for (int master = 0; master < numseam; master++) { std::cout << "Computing and removing seam #" << master + 1 << "\r" << std::flush; std::vector<std::vector<std::pair<double, double> > > gradient_map = calculate_gradient(luminosity_map); //set all energies specified in energy_map to negative/positive on the gradient map for (int i = 0; i < energy_map.size(); i++) { for (int j = 0; j < energy_map[0].size(); j++) { if (energy_map[i][j] != 0) { gradient_map[i][j].second = energy_map[i][j] * 1000; } } } double min_seam = DBL_MAX; int loc = -1; for (int i = 0; i < gradient_map.back().size(); i++) { calculate_seam(gradient_map, gradient_map.size() - 1, i); if (gradient_map.back()[i].first < min_seam) { min_seam = gradient_map.back()[i].first; loc = i; } } //remove seams and the object manipulation map coordinates std::vector<std::pair<int, int> > toremove = trace_seam(gradient_map, loc); for (int i = 0; i < toremove.size(); i++) { int row = toremove[i].first; int col = toremove[i].second; im_vec[row].erase(im_vec[row].begin() + col); luminosity_map[row].erase(luminosity_map[row].begin() + col); energy_map[row].erase(energy_map[row].begin() + col); } } cimg_library::CImg<unsigned char> newimage(im_vec[0].size(), im_vec.size(), 1, 3); for (int i = 0; i < im_vec.size(); i++) { for (int j = 0; j < im_vec[i].size(); j++) { char color[3] = { im_vec[i][j][0], im_vec[i][j][1], im_vec[i][j][2] }; newimage.draw_point(j, i, color); } } std::cout << "\n" << "Computation finished, displaying image" << "\n"; cimg_library::CImgDisplay display(newimage, "Seam Carved Image"); while (!display.is_closed()) { display.wait(); newimage.display(display); } }