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