-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathspotmeter.c
142 lines (121 loc) · 2.85 KB
/
spotmeter.c
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
/** \file
* Measure the intensity of the center few pixels and
* display a numeric value at the bottom of the screen.
*/
/*
* Copyright (C) 2009 Trammell Hudson <hudson+ml@osresearch.net>
*
* This program 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.
*
* This program 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 this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "dryos.h"
#include "bmp.h"
#include "tasks.h"
#include "menu.h"
#include "config.h"
CONFIG_INT( "spotmeter.size", spotmeter_size, 5 );
CONFIG_INT( "spotmeter.draw", spotmeter_draw, 0 );
static void
spotmeter_menu_display(
void * priv,
int x,
int y,
int selected
)
{
int * draw_ptr = priv;
bmp_printf(
selected ? MENU_FONT_SEL : MENU_FONT,
x, y,
//23456789012
"Spotmeter: %s",
*draw_ptr ? "ON " : "OFF"
);
}
static void
spotmeter_clear_display( void * priv )
{
gui_stop_menu();
bmp_fill( 0x0, 0, 0, 1080, 480 );
}
static struct menu_entry spotmeter_menus[] = {
{
.priv = "Clear screen",
.select = spotmeter_clear_display,
.display = menu_print,
},
{
.priv = &spotmeter_draw,
.select = menu_binary_toggle,
.display = spotmeter_menu_display,
},
};
static void
spotmeter_task( void * priv )
{
menu_add( "Video", spotmeter_menus, COUNT(spotmeter_menus) );
msleep( 1000 );
while(!shutdown_requested)
{
// Draw a few pixels to indicate the center
if( !spotmeter_draw )
{
msleep( 1000 );
continue;
}
msleep( 100 );
struct vram_info * vram = &vram_info[ vram_get_number(2) ];
if( !vram->vram )
continue;
const unsigned width = vram->width;
const unsigned pitch = vram->pitch;
const unsigned height = vram->height;
const unsigned dx = spotmeter_size;
unsigned sum = 0;
unsigned x, y;
bmp_fill(
0xA,
width/2 - dx,
height/2 - dx,
2*dx + 1,
4
);
bmp_fill(
0xA,
width/2 - dx,
height/2 + dx,
2*dx + 1,
4
);
// Sum the values around the center
for( y = height/2 - dx ; y <= height/2 + dx ; y++ )
{
for( x = width/2 - dx ; x <= width/2 + dx ; x++ )
sum += vram->vram[ x + y * pitch ];
}
sum /= (2 * dx + 1) * (2 * dx + 1);
// Scale to 100%
const unsigned scaled = (100 * sum) / 65536;
bmp_printf(
FONT_MED,
300,
400,
"%3d%%",
scaled
);
}
}
TASK_CREATE( __FILE__, spotmeter_task, 0, 0x1f, 0x1000 );