<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: icon code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 04:50:28 GMT</pubDate>
    <description>DZone Snippets: icon code</description>
    <item>
      <title>HTML - AddIcon</title>
      <link>http://snippets.dzone.com/posts/show/2963</link>
      <description>&lt;code&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;    &lt;link rel="shortcut icon" href="img.ico" /&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 03 Nov 2006 19:44:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2963</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Show all icons in avkon.mbm</title>
      <link>http://snippets.dzone.com/posts/show/1482</link>
      <description>There are 2 type of mbm files. The following code work with&lt;br /&gt;ROM-type (most mbm on Z:\) only.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; from appuifw import *&lt;br /&gt;&gt;&gt;&gt; avkon = u'z:\\system\\data\\avkon.mbm'&lt;br /&gt;&gt;&gt;&gt; def showicon(id_list, maskfunc=lambda x:x):&lt;br /&gt;...     if type(id_list) == int:&lt;br /&gt;...         id_list = [id_list] # one item&lt;br /&gt;...     entries = []&lt;br /&gt;...     if type(maskfunc) == dict:  # allow dict as a func&lt;br /&gt;...         func = lambda id: maskfunc.get(id,id)&lt;br /&gt;...     else:&lt;br /&gt;...         func = maskfunc&lt;br /&gt;...     for id in id_list:&lt;br /&gt;...         item = u'%s, %s' % (id, func(id))&lt;br /&gt;...         icon = Icon(avkon, id, func(id))&lt;br /&gt;...         entries.append((item, u'', icon))&lt;br /&gt;...     app.body = Listbox(entries, lambda: None)&lt;br /&gt;...&lt;br /&gt;&gt;&gt;&gt; showicon(range(503))  # all icons, including mask&lt;br /&gt;&gt;&gt;&gt; showicon(range(0,100,2), lambda x:x+1)  # first 50 icons, with their mask brother&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 14 Feb 2006 16:41:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1482</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Reading a 24-bit icon in an mbm file</title>
      <link>http://snippets.dzone.com/posts/show/1476</link>
      <description>Here's an example how I read the icon and display it on canvas&lt;br /&gt;It's a continued part of my previous &lt;a href=http://discussion.forum.nokia.com/forum/showthread.php?t=63608&gt;mbm hack&lt;/a&gt;.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; from appuifw import *&lt;br /&gt;&gt;&gt;&gt; from struct import unpack&lt;br /&gt;&gt;&gt;&gt; def readL(f, pos=None):     # helping function&lt;br /&gt;...     if pos is not None:&lt;br /&gt;...         f.seek(pos)&lt;br /&gt;...     return unpack('L', f.read(4))[0]&lt;br /&gt;...&lt;br /&gt;&gt;&gt;&gt; fxmbm = 'E:\\system\\apps\\FExplorer\\FExplorer.mbm'&lt;br /&gt;&gt;&gt;&gt; f = open(fxmbm, 'rb')&lt;br /&gt;&gt;&gt;&gt; trailer = readL(f, 16)&lt;br /&gt;&gt;&gt;&gt; num = readL(f, trailer)   # 19 icons&lt;br /&gt;&gt;&gt;&gt; offset = []&lt;br /&gt;&gt;&gt;&gt; for i in range(num):&lt;br /&gt;...   offset.append(readL(f))&lt;br /&gt;...&lt;br /&gt;&gt;&gt;&gt; offset&lt;br /&gt;[20L, 68L, 116L, 474L, 588L, 1038L, 1228L, 1636L, 1864L, 2277L, 2430L, 3735L, 41&lt;br /&gt;69L, 4569L, 4697L, 5197L, 5370L, 5897L, 6062L]&lt;br /&gt;&gt;&gt;&gt; start = offset[2]  # folder icon&lt;br /&gt;&gt;&gt;&gt; f.seek(start)&lt;br /&gt;&gt;&gt;&gt; length = readL(f) - readL(f)    # length of data section&lt;br /&gt;&gt;&gt;&gt; width, height = readL(f), readL(f)  # 16 x 13&lt;br /&gt;&gt;&gt;&gt; f.seek(start+0x28)  # start of data section&lt;br /&gt;&gt;&gt;&gt; data_enc = f.read(length)   # got the data&lt;br /&gt;&gt;&gt;&gt; def rle24_decode(bytes):&lt;br /&gt;...     out = []&lt;br /&gt;...     i = 0&lt;br /&gt;...     while i &lt; len(bytes):&lt;br /&gt;...         n = ord(bytes[i])&lt;br /&gt;...         i += 1&lt;br /&gt;...         if n &lt; 0x80:&lt;br /&gt;...             out.append( bytes[i:i+3] * (n+1) )&lt;br /&gt;...             i += 3&lt;br /&gt;...         else:&lt;br /&gt;...             n = 0x100 - n&lt;br /&gt;...             out.append( bytes[i:i+3*n] )&lt;br /&gt;...             i += 3*n&lt;br /&gt;...     return ''.join(out)&lt;br /&gt;...&lt;br /&gt;&gt;&gt;&gt; data = rel24_decode(data_enc)&lt;br /&gt;&gt;&gt;&gt; app.body = canvas = Canvas()&lt;br /&gt;&gt;&gt;&gt; for j in range(height):&lt;br /&gt;...     for i in range(width):&lt;br /&gt;...         p = 3*(j*width+i)&lt;br /&gt;...         color = [ord(data[p+k]) for k in (2,1,0)]  # It's BGR&lt;br /&gt;...         canvas.point((i,j), tuple(color))&lt;br /&gt;...&lt;br /&gt;&gt;&gt;&gt;  # folder icon is drawn on screen&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 14 Feb 2006 12:27:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1476</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Counting number of bitmaps in an mbm file</title>
      <link>http://snippets.dzone.com/posts/show/1472</link>
      <description>I continue &lt;a href=http://discussion.forum.nokia.com/forum/showthread.php?t=63608&gt;my hacking&lt;/a&gt; on symbian mbm(multi-bitmap) format.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# a helping function&lt;br /&gt;from struct import unpack&lt;br /&gt;def readL(f, pos=None):&lt;br /&gt;    if pos is not None:&lt;br /&gt;        f.seek(pos)&lt;br /&gt;    return unpack('L', f.read(4))[0]&lt;br /&gt;&lt;br /&gt;# the real counting function&lt;br /&gt;def mbm_count(mbm_file):&lt;br /&gt;    f = open(mbm_file, 'rb')&lt;br /&gt;    mbm_type = readL(f)&lt;br /&gt;    if mbm_type == 0x10000041:  # mbm on ROM (Z:)&lt;br /&gt;        return readL(f) &lt;br /&gt;    elif mbm_type == 0x10000037L:  # mbm on file (normal)&lt;br /&gt;        return readL(f, readL(f, 16)) # read at trailer&lt;br /&gt;    else:       # what type is it?&lt;br /&gt;        return None&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;For example (you may try this on your phone)&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; mbm_count('z:\\system\\data\\avkon.mbm')&lt;br /&gt;503L&lt;br /&gt;&gt;&gt;&gt; mbm_count('E:\\system\\apps\\FExplorer\\FExplorer.mbm')&lt;br /&gt;19L&lt;br /&gt;&gt;&gt;&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Mon, 13 Feb 2006 22:32:04 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1472</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Using Icon as Image</title>
      <link>http://snippets.dzone.com/posts/show/445</link>
      <description>Pys60 1.1.3 have 2 differnt classes for graphics data.&lt;br /&gt;Icon class represents icon (typically from .mbm file)&lt;br /&gt;which can be put in ListBox for selection.&lt;br /&gt;Image class represents a bigger image which can be&lt;br /&gt;drawn upon. These 2 classes can't convert to/from&lt;br /&gt;each other.&lt;br /&gt;&lt;br /&gt;So, I create a library that read .mbm file and draw&lt;br /&gt;an Image from the data there. So, you can make&lt;br /&gt;an icon into an image (now only 1-bit icons).&lt;br /&gt;the module can be downloaded from here&lt;br /&gt;http://larndham.net/service/pys60/icon_image.py&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from appuifw import *&lt;br /&gt;import icon_image, e32&lt;br /&gt;&lt;br /&gt;app.body = c = Canvas()&lt;br /&gt;# choose a bitmap from plenty inside mbm (multi-bitmap)&lt;br /&gt;icon = icon_image('z:\\system\\data\\avkon.mbm', 28) &lt;br /&gt;c.blit(icon)&lt;br /&gt;&lt;br /&gt;e32.ao_sleep(10)  # 10 sec to end program&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Look here for more information.&lt;br /&gt;http://discussion.forum.nokia.com/forum/showthread.php?s=&amp;threadid=63608</description>
      <pubDate>Sun, 03 Jul 2005 02:02:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/445</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Using icons in Listbox</title>
      <link>http://snippets.dzone.com/posts/show/422</link>
      <description>pys60 1.1.3 provide some graphics capabilitis.&lt;br /&gt;One of them is using icons in Listbox&lt;br /&gt;(code taken from pys60 API reference)&lt;br /&gt;&lt;code&gt;&lt;br /&gt;icon1 = appuifw.Icon(u"z:\\system\\data\\avkon.mbm", 28, 29)&lt;br /&gt;icon2 = appuifw.Icon(u"z:\\system\\data\\avkon.mbm ", 40, 41)&lt;br /&gt;entries = [(u"Signal", icon1),&lt;br /&gt;           (u"Battery", icon2)]&lt;br /&gt;lb = appuifw.Listbox(entries, lbox_observe)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Listbox is one of the 3 types that can be assigned to app.body&lt;br /&gt;(i.e. Text, Listbox, Canvas)&lt;br /&gt;So, to make code above able to run, you must add&lt;br /&gt;&lt;code&gt;appuifw.app.body = lb&lt;/code&gt;&lt;br /&gt;and the function lbox_observe that will handle the selection&lt;br /&gt;need to be defined.</description>
      <pubDate>Fri, 01 Jul 2005 15:24:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/422</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
