File: imgbuff.C

package info (click to toggle)
xjig 2.4-14.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 892 kB
  • sloc: cpp: 10,177; makefile: 1,142; perl: 23
file content (82 lines) | stat: -rw-r--r-- 1,624 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

#ifndef _global_h
#	include "global.h"
#endif
#ifndef _imgbuff_h
#	include "imgbuff.H"
#endif

ImageBuffer::ImageBuffer() {
	ximage=0;
	width=0;
	height=0;
#ifdef USE_MIT_SHM
int	major,minor;
Bool	pmaps;

	shm=(shared)?XShmQueryVersion(dpy,&major,&minor,&pmaps):0;
	if (shm&&verbose)	{
		printf( "--- using shared memory extension V%d.%d %s\n", major, minor,
					((pmaps)?"(shared pixmaps supported)":"") );
	}
#endif
}

ImageBuffer::~ImageBuffer() {
	FreeData();
}

void ImageBuffer::FreeData() {
	if (ximage) {
#ifdef USE_MIT_SHM
		if (shm) {
			XShmDetach(dpy,&shminfo);
			XDestroyImage(ximage);
			shmdt(shminfo.shmaddr);
			shmctl(shminfo.shmid, IPC_RMID, 0 );
		}
		else
#endif
		{
			free( ximage->data );
			ximage->data = 0L;
			XDestroyImage(ximage);
		}
		ximage=0;
	}
}

void ImageBuffer::AllocData(int w, int h, int bpp8) {
	FreeData();
	width  = w;
	height = h;

#ifdef USE_MIT_SHM
	if (shm) {
		ximage = XShmCreateImage(dpy, DefaultVisual(dpy,scr),
			DefaultDepth(dpy,scr), ZPixmap, NULL, &shminfo, width, height );
		shminfo.shmid    = shmget(IPC_PRIVATE, ximage->bytes_per_line * ximage->height, IPC_CREAT|0777);
		shminfo.shmaddr  = ximage->data = (char*)shmat(shminfo.shmid,0,0);
		shminfo.readOnly = False;
		XShmAttach(dpy,&shminfo);
	}
	else
#endif
	{
		char *data=(char*)malloc(width*height*bpp8);
		ximage = XCreateImage(dpy, DefaultVisual(dpy,scr),
			DefaultDepth(dpy,scr), ZPixmap, 0,
			data, width, height, (8*bpp8), width*bpp8 );
	}
}


XImage *ImageBuffer::Init(int w,int h,int bpp8) {
	// w+=10; h+=10;
	if (w>width||h>height) {
		FreeData();
		AllocData(w,h,bpp8);
	}
	return ximage;
}