09源代码.docx

上传人:b****9 文档编号:26131274 上传时间:2023-06-17 格式:DOCX 页数:16 大小:16.38KB
下载 相关 举报
09源代码.docx_第1页
第1页 / 共16页
09源代码.docx_第2页
第2页 / 共16页
09源代码.docx_第3页
第3页 / 共16页
09源代码.docx_第4页
第4页 / 共16页
09源代码.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

09源代码.docx

《09源代码.docx》由会员分享,可在线阅读,更多相关《09源代码.docx(16页珍藏版)》请在冰豆网上搜索。

09源代码.docx

09源代码

#include"config.h"

#include"window1.h"

voidsnippet_normalize(cairo_t*cr,doublewidth,doubleheight)

{

cairo_scale(cr,width,height);

cairo_set_line_width(cr,0.04);

}

voidWindow1:

:

setup()

{

p_img_show_data=newpixel[640*640];

p_img_buf_data=newpixel[640*640];

p_img_buf=newpixel[640*640];

p_buf_cairo=newguint8[STRIDE*HEIGHT];

m_refGlade=Gnome:

:

Glade:

:

Xml:

:

create("../gmcsvl02.glade");

m_refGlade->reparent_widget("vbox1",*this);

m_refGlade->get_widget("toolbutton1",p_button_home);

if(p_button_home)p_button_home->signal_clicked().connect(sigc:

:

mem_fun(*this,&Window1:

:

on_button_home));

m_refGlade->get_widget("toolbutton2",p_button_new);

if(p_button_new)p_button_new->signal_clicked().connect(sigc:

:

mem_fun(*this,&Window1:

:

on_button_new));

m_refGlade->get_widget("toolbutton3",p_button_refresh);

if(p_button_refresh)p_button_refresh->signal_clicked().connect(sigc:

:

mem_fun(*this,&Window1:

:

on_button_refresh));

m_refGlade->get_widget("toolbutton4",p_button_save);

if(p_button_save)p_button_save->signal_clicked().connect(sigc:

:

mem_fun(*this,&Window1:

:

on_button_save));

m_refGlade->get_widget("toolbutton8",p_button_exit);

if(p_button_exit)p_button_exit->signal_clicked().connect(sigc:

:

mem_fun(*this,&Window1:

:

on_button_exit));

m_refGlade->get_widget("drawingarea1",p_drawingarea);

if(p_drawingarea)p_drawingarea->signal_expose_event().connect(sigc:

:

mem_fun(*this,&Window1:

:

on_drawingarea_expose));

this->signal_show().connect(sigc:

:

mem_fun(*this,&Window1:

:

on_win_show));

image01=cairo_image_surface_create_from_png("06.png");

//image01=cairo_image_surface_create_from_png("09.png");

image02=cairo_image_surface_create_for_data(p_buf_cairo,CAIRO_FORMAT_ARGB32,WIDTH,HEIGHT,STRIDE);

a=0;

amin=0;

size_rect=0;

size_rect_min=0;

image_long=640;

}

voidWindow1:

:

on_win_show()

{

std:

:

cout<<"onwinshow"<

:

endl;

ref_pixmap_scribble=Gdk:

:

Pixmap:

:

create(p_drawingarea->get_window(),

p_drawingarea->get_allocation().get_width(),

p_drawingarea->get_allocation().get_height(),

-1);

ref_pixmap_scribble->draw_rectangle(p_drawingarea->get_style()->get_white_gc(),

true,

0,0,

p_drawingarea->get_allocation().get_width(),

p_drawingarea->get_allocation().get_height());

translate_img();

draw();

my_slot=sigc:

:

bind(sigc:

:

mem_fun(*this,&Window1:

:

on_timeout),1);

conn=Glib:

:

signal_timeout().connect(my_slot,100*5);

}

boolWindow1:

:

on_drawingarea_expose(GdkEventExpose*event)

{

//std:

:

cout<<"ondrawingareaexpose"<

:

endl;

p_drawingarea->get_window()->draw_drawable(p_drawingarea->get_style()->get_fg_gc(p_drawingarea->get_state()),

ref_pixmap_scribble,

0,

0,

0,

0);

}

boolWindow1:

:

on_timeout(gint32timer_number)

{

//std:

:

cout<<"on_timeout"<

:

endl;

translate_img();

draw();

a++;

std:

:

cout<<"a="<

:

endl;

if(a>360)

{

conn.disconnect();

show_img();

}

}

voidWindow1:

:

on_button_home()

{

}

