| Reply | « Previous Thread | Next Thread » |
|
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 |
|
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? |
|
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? |
|
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
|
|
Quote:
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 | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| 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 |