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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/***************************************************************************
* yuv_draw.cc
*
* Thu Sep 22 12:35:28 CEST 2005
* Copyright 2005 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
/*
* This file is part of MIaV.
*
* MIaV is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MIaV 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIaV; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "config.h"
#ifdef USE_GUI
#include <qapplication.h>
extern QApplication *miav_app;
#include "yuv_draw.h"
// for miav_app
#include "miav.h"
//#include "font.h"
#include <string.h>
#define TEXT_MARGIN 10
#include "mainwindow.h"
static QImage *loadIcon( char *name, int height )
{
QImage scaled;
QImage *img;
img = new QImage();
img->load( name );
int h = height;
int w = (int)((float)img->width() / (float)(img->height() / (float)h));
scaled = img->smoothScale(w, h);
delete img;
img = new QImage(scaled);
return img;
}
YUVDraw::YUVDraw()
{
overlay = NULL;
// One line of text!
top_pixmap = new QPixmap(720 - TEXT_MARGIN, 20);
bottom_pixmap = new QPixmap(720 - TEXT_MARGIN, 20);
for(int x = 0; x < 720 - TEXT_MARGIN; x++) {
for(int y = 0; y < 20; y++) {
top_grey[x][y] = 255;
}
}
for(int x = 0; x < 720 - TEXT_MARGIN; x++) {
for(int y = 0; y < 20; y++) {
bottom_grey[x][y] = 255;
}
}
img_muted = loadIcon(PIXMAP_MUTE, ICON_HEIGHT);
img_unmuted = loadIcon(PIXMAP_UNMUTE, ICON_HEIGHT);
}
YUVDraw::~YUVDraw()
{
delete top_pixmap;
delete bottom_pixmap;
}
void YUVDraw::setOverlay(SDL_Overlay* o)
{
overlay = o;
}
void YUVDraw::addPixel(int x, int y, int val)
{
if(overlay->w < x) return; // Out of range
if(overlay->h < y) return; // Out of range
Uint8 **pixels = overlay->pixels;
Uint16 *pitches = overlay->pitches;
Uint8* pixel = &pixels[0][(2 * x) + (y * pitches[0])];
if(val > 0) *pixel = (255<*pixel+val?255:*pixel+val);
else *pixel = (0>*pixel+val?0:*pixel+val);
}
void YUVDraw::setTopText(char* text)
{
miav_app->lock();
top_pixmap->fill();
QPainter painter;
painter.begin(top_pixmap);
painter.setFont( QFont( "Arial", 12, QFont::Bold ) );
painter.setPen( Qt::black );
painter.drawText(64, 15, text);
painter.end();
QImage image = top_pixmap->convertToImage();
for(int x = 64; x < 720 - TEXT_MARGIN; x++) {
for(int y = 0; y < 20; y++) {
top_grey[x][y] = qGray(image.pixel(x, y));
}
}
miav_app->unlock();
}
void YUVDraw::setBottomText(char* text)
{
miav_app->lock();
bottom_pixmap->fill();
QPainter painter;
painter.begin(bottom_pixmap);
painter.setFont( QFont( "Arial", 12, QFont::Bold ) );
painter.setPen( Qt::black );
painter.drawText(0, 15, text);
painter.end();
QImage image = bottom_pixmap->convertToImage();
for(int x = 0; x < 720 - TEXT_MARGIN; x++) {
for(int y = 0; y < 20; y++) {
bottom_grey[x][y] = qGray(image.pixel(x, y));
}
}
miav_app->unlock();
}
void YUVDraw::draw()
{
for(int x = 0; x < 720 - TEXT_MARGIN; x++) {
for(int y = 0; y < 20; y++) {
if(top_grey[x][y] != 255) addPixel(x + TEXT_MARGIN, y + TEXT_MARGIN, 255 - top_grey[x][y]);
}
}
for(int x = 0; x < 720 - TEXT_MARGIN; x++) {
for(int y = 0; y < 20; y++) {
if(bottom_grey[x][y] != 255) addPixel(x + TEXT_MARGIN, (556 - TEXT_MARGIN)+ y, 255 - bottom_grey[x][y]);
}
}
}
void YUVDraw::mute(bool muted)
{
int xoffset = 0;
int yoffset = 0;
QImage *img;
if(muted) img = img_muted;
else img = img_unmuted;
// Swicth the bool and draw an mute/unmute symbol
float alpha, color;
for(int x = 0; x < ICON_WIDTH; x++) {
for(int y = 0; y < ICON_HEIGHT; y++) {
alpha = ((float)qAlpha(img->pixel(x, y)) / 255.0);
color = (float)qGray(img->pixel(x, y)) * alpha;
addPixel(x + xoffset, y + yoffset, (unsigned char)color);
}
}
}
/*
void YUVDraw::setText(int xoffset, int yoffset, char* text, int val)
{
for(unsigned int i = 0; i < strlen(text); i++) {
for(int x = 0; x < FONT_WIDTH; x++) {
for(int y = 0; y < FONT_HEIGHT; y++) {
unsigned char col = palette[letter[(int)text[i]][y][x]];
if(col) col += val;
addPixel(i * FONT_WIDTH + x + xoffset, y + yoffset, col);
}
}
}
}
*/
/*
typedef struct{
Uint32 format;
int w, h;
int planes;
Uint16 *pitches;
Uint8 **pixels;
Uint32 hw_overlay:1;
} SDL_Overlay;
*/
#endif/*USE_GUI*/
|