×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    8

    Loading Icons from MBM

    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

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    8

    Re: Loading Icons from MBM

    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?

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    8

    Re: Loading Icons from MBM

    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?

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    8

    Re: Loading Icons from MBM

    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

  5. #5
    Registered User
    Join Date
    Feb 2005
    Location
    Belgium (Europe)
    Posts
    1,352

    Re: Loading Icons from MBM

    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 and 2.0.0, pygame, PyS60 CE on E90 and 5800 !

    Find my pys60 extension modules on cyke64.googlepages.com

Similar Threads

  1. Problem with loading mbm on emulator
    By vrs666 in forum Symbian
    Replies: 4
    Last Post: 2006-03-10, 09:17
  2. Getting images from different MBM file in ListBox
    By anoopd in forum Symbian User Interface
    Replies: 8
    Last Post: 2006-02-21, 06:34
  3. loading part of MBM...?.
    By julie_777 in forum Symbian
    Replies: 3
    Last Post: 2005-03-05, 04:53
  4. Dynamic loading and converting to MBM
    By whitemoon in forum Symbian User Interface
    Replies: 3
    Last Post: 2003-11-04, 04:39
  5. dynamic loading of icons?
    By ssseko in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-08-12, 16:26

Posting Permissions

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