def resize_lowres(file_path):
    filename = os.path.basename(file_path)
    filedir = os.path.dirname(file_path) + "/"
    # load file
    #debug_output("DEBUG: loading: " + file_path + "...")
    try:
        image = pdb.gimp_file_load(file_path, filename)
    except:
        try:
            image = pdb.file_tga_load(file_path, filename)
        except:
            debug_output("ERROR trying to load: " + file_path + ", skipping...")
            return -1
            #pdb.gimp_quit(-1)
    use_width = False
    width = image.width
    height = image.height
    if (width < height):
        shortlength = width
        use_width = True
    else:
        shortlength = height
    if (shortlength <= 64):
        debug_output("DEBUG: image dimensions too small: [" + str(width) + " x " + str(height) + "], no need to scale.")
        # continue with save step to optimize format (dxt1)
    else:
        shortlength = shortlength / 8
        if (shortlength < 64):
            shortlength = 64
        # resize shortest dimension to div8 or minimum 64
        if (use_width == True):
            ratio = float(shortlength) / float(width)
            longlength = int(height * ratio)
            #debug_output("DEBUG: scaling to: [" + str(shortlength) + " x " + str(longlength) + "]...")
            pdb.gimp_image_scale(image, shortlength, longlength)
        else:
            ratio = float(shortlength) / float(height)
            longlength = int(width * ratio)
            #debug_output("DEBUG: scaling to: [" + str(longlength) + " x " + str(shortlength) + "]...")
            pdb.gimp_image_scale(image, longlength, shortlength)
    # save
    debug_output("DEBUG: saving: " + file_path + "...")
    pdb.file_dds_save(image, image.active_layer, #image, drawyable/layer
                      file_path, filename, #filename, raw-filename
                      1, # compression: 0=none, 1=bc1/dxt1, 2=bc2/dxt3, 3=bc3/dxt5, 4=BC3n/dxt5nm, ... 8=alpha exponent... 
                      1, # mipmaps: 0=no mipmaps, 1=generate mipmaps, 2=use existing mipmaps(layers)
                      0, # savetype: 0=selected layer, 1=cube map, 2=volume map, 3=texture array
                      0, # format: 0=default, 1=R5G6B5, 2=RGBA4, 3=RGB5A1, 4=RGB10A2
                      -1, # transparent_index: -1 to disable (indexed images only)
                      0, # filter for generated mipmaps: 0=default, 1=nearest, 2=box, 3=triangle, 4=quadratic, 5=bspline, 6=mitchell, 7=lanczos, 8=kaiser
                      0, # wrap-mode for generated mipmaps: 0=default, 1=mirror, 2=repeat, 3=clamp
                      0, # gamma_correct: use gamma corrected mipmap filtering
                      0, # srgb: use sRGB colorspace for gamma correction
                      2.2, # gamma: gamma value used for gamma correction (ex: 2.2)
                      1, # perceptual_metric: use a perceptual error metric during compression
                      0, # preserve_alpha_coverage: preserve alpha test coverage for alpha channel maps
                      0) # alpha_test_threshold: alpha test threshold value for which alpha test coverage should be preserved
    fake_normalmap_file(filedir, filename)
    gimp.delete(image)
Ejemplo n.º 2
0
def resize_icons(dirname=""):
    debug_output("DEBUG: resize_icons() started...")
    if (dirname == ""):
        top_dir = output_dir + "menus/icons/"
    else:
        top_dir = dirname
    if os.path.exists(top_dir):
        debug_output("DEBUG: searching top_dir: " + top_dir + "...")
        for filename in os.listdir(top_dir):
            if os.path.isdir(top_dir + filename):
                # recurse down and do check below
                filename += "/"
                resize_icons(top_dir + filename)
                continue
            # load file
            #debug_output("DEBUG: loading: " + top_dir+filename + "...")
            try:
                image = pdb.gimp_file_load(top_dir + filename, filename)
            except:
                try:
                    image = pdb.file_tga_load(top_dir + filename, filename)
                except:
                    debug_output("ERROR trying to load: " + top_dir +
                                 filename + ", skipping...")
                    continue
            #debug_output("DEBUG: " + top_dir+filename + " loaded.")
            # check dimensions
            if (image.height != 64) or (image.width != 64):
                # resize to 64x64
                debug_output("DEBUG: scaling: " + top_dir + filename + "...")
                pdb.gimp_image_scale(image, 64, 64)
            else:
                debug_output("DEBUG: already 64x64: " + top_dir + filename)
                # continue with save step to optimize format (dxt1)
            # save
            debug_output("DEBUG: saving: " + top_dir + filename + "...")
            pdb.file_dds_save(
                image,
                image.active_layer,  #image, drawyable/layer
                top_dir + filename,
                filename,  #filename, raw-filename
                1,  # compression: 0=none, 1=bc1/dxt1, 2=bc2/dxt3, 3=bc3/dxt5, 4=BC3n/dxt5nm, ... 8=alpha exponent... 
                1,  # mipmaps: 0=no mipmaps, 1=generate mipmaps, 2=use existing mipmaps(layers)
                0,  # savetype: 0=selected layer, 1=cube map, 2=volume map, 3=texture array
                0,  # format: 0=default, 1=R5G6B5, 2=RGBA4, 3=RGB5A1, 4=RGB10A2
                -1,  # transparent_index: -1 to disable (indexed images only)
                0,  # filter for generated mipmaps: 0=default, 1=nearest, 2=box, 3=triangle, 4=quadratic, 5=bspline, 6=mitchell, 7=lanczos, 8=kaiser
                0,  # wrap-mode for generated mipmaps: 0=default, 1=mirror, 2=repeat, 3=clamp
                0,  # gamma_correct: use gamma corrected mipmap filtering
                0,  # srgb: use sRGB colorspace for gamma correction
                2.2,  # gamma: gamma value used for gamma correction (ex: 2.2)
                1,  # perceptual_metric: use a perceptual error metric during compression
                0,  # preserve_alpha_coverage: preserve alpha test coverage for alpha channel maps
                0
            )  # alpha_test_threshold: alpha test threshold value for which alpha test coverage should be preserved
            #debug_output("DEBUG: unloading: " + top_dir+filename)
            gimp.delete(image)
