media/libyuv/source/video_common.cc
author Randell Jesup <rjesup@jesup.org>
Thu, 30 Jan 2014 19:55:04 -0500
changeset 166823 f9315e1a38447e5f62ed9ff64470397252fcbc1f
parent 166820 media/webrtc/trunk/third_party/libyuv/source/video_common.cc@aaf73bfa3900c3d7d9577fb5b2474e005d251ffd
child 304758 92c15211f59b03279452759986e8b896a2a1a42f
permissions -rw-r--r--
Bug 813645 - Move libyuv to media/libyuv r=glandium

/*
 *  Copyright 2011 The LibYuv Project Authors. All rights reserved.
 *
 *  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
 *  in the file PATENTS. All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */


#include "libyuv/video_common.h"

#ifdef __cplusplus
namespace libyuv {
extern "C" {
#endif

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

struct FourCCAliasEntry {
  uint32 alias;
  uint32 canonical;
};

static const struct FourCCAliasEntry kFourCCAliases[] = {
  {FOURCC_IYUV, FOURCC_I420},
  {FOURCC_YU16, FOURCC_I422},
  {FOURCC_YU24, FOURCC_I444},
  {FOURCC_YUYV, FOURCC_YUY2},
  {FOURCC_YUVS, FOURCC_YUY2},  // kCMPixelFormat_422YpCbCr8_yuvs
  {FOURCC_HDYC, FOURCC_UYVY},
  {FOURCC_2VUY, FOURCC_UYVY},  // kCMPixelFormat_422YpCbCr8
  {FOURCC_JPEG, FOURCC_MJPG},  // Note: JPEG has DHT while MJPG does not.
  {FOURCC_DMB1, FOURCC_MJPG},
  {FOURCC_BA81, FOURCC_BGGR},
  {FOURCC_RGB3, FOURCC_RAW },
  {FOURCC_BGR3, FOURCC_24BG},
  {FOURCC_CM32, FOURCC_BGRA},  // kCMPixelFormat_32ARGB
  {FOURCC_CM24, FOURCC_RAW },  // kCMPixelFormat_24RGB
  {FOURCC_L555, FOURCC_RGBO},  // kCMPixelFormat_16LE555
  {FOURCC_L565, FOURCC_RGBP},  // kCMPixelFormat_16LE565
  {FOURCC_5551, FOURCC_RGBO},  // kCMPixelFormat_16LE5551
};
// TODO(fbarchard): Consider mapping kCMPixelFormat_32BGRA to FOURCC_ARGB.
//  {FOURCC_BGRA, FOURCC_ARGB},  // kCMPixelFormat_32BGRA

LIBYUV_API
uint32 CanonicalFourCC(uint32 fourcc) {
  int i;
  for (i = 0; i < ARRAY_SIZE(kFourCCAliases); ++i) {
    if (kFourCCAliases[i].alias == fourcc) {
      return kFourCCAliases[i].canonical;
    }
  }
  // Not an alias, so return it as-is.
  return fourcc;
}

#ifdef __cplusplus
}  // extern "C"
}  // namespace libyuv
#endif