summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/avdevice/qvideo.cpp
blob: cc1a0252314581687c839a9e2de746fca17a4aea (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/***************************************************************************
                           qvideo.cpp
                           ----------
    begin                : Sat Jun 12 2004
    copyright            : (C) 2004 by Dirk Ziegelmeier
                           (C) 2002 by George Staikos
    email                : dziegel@gmx.de
 ***************************************************************************/

/*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "qvideo.h"

#include <kdebug.h>
#include <tqpaintdevice.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>

unsigned int QVideo::bytesppForFormat(ImageFormat fmt)
{
    switch (fmt) {
    case FORMAT_RGB32:
    case FORMAT_RGB24:
    case FORMAT_BGR32:
    case FORMAT_BGR24:
        return 4;
        
    case FORMAT_RGB15_LE:
    case FORMAT_RGB16_LE:
    case FORMAT_RGB15_BE:
    case FORMAT_RGB16_BE:
    case FORMAT_YUYV:
    case FORMAT_UYVY:
    case FORMAT_YUV422P:
    case FORMAT_YUV420P:
        return 2;
        
    case FORMAT_GREY:
    case FORMAT_HI240:
        return 1;
        
    default:
        // unknown format
        return 0;
    }
}

bool QVideo::findDisplayProperties(ImageFormat& fmt, int& depth, unsigned int& bitsperpixel, int& bytesperpixel)
{
    XVisualInfo *vi_in, vi_out;
    long mask = VisualScreenMask;
    int  nvis = 0;

    ImageFormat p = FORMAT_NONE;
    int bpp       = 0;
    int d         = 0;
    
	vi_out.screen = TQPaintDevice::x11AppScreen();
	vi_in         = XGetVisualInfo(tqt_xdisplay(), mask, &vi_out, &nvis);

	if (vi_in) {
		for (int i = 0; i < nvis; i++) {
            bpp = 0;
			int n;
			XPixmapFormatValues *pf = XListPixmapFormats(tqt_xdisplay(),&n);
            d = vi_in[i].depth;
			for (int j = 0; j < n; j++) {
				if (pf[j].depth == d) {
					bpp = pf[j].bits_per_pixel;
					break;
				}
			}
			XFree(pf);

            // FIXME: Endianess detection
            
            p = FORMAT_NONE;
			switch (bpp) {
			case 32:
				if (vi_in[i].red_mask   == 0xff0000 &&
				    vi_in[i].green_mask == 0x00ff00 &&
				    vi_in[i].blue_mask  == 0x0000ff) {
					p = FORMAT_BGR32;
					kdDebug() << "QVideo: Found BGR32 display." << endl;
				}
                break;
			case 24:
				if (vi_in[i].red_mask   == 0xff0000 &&
				    vi_in[i].green_mask == 0x00ff00 &&
				    vi_in[i].blue_mask  == 0x0000ff) {
					p = FORMAT_BGR24;
					kdDebug() << "QVideo: Found BGR24 display." << endl;
				}
                break;
			case 16:
				if (vi_in[i].red_mask   == 0x00f800 &&
				    vi_in[i].green_mask == 0x0007e0 &&
				    vi_in[i].blue_mask  == 0x00001f) {
					p = FORMAT_RGB15_LE;
					kdDebug() << "QVideo: Found RGB16_LE display." << endl;
				} else
                    if (vi_in[i].red_mask   == 0x007c00 &&
                        vi_in[i].green_mask == 0x0003e0 &&
                        vi_in[i].blue_mask  == 0x00001f) {
                        p = FORMAT_RGB15_LE;
                        kdDebug() << "QVideo: Found RGB15_LE display." << endl;
                    }
                break;
			case 8:
			default:
				continue;
			}

			if (p != FORMAT_NONE)
				break;
		}
		XFree(vi_in);
	}
    
    if (p != FORMAT_NONE) {
        int bytespp = bytesppForFormat(p);        
        kdDebug() << "QVideo: Display properties: depth: " << d
                  << ", bits/pixel: " << bpp
                  << ", bytes/pixel: " << bytespp << endl;
        fmt           = p;
        bitsperpixel  = bpp;
        bytesperpixel = bytespp;
        depth         = d;
        return true;
    } else {
        kdWarning() << "QVideo: Unable to find out palette. What display do you have????" << endl;
        fmt           = FORMAT_NONE;
        bitsperpixel  = 0;
        bytesperpixel = 0;
        depth         = 0;
        return false;
    }
}