File: create_8bit_gradient.py

package info (click to toggle)
displaycal-py3 3.9.17-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 29,124 kB
  • sloc: python: 115,810; javascript: 11,545; xml: 598; sh: 257; makefile: 173
file content (33 lines) | stat: -rw-r--r-- 684 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os

import wx


def main():
    img = wx.Image(640, 640)
    buf = img.GetDataBuffer()
    x = y = 0
    levels = []
    for i in range(256):
        for _j in range(5):
            levels.append(i)
    offset = 0
    for i, _byte in enumerate(buf):
        if i and i % 3 == 0:
            x += 1
            if x % 640 == 0:
                x = 0
                y += 1
                offset = y
            else:
                offset += 1
        level = levels[offset]
        buf[i] = chr(level)
    img.SaveFile(os.path.join(os.getcwd(), "gradient_8bit.png"), wx.BITMAP_TYPE_PNG)


if __name__ == "__main__":
    main()