You Are Here:

Community: Developer Discussion Boards

#1 Old Loading Icons from MBM - 2006-07-19, 17:51

Join Date: Feb 2006
Posts: 8
ee7drs
Offline
Registered User
Hi,

I'm trying to load an Icon from an MBM but get:
TypeError: expected valid icon file

MBMViewer accepts the MBM file as valid and displays it's content fine and bmconv splits it fine. I have generated the file on the fly with Python code (as I want to be able to update the icons in a list).
Do I need to deviate from the standard MBM format to produce icon files? Or can I find out what is causing this error (unlikely but worth a try)?

Thanks
Reply With Quote

#2 Old Re: Loading Icons from MBM - 2006-07-21, 12:33

Join Date: Feb 2006
Posts: 8
ee7drs
Offline
Registered User
I've updated my code to generate ROM type MBMs (ClipArt to you Psioneers) but the emulator and real interpreter still give the same error despite MBMViewer still being able to view the contents correctly.
Can ROM type MBMs only be loaded from ROM?
Do Icons have to be loaded from ROM?
Reply With Quote

#3 Old Re: Loading Icons from MBM - 2006-07-21, 15:29

Join Date: Feb 2006
Posts: 8
ee7drs
Offline
Registered User
Oops, wasn't using UNICODE filename.
Having had a quick look at the source code the error could be more useful if it was something like 'expected valid icon file name'. Also seems a bit dodgy relying on file extension to determine if file is valid, why not check UIDs properly?
Reply With Quote

#4 Old Re: Loading Icons from MBM - 2006-07-21, 17:26

Join Date: Feb 2006
Posts: 8
ee7drs
Offline
Registered User
Here's my code for producing MBM/Icon files.
The parameters are:
fn = filename to create
img_list = a list of 'RGB' and '1' type images
rom = True to produce a ROM/ClipArt type MBM, False to produce plain MBM

Code:
from struct import pack

def image2icon(fn, img_list, rom = False):
    try:
        fp = open(fn, 'wb')
    except Exception, inst:
        traceback.print_exc()
        return False
    if rom == False:
        fp.write(pack('LLLL',0x10000037,0x10000042,0x0,0x47396439)) #MBM UIDs
        fp.write(pack('L',20)) #offset to image table
    else:
        fp.write(pack('L',0x10000041)) #ROM/Clip art MBM UID
    fp.write(pack('L',len(img_list))) #num images
    image_offset_list = fp.tell()
    i = 0
    while i < len(img_list):
        fp.write(pack('L',0)) #dummy offset
        i = i + 1
    n = 0
    if rom:
        offset = 8 + (len(img_list)*4)
    else:
        offset = 24 + (len(img_list)*4)
    for img in img_list:
        (w,h) = img.size
        fp.seek(image_offset_list + (n*4))
        fp.write(pack('L', offset)) #offset to image n
        fp.seek(offset)
        n = n + 1
        if rom:
            if img.mode == '1':
                fp.write(pack('L',0x10000040)) # Clip art stuff
                fp.write(pack('L',0x01))
                fp.write(pack('L',0))
                fp.write(pack('L',0))
                fp.write(pack('L',0x04))
            else:                
                fp.write(pack('L',0x10000040)) # Clip art stuff
                fp.write(pack('L',0x08))
                fp.write(pack('L',0))
                fp.write(pack('L',0))
                fp.write(pack('L',0x60))
        size_offset = fp.tell()
        fp.write(pack('L',0)) #size of section - temporary
        fp.write(pack('L',40)) #offset to image data
        fp.write(pack('L',w))
        fp.write(pack('L',h))
        fp.write(pack('L',0)) # twips x
        fp.write(pack('L',0)) # twips y
        if img.mode == 'RGB':
            fp.write(pack('L',24)) # bpp
            fp.write(pack('L',1)) # colour
            fp.write(pack('L',0)) # ??
            fp.write(pack('L',0)) # encoding - no RLE
            if rom:
                fp.write(pack('L',0xffffffff)) # CA
                fp.write(pack('L',0x44)) # CA
            row_sz = w
            if w%4:
                row_sz = w + (4 - w%4)
            data_size = 40 + (3 * h * row_sz)
            if rom:
                data_size = data_size + 28 # CA has 7 extra ints
            row = 0
            while row < h:
                c = 0
                while c < w:
                    rgb = img.getpixel((c,row))
                    fp.write(pack('B',rgb[0][2]))
                    fp.write(pack('B',rgb[0][1]))
                    fp.write(pack('B',rgb[0][0]))
                    c = c + 1
                while c < row_sz:
                    fp.write(pack('B', 0))
                    c = c + 1
                row = row + 1
        elif img.mode == '1':
            fp.write(pack('L',1)) # bpp
            fp.write(pack('L',0)) # colour - black & white
            fp.write(pack('L',0)) # ??
            fp.write(pack('L',0)) # encoding - no RLE
            if rom:
                fp.write(pack('L',0xffffffff)) # CA
                fp.write(pack('L',0x44)) # CA
            row_sz = w
            if w%32:
                row_sz = w + (32 - w%32)
            data_size = 40 + (h * row_sz/8)
            if rom:
                data_size = data_size + 28 # CA has 7 extra ints
            row = 0
            while row < h:
                c = 0
                word = 0
                bit_offset = 0
                while c < w:
                    rgb = img.getpixel((c,row))
                    if rgb[0][0] <> 0:
                        word = word | (1<<bit_offset)
                    bit_offset = bit_offset + 1
                    if bit_offset == 32:
                        fp.write(pack('L', word))
                        bit_offset = 0
                        word = 0
                    c = c + 1
                if c < row_sz:
                    fp.write(pack('L', word))
                row = row + 1
        offset = offset + data_size
        fp.seek(size_offset)
        if rom:
            fp.write(pack('L',data_size - 28)) #size of section minus extra CA bits
        else:
            fp.write(pack('L',data_size)) #size of section
    fp.close()
    return True
Reply With Quote

#5 Old Re: Loading Icons from MBM - 2006-07-30, 05:35

Join Date: Feb 2005
Posts: 1,353
Location: Belgium (Europe)
cyke64's Avatar
cyke64
Offline
Super Contributor
Quote:
Originally Posted by ee7drs
Here's my code for producing MBM/Icon files.
The parameters are:
fn = filename to create
img_list = a list of 'RGB' and '1' type images
rom = True to produce a ROM/ClipArt type MBM, False to produce plain MBM
There's an interesting post about MBM images at http://discussion.forum.nokia.com/fo...23&postcount=1

other code can be seen here
here

and here !


pys60 1.4.5,1.9.7,pygame,PyS60 CE on E90 , N810 with Python 2.5.2 and ... last PyS60 1.9.7 with touch ui on 5800 !

pys60 extension modules on http://cyke64.googlepages.com/
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with loading mbm on emulator vrs666 General Symbian C++ 4 2006-03-10 10:17
Getting images from different MBM file in ListBox anoopd Symbian User Interface 8 2006-02-21 07:34
loading part of MBM...?. julie_777 General Symbian C++ 3 2005-03-05 05:53
Dynamic loading and converting to MBM whitemoon Symbian User Interface 3 2003-11-04 05:39
dynamic loading of icons? ssseko Symbian User Interface 0 2003-08-12 17:26

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia