summaryrefslogtreecommitdiff
path: root/apps/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/misc.c')
-rw-r--r--apps/misc.c105
1 files changed, 86 insertions, 19 deletions
diff --git a/apps/misc.c b/apps/misc.c
index 055bcd2983..9a890155a7 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -136,35 +136,81 @@ int read_line(int fd, char* buffer, int buffer_size)
136} 136}
137 137
138#ifdef HAVE_LCD_BITMAP 138#ifdef HAVE_LCD_BITMAP
139extern unsigned char lcd_framebuffer[LCD_HEIGHT/8][LCD_WIDTH]; 139
140static const unsigned char bmpheader[] = 140#if LCD_DEPTH <= 8
141{ 141#define BMP_NUMCOLORS (1 << LCD_DEPTH)
142 0x42, 0x4d, 0x3e, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00,
143 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, LCD_WIDTH, 0x00, 0x00, 0x00, LCD_HEIGHT, 0x00,
144 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
145#if LCD_WIDTH == 160
146 0x00, 0x00, 0x00, 0x0a,
147#else 142#else
148 0x00, 0x00, 0x00, 0x04, 143#define BMP_NUMCOLORS 0
149#endif 144#endif
150 0x00, 0x00, 0xc4, 0x0e, 0x00, 0x00, 0xc4, 0x0e, 0x00, 0x00, 0x00, 0x00, 145
151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 146#if LCD_DEPTH == 1
152#ifdef IRIVER_H100 147#define BMP_BPP 1
153 0xe6, 0xd8, 0xad, 148#define BMP_LINESIZE ((LCD_WIDTH/8 + 3) & ~3)
149#elif LCD_DEPTH <= 4
150#define BMP_BPP 4
151#define BMP_LINESIZE ((LCD_WIDTH/2 + 3) & ~3)
152#elif LCD_DEPTH <= 8
153#define BMP_BPP 8
154#define BMP_LINESIZE ((LCD_WIDTH + 3) & ~3)
155#elif LCD_DEPTH <= 16
156#define BMP_BPP 16
157#define BMP_LINESIZE ((LCD_WIDTH*2 + 3) & ~3)
154#else 158#else
155 0x90, 0xee, 0x90, 159#define BMP_BPP 24
160#define BMP_LINESIZE ((LCD_WIDTH*3 + 3) & ~3)
161#endif
162
163#define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
164#define BMP_DATASIZE (BMP_LINESIZE * LCD_HEIGHT)
165#define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
166
167#define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
168#define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
169
170static const unsigned char bmpheader[] =
171{
172 0x42, 0x4d, /* 'BM' */
173 LE32_CONST(BMP_TOTALSIZE), /* Total file size */
174 0x00, 0x00, 0x00, 0x00, /* Reserved */
175 LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */
176
177 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
178 LE32_CONST(LCD_WIDTH), /* Width in pixels */
179 LE32_CONST(LCD_HEIGHT), /* Height in pixels */
180 0x01, 0x00, /* Number of planes (always 1) */
181 LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */
182 0x00, 0x00, 0x00, 0x00, /* Compression mode, 0 = none */
183 LE32_CONST(BMP_DATASIZE), /* Size of bitmap data */
184 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
185 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
186 LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */
187 LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */
188
189#if LCD_DEPTH == 1
190 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
191 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
192#elif LCD_DEPTH == 2
193 0xe6, 0xd8, 0xad, 0x00, /* Colour #0 */
194 0x99, 0x90, 0x73, 0x00, /* Colour #1 */
195 0x4c, 0x48, 0x39, 0x00, /* Colour #2 */
196 0x00, 0x00, 0x00, 0x00 /* Colour #3 */
156#endif 197#endif
157 0x00, 0x00, 0x00,
158 0x00, 0x00
159}; 198};
160 199
161void screen_dump(void) 200void screen_dump(void)
162{ 201{
163 int fh; 202 int fh;
164 int bx, by, ix, iy; 203 int bx, by, iy;
165 int src_byte, src_mask, dst_mask; 204 int src_byte;
166 char filename[MAX_PATH]; 205 char filename[MAX_PATH];
167 static unsigned char line_block[8][(LCD_WIDTH/8+3) & ~3]; 206#if LCD_DEPTH == 1
207 int ix, src_mask, dst_mask;
208 static unsigned char line_block[8][BMP_LINESIZE];
209#elif LCD_DEPTH == 2
210 int src_byte2;
211 static unsigned char line_block[4][BMP_LINESIZE];
212#endif
213
168#ifdef HAVE_RTC 214#ifdef HAVE_RTC
169 struct tm *tm = get_time(); 215 struct tm *tm = get_time();
170 216
@@ -213,6 +259,7 @@ void screen_dump(void)
213 write(fh, bmpheader, sizeof(bmpheader)); 259 write(fh, bmpheader, sizeof(bmpheader));
214 260
215 /* BMP image goes bottom up */ 261 /* BMP image goes bottom up */
262#if LCD_DEPTH == 1
216 for (by = LCD_HEIGHT/8 - 1; by >= 0; by--) 263 for (by = LCD_HEIGHT/8 - 1; by >= 0; by--)
217 { 264 {
218 memset(&line_block[0][0], 0, sizeof(line_block)); 265 memset(&line_block[0][0], 0, sizeof(line_block));
@@ -236,6 +283,26 @@ void screen_dump(void)
236 283
237 write(fh, &line_block[0][0], sizeof(line_block)); 284 write(fh, &line_block[0][0], sizeof(line_block));
238 } 285 }
286#elif LCD_DEPTH == 2
287 for (by = LCD_HEIGHT/4 - 1; by >= 0; by--)
288 {
289 memset(&line_block[0][0], 0, sizeof(line_block));
290
291 for (bx = 0; bx < LCD_WIDTH/2; bx++)
292 {
293 src_byte = lcd_framebuffer[by][2*bx];
294 src_byte2 = lcd_framebuffer[by][2*bx+1];
295 for (iy = 3; iy >= 0; iy--)
296 {
297 line_block[iy][bx] = ((src_byte & 3) << 4) | (src_byte2 & 3);
298 src_byte >>= 2;
299 src_byte2 >>= 2;
300 }
301 }
302
303 write(fh, &line_block[0][0], sizeof(line_block));
304 }
305#endif
239 close(fh); 306 close(fh);
240} 307}
241#endif 308#endif