From dd7d69515391322e37215fad385ff2c59f80a68b Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Sun, 11 Aug 2002 09:22:40 +0000 Subject: Forgot to add the new files git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1668 a1c6a512-1295-4272-9138-f99709370657 --- firmware/ajf.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 firmware/ajf.c (limited to 'firmware/ajf.c') 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 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Alex Gitelman + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifdef SIMULATOR +#include +#endif +#include +#include "ajf.h" +#include +#include +#include +#include +#include "debug.h" + +static unsigned char font_buf[MAX_FONT_BUFLEN]; + +unsigned char* ajf_read_font(char* fname) +{ + int count; +#ifdef WIN32 + int fd = open(fname, O_RDONLY|O_BINARY); +#else + int fd = open(fname, O_RDONLY); +#endif + if (fd<0) + { +#ifdef SIMULATOR +#ifdef WIN32 + DEBUGF("Failed opening font file: %d %s. ", _errno(), fname); +#else + DEBUGF("Failed opening font file: %d %s. ", errno, fname); +#endif +#endif + return NULL; + } + + count = read(fd, font_buf, MAX_FONT_BUFLEN); + if (count==MAX_FONT_BUFLEN) { + DEBUGF("Font is larger than allocated %d bytes!\n",MAX_FONT_BUFLEN); + return NULL; + } + close(fd); + + if (font_buf[0]!=MAGIC1 || font_buf[1]!=MAGIC2) { + DEBUGF("Bad magic word in font"); + return NULL; + } + return font_buf; +} + + +unsigned char* ajf_get_charbuf(unsigned char c, unsigned char* font, + int *w, int *h) +{ + int height = READ_SHORT(&font[HEIGHT_OFFSET]); + int size = READ_SHORT(&font[SIZE_OFFSET]); + int chars_offset = LOOKUP_MAP_OFFSET + size*3; + int rows = (height-1)/8 + 1; + int first_char = READ_SHORT(&font[FIRST_CHAR_OFFSET]); + int map_idx = LOOKUP_MAP_OFFSET + (c-first_char)*3; + int byte_count = font[map_idx]; + int char_idx; + + *h = height; + *w = byte_count/rows; + + map_idx++; + char_idx = READ_SHORT(&font[map_idx]); + return &font[chars_offset + char_idx]; +} + +void ajf_get_charsize(unsigned char c, unsigned char* font, + int *width, int *height) +{ + int first_char = READ_SHORT(&font[FIRST_CHAR_OFFSET]); + int map_idx = LOOKUP_MAP_OFFSET + (c-first_char)*3; + int rows = 1; + *height = READ_SHORT(&font[HEIGHT_OFFSET]); + rows = (*height-1)/8 + 1; + *width = font[map_idx]/rows; +} + +int ajf_get_fontheight(unsigned char* font) +{ + return READ_SHORT(&font[HEIGHT_OFFSET]); +} -- cgit v1.2.3