~ubuntu-branches/ubuntu/utopic/ohphone/utopic

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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 * vidlinux.cxx
 *
 * Linux video interface
 *
 * Copyright (c) 1999-2000 Equivalence Pty. Ltd.
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 *
 * The Original Code is Open H323 Library.
 *
 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
 *
 * Contributor(s): ______________________________________.
 *
 * $Log: vidlinux.cxx,v $
 * Revision 1.10  2003/03/19 00:51:15  robertj
 * Removed openh323 versions of videoio.h classes as PVideoOutputDevice
 *   descendants for NULL and PPM files added to PWLib.
 *
 * Revision 1.9  2002/12/02 07:42:15  robertj
 * Fixed GNU warning
 *
 * Revision 1.8  2000/05/02 04:32:25  robertj
 * Fixed copyright notice comment.
 *
 * Revision 1.7  2000/04/06 17:08:51  craigs
 * Fixed problems when compiling with X11 capable systems
 *
 * Revision 1.6  1999/11/01 11:50:53  craigs
 * Updated for changes to video interface
 *
 * Revision 1.5  1999/11/01 00:52:00  robertj
 * Fixed various problems in video, especially ability to pass error return value.
 *
 * Revision 1.4  1999/09/21 14:58:19  craigs
 * Fixed problem with SVGAFull mode
 *
 * Revision 1.3  1999/09/21 12:27:18  craigs
 * Fixed problem with incorrect BYTE ordering on VGAFull mode
 *
 * Revision 1.2  1999/09/21 11:00:44  craigs
 * Added support for full colour SVGA displays
 *
 * Revision 1.1  1999/09/21 08:55:11  craigs
 * Added support for Linux video
 *
 *
 */

#include <ptlib.h>
#include "vidlinux.h"

#ifdef HAS_VGALIB
#include <vga.h>

static BYTE rgbto256(const BYTE * rgb)
{
  return (rgb[0] & 0xe0) | ((rgb[1] >> 3) & 0x1c) | ((rgb[2] >> 6) & 0x03);
}

LinuxSVGAOutputDevice::LinuxSVGAOutputDevice(int _numColours)
  : numColours(_numColours)
{
  vgaOk = vga_init() == 0;

  if (vgaOk) {
    if (numColours == 256)
      vgaOk = vga_setmode(G320x200x256) == 0;
    else if (numColours > 256) {
      vgaOk = vga_setmode(G320x200x16M) == 0;
      if (!vgaOk)
        vgaOk = vga_setmode(G320x200x32K) == 0;
    } else
      vgaOk = FALSE;
  }

  if (!vgaOk) {
    vga_setmode(TEXT);
    PError << "cannot open specified svga device" << endl;
  }
}

LinuxSVGAOutputDevice::~LinuxSVGAOutputDevice()
{
  if (vgaOk)
    vga_setmode(TEXT);
}

BOOL LinuxSVGAOutputDevice::Open(const PString &, BOOL)
{
  return TRUE;
}

PStringList LinuxSVGAOutputDevice::GetDeviceNames() const
{
  return PStringList();
}

PINDEX LinuxSVGAOutputDevice::GetMaxFrameBytes()
{
  return 0;
}

BOOL LinuxSVGAOutputDevice::EndFrame()
{
  return TRUE;
}


///////////////////////////////////////////////////////////////

LinuxSVGA256OutputDevice::LinuxSVGA256OutputDevice()
  : LinuxSVGAOutputDevice(256)
{
  if (vgaOk) {
    PINDEX r, g, b, i = 0;
    for (r = 0; r < 8; r++)
      for (g = 0; g < 8; g++)
        for (b = 0; b < 4; b++)
          vga_setpalette(i++, (r * 36) >> 2, (g * 36) >> 2, (b * 85) >> 2);
  }
}

BOOL LinuxSVGA256OutputDevice::SetFrameData(unsigned x, unsigned y,
			                    unsigned w, unsigned h,
					    const BYTE * data,
					    BOOL endFrame)
{
  if (vgaOk) {
    PBYTEArray rgb256(w);

    for (unsigned dy = 0; dy < h; dy++) {
      for (unsigned dx = 0; dx < w; dx++)
        rgb256[dx] = rgbto256(data + dx*3);

      vga_drawscansegment(rgb256.GetPointer(), x, y+dy, w);
    }
  }
  return TRUE;
}

///////////////////////////////////////////////////////////////

LinuxSVGAFullOutputDevice::LinuxSVGAFullOutputDevice()
  : LinuxSVGAOutputDevice(256*256*256)
{
}


BOOL LinuxSVGAFullOutputDevice::SetFrameData(unsigned x, unsigned y,
			                     unsigned w, unsigned h,
					     const BYTE * data,
					     BOOL endFrame)
{
  if (vgaOk) {
    for (unsigned dy = 0; dy < h; dy++) {
      BYTE bgr[3];
      bgr[2] = data[dy*w*3+0];
      bgr[1] = data[dy*w*3+1];
      bgr[0] = data[dy*w*3+2];
      vga_drawscansegment(bgr, x, y+dy, w*3);
    }
  }
  return TRUE;
}


#endif


// End of File ///////////////////////////////////////////////////////////////