Fixed color conversion
This commit is contained in:
parent
a63d5206b2
commit
66f69ae861
|
@ -1,2 +1,3 @@
|
||||||
demod.dat
|
demod.dat
|
||||||
*.png
|
*.png
|
||||||
|
top_block.py
|
||||||
|
|
20
render.py
20
render.py
|
@ -35,10 +35,14 @@ def to_color(sample):
|
||||||
return sample
|
return sample
|
||||||
|
|
||||||
def ycbcr_to_rgb(y, cb, cr):
|
def ycbcr_to_rgb(y, cb, cr):
|
||||||
r = int(y + 1.402 * (cr - 128))
|
#https://stackoverflow.com/questions/4041840/function-to-convert-ycbcr-to-rgb/15333019#15333019
|
||||||
g = int(y - 3.44136 * (cb - 128) - 0.714136 * (cr - 128))
|
cr = cr - 128 ;
|
||||||
b = int(y + 1.772 * (cb - 128))
|
cb = cb - 128 ;
|
||||||
return (r,g,b)
|
r = y + 45 * cr / 32 ;
|
||||||
|
g = y - (11 * cb + 23 * cr) / 32 ;
|
||||||
|
b = y + 113 * cb / 64 ;
|
||||||
|
|
||||||
|
return (int(r), int(g), int(b))
|
||||||
|
|
||||||
last_sync = False
|
last_sync = False
|
||||||
def is_sync(backlog):
|
def is_sync(backlog):
|
||||||
|
@ -71,8 +75,8 @@ def render_lines(line):
|
||||||
cb = to_color(line[2 * IMG_WIDTH + i])
|
cb = to_color(line[2 * IMG_WIDTH + i])
|
||||||
y1 = to_color(line[3 * IMG_WIDTH + i])
|
y1 = to_color(line[3 * IMG_WIDTH + i])
|
||||||
|
|
||||||
pixels[0][i] = y0, cb, cr
|
pixels[0][i] = ycbcr_to_rgb(y0, cb, cr)
|
||||||
pixels[1][i] = y1, cb, cr
|
pixels[1][i] = ycbcr_to_rgb(y1, cb, cr)
|
||||||
|
|
||||||
return pixels
|
return pixels
|
||||||
|
|
||||||
|
@ -115,14 +119,12 @@ def main():
|
||||||
plt.plot(syncs)
|
plt.plot(syncs)
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
img = Image.new('YCbCr', (IMG_WIDTH, len(pixels)))
|
img = Image.new('RGB', (IMG_WIDTH, len(pixels)))
|
||||||
img_pix = img.load()
|
img_pix = img.load()
|
||||||
for x in range(0, IMG_WIDTH):
|
for x in range(0, IMG_WIDTH):
|
||||||
for y in range(0, len(pixels)):
|
for y in range(0, len(pixels)):
|
||||||
img_pix[x,y] = pixels[y][x]
|
img_pix[x,y] = pixels[y][x]
|
||||||
|
|
||||||
img = img.convert('RGB')
|
|
||||||
|
|
||||||
img.save('output.png')
|
img.save('output.png')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,7 @@
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>_coordinate</key>
|
<key>_coordinate</key>
|
||||||
<value>(979, 187)</value>
|
<value>(63, 410)</value>
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>_rotation</key>
|
<key>_rotation</key>
|
||||||
|
@ -199,7 +199,7 @@
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>_coordinate</key>
|
<key>_coordinate</key>
|
||||||
<value>(1011, 505)</value>
|
<value>(836, 513)</value>
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>_rotation</key>
|
<key>_rotation</key>
|
||||||
|
@ -474,7 +474,7 @@
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>_coordinate</key>
|
<key>_coordinate</key>
|
||||||
<value>(549, 442)</value>
|
<value>(302, 386)</value>
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>_rotation</key>
|
<key>_rotation</key>
|
||||||
|
@ -549,7 +549,7 @@
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>_coordinate</key>
|
<key>_coordinate</key>
|
||||||
<value>(1011, 402)</value>
|
<value>(828, 418)</value>
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>gui_hint</key>
|
<key>gui_hint</key>
|
||||||
|
@ -916,7 +916,7 @@
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>_coordinate</key>
|
<key>_coordinate</key>
|
||||||
<value>(597, 115)</value>
|
<value>(661, 115)</value>
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>gui_hint</key>
|
<key>gui_hint</key>
|
||||||
|
@ -952,7 +952,7 @@
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>color1</key>
|
<key>color1</key>
|
||||||
<value>0</value>
|
<value>3</value>
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>label1</key>
|
<key>label1</key>
|
||||||
|
@ -1139,7 +1139,7 @@
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>_coordinate</key>
|
<key>_coordinate</key>
|
||||||
<value>(1011, 609)</value>
|
<value>(836, 609)</value>
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>gui_hint</key>
|
<key>gui_hint</key>
|
||||||
|
@ -1175,7 +1175,7 @@
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>color1</key>
|
<key>color1</key>
|
||||||
<value>0</value>
|
<value>3</value>
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>label1</key>
|
<key>label1</key>
|
||||||
|
@ -1354,7 +1354,7 @@
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>_coordinate</key>
|
<key>_coordinate</key>
|
||||||
<value>(732, 466)</value>
|
<value>(549, 410)</value>
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>_rotation</key>
|
<key>_rotation</key>
|
||||||
|
|
Loading…
Reference in New Issue