From 0090434e53ddc1e0a5eceb0ab0b1732b27ddc168 Mon Sep 17 00:00:00 2001 From: "mikhal@webrtc.org" Date: Tue, 27 Dec 2011 23:22:44 +0000 Subject: [PATCH] libyuv: Moving video_common to the include directory and updating rgb convert orientation. Review URL: http://webrtc-codereview.appspot.com/333022 git-svn-id: http://libyuv.googlecode.com/svn/trunk@120 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- include/libyuv/video_common.h | 96 +++++++++++++++++++++++++++++++++++ libyuv.gyp | 2 +- source/convert.cc | 18 +++---- source/convertfrom.cc | 2 +- source/format_conversion.cc | 2 +- source/video_common.cc | 2 +- source/video_common.h | 96 ----------------------------------- 7 files changed, 108 insertions(+), 110 deletions(-) create mode 100644 include/libyuv/video_common.h diff --git a/include/libyuv/video_common.h b/include/libyuv/video_common.h new file mode 100644 index 000000000..d66f1a5b3 --- /dev/null +++ b/include/libyuv/video_common.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 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. + */ + +/* +* Common definitions for video, including fourcc and VideoFormat +*/ + + +#ifndef LIBYUV_SOURCE_VIDEO_COMMON_H_ +#define LIBYUV_SOURCE_VIDEO_COMMON_H_ + +#include + +#include "libyuv/basic_types.h" + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +////////////////////////////////////////////////////////////////////////////// +// Definition of fourcc. +////////////////////////////////////////////////////////////////////////////// +// Convert four characters to a fourcc code. +// Needs to be a macro otherwise the OS X compiler complains when the kFormat* +// constants are used in a switch. +#define FOURCC(a, b, c, d) (\ + (static_cast(a)) | (static_cast(b) << 8) | \ + (static_cast(c) << 16) | (static_cast(d) << 24)) + +// Some good pages discussing FourCC codes: +// http://developer.apple.com/quicktime/icefloe/dispatch020.html +// http://www.fourcc.org/yuv.php +enum FourCC { + // Canonical fourcc codes used in our code. + FOURCC_I420 = FOURCC('I', '4', '2', '0'), + FOURCC_I422 = FOURCC('I', '4', '2', '2'), + FOURCC_I444 = FOURCC('I', '4', '4', '4'), + FOURCC_I400 = FOURCC('I', '4', '0', '0'), + FOURCC_YV12 = FOURCC('Y', 'V', '1', '2'), + FOURCC_YV16 = FOURCC('Y', 'V', '1', '6'), + FOURCC_YV24 = FOURCC('Y', 'V', '2', '4'), + FOURCC_YUY2 = FOURCC('Y', 'U', 'Y', '2'), + FOURCC_UYVY = FOURCC('U', 'Y', 'V', 'Y'), + FOURCC_M420 = FOURCC('M', '4', '2', '0'), + FOURCC_Q420 = FOURCC('Q', '4', '2', '0'), + FOURCC_24BG = FOURCC('2', '4', 'B', 'G'), + FOURCC_ABGR = FOURCC('A', 'B', 'G', 'R'), + FOURCC_BGRA = FOURCC('B', 'G', 'R', 'A'), + FOURCC_ARGB = FOURCC('A', 'R', 'G', 'B'), + FOURCC_MJPG = FOURCC('M', 'J', 'P', 'G'), + FOURCC_RAW = FOURCC('r', 'a', 'w', ' '), + FOURCC_NV21 = FOURCC('N', 'V', '2', '1'), + FOURCC_NV12 = FOURCC('N', 'V', '1', '2'), + // Next four are Bayer RGB formats. The four characters define the order of + // the colours in each 2x2 pixel grid, going left-to-right and top-to-bottom. + FOURCC_RGGB = FOURCC('R', 'G', 'G', 'B'), + FOURCC_BGGR = FOURCC('B', 'G', 'G', 'R'), + FOURCC_GRBG = FOURCC('G', 'R', 'B', 'G'), + FOURCC_GBRG = FOURCC('G', 'B', 'R', 'G'), + + // Aliases for canonical fourcc codes, replaced with their canonical + // equivalents by CanonicalFourCC(). + FOURCC_IYUV = FOURCC('I', 'Y', 'U', 'V'), // Alias for I420 + FOURCC_YU12 = FOURCC('Y', 'U', '1', '2'), // Alias for I420 + FOURCC_YU16 = FOURCC('Y', 'U', '1', '6'), // Alias for I422 + FOURCC_YU24 = FOURCC('Y', 'U', '2', '4'), // Alias for I444 + FOURCC_YUYV = FOURCC('Y', 'U', 'Y', 'V'), // Alias for YUY2 + FOURCC_YUVS = FOURCC('y', 'u', 'v', 's'), // Alias for YUY2 on Mac + FOURCC_HDYC = FOURCC('H', 'D', 'Y', 'C'), // Alias for UYVY + FOURCC_2VUY = FOURCC('2', 'v', 'u', 'y'), // Alias for UYVY + FOURCC_JPEG = FOURCC('J', 'P', 'E', 'G'), // Alias for MJPG + FOURCC_BA81 = FOURCC('B', 'A', '8', '1'), // Alias for BGGR + FOURCC_RGB3 = FOURCC('R', 'G', 'B', '3'), // Alias for RAW + FOURCC_BGR3 = FOURCC('B', 'G', 'R', '3'), // Alias for 24BG + + // Match any fourcc. + FOURCC_ANY = 0xFFFFFFFF, +}; + +// Converts fourcc aliases into canonical ones. +uint32 CanonicalFourCC(uint32 fourcc); + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // LIBYUV_SOURCE_VIDEO_COMMON_H_ diff --git a/libyuv.gyp b/libyuv.gyp index d8ab98b38..86468b1b6 100644 --- a/libyuv.gyp +++ b/libyuv.gyp @@ -27,12 +27,12 @@ 'include/libyuv/convert.h', 'include/libyuv/scale.h', 'include/libyuv/planar_functions.h', + 'include/video_common.h', # headers 'source/conversion_tables.h', 'source/rotate_priv.h', 'source/row.h', - 'source/video_common.h', # sources 'source/compare.cc', diff --git a/source/convert.cc b/source/convert.cc index 4478a7f22..d9b39d8da 100644 --- a/source/convert.cc +++ b/source/convert.cc @@ -23,7 +23,7 @@ #include "libyuv/planar_functions.h" #include "libyuv/rotate.h" #include "row.h" -#include "video_common.h" +#include "libyuv/video_common.h" #ifdef __cplusplus namespace libyuv { @@ -48,11 +48,9 @@ int I420ToRGB24(const uint8* src_y, int src_stride_y, if (src_y == NULL || src_u == NULL || src_v == NULL || dst_frame == NULL) { return -1; } - - // RGB orientation - bottom up // TODO(fbarchard): support inversion - uint8* out = dst_frame + dst_stride_frame * height - dst_stride_frame; - uint8* out2 = out - dst_stride_frame; + uint8* out = dst_frame; + uint8* out2 = out + dst_stride_frame; int h, w; int tmp_r, tmp_g, tmp_b; const uint8 *y1, *y2 ,*u, *v; @@ -99,13 +97,13 @@ int I420ToRGB24(const uint8* src_y, int src_stride_y, u++; v++; } - y1 += src_stride_y + src_stride_y - width; - y2 += src_stride_y + src_stride_y - width; + y1 += 2 * src_stride_y - width; + y2 += 2 * src_stride_y - width; u += src_stride_u - ((width + 1) >> 1); v += src_stride_v - ((width + 1) >> 1); - out -= dst_stride_frame * 3; - out2 -= dst_stride_frame * 3; - } // end height for + out += dst_stride_frame; + out2 += dst_stride_frame; + } return 0; } diff --git a/source/convertfrom.cc b/source/convertfrom.cc index 930b7d7d0..b4a51e957 100644 --- a/source/convertfrom.cc +++ b/source/convertfrom.cc @@ -13,7 +13,7 @@ #include "libyuv/basic_types.h" #include "libyuv/format_conversion.h" #include "libyuv/planar_functions.h" -#include "video_common.h" +#include "libyuv/video_common.h" #ifdef __cplusplus namespace libyuv { diff --git a/source/format_conversion.cc b/source/format_conversion.cc index ebc20ac43..d8ab5a556 100644 --- a/source/format_conversion.cc +++ b/source/format_conversion.cc @@ -13,7 +13,7 @@ #include "libyuv/basic_types.h" #include "libyuv/cpu_id.h" #include "row.h" -#include "video_common.h" +#include "libyuv/video_common.h" #ifdef __cplusplus namespace libyuv { diff --git a/source/video_common.cc b/source/video_common.cc index 63e2e0abb..be25359d7 100644 --- a/source/video_common.cc +++ b/source/video_common.cc @@ -9,7 +9,7 @@ */ -#include "video_common.h" +#include "libyuv/video_common.h" #include diff --git a/source/video_common.h b/source/video_common.h index d66f1a5b3..e69de29bb 100644 --- a/source/video_common.h +++ b/source/video_common.h @@ -1,96 +0,0 @@ -/* - * Copyright (c) 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. - */ - -/* -* Common definitions for video, including fourcc and VideoFormat -*/ - - -#ifndef LIBYUV_SOURCE_VIDEO_COMMON_H_ -#define LIBYUV_SOURCE_VIDEO_COMMON_H_ - -#include - -#include "libyuv/basic_types.h" - -#ifdef __cplusplus -namespace libyuv { -extern "C" { -#endif - -////////////////////////////////////////////////////////////////////////////// -// Definition of fourcc. -////////////////////////////////////////////////////////////////////////////// -// Convert four characters to a fourcc code. -// Needs to be a macro otherwise the OS X compiler complains when the kFormat* -// constants are used in a switch. -#define FOURCC(a, b, c, d) (\ - (static_cast(a)) | (static_cast(b) << 8) | \ - (static_cast(c) << 16) | (static_cast(d) << 24)) - -// Some good pages discussing FourCC codes: -// http://developer.apple.com/quicktime/icefloe/dispatch020.html -// http://www.fourcc.org/yuv.php -enum FourCC { - // Canonical fourcc codes used in our code. - FOURCC_I420 = FOURCC('I', '4', '2', '0'), - FOURCC_I422 = FOURCC('I', '4', '2', '2'), - FOURCC_I444 = FOURCC('I', '4', '4', '4'), - FOURCC_I400 = FOURCC('I', '4', '0', '0'), - FOURCC_YV12 = FOURCC('Y', 'V', '1', '2'), - FOURCC_YV16 = FOURCC('Y', 'V', '1', '6'), - FOURCC_YV24 = FOURCC('Y', 'V', '2', '4'), - FOURCC_YUY2 = FOURCC('Y', 'U', 'Y', '2'), - FOURCC_UYVY = FOURCC('U', 'Y', 'V', 'Y'), - FOURCC_M420 = FOURCC('M', '4', '2', '0'), - FOURCC_Q420 = FOURCC('Q', '4', '2', '0'), - FOURCC_24BG = FOURCC('2', '4', 'B', 'G'), - FOURCC_ABGR = FOURCC('A', 'B', 'G', 'R'), - FOURCC_BGRA = FOURCC('B', 'G', 'R', 'A'), - FOURCC_ARGB = FOURCC('A', 'R', 'G', 'B'), - FOURCC_MJPG = FOURCC('M', 'J', 'P', 'G'), - FOURCC_RAW = FOURCC('r', 'a', 'w', ' '), - FOURCC_NV21 = FOURCC('N', 'V', '2', '1'), - FOURCC_NV12 = FOURCC('N', 'V', '1', '2'), - // Next four are Bayer RGB formats. The four characters define the order of - // the colours in each 2x2 pixel grid, going left-to-right and top-to-bottom. - FOURCC_RGGB = FOURCC('R', 'G', 'G', 'B'), - FOURCC_BGGR = FOURCC('B', 'G', 'G', 'R'), - FOURCC_GRBG = FOURCC('G', 'R', 'B', 'G'), - FOURCC_GBRG = FOURCC('G', 'B', 'R', 'G'), - - // Aliases for canonical fourcc codes, replaced with their canonical - // equivalents by CanonicalFourCC(). - FOURCC_IYUV = FOURCC('I', 'Y', 'U', 'V'), // Alias for I420 - FOURCC_YU12 = FOURCC('Y', 'U', '1', '2'), // Alias for I420 - FOURCC_YU16 = FOURCC('Y', 'U', '1', '6'), // Alias for I422 - FOURCC_YU24 = FOURCC('Y', 'U', '2', '4'), // Alias for I444 - FOURCC_YUYV = FOURCC('Y', 'U', 'Y', 'V'), // Alias for YUY2 - FOURCC_YUVS = FOURCC('y', 'u', 'v', 's'), // Alias for YUY2 on Mac - FOURCC_HDYC = FOURCC('H', 'D', 'Y', 'C'), // Alias for UYVY - FOURCC_2VUY = FOURCC('2', 'v', 'u', 'y'), // Alias for UYVY - FOURCC_JPEG = FOURCC('J', 'P', 'E', 'G'), // Alias for MJPG - FOURCC_BA81 = FOURCC('B', 'A', '8', '1'), // Alias for BGGR - FOURCC_RGB3 = FOURCC('R', 'G', 'B', '3'), // Alias for RAW - FOURCC_BGR3 = FOURCC('B', 'G', 'R', '3'), // Alias for 24BG - - // Match any fourcc. - FOURCC_ANY = 0xFFFFFFFF, -}; - -// Converts fourcc aliases into canonical ones. -uint32 CanonicalFourCC(uint32 fourcc); - -#ifdef __cplusplus -} // extern "C" -} // namespace libyuv -#endif - -#endif // LIBYUV_SOURCE_VIDEO_COMMON_H_