Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
752 theseven 1
//
2
//
3
//    Copyright 2011 TheSeven
4
//
5
//
6
//    This file is part of emCORE.
7
//
8
//    emCORE is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emCORE is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "emcoreapp.h"
25
 
26
 
27
static void main()
28
{
29
    int x, y, r;
30
    int width = lcd_get_width();
31
    int height = lcd_get_height();
32
    int l1, s1, ls1, ss1, l2, s2, ls2, ss2, x1, y1, x2, y2, ox1, oy1, ox2, oy2;
33
    if (width > height)
34
    {
35
        l1 = width;
36
        s1 = height;
37
    }
38
    else
39
    {
40
        l1 = height;
41
        s1 = width;
42
    }
43
    for (l2 = 0x40000000; l2 > l1; l2 >>= 1);
44
    if ((l2 * 9) / 8 > l1) l2 >>= 1;
45
    while ((l2 / 9) * 6 > s1) l2 >>= 1;
46
    l1 = (l2 * 9) / 8;
47
    s1 = l2 / 2;
48
    s2 = s1 / 2;
49
    if (height >= l1)
50
    {
51
        x1 = s1;
52
        x2 = s2;
53
        y1 = l1;
54
        y2 = l2;
55
        ls1 = 0;
56
        ls2 = 0;
57
        ss1 = 0;
58
        ss2 = 0;
59
        ox1 = (width - s1 - s2) / 2;
60
        ox2 = ox1 + s1;
61
        oy1 = (height - l1) / 2;
62
        oy2 = oy1;
63
    }
64
    else
65
    {
66
        x1 = l1;
67
        x2 = l2;
68
        y1 = s1;
69
        y2 = s2;
70
        ls1 = 3 - 3 * l1 * s1;
71
        ls2 = 3 - 3 * l2 * s2;
72
        ss1 = l1 * 3 - 3;
73
        ss2 = l2 * 3 - 3;
74
        ox1 = (width - l1) / 2;
75
        ox2 = ox1;
76
        oy1 = (height - s1 - s2) / 2;
77
        oy2 = oy1 + s1;
78
    }
79
 
80
 
81
    uint8_t* framebuf = (uint8_t*)malloc(s1 * l1 * 3);
82
    if (!framebuf) panicf(PANIC_KILLTHREAD, "Out of memory!");
83
 
84
    int s = s1 / 4;
85
    uint8_t* ptr = framebuf;
86
    for (r = 0; r < 8; r++)
87
        for (y = 0; y < s; y++)
88
        {
89
            for (x = 0; x < s; x++)
90
            {
91
                *ptr++ = 1 << r;
92
                *ptr++ = 0;
93
                *ptr++ = 0;
94
                ptr += ss1;
95
            }
96
            for (x = 0; x < s; x++)
97
            {
98
                *ptr++ = 0;
99
                *ptr++ = 1 << r;
100
                *ptr++ = 0;
101
                ptr += ss1;
102
            }
103
            for (x = 0; x < s; x++)
104
            {
105
                *ptr++ = 0;
106
                *ptr++ = 0;
107
                *ptr++ = 1 << r;
108
                ptr += ss1;
109
            }
110
            for (x = 0; x < s; x++)
111
            {
112
                *ptr++ = 1 << r;
113
                *ptr++ = 1 << r;
114
                *ptr++ = 1 << r;
115
                ptr += ss1;
116
            }
117
            ptr += ls1;
118
        }
119
    for (y = 0; y < s; y++)
120
    {
121
        for (x = 0; x < s; x++)
122
        {
123
            *ptr++ = 0xff;
124
            *ptr++ = 0;
125
            *ptr++ = 0;
126
            ptr += ss1;
127
        }
128
        for (x = 0; x < s; x++)
129
        {
130
            *ptr++ = 0;
131
            *ptr++ = 0xff;
132
            *ptr++ = 0;
133
            ptr += ss1;
134
        }
135
        for (x = 0; x < s; x++)
136
        {
137
            *ptr++ = 0;
138
            *ptr++ = 0;
139
            *ptr++ = 0xff;
140
            ptr += ss1;
141
        }
142
        for (x = 0; x < s; x++)
143
        {
144
            *ptr++ = 0xff;
145
            *ptr++ = 0xff;
146
            *ptr++ = 0xff;
147
            ptr += ss1;
148
        }
149
        ptr += ls1;
150
    }
151
    displaylcd(ox1, oy1, x1, y1, framebuf, 0, 0, x1);
152
 
153
    int sx = s2 / 8;
154
    int sy = MAX(1, l2 / 256);
155
    int i = 256 / (l2 / sy);
156
    s = 8;
157
    for (x = i; x > 1; x >>= 1) s--;
158
    ptr = framebuf;
159
    for (r = 0; r < 256; r += i)
160
        for (y = 0; y < sy; y++)
161
        {
162
            for (x = 0; x < sx; x++)
163
            {
164
                *ptr++ = ~(r | (r >> s));
165
                *ptr++ = ~(r | (r >> s));
166
                *ptr++ = ~(r | (r >> s));
167
                ptr += ss2;
168
            }
169
            for (x = 0; x < sx; x++)
170
            {
171
                *ptr++ = r | (r >> s);
172
                *ptr++ = r | (r >> s);
173
                *ptr++ = r | (r >> s);
174
                ptr += ss2;
175
            }
176
            for (x = 0; x < sx; x++)
177
            {
178
                *ptr++ = 0;
179
                *ptr++ = r | (r >> s);
180
                *ptr++ = r | (r >> s);
181
                ptr += ss2;
182
            }
183
            for (x = 0; x < sx; x++)
184
            {
185
                *ptr++ = r | (r >> s);
186
                *ptr++ = 0;
187
                *ptr++ = r | (r >> s);
188
                ptr += ss2;
189
            }
190
            for (x = 0; x < sx; x++)
191
            {
192
                *ptr++ = r | (r >> s);
193
                *ptr++ = r | (r >> s);
194
                *ptr++ = 0;
195
                ptr += ss2;
196
            }
197
            for (x = 0; x < sx; x++)
198
            {
199
                *ptr++ = r | (r >> s);
200
                *ptr++ = 0;
201
                *ptr++ = 0;
202
                ptr += ss2;
203
            }
204
            for (x = 0; x < sx; x++)
205
            {
206
                *ptr++ = 0;
207
                *ptr++ = r | (r >> s);
208
                *ptr++ = 0;
209
                ptr += ss2;
210
            }
211
            for (x = 0; x < sx; x++)
212
            {
213
                *ptr++ = 0;
214
                *ptr++ = 0;
215
                *ptr++ = r | (r >> s);
216
                ptr += ss2;
217
            }
218
            ptr += ls2;
219
        }
220
    displaylcd(ox2, oy2, x2, y2, framebuf, 0, 0, x2);
221
 
222
    free(framebuf);
223
}
224
 
225
 
226
EMCORE_APP_HEADER("LCD test pattern generator", main, 127)