video_common.cc 1.86 KB
Newer Older
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1
/*
2
 *  Copyright 2011 The LibYuv Project Authors. All rights reserved.
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
3 4 5 6
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS. All contributing project authors may
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
8 9 10 11
 *  be found in the AUTHORS file in the root of the source tree.
 */


12
#include "libyuv/video_common.h"
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
13

14
#ifdef __cplusplus
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
15
namespace libyuv {
16 17
extern "C" {
#endif
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
18

19
#define ARRAY_SIZE(x) (int)(sizeof(x) / sizeof(x[0]))
20

mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
21 22 23 24 25
struct FourCCAliasEntry {
  uint32 alias;
  uint32 canonical;
};

26
static const struct FourCCAliasEntry kFourCCAliases[] = {
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
27
  {FOURCC_IYUV, FOURCC_I420},
28 29
  {FOURCC_YU16, FOURCC_I422},
  {FOURCC_YU24, FOURCC_I444},
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
30
  {FOURCC_YUYV, FOURCC_YUY2},
31
  {FOURCC_YUVS, FOURCC_YUY2},  // kCMPixelFormat_422YpCbCr8_yuvs
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
32
  {FOURCC_HDYC, FOURCC_UYVY},
33
  {FOURCC_2VUY, FOURCC_UYVY},  // kCMPixelFormat_422YpCbCr8
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
34
  {FOURCC_JPEG, FOURCC_MJPG},  // Note: JPEG has DHT while MJPG does not.
35 36
  {FOURCC_DMB1, FOURCC_MJPG},
  {FOURCC_BA81, FOURCC_BGGR},
37
  {FOURCC_RGB3, FOURCC_RAW },
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
38
  {FOURCC_BGR3, FOURCC_24BG},
39 40
  {FOURCC_CM32, FOURCC_BGRA},  // kCMPixelFormat_32ARGB
  {FOURCC_CM24, FOURCC_RAW },  // kCMPixelFormat_24RGB
41 42 43
  {FOURCC_L555, FOURCC_RGBO},  // kCMPixelFormat_16LE555
  {FOURCC_L565, FOURCC_RGBP},  // kCMPixelFormat_16LE565
  {FOURCC_5551, FOURCC_RGBO},  // kCMPixelFormat_16LE5551
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
44
};
45 46
// TODO(fbarchard): Consider mapping kCMPixelFormat_32BGRA to FOURCC_ARGB.
//  {FOURCC_BGRA, FOURCC_ARGB},  // kCMPixelFormat_32BGRA
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
47

48
LIBYUV_API
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
49
uint32 CanonicalFourCC(uint32 fourcc) {
50 51
  int i;
  for (i = 0; i < ARRAY_SIZE(kFourCCAliases); ++i) {
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
52 53 54 55 56 57 58 59
    if (kFourCCAliases[i].alias == fourcc) {
      return kFourCCAliases[i].canonical;
    }
  }
  // Not an alias, so return it as-is.
  return fourcc;
}

60 61
#ifdef __cplusplus
}  // extern "C"
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
62
}  // namespace libyuv
63 64
#endif