Skip to content

Commit f2b8054

Browse files
ArcaneNibblemarcan
authored andcommitted
jpeg: Support encoding linear YUV
Signed-off-by: R <[email protected]>
1 parent c71d341 commit f2b8054

2 files changed

Lines changed: 57 additions & 9 deletions

File tree

proxyclient/experiments/jpeg.py

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,14 @@ def rgb2yuv(r, g, b):
224224
'RGB101010',
225225
'RGB565',
226226
'YUV10',
227+
'YUV-linear',
227228
]
228229
pixfmt = args.encode_pixelfmt
229230

231+
if pixfmt == 'YUV-linear' and args.encode_subsampling == '444':
232+
# Driver doesn't support this either
233+
print("WARNING: This combination does not appear to work!!!")
234+
230235
image_data = b''
231236
with Image.open(args.input) as im:
232237
im_W, im_H = im.size
@@ -245,12 +250,21 @@ def rgb2yuv(r, g, b):
245250
# for demonstration purposes only
246251
y_, u_, v_ = rgb2yuv(r, g, b)
247252
image_data += struct.pack("<I", (y_ << 2) | (u_ << 12) | (v_ << 22))
253+
elif pixfmt == 'YUV-linear':
254+
# garbage color space conversion, garbage subsampling
255+
# for demonstration purposes only
256+
y_, u_, v_ = rgb2yuv(r, g, b)
257+
if x & 1 == 0:
258+
color = u_
259+
else:
260+
color = v_
261+
image_data += struct.pack("BB", y_, color)
248262
else:
249263
assert False
250264

251265
if pixfmt in ['RGB888', 'RGB101010', 'YUV10']:
252266
BYTESPP = 4
253-
elif pixfmt == 'RGB565':
267+
elif pixfmt in ['RGB565', 'YUV-linear']:
254268
BYTESPP = 2
255269
else:
256270
assert False
@@ -873,15 +887,39 @@ def set_default_regs(param1=0):
873887
jpeg.PX_PLANE1_TILING_V = 0
874888
else:
875889
assert False
890+
elif pixfmt == 'YUV-linear':
891+
if args.encode_subsampling == '444' or args.encode_subsampling == '400':
892+
jpeg.PX_PLANE0_TILING_H = 2
893+
jpeg.PX_PLANE0_TILING_V = 8
894+
jpeg.PX_PLANE1_TILING_H = 1
895+
jpeg.PX_PLANE1_TILING_V = 1
896+
elif args.encode_subsampling == '422':
897+
jpeg.PX_PLANE0_TILING_H = 4
898+
jpeg.PX_PLANE0_TILING_V = 8
899+
jpeg.PX_PLANE1_TILING_H = 1
900+
jpeg.PX_PLANE1_TILING_V = 1
901+
elif args.encode_subsampling == '420':
902+
jpeg.PX_PLANE0_TILING_H = 4
903+
jpeg.PX_PLANE0_TILING_V = 16
904+
jpeg.PX_PLANE1_TILING_H = 0
905+
jpeg.PX_PLANE1_TILING_V = 0
906+
else:
907+
assert False
876908
else:
877909
assert False
878910
jpeg.PX_PLANE0_STRIDE = surface_stride
879911
jpeg.PX_PLANE1_STRIDE = 0
880912

881-
if args.encode_subsampling in ['422', '420']:
882-
jpeg.CHROMA_HALVE_H_TYPE1 = 1
883-
if args.encode_subsampling == '420':
884-
jpeg.CHROMA_HALVE_V_TYPE1 = 1
913+
if pixfmt in ['RGB888', 'RGB101010', 'RGB565', 'YUV10']:
914+
if args.encode_subsampling in ['422', '420']:
915+
jpeg.CHROMA_HALVE_H_TYPE1 = 1
916+
if args.encode_subsampling == '420':
917+
jpeg.CHROMA_HALVE_V_TYPE1 = 1
918+
elif pixfmt in ['YUV-linear']:
919+
if args.encode_subsampling == '420':
920+
jpeg.CHROMA_HALVE_V_TYPE1 = 1
921+
else:
922+
assert False
885923

886924
# none of this seems to affect anything????
887925
jpeg.REG_0x94 = 0xc # c/2 for 444; 8/2 for 422; 3/1 for 411; b/2 for 400
@@ -911,12 +949,20 @@ def set_default_regs(param1=0):
911949
jpeg.ENCODE_PIXEL_FORMAT.set(FORMAT=E_ENCODE_PIXEL_FORMAT.RGB565)
912950
elif pixfmt == 'YUV10':
913951
jpeg.ENCODE_PIXEL_FORMAT.set(FORMAT=E_ENCODE_PIXEL_FORMAT.YUV10_linear)
952+
elif pixfmt == 'YUV-linear':
953+
jpeg.ENCODE_PIXEL_FORMAT.set(FORMAT=E_ENCODE_PIXEL_FORMAT.YUV_linear)
914954
else:
915955
assert False
916-
jpeg.ENCODE_COMPONENT0_POS = 0
917-
jpeg.ENCODE_COMPONENT1_POS = 1
918-
jpeg.ENCODE_COMPONENT2_POS = 2
919-
jpeg.ENCODE_COMPONENT3_POS = 3
956+
if pixfmt == 'YUV-linear':
957+
jpeg.ENCODE_COMPONENT0_POS = 0
958+
jpeg.ENCODE_COMPONENT1_POS = 1
959+
jpeg.ENCODE_COMPONENT2_POS = 3
960+
jpeg.ENCODE_COMPONENT3_POS = 2
961+
else:
962+
jpeg.ENCODE_COMPONENT0_POS = 0
963+
jpeg.ENCODE_COMPONENT1_POS = 1
964+
jpeg.ENCODE_COMPONENT2_POS = 2
965+
jpeg.ENCODE_COMPONENT3_POS = 3
920966

921967
jpeg.INPUT_START1 = input_buf_iova
922968
jpeg.INPUT_START2 = 0xdeadbeef

proxyclient/m1n1/hw/jpeg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class JPEGRegs(RegMap):
163163
# RGB888: R, G, B = byte pos
164164
# RGB101010: R, G, B = 0/1/2 = low/mid/high bits
165165
# RGB565: R, G, B = 0/1/2 = low/mid/high bits
166+
# YUV10: Y, U, V = 0/1/2 = low/mid/high bits
167+
# YUV linear: Y0 Cb Cr Y1 = byte pos
166168
ENCODE_COMPONENT0_POS = 0x104, Register32
167169
ENCODE_COMPONENT1_POS = 0x108, Register32
168170
ENCODE_COMPONENT2_POS = 0x10c, Register32

0 commit comments

Comments
 (0)