parsing bitmap fonts

99 views
Skip to first unread message

indy arm

unread,
Aug 21, 2011, 6:15:28 AM8/21/11
to ml-devel
hi,

Please find a python script to find them in the firmware.
tested on 550d, 60d, 7d, 600d.
based on work by Pel, Trammel Hudson and A1ex

See related discussion information:
http://magiclantern.wikia.com/wiki/Fonts

I was not able to compute the bitmap data and padding size to make it coherent with offsets...
My goal was to determine the exact end of bitmap data in the firmware.

Indy

$ python python/find_fnt.py ../600d/1.0.1/ROM0.bin
Find bitmap fonts in Canon DSLR firmwares
Arm.Indy. based on work by Pel, Trammel Hudson and A1ex

0xff894758: FNT
0xff89475c: (+0x04) 0xffd8
0xff89475e: (+0x06) font_width = 40
0xff894760: (+0x08) charmap_offset = 0x24
0xff894764: (+0x0c) charmap_size = 0x2a34
0xff894768: (+0x10) bitmap_size = 0x726ca
0xff89476c: (+0x14) font name = 'HCanonGothic ///'
0xff89477c: (+0x24) char_codes[]. 2701 chars
0xff8971b0: (+0x2a58) offsets[]. Last offset value = 0x72694
0xff899be4: (+0x548c) bitmaps[]
  0xff90c278: (+0x77b20) last bitmap
  +0x00: bitmap width = 28
  +0x02: bitmap height = 28
  +0x04: char width = 36
  +0x06: X offset = 4
  +0x08: Y offset = 16
    bitmap size = 0x70

0xff90c2b0: FNT
0xff90c2b4: (+0x04) 0xffd8
0xff90c2b6: (+0x06) font_width = 40
0xff90c2b8: (+0x08) charmap_offset = 0x24
0xff90c2bc: (+0x0c) charmap_size = 0x188
0xff90c2c0: (+0x10) bitmap_size = 0x31c4
0xff90c2c4: (+0x14) font name = 'CanonMonospace  '
0xff90c2d4: (+0x24) char_codes[]. 98 chars
0xff90c45c: (+0x1ac) offsets[]. Last offset value = 0x3142
0xff90c5e4: (+0x334) bitmaps[]
  0xff90f726: (+0x3476) last bitmap
  +0x00: bitmap width = 22
  +0x02: bitmap height = 22
  +0x04: char width = 22
  +0x06: X offset = 0
  +0x08: Y offset = 0
    bitmap size = 0x42


find_fnt.py

Alex

unread,
Aug 21, 2011, 6:18:45 AM8/21/11
to ml-d...@googlegroups.com
Thanks!

