Created
September 11, 2010 19:25
-
-
Save drx/575472 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rx@drx-laptok:~/feel2$ kernprof.py -v -l feel.py | |
Wrote profile results to feel.py.lprof | |
Timer unit: 1e-06 s | |
File: loaders.py | |
Function: build_blocks_16 at line 324 | |
Total time: 20.7852 s | |
Line # Hits Time Per Hit % Time Line Contents | |
============================================================== | |
324 @profile | |
325 def build_blocks_16(level): | |
326 '''Build 16x16 blocks''' | |
327 6 37 6.2 0.0 for plane in ('foreground', 'background'): | |
328 4 19 4.8 0.0 blocks_16 = [] | |
329 1128 6035 5.4 0.0 for i in xrange(len(level['mappings_16_'+plane].data)/8): | |
330 1124 18313 16.3 0.1 block = QtGui.QImage(16, 16, QtGui.QImage.Format_ARGB32) | |
331 1124 8022 7.1 0.0 block.fill(0xff000000) | |
332 1124 13390 11.9 0.1 block_bits = array('B', '\0'*block.numBytes()) | |
333 1124 14889 13.2 0.1 block_bytes_per_line = block.bytesPerLine() | |
334 3372 18301 5.4 0.1 for x in xrange(2): | |
335 6744 37355 5.5 0.2 for y in xrange(2): | |
336 4496 79019 17.6 0.4 flags, tile_id = divmod(level['mappings_16_'+plane].data.word(i*8+y*4+x*2), 0x800) | |
337 4496 25056 5.6 0.1 flip_x, flip_y = flags & 0x1, flags & 0x2 | |
338 4496 23630 5.3 0.1 palette_line = (flags & 0xc) >> 2 | |
339 | |
340 4496 130020 28.9 0.6 tile_data = level['tiles'].data[tile_id*0x20:(tile_id+1)*0x20] | |
341 4496 26772 6.0 0.1 tile_i = 0 | |
342 148368 757200 5.1 3.6 for tile_byte in tile_data: | |
343 143872 790309 5.5 3.8 tile_y, tile_x = divmod(tile_i, 8) | |
344 431616 2242514 5.2 10.8 for k in (0, 1): | |
345 287744 1593106 5.5 7.7 tyle_byte, palette_cell = divmod(ord(tile_byte), 0x10) | |
346 287744 1605451 5.6 7.7 color = level['palette'].data[palette_line*0x10+palette_cell] | |
347 287744 1507077 5.2 7.3 set_x, set_y = tile_x+k, tile_y | |
348 287744 1452899 5.0 7.0 if flip_x: | |
349 48256 242518 5.0 1.2 set_x = 7-set_x | |
350 287744 1455991 5.1 7.0 if flip_y: | |
351 22848 114328 5.0 0.6 set_y = 7-set_y | |
352 287744 1555910 5.4 7.5 pixel_addr = (y*8+set_y)*block_bytes_per_line+(x*8+set_x)*4 | |
353 287744 1659330 5.8 8.0 block_bits[pixel_addr+3] = (color >> 24) & 0xff | |
354 287744 1572620 5.5 7.6 block_bits[pixel_addr+2] = (color >> 16) & 0xff | |
355 287744 1562471 5.4 7.5 block_bits[pixel_addr+1] = (color >> 8) & 0xff | |
356 287744 1514592 5.3 7.3 block_bits[pixel_addr] = color & 0xff | |
357 143872 724893 5.0 3.5 tile_i += 2 | |
358 | |
359 1124 7779 6.9 0.0 block_16 = {'data': block_bits.tostring()} | |
360 1124 17603 15.7 0.1 block_16['block'] = QtGui.QImage(block_16['data'], 16, 16, QtGui.QImage.Format_ARGB32) | |
361 1124 7693 6.8 0.0 blocks_16.append(block_16) | |
362 4 23 5.8 0.0 level['blocks_16_'+plane] = blocks_16 | |
363 2 8 4.0 0.0 return level |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment