Skip to content

Commit 7350baf

Browse files
ArcaneNibblemarcan
authored andcommitted
jpeg: Implement decoding other subsampling modes
Signed-off-by: R <[email protected]>
1 parent 0c1f89d commit 7350baf

1 file changed

Lines changed: 85 additions & 41 deletions

File tree

proxyclient/experiments/jpeg.py

Lines changed: 85 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def divroundup(val, div):
2525
g.add_argument("-e", "--encode", action='store_true')
2626
g.add_argument("-d", "--decode", action='store_true')
2727
ap.add_argument("--raw-output", type=str, required=False)
28+
ap.add_argument("--decode-scale", type=int, required=False)
2829
ap.add_argument("input", type=str)
2930
ap.add_argument("output", type=str)
3031
args = ap.parse_args()
@@ -33,6 +34,13 @@ def divroundup(val, div):
3334

3435
# Perform necessary pre-parsing
3536
if args.decode:
37+
if args.decode_scale is not None:
38+
assert args.decode_scale in [1, 2, 4, 8]
39+
decode_scale = args.decode_scale
40+
else:
41+
decode_scale = 1
42+
# TODO: finish implementing this
43+
3644
with open(args.input, 'rb') as f:
3745
jpeg_data = f.read()
3846

@@ -94,9 +102,7 @@ def divroundup(val, div):
94102
assert found_sof0
95103
print(f"JPEG is {jpeg_W}x{jpeg_H} with subsampling {jpeg_MODE}")
96104

97-
if jpeg_MODE == '444':
98-
macroblock_W, macroblock_H = 8, 8
99-
elif jpeg_MODE == '400':
105+
if jpeg_MODE == '444' or jpeg_MODE == '400':
100106
macroblock_W, macroblock_H = 8, 8
101107
elif jpeg_MODE == '422':
102108
macroblock_W, macroblock_H = 16, 8
@@ -293,20 +299,31 @@ def set_default_regs(param1=0):
293299
jpeg.REG_0x34 = 1
294300
jpeg.REG_0x2c = 0
295301
jpeg.REG_0x38 = 0
296-
jpeg.CODEC.set(CODEC=E_CODEC._444)
302+
if jpeg_MODE == '444':
303+
jpeg.CODEC.set(CODEC=E_CODEC._444)
304+
elif jpeg_MODE == '400':
305+
jpeg.CODEC.set(CODEC=E_CODEC._400)
306+
elif jpeg_MODE == '422':
307+
jpeg.CODEC.set(CODEC=E_CODEC._422)
308+
elif jpeg_MODE == '420':
309+
jpeg.CODEC.set(CODEC=E_CODEC._420)
310+
elif jpeg_MODE == '411':
311+
jpeg.CODEC.set(CODEC=E_CODEC._411)
312+
else:
313+
assert False
297314
jpeg.DECODE_PIXEL_FORMAT.set(FORMAT=E_DECODE_PIXEL_FORMAT.RGBA8888)
298315

299316
jpeg.PX_USE_PLANE1 = 0
300317
jpeg.PX_PLANE0_WIDTH = jpeg_W*BYTESPP - 1
301318
jpeg.PX_PLANE0_HEIGHT = jpeg_H - 1
302319
# TODO P1
303-
jpeg.TIMEOUT.val = 266000000
320+
jpeg.TIMEOUT = 266000000
304321

305322
jpeg.REG_0x94 = 0x1f
306323
jpeg.REG_0x98 = 1
307324

308-
jpeg.DECODE_MACROBLOCKS_W.val = divroundup(jpeg_W, macroblock_W)
309-
jpeg.DECODE_MACROBLOCKS_H.val = divroundup(jpeg_H, macroblock_H)
325+
jpeg.DECODE_MACROBLOCKS_W = divroundup(jpeg_W, macroblock_W)
326+
jpeg.DECODE_MACROBLOCKS_H = divroundup(jpeg_H, macroblock_H)
310327
# right_edge_px = jpeg_W - divroundup(jpeg_W, 8)*8 + 8
311328
# bot_edge_px = jpeg_H - divroundup(jpeg_H, 8)*8 + 8
312329
# # XXX changing this does not seem to do anything
@@ -315,12 +332,39 @@ def set_default_regs(param1=0):
315332
# jpeg.RIGHT_EDGE_SAMPLES.val = right_edge_px // 2
316333
# jpeg.BOTTOM_EDGE_SAMPLES.val = bot_edge_px // 2
317334

