summaryrefslogtreecommitdiff
path: root/firmware/ajf.c
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-08-11 09:22:40 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-08-11 09:22:40 +0000
commitdd7d69515391322e37215fad385ff2c59f80a68b (patch)
tree6ad8c1696c585164e8671cc29b2cb8fe33f64db0 /firmware/ajf.c
parent71f71ef8370c90b818318cf0d04749bb8e15a82c (diff)
downloadrockbox-dd7d69515391322e37215fad385ff2c59f80a68b.tar.gz
rockbox-dd7d69515391322e37215fad385ff2c59f80a68b.zip
Forgot to add the new files
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1668 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/ajf.c')
-rw-r--r--firmware/ajf.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/firmware/ajf.c b/firmware/ajf.c
new file mode 100644
index 0000000000..e542bdc81e
--- /dev/null
+++ b/firmware/ajf.c
@@ -0,0 +1,101 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Alex Gitelman
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifdef SIMULATOR
20#include <fcntl.h>
21#endif
22#include <file.h>
23#include "ajf.h"
24#include <malloc.h>
25#include <string.h>
26#include <errno.h>
27#include <stdbool.h>
28#include "debug.h"
29
30static unsigned char font_buf[MAX_FONT_BUFLEN];
31
32unsigned char* ajf_read_font(char* fname)
33{
34 int count;
35#ifdef WIN32
36 int fd = open(fname, O_RDONLY|O_BINARY);
37#else
38 int fd = open(fname, O_RDONLY);
39#endif
40 if (fd<0)
41 {
42#ifdef SIMULATOR
43#ifdef WIN32
44 DEBUGF("Failed opening font file: %d %s. ", _errno(), fname);
45#else
46 DEBUGF("Failed opening font file: %d %s. ", errno, fname);
47#endif
48#endif
49 return NULL;
50 }
51
52 count = read(fd, font_buf, MAX_FONT_BUFLEN);
53 if (count==MAX_FONT_BUFLEN) {
54 DEBUGF("Font is larger than allocated %d bytes!\n",MAX_FONT_BUFLEN);
55 return NULL;
56 }
57 close(fd);
58
59 if (font_buf[0]!=MAGIC1 || font_buf[1]!=MAGIC2) {
60 DEBUGF("Bad magic word in font");
61 return NULL;
62 }
63 return font_buf;
64}
65
66
67unsigned char* ajf_get_charbuf(unsigned char c, unsigned char* font,
68 int *w, int *h)
69{
70 int height = READ_SHORT(&font[HEIGHT_OFFSET]);
71 int size = READ_SHORT(&font[SIZE_OFFSET]);
72 int chars_offset = LOOKUP_MAP_OFFSET + size*3;
73 int rows = (height-1)/8 + 1;
74 int first_char = READ_SHORT(&font[FIRST_CHAR_OFFSET]);
75 int map_idx = LOOKUP_MAP_OFFSET + (c-first_char)*3;
76 int byte_count = font[map_idx];
77 int char_idx;
78
79 *h = height;
80 *w = byte_count/rows;
81
82 map_idx++;
83 char_idx = READ_SHORT(&font[map_idx]);
84 return &font[chars_offset + char_idx];
85}
86
87void ajf_get_charsize(unsigned char c, unsigned char* font,
88 int *width, int *height)
89{
90 int first_char = READ_SHORT(&font[FIRST_CHAR_OFFSET]);
91 int map_idx = LOOKUP_MAP_OFFSET + (c-first_char)*3;
92 int rows = 1;
93 *height = READ_SHORT(&font[HEIGHT_OFFSET]);
94 rows = (*height-1)/8 + 1;
95 *width = font[map_idx]/rows;
96}
97
98int ajf_get_fontheight(unsigned char* font)
99{
100 return READ_SHORT(&font[HEIGHT_OFFSET]);
101}