I'll include the new in the main build when I'll find some time to
rework the entire menu, since proportional fonts will break the
current layout. Hopefully they have the same font size on all cameras
(didn't try).

> --
> http://magiclantern.wikia.com/
>
> To post to this group, send email to ml-d...@googlegroups.com
> To unsubscribe from this group, send email to
> ml-devel+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ml-devel?hl=en

arm.indy

unread,
Aug 21, 2011, 6:24:21 AM8/21/11
to Magic Lantern firmware development
Alex,

my goal was unrelated to existing ML fonts, but just to identify data
in the firmware...
like tracking zlib streams...

Indy

arm.indy

unread,
Aug 21, 2011, 3:48:59 PM8/21/11
to Magic Lantern firmware development
just to let you know,
by considering the firmware as bitmap data with this script:

import sys
import Image

width = 1280
heigth = 100

f = open(sys.argv[1], 'rb')
m = f.read()
im = Image.fromstring('1', (width,len(m)/(width/8)), m)
im2 = Image.fromstring('L', (width,len(m)/(width)), m)
im.save('test.jpg')
im2.save('test2.jpg')

we can 'guess' our fonts around line 41410 in test.jpg (with Paint for
example)

but where are the icons ? must be compressed...

Indy
>  find_fnt.py
> 6KAfficherTélécharger

Alex

unread,
Aug 21, 2011, 3:53:33 PM8/21/11
to ml-d...@googlegroups.com
That's probably a good idea for guessing image buffers too.

"Sztupák Sz. Zsolt"

unread,
Aug 21, 2011, 4:01:29 PM8/21/11
to ml-d...@googlegroups.com

>
> but where are the icons ? must be compressed...
>
> Indy
>
>
Do we know what format they probably are? (raw data, bmp, png, jpg, etc?)

SztupY

Alex

unread,
Aug 21, 2011, 4:09:55 PM8/21/11
to ml-d...@googlegroups.com
Some of the icons are included in the fonts themselves (special
character codes).

From debug messages, many things seem to be bitmap (not sure if BMP or
some other format). Pel found this in 50D:
http://chdk.setepontos.com/index.php?topic=6161.msg62960#msg62960

arm.indy

unread,
Aug 21, 2011, 6:08:15 PM8/21/11
to Magic Lantern firmware development
Follow BitmapCodec which uses zlib co(mpression)dec(ompression)

On 21 août, 22:09, Alex <broscutama...@gmail.com> wrote:
> Some of the icons are included in the fonts themselves (special
> character codes).
>
> From debug messages, many things seem to be bitmap (not sure if BMP or
> some other format). Pel found this in 50D:http://chdk.setepontos.com/index.php?topic=6161.msg62960#msg62960
>

Chucho

unread,
Aug 21, 2011, 9:16:19 PM8/21/11
to Magic Lantern firmware development
There are some jpeg header @ ff624a30,ff630150,ff63b500,ff647098 and
ff654750 in the 600d rom. Have you tried running magic numbers to find
more headers?

Piers

unread,
Aug 22, 2011, 2:37:19 AM8/22/11
to ml-d...@googlegroups.com
Hi Lanterners, just passing thru.

Builds I made with the Canon font had MUCH taller menus - like 2 or maybe 3 fewer lines will fit on screen (you could obviously fudge the line spacing, but I think they'll start to overlap). I only found one size of Canon proportional font in my ROM0.bin (550D).

But I know there's been a LOT of development since then and I may be talking crap, just throwing in my experience in case it's useful.

PG

Piers

unread,
Aug 22, 2011, 2:50:38 AM8/22/11
to ml-d...@googlegroups.com
e.g. for font-height see the screenshot here (although I picked an emptyish menu to grab)


There are some icons in the middle of the font (see Pel's original bitmap) but they're obviously for small use. The big ones are anti-aliased so I assumed SVG, but they could of course be bitmaps.

PG

arm.indy

unread,
Aug 22, 2011, 3:21:10 PM8/22/11
to Magic Lantern firmware development, Alex, Sztupák Sz. Zsolt, Antony Newman
Hi everyone,

no success yet with this zlib code below... maybe someone will
understand what is wrong ?

see also http://groups.google.com/group/ml-devel/browse_frm/thread/9a122f7afb94490b#

/* 550d 109 */
int (*zlib_uncompress)(uint8_t *dest, int *destLen, uint8_t *src, int
srcLen)=(void*)0xFF2D817C;
int (*zlib_compress)(uint8_t *dest, unsigned long *destLen, uint8_t
*src, int srcLen, int level)=(void*)0xFF2D80b0;

// look for the "1.1.f-LZC.1.1.2" string for zlib_(de)compress()

/* 60d 109: zlib_uncompress=FF32E388, compress=FF32E2BC */

/* 5dm2 208: (by order of screen appearance)
FFA8D5A8 zlib_compress_maybe
FFB24968 zlib_deflate_init2_maybe
FFB24EB4 zlib_deflate_maybe
FFB246EC zlib_deflateEnd_maybe
FFA8D674 zlib_uncompress_maybe
FF9A1C00 zlib_inflateInit2
FF9A3A24 zlib_inflate
FF9A1CFC zlib_inflateEnd
*/
// Credit goes to Sztupak for 60d funcs addresses and Alex for 550d

// try decompression
uint8_t srcbuf[100];
uint8_t dstbuf[100];
int destLen, zliberr;
destLen = 30;
FILE * zfile = FIO_Open( "B:/zlibtext.gz", O_RDONLY | O_SYNC );
// compressed using gzip. tried -1, -9 and default levels
if (zfile) {
unsigned rc = FIO_ReadFile( zfile, srcbuf, 51 );
bmp_printf( FONT_SMALL, x, y+10, "rc=%d ", rc );
FIO_CloseFile( zfile );
dstbuf[0] = '\0';
zliberr = zlib_uncompress( dstbuf, &destLen, srcbuf, rc);
// returns 0, but nothing happens, destLen is not updated
}

// try compression
uint8_t dstbuf[100];
unsigned long destLen, zliberr;
FILE * zfile ;
destLen = 30;
if (dstbuf) {
zliberr = zlib_compress( dstbuf, &destLen, 0xff010000, 32, 9); //
level 9 in in code
//zliberr is 0, but destLen is not updated with compressed length
zfile = FIO_CreateFile( "B:/compr.dat" ); // freezes if compress is
asked
FIO_WriteFile(zfile, dstbuf, destLen);
FIO_CloseFile(zfile);
}

Indy
Reply all
Reply to author
Forward
0 new messages