1 /*
2 * Copyright 2011 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 "libyuv/video_common.h"
12
13 #ifdef __cplusplus
14 namespace libyuv {
15 extern "C" {
16 #endif
17
18 struct FourCCAliasEntry {
19 uint32_t alias;
20 uint32_t canonical;
21 };
22
23 #define NUM_ALIASES 18
24 static const struct FourCCAliasEntry kFourCCAliases[NUM_ALIASES] = {
25 {FOURCC_IYUV, FOURCC_I420},
26 {FOURCC_YU12, FOURCC_I420},
27 {FOURCC_YU16, FOURCC_I422},
28 {FOURCC_YU24, FOURCC_I444},
29 {FOURCC_YUYV, FOURCC_YUY2},
30 {FOURCC_YUVS, FOURCC_YUY2}, // kCMPixelFormat_422YpCbCr8_yuvs
31 {FOURCC_HDYC, FOURCC_UYVY},
32 {FOURCC_2VUY, FOURCC_UYVY}, // kCMPixelFormat_422YpCbCr8
33 {FOURCC_JPEG, FOURCC_MJPG}, // Note: JPEG has DHT while MJPG does not.
34 {FOURCC_DMB1, FOURCC_MJPG},
35 {FOURCC_BA81, FOURCC_BGGR}, // deprecated.
36 {FOURCC_RGB3, FOURCC_RAW},
37 {FOURCC_BGR3, FOURCC_24BG},
38 {FOURCC_CM32, FOURCC_BGRA}, // kCMPixelFormat_32ARGB
39 {FOURCC_CM24, FOURCC_RAW}, // kCMPixelFormat_24RGB
40 {FOURCC_L555, FOURCC_RGBO}, // kCMPixelFormat_16LE555
41 {FOURCC_L565, FOURCC_RGBP}, // kCMPixelFormat_16LE565
42 {FOURCC_5551, FOURCC_RGBO}, // kCMPixelFormat_16LE5551
43 };
44 // TODO(fbarchard): Consider mapping kCMPixelFormat_32BGRA to FOURCC_ARGB.
45 // {FOURCC_BGRA, FOURCC_ARGB}, // kCMPixelFormat_32BGRA
46
47 LIBYUV_API
CanonicalFourCC(uint32_t fourcc)48 uint32_t CanonicalFourCC(uint32_t fourcc) {
49 int i;
50 for (i = 0; i < NUM_ALIASES; ++i) {
51 if (kFourCCAliases[i].alias == fourcc) {
52 return kFourCCAliases[i].canonical;
53 }
54 }
55 // Not an alias, so return it as-is.
56 return fourcc;
57 }
58
59 #ifdef __cplusplus
60 } // extern "C"
61 } // namespace libyuv
62 #endif
63