1/*
2 *  Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS. All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <stdlib.h>
12#include <string.h>
13
14#include "libyuv/video_common.h"
15#include "../unit_test/unit_test.h"
16
17namespace libyuv {
18
19// Tests FourCC codes in video common, which are used for ConvertToI420().
20
21static bool TestValidChar(uint32 onecc) {
22  if ((onecc >= '0' && onecc <= '9') ||
23      (onecc >= 'A' && onecc <= 'Z') ||
24      (onecc >= 'a' && onecc <= 'z') ||
25      (onecc == ' ') || (onecc == 0xff)) {
26    return true;
27  }
28  return false;
29}
30
31static bool TestValidFourCC(uint32 fourcc, int bpp) {
32  if (!TestValidChar(fourcc & 0xff) ||
33      !TestValidChar((fourcc >> 8) & 0xff) ||
34      !TestValidChar((fourcc >> 16) & 0xff) ||
35      !TestValidChar((fourcc >> 24) & 0xff)) {
36    return false;
37  }
38  if (bpp < 0 || bpp > 32) {
39    return false;
40  }
41  return true;
42}
43
44TEST_F(LibYUVBaseTest, TestCanonicalFourCC) {
45  EXPECT_EQ(FOURCC_I420, CanonicalFourCC(FOURCC_IYUV));
46  EXPECT_EQ(FOURCC_I420, CanonicalFourCC(FOURCC_YU12));
47  EXPECT_EQ(FOURCC_I422, CanonicalFourCC(FOURCC_YU16));
48  EXPECT_EQ(FOURCC_I444, CanonicalFourCC(FOURCC_YU24));
49  EXPECT_EQ(FOURCC_YUY2, CanonicalFourCC(FOURCC_YUYV));
50  EXPECT_EQ(FOURCC_YUY2, CanonicalFourCC(FOURCC_YUVS));
51  EXPECT_EQ(FOURCC_UYVY, CanonicalFourCC(FOURCC_HDYC));
52  EXPECT_EQ(FOURCC_UYVY, CanonicalFourCC(FOURCC_2VUY));
53  EXPECT_EQ(FOURCC_MJPG, CanonicalFourCC(FOURCC_JPEG));
54  EXPECT_EQ(FOURCC_MJPG, CanonicalFourCC(FOURCC_DMB1));
55  EXPECT_EQ(FOURCC_RAW,  CanonicalFourCC(FOURCC_RGB3));
56  EXPECT_EQ(FOURCC_24BG, CanonicalFourCC(FOURCC_BGR3));
57  EXPECT_EQ(FOURCC_BGRA, CanonicalFourCC(FOURCC_CM32));
58  EXPECT_EQ(FOURCC_RAW,  CanonicalFourCC(FOURCC_CM24));
59  EXPECT_EQ(FOURCC_RGBO, CanonicalFourCC(FOURCC_L555));
60  EXPECT_EQ(FOURCC_RGBP, CanonicalFourCC(FOURCC_L565));
61  EXPECT_EQ(FOURCC_RGBO, CanonicalFourCC(FOURCC_5551));
62}
63
64TEST_F(LibYUVBaseTest, TestFourCC) {
65  EXPECT_TRUE(TestValidFourCC(FOURCC_I420, FOURCC_BPP_I420));
66  EXPECT_TRUE(TestValidFourCC(FOURCC_I420, FOURCC_BPP_I420));
67  EXPECT_TRUE(TestValidFourCC(FOURCC_I422, FOURCC_BPP_I422));
68  EXPECT_TRUE(TestValidFourCC(FOURCC_I444, FOURCC_BPP_I444));
69  EXPECT_TRUE(TestValidFourCC(FOURCC_I411, FOURCC_BPP_I411));
70  EXPECT_TRUE(TestValidFourCC(FOURCC_I400, FOURCC_BPP_I400));
71  EXPECT_TRUE(TestValidFourCC(FOURCC_NV21, FOURCC_BPP_NV21));
72  EXPECT_TRUE(TestValidFourCC(FOURCC_NV12, FOURCC_BPP_NV12));
73  EXPECT_TRUE(TestValidFourCC(FOURCC_YUY2, FOURCC_BPP_YUY2));
74  EXPECT_TRUE(TestValidFourCC(FOURCC_UYVY, FOURCC_BPP_UYVY));
75  EXPECT_TRUE(TestValidFourCC(FOURCC_M420, FOURCC_BPP_M420));
76  EXPECT_TRUE(TestValidFourCC(FOURCC_Q420, FOURCC_BPP_Q420));  // deprecated.
77  EXPECT_TRUE(TestValidFourCC(FOURCC_ARGB, FOURCC_BPP_ARGB));
78  EXPECT_TRUE(TestValidFourCC(FOURCC_BGRA, FOURCC_BPP_BGRA));
79  EXPECT_TRUE(TestValidFourCC(FOURCC_ABGR, FOURCC_BPP_ABGR));
80  EXPECT_TRUE(TestValidFourCC(FOURCC_24BG, FOURCC_BPP_24BG));
81  EXPECT_TRUE(TestValidFourCC(FOURCC_RAW,  FOURCC_BPP_RAW));
82  EXPECT_TRUE(TestValidFourCC(FOURCC_RGBA, FOURCC_BPP_RGBA));
83  EXPECT_TRUE(TestValidFourCC(FOURCC_RGBP, FOURCC_BPP_RGBP));
84  EXPECT_TRUE(TestValidFourCC(FOURCC_RGBO, FOURCC_BPP_RGBO));
85  EXPECT_TRUE(TestValidFourCC(FOURCC_R444, FOURCC_BPP_R444));
86  EXPECT_TRUE(TestValidFourCC(FOURCC_MJPG, FOURCC_BPP_MJPG));
87  EXPECT_TRUE(TestValidFourCC(FOURCC_YV12, FOURCC_BPP_YV12));
88  EXPECT_TRUE(TestValidFourCC(FOURCC_YV16, FOURCC_BPP_YV16));
89  EXPECT_TRUE(TestValidFourCC(FOURCC_YV24, FOURCC_BPP_YV24));
90  EXPECT_TRUE(TestValidFourCC(FOURCC_YU12, FOURCC_BPP_YU12));
91  EXPECT_TRUE(TestValidFourCC(FOURCC_IYUV, FOURCC_BPP_IYUV));
92  EXPECT_TRUE(TestValidFourCC(FOURCC_YU16, FOURCC_BPP_YU16));
93  EXPECT_TRUE(TestValidFourCC(FOURCC_YU24, FOURCC_BPP_YU24));
94  EXPECT_TRUE(TestValidFourCC(FOURCC_YUYV, FOURCC_BPP_YUYV));
95  EXPECT_TRUE(TestValidFourCC(FOURCC_YUVS, FOURCC_BPP_YUVS));
96  EXPECT_TRUE(TestValidFourCC(FOURCC_HDYC, FOURCC_BPP_HDYC));
97  EXPECT_TRUE(TestValidFourCC(FOURCC_2VUY, FOURCC_BPP_2VUY));
98  EXPECT_TRUE(TestValidFourCC(FOURCC_JPEG, FOURCC_BPP_JPEG));
99  EXPECT_TRUE(TestValidFourCC(FOURCC_DMB1, FOURCC_BPP_DMB1));
100  EXPECT_TRUE(TestValidFourCC(FOURCC_BA81, FOURCC_BPP_BA81));
101  EXPECT_TRUE(TestValidFourCC(FOURCC_RGB3, FOURCC_BPP_RGB3));
102  EXPECT_TRUE(TestValidFourCC(FOURCC_BGR3, FOURCC_BPP_BGR3));
103  EXPECT_TRUE(TestValidFourCC(FOURCC_H264, FOURCC_BPP_H264));
104  EXPECT_TRUE(TestValidFourCC(FOURCC_ANY,  FOURCC_BPP_ANY));
105}
106
107}  // namespace libyuv
108