Ejemplo n.º 1
0
def encodeDXT(width, height, im, dxt_type):
    # 调用squish库压缩(squish.pyd 需要编译)
    import squish
    if dxt_type == "DXT1": dxt_type = squish.DXT1
    if dxt_type == "DXT3": dxt_type = squish.DXT3
    if dxt_type == "DXT5": dxt_type = squish.DXT5
    data = im.tobytes()
    img_dxt = squish.compressImage(data, width, height, dxt_type)
    return img_dxt
Ejemplo n.º 2
0
def encodeDXT(width,height,im , dxt_type):
    # 调用squish库压缩(squish.pyd 需要编译)
    import squish
    if dxt_type == "DXT1":dxt_type = squish.DXT1
    if dxt_type == "DXT3":dxt_type = squish.DXT3
    if dxt_type == "DXT5":dxt_type = squish.DXT5
    data = im.tobytes()
    img_dxt = squish.compressImage(data, width, height, dxt_type)
    return img_dxt
#!/usr/bin/env python
import sys
import pygame
import squish

if __name__ == '__main__':

    if len(sys.argv) != 2:
        print 'Usage: python dxt1compress.py <image>'
        sys.exit(1)

    pygame.init()
    fn = sys.argv[1]
    img = pygame.image.load(fn)
    width, height = img.get_size()

    # ensure RGBA
    if img.get_bytesize() != 4:
        img = img.convert(32)
    data = pygame.image.tostring(img, 'RGBA', False)

    # convert
    img_dxt1 = squish.compressImage(data, width, height, squish.DXT1)

    # write
    fn_dxt1 = fn.rsplit('.', 1)[0] + '.dxt1'
    with open(fn_dxt1, 'wb') as fd:
        fd.write(img_dxt1)

    print 'Written to', fn_dxt1
Ejemplo n.º 4
0
#!/usr/bin/env python
import sys
import pygame
import squish

if __name__ == "__main__":

    if len(sys.argv) != 2:
        print "Usage: python dxt1compress.py <image>"
        sys.exit(1)

    pygame.init()
    fn = sys.argv[1]
    img = pygame.image.load(fn)
    width, height = img.get_size()

    # ensure RGBA
    if img.get_bytesize() != 4:
        img = img.convert(32)
    data = pygame.image.tostring(img, "RGBA", False)

    # convert
    img_dxt1 = squish.compressImage(data, width, height, squish.DXT1)

    # write
    fn_dxt1 = fn.rsplit(".", 1)[0] + ".dxt1"
    with open(fn_dxt1, "wb") as fd:
        fd.write(img_dxt1)

    print "Written to", fn_dxt1