int main(int argc, char**argv) { if (argc != 2) { fprintf(stderr, "usage: qxembedtest [qtoptions] windowid\n" " qxembedtest [qtoptions] windowTitle\n"); exit(10); } TQApplication a(argc,argv); TQWidget *main = new TQVBox(NULL,"main",Qt::WDestructiveClose); TQWidget *top = new TQHBox(main); TQPushButton *quit = new TQPushButton("Quit", top); TQObject::connect( quit, TQT_SIGNAL(clicked()), main, TQT_SLOT(close()) ); TQLineEdit *edit = new TQLineEdit(top); edit->setText( "Just to see focus changes"); QXEmbed *embed = new QXEmbed(main); embed->setProtocol(QXEmbed::XPLAIN); a.setMainWidget(main); main->show(); WId wid = strtol(argv[1], NULL, 0); if (! wid) wid = windowWithName(argv[1]); if (! wid) { fprintf(stderr,"qxembedtest: window not found\n"); exit(10); } fprintf(stderr,"qxembedtest: embedding wid=0x%08x\n", (unsigned int)wid); embed->embed(wid); return a.exec(); }
///Получение объекта окна по его названию в титле Window windowWithName(Display *dpy, Window top, char *name) { Window *children, dummy; unsigned int nchildren; unsigned int i; Window w = 0; char *window_name; if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name)) return (top); if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren)) return (0); for (i = 0; i < nchildren; i++) { w = windowWithName(dpy, children[i], name); if (w) break; } if (children) XFree((char *) children); return (w); }
///Сохранение и уменьшение скринота в массив - сохранение изображения //1)Снятие скриншота с сохранением указателя //2)Уменьшение изображения по указателю //3)Сохранение изображение void get_screen (string filenom) { Display *disp; Window root; XWindowAttributes watts; XImage *image; cairo_surface_t *surface; unsigned int width; unsigned int height; int stride; /*Глобальная перменная - замер времени выполнения участков кода*/ disp = XOpenDisplay(NULL); root = DefaultRootWindow(disp); //Взять скрин с окна с именем в заголовке "FCEUX 2.2.1" root = windowWithName(disp, root,"FCEUX 2.2.1"); XGetWindowAttributes(disp, root, &watts); width = watts.width; height = watts.height; image = XGetImage(disp, root, watts.x, watts.y, width, height, AllPlanes,ZPixmap); stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, width); unsigned char *datapng = (unsigned char *) malloc (stride * height); int red_shift= get_shift(image->red_mask); int green_shift= get_shift(image->green_mask); int blue_shift= get_shift(image->blue_mask); //Массив с пикселями изображения //map< int ,map <int , map < int, unsigned char > > > in; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { unsigned long pixel = XGetPixel(image, x, y); unsigned char red = (image->red_mask & pixel) >> red_shift; unsigned char green = (image->green_mask & pixel) >> green_shift; unsigned char blue = (image->blue_mask & pixel) >> blue_shift; /* in[y][x][0]=blue; in[y][x][1]=green; in[y][x][2]=red; */ //Буффер записи в файл datapng[y * stride + x * 4 + 0]=blue; datapng[y * stride + x * 4 + 1]=green; datapng[y * stride + x * 4 + 2]=red; in[y][x][0]=red; in[y][x][1]=green; in[y][x][2]=blue; } } const float tx = float(width) / nwidth; const float ty = float(height) / nheight; const int components = 3; const int bytes_per_row = width * components; const int components2 = components; const int bytes_per_row2=width * components; int a, b, c, d, index; unsigned char Ca, Cb, Cc; unsigned char C[5]; unsigned char d0, d2, d3, a0, a1, a2, a3; for (int i = 0; i < nheight; ++i) { for (int j = 0; j < nwidth; ++j) { const int x = int(tx * j); const int y = int(ty * i); const float dx = tx * j - x; const float dy = ty * i - y; index = y * bytes_per_row + x * components; a = y * bytes_per_row + (x + 1) * components; b = (y + 1) * bytes_per_row + x * components; c = (y + 1) * bytes_per_row + (x + 1) * components; for (int k = 0; k < 3; ++k) { for (int jj = 0; jj <= 3; ++jj) { //Беруться пиксели из входящего изображения d0 = in[(y - 1 + jj)][(x - 1)][k] - in[(y - 1 + jj)][x][k]; d2 = in[(y - 1 + jj)][(x + 1)][k] - in[(y - 1 + jj)][x][k]; d3 = in[(y - 1 + jj)][(x + 2)][k] - in[(y - 1 + jj)][x][k]; a0 = in[(y - 1 + jj)][x][k]; //Вычисляются параметры a1 = -1.0 / 3 * d0 + d2 - 1.0 / 6 * d3; a2 = 1.0 / 2 * d0 + 1.0 / 2 * d2; a3 = -1.0 / 6 * d0 - 1.0 / 2 * d2 + 1.0 / 6 * d3; C[jj] = a0 + a1 * dx + a2 * dx * dx + a3 * dx * dx * dx; d0 = C[0] - C[1]; d2 = C[2] - C[1]; d3 = C[3] - C[1]; a0 = C[1]; a1 = -1.0 / 3 * d0 + d2 -1.0 / 6 * d3; a2 = 1.0 / 2 * d0 + 1.0 / 2 * d2; a3 = -1.0 / 6 * d0 - 1.0 / 2 * d2 + 1.0 / 6 * d3; Cc = a0 + a1 * dy + a2 * dy * dy + a3* dy * dy * dy; //Буффер записи в файл // datapng[i * stride + j * 4 + k]=Cc; //Запись в массив изображения pixels_image[i][j][k]=(int)Cc; } } } } //Сохранение изображения string filename; filename="output/"+filenom+".png"; const char* filename2=filename.c_str(); surface = cairo_image_surface_create_for_data( datapng, CAIRO_FORMAT_RGB24, width, height, stride); cairo_surface_write_to_png( surface, filename2 ); cairo_surface_destroy(surface); free(datapng); }