Ejemplo n.º 3
0
def fix_mgso_normalmaps(file_path):
    global mgso_specular_fix
    filename = os.path.basename(file_path)
    # first, load existing mgso normal map
    try:
        image = pdb.gimp_file_load(file_path, filename)
    except:
        try:
            image = pdb.file_tga_load(file_path, filename)
        except:
            debug_output("ERROR trying to load: " + file_path +
                         ", skipping...")
            return -1
            #pdb.gimp_quit(-1)
    # select all
    pdb.gimp_selection_all(image)
    # cut selection
    pdb.gimp_edit_cut(image.layers[0])
    # paste to floating layer
    templayer = pdb.gimp_edit_paste(image.layers[0], FALSE)
    # decrease opacity of floating layer
    pdb.gimp_layer_set_opacity(templayer, mgso_specular_fix)
    # merge-down
    pdb.gimp_image_merge_down(image, templayer, 0)
    # save output
    debug_output("DEBUG: fixing existing normalmap: " + file_path)
    pdb.file_dds_save(
        image,
        image.active_layer,  #image, drawyable/layer
        file_path,
        filename,  #filename, raw-filename
        3,  # compression: 0=none, 1=bc1/dxt1, 2=bc2/dxt3, 3=bc3/dxt5, 4=BC3n/dxt5nm, ... 8=alpha exponent... 
        1,  # mipmaps: 0=no mipmaps, 1=generate mipmaps, 2=use existing mipmaps(layers)
        0,  # savetype: 0=selected layer, 1=cube map, 2=volume map, 3=texture array
        0,  # format: 0=default, 1=R5G6B5, 2=RGBA4, 3=RGB5A1, 4=RGB10A2
        -1,  # transparent_index: -1 to disable (indexed images only)
        0,  # filter for generated mipmaps: 0=default, 1=nearest, 2=box, 3=triangle, 4=quadratic, 5=bspline, 6=mitchell, 7=lanczos, 8=kaiser
        0,  # wrap-mode for generated mipmaps: 0=default, 1=mirror, 2=repeat, 3=clamp
        0,  # gamma_correct: use gamma corrected mipmap filtering
        0,  # srgb: use sRGB colorspace for gamma correction
        2.2,  # gamma: gamma value used for gamma correction (ex: 2.2)
        1,  # perceptual_metric: use a perceptual error metric during compression
        0,  # preserve_alpha_coverage: preserve alpha test coverage for alpha channel maps
        0
    )  # alpha_test_threshold: alpha test threshold value for which alpha test coverage should be preserved
    #debug_output("Completed: normalmap fix for: " + filename)
    gimp.delete(image)
