1e5c31af7Sopenharmony_ci# -*- coding: utf-8 -*-
2e5c31af7Sopenharmony_ci
3e5c31af7Sopenharmony_ci#-------------------------------------------------------------------------
4e5c31af7Sopenharmony_ci#
5e5c31af7Sopenharmony_ci# Copyright (C) 2023 The Khronos Group Inc
6e5c31af7Sopenharmony_ci#
7e5c31af7Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
8e5c31af7Sopenharmony_ci# you may not use this file except in compliance with the License.
9e5c31af7Sopenharmony_ci# You may obtain a copy of the License at
10e5c31af7Sopenharmony_ci#
11e5c31af7Sopenharmony_ci#      http://www.apache.org/licenses/LICENSE-2.0
12e5c31af7Sopenharmony_ci#
13e5c31af7Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
14e5c31af7Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
15e5c31af7Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16e5c31af7Sopenharmony_ci# See the License for the specific language governing permissions and
17e5c31af7Sopenharmony_ci# limitations under the License.
18e5c31af7Sopenharmony_ci#
19e5c31af7Sopenharmony_ci#-------------------------------------------------------------------------
20e5c31af7Sopenharmony_ci#
21e5c31af7Sopenharmony_ci# Generate checksums from a sequence of YV12 YUV frames as produced by
22e5c31af7Sopenharmony_ci# the Fraunhofer reference decoders.
23e5c31af7Sopenharmony_ci#
24e5c31af7Sopenharmony_ci#  The reference checksums were generated using the Fluster testing
25e5c31af7Sopenharmony_ci#  framework (git@github.com:fluendo/fluster.git @
26e5c31af7Sopenharmony_ci#  fd2a3aec596ba5437b4c3364111938531a4b5f92) to build the Fraunhofer
27e5c31af7Sopenharmony_ci#  reference decoders,
28e5c31af7Sopenharmony_ci#
29e5c31af7Sopenharmony_ci#  ~/src/fluster $ make h26[45]_reference_decoder
30e5c31af7Sopenharmony_ci#
31e5c31af7Sopenharmony_ci#  Then, to generate references for H.264 test content,
32e5c31af7Sopenharmony_ci#
33e5c31af7Sopenharmony_ci#  $ cd ~/src/vk-gl-cts/external/vulkancts/data/vulkan/video/
34e5c31af7Sopenharmony_ci#  $ ~/src/fluster/contrib/JM/bin/umake/gcc-12.2/x86_64/release/ldecod -s -i clip-a.h264 -o clip-a.out
35e5c31af7Sopenharmony_ci#  $ python frame_checksums.py  clip-a.out  176 144 ; rm clip-a.out
36e5c31af7Sopenharmony_ci#
37e5c31af7Sopenharmony_ci#  To generate the H.265 YUV files, change the reference decoder line above to,
38e5c31af7Sopenharmony_ci#
39e5c31af7Sopenharmony_ci#  $ ~/src/fluster/contrib/HM/bin/umake/gcc-12.2/x86_64/release/TAppDecoder -b jellyfish-250-mbps-4k-uhd-GOB-IPB13.h265 -o jellyfish265.out
40e5c31af7Sopenharmony_ci#
41e5c31af7Sopenharmony_ci#  The h264_resolution_change example was specially handled, since
42e5c31af7Sopenharmony_ci#  it's actually a non-conformant bitstream according to the reference
43e5c31af7Sopenharmony_ci#  decoders. There are two streams of different resolution
44e5c31af7Sopenharmony_ci#  concatenated together in the test vector. They were manually cut
45e5c31af7Sopenharmony_ci#  out and each independent stream was passed through the above
46e5c31af7Sopenharmony_ci#  process to generate the checksums.
47e5c31af7Sopenharmony_ci#
48e5c31af7Sopenharmony_ci
49e5c31af7Sopenharmony_ciimport os
50e5c31af7Sopenharmony_ciimport sys
51e5c31af7Sopenharmony_ciimport hashlib
52e5c31af7Sopenharmony_ci
53e5c31af7Sopenharmony_ciif len(sys.argv) != 4:
54e5c31af7Sopenharmony_ci	print("Usage: yuv2rgb-cv.py yuvFile width height")
55e5c31af7Sopenharmony_ci	sys.exit(1)
56e5c31af7Sopenharmony_ci
57e5c31af7Sopenharmony_ciyuv_filename = sys.argv[1]
58e5c31af7Sopenharmony_ciwidth = int(sys.argv[2])
59e5c31af7Sopenharmony_ciheight = int(sys.argv[3])
60e5c31af7Sopenharmony_ci
61e5c31af7Sopenharmony_cidef checksum(bs: bytes) -> str:
62e5c31af7Sopenharmony_ci	md5 = hashlib.md5()
63e5c31af7Sopenharmony_ci	md5.update(bs)
64e5c31af7Sopenharmony_ci	return md5.hexdigest()
65e5c31af7Sopenharmony_ci
66e5c31af7Sopenharmony_cifile_size = os.path.getsize(yuv_filename)
67e5c31af7Sopenharmony_ci
68e5c31af7Sopenharmony_ci# This assumes the YCrCb format is YV12, as produced by the Fraunhofer
69e5c31af7Sopenharmony_ci# reference decoders.
70e5c31af7Sopenharmony_ciframe_size = int(width * height * 1.5)
71e5c31af7Sopenharmony_cin_frames = file_size // frame_size
72e5c31af7Sopenharmony_ci
73e5c31af7Sopenharmony_ciwith open(yuv_filename, 'rb') as f:
74e5c31af7Sopenharmony_ci	print("Computing checksums for ", n_frames, " frames")
75e5c31af7Sopenharmony_ci	for frame in range(n_frames):
76e5c31af7Sopenharmony_ci		print(checksum(f.read(frame_size)))
77