voidWindow1:

:

on_button_new()

{

std:

:

cout<<"buttonnew"<

:

endl;

}

voidWindow1:

:

show_img()

{

a=amin;

translate_img();

if(xn-x1>yn-y1)

{

amin+=270;

}

a=amin;

translate_img();

ref_pixmap_scribble->draw_rectangle(p_drawingarea->get_style()->get_black_gc(),

true,

0,0,

p_drawingarea->get_allocation().get_width(),

p_drawingarea->get_allocation().get_height());

gint16m,n;

width_img=xn-x1;

height_img=yn-y1;

std:

:

cout<<"width_img="<

:

endl;

std:

:

cout<<"height_img="<

:

endl;

p_tmp_pixel=p_img_buf;

p_show_pixel=p_img_show_data;

for(intix=0;ix

{

for(intiy=0;iy

{

p_tmp_pixel=p_img_buf+iy*width_img+ix;

p_show_pixel=p_img_show_data+(y1+iy+1)*640+(ix+x1+1);

p_tmp_pixel->red=p_show_pixel->red;

p_tmp_pixel->green=p_show_pixel->green;

p_tmp_pixel->blue=p_show_pixel->blue;

}

}

gint32size_x_step=width_img/5;

gint32size_y_step=height_img/5;

p_tmp_pixel=img_small;

p_show_pixel=p_img_buf;

for(intix=0;ix<5;ix++)

{

for(intiy=0;iy<5;iy++)

{

gint32xn,yn;

xn=ix*size_x_step;

yn=iy*size_y_step;

gint32white_pixels=0;

for(intxs=0;xs

{

for(intys=0;ys

{

p_show_pixel=p_img_buf+(yn+ys)*width_img+(xn+xs);

if(p_show_pixel->red>200)white_pixels++;

}

}

p_tmp_pixel=img_small+iy*5+ix;

p_tmp_pixel->red=0;

p_tmp_pixel->green=0;

p_tmp_pixel->blue=0;

if(white_pixels>(size_x_step*size_y_step/2))

{

p_tmp_pixel->red=255;

p_tmp_pixel->green=255;

p_tmp_pixel->blue=255;

}

}

}

p_tmp_pixel=img_small;

for(intix=0;ix<5;ix++)

{

for(intiy=0;iy<5;iy++)

{

gint32xn,yn;

xn=ix*size_x_step+300;

yn=iy*size_y_step+20;

p_tmp_pixel=img_small+iy*5+ix;

if(p_tmp_pixel->red>200)

{

ref_pixmap_scribble->draw_rectangle(p_drawingarea->get_style()->get_white_gc(),

true,

xn,

yn,

size_x_step,

size_y_step);

//std:

:

cout<<"on_button_refresh"<

:

endl;

}

}

}

Glib:

:

RefPtr

:

GC>ref_gc=Gdk:

:

GC:

:

create(p_drawingarea->get_window());

Gdk:

:

Colorcolor;

color.set_red(60000);

color.set_green(0);

color.set_blue(60000);

ref_gc->set_rgb_fg_color(color);

p_tmp_pixel=img_small;

for(intix=0;ix<5;ix++)

{

for(intiy=0;iy<5;iy++)

{

gint32xn,yn;

xn=ix*size_x_step+300;

yn=iy*size_y_step+20;

p_tmp_pixel=img_small+iy*5+ix;

if(p_tmp_pixel->red>200)

{

ref_pixmap_scribble->draw_rectangle(ref_gc,

false/*true*/,

xn,

yn,

size_x_step,

size_y_step);

//std:

:

cout<<"on_button_refresh"<

:

endl;

}

}

}

p_show_pixel=p_img_buf;

for(intiy=0;iy<=height_img;iy+=size_y_step)

{

for(intix=0;ix<=width_img;ix++)

{

p_show_pixel=p_img_buf+iy*width_img+ix;

p_show_pixel->red=255;

p_show_pixel->green=255;

p_show_pixel->blue=0;

}

}

p_show_pixel=p_img_buf;

for(intix=0;ix<=width_img;ix+=size_x_step)

{

for(intiy=0;iy<=height_img;iy++)

{

p_show_pixel=p_img_buf+iy*width_img+ix;

p_show_pixel->red=255;

p_show_pixel->green=255;

p_show_pixel->blue=0;

}

}

my_img_pixbuf=Gdk:

:

Pixbuf:

:

create_from_data((guint8*)p_img_buf,

Gdk:

:

COLORSPACE_RGB,

false,

8,

width_img,

height_img,

width_img*3

);

my_img_pixbuf->render_to_drawable(ref_pixmap_scribble,

p_drawingarea->get_style()->get_fg_gc(p_drawingarea->get_state()),

0,

0,

20,

20,

width_img,

height_img,

Gdk:

:

RGB_DITHER_NONE,

0,

0);

p_drawingarea->queue_draw();

}

voidWindow1:

:

on_button_refresh()

{

}

voidWindow1:

:

on_button_save()

{

}

voidWindow1:

:

on_button_exit()

{

cairo_surface_destroy(image01);

cairo_surface_destroy(image02);

hide();

}

voidWindow1:

:

translate_img()

{

width=WIDTH;

height=HEIGHT;

cr01=cairo_create(image01);

cr02=cairo_create(image02);

doublew01=cairo_image_surface_get_width(image01);

doubleh01=cairo_image_surface_get_height(image01);

snippet_normalize(cr01,w01,h01);

cairo_stroke(cr01);

memset(p_buf_cairo,0,STRIDE*HEIGHT);

doublew02=cairo_image_surface_get_width(image02);

doubleh02=cairo_image_surface_get_height(image02);

snippet_normalize(cr02,w02,h02);

cairo_translate(cr02,0.5,0.5);

cairo_rotate(cr02,a*M_PI/180);

cairo_scale(cr02,1.0/w02,1.0/h02);

cairo_translate(cr02,-0.5*w01,-0.5*h01);

cairo_set_source_surface(cr02,image01,0,0);

cairo_paint(cr02);

cairo_stroke(cr02);

//cairo_surface_write_to_png(image02,"zj02.png");

guint8*p_uch=p_buf_cairo;

p_show_pixel=p_img_show_data;

for(guint32i=0;i

{

p_show_pixel->red=0;

p_show_pixel->green=0;

p_show_pixel->blue=0;

p_show_pixel->red=*(p_uch+2);

p_show_pixel->green=*(p_uch+1);

p_show_pixel->blue=*(p_uch+0);

p_uch+=4;

p_show_pixel++;

}

intx0,y0;

for(guint32i=0;i

{

intx=i%image_long;

inty=(guint16)(i/image_long);

p_tmp_pixel=p_img_show_data+y*image_long+x;

if(p_tmp_pixel->red>200

&&p_tmp_pixel->green>200

&&p_tmp_pixel->blue>200)

{

x0=x;

y0=y;

break;

}

}

x1=x0;

y1=y0;

xn=x0;

yn=y0;

for(guint32i=0;i

{

intx=i%image_long;

inty=(guint16)(i/image_long);

p_tmp_pixel=p_img_show_data+y*image_long+x;

if(p_tmp_pixel->red>200

&&p_tmp_pixel->green>200

&&p_tmp_pixel->blue>200)

{

if(x

if(y

if(x>xn)xn=x;

if(y>yn)yn=y;

}

}

for(guint32i=0;i

{

intx=i%image_long;

inty=(guint16)(i/image_long);

p_tmp_pixel=p_img_show_data+y*image_long+x;

if(x>x1&&y==y1&&x<=xn)

{

p_tmp_pixel->red=255;

p_tmp_pixel->green=255;

p_tmp_pixel->blue=255;

}

if(x>x1&&y==yn&&x<=xn)

{

p_tmp_pixel->red=255;

p_tmp_pixel->green=255;

p_tmp_pixel->blue=255;

}

if(y>y1&&x==x1&&y<=yn)

{

p_tmp_pixel->red=255;

p_tmp_pixel->green=255;

p_tmp_pixel->blue=255;

}

if(y>y1&&x==xn&&y<=yn)

{

p_tmp_pixel->red=255;

p_tmp_pixel->green=255;

p_tmp_pixel->blue=255;

}

}

size_rect=(xn-x1)*(yn-y1);

if(size_rect_min==0)

{

size_rect_min=size_rect;

amin=a;

}

if(size_rect_min>size_rect)

{

size_rect_min=size_rect;

amin=a;

}

cairo_destroy(cr01);

cairo_destroy(cr02);

}

voidWindow1:

:

draw()

{

my_img_pixbuf=Gdk:

:

Pixbuf:

:

create_from_data((guint8*)p_img_show_data,

Gdk:

:

COLORSPACE_RGB,

false,

8,

image_long,

image_long,

image_long*3

);

my_img_pixbuf->render_to_drawable(ref_pixmap_scribble,

p_drawingarea->get_style()->get

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 法学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1