1# Copyright 2015 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import its.image
16import sys
17
18def main():
19    """Open a YUV420 file and save it as a JPEG.
20
21    Command line args:
22        filename.yuv: The YUV420 file to open.
23        w: The width of the image.
24        h: The height of the image.
25        layout: The layout of the data, in ["planar", "nv21"].
26    """
27    if len(sys.argv) != 5:
28        print "Usage: python %s <filename.yuv> <w> <h> <layout>"%(sys.argv[0])
29    else:
30        fname, w,h = sys.argv[1], int(sys.argv[2]), int(sys.argv[3])
31        layout = sys.argv[4]
32        img = its.image.load_yuv420_to_rgb_image(fname, w,h, layout=layout)
33        its.image.write_image(img, fname.replace(".yuv",".jpg"), False)
34
35if __name__ == '__main__':
36    main()
37
38