MIT License

项目介绍

MircoT/pyTGA 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 MIT License 许可证,目前获得 29 个 Star、3 次 Fork。

仓库全名
MircoT/pyTGA
开源许可证
MIT License
Star 数
29
Fork 数
3

README 摘要

pyTGA A pure Python module to manage TGA images. This module is compatible with Python 2 and Python 3 and we refer on the New TGA Format. The library supports these kind of formats (compressed with RLE or uncompressed): Grayscale - 8 bit depth RGB - 16 bit depth RGB - 24 bit depth RGBA - 32 bit depth As you can see in the example you can use the python basic types for data. Install Simply type: Test Contributing…

完整内容见 GitHub 原始 README 或本页 。

常见问题

pyTGA 用什么语言开发?

主要使用 Python 编写,采用 MIT License 许可证,目前有 29 个 Star。

pyTGA 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 pyTGA 的源码?

可以直接克隆仓库:git clone https://github.com/MircoT/pyTGA.git,默认分支为 master;安装与运行步骤见仓库 README。

pyTGA 最近还在维护吗?

仓库最近一次更新为 2019年3月5日,当前没有未关闭的 Issue;Star 数为 29,可作为社区活跃度的参考。

关于

A simple pure Python module to manage TGA images

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
36
价值分
18
活跃状态
活跃

语言占比

Python

Release

README

pyTGA

A pure Python module to manage TGA images. This module is compatible with Python 2 and Python 3 and we refer on the New TGA Format.

The library supports these kind of formats (compressed with RLE or uncompressed):

  • Grayscale - 8 bit depth
  • RGB - 16 bit depth
  • RGB - 24 bit depth
  • RGBA - 32 bit depth

As you can see in the example you can use the python basic types for data.

Install

Simply type:

python setup.py install

Test

cd test
python test_module.py

Contributing

Contributions are welcome, so please feel free to fix bugs, improve things, provide documentation. For anything submit a personal message or fork the project to make a pull request and so on… thanks!

Example

import pyTGA


def main():
    data_bw = [
        [0, 255, 0, 0],
        [0, 0, 255, 0],
        [255, 255, 255, 0]
    ]

    data_rgb = [
        [(0, 0, 0), (255, 0, 0), (0, 0, 0), (0, 0, 0)],
        [(0, 0, 0), (0, 0, 0), (255, 0, 0), (0, 0, 0)],
        [(255, 0, 0), (255, 0, 0), (255, 0, 0), (0, 0, 0)]
    ]

    data_rgba = [
        [(0, 0, 0, 0), (255, 0, 0, 150), (0, 0, 0, 0), (0, 0, 0, 0)],
        [(0, 0, 0, 0), (0, 0, 0, 0), (255, 0, 0, 150), (0, 0, 0, 0)],
        [(255, 0, 0, 150), (255, 0, 0, 150), (255, 0, 0, 150), (0, 0, 0, 0)]
    ]

    ##
    # Create from grayscale data
    image = pyTGA.Image(data=data_bw)
    # Save as TGA
    image.save("image_black_and_white")

    ##
    # Create from RGB data
    image = pyTGA.Image(data=data_rgb)
    image.save("image_rgb")

    ##
    # Create from RGBA data
    image = pyTGA.Image(data=data_rgba)
    image.save("image_rgba")

    ##
    # Save with RLE compression
    image = pyTGA.Image(data=data_rgba)
    image.save("image_rgba_compressed", compress=True)

    ##
    # Save in original format
    image = pyTGA.Image(data=data_rgba)
    image.save("image_rgba_original", original_format=True)

    ##
    # Save with 16 bit depth
    # You can start also from RGB, but you will lose data
    image = pyTGA.Image(data=data_rgb)
    image.save("test_16", force_16_bit=True)

    data_rgb_16 = [
        [(0, 0, 0), (31, 0, 0), (0, 0, 0), (0, 0, 0)],
        [(0, 0, 0), (0, 0, 0), (31, 0, 0), (0, 0, 0)],
        [(31, 0, 0), (31, 0, 0), (31, 0, 0), (0, 0, 0)]
    ]

    image = pyTGA.Image(data=data_rgb_16)
    image.save("image_16_bit", force_16_bit=True)

    ##
    # Load and modify an image
    image = pyTGA.Image()
    image.load("image_black_and_white.tga").set_pixel(0, 3, 175)
    image.save("image_black_and_white_mod.tga")

    # Get some data
    print(image.get_pixel(0, 3))
    print(image.get_pixels())

if __name__ == '__main__':
    main()

评论

暂无评论