Ejemplo n.º 4
0
def convert_textures(file_path):
    filename = os.path.basename(file_path)
    filedir = os.path.dirname(file_path) + "/"
    # load file
    #debug_output("DEBUG: loading: " + top_dir+filename + "...")
    try:
        image = pdb.gimp_file_load(file_path, filename)
    except:
        try:
            image = pdb.file_tga_load(file_path, filename)
        except:
            debug_output("ERROR trying to load: " + file_path +
                         ", skipping...")
            return -1
            #pdb.gimp_quit(-1)
    # save
    debug_output("DEBUG: saving: " + file_path + "...")
    pdb.file_dds_save(
        image,
        image.active_layer,  #image, drawyable/layer
        file_path,
        filename,  #filename, raw-filename
        3,  # compression: 0=none, 1=bc1/dxt1, 2=bc2/dxt3, 3=bc3/dxt5, 4=BC3n/dxt5nm, ... 8=alpha exponent... 
        1,  # mipmaps: 0=no mipmaps, 1=generate mipmaps, 2=use existing mipmaps(layers)
        0,  # savetype: 0=selected layer, 1=cube map, 2=volume map, 3=texture array
        0,  # format: 0=default, 1=R5G6B5, 2=RGBA4, 3=RGB5A1, 4=RGB10A2
        -1,  # transparent_index: -1 to disable (indexed images only)
        0,  # filter for generated mipmaps: 0=default, 1=nearest, 2=box, 3=triangle, 4=quadratic, 5=bspline, 6=mitchell, 7=lanczos, 8=kaiser
        0,  # wrap-mode for generated mipmaps: 0=default, 1=mirror, 2=repeat, 3=clamp
        0,  # gamma_correct: use gamma corrected mipmap filtering
        0,  # srgb: use sRGB colorspace for gamma correction
        2.2,  # gamma: gamma value used for gamma correction (ex: 2.2)
        1,  # perceptual_metric: use a perceptual error metric during compression
        0,  # preserve_alpha_coverage: preserve alpha test coverage for alpha channel maps
        0
    )  # alpha_test_threshold: alpha test threshold value for which alpha test coverage should be preserved
    try:
        make_normalmap_file(image, filedir, filename)
    except Exception as e:
        debug_output("ERROR: trying to make normalmap: " + str(e))
    gimp.delete(image)
Ejemplo n.º 5
0
def convert_textures(dirname=""):
    debug_output("DEBUG: convert_textures() started...")
    if (dirname == ""):
        top_dir = output_dir
    else:
        top_dir = dirname
    # skip icons or lowres directories
    if ("/icons/" in top_dir.lower()) or ("/lowres/" in top_dir.lower()):
        debug_output("skipping icons/lowres textures...")
        return
    if os.path.exists(top_dir):
        debug_output("DEBUG: searching top_dir: " + top_dir + "...")
        # first, build list
        file_list = list()
        for filename in os.listdir(top_dir):
            file_list.append(filename)
        # now iterate through list rather than directly to listdir()
        for filename in file_list:
            # skip icons or lowres filename
            if ("icons" == filename.lower()) or ("lowres" == filename.lower()):
                debug_output("skipping icons/lowres textures...")
                continue
            if os.path.isdir(top_dir + filename):
                # recurse down and do check below
                filename += "/"
                convert_textures(top_dir + filename)
                continue
            # load file
            #debug_output("DEBUG: loading: " + top_dir+filename + "...")
            try:
                image = pdb.gimp_file_load(top_dir + filename, filename)
            except:
                try:
                    image = pdb.file_tga_load(top_dir + filename, filename)
                except:
                    debug_output("ERROR trying to load: " + top_dir +
                                 filename + ", skipping...")
                    continue
            # save
            debug_output("DEBUG: saving: " + top_dir + filename + "...")
            pdb.file_dds_save(
                image,
                image.active_layer,  #image, drawyable/layer
                top_dir + filename,
                filename,  #filename, raw-filename
                3,  # compression: 0=none, 1=bc1/dxt1, 2=bc2/dxt3, 3=bc3/dxt5, 4=BC3n/dxt5nm, ... 8=alpha exponent... 
                1,  # mipmaps: 0=no mipmaps, 1=generate mipmaps, 2=use existing mipmaps(layers)
                0,  # savetype: 0=selected layer, 1=cube map, 2=volume map, 3=texture array
                0,  # format: 0=default, 1=R5G6B5, 2=RGBA4, 3=RGB5A1, 4=RGB10A2
                -1,  # transparent_index: -1 to disable (indexed images only)
                0,  # filter for generated mipmaps: 0=default, 1=nearest, 2=box, 3=triangle, 4=quadratic, 5=bspline, 6=mitchell, 7=lanczos, 8=kaiser
                0,  # wrap-mode for generated mipmaps: 0=default, 1=mirror, 2=repeat, 3=clamp
                0,  # gamma_correct: use gamma corrected mipmap filtering
                0,  # srgb: use sRGB colorspace for gamma correction
                2.2,  # gamma: gamma value used for gamma correction (ex: 2.2)
                1,  # perceptual_metric: use a perceptual error metric during compression
                0,  # preserve_alpha_coverage: preserve alpha test coverage for alpha channel maps
                0
            )  # alpha_test_threshold: alpha test threshold value for which alpha test coverage should be preserved
            try:
                make_normalmap_file(image, top_dir, filename)
            except Exception as e:
                debug_output("ERROR: trying to make normalmap: " + str(e))
            gimp.delete(image)