zaka100
W͂Oͨ̍̍̒̈́͛̕
- Messages
- 762
- Location
- Birmingham, UK
Sup, I've been designing a new image format, its called Compressed Network Graphics, Its supposed to be smaller than png (Its not ATM ). Its compressed using bz2 (Need help with this aswell, I need a better compression algorithm).
I'm using pygame to display the graphics and here is the code (very sorry about the mess):
This is the part that is slowing the program down:
This:
And This:
And here is the link for the image file: https://www.mediafire.com/?me42i52w91rb9h2 (yep, 64kb for a 205x130 image)
Code download: https://www.mediafire.com/?hy8ryqq57d7b6e0
So, is there a way to speed this up other than using something like cython?
Edit: Please ignore the while loop at the end of the code
I'm using pygame to display the graphics and here is the code (very sorry about the mess):
Code:
import pygame
import bz2 as lzma
from pygame import gfxdraw
import sys
#from GetColour import *
inputfile = 'test.cng'
list2 = ['!','"','#','$','%','&',"'",'(',')','*','+','0','1','2','3','4','5','6','7','8','9',':',';','@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','~','?','/','{','}',']','|','─','│','â”','┘','├','┤','┬','â”´','┼','â•','â•‘','â•’','â•“','â•”','â••','â•–','â•—','╘','â•™','â•š','â•›','â•œ','â•','â•ž','â•Ÿ','â• ','â•¡','â•¢','â•£','╤','â•¥','╦','╧','╨','â•©','╪','â•«','╬','ª','À','Ø','Ë','Ä…','ü','ù','Äž','Ä£','ĵ','Ä°','Ķ','ÅŒ','ʼn','Å„','Å','ÆŠ','Ɔ','Ƈ','ƃ','Æ‚','Æ','Ç„','Ç…','dž','LJ','Lj','lj','dz','Ǭ','ǧ','Ç£','Ǥ','Ƶ','ƶ','Æ·','Ƹ','ƹ','ƺ','Ʀ','É£','Ê‹','É·','ɶ','É¢','ÊŠ','ʉ','ɵ','É´','ʈ','Ê›','É ','Êš','Ê™','ɱ','É','Éœ','É›','Éš','É™','ɸ','ɤ','Ê ','Ê¡','Ê¢','Ê£','ʤ','Ê¥','ʦ','ʧ','ʨ','Ḁ','á¸','Ḃ','ḃ','Ḅ','ḅ','Ḇ','ḇ','Ḉ','ḉ','Ḋ','ḋ','Ḍ','á¸','Ḏ','á¸','á¸','Ḓ','ḓ','Ḕ','ḕ','Ḗ','ḗ','Ḙ','ḙ','Ḛ','ḛ','Ḝ','á¸','Ḟ','ḟ','Ḡ','ḡ','Ḣ','ḣ','Ḥ','ḥ','Ḧ','ḧ','Ḩ','ḩ','Ḫ','ḫ','Ḭ','á¸','Ḯ','ḯ','Ḱ','ḱ','Ḳ','ḳ','Ḵ','ḵ','Ḷ','ḷ','Ḹ','ḹ','Ḻ','ḻ','Ḽ','ḽ','Ḿ']
reserve = 'Ḿ'
listalpha = ['0','1','2','3','4','5','6','7','8','9','F']
dec = open(inputfile,'rb')
rtxt = dec.read()
#print(bytes(rtxt,'UTF-8'))
#compressed1 = bytes(rtxt,'UTF-8').decode('UTF-8')
#compressed = bytes(rtxt,'UTF-8')
decompress = lzma.decompress(rtxt)
'''
df = open('rawcngexample.txt','wb')
df.write(decompress)
df.close()
'''
lines = decompress.split(b'\n')
print(lines[0])
#print('lines[0]: '+bytes(lines[0],'UTF-8'))
res=lines[0].split(b'x')
width=int(res[0])
height=int(res[1])
screen_size = (width,height)
screen = pygame.display.set_mode(screen_size)
screen.fill(pygame.Color(255,255,255))
pygame.display.set_caption('Image Viewer')
'''
def makepix(x,y,color):
screen.fill(color, ((x,y), (1, 1)))
makepix(10,10,(100,100,100))
'''
pygame.display.init()
def makepixel(x,y,color):
#rgb_color = hex2color(color)
#print(rgb_color)
#screen.fill(rgb_color, ((x,y), (1, 1)))
#gfxdraw.pixel(screen, x, y, color)
#pygame.display.init()
#pygame.display.update()
pixels = pygame.surfarray.pixels3d(screen)
pixels[x][y] = color
pygame.display.update()
#pixel(screen,(100,100,100),(100,100))
#pygame.draw.circle(screen, (0,0,0), (250,250), 125)
num=0
for i in lines:
if num == 0:
pass
else:
#print(bytes.decode(i))
numy=0
line = bytes.decode(i)
n = 3
splitinto3 = [line[i:i+n] for i in range(0, len(line), n)]
for x1 in splitinto3:
chars3=[]
#x = chr(x1)
#rgbs = getcolour(bytes.decode(chars3[0]),bytes.decode(chars3[1]),bytes.decode(chars3[2]))
#rgbs = getcolour(chars3[0],chars3[1],chars3[2])
numred = list2.index(x1[0])
numgreen = list2.index(x1[1])
numblue = list2.index(x1[2])
#col = rgb_to_hex((numred,numgreen,numblue))
makepixel(numy,num-1,color=(numred,numgreen,numblue))
pygame.display.update()
numy+=1
num+=1
#print('Line Complete')
#pygame.display.flip()
'''
def makepix(x,y,color):
screen.fill(color, ((x,y), (1, 1)))
makepix(10,10,(100,100,100))
'''
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == event.QUIT:
pygame.quit()
sys.exit()
This is the part that is slowing the program down:
This:
Code:
def makepixel(x,y,color):
#rgb_color = hex2color(color)
#print(rgb_color)
#screen.fill(rgb_color, ((x,y), (1, 1)))
#gfxdraw.pixel(screen, x, y, color)
#pygame.display.init()
#pygame.display.update()
pixels = pygame.surfarray.pixels3d(screen)
pixels[x][y] = color
Code:
num=0
for i in lines:
if num == 0:
pass
else:
#print(bytes.decode(i))
numy=0
line = bytes.decode(i)
n = 3
splitinto3 = [line[i:i+n] for i in range(0, len(line), n)]
for x1 in splitinto3:
chars3=[]
#x = chr(x1)
#rgbs = getcolour(bytes.decode(chars3[0]),bytes.decode(chars3[1]),bytes.decode(chars3[2]))
#rgbs = getcolour(chars3[0],chars3[1],chars3[2])
numred = list2.index(x1[0])
numgreen = list2.index(x1[1])
numblue = list2.index(x1[2])
#col = rgb_to_hex((numred,numgreen,numblue))
makepixel(numy,num-1,color=(numred,numgreen,numblue))
pygame.display.update()
numy+=1
num+=1
#print('Line Complete')
And here is the link for the image file: https://www.mediafire.com/?me42i52w91rb9h2 (yep, 64kb for a 205x130 image)
Code download: https://www.mediafire.com/?hy8ryqq57d7b6e0
So, is there a way to speed this up other than using something like cython?
Edit: Please ignore the while loop at the end of the code
Last edited: