source: abuse/tags/pd/macabuse/imlib/port/x11/video24.c @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 12 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1
2void x24_make_page(short width, short height, unsigned char *page_buffer)
3{
4  XImage_Info *xi; 
5  if (special && !special->static_mem)
6  {
7    xi=new XImage_Info;
8    special->extended_descriptor=(void *)xi;   
9#ifndef NO_SHM
10    if (doShm)
11    {
12      width=(width+3)&(0xffffffff-3);
13      // create the image
14      xi->XImg = XShmCreateImage(display,
15                                 X_visual,
16                                 24,
17                                 ZPixmap,
18                                 0,
19                                 &xi->X_shminfo,
20                                 width,
21                                 height );
22
23      w=width=xi->XImg->bytes_per_line;  // adjust image size to X requirments
24     
25      // create the shared memory segment
26      xi->X_shminfo.shmid = shmget (IPC_PRIVATE, width*height*3, IPC_CREAT | 0777);
27      ERROR(xi->X_shminfo.shmid>=0,"shmget() failed, go figure");
28
29      xi->X_shminfo.readOnly=False;
30     
31
32      // attach to the shared memory segment to us
33      xi->XImg->data = xi->X_shminfo.shmaddr =
34                (char *) shmat(xi->X_shminfo.shmid, 0, 0);
35      ERROR(xi->XImg->data,"shmat() failed, go figure");
36
37      if (page_buffer)
38        memcpy(xi->XImg->data,page_buffer,width*height);           
39
40      // get the X server to attach to it to the X server
41      ERROR(XShmAttach(display, &xi->X_shminfo),"XShmAttach() failed, go figure");
42      XSync(display,False); // make sure segment gets attached
43      ERROR(shmctl(xi->X_shminfo.shmid,IPC_RMID,NULL)==0,"shmctl failed, why?");
44
45    } else
46#endif
47    {
48      if (!page_buffer)
49        page_buffer=(unsigned char *)jmalloc(width*height,"image::data");
50     
51      xi->XImg = XCreateImage(  display,
52                                X_visual,
53                                8, // my_visual->depth,
54                                ZPixmap,
55                                0,
56                                (char *)page_buffer,
57                                width, height,
58                                8,
59                                width );
60      ERROR(xi->XImg,"XCreateImage failed");
61    }
62    data=(unsigned char *) (xi->XImg->data);       
63  }
64  else
65  {
66    if (!page_buffer)
67      data=(unsigned char *)jmalloc(width*height,"image::data");
68    else data=page_buffer;
69  }
70
71  if (special)
72    special->resize(width,height);
73}
Note: See TracBrowser for help on using the repository browser.