318-
jpeg.PX_TILES_H.val = divroundup(jpeg_H, macroblock_W)
319-
jpeg.PX_TILES_W.val = divroundup(jpeg_W, macroblock_H)
320-
jpeg.PX_PLANE0_TILING_H.val = 4
321-
jpeg.PX_PLANE0_TILING_V.val = 8
322-
jpeg.PX_PLANE1_TILING_H.val = 1
323-
jpeg.PX_PLANE1_TILING_V.val = 1
335+
jpeg.PX_TILES_H = divroundup(jpeg_H, macroblock_H)
336+
jpeg.PX_TILES_W = divroundup(jpeg_W, macroblock_W)
337+
if jpeg_MODE == '444' or jpeg_MODE == '400':
338+
jpeg.PX_PLANE0_TILING_H = 4
339+
jpeg.PX_PLANE0_TILING_V = 8
340+
jpeg.PX_PLANE1_TILING_H = 1
341+
jpeg.PX_PLANE1_TILING_V = 1
342+
elif jpeg_MODE == '422':
343+
jpeg.PX_PLANE0_TILING_H = 8
344+
jpeg.PX_PLANE0_TILING_V = 8
345+
jpeg.PX_PLANE1_TILING_H = 1
346+
jpeg.PX_PLANE1_TILING_V = 1
347+
elif jpeg_MODE == '420':
348+
jpeg.PX_PLANE0_TILING_H = 8
349+
jpeg.PX_PLANE0_TILING_V = 16
350+
jpeg.PX_PLANE1_TILING_H = 0
351+
jpeg.PX_PLANE1_TILING_V = 0
352+
elif jpeg_MODE == '411':
353+
jpeg.PX_PLANE0_TILING_H = 16
354+
jpeg.PX_PLANE0_TILING_V = 8
355+
jpeg.PX_PLANE1_TILING_H = 0
356+
jpeg.PX_PLANE1_TILING_V = 0
357+
else:
358+
assert False
359+
360+
if jpeg_MODE in ['422', '420']: # TODO
361+
jpeg.CHROMA_DOUBLE_H = 1
362+
363+
if jpeg_MODE == '411': # TODO
364+
jpeg.CHROMA_QUADRUPLE_H = 1
365+
366+
if jpeg_MODE == '420': # TODO
367+
jpeg.CHROMA_DOUBLE_V = 1
324368

325369
jpeg.MATRIX_MULT[0].val = 0x100
326370
jpeg.MATRIX_MULT[1].val = 0x0
@@ -334,36 +378,36 @@ def set_default_regs(param1=0):
334378
jpeg.MATRIX_MULT[9].val = 0x0
335379
jpeg.MATRIX_MULT[10].val = 0xffffff80
336380

337-
jpeg.RGBA_ALPHA.val = 0xff
338-
jpeg.RGBA_ORDER.val = 1
381+
jpeg.RGBA_ALPHA = 0xff
382+
jpeg.RGBA_ORDER = 1
339383

340-
jpeg.SCALE_FACTOR.val = 0
384+
jpeg.SCALE_FACTOR = 0
385+
386+
jpeg.INPUT_START1 = input_buf_iova
387+
jpeg.INPUT_START2 = 0xdeadbeef
388+
jpeg.INPUT_END = input_buf_iova + input_mem_sz
389+
jpeg.OUTPUT_START1 = output_buf_iova
390+
# jpeg.OUTPUT_START2 = output_buf_iova + jpeg_W * 4 # HACK
391+
jpeg.OUTPUT_START2 = 0xdeadbeef
392+
jpeg.OUTPUT_END = output_buf_iova + output_mem_sz
393+
jpeg.PX_PLANE0_STRIDE = surface_stride
394+
# jpeg.PX_PLANE1_STRIDE = output_W * 4 # HACK
395+
396+
jpeg.REG_0x1ac = 0x0
397+
jpeg.REG_0x1b0 = 0x0
398+
jpeg.REG_0x1b4 = 0x0
399+
jpeg.REG_0x1bc = 0x0
400+
jpeg.REG_0x1c0 = 0x0
401+
jpeg.REG_0x1c4 = 0x0
402+
403+
jpeg.REG_0x118 = 0x0
404+
jpeg.REG_0x11c = 0x1
405+
406+
jpeg.MODE = 0x177
407+
jpeg.REG_0x1028 = 0x400
341408

342-
jpeg.INPUT_START1.val = input_buf_iova
343-
jpeg.INPUT_START2.val = 0xdeadbeef
344-
jpeg.INPUT_END.val = input_buf_iova + input_mem_sz
345-
jpeg.OUTPUT_START1.val = output_buf_iova
346-
# jpeg.OUTPUT_START2.val = output_buf_iova + jpeg_W * 4 # HACK
347-
jpeg.OUTPUT_START2.val = 0xdeadbeef
348-
jpeg.OUTPUT_END.val = output_buf_iova + output_mem_sz
349-
jpeg.PX_PLANE0_STRIDE.val = surface_stride
350-
# jpeg.PX_PLANE1_STRIDE.val = output_W * 4 # HACK
351-
352-
jpeg.REG_0x1ac.val = 0x0
353-
jpeg.REG_0x1b0.val = 0x0
354-
jpeg.REG_0x1b4.val = 0x0
355-
jpeg.REG_0x1bc.val = 0x0
356-
jpeg.REG_0x1c0.val = 0x0
357-
jpeg.REG_0x1c4.val = 0x0
358-
359-
jpeg.REG_0x118.val = 0x0
360-
jpeg.REG_0x11c.val = 0x1
361-
362-
jpeg.MODE.val = 0x177
363-
jpeg.REG_0x1028.val = 0x400
364-
365-
jpeg.JPEG_IO_FLAGS.val = 0x3f
366-
jpeg.REG_0x0.val = 0x1
409+
jpeg.JPEG_IO_FLAGS = 0x3f
410+
jpeg.REG_0x0 = 0x1
367411
jpeg.REG_0x1004 = 0x1
368412

369413
# FIXME: we don't actually know when it's done

0 commit comments

Comments
 (0)