-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.py
76 lines (61 loc) · 1.95 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from __future__ import unicode_literals, print_function
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()