media.set_xx giving me grief!

Posted by Firas on Stack Overflow See other posts from Stack Overflow or by Firas
Published on 2009-12-02T00:00:35Z Indexed on 2010/03/14 0:05 UTC
Read the original article Hit count: 231

Filed under:
|

New guy here. I asked a while back about a sprite recolouring program that I was having difficulty with and got some great responses. Basically, I tried to write a program that would recolour pixels of all the pictures in a given folder from one given colour to another.

I believe I have it down, but, now the program is telling me that I have an invalid value specified for the red component of my colour. (ValueError: Invalid red value specified.), even though it's only being changed from 64 to 56. Any help on the matter would be appreciated!

(Here's the code, in case I messed up somewhere else; It's in Python):

import os import media import sys

def recolour(old, new, folder): old_list = old.split(' ') new_list = new.split(' ') folder_location = os.path.join('C:\', 'Users', 'Owner', 'Spriting', folder)

for filename in os.listdir (folder):
    current_file = media.load_picture(folder_location + '\\' + filename)
    for pix in current_file:
        if (media.get_red(pix) == int(old_list[0])) and \
            (media.get_green(pix) == int(old_list[1])) and \
                (media.get_blue(pix) == int(old_list[2])):
            media.set_red(pix, new_list[0])
            media.set_green(pix, new_list[1])
            media.set_blue(pix, new_list[2])                
            media.save(pic)

if name == 'main':

while 1:
    old = str(raw_input('Please insert the original RGB component, separated by a single space: '))
    if old == 'quit':
        sys.exit(0)
    new = str(raw_input('Please insert the new RGB component, separated by a single space: '))
    if new == 'quit':
        sys.exit(0)
    folder = str(raw_input('Please insert the name of the folder you wish to modify: '))
    if folder == 'quit':
        sys.exit(0)
    else:
        recolour(old, new, folder)

© Stack Overflow or respective owner

Related posts about beginner

Related posts about media