git-svn-id: http://webrtc.googlecode.com/svn/trunk@160 4adac7df-926f-26a2-2b94-8c16560cd09d

This commit is contained in:
niklase@google.com 2011-07-07 08:26:13 +00:00
parent 2b774c73e2
commit d784e5535c
26 changed files with 0 additions and 8517 deletions

View File

@ -1,4 +0,0 @@
holmer@google.com
mikhal@google.com
marpan@google.com
hlundin@google.com

View File

@ -1,75 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
#ifndef COMMON_VIDEO_INTERFACE_VIDEO_IMAGE_H
#define COMMON_VIDEO_INTERFACE_VIDEO_IMAGE_H
#include "typedefs.h"
#include <stdlib.h>
namespace webrtc
{
enum VideoFrameType
{
kKeyFrame = 0,
kDeltaFrame = 1,
kGoldenFrame = 2,
kAltRefFrame = 3,
kSkipFrame = 4
};
class RawImage
{
public:
RawImage() : _width(0), _height(0), _timeStamp(0), _buffer(NULL),
_length(0), _size(0) {}
RawImage(WebRtc_UWord8* buffer, WebRtc_UWord32 length,
WebRtc_UWord32 size) :
_width(0), _height(0), _timeStamp(0),
_buffer(buffer), _length(length), _size(size) {}
WebRtc_UWord32 _width;
WebRtc_UWord32 _height;
WebRtc_UWord32 _timeStamp;
WebRtc_UWord8* _buffer;
WebRtc_UWord32 _length;
WebRtc_UWord32 _size;
};
class EncodedImage
{
public:
EncodedImage() :
_encodedWidth(0), _encodedHeight(0), _timeStamp(0),
_frameType(kDeltaFrame), _buffer(NULL), _length(0),
_size(0), _completeFrame(false) {}
EncodedImage(WebRtc_UWord8* buffer,
WebRtc_UWord32 length,
WebRtc_UWord32 size) :
_encodedWidth(0), _encodedHeight(0), _timeStamp(0),
_frameType(kDeltaFrame), _buffer(buffer), _length(length),
_size(size), _completeFrame(false) {}
WebRtc_UWord32 _encodedWidth;
WebRtc_UWord32 _encodedHeight;
WebRtc_UWord32 _timeStamp;
VideoFrameType _frameType;
WebRtc_UWord8* _buffer;
WebRtc_UWord32 _length;
WebRtc_UWord32 _size;
bool _completeFrame;
};
} // namespace webrtc
#endif // COMMON_VIDEO_INTERFACE_VIDEO_IMAGE_H

View File

@ -1,84 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
/*
* JPEG wrapper
*/
#ifndef WEBRTC_COMMON_VIDEO_JPEG
#define WEBRTC_COMMON_VIDEO_JPEG
#include "typedefs.h"
#include "video_image.h"
// jpeg forward declaration
struct jpeg_compress_struct;
struct jpeg_decompress_struct;
namespace webrtc
{
class JpegEncoder
{
public:
JpegEncoder();
~JpegEncoder();
// SetFileName
// Input:
// - fileName - Pointer to input vector (should be less than 256) to which the
// compressed file will be written to
// Output:
// - 0 : OK
// - (-1) : Error
WebRtc_Word32 SetFileName(const WebRtc_Word8* fileName);
// Encode an I420 image. The encoded image is saved to a file
//
// Input:
// - inputImage : Image to be encoded
//
// Output:
// - 0 : OK
// - (-1) : Error
WebRtc_Word32 Encode(const RawImage& inputImage);
private:
jpeg_compress_struct* _cinfo;
WebRtc_Word8 _fileName[256];
};
class JpegDecoder
{
public:
JpegDecoder();
~JpegDecoder();
// Decodes a JPEG-stream
// Supports 1 image component. 3 interleaved image components,
// YCbCr sub-sampling 4:4:4, 4:2:2, 4:2:0.
//
// Input:
// - inputImage : encoded image to be decoded.
// - outputImage : RawImage to store decoded output
//
// Output:
// - 0 : OK
// - (-1) : Error
WebRtc_Word32 Decode(const EncodedImage& inputImage,
RawImage& outputImage);
private:
jpeg_decompress_struct* _cinfo;
};
}
#endif /* WEBRTC_COMMON_VIDEO_JPEG */

View File

@ -1,50 +0,0 @@
# Copyright (c) 2011 The WebRTC 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.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE := libwebrtc_jpeg
LOCAL_MODULE_TAGS := optional
LOCAL_CPP_EXTENSION := .cc
LOCAL_GENERATED_SOURCES :=
LOCAL_SRC_FILES := jpeg.cc \
data_manager.cc
# Flags passed to both C and C++ files.
MY_CFLAGS :=
MY_CFLAGS_C :=
MY_DEFS := '-DNO_TCMALLOC' \
'-DNO_HEAPCHECKER' \
'-DWEBRTC_ANDROID' \
'-DANDROID'
LOCAL_CFLAGS := $(MY_CFLAGS_C) $(MY_CFLAGS) $(MY_DEFS)
# Include paths placed before CFLAGS/CPPFLAGS
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../.. \
$(LOCAL_PATH)/../interface \
$(LOCAL_PATH)/../../../../../../ \
$(LOCAL_PATH)/../../../vplib/main/interface \
external/jpeg
# Flags passed to only C++ (and not C) files.
LOCAL_CPPFLAGS :=
LOCAL_LDFLAGS :=
LOCAL_STATIC_LIBRARIES :=
LOCAL_SHARED_LIBRARIES := libcutils \
libdl \
libstlport
LOCAL_ADDITIONAL_DEPENDENCIES :=
include external/stlport/libstlport.mk
include $(BUILD_STATIC_LIBRARY)

View File

@ -1,100 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
/*
* data_manager.cc
*/
#include "data_manager.h"
#ifdef WEBRTC_ANDROID
extern "C" {
#endif
#include "jpeglib.h"
#ifdef WEBRTC_ANDROID
}
#endif
#include "jmorecfg.h"
namespace webrtc
{
typedef struct
{
jpeg_source_mgr mgr;
JOCTET* next_input_byte;
size_t bytes_in_buffer; /* # of byte spaces remaining in buffer */
} DataSrcMgr;
void
jpegSetSrcBuffer(j_decompress_ptr cinfo, JOCTET* srcBuffer, size_t bufferSize)
{
DataSrcMgr* src;
if (cinfo->src == NULL)
{ /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
JPOOL_PERMANENT, sizeof(DataSrcMgr));
}
// Setting required functionality
src = (DataSrcMgr*) cinfo->src;
src->mgr.init_source = initSrc;;
src->mgr.fill_input_buffer = fillInputBuffer;
src->mgr.skip_input_data = skipInputData;
src->mgr.resync_to_restart = jpeg_resync_to_restart; // use default
src->mgr.term_source = termSource;
// setting buffer/src
src->bytes_in_buffer = bufferSize;
src->next_input_byte = srcBuffer;
}
void
initSrc(j_decompress_ptr cinfo)
{
DataSrcMgr *src = (DataSrcMgr*)cinfo->src;
src->mgr.next_input_byte = src->next_input_byte;
src->mgr.bytes_in_buffer = src->bytes_in_buffer;
}
boolean
fillInputBuffer(j_decompress_ptr cinfo)
{
return false;
}
void
skipInputData(j_decompress_ptr cinfo, long num_bytes)
{
DataSrcMgr* src = (DataSrcMgr*)cinfo->src;
if (num_bytes > 0)
{
if ((unsigned long)num_bytes > src->mgr.bytes_in_buffer)
src->mgr.bytes_in_buffer = 0;
else
{
src->mgr.next_input_byte += num_bytes;
src->mgr.bytes_in_buffer -= num_bytes;
}
}
}
void
termSource (j_decompress_ptr cinfo)
{
//
}
} // end of namespace webrtc

View File

@ -1,68 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
/*
* Jpeg source data manager
*/
#ifndef WEBRTC_COMMON_VIDEO_JPEG_DATA_MANAGER
#define WEBRTC_COMMON_VIDEO_JPEG_DATA_MANAGER
#include <stdio.h>
// jpeg forward declaration
struct jpeg_source_mgr;
typedef unsigned char JOCTET;
typedef int boolean;
typedef struct jpeg_decompress_struct* j_decompress_ptr;
typedef struct jpeg_compress_struct* j_compress_ptr;
namespace webrtc
{
// Source manager:
// a general function that will set these values
void
jpegSetSrcBuffer(j_decompress_ptr cinfo, JOCTET* srcBuffer, size_t bufferSize);
// Initialize source. This is called by jpeg_read_header() before any
// data is actually read.
void
initSrc(j_decompress_ptr cinfo);
// Fill input buffer
// This is called whenever bytes_in_buffer has reached zero and more
// data is wanted.
boolean
fillInputBuffer(j_decompress_ptr cinfo);
// Skip input data
// Skip num_bytes worth of data.
void
skipInputData(j_decompress_ptr cinfo, long num_bytes);
// Terminate source
void
termSource (j_decompress_ptr cinfo);
} // end of namespace webrtc
#endif /* WEBRTC_COMMON_VIDEO_JPEG_DATA_MANAGER */

View File

@ -1,362 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
/*
* jpeg.cc
*/
#include <stdio.h>
#include <string.h>
#include "vplib.h"
#include "jpeg.h"
#include "data_manager.h"
#if defined(WIN32)
#include <basetsd.h>
#endif
#ifdef WEBRTC_ANDROID
extern "C" {
#endif
#include "jpeglib.h"
#ifdef WEBRTC_ANDROID
}
#endif
#include <setjmp.h>
namespace webrtc
{
// Error handler
struct myErrorMgr {
struct jpeg_error_mgr pub;
jmp_buf setjmp_buffer;
};
typedef struct myErrorMgr * myErrorPtr;
METHODDEF(void)
MyErrorExit (j_common_ptr cinfo)
{
myErrorPtr myerr = (myErrorPtr) cinfo->err;
// Return control to the setjmp point
longjmp(myerr->setjmp_buffer, 1);
}
JpegEncoder::JpegEncoder()
{
_cinfo = new jpeg_compress_struct;
strcpy(_fileName, "Snapshot.jpg");
}
JpegEncoder::~JpegEncoder()
{
if (_cinfo != NULL)
{
delete _cinfo;
_cinfo = NULL;
}
}
WebRtc_Word32
JpegEncoder::SetFileName(const WebRtc_Word8* fileName)
{
if (!fileName)
{
return -1;
}
if (fileName)
{
strncpy(_fileName, fileName, 256);
}
return 0;
}
WebRtc_Word32
JpegEncoder::Encode(const RawImage& inputImage)
{
if (inputImage._buffer == NULL || inputImage._size == 0)
{
return -1;
}
if (inputImage._width < 1 || inputImage._height < 1)
{
return -1;
}
FILE* outFile = NULL;
const WebRtc_Word32 width = inputImage._width;
const WebRtc_Word32 height = inputImage._height;
// Set error handler
myErrorMgr jerr;
_cinfo->err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = MyErrorExit;
// Establish the setjmp return context
if (setjmp(jerr.setjmp_buffer))
{
// If we get here, the JPEG code has signaled an error.
jpeg_destroy_compress(_cinfo);
if (outFile != NULL)
{
fclose(outFile);
}
return -1;
}
if ((outFile = fopen(_fileName, "wb")) == NULL)
{
return -2;
}
// Create a compression object
jpeg_create_compress(_cinfo);
// Setting destination file
jpeg_stdio_dest(_cinfo, outFile);
// Set parameters for compression
_cinfo->in_color_space = JCS_YCbCr;
jpeg_set_defaults(_cinfo);
_cinfo->image_width = width;
_cinfo->image_height = height;
_cinfo->input_components = 3;
_cinfo->comp_info[0].h_samp_factor = 2; // Y
_cinfo->comp_info[0].v_samp_factor = 2;
_cinfo->comp_info[1].h_samp_factor = 1; // U
_cinfo->comp_info[1].v_samp_factor = 1;
_cinfo->comp_info[2].h_samp_factor = 1; // V
_cinfo->comp_info[2].v_samp_factor = 1;
_cinfo->raw_data_in = TRUE;
jpeg_start_compress(_cinfo, TRUE);
JSAMPROW y[16],u[8],v[8];
JSAMPARRAY data[3];
data[0] = y;
data[1] = u;
data[2] = v;
WebRtc_UWord32 i, j;
for (j = 0; j < height; j += 16)
{
for (i = 0; i < 16; i++)
{
y[i] = (JSAMPLE*) inputImage._buffer + width * (i + j);
if (i % 2 == 0)
{
u[i / 2] = (JSAMPLE*) inputImage._buffer + width * height +
width / 2 * ((i + j) / 2);
v[i / 2] = (JSAMPLE*) inputImage._buffer + width * height +
width * height / 4 + width / 2 * ((i + j) / 2);
}
}
jpeg_write_raw_data(_cinfo, data, 16);
}
jpeg_finish_compress(_cinfo);
jpeg_destroy_compress(_cinfo);
fclose(outFile);
return 0;
}
JpegDecoder::JpegDecoder()
{
_cinfo = new jpeg_decompress_struct;
}
JpegDecoder::~JpegDecoder()
{
if (_cinfo != NULL)
{
delete _cinfo;
_cinfo = NULL;
}
}
WebRtc_Word32
JpegDecoder::Decode(const EncodedImage& inputImage,
RawImage& outputImage)
{
WebRtc_UWord8* tmpBuffer = NULL;
// Set error handler
myErrorMgr jerr;
_cinfo->err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = MyErrorExit;
// Establish the setjmp return context
if (setjmp(jerr.setjmp_buffer))
{
if (_cinfo->is_decompressor)
{
jpeg_destroy_decompress(_cinfo);
}
if (tmpBuffer != NULL)
{
delete [] tmpBuffer;
}
return -1;
}
_cinfo->out_color_space = JCS_YCbCr;
// Create decompression object
jpeg_create_decompress(_cinfo);
// Specify data source
jpegSetSrcBuffer(_cinfo, (JOCTET*) inputImage._buffer, inputImage._size);
// Read header data
jpeg_read_header(_cinfo, TRUE);
_cinfo->raw_data_out = TRUE;
jpeg_start_decompress(_cinfo);
// Check header
if (_cinfo->num_components == 4)
{
return -2; // not supported
}
if (_cinfo->progressive_mode == 1)
{
return -2; // not supported
}
WebRtc_UWord32 height = _cinfo->image_height;
WebRtc_UWord32 width = _cinfo->image_width;
// Making sure width and height are even
if (height % 2)
{
height++;
}
if (width % 2)
{
width++;
}
WebRtc_UWord32 height16 = (height + 15) & ~15;
WebRtc_UWord32 stride = (width + 15) & ~15;
WebRtc_UWord32 uvStride = (((stride + 1 >> 1) + 15) & ~15);
WebRtc_UWord32 tmpRequiredSize = stride * height16 +
2 * (uvStride * ((height16 + 1) >> 1));
WebRtc_UWord32 requiredSize = width * height * 3 >> 1;
// verify sufficient buffer size
if (outputImage._buffer && outputImage._size < requiredSize)
{
delete [] outputImage._buffer;
outputImage._buffer = NULL;
}
if (outputImage._buffer == NULL)
{
outputImage._buffer = new WebRtc_UWord8[requiredSize];
outputImage._size = requiredSize;
}
WebRtc_UWord8* outPtr = outputImage._buffer;
if (tmpRequiredSize > requiredSize)
{
tmpBuffer = new WebRtc_UWord8[(int) (tmpRequiredSize)];
outPtr = tmpBuffer;
}
JSAMPROW y[16],u[8],v[8];
JSAMPARRAY data[3];
data[0] = y;
data[1] = u;
data[2] = v;
WebRtc_UWord32 hInd, i;
WebRtc_UWord32 numScanLines = 16;
WebRtc_UWord32 numLinesProcessed = 0;
while (_cinfo->output_scanline < _cinfo->output_height)
{
hInd = _cinfo->output_scanline;
for (i = 0; i < numScanLines; i++)
{
y[i] = outPtr + stride * (i + hInd);
if (i % 2 == 0)
{
u[i / 2] = outPtr + stride * height16 +
stride / 2 * ((i + hInd) / 2);
v[i / 2] = outPtr + stride * height16 +
stride * height16 / 4 +
stride / 2 * ((i + hInd) / 2);
}
}
// Processes exactly one iMCU row per call
numLinesProcessed = jpeg_read_raw_data(_cinfo, data, numScanLines);
// Error in read
if (numLinesProcessed == 0)
{
jpeg_abort((j_common_ptr)_cinfo);
return -1;
}
}
if (tmpRequiredSize > requiredSize)
{
WebRtc_UWord8* dstFramePtr = outputImage._buffer;
WebRtc_UWord8* tmpPtr = outPtr;
for (WebRtc_UWord32 p = 0; p < 3; p++)
{
const WebRtc_UWord32 h = (p == 0) ? height : height >> 1;
const WebRtc_UWord32 h16 = (p == 0) ? height16 : height16 >> 1;
const WebRtc_UWord32 w = (p == 0) ? width : width >> 1;
const WebRtc_UWord32 s = (p == 0) ? stride : stride >> 1;
for (WebRtc_UWord32 i = 0; i < h; i++)
{
memcpy(dstFramePtr, tmpPtr, w);
dstFramePtr += w;
tmpPtr += s;
}
tmpPtr += (h16 - h) * s;
}
}
if (tmpBuffer != NULL)
{
delete [] tmpBuffer;
}
// Setting output Image parameter
outputImage._width = width;
outputImage._height = height;
outputImage._length = requiredSize;
outputImage._timeStamp = inputImage._timeStamp;
jpeg_finish_decompress(_cinfo);
jpeg_destroy_decompress(_cinfo);
return 0;
}
}

View File

@ -1,97 +0,0 @@
# Copyright (c) 2011 The WebRTC 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.
{
'includes': [
'../../../../common_settings.gypi', # Common settings
],
'targets': [
{
'target_name': 'webrtc_jpeg',
'type': '<(library)',
'dependencies': [
'../../../vplib/main/source/vplib.gyp:webrtc_vplib',
],
'include_dirs': [
'../../../interface',
'../interface',
'../../../../../../',
],
'direct_dependent_settings': {
'include_dirs': [
'../interface',
'../../../interface',
],
},
'conditions': [
['build_with_chromium==1', {
'dependencies': [
'../../../../../libjpeg_turbo/libjpeg.gyp:libjpeg',
],
'include_dirs': [
'../../../../../libjpeg_turbo',
],
'direct_dependent_settings': {
'include_dirs': [
'../../../../../libjpeg_turbo',
],
},
},{
'dependencies': [
'../../../../../third_party/libjpeg_turbo/libjpeg.gyp:libjpeg',
],
'include_dirs': [
'../../../../third_party/libjpeg_turbo',
],
'direct_dependent_settings': {
'include_dirs': [
'../../../../third_party/libjpeg_turbo',
],
},
}],
],
'sources': [
# interfaces
'../interface/jpeg.h',
# headers
'data_manager.h',
# sources
'jpeg.cc',
'data_manager.cc',
],
},
{
'target_name': 'jpeg_test',
'type': 'executable',
'dependencies': [
'webrtc_jpeg',
],
'include_dirs': [
'../interface',
'../../../vplib/main/interface',
'../source',
],
'sources': [
# headers
# sources
'../test/test_jpeg.cc',
], # source
},
],
}
# Local Variables:
# tab-width:2
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=2 shiftwidth=2:

View File

@ -1,161 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
// system includes
#include <assert.h>
#include <string.h> // memcpy
#include "test_buffer.h"
#include "vplib.h"
TestBuffer::TestBuffer():
_buffer(0),
_bufferSize(0),
_bufferLength(0),
_width(0),
_height(0)
{
//
}
TestBuffer::~TestBuffer()
{
_bufferLength = 0;
_bufferSize = 0;
if(_buffer)
{
delete [] _buffer;
_buffer = 0;
}
}
TestBuffer::TestBuffer(const TestBuffer& rhs)
:
_bufferLength(rhs._bufferLength),
_bufferSize(rhs._bufferSize),
_height(rhs._height),
_width(rhs._width),
_buffer(0)
{
// make sure that our buffer is big enough
_buffer = new WebRtc_UWord8[_bufferSize];
// only copy required length
memcpy(_buffer, rhs._buffer, _bufferLength);
}
WebRtc_UWord32
TestBuffer::GetWidth() const
{
return _width;
}
WebRtc_UWord32
TestBuffer::GetHeight() const
{
return _height;
}
void
TestBuffer::SetWidth(WebRtc_UWord32 width)
{
_width = width;
}
void
TestBuffer::SetHeight(WebRtc_UWord32 height)
{
_height = height;
}
void
TestBuffer::Free()
{
_bufferLength = 0;
_bufferSize = 0;
_height = 0;
_width = 0;
if(_buffer)
{
delete [] _buffer;
_buffer = 0;
}
}
void
TestBuffer::VerifyAndAllocate(WebRtc_UWord32 minimumSize)
{
if(minimumSize > _bufferSize)
{
// make sure that our buffer is big enough
WebRtc_UWord8 * newBufferBuffer = new WebRtc_UWord8[minimumSize];
if(_buffer)
{
// copy the old data
memcpy(newBufferBuffer, _buffer, _bufferSize);
delete [] _buffer;
}
_buffer = newBufferBuffer;
_bufferSize = minimumSize;
}
}
void
TestBuffer::UpdateLength(WebRtc_UWord32 newLength)
{
assert(newLength <= _bufferSize);
_bufferLength = newLength;
}
void
TestBuffer::CopyBuffer(WebRtc_UWord32 length, const WebRtc_UWord8* buffer)
{
assert(length <= _bufferSize);
memcpy(_buffer, buffer, length);
_bufferLength = length;
}
void
TestBuffer::CopyBuffer(TestBuffer& fromVideoBuffer)
{
assert(fromVideoBuffer.GetLength() <= _bufferSize);
assert(fromVideoBuffer.GetSize() <= _bufferSize);
_bufferLength = fromVideoBuffer.GetLength();
_height = fromVideoBuffer.GetHeight();
_width = fromVideoBuffer.GetWidth();
memcpy(_buffer, fromVideoBuffer.GetBuffer(), fromVideoBuffer.GetLength());
}
void
TestBuffer::Set(WebRtc_UWord8* tempBuffer,WebRtc_UWord32 tempSize, WebRtc_UWord32 tempLength)
{
_buffer = tempBuffer;
_bufferSize = tempSize;
_bufferLength = tempLength;
}
WebRtc_UWord8*
TestBuffer::GetBuffer() const
{
return _buffer;
}
WebRtc_UWord32
TestBuffer::GetSize() const
{
return _bufferSize;
}
WebRtc_UWord32
TestBuffer::GetLength() const
{
return _bufferLength;
}

View File

@ -1,77 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
#ifndef WEBRTC_COMMON_VIDEO_JPEG_TEST_BUFFER_H
#define WEBRTC_COMMON_VIDEO_JPEG_TEST_BUFFER_H
#include "typedefs.h"
class TestBuffer
{
public:
TestBuffer();
virtual ~TestBuffer();
TestBuffer(const TestBuffer& rhs);
/**
* Verifies that current allocated buffer size is larger than or equal to the input size.
* If the current buffer size is smaller, a new allocation is made and the old buffer data is copied to the new buffer.
*/
void VerifyAndAllocate(WebRtc_UWord32 minimumSize);
void UpdateLength(WebRtc_UWord32 newLength);
void CopyBuffer(WebRtc_UWord32 length, const WebRtc_UWord8* fromBuffer);
void CopyBuffer(TestBuffer& fromBuffer);
void Free(); // Deletes frame buffer and resets members to zero
/**
* Gets pointer to frame buffer
*/
WebRtc_UWord8* GetBuffer() const;
/**
* Gets allocated buffer size
*/
WebRtc_UWord32 GetSize() const;
/**
* Gets length of frame
*/
WebRtc_UWord32 GetLength() const;
WebRtc_UWord32 GetWidth() const;
WebRtc_UWord32 GetHeight() const;
void SetWidth(WebRtc_UWord32 width);
void SetHeight(WebRtc_UWord32 height);
private:
// TestBuffer& operator=(const TestBuffer& inBuffer);
private:
void Set(WebRtc_UWord8* buffer,WebRtc_UWord32 size,WebRtc_UWord32 length);
WebRtc_UWord8* _buffer; // Pointer to frame buffer
WebRtc_UWord32 _bufferSize; // Allocated buffer size
WebRtc_UWord32 _bufferLength; // Length (in bytes) of frame
WebRtc_UWord32 _width;
WebRtc_UWord32 _height;
};
#endif

View File

@ -1,132 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
/*
* test_jpeg.cc
*/
#include <cassert>
#include <iostream>
#include <cmath>
#include <string>
#include <stdio.h>
#include "video_image.h"
#include "jpeg.h"
using namespace webrtc;
int
main(int argc, char **argv)
{
if (argc < 1)
{
return -1;
}
std::string fileName = argv[1];
const char* fileNameDec = "TestJpegDec.yuv";
const char* fileNameEnc = "TestJpegEnc.jpg";
std::string str;
std::cout << "---------------------" << std::endl;
std::cout << "----- Test JPEG -----" << std::endl;
std::cout << "---------------------" << std::endl;
std::cout << " " << std::endl;
JpegDecoder* JpgDecPtr = new JpegDecoder( );
// Open input file
FILE* openFile = fopen(fileName.c_str(), "rb");
assert(openFile != NULL);
// Get file length
fseek(openFile, 0, SEEK_END);
int length = ftell(openFile);
fseek(openFile, 0, SEEK_SET);
// Read input file to buffer
EncodedImage encodedBuffer;
encodedBuffer._buffer = new WebRtc_UWord8[length];
encodedBuffer._size = length;
encodedBuffer._length = length;
fread(encodedBuffer._buffer, 1, length, openFile);
fclose(openFile);
// ------------------
// Decode
// ------------------
RawImage imageBuffer;
int error = JpgDecPtr->Decode(encodedBuffer, imageBuffer);
std::cout << error << " = Decode(" << fileName.c_str() << ", "
"(" << imageBuffer._width <<
"x" << imageBuffer._height << "))" << std::endl;
if (error == 0)
{
// Save decoded image to file
FILE* saveFile = fopen(fileNameDec, "wb");
fwrite(imageBuffer._buffer, 1, imageBuffer._length, saveFile);
fclose(saveFile);
// ------------------
// Encode
// ------------------
JpegEncoder* JpegEncoderPtr = new JpegEncoder();
// Test invalid inputs
RawImage empty;
empty._width = 164;
empty._height = 164;
int error = JpegEncoderPtr->SetFileName(0);
assert(error == -1);
error = JpegEncoderPtr->Encode(empty);
assert(error == -1);
empty._buffer = new WebRtc_UWord8[10];
empty._size = 0;
error = JpegEncoderPtr->Encode(empty);
assert(error == -1);
empty._size = 10;
empty._height = 0;
error = JpegEncoderPtr->Encode(empty);
assert(error == -1);
empty._height = 164;
empty._width = 0;
error = JpegEncoderPtr->Encode(empty);
assert(error == -1);
error = JpegEncoderPtr->SetFileName(fileNameEnc);
assert(error == 0);
delete [] empty._buffer;
// Actual Encode
error = JpegEncoderPtr->Encode(imageBuffer);
assert(error == 0);
std::cout << error << " = Encode(" << fileNameDec << ")" << std::endl;
delete JpegEncoderPtr;
}
delete [] imageBuffer._buffer;
delete [] encodedBuffer._buffer;
delete JpgDecPtr;
std::cout << "Verify that the encoded and decoded images look correct."
<< std::endl;
std::cout << "Press enter to quit test...";
std::getline(std::cin, str);
return 0;
}

View File

@ -1,80 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
/*
* interpolator.h
* Interface to the WebRTC's interpolation functionality
*/
#ifndef WEBRTC_COMMON_VIDEO_VPLIB_INTERFACE_INTERPOLATOR_H
#define WEBRTC_COMMON_VIDEO_VPLIB_INTERFACE_INTERPOLATOR_H
#include "typedefs.h"
#include "vplib.h"
namespace webrtc
{
// supported interpolation types
enum interpolatorType
{
kBilinear
};
class interpolator
{
public:
interpolator();
~interpolator();
// Set interpolation properties:
//
// Return value : 0 if OK,
// : -1 - parameter error
// : -2 - general error
WebRtc_Word32 Set(WebRtc_UWord32 srcWidth, WebRtc_UWord32 srcHeight,
WebRtc_UWord32 dstWidth, WebRtc_UWord32 dstHeight,
VideoType srcVideoType, VideoType dstVideoType,
interpolatorType type);
// Interpolate frame
//
// Return value : Height of interpolated frame if OK,
// : -1 - parameter error
// : -2 - interpolator not set
WebRtc_Word32 Interpolate(const WebRtc_UWord8* srcFrame,
WebRtc_UWord8*& dstFrame,
WebRtc_UWord32& dstSize);
private:
// Extract computation method given actual type
//
// Return value : True if requested type is supported, false otherwise
bool Method(interpolatorType type);
// Determine if the VideoTypes are currently supported
WebRtc_Word32 SupportedVideoType(VideoType srcVideoType,
VideoType dstVideoType);
interpolatorType _method;
WebRtc_UWord32 _srcWidth;
WebRtc_UWord32 _srcHeight;
WebRtc_UWord32 _dstWidth;
WebRtc_UWord32 _dstHeight;
bool _set;
};
} // namespace webrtc
#endif // WEBRTC_COMMON_VIDEO_VPLIB_INTERFACE_INTERPOLATOR_H

View File

@ -1,356 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
#ifndef WEBRTC_COMMON_VIDEO_INTERFACE_VPLIB_H
#define WEBRTC_COMMON_VIDEO_INTERFACE_VPLIB_H
#include "typedefs.h"
namespace webrtc
{
// Supported video types
enum VideoType
{
kUnknown,
kI420,
kIYUV,
kRGB24,
kARGB,
kARGB4444,
kRGB565,
kARGB1555,
kYUY2,
kYV12,
kUYVY,
kMJPG,
kNV21,
kNV12,
kARGBMac,
kRGBAMac,
kNumberOfVideoTypes
};
// Supported rotation
enum VideoRotationMode
{
kRotateNone = 0,
kRotateClockwise = 90,
kRotateAntiClockwise = -90,
kRotate180 = 180,
};
// Calculate the required buffer size
// Input
// - type - The type of the designated video frame
// - width - frame width in pixels
// - height - frame height in pixels
// Output
// - The required size in bytes to accommodate the specified video frame
//
WebRtc_UWord32 CalcBufferSize(VideoType type, WebRtc_UWord32 width, WebRtc_UWord32 height);
// Calculate the required buffer size when converting from one type to another
// Input
// - incomingVideoType - The type of the existing video frame
// - convertedVideoType - width of the designated video frame
// - length - length in bytes of the data
// Output
// - The required size in bytes to accommodate the specified converted video frame
//
WebRtc_UWord32 CalcBufferSize(VideoType incomingVideoType, VideoType convertedVideoType,
WebRtc_UWord32 length);
//
// Convert To/From I420
//
// The following 2 functions convert an image to/from a I420 type to/from a specified
// format.
//
// Input:
// - incomingVideoType : Type of input video
// - incomingBuffer : Pointer to an input image.
// - width : Image width in pixels.
// - height : Image height in pixels.
// - outgoingBuffer : Pointer to converted image.
// - interlaced : Flag indicating if interlaced I420 output
// - rotate : Rotation mode of output image
// Return value : Size of converted image if OK, otherwise, the following error
// codes:
// -1 : Parameter error
// -2 : Unsupported command (parameter request)
//
// Note: the following functions includes the most common usage cases; for a more general
// usage, refer to explicit function
WebRtc_Word32 ConvertToI420(VideoType incomingVideoType,
const WebRtc_UWord8* incomingBuffer,
WebRtc_UWord32 width,
WebRtc_UWord32 height,
WebRtc_UWord8* outgoingBuffer,
bool interlaced = false ,
VideoRotationMode rotate = kRotateNone
);
WebRtc_Word32 ConvertFromI420(VideoType outgoingVideoType,
const WebRtc_UWord8* incomingBuffer,
WebRtc_UWord32 width,
WebRtc_UWord32 height,
WebRtc_UWord8* outgoingBuffer,
bool interlaced = false ,
VideoRotationMode rotate = kRotateNone
);
// Designated Convert Functions
// The following list describes the designated conversion function which are called by the
// 2 prior general conversion function.
// Input and output descriptions match the above descriptions, and are therefore omitted.
WebRtc_Word32 ConvertI420ToRGB24(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height);
WebRtc_Word32 ConvertI420ToARGB(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord32 strideOut);
WebRtc_Word32 ConvertI420ToARGB4444(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord32 strideOut);
WebRtc_Word32 ConvertI420ToRGB565(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height);
WebRtc_Word32 ConvertI420ToRGB565Android(const WebRtc_UWord8* inFrame,
WebRtc_UWord8* outFrame, WebRtc_UWord32 width,
WebRtc_UWord32 height);
WebRtc_Word32 ConvertI420ToARGB1555(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord32 strideOut);
WebRtc_Word32 ConvertI420ToARGBMac(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord32 strideOut);
WebRtc_Word32 ConvertI420ToRGBAMac(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord32 strideOut);
WebRtc_Word32 ConvertI420ToI420(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord32 strideOut = 0);
WebRtc_Word32 ConvertI420ToUYVY(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord32 strideOut = 0);
WebRtc_Word32 ConvertI420ToYUY2(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord32 strideOut = 0);
WebRtc_Word32 ConvertI420ToYV12(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord32 strideOut);
WebRtc_Word32 ConvertYUY2ToI420interlaced(const WebRtc_UWord8* inFrame, WebRtc_UWord32 inWidth,
WebRtc_UWord32 inHeight, WebRtc_UWord8* outFrame,
WebRtc_UWord32 outWidth, WebRtc_UWord32 outHeight);
WebRtc_Word32 ConvertYV12ToI420(const WebRtc_UWord8* inFrame, WebRtc_UWord32 width,
WebRtc_UWord32 height, WebRtc_UWord8* outFrame);
WebRtc_Word32 ConvertRGB24ToARGB(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord32 strideOut);
WebRtc_Word32 ConvertRGB24ToI420(WebRtc_Word32 width, WebRtc_Word32 height,
const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame);
WebRtc_Word32 ConvertRGB565ToI420(const WebRtc_UWord8* inFrame, WebRtc_UWord32 width,
WebRtc_UWord32 height, WebRtc_UWord8* outFrame);
WebRtc_Word32 ConvertARGBMacToI420(WebRtc_UWord32 width, WebRtc_UWord32 height,
const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame);
WebRtc_Word32 ConvertUYVYToI420(WebRtc_UWord32 width, WebRtc_UWord32 height,
const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame);
// pad cut and convert
WebRtc_Word32 ConvertYUY2ToI420(const WebRtc_UWord8* inFrame, WebRtc_UWord32 inWidth,
WebRtc_UWord32 inHeight, WebRtc_UWord8* outFrame,
WebRtc_UWord32 outWidth, WebRtc_UWord32 outHeight);
WebRtc_Word32 ConvertUYVYToI420interlaced(const WebRtc_UWord8* inFrame,
WebRtc_UWord32 inWidth, WebRtc_UWord32 inHeight,
WebRtc_UWord8* outFrame, WebRtc_UWord32 outWidth,
WebRtc_UWord32 outHeight);
WebRtc_Word32 ConvertRGB24ToI420(const WebRtc_UWord8* inFrame, WebRtc_UWord32 inWidth,
WebRtc_UWord32 inHeight, WebRtc_UWord8* outFrame,
WebRtc_UWord32 outWidth, WebRtc_UWord32 outHeight);
WebRtc_Word32 ConvertI420ToI420(const WebRtc_UWord8* inFrame, WebRtc_UWord32 inWidth,
WebRtc_UWord32 inHeight, WebRtc_UWord8* outFrame,
WebRtc_UWord32 outWidth, WebRtc_UWord32 outHeight);
//NV12 Conversion/Rotation
WebRtc_Word32 ConvertNV12ToI420(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height);
WebRtc_Word32 ConvertNV12ToI420AndRotate180(const WebRtc_UWord8* inFrame,
WebRtc_UWord8* outFrame, WebRtc_UWord32 width,
WebRtc_UWord32 height);
WebRtc_Word32 ConvertNV12ToI420AndRotateAntiClockwise(const WebRtc_UWord8* inFrame,
WebRtc_UWord8* outFrame,
WebRtc_UWord32 width,
WebRtc_UWord32 height);
WebRtc_Word32 ConvertNV12ToI420AndRotateClockwise(const WebRtc_UWord8* inFrame,
WebRtc_UWord8* outFrame,
WebRtc_UWord32 width,
WebRtc_UWord32 height);
WebRtc_Word32 ConvertNV12ToRGB565(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height);
//NV21 Conversion/Rotation
WebRtc_Word32 ConvertNV21ToI420(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height);
WebRtc_Word32 ConvertNV21ToI420AndRotate180(const WebRtc_UWord8* inFrame,
WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height);
WebRtc_Word32 ConvertNV21ToI420AndRotateAntiClockwise(const WebRtc_UWord8* inFrame,
WebRtc_UWord8* outFrame,
WebRtc_UWord32 width,
WebRtc_UWord32 height);
WebRtc_Word32 ConvertNV21ToI420AndRotateClockwise(const WebRtc_UWord8* inFrame,
WebRtc_UWord8* outFrame,
WebRtc_UWord32 width,
WebRtc_UWord32 height);
//IPhone
WebRtc_Word32 ConvertI420ToRGBAIPhone(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord32 strideOut);
// I420 Cut and Pad - make a center cut
WebRtc_Word32 CutI420Frame(WebRtc_UWord8* frame, WebRtc_UWord32 fromWidth,
WebRtc_UWord32 fromHeight, WebRtc_UWord32 toWidth,
WebRtc_UWord32 toHeight);
// Pad an I420 frame
// Input:
// - inBuffer : Pointer to the input image component to be padded.
// - outBuffer : Pointer to the output padded image component.
// - fromWidth : Width in pixels of the inBuffer component.
// - fromHeight : Height in pixels of the inBuffer component.
// - toWidth : Width in pixels of the outBuffer component.
// - toHeight : Height in pixels of the outBuffer component.
// Return Value:
// - Length of the output component.
WebRtc_Word32 PadI420Frame(const WebRtc_UWord8* inBuffer, WebRtc_UWord8* outBuffer,
WebRtc_UWord32 fromWidth, WebRtc_UWord32 fromHeight,
WebRtc_UWord32 toWidth, WebRtc_UWord32 toHeight);
WebRtc_Word32 PadI420BottomRows(WebRtc_UWord8* buffer, WebRtc_UWord32 size,
WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_Word32 nrRows, WebRtc_UWord32& newLength);
// I420 Scale
// Scale an I420 frame:Half frame, quarter frame
// Input:
// - inFrame : Pointer to the image component to be scaled
// - width : Width in pixels of the output frame.
// - height : Height in pixels of the out frame.
// Return Value:
// - Length of the output component.
WebRtc_Word32 ScaleI420FrameQuarter(WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord8* inFrame);
WebRtc_Word32 ScaleI420DownHalfFrame(WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord8* inFrame);
WebRtc_Word32 ScaleI420UpHalfFrame(WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord8* inFrame);
// Scales up an I420-frame to twice its width and height. Interpolates by using mean value
// of neighboring pixels.
// The following two function allow up-scaling by either twice or 3/2 of the original
// the width and height
// Input:
// - width : Width of input frame in pixels.
// - height : Height of input frame in pixels.
// - buffer : Reference to a buffer containing the frame.
// - size :Size of allocated buffer
// - scaledWidth : Reference to the width of scaled frame in pixels.
// - scaledHeight : Reference to the height of scaled frame in pixels.
// Return value:
// - (length) : Length of scaled frame.
// - (-1) : Error.
WebRtc_Word32 ScaleI420Up2(WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord8*& buffer, WebRtc_UWord32 size,
WebRtc_UWord32 &scaledWidth, WebRtc_UWord32 &scaledHeight);
WebRtc_Word32 ScaleI420Up3_2(WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord8*& buffer, WebRtc_UWord32 size,
WebRtc_UWord32 &scaledWidth, WebRtc_UWord32 &scaledHeight);
// Scales down an I420-frame to one third its width and height.
// Input:
// - width : Width of frame in pixels.
// - height : Height of frame in pixels.
// - videoBuffer : Reference to a buffer containing the frame.
// - scaledWidth : Width of scaled frame in pixels.
// - scaledHeight : Height of scaled frame in pixels.
// Return value:
// - (length) : Length of scaled frame.
// - (-1) : Error.
WebRtc_Word32 ScaleI420Down1_3(WebRtc_UWord32 width, WebRtc_UWord32 height,
WebRtc_UWord8*& buffer, WebRtc_UWord32 size,
WebRtc_UWord32 &scaledWidth, WebRtc_UWord32 &scaledHeight);
// Convert From I420/YV12 to I420 and Rotate clockwise
// Input:
// - srcBuffer : Reference to a buffer containing the source frame.
// - srcWidth : Width of source frame in pixels.
// - srcHeight : Height of source frame in pixels.
// - dstBuffer : Reference to a buffer containing the destination frame.
// - dstWidth : Width of destination frame in pixels.
// - dstHeight : Height of destination frame in pixels.
// - colorSpaceIn : Input color space
// Return value:
// - (length) : Length of scaled frame.
// - (-1) : Error.
WebRtc_Word32 ConvertToI420AndRotateClockwise(const WebRtc_UWord8* srcBuffer,
WebRtc_UWord32 srcWidth,
WebRtc_UWord32 srcHeight,
WebRtc_UWord8* dstBuffer,
WebRtc_UWord32 dstWidth,
WebRtc_UWord32 dstHeight,
VideoType colorSpaceIn);
// Convert From I420/YV12 to I420 and Rotate anti clockwise
// Inputs/outputs as the above function
WebRtc_Word32 ConvertToI420AndRotateAntiClockwise(const WebRtc_UWord8* srcBuffer,
WebRtc_UWord32 srcWidth,
WebRtc_UWord32 srcHeight,
WebRtc_UWord8* dstBuffer,
WebRtc_UWord32 dstWidth,
WebRtc_UWord32 dstHeight,
VideoType colorSpaceIn);
// Mirror functions
// The following 2 functions perform mirroring on a given image (LeftRight/UpDown)
// Input:
// - width : Image width in pixels.
// - height : Image height in pixels.
// - inFrame : Reference to input image.
// - outFrame : Reference to converted image.
// Return value: 0 if OK, < 0 otherwise.
WebRtc_Word32 MirrorI420LeftRight(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height);
WebRtc_Word32 MirrorI420UpDown(const WebRtc_UWord8* inFrame, WebRtc_UWord8* outFrame,
WebRtc_UWord32 width, WebRtc_UWord32 height);
// Mirror functions - Don't work in place (srcBuffer == dstBuffer),
// and are therefore faster. Also combine mirroring with conversion to speed things up.
// Input:
// - srcBuffer : Pointer to source image.
// - dstBuffer : Pointer to destination image.
// - srcWidth : Width of input buffer.
// - srcHeight : Height of input buffer.
// - colorSpaceIn : Color space to convert from, I420 if no conversion should be done
// - dstBuffer : Pointer to converted/rotated image.
// Return value: 0 if OK, < 0 otherwise.
WebRtc_Word32 ConvertToI420AndMirrorUpDown(const WebRtc_UWord8* srcBuffer,
WebRtc_UWord8* dstBuffer,
WebRtc_UWord32 srcWidth,
WebRtc_UWord32 srcHeight,
VideoType colorSpaceIn = kI420);
}
#endif

View File

@ -1,53 +0,0 @@
# Copyright (c) 2011 The WebRTC 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.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE := libwebrtc_vplib
LOCAL_MODULE_TAGS := optional
LOCAL_CPP_EXTENSION := .cc
LOCAL_GENERATED_SOURCES :=
LOCAL_SRC_FILES := \
vplib.cc \
interpolator.cc \
scale_bilinear_yuv.cc
# Flags passed to both C and C++ files.
MY_CFLAGS :=
MY_CFLAGS_C :=
MY_DEFS := '-DNO_TCMALLOC' \
'-DNO_HEAPCHECKER' \
'-DWEBRTC_TARGET_PC' \
'-DWEBRTC_LINUX' \
'-DWEBRTC_THREAD_RR' \
'-DWEBRTC_ANDROID' \
'-DANDROID'
LOCAL_CFLAGS := $(MY_CFLAGS_C) $(MY_CFLAGS) $(MY_DEFS)
# Include paths placed before CFLAGS/CPPFLAGS
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../.. \
$(LOCAL_PATH)/../interface
# Flags passed to only C++ (and not C) files.
LOCAL_CPPFLAGS :=
LOCAL_LDFLAGS :=
LOCAL_STATIC_LIBRARIES :=
LOCAL_SHARED_LIBRARIES := libcutils \
libdl \
libstlport
LOCAL_ADDITIONAL_DEPENDENCIES :=
include external/stlport/libstlport.mk
include $(BUILD_STATIC_LIBRARY)

View File

@ -1,182 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
/**************************************************************
* conversion_tables.h
*
* Pre-compiled definitions of the conversion equations: YUV -> RGB.
*
***************************************************************/
#ifndef WEBRTC_COMMON_VIDEO_VPLIB_CONVERSION_TABLES
#define WEBRTC_COMMON_VIDEO_VPLIB_CONVERSION_TABLES
#include "typedefs.h"
namespace webrtc
{
/*********************************************************************************************
* YUV TO RGB approximation
*
* R = clip( (298 * (Y - 16) + 409 * (V - 128) + 128 ) >> 8 )
* G = clip( (298 * (Y - 16) - 100 * (U - 128) - 208 * (V - 128) + 128 ) >> 8 )
* B = clip( (298 * (Y - 16) + 516 * (U - 128) + 128 ) >> 8 )
**********************************************************************************************/
#define Yc(i) static_cast<WebRtc_Word32> ( 298 * ( i - 16 )) // Y contribution
#define Ucg(i) static_cast<WebRtc_Word32> ( -100 * ( i - 128 )) // U contribution to G
#define Ucb(i) static_cast<WebRtc_Word32> ( 516 * ( i - 128 )) // U contribution to B
#define Vcr(i) static_cast<WebRtc_Word32> ( 409 * ( i - 128 )) // V contribution to R
#define Vcg(i) static_cast<WebRtc_Word32> ( -208 * ( i - 128 )) // V contribution to G
static const WebRtc_Word32 mapYc[256] = {
Yc(0),Yc(1),Yc(2),Yc(3),Yc(4),Yc(5),Yc(6),Yc(7),Yc(8),Yc(9),
Yc(10),Yc(11),Yc(12),Yc(13),Yc(14),Yc(15),Yc(16),Yc(17),Yc(18),Yc(19),
Yc(20),Yc(21),Yc(22),Yc(23),Yc(24),Yc(25),Yc(26),Yc(27),Yc(28),Yc(29),
Yc(30),Yc(31),Yc(32),Yc(33),Yc(34),Yc(35),Yc(36),Yc(37),Yc(38),Yc(39),
Yc(40),Yc(41),Yc(42),Yc(43),Yc(44),Yc(45),Yc(46),Yc(47),Yc(48),Yc(49),
Yc(50),Yc(51),Yc(52),Yc(53),Yc(54),Yc(55),Yc(56),Yc(57),Yc(58),Yc(59),
Yc(60),Yc(61),Yc(62),Yc(63),Yc(64),Yc(65),Yc(66),Yc(67),Yc(68),Yc(69),
Yc(70),Yc(71),Yc(72),Yc(73),Yc(74),Yc(75),Yc(76),Yc(77),Yc(78),Yc(79),
Yc(80),Yc(81),Yc(82),Yc(83),Yc(84),Yc(85),Yc(86),Yc(87),Yc(88),Yc(89),
Yc(90),Yc(91),Yc(92),Yc(93),Yc(94),Yc(95),Yc(96),Yc(97),Yc(98),Yc(99),
Yc(100),Yc(101),Yc(102),Yc(103),Yc(104),Yc(105),Yc(106),Yc(107),Yc(108),Yc(109),
Yc(110),Yc(111),Yc(112),Yc(113),Yc(114),Yc(115),Yc(116),Yc(117),Yc(118),Yc(119),
Yc(120),Yc(121),Yc(122),Yc(123),Yc(124),Yc(125),Yc(126),Yc(127),Yc(128),Yc(129),
Yc(130),Yc(131),Yc(132),Yc(133),Yc(134),Yc(135),Yc(136),Yc(137),Yc(138),Yc(139),
Yc(140),Yc(141),Yc(142),Yc(143),Yc(144),Yc(145),Yc(146),Yc(147),Yc(148),Yc(149),
Yc(150),Yc(151),Yc(152),Yc(153),Yc(154),Yc(155),Yc(156),Yc(157),Yc(158),Yc(159),
Yc(160),Yc(161),Yc(162),Yc(163),Yc(164),Yc(165),Yc(166),Yc(167),Yc(168),Yc(169),
Yc(170),Yc(171),Yc(172),Yc(173),Yc(174),Yc(175),Yc(176),Yc(177),Yc(178),Yc(179),
Yc(180),Yc(181),Yc(182),Yc(183),Yc(184),Yc(185),Yc(186),Yc(187),Yc(188),Yc(189),
Yc(190),Yc(191),Yc(192),Yc(193),Yc(194),Yc(195),Yc(196),Yc(197),Yc(198),Yc(199),
Yc(200),Yc(201),Yc(202),Yc(203),Yc(204),Yc(205),Yc(206),Yc(207),Yc(208),Yc(209),
Yc(210),Yc(211),Yc(212),Yc(213),Yc(214),Yc(215),Yc(216),Yc(217),Yc(218),Yc(219),
Yc(220),Yc(221),Yc(222),Yc(223),Yc(224),Yc(225),Yc(226),Yc(227),Yc(228),Yc(229),
Yc(230),Yc(231),Yc(232),Yc(233),Yc(234),Yc(235),Yc(236),Yc(237),Yc(238),Yc(239),
Yc(240),Yc(241),Yc(242),Yc(243),Yc(244),Yc(245),Yc(246),Yc(247),Yc(248),Yc(249),
Yc(250),Yc(251),Yc(252),Yc(253),Yc(254),Yc(255)};
static const WebRtc_Word32 mapUcg[256] = {
Ucg(0),Ucg(1),Ucg(2),Ucg(3),Ucg(4),Ucg(5),Ucg(6),Ucg(7),Ucg(8),Ucg(9),
Ucg(10),Ucg(11),Ucg(12),Ucg(13),Ucg(14),Ucg(15),Ucg(16),Ucg(17),Ucg(18),Ucg(19),
Ucg(20),Ucg(21),Ucg(22),Ucg(23),Ucg(24),Ucg(25),Ucg(26),Ucg(27),Ucg(28),Ucg(29),
Ucg(30),Ucg(31),Ucg(32),Ucg(33),Ucg(34),Ucg(35),Ucg(36),Ucg(37),Ucg(38),Ucg(39),
Ucg(40),Ucg(41),Ucg(42),Ucg(43),Ucg(44),Ucg(45),Ucg(46),Ucg(47),Ucg(48),Ucg(49),
Ucg(50),Ucg(51),Ucg(52),Ucg(53),Ucg(54),Ucg(55),Ucg(56),Ucg(57),Ucg(58),Ucg(59),
Ucg(60),Ucg(61),Ucg(62),Ucg(63),Ucg(64),Ucg(65),Ucg(66),Ucg(67),Ucg(68),Ucg(69),
Ucg(70),Ucg(71),Ucg(72),Ucg(73),Ucg(74),Ucg(75),Ucg(76),Ucg(77),Ucg(78),Ucg(79),
Ucg(80),Ucg(81),Ucg(82),Ucg(83),Ucg(84),Ucg(85),Ucg(86),Ucg(87),Ucg(88),Ucg(89),
Ucg(90),Ucg(91),Ucg(92),Ucg(93),Ucg(94),Ucg(95),Ucg(96),Ucg(97),Ucg(98),Ucg(99),
Ucg(100),Ucg(101),Ucg(102),Ucg(103),Ucg(104),Ucg(105),Ucg(106),Ucg(107),Ucg(108),Ucg(109),
Ucg(110),Ucg(111),Ucg(112),Ucg(113),Ucg(114),Ucg(115),Ucg(116),Ucg(117),Ucg(118),Ucg(119),
Ucg(120),Ucg(121),Ucg(122),Ucg(123),Ucg(124),Ucg(125),Ucg(126),Ucg(127),Ucg(128),Ucg(129),
Ucg(130),Ucg(131),Ucg(132),Ucg(133),Ucg(134),Ucg(135),Ucg(136),Ucg(137),Ucg(138),Ucg(139),
Ucg(140),Ucg(141),Ucg(142),Ucg(143),Ucg(144),Ucg(145),Ucg(146),Ucg(147),Ucg(148),Ucg(149),
Ucg(150),Ucg(151),Ucg(152),Ucg(153),Ucg(154),Ucg(155),Ucg(156),Ucg(157),Ucg(158),Ucg(159),
Ucg(160),Ucg(161),Ucg(162),Ucg(163),Ucg(164),Ucg(165),Ucg(166),Ucg(167),Ucg(168),Ucg(169),
Ucg(170),Ucg(171),Ucg(172),Ucg(173),Ucg(174),Ucg(175),Ucg(176),Ucg(177),Ucg(178),Ucg(179),
Ucg(180),Ucg(181),Ucg(182),Ucg(183),Ucg(184),Ucg(185),Ucg(186),Ucg(187),Ucg(188),Ucg(189),
Ucg(190),Ucg(191),Ucg(192),Ucg(193),Ucg(194),Ucg(195),Ucg(196),Ucg(197),Ucg(198),Ucg(199),
Ucg(200),Ucg(201),Ucg(202),Ucg(203),Ucg(204),Ucg(205),Ucg(206),Ucg(207),Ucg(208),Ucg(209),
Ucg(210),Ucg(211),Ucg(212),Ucg(213),Ucg(214),Ucg(215),Ucg(216),Ucg(217),Ucg(218),Ucg(219),
Ucg(220),Ucg(221),Ucg(222),Ucg(223),Ucg(224),Ucg(225),Ucg(226),Ucg(227),Ucg(228),Ucg(229),
Ucg(230),Ucg(231),Ucg(232),Ucg(233),Ucg(234),Ucg(235),Ucg(236),Ucg(237),Ucg(238),Ucg(239),
Ucg(240),Ucg(241),Ucg(242),Ucg(243),Ucg(244),Ucg(245),Ucg(246),Ucg(247),Ucg(248),Ucg(249),
Ucg(250),Ucg(251),Ucg(252),Ucg(253),Ucg(254),Ucg(255)};
static const WebRtc_Word32 mapUcb[256] = {
Ucb(0),Ucb(1),Ucb(2),Ucb(3),Ucb(4),Ucb(5),Ucb(6),Ucb(7),Ucb(8),Ucb(9),
Ucb(10),Ucb(11),Ucb(12),Ucb(13),Ucb(14),Ucb(15),Ucb(16),Ucb(17),Ucb(18),Ucb(19),
Ucb(20),Ucb(21),Ucb(22),Ucb(23),Ucb(24),Ucb(25),Ucb(26),Ucb(27),Ucb(28),Ucb(29),
Ucb(30),Ucb(31),Ucb(32),Ucb(33),Ucb(34),Ucb(35),Ucb(36),Ucb(37),Ucb(38),Ucb(39),
Ucb(40),Ucb(41),Ucb(42),Ucb(43),Ucb(44),Ucb(45),Ucb(46),Ucb(47),Ucb(48),Ucb(49),
Ucb(50),Ucb(51),Ucb(52),Ucb(53),Ucb(54),Ucb(55),Ucb(56),Ucb(57),Ucb(58),Ucb(59),
Ucb(60),Ucb(61),Ucb(62),Ucb(63),Ucb(64),Ucb(65),Ucb(66),Ucb(67),Ucb(68),Ucb(69),
Ucb(70),Ucb(71),Ucb(72),Ucb(73),Ucb(74),Ucb(75),Ucb(76),Ucb(77),Ucb(78),Ucb(79),
Ucb(80),Ucb(81),Ucb(82),Ucb(83),Ucb(84),Ucb(85),Ucb(86),Ucb(87),Ucb(88),Ucb(89),
Ucb(90),Ucb(91),Ucb(92),Ucb(93),Ucb(94),Ucb(95),Ucb(96),Ucb(97),Ucb(98),Ucb(99),
Ucb(100),Ucb(101),Ucb(102),Ucb(103),Ucb(104),Ucb(105),Ucb(106),Ucb(107),Ucb(108),Ucb(109),
Ucb(110),Ucb(111),Ucb(112),Ucb(113),Ucb(114),Ucb(115),Ucb(116),Ucb(117),Ucb(118),Ucb(119),
Ucb(120),Ucb(121),Ucb(122),Ucb(123),Ucb(124),Ucb(125),Ucb(126),Ucb(127),Ucb(128),Ucb(129),
Ucb(130),Ucb(131),Ucb(132),Ucb(133),Ucb(134),Ucb(135),Ucb(136),Ucb(137),Ucb(138),Ucb(139),
Ucb(140),Ucb(141),Ucb(142),Ucb(143),Ucb(144),Ucb(145),Ucb(146),Ucb(147),Ucb(148),Ucb(149),
Ucb(150),Ucb(151),Ucb(152),Ucb(153),Ucb(154),Ucb(155),Ucb(156),Ucb(157),Ucb(158),Ucb(159),
Ucb(160),Ucb(161),Ucb(162),Ucb(163),Ucb(164),Ucb(165),Ucb(166),Ucb(167),Ucb(168),Ucb(169),
Ucb(170),Ucb(171),Ucb(172),Ucb(173),Ucb(174),Ucb(175),Ucb(176),Ucb(177),Ucb(178),Ucb(179),
Ucb(180),Ucb(181),Ucb(182),Ucb(183),Ucb(184),Ucb(185),Ucb(186),Ucb(187),Ucb(188),Ucb(189),
Ucb(190),Ucb(191),Ucb(192),Ucb(193),Ucb(194),Ucb(195),Ucb(196),Ucb(197),Ucb(198),Ucb(199),
Ucb(200),Ucb(201),Ucb(202),Ucb(203),Ucb(204),Ucb(205),Ucb(206),Ucb(207),Ucb(208),Ucb(209),
Ucb(210),Ucb(211),Ucb(212),Ucb(213),Ucb(214),Ucb(215),Ucb(216),Ucb(217),Ucb(218),Ucb(219),
Ucb(220),Ucb(221),Ucb(222),Ucb(223),Ucb(224),Ucb(225),Ucb(226),Ucb(227),Ucb(228),Ucb(229),
Ucb(230),Ucb(231),Ucb(232),Ucb(233),Ucb(234),Ucb(235),Ucb(236),Ucb(237),Ucb(238),Ucb(239),
Ucb(240),Ucb(241),Ucb(242),Ucb(243),Ucb(244),Ucb(245),Ucb(246),Ucb(247),Ucb(248),Ucb(249),
Ucb(250),Ucb(251),Ucb(252),Ucb(253),Ucb(254),Ucb(255)};
static const WebRtc_Word32 mapVcr[256] = {
Vcr(0),Vcr(1),Vcr(2),Vcr(3),Vcr(4),Vcr(5),Vcr(6),Vcr(7),Vcr(8),Vcr(9),
Vcr(10),Vcr(11),Vcr(12),Vcr(13),Vcr(14),Vcr(15),Vcr(16),Vcr(17),Vcr(18),Vcr(19),
Vcr(20),Vcr(21),Vcr(22),Vcr(23),Vcr(24),Vcr(25),Vcr(26),Vcr(27),Vcr(28),Vcr(29),
Vcr(30),Vcr(31),Vcr(32),Vcr(33),Vcr(34),Vcr(35),Vcr(36),Vcr(37),Vcr(38),Vcr(39),
Vcr(40),Vcr(41),Vcr(42),Vcr(43),Vcr(44),Vcr(45),Vcr(46),Vcr(47),Vcr(48),Vcr(49),
Vcr(50),Vcr(51),Vcr(52),Vcr(53),Vcr(54),Vcr(55),Vcr(56),Vcr(57),Vcr(58),Vcr(59),
Vcr(60),Vcr(61),Vcr(62),Vcr(63),Vcr(64),Vcr(65),Vcr(66),Vcr(67),Vcr(68),Vcr(69),
Vcr(70),Vcr(71),Vcr(72),Vcr(73),Vcr(74),Vcr(75),Vcr(76),Vcr(77),Vcr(78),Vcr(79),
Vcr(80),Vcr(81),Vcr(82),Vcr(83),Vcr(84),Vcr(85),Vcr(86),Vcr(87),Vcr(88),Vcr(89),
Vcr(90),Vcr(91),Vcr(92),Vcr(93),Vcr(94),Vcr(95),Vcr(96),Vcr(97),Vcr(98),Vcr(99),
Vcr(100),Vcr(101),Vcr(102),Vcr(103),Vcr(104),Vcr(105),Vcr(106),Vcr(107),Vcr(108),Vcr(109),
Vcr(110),Vcr(111),Vcr(112),Vcr(113),Vcr(114),Vcr(115),Vcr(116),Vcr(117),Vcr(118),Vcr(119),
Vcr(120),Vcr(121),Vcr(122),Vcr(123),Vcr(124),Vcr(125),Vcr(126),Vcr(127),Vcr(128),Vcr(129),
Vcr(130),Vcr(131),Vcr(132),Vcr(133),Vcr(134),Vcr(135),Vcr(136),Vcr(137),Vcr(138),Vcr(139),
Vcr(140),Vcr(141),Vcr(142),Vcr(143),Vcr(144),Vcr(145),Vcr(146),Vcr(147),Vcr(148),Vcr(149),
Vcr(150),Vcr(151),Vcr(152),Vcr(153),Vcr(154),Vcr(155),Vcr(156),Vcr(157),Vcr(158),Vcr(159),
Vcr(160),Vcr(161),Vcr(162),Vcr(163),Vcr(164),Vcr(165),Vcr(166),Vcr(167),Vcr(168),Vcr(169),
Vcr(170),Vcr(171),Vcr(172),Vcr(173),Vcr(174),Vcr(175),Vcr(176),Vcr(177),Vcr(178),Vcr(179),
Vcr(180),Vcr(181),Vcr(182),Vcr(183),Vcr(184),Vcr(185),Vcr(186),Vcr(187),Vcr(188),Vcr(189),
Vcr(190),Vcr(191),Vcr(192),Vcr(193),Vcr(194),Vcr(195),Vcr(196),Vcr(197),Vcr(198),Vcr(199),
Vcr(200),Vcr(201),Vcr(202),Vcr(203),Vcr(204),Vcr(205),Vcr(206),Vcr(207),Vcr(208),Vcr(209),
Vcr(210),Vcr(211),Vcr(212),Vcr(213),Vcr(214),Vcr(215),Vcr(216),Vcr(217),Vcr(218),Vcr(219),
Vcr(220),Vcr(221),Vcr(222),Vcr(223),Vcr(224),Vcr(225),Vcr(226),Vcr(227),Vcr(228),Vcr(229),
Vcr(230),Vcr(231),Vcr(232),Vcr(233),Vcr(234),Vcr(235),Vcr(236),Vcr(237),Vcr(238),Vcr(239),
Vcr(240),Vcr(241),Vcr(242),Vcr(243),Vcr(244),Vcr(245),Vcr(246),Vcr(247),Vcr(248),Vcr(249),
Vcr(250),Vcr(251),Vcr(252),Vcr(253),Vcr(254),Vcr(255)};
static const WebRtc_Word32 mapVcg[256] = {
Vcg(0),Vcg(1),Vcg(2),Vcg(3),Vcg(4),Vcg(5),Vcg(6),Vcg(7),Vcg(8),Vcg(9),
Vcg(10),Vcg(11),Vcg(12),Vcg(13),Vcg(14),Vcg(15),Vcg(16),Vcg(17),Vcg(18),Vcg(19),
Vcg(20),Vcg(21),Vcg(22),Vcg(23),Vcg(24),Vcg(25),Vcg(26),Vcg(27),Vcg(28),Vcg(29),
Vcg(30),Vcg(31),Vcg(32),Vcg(33),Vcg(34),Vcg(35),Vcg(36),Vcg(37),Vcg(38),Vcg(39),
Vcg(40),Vcg(41),Vcg(42),Vcg(43),Vcg(44),Vcg(45),Vcg(46),Vcg(47),Vcg(48),Vcg(49),
Vcg(50),Vcg(51),Vcg(52),Vcg(53),Vcg(54),Vcg(55),Vcg(56),Vcg(57),Vcg(58),Vcg(59),
Vcg(60),Vcg(61),Vcg(62),Vcg(63),Vcg(64),Vcg(65),Vcg(66),Vcg(67),Vcg(68),Vcg(69),
Vcg(70),Vcg(71),Vcg(72),Vcg(73),Vcg(74),Vcg(75),Vcg(76),Vcg(77),Vcg(78),Vcg(79),
Vcg(80),Vcg(81),Vcg(82),Vcg(83),Vcg(84),Vcg(85),Vcg(86),Vcg(87),Vcg(88),Vcg(89),
Vcg(90),Vcg(91),Vcg(92),Vcg(93),Vcg(94),Vcg(95),Vcg(96),Vcg(97),Vcg(98),Vcg(99),
Vcg(100),Vcg(101),Vcg(102),Vcg(103),Vcg(104),Vcg(105),Vcg(106),Vcg(107),Vcg(108),Vcg(109),
Vcg(110),Vcg(111),Vcg(112),Vcg(113),Vcg(114),Vcg(115),Vcg(116),Vcg(117),Vcg(118),Vcg(119),
Vcg(120),Vcg(121),Vcg(122),Vcg(123),Vcg(124),Vcg(125),Vcg(126),Vcg(127),Vcg(128),Vcg(129),
Vcg(130),Vcg(131),Vcg(132),Vcg(133),Vcg(134),Vcg(135),Vcg(136),Vcg(137),Vcg(138),Vcg(139),
Vcg(140),Vcg(141),Vcg(142),Vcg(143),Vcg(144),Vcg(145),Vcg(146),Vcg(147),Vcg(148),Vcg(149),
Vcg(150),Vcg(151),Vcg(152),Vcg(153),Vcg(154),Vcg(155),Vcg(156),Vcg(157),Vcg(158),Vcg(159),
Vcg(160),Vcg(161),Vcg(162),Vcg(163),Vcg(164),Vcg(165),Vcg(166),Vcg(167),Vcg(168),Vcg(169),
Vcg(170),Vcg(171),Vcg(172),Vcg(173),Vcg(174),Vcg(175),Vcg(176),Vcg(177),Vcg(178),Vcg(179),
Vcg(180),Vcg(181),Vcg(182),Vcg(183),Vcg(184),Vcg(185),Vcg(186),Vcg(187),Vcg(188),Vcg(189),
Vcg(190),Vcg(191),Vcg(192),Vcg(193),Vcg(194),Vcg(195),Vcg(196),Vcg(197),Vcg(198),Vcg(199),
Vcg(200),Vcg(201),Vcg(202),Vcg(203),Vcg(204),Vcg(205),Vcg(206),Vcg(207),Vcg(208),Vcg(209),
Vcg(210),Vcg(211),Vcg(212),Vcg(213),Vcg(214),Vcg(215),Vcg(216),Vcg(217),Vcg(218),Vcg(219),
Vcg(220),Vcg(221),Vcg(222),Vcg(223),Vcg(224),Vcg(225),Vcg(226),Vcg(227),Vcg(228),Vcg(229),
Vcg(230),Vcg(231),Vcg(232),Vcg(233),Vcg(234),Vcg(235),Vcg(236),Vcg(237),Vcg(238),Vcg(239),
Vcg(240),Vcg(241),Vcg(242),Vcg(243),Vcg(244),Vcg(245),Vcg(246),Vcg(247),Vcg(248),Vcg(249),
Vcg(250),Vcg(251),Vcg(252),Vcg(253),Vcg(254),Vcg(255)};
}
#endif

View File

@ -1,129 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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 <stdlib.h>
#include "interpolator.h"
#include "scale_bilinear_yuv.h"
namespace webrtc
{
interpolator::interpolator():
_method(kBilinear),
_srcWidth(0),
_srcHeight(0),
_dstWidth(0),
_dstHeight(0),
_set(false)
{
}
interpolator:: ~interpolator()
{
//
}
WebRtc_Word32
interpolator::Set(WebRtc_UWord32 srcWidth, WebRtc_UWord32 srcHeight,
WebRtc_UWord32 dstWidth, WebRtc_UWord32 dstHeight,
VideoType srcVideoType, VideoType dstVideoType,
interpolatorType type)
{
_set = false;
if (srcWidth < 1 || srcHeight < 1 || dstWidth < 1 || dstHeight < 1 )
{
return -1;
}
if (!Method(type))
{
return -1;
}
if (!SupportedVideoType(srcVideoType, dstVideoType))
{
return -1;
}
_srcWidth = srcWidth;
_srcHeight = srcHeight;
_dstWidth = dstWidth;
_dstHeight = dstHeight;
_set = true;
return 0;
}
WebRtc_Word32
interpolator::Interpolate(const WebRtc_UWord8* srcFrame,
WebRtc_UWord8*& dstFrame,
WebRtc_UWord32& dstSize)
{
if (srcFrame == NULL)
{
return -1;
}
if (!_set)
{
return -2;
}
WebRtc_Word32 ret = 0;
switch (_method)
{
case kBilinear :
ret = ScaleBilinear(srcFrame, dstFrame,
_srcWidth, _srcHeight,
_dstWidth, _dstHeight,
dstSize);
break;
default :
ret = -1;
break;
}
return ret;
}
bool
interpolator::Method(interpolatorType type)
{
// currently only 1 supported
if (type != kBilinear)
{
return false;
}
_method = type;
return true;
}
WebRtc_Word32
interpolator::SupportedVideoType(VideoType srcVideoType,
VideoType dstVideoType)
{
if (srcVideoType != dstVideoType)
{
return -1;
}
if ((srcVideoType != kI420) ||
(srcVideoType != kIYUV) ||
(srcVideoType != kYV12))
{
return -1;
}
return 0;
}
} // namespace webrtc

View File

@ -1,364 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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 "scale_bilinear_yuv.h"
#include <string.h>
namespace webrtc
{
// 16.16 fixed point arithmetic
const WebRtc_UWord32 kFractionBits = 16;
const WebRtc_UWord32 kFractionMax = 1 << kFractionBits;
const WebRtc_UWord32 kFractionMask = ((1 << kFractionBits) - 1);
#if USE_MMX
#if defined(_MSC_VER)
#include <intrin.h>
#else
#include <mmintrin.h>
#endif
#endif
#if USE_SSE2
#include <emmintrin.h>
#endif
#if USE_SSE2
// FilterHorizontal combines two rows of the image using linear interpolation.
// SSE2 version does 16 pixels at a time
static void FilterHorizontal(WebRtc_UWord8* ybuf,
const WebRtc_UWord8* y0_ptr,
const WebRtc_UWord8* y1_ptr,
WebRtc_UWord32 source_width,
WebRtc_UWord32 source_y_fraction)
{
__m128i zero = _mm_setzero_si128();
__m128i y1_fraction = _mm_set1_epi16(source_y_fraction);
__m128i y0_fraction = _mm_set1_epi16(256 - source_y_fraction);
const __m128i* y0_ptr128 = reinterpret_cast<const __m128i*>(y0_ptr);
const __m128i* y1_ptr128 = reinterpret_cast<const __m128i*>(y1_ptr);
__m128i* dest128 = reinterpret_cast<__m128i*>(ybuf);
__m128i* end128 = reinterpret_cast<__m128i*>(ybuf + source_width);
do
{
__m128i y0 = _mm_loadu_si128(y0_ptr128);
__m128i y1 = _mm_loadu_si128(y1_ptr128);
__m128i y2 = _mm_unpackhi_epi8(y0, zero);
__m128i y3 = _mm_unpackhi_epi8(y1, zero);
y0 = _mm_unpacklo_epi8(y0, zero);
y1 = _mm_unpacklo_epi8(y1, zero);
y0 = _mm_mullo_epi16(y0, y0_fraction);
y1 = _mm_mullo_epi16(y1, y1_fraction);
y2 = _mm_mullo_epi16(y2, y0_fraction);
y3 = _mm_mullo_epi16(y3, y1_fraction);
y0 = _mm_add_epi16(y0, y1);
y2 = _mm_add_epi16(y2, y3);
y0 = _mm_srli_epi16(y0, 8);
y2 = _mm_srli_epi16(y2, 8);
y0 = _mm_packus_epi16(y0, y2);
*dest128++ = y0;
++y0_ptr128;
++y1_ptr128;
}
while (dest128 < end128);
}
#elif USE_MMX
// MMX version does 8 pixels at a time
static void FilterHorizontal(WebRtc_UWord8* ybuf,
const WebRtc_UWord8* y0_ptr,
const WebRtc_UWord8* y1_ptr,
WebRtc_UWord32 source_width,
WebRtc_UWord32 source_y_fraction)
{
__m64 zero = _mm_setzero_si64();
__m64 y1_fraction = _mm_set1_pi16(source_y_fraction);
__m64 y0_fraction = _mm_set1_pi16(256 - source_y_fraction);
const __m64* y0_ptr64 = reinterpret_cast<const __m64*>(y0_ptr);
const __m64* y1_ptr64 = reinterpret_cast<const __m64*>(y1_ptr);
__m64* dest64 = reinterpret_cast<__m64*>(ybuf);
__m64* end64 = reinterpret_cast<__m64*>(ybuf + source_width);
do
{
__m64 y0 = *y0_ptr64++;
__m64 y1 = *y1_ptr64++;
__m64 y2 = _mm_unpackhi_pi8(y0, zero);
__m64 y3 = _mm_unpackhi_pi8(y1, zero);
y0 = _mm_unpacklo_pi8(y0, zero);
y1 = _mm_unpacklo_pi8(y1, zero);
y0 = _mm_mullo_pi16(y0, y0_fraction);
y1 = _mm_mullo_pi16(y1, y1_fraction);
y2 = _mm_mullo_pi16(y2, y0_fraction);
y3 = _mm_mullo_pi16(y3, y1_fraction);
y0 = _mm_add_pi16(y0, y1);
y2 = _mm_add_pi16(y2, y3);
y0 = _mm_srli_pi16(y0, 8);
y2 = _mm_srli_pi16(y2, 8);
y0 = _mm_packs_pu16(y0, y2);
*dest64++ = y0;
}
while (dest64 < end64);
}
#else // no MMX or SSE2
// C version does 8 at a time to mimic MMX code
static void FilterHorizontal(WebRtc_UWord8* ybuf,
const WebRtc_UWord8* y0_ptr,
const WebRtc_UWord8* y1_ptr,
WebRtc_UWord32 source_width,
WebRtc_UWord32 source_y_fraction)
{
WebRtc_UWord32 y1_fraction = source_y_fraction;
WebRtc_UWord32 y0_fraction = 256 - y1_fraction;
WebRtc_UWord8* end = ybuf + source_width;
do
{
ybuf[0] = (y0_ptr[0] * y0_fraction + y1_ptr[0] * y1_fraction) >> 8;
ybuf[1] = (y0_ptr[1] * y0_fraction + y1_ptr[1] * y1_fraction) >> 8;
ybuf[2] = (y0_ptr[2] * y0_fraction + y1_ptr[2] * y1_fraction) >> 8;
ybuf[3] = (y0_ptr[3] * y0_fraction + y1_ptr[3] * y1_fraction) >> 8;
ybuf[4] = (y0_ptr[4] * y0_fraction + y1_ptr[4] * y1_fraction) >> 8;
ybuf[5] = (y0_ptr[5] * y0_fraction + y1_ptr[5] * y1_fraction) >> 8;
ybuf[6] = (y0_ptr[6] * y0_fraction + y1_ptr[6] * y1_fraction) >> 8;
ybuf[7] = (y0_ptr[7] * y0_fraction + y1_ptr[7] * y1_fraction) >> 8;
y0_ptr += 8;
y1_ptr += 8;
ybuf += 8;
}
while (ybuf < end);
}
#endif
static void FilterVertical(WebRtc_UWord8* ybuf,
const WebRtc_UWord8* y0_ptr,
WebRtc_UWord32 width,
WebRtc_UWord32 source_dx)
{
WebRtc_UWord32 x = 0;
for (WebRtc_UWord32 i = 0; i < width; i ++)
{
WebRtc_UWord32 y0 = y0_ptr[x >> 16];
WebRtc_UWord32 y1 = y0_ptr[(x >> 16) + 1];
WebRtc_UWord32 y_frac = (x & 65535);
ybuf[i] = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16;
x += source_dx;
}
}
WebRtc_Word32
ScaleBilinear(const WebRtc_UWord8* srcFrame, WebRtc_UWord8*& dstFrame,
WebRtc_UWord32 srcWidth, WebRtc_UWord32 srcHeight,
WebRtc_UWord32 dstWidth, WebRtc_UWord32 dstHeight,
WebRtc_UWord32& dstSize)
{
// Setting source
const WebRtc_UWord8* src = srcFrame;
WebRtc_UWord8* srcTmp = NULL;
const WebRtc_UWord32 srcStride = (srcWidth + 15) & ~15;
const WebRtc_UWord32 srcUvStride = (((srcStride + 1 >> 1) + 15) & ~15);
const WebRtc_UWord32 srcStrideArray[3] = {srcStride,
srcUvStride,
srcUvStride
};
const WebRtc_UWord32 srcWidthArray[3] = {srcWidth,
(srcWidth + 1) >> 1,
(srcWidth + 1) >> 1
};
// if srcFrame isn't aligned to nice boundaries then copy it over
// in another buffer
if ((srcStride > srcWidth) || (srcUvStride > ((srcWidth + 1) >> 1)))
{
// allocate buffer that can accommodate the stride
srcTmp = new WebRtc_UWord8[srcStride * srcHeight * 3 >> 1];
WebRtc_UWord8* tmpPlaneArray[3];
tmpPlaneArray[0] = srcTmp;
tmpPlaneArray[1] = tmpPlaneArray[0] + srcStride * srcHeight;
tmpPlaneArray[2] = tmpPlaneArray[1] +
(srcStride >> 1) * (srcHeight >> 1);
WebRtc_UWord8* tmpPtr = srcTmp;
const WebRtc_UWord8* srcPtr = srcFrame;
for (WebRtc_UWord32 p = 0; p < 3; p++)
{
WebRtc_UWord8* dstPtr = tmpPlaneArray[p];
const WebRtc_UWord32 h = (p == 0) ? srcHeight : srcHeight >> 1;
for (WebRtc_UWord32 i = 0; i < h; i++)
{
memcpy(dstPtr, srcPtr, srcWidthArray[p]);
dstPtr += srcStrideArray[p];
srcPtr += srcWidthArray[p];
}
}
src = srcTmp;
}
const WebRtc_UWord8* srcPlaneArray[3];
srcPlaneArray[0] = src;
srcPlaneArray[1] = srcPlaneArray[0] + srcStride * srcHeight;
srcPlaneArray[2] = srcPlaneArray[1] + (srcStride >> 1) * (srcHeight >> 1);
// Setting destination
const WebRtc_UWord32 dstStride = (dstWidth + 31) & ~31;
const WebRtc_UWord32 dstUvStride = (((dstStride + 1 >> 1) + 31) & ~31);
WebRtc_UWord32 dstRequiredSize = dstStride * dstHeight +
2 * (dstUvStride * ((dstHeight + 1) >> 1));
WebRtc_UWord32 dstFinalRequiredSize = dstWidth * dstHeight * 3 >> 1;
if (dstFrame && dstFinalRequiredSize > dstSize)
{
// allocated buffer is too small
delete [] dstFrame;
dstFrame = NULL;
}
if (dstFrame == NULL)
{
dstFrame = new WebRtc_UWord8[dstFinalRequiredSize];
dstSize = dstFinalRequiredSize;
}
WebRtc_UWord8* dstPtr = dstFrame;
WebRtc_UWord8* tmpDst = NULL;
if (dstFinalRequiredSize < dstRequiredSize)
{
// allocate a tmp buffer for destination
tmpDst = new WebRtc_UWord8[dstRequiredSize];
dstPtr = tmpDst;
}
WebRtc_UWord8* dstPlaneArray[3] = {dstPtr,
dstPlaneArray[0] + dstStride * dstHeight,
dstPlaneArray[1] +
(dstUvStride * ((dstHeight + 1) >> 1))
};
const WebRtc_UWord32 dstStrideArray[3] = {dstStride,
dstUvStride,
dstUvStride
};
const WebRtc_UWord32 dstWidthArray[3] = {dstWidth,
dstWidth>>1,
dstWidth>>1
};
for (WebRtc_UWord32 p = 0; p < 3; p++)
{
const WebRtc_UWord32 sh = (p == 0) ? srcHeight : srcHeight >> 1;
const WebRtc_UWord32 dh = (p == 0) ? dstHeight : dstHeight >> 1;
WebRtc_UWord8* filteredBuf = dstPlaneArray[p];
WebRtc_UWord8* horizontalFilteredBuf;
WebRtc_UWord8* intermediaryBuf = new WebRtc_UWord8[srcStrideArray[p]];
const WebRtc_UWord32 hscale_fixed = (sh << kFractionBits) / dh;
const WebRtc_UWord32 source_dx = srcWidthArray[p] * kFractionMax /
dstWidthArray[p];
for (WebRtc_UWord32 h = 0; h < dh; ++h)
{
horizontalFilteredBuf = filteredBuf;
if (source_dx != kFractionMax)
{
horizontalFilteredBuf = intermediaryBuf;
}
// horizontal filter
WebRtc_UWord32 source_h_subpixel = (h * hscale_fixed);
if (hscale_fixed >= (kFractionMax * 2))
{
// For 1/2 or less, center filter.
source_h_subpixel += kFractionMax / 2;
}
WebRtc_UWord32 source_h = source_h_subpixel >> kFractionBits;
const WebRtc_UWord8* ptr_0 = srcPlaneArray[p] +
source_h * srcStrideArray[p];
const WebRtc_UWord8* ptr_1 = ptr_0 + srcStrideArray[p];
// vertical scaler uses 16.8 fixed point
WebRtc_UWord32 source_h_fraction =
(source_h_subpixel & kFractionMask) >> 8;
if (hscale_fixed != kFractionMax &&
source_h_fraction && ((source_h + 1) < sh))
{
FilterHorizontal(horizontalFilteredBuf, ptr_0, ptr_1,
srcWidthArray[p], source_h_fraction);
}
else
{
memcpy(horizontalFilteredBuf, ptr_1, srcWidthArray[p]);
}
filteredBuf[srcWidthArray[p]] = filteredBuf[srcWidthArray[p]-1];
// vertical filter only if necessary
if (source_dx != kFractionMax)
{
FilterVertical(filteredBuf, horizontalFilteredBuf,
dstWidthArray[p], source_dx);
}
filteredBuf += dstStrideArray[p];
}
if (intermediaryBuf != NULL)
{
delete [] intermediaryBuf;
}
}
if (srcTmp != NULL)
{
delete [] srcTmp;
}
// Filtered image was placed in an aligned buffer. If the
// final output is not in an aligned buffer copy the image over.
if (dstStride > dstWidth)
{
WebRtc_UWord8* dstFramePtr = dstFrame;
for (WebRtc_UWord32 p = 0; p < 3; p++)
{
WebRtc_UWord8* dstPlanePtr = dstPlaneArray[p];
const WebRtc_UWord32 h = (p == 0) ? dstHeight : dstHeight >> 1;
for (WebRtc_UWord32 i = 0; i < h; i++)
{
memcpy(dstFramePtr, dstPlanePtr, dstWidthArray[p]);
dstFramePtr += dstWidthArray[p];
dstPlanePtr += dstStrideArray[p];
}
}
}
if (tmpDst != NULL)
{
delete [] tmpDst;
}
return dstHeight;
}
} // namespace webrtc

View File

@ -1,32 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
/*
* scale_bilinear_yuv.h
* yuv bilinear scaler
*/
#ifndef WEBRTC_COMMON_VIDEO_VPLIB_SCALE_BILINEAR_YUV_H
#define WEBRTC_COMMON_VIDEO_VPLIB_SCALE_BILINEAR_YUV_H
#include "typedefs.h"
#include "vplib.h"
namespace webrtc
{
WebRtc_Word32
ScaleBilinear(const WebRtc_UWord8* srcFrame, WebRtc_UWord8*& dstFrame,
WebRtc_UWord32 srcWidth, WebRtc_UWord32 srcHeight,
WebRtc_UWord32 dstWidth, WebRtc_UWord32 dstHeight,
WebRtc_UWord32& dstSize);
} // namespace webrtc
#endif // WEBRTC_COMMON_VIDEO_VPLIB_SCALE_BILINEAR_YUV_H

File diff suppressed because it is too large Load Diff

View File

@ -1,71 +0,0 @@
# Copyright (c) 2011 The WebRTC 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.
{
'includes': [
'../../../../common_settings.gypi', # Common settings
],
'targets': [
{
'target_name': 'webrtc_vplib',
'type': '<(library)',
'dependencies': [
],
'include_dirs': [
'../interface',
],
'direct_dependent_settings': {
'include_dirs': [
'../interface',
],
},
'sources': [
# interfaces
'../interface/vplib.h',
'../interface/interpolator.h',
# headers
'conversion_tables.h',
'scale_bilinear_yuv.h',
# sources
'vplib.cc',
'interpolator.cc',
'scale_bilinear_yuv.cc',
],
},
{
'target_name': 'vplib_test',
'type': 'executable',
'dependencies': [
'webrtc_vplib',
],
'include_dirs': [
'../interface',
'../source',
],
'sources': [
# headers
'../test/test_util.h',
# sources
'../test/tester_main.cc',
'../test/scale_test.cc',
'../test/convert_test.cc',
'../test/interpolation_test.cc',
], # source
},
],
}
# Local Variables:
# tab-width:2
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=2 shiftwidth=2:

View File

@ -1,368 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
// Test application for color space conversion functions
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <cmath>
#include <time.h>
#include "test_util.h"
#include "vplib.h"
using namespace webrtc;
// Optimization testing
//#define SCALEOPT //For Windows currently, June 2010
WebRtc_Word32
ImagePSNRfromBuffer(WebRtc_UWord8 *refBufName, WebRtc_UWord8 *testBufName,
WebRtc_Word32 width, WebRtc_Word32 height,
VideoType vType, double *YPSNRptr);
void TestRetVal(int testVal, int refVal );
int convert_test(CmdArgs& args)
{
// reading YUV frame - testing on the first frame of the foreman sequence
//SET UP
int j = 0;
int retVal;
std::string outname = args.outputFile;
if (outname == "")
{
outname = "conversionTest_out.yuv";
}
std::string inname;
inname = args.inputFile;
FILE* sourceFile;
FILE* outputFile;
FILE* logFile;
WebRtc_UWord32 width = args.width;
WebRtc_UWord32 height = args.height;
WebRtc_UWord32 lengthSourceFrame = width*height*3/2;
double psnr = 0;
if ((sourceFile = fopen(inname.c_str(), "rb")) == NULL)
{
printf("Cannot read file %s.\n", inname.c_str());
exit(1);
}
if ((outputFile = fopen(outname.c_str(), "wb")) == NULL)
{
printf("Cannot write file %s.\n", outname.c_str());
exit(1);
}
if ((logFile = fopen("../log.txt", "a")) == NULL)
{
printf("Cannot write file ../log.txt.\n");
exit(1);
}
// reading first frame of Foreman sequence
WebRtc_UWord8* origBuffer = new WebRtc_UWord8[width * height*3/2];
fread(origBuffer, 1, lengthSourceFrame, sourceFile);
// START TEST
printf("\nTEST #%d I420 <-> RGB24\n", j);
WebRtc_UWord8* resRGBBuffer2 = new WebRtc_UWord8[width*height*3];
WebRtc_UWord8* resI420Buffer = new WebRtc_UWord8[width*height*3/2];
retVal = ConvertFromI420(kRGB24, origBuffer, width, height,resRGBBuffer2);
TestRetVal(retVal, width*height*3);
clock_t tticks = clock();
for (int tt = 0; tt < 1000; tt++)
{
retVal = ConvertToI420(kRGB24, resRGBBuffer2, width, height,
resI420Buffer);
}
tticks = clock() - tticks;
printf("RGB24->I420 Time(1000): %d\n", tticks);
TestRetVal(retVal, width*height*3/2);
fwrite(resI420Buffer, lengthSourceFrame, 1, outputFile);
ImagePSNRfromBuffer(origBuffer, resI420Buffer, width, height, kI420, &psnr);
printf("Conversion between type #%d and type #%d, PSNR = %f\n", kI420,
kRGB24, psnr);
j++;
delete [] resRGBBuffer2;
printf("\nTEST #%d I420 <-> UYVY\n", j);
WebRtc_UWord8* outUYVYBuffer = new WebRtc_UWord8[width*height*2];
clock_t ticks = clock();
for (int t = 0; t < 100; t++)
{
retVal = ConvertFromI420(kUYVY, origBuffer, width,
height, outUYVYBuffer);
}
ticks = clock() - ticks;
#ifndef SCALEOPT
fprintf(logFile, "\nConvertI420ToUYVY, before opt: %d\n", ticks);
#else
fprintf(logFile, "\nConvertI420ToUYVY, after opt: %d\n", ticks);
#endif
TestRetVal(retVal, width*height*2);
retVal = ConvertToI420(kUYVY, outUYVYBuffer, width, height, resI420Buffer);
TestRetVal(retVal, width*height*3/2);
ImagePSNRfromBuffer(origBuffer, resI420Buffer, width, height, kI420, &psnr);
printf("Conversion between type #%d and type #%d, PSNR = %f\n",
kI420, kUYVY, psnr);
j++;
delete [] outUYVYBuffer;
printf("\nTEST #%d I420 <-> I420 \n", j);
WebRtc_UWord8* outI420Buffer = new WebRtc_UWord8[width*height*2];
retVal = ConvertToI420(kI420, origBuffer, width, height, outI420Buffer);
TestRetVal(retVal, width*height*3/2);
retVal = ConvertToI420(kI420 ,outI420Buffer, width, height, resI420Buffer);
TestRetVal(retVal, width*height*3/2);
fwrite(resI420Buffer, lengthSourceFrame, 1, outputFile);
ImagePSNRfromBuffer(origBuffer, resI420Buffer, width, height,
kI420, &psnr);
printf("Conversion between type #%d and type #%d, PSNR = %f\n",
kI420, kUYVY, psnr);
j++;
delete [] outI420Buffer;
printf("\nTEST #%d I420 <-> YV12\n", j);
outI420Buffer = new WebRtc_UWord8[width*height*3/2]; // assuming DIFF = 0
ticks = clock();
for (int t = 0; t < 1000; t++)
{
retVal = ConvertFromI420(kYV12, origBuffer, width, height, outI420Buffer);
}
ticks = clock() - ticks;
#ifndef SCALEOPT
fprintf(logFile, "\nConvertI420ToYV12, before opt: %d\n", ticks);
#else
fprintf(logFile, "\nConvertI420ToYV12, after opt: %d\n", ticks);
#endif
TestRetVal(retVal, width*height*3/2);
retVal = webrtc::ConvertYV12ToI420(outI420Buffer, width, height,
resI420Buffer);
TestRetVal(retVal, width*height*3/2);
fwrite(resI420Buffer, lengthSourceFrame, 1, outputFile);
ImagePSNRfromBuffer(origBuffer, resI420Buffer, width, height, kI420, &psnr);
printf("Conversion between type #%d and type #%d, PSNR = %f\n", kI420,
kYV12, psnr);
j++;
delete [] outI420Buffer;
delete [] resI420Buffer;
printf("\nTEST #%d I420<-> RGB565\n", j);
WebRtc_UWord8* res2ByteBuffer = new WebRtc_UWord8[width*height*2];
resI420Buffer = new WebRtc_UWord8[width * height * 3 / 2];
retVal = ConvertFromI420(kRGB565, origBuffer, width, height, res2ByteBuffer);
TestRetVal(retVal, width*height*2);
retVal = ConvertRGB565ToI420(res2ByteBuffer, width, height, resI420Buffer);
TestRetVal(retVal, width*height*3/2);
fwrite(resI420Buffer, lengthSourceFrame, 1, outputFile);
ImagePSNRfromBuffer(origBuffer, resI420Buffer, width, height, kI420, &psnr);
printf("Note: Frame was compressed!\n");
printf("Conversion between type #%d and type #%d, PSNR = %f\n", kI420,
kRGB565, psnr);
delete [] res2ByteBuffer;
j++;
printf("\nTEST #%d I420 <-> YUY2\n", j);
WebRtc_UWord8* outYUY2Buffer = new WebRtc_UWord8[width*height*2];
ticks = clock();
for (int t = 0; t < 1000; t++)
{
retVal = ConvertI420ToYUY2(origBuffer, outYUY2Buffer, width, height,0);
}
ticks = clock() - ticks;
#ifndef SCALEOPT
fprintf(logFile, "\nConvertI420ToYUY2, before opt: %d\n", ticks);
#else
fprintf(logFile, "\nConvertI420ToYUY2, after opt: %d\n", ticks);
#endif
TestRetVal(retVal, width*height*2);
ticks = clock();
for (int t = 0; t < 1000; t++)
{
retVal = ConvertToI420(kYUY2, outYUY2Buffer, width, height,
resI420Buffer);
}
ticks = clock() - ticks;
#ifndef SCALEOPT
fprintf(logFile, "\nConvertYUY2ToI420, before opt: %d\n", ticks);
#else
fprintf(logFile, "\nConvertYUY2ToI420, after opt: %d\n", ticks);
#endif
TestRetVal(retVal, width*height*3/2);
fwrite(resI420Buffer, lengthSourceFrame, 1, outputFile);
ImagePSNRfromBuffer(origBuffer, resI420Buffer, width, height, kI420, &psnr);
printf("Conversion between type #%d and type #%d,PSNR = %f\n", kI420,
kYUY2, psnr);
delete [] outYUY2Buffer;
j++;
printf("\nTEST #%d I420 <-> UYVY\n", j);
outUYVYBuffer = new WebRtc_UWord8[width*height*2]; // assuming DIFF = 0
WebRtc_UWord8* resYUVBuffer = new WebRtc_UWord8[width*height*2];
retVal = ConvertFromI420(kUYVY, origBuffer, width, height, outUYVYBuffer);
TestRetVal(retVal, width*height*2);
retVal = ConvertToI420(kUYVY, outUYVYBuffer, width, height, resYUVBuffer);
TestRetVal(retVal, width*height*3/2);
fwrite(resYUVBuffer, lengthSourceFrame, 1, outputFile);
ImagePSNRfromBuffer(origBuffer, resYUVBuffer, width, height, kI420, &psnr);
printf("Conversion between type #%d and type #%d,PSNR = %f\n", kI420,
kUYVY, psnr);
delete [] outUYVYBuffer;
delete [] resYUVBuffer;
j++;
/*******************************************************************
* THE FOLLOWING FUNCTIONS HAVE NO INVERSE, BUT ARE PART OF THE TEST
* IN ORDER TO VERIFY THAT THEY DO NOT CRASH
*******************************************************************/
printf("\n\n Running functions with no inverse...\n");
//printf("TEST #%d I420 -> ARGB4444 \n", j);
res2ByteBuffer = new WebRtc_UWord8[width*height*2];
ConvertI420ToARGB4444(origBuffer, res2ByteBuffer, width, height, 0);
delete [] res2ByteBuffer;
// YUY2 conversions
//printf("TEST #%d I420 -> YUY2 \n", j);
WebRtc_UWord8* sourceYUY2 = new WebRtc_UWord8[width*height*2];
ConvertI420ToYUY2(origBuffer, sourceYUY2, width, height, 0);
delete [] sourceYUY2;
//UYVY conversions
WebRtc_UWord8* sourceUYVY = new WebRtc_UWord8[width*height*2];
ConvertI420ToUYVY(origBuffer, sourceUYVY, width, height, 0);
//printf("TEST I420-> ARGB444\n");
res2ByteBuffer = new WebRtc_UWord8[(width+10)*height*2];
retVal = webrtc::ConvertI420ToARGB4444(origBuffer, res2ByteBuffer,
width, height, width + 10);
TestRetVal(retVal, (width+10)*height*2);
delete [] res2ByteBuffer;
//printf("TEST I420-> ARGB1555\n");
res2ByteBuffer = new WebRtc_UWord8[(width+10)*height*2];
retVal = ConvertI420ToARGB1555(origBuffer, res2ByteBuffer, width,
height, width + 10);
TestRetVal(retVal, (width+10)*height*2);
delete [] res2ByteBuffer;
//printf("TEST NV12 - > I420\n");
// using original I420 sequence - > just to verify it doesn't crash
ConvertNV12ToI420(origBuffer,resI420Buffer, width, height);
//printf("TEST NV12 - > I420 and Rotate 180\n");
ConvertNV12ToI420AndRotate180(origBuffer, resI420Buffer, width, height);
//printf("TEST NV12 - > I420 and Rotate anti Clockwise\n");
ConvertNV12ToI420AndRotateAntiClockwise(origBuffer, resI420Buffer,
width, height);
//printf("TEST NV12 - > I420 and Rotate Clockwise\n");
ConvertNV12ToI420AndRotateClockwise(origBuffer, resI420Buffer,
width, height);
//printf("TEST NV12 -> RGB565 \n");
res2ByteBuffer = new WebRtc_UWord8[(width+10)*height*2];
ConvertNV12ToRGB565(origBuffer, res2ByteBuffer, width, height);
delete [] res2ByteBuffer;
//printf("TEST I420 - > RGBAIPhone");
WebRtc_UWord8* resBuffer = new WebRtc_UWord8[(width + 10) * height * 4];
ConvertI420ToRGBAIPhone(origBuffer, resBuffer, width, height, width + 10);
delete [] resBuffer;
//printf("TEST #%d I420 <-> ARGB_Mac", j);
WebRtc_UWord8* outARGBBuffer = new WebRtc_UWord8[width * height * 4];
retVal = ConvertI420ToARGBMac(origBuffer,outARGBBuffer, width, height, 0);
TestRetVal(retVal, width * height * 4);
delete [] outARGBBuffer;
//closing
fclose(sourceFile);
fclose(outputFile);
fclose(logFile);
delete [] origBuffer;
delete [] resI420Buffer;
std::cout << "\n** View output file **\n";
std::cout << "Press enter to quit test...";
std::string str;
std::getline(std::cin, str);
return 0;
}
WebRtc_Word32
ImagePSNRfromBuffer(WebRtc_UWord8 *refBufName, WebRtc_UWord8 *testBufName,
WebRtc_Word32 width, WebRtc_Word32 height,
VideoType vType, double *YPSNRptr)
{
// currently assumes I420
if (vType != kI420)
{
return -1;
}
double mse = 0.0;
double mseLogSum = 0.0;
WebRtc_UWord8 *ref = refBufName;
WebRtc_UWord8 * test = testBufName;
// comparing only 1 frame
mse = 0.0;
// calculate Y sum-square-difference
for( int k = 0; k < width * height; k++ )
{
mse += (test[k] - ref[k]) * (test[k] - ref[k]);
}
// divide by number of pixels
mse /= (double) (width * height);
if (mse == 0)
{
*YPSNRptr = 48;
return 0;
}
// accumulate for total average
mseLogSum += std::log10( mse );
*YPSNRptr = 20.0 * std::log10(255.0) - 10.0 * mseLogSum;
return 0;
}
void TestRetVal(int testVal, int refVal )
{
if (testVal != refVal)
{
printf("return value = %d, desired value = %d\n", testVal, refVal);
}
}

View File

@ -1,22 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
#ifndef WEBRTC_COMMON_VIDEO_VPLIB_TEST_CONVERT_TEST_H
#define WEBRTC_COMMON_VIDEO_VPLIB_TEST_CONVERT_TEST_H
#include "vplib.h"
void ToFile(WebRtc_UWord8 *buf, WebRtc_Word32 length, WebRtc_Word32 num);
WebRtc_Word32
PSNRfromFiles(const WebRtc_Word8 *refFileName, const WebRtc_Word8 *testFileName, WebRtc_Word32 width,
WebRtc_Word32 height, WebRtc_Word32 numberOfFrames, double *YPSNRptr);
#endif

View File

@ -1,183 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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 <string.h>
#include <stdio.h>
#include <time.h>
#include "interpolator.h"
#include "vplib.h"
#include "test_util.h"
using namespace webrtc;
int interpolation_test(CmdArgs& args)
{
// Read input file, interpolate first frame according to requested method
// for now only YUV input and output
FILE* sourceFile;
FILE* outputFile;
std::string outname = args.outputFile;
if (outname == "")
{
outname = "InterTest_out.yuv";
}
if (args.width < 1 || args.height < 1 ||
args.dstWidth < 1 || args.dstHeight < 1)
{
printf("Error in input dimensions\n" );
return -1;
}
WebRtc_Word32 ret;
// create interpolator
webrtc::interpolator* inter = new webrtc::interpolator();
ret = inter->Set(args.width, args.height,
args.dstWidth, args.dstHeight,
kI420, kI420,
(webrtc::interpolatorType) args.intMethod);
if (ret != 0)
{
printf("Error in set interpolator = %d\n", ret);
delete inter;
return ret;
}
// read frame into buffer / create destination buffer
if ((outputFile = fopen(outname.c_str(), "wb")) == NULL)
{
printf("Cannot write file %s.\n", outname.c_str());
exit(1);
}
std::string inname = args.inputFile;
if ((sourceFile = fopen(inname.c_str(), "rb")) == NULL)
{
printf("Cannot read file %s.\n", inname.c_str());
exit(1);
}
WebRtc_UWord32 inRequiredSize = args.width * args.height * 3 >> 1;
WebRtc_UWord32 outRequiredSize = args.dstWidth * args.dstHeight * 3 >> 1;
WebRtc_UWord8* inputBuffer = new WebRtc_UWord8[inRequiredSize];
WebRtc_UWord8* outputBuffer = new WebRtc_UWord8[outRequiredSize];
WebRtc_UWord32 outputBufferSz = outRequiredSize;
clock_t startClock, TotalClock;
TotalClock = 0;
int frameCnt = 0;
// running through entire sequence
while (feof(sourceFile) == 0)
{
if (inRequiredSize != fread(inputBuffer, 1, inRequiredSize, sourceFile))
{
break;
}
startClock = clock();
ret = inter->Interpolate(inputBuffer, outputBuffer, outputBufferSz);
TotalClock += clock() - startClock;
if (ret == args.dstHeight)
{
fwrite(outputBuffer, 1, outRequiredSize, outputFile);
ret = 0; // signaling OK to main tester
}
else
{
printf("frame #%d: Interpolation Error, ret = %d\n", frameCnt, ret);
}
frameCnt++;
printf(".");
}
printf("\nProcessed %d frames\n", frameCnt);
if (frameCnt)
{
printf("\nAvg. Time per frame[mS]: %.2lf\n",
(1000.0 * static_cast<double>(TotalClock + 0.0)
/CLOCKS_PER_SEC)/frameCnt);
}
delete [] outputBuffer;
outputBuffer = NULL;
outputBufferSz = 0;
// running some sanity checks
ret = inter->Set(0, 10, 20, 30, kI420, kI420,
(webrtc::interpolatorType) args.intMethod);
TEST(ret < 0);
ret = inter->Set(1, 10, 0, 30, kI420, kI420,
(webrtc::interpolatorType) args.intMethod);
TEST(ret < 0);
rewind(sourceFile);
if (inRequiredSize != fread(inputBuffer, 1, inRequiredSize, sourceFile))
{
printf("Error reading input file\n");
return -1;
}
ret = inter->Set(20, 10, 20, 30, kI420, kI420,
(webrtc::interpolatorType) 2);
TEST(ret < 0);
ret = inter->Interpolate(inputBuffer, outputBuffer, outputBufferSz);
TEST(ret < 0);
// computing required size for user-defined settings
WebRtc_UWord32 dstRequiredSize = args.dstWidth * args.dstHeight * 3 >> 1;
// null output buffer - should allocate required size
ret = inter->Set(args.width, args.height,
args.dstWidth, args.dstHeight,
kI420, kI420,
(webrtc::interpolatorType) args.intMethod);
TEST(ret == 0);
ret = inter->Interpolate(inputBuffer, outputBuffer, outputBufferSz);
TEST(ret == args.dstHeight);
TEST(outputBufferSz == dstRequiredSize);
if (outputBuffer)
{
delete [] outputBuffer;
}
// output buffer too small (should reallocate)
outputBufferSz = dstRequiredSize / 2;
outputBuffer = new WebRtc_UWord8[outputBufferSz];
ret = inter->Interpolate(inputBuffer, outputBuffer, outputBufferSz);
TEST(ret == args.dstHeight);
TEST(outputBufferSz == dstRequiredSize);
if (outputBuffer)
{
delete [] outputBuffer;
}
// output buffer too large (should maintain existing buffer size)
outputBufferSz = dstRequiredSize + 20;
outputBuffer = new WebRtc_UWord8[outputBufferSz];
ret = inter->Interpolate(inputBuffer, outputBuffer, outputBufferSz);
TEST(ret == args.dstHeight);
TEST(outputBufferSz == dstRequiredSize + 20);
if (outputBuffer)
{
delete [] outputBuffer;
}
fclose(sourceFile);
fclose(outputFile);
delete inter;
delete [] inputBuffer;
return 0;
}

View File

@ -1,695 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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 <cassert>
#include <iostream>
#include <string>
#include "vplib.h"
#include <cstring>
using namespace webrtc;
#define TEST_STR "Test Scale."
#define TEST_PASSED() std::cerr << TEST_STR << " : [OK]" << std::endl
#define PRINT_LINE std::cout << "------------------------------------------" << std::endl;
void PrintFrame(WebRtc_UWord8* ptrFrame, WebRtc_Word32 width, WebRtc_Word32 height)
{
WebRtc_Word32 k = 0;
for (WebRtc_Word32 i = 0; i < height; i++)
{
for (WebRtc_Word32 j = 0; j < width; j++)
{
std::cout << (WebRtc_Word32)ptrFrame[k++] << " ";
}
std::cout << " " << std::endl;
}
std::cout << " " << std::endl;
}
void PrintFrame(WebRtc_UWord8* ptrInFrame, WebRtc_Word32 width, WebRtc_Word32 height, const WebRtc_Word8* str)
{
std::cout << str << " (" << width << "x" << height << ") = " << std::endl;
WebRtc_UWord8* ptrFrameY = ptrInFrame;
WebRtc_UWord8* ptrFrameCb = ptrFrameY + width*height;
WebRtc_UWord8* ptrFrameCr = ptrFrameCb + width*height/4;
PrintFrame(ptrFrameY, width, height);
PrintFrame(ptrFrameCb, width/2, height/2);
PrintFrame(ptrFrameCr, width/2, height/2);
}
void CreateImage(WebRtc_Word32 width, WebRtc_Word32 height, WebRtc_UWord8* ptrFrame, WebRtc_Word32 offset, WebRtc_Word32 heightFactor, WebRtc_Word32 widthFactor = 0)
{
for (WebRtc_Word32 i = 0; i < height; i++)
{
for (WebRtc_Word32 j = 0; j < width; j++)
{
*ptrFrame = (WebRtc_UWord8)((i + offset)*heightFactor + j*widthFactor);
ptrFrame++;
}
}
}
void ValidateImage2(WebRtc_Word32 width, WebRtc_Word32 height, WebRtc_UWord8* ptrFrame, WebRtc_Word32 offset, WebRtc_Word32 factor)
{
WebRtc_Word32 k = 0;
WebRtc_Word32 res = offset*factor;
for (WebRtc_Word32 i = 0; i < height; i++)
{
for (WebRtc_Word32 j = 0; j < width; j++)
{
assert(ptrFrame[k++] == res);
}
if (i > 0)
{
res += factor/2;
}
}
}
void ValidateImage3_2(WebRtc_Word32 width, WebRtc_Word32 height, WebRtc_UWord8* ptrFrame, WebRtc_Word32 offset, WebRtc_Word32 factor)
{
WebRtc_Word32 k = 0;
bool inc = true;
WebRtc_Word32 res = offset*factor;
for (WebRtc_Word32 i = 1; i <= height; i++)
{
for (WebRtc_Word32 j = 0; j < width; j++)
{
assert(ptrFrame[k++] == res);
}
res += factor/2;
if ((i % 3) == 0)
{
res += factor/2;
}
}
}
void ValidateImage1_3(WebRtc_Word32 width, WebRtc_Word32 height, WebRtc_UWord8* ptrFrame, WebRtc_Word32 offset, WebRtc_Word32 factor)
{
WebRtc_Word32 k = 0;
WebRtc_Word32 res = offset*factor;
res += factor/2;
for (WebRtc_Word32 i = 0; i < height; i++)
{
for (WebRtc_Word32 j = 0; j < width; j++)
{
assert(ptrFrame[k++] == res);
}
res += factor*3;
}
}
static void VerifyInBounds(const WebRtc_UWord8* ptrImage, const WebRtc_Word32 imageLength,
const WebRtc_Word32 startOffset, const WebRtc_Word32 endOffset)
{
// Verify that function does not write outside buffer
const WebRtc_UWord8* ptrFrameStart = ptrImage - startOffset;
const WebRtc_UWord8* ptrFrameEnd = ptrImage + imageLength;
// Verify that function does not write outside buffer
for (WebRtc_Word32 i = 0; i < startOffset; i++)
{
assert(ptrFrameStart[i] == 255);
}
for (WebRtc_Word32 i = 0; i < endOffset; i++)
{
assert(ptrFrameEnd[i] == 255);
}
}
WebRtc_Word32
VerifyAndAllocateTest(WebRtc_UWord8*& buffer, WebRtc_Word32 currentSize, WebRtc_Word32 newSize)
{
if(newSize > currentSize)
{
// make sure that our buffer is big enough
WebRtc_UWord8* newBuffer = new WebRtc_UWord8[newSize];
if(buffer)
{
// copy the old data
memcpy(newBuffer, buffer, currentSize);
delete [] buffer;
}
buffer = newBuffer;
return newSize;
}
return currentSize;
}
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
int
scale_test()
{
std::string str;
std::cout << "--------------------------------" << std::endl;
std::cout << "-------- Test Scaling ----------" << std::endl;
std::cout << "--------------------------------" << std::endl;
std::cout << " " << std::endl;
// -------------------------------
// Test ScaleI420Up2() -----------
// -------------------------------
PRINT_LINE;
std::cout << "Test ScaleI420Up2()" << std::endl;
PRINT_LINE;
WebRtc_UWord32 width = 12;
WebRtc_UWord32 height = 10;
WebRtc_Word32 factorY = 2;
WebRtc_Word32 factorCb = 10;
WebRtc_Word32 factorCr = 20;
WebRtc_Word32 offset = 5;
WebRtc_Word32 startBufferOffset = 10;
WebRtc_UWord32 length = CalcBufferSize(kI420, width, height);
// Test bad inputs
WebRtc_UWord32 scW = 0;
WebRtc_UWord32 scH = 0;
WebRtc_UWord8* testFrame = new WebRtc_UWord8[length + offset];
WebRtc_Word32 retVal = ScaleI420Up2(0, height,testFrame,length, scW, scH);
assert(retVal == -1);
retVal = ScaleI420Up2(width, 0, testFrame,length, scW, scH);
assert(retVal == -1);
retVal = ScaleI420Up2(49, height, testFrame, length, scW, scH);
assert(retVal == -1);
retVal = ScaleI420Up2(width, 3, testFrame,length, scW, scH); // odd height
assert(retVal == -1);
retVal = ScaleI420Up2(width + 2, height, testFrame,length, scW, scH); // width, height > allocated buffer size
assert(retVal == -1);
retVal = ScaleI420Up2(width, height + 2, testFrame,length, scW, scH); // width, height > allocated buffer size
assert(retVal == -1);
retVal = ScaleI420Up2(width, height, testFrame,length, scW, scH); // width, height == allocated buffer size, OK
assert(retVal == scW * scH * 3 / 2);
delete [] testFrame;
testFrame = new WebRtc_UWord8[ length * 4 + startBufferOffset * 2];
memset(testFrame, 255, length * 4 + startBufferOffset * 2);
// Create input frame
WebRtc_UWord8* ptrFrameY = testFrame;
WebRtc_UWord8* ptrFrameCb = ptrFrameY + width*height;
WebRtc_UWord8* ptrFrameCr = ptrFrameCb + width*height/4;
CreateImage(width, height, ptrFrameY, offset, factorY); // Y
CreateImage(width/2, height/2, ptrFrameCb, offset, factorCb); // Cb
CreateImage(width/2, height/2, ptrFrameCr, offset, factorCr); // Cr
PrintFrame(testFrame, width, height, "InputFrame");
// Scale frame to twice its size
WebRtc_UWord32 scaledWidth = 0;
WebRtc_UWord32 scaledHeight = 0;
retVal = ScaleI420Up2(width, height, testFrame, length * 4 + startBufferOffset * 2, scaledWidth, scaledHeight);
PrintFrame(testFrame, scaledWidth, scaledHeight, "Output Frame");
// Validate results
assert(retVal == scaledWidth * scaledHeight * 3 / 2);
ptrFrameY = testFrame;
ptrFrameCb = ptrFrameY + scaledWidth*scaledHeight;
ptrFrameCr = ptrFrameCb + scaledWidth*scaledHeight/4;
ValidateImage2(scaledWidth, scaledHeight, ptrFrameY, offset, factorY);
ValidateImage2(scaledWidth/2, scaledHeight/2, ptrFrameCb, offset, factorCb);
ValidateImage2(scaledWidth/2, scaledHeight/2, ptrFrameCr, offset, factorCr);
delete [] testFrame;
// --------------------------------
// Test ScaleI420Up3_2() ----------
// --------------------------------
PRINT_LINE;
std::cout << "Test ScaleI420Up3_2()" << std::endl;
PRINT_LINE;
width = 12;
height = 8;
factorY = 2;
factorCb = 10;
factorCr = 20;
offset = 5;
startBufferOffset = 10;
length = CalcBufferSize(kI420, width, height);
// Test bad inputs
testFrame = new WebRtc_UWord8[length];
retVal = ScaleI420Up3_2(0, height, testFrame,length, scW, scH);
assert(retVal == -1);
retVal = ScaleI420Up3_2(width, 0, testFrame,length, scW, scH);
assert(retVal == -1);
retVal = ScaleI420Up3_2(49, height, testFrame,length, scW, scH); // odd width
assert(retVal == -1);
retVal = ScaleI420Up3_2(width, 3, testFrame,length, scW, scH); // odd height
assert(retVal == -1);
retVal = ScaleI420Up3_2(width, 10, testFrame,length, scW, scH); // odd height (color)
assert(retVal == -1);
retVal = ScaleI420Up3_2(14, height, testFrame,length, scW, scH); // odd width (color)
assert(retVal == -1);
retVal = ScaleI420Up3_2(width + 2, height, testFrame,length, scW, scH); // width, height > allocated buffer size
assert(retVal == -1);
retVal = ScaleI420Up3_2(width, height + 2, testFrame,length, scW, scH); // width, height > allocated buffer size
assert(retVal == -1);
retVal = ScaleI420Up3_2(width, height, testFrame,length, scW, scH); // width, height == allocated buffer size, OK
assert(retVal == scW * scH * 3 / 2);
delete [] testFrame;
testFrame = new WebRtc_UWord8[length + startBufferOffset];
memset(testFrame, 255, length + startBufferOffset);
// Create input frame
ptrFrameY = testFrame;
ptrFrameCb = ptrFrameY + width*height;
ptrFrameCr = ptrFrameCb + width*height/4;
CreateImage(width, height, ptrFrameY, offset, factorY); // Y
CreateImage(width/2, height/2, ptrFrameCb, offset, factorCb); // Cb
CreateImage(width/2, height/2, ptrFrameCr, offset, factorCr); // Cr
PrintFrame(testFrame, width, height, "Input Frame");
// Scale frame to 1.5 times its size
scaledWidth = 0;
scaledHeight = 0;
retVal = ScaleI420Up3_2(width, height, testFrame, length + startBufferOffset, scaledWidth, scaledHeight);
PrintFrame(testFrame, scaledWidth, scaledHeight, "Output Frame");
// Validate results
assert(retVal == scaledWidth * scaledHeight * 3 / 2);
// Verify that function does not write outside buffer
ptrFrameY = testFrame;//imageBuffer.GetBuffer();
ptrFrameCb = ptrFrameY + scaledWidth*scaledHeight;
ptrFrameCr = ptrFrameCb + scaledWidth*scaledHeight/4;
ValidateImage3_2(scaledWidth, scaledHeight, ptrFrameY, offset, factorY);
ValidateImage3_2(scaledWidth/2, scaledHeight/2, ptrFrameCb, offset, factorCb);
ValidateImage3_2(scaledWidth/2, scaledHeight/2, ptrFrameCr, offset, factorCr);
delete [] testFrame;
// --------------------------------
// Test ScaleI420Down1_3() ----------
// --------------------------------
PRINT_LINE;
std::cout << "Test ScaleI420Up1_3()" << std::endl;
PRINT_LINE;
width = 10;
height = 8;
factorY = 2;
factorCb = 10;
factorCr = 20;
offset = 5;
startBufferOffset = 10;
length = webrtc::CalcBufferSize(kI420, width, height);
// Test bad inputs
testFrame = new WebRtc_UWord8[length];
retVal = ScaleI420Down1_3(0, height, testFrame, length, scW, scH);
assert(retVal == -1);
retVal = ScaleI420Down1_3(width, 0, testFrame, length, scW, scH);
assert(retVal == -1);
retVal = ScaleI420Down1_3(49, height, testFrame, length, scW, scH); // odd width
assert(retVal == -1);
retVal = ScaleI420Down1_3(width, 3, testFrame, length, scW, scH); // odd height
assert(retVal == -1);
retVal = ScaleI420Down1_3(width + 2, height, testFrame, length, scW, scH); // width, height > allocated buffer size
assert(retVal == -1);
retVal = ScaleI420Down1_3(width, height + 2, testFrame, length, scW, scH); // width, height > allocated buffer size
assert(retVal == -1);
retVal = ScaleI420Down1_3(width, height, testFrame, length, scW, scH); // width, height == allocated buffer size, ok
assert(retVal == scW * scH * 3 / 2);
delete [] testFrame;
testFrame = new WebRtc_UWord8[length + startBufferOffset * 2];
memset(testFrame, 255, length + startBufferOffset * 2);
// Create input frame
ptrFrameY = testFrame;
ptrFrameCb = ptrFrameY + width*height;
ptrFrameCr = ptrFrameCb + width*height/4;
CreateImage(width, height, ptrFrameY, offset, factorY); // Y
CreateImage(width/2, height/2, ptrFrameCb, offset, factorCb); // Cb
CreateImage(width/2, height/2, ptrFrameCr, offset, factorCr); // Cr
PrintFrame(testFrame, width, height, "Input Frame");
// Scale frame to one third its size
scaledWidth = 0;
scaledHeight = 0;
retVal = ScaleI420Down1_3(width, height, testFrame, length + startBufferOffset * 2 , scaledWidth, scaledHeight);
PrintFrame(testFrame, scaledWidth, scaledHeight, "Output Frame");
// Validate results
assert(retVal == scaledWidth * scaledHeight * 3 / 2);
// Verify that function does not write outside buffer
ptrFrameY = testFrame;//imageBuffer.GetBuffer();
ptrFrameCb = ptrFrameY + scaledWidth*scaledHeight;
ptrFrameCr = ptrFrameCb + scaledWidth*scaledHeight/4;
ValidateImage1_3(scaledWidth, scaledHeight, ptrFrameY, offset, factorY);
ValidateImage1_3(scaledWidth/2, scaledHeight/2, ptrFrameCb, offset, factorCb);
ValidateImage1_3(scaledWidth/2, scaledHeight/2, ptrFrameCr, offset, factorCr);
delete [] testFrame;
// -------------------
// Test PadI420Frame()
// -------------------
PRINT_LINE;
std::cout << "Test PadI420Frame()" << std::endl;
PRINT_LINE;
width = 16;
height = 8;
factorY = 1;
factorCb = 1;
factorCr = 1;
offset = 5;
startBufferOffset = 10;
length = CalcBufferSize(kI420, width, height);
testFrame = new WebRtc_UWord8[length];
memset(testFrame, 255, length);
// Create input frame
ptrFrameY = testFrame;//imageBuffer.GetBuffer();
ptrFrameCb = ptrFrameY + width*height;
ptrFrameCr = ptrFrameCb + width*height/4;
CreateImage(width, height, ptrFrameY, 1, factorY); // Y
CreateImage(width/2, height/2, ptrFrameCb, 100, factorCb); // Cb
CreateImage(width/2, height/2, ptrFrameCr, 200, factorCr); // Cr
PrintFrame(testFrame, width, height, "Input Frame");
WebRtc_UWord8* testFrame2 = new WebRtc_UWord8[352*288];
// Test bad input
assert(PadI420Frame(NULL, testFrame2, 16, 16, 32, 32) == -1);
assert(PadI420Frame(testFrame, NULL, 16, 16, 32, 32) == -1);
assert(PadI420Frame(testFrame, testFrame2, 0, 16, 32, 32) == -1);
assert(PadI420Frame(testFrame, testFrame2, 16, 0, 32, 32) == -1);
assert(PadI420Frame(testFrame, testFrame2, 16, 16, 0, 32) == -1);
assert(PadI420Frame(testFrame, testFrame2, 16, 16, 32, 0) == -1);
assert(PadI420Frame(testFrame, testFrame2, 16, 16, 8, 32) == -1);
assert(PadI420Frame(testFrame, testFrame2, 16, 16, 32, 8) == -1);
assert(PadI420Frame(testFrame, testFrame2, 16, 16, 16, 16) == 3 * 16 * 16 / 2);
enum { NumOfPaddedSizes = 4 };
WebRtc_Word32 paddedWidth[NumOfPaddedSizes] = { 32, 22, 16, 20 };
WebRtc_Word32 paddedHeight[NumOfPaddedSizes] = { 16, 14, 12, 8 };
for (WebRtc_Word32 i = 0; i < NumOfPaddedSizes; i++)
{
scaledWidth = paddedWidth[i];
scaledHeight = paddedHeight[i];
WebRtc_Word32 toLength = webrtc::CalcBufferSize(kI420, scaledWidth, scaledHeight);
if (testFrame2)
{
delete [] testFrame2;
}
testFrame2 = new WebRtc_UWord8[toLength + startBufferOffset * 2];
memset(testFrame2, 255, toLength + startBufferOffset * 2);
retVal = webrtc::PadI420Frame(testFrame, testFrame2, width, height, scaledWidth, scaledHeight);
PrintFrame(testFrame2, scaledWidth, scaledHeight, "Output Frame");
// Validate results
assert(retVal == toLength);
}
std::cout << "Do the padded frames look correct?" << std::endl
<< "(Padded dimensions which are multiples of 16 will have the" << std::endl
<< "padding applied in blocks of 16)" << std::endl
<< "Press enter to continue...";
std::getline(std::cin, str);
// -----------------
// Test video sizes
// -----------------
const WebRtc_Word32 nr = 16;
// currently not keeping video sizes as a type - testing scaling functions only
WebRtc_UWord16 widths[nr] = {128, 160, 176, 320, 352, 640, 720, 704, 800, 960, 1024, 1440, 400, 800, 1280, 1920};
WebRtc_UWord16 heights[nr] = { 96, 120, 144, 240, 288, 480, 480, 576, 600, 720, 768, 1080, 240, 480, 720, 1080};
for (WebRtc_Word32 j = 0; j < 3; j++)
{
for (WebRtc_Word32 i = 0; i < nr; i++)
{
width = widths[i];
height = heights[i];
factorY = 2;
factorCb = 2;
factorCr = 2;
offset = 2;
startBufferOffset = 10;
length = webrtc::CalcBufferSize(kI420, width, height);
float f = 1;
if (j == 0)
{
f = 2;
}
else if (j == 1)
{
f = 1.5;
}
else if (j == 2)
{
f = 1;
}
if (testFrame)
{
delete testFrame;
testFrame = 0;
}
WebRtc_Word32 frameSize = (WebRtc_Word32) ((length * f * f) + startBufferOffset * 2);
testFrame = new WebRtc_UWord8[frameSize];
memset(testFrame, 255, frameSize);
// Create input frame
ptrFrameY = testFrame;
ptrFrameCb = ptrFrameY + width*height;
ptrFrameCr = ptrFrameCb + width*height/4;
CreateImage(width, height, ptrFrameY, offset, factorY); // Y
CreateImage(width/2, height/2, ptrFrameCb, offset, factorCb); // Cb
CreateImage(width/2, height/2, ptrFrameCr, offset, factorCr); // Cr
scaledWidth = 0;
scaledHeight = 0;
if (j == 0)
{
retVal = ScaleI420Up2(width, height, testFrame,frameSize, scaledWidth, scaledHeight);
length = scaledWidth*scaledHeight*3/2;
}
else if (j == 1)
{
retVal = ScaleI420Up3_2(width, height, testFrame,frameSize, scaledWidth, scaledHeight);
length = scaledWidth*scaledHeight*3/2;
}
else if (j == 2)
{
retVal = ScaleI420Down1_3(width, height, testFrame,frameSize, scaledWidth, scaledHeight);
length = width*height*3/2;
}
// Validate results
assert(retVal == scaledWidth * scaledHeight * 3 / 2);
}
}
// ---------------------
// Test mirror functions
// ---------------------
std::cout << "Test Mirror function" << std::endl;
// 4:2:0 images can't have odd width or height
width = 16;
height = 8;
factorY = 1;
factorCb = 1;
factorCr = 1;
offset = 5;
startBufferOffset = 10;
length = webrtc::CalcBufferSize(kI420, width, height);
delete [] testFrame;
testFrame = new WebRtc_UWord8[length];
memset(testFrame, 255, length);
// Create input frame
WebRtc_UWord8* inFrame = testFrame;
ptrFrameCb = inFrame + width * height;
ptrFrameCr = ptrFrameCb + (width * height) / 4;
CreateImage(width, height, inFrame, 10, factorY, 1); // Y
CreateImage(width/2, height/2, ptrFrameCb, 100, factorCb, 1); // Cb
CreateImage(width/2, height/2, ptrFrameCr, 200, factorCr, 1); // Cr
PrintFrame(testFrame, width, height, "Input Frame");
if (testFrame2)
{
delete [] testFrame2;
testFrame2 = 0;
}
testFrame2 = new WebRtc_UWord8[length + startBufferOffset * 2];
memset(testFrame2, 255, length + startBufferOffset * 2);
WebRtc_UWord8* outFrame = testFrame2;
// LeftRight
std::cout << "Test Mirror function: LeftRight" << std::endl;
retVal = MirrorI420LeftRight(inFrame, outFrame, width, height);
PrintFrame(testFrame2, width, height, "Output Frame");
retVal = MirrorI420LeftRight(outFrame, outFrame, width, height);
assert(memcmp(inFrame, outFrame, length) == 0);
//VerifyInBounds(outFrame, length, startBufferOffset, startBufferOffset);
//UpDown
std::cout << "Test Mirror function: UpDown" << std::endl;
retVal = MirrorI420UpDown(inFrame, outFrame, width, height);
PrintFrame(testFrame2, width, height, "Output Frame");
retVal = MirrorI420UpDown(outFrame, outFrame, width, height);
assert(memcmp(inFrame, outFrame, length) == 0);
//VerifyInBounds(outFrame, length, startBufferOffset, startBufferOffset);
std::cout << "Do the mirrored frames look correct?" << std::endl
<< "Press enter to continue...";
std::getline(std::cin, str);
// end Mirror Function check
delete [] testFrame;
testFrame = new WebRtc_UWord8[length];
memset(testFrame,255,length);
inFrame = testFrame;
CreateImage(width, height, inFrame, 10, factorY, 1); // Y
CreateImage(width/2, height/2, ptrFrameCb, 100, factorCb, 1); // Cb
CreateImage(width/2, height/2, ptrFrameCr, 200, factorCr, 1); // Cr
PrintFrame(inFrame, width, height, "Input frame");
delete [] testFrame2;
testFrame2 = new WebRtc_UWord8[length];
memset(testFrame2, 255, length);
int yv12Size = CalcBufferSize(kI420, kYV12, length);
WebRtc_UWord8* yv12TestFrame = new WebRtc_UWord8[yv12Size];
memset(yv12TestFrame, 255, yv12Size);
outFrame = testFrame2;
retVal = ConvertI420ToYV12(inFrame, yv12TestFrame, width, height, 0);
assert(retVal >= 0);
// Test convert and mirror functions
ConvertToI420AndMirrorUpDown(yv12TestFrame, outFrame, width, height, kYV12);
std::cout << "Test: ConvertAndMirrorUpDown" << std::endl;
PrintFrame(outFrame, width, height, "Output Frame");
MirrorI420UpDown(outFrame, outFrame, width, height);
assert(memcmp(inFrame, outFrame, length) == 0);
std::cout << "Does the converted (U and V flipped) mirrored frame look correct?" << std::endl
<< "Press enter to continue...";
std::getline(std::cin, str);
delete [] testFrame2;
PrintFrame(inFrame, width, height, "Input frame");
// Test convert and rotate functions
testFrame2 = new WebRtc_UWord8[length];
memset(testFrame2, 255, length);
outFrame = testFrame2;
WebRtc_UWord8* tempFrame = new WebRtc_UWord8[length];
ConvertToI420(kYV12, yv12TestFrame, width, height, outFrame, false, kRotateAntiClockwise);
std::cout << "Test: ConvertAndRotateAntiClockwise" << std::endl;
PrintFrame(outFrame, height, width, "Output Frame");
ConvertToI420(kI420, outFrame, height, width, tempFrame, false, kRotateAntiClockwise);
ConvertToI420(kI420, tempFrame, width, height, outFrame, false, kRotateAntiClockwise);
ConvertToI420(kI420, outFrame, height, width, tempFrame, false, kRotateAntiClockwise);
assert(memcmp(inFrame, tempFrame, length) == 0);
delete [] testFrame2;
testFrame2 = new WebRtc_UWord8[length];
outFrame = testFrame2;
memset(outFrame, 255, length);
memset(tempFrame, 255, length);
ConvertToI420(kYV12, yv12TestFrame, width, height, outFrame, false, kRotateClockwise);
std::cout << "Test: ConvertAndRotateClockwise" << std::endl;
PrintFrame(outFrame, height, width, "Output Frame");
ConvertToI420(kI420, outFrame, height, width, tempFrame, false, kRotateClockwise);
ConvertToI420(kI420, tempFrame, width, height, outFrame, false, kRotateClockwise);
ConvertToI420(kI420, outFrame, height, width, tempFrame, false, kRotateClockwise);
assert(memcmp(inFrame, tempFrame, length) == 0);
delete [] testFrame2;
std::cout << "Do the converted (U and V flipped) and rotated frames look correct?" << std::endl
<< "Press enter to continue...";
std::getline(std::cin, str);
PrintFrame(inFrame, width, height, "Input frame");
// Test rotation with padding
height += 4;
length = width * height * 3 / 2;
testFrame2 = new WebRtc_UWord8[length];
memset(testFrame2, 255, length);
outFrame = testFrame2;
webrtc::ConvertToI420(kYV12, yv12TestFrame, width, height - 4, outFrame, false, webrtc::kRotateClockwise);
std::cout << "Test: ConvertAndRotateClockwise (width padding)" << std::endl;
PrintFrame(outFrame, height, width, "Output Frame");
width += 4;
height -= 4;
memset(testFrame2, 255, length);
outFrame = testFrame2;
ConvertToI420(kYV12, yv12TestFrame, width - 4, height, outFrame, false, webrtc::kRotateAntiClockwise);
std::cout << "Test: ConvertAndRotateClockwise (height padding)" << std::endl;
PrintFrame(outFrame, height, width, "Output Frame");
std::cout << "Do the rotated and padded images look correct?" << std::endl
<< "Press enter to continue...";
std::getline(std::cin, str);
delete [] tempFrame;
tempFrame = NULL;
delete [] testFrame;
testFrame = NULL;
delete [] testFrame2;
testFrame2 = NULL;
delete [] yv12TestFrame;
yv12TestFrame = NULL;
TEST_PASSED();
std::cout << "Press enter to quit test...";
std::getline(std::cin, str);
return 0;
}

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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.
*/
#ifndef COMMON_VIDEO_VPLIB_TEST_UTIL_H
#define COMMON_VIDEO_VPLIB_TEST_UTIL_H
#include <string.h>
#include <fstream>
#include <cstdlib>
class CmdArgs
{
public:
CmdArgs() : width(-1), height(-1), dstWidth(-1), dstHeight(-1),
intMethod(-1), inputFile(""), outputFile(""), testNum(-1)
{}
int width;
int height;
int dstWidth;
int dstHeight;
int intMethod;
std::string inputFile;
std::string outputFile;
int testNum;
};
int interpolationTest(CmdArgs& args);
int convert_test(CmdArgs& args);
int scale_test();
#endif // COMMON_VIDEO_VPLIB_TEST_UTIL_H

View File

@ -1,133 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "vplib.h"
#include "test_util.h"
using namespace webrtc;
int ParseArguments(int argc, char **argv, CmdArgs& args)
{
int i = 1;
while (i < argc)
{
if (argv[i][0] != '-')
{
return -1;
}
switch (argv[i][1])
{
case 'w':
{
int w = atoi(argv[i+1]);
if (w < 1)
return -1;
args.width = w;
break;
}
case 'h':
{
int h = atoi(argv[i+1]);
if (h < 1)
return -1;
args.height = h;
break;
}
case 'x':
{
int x = atoi(argv[i+1]);
if (x < 1)
return -1;
args.dstWidth = x;
break;
}
case 'y':
{
int y = atoi(argv[i+1]);
if (y < 1)
return -1;
args.dstHeight = y;
break;
}
case 'm': // interpolation method
{
int m = atoi(argv[i+1]);
if (m < 0)
return -1;
args.intMethod = m;
break;
}
case 'i':
{
args.inputFile = argv[i+1];
break;
}
case 'o':
args.outputFile = argv[i+1];
break;
case 'n':
{
int n = atoi(argv[i+1]);
if (n < 1)
return -1;
args.testNum = n;
break;
}
default:
return -1;
}
i += 2;
}
return 0;
}
int main(int argc, char **argv)
{
CmdArgs args;
if (ParseArguments(argc, argv, args) != 0)
{
printf("Unable to parse input arguments\n");
printf("args: -n <test #> -w <width> -h <height> "
"-x <destination width> -y <destination height> -f <fps> "
"-b <bps> -m <method> -i <input file> -o <output file>\n");
return -1;
}
int ret = -1;
switch (args.testNum)
{
printf("\n");
case 1:
printf("VPLIB Interpolation Test\n");
ret = interpolation_test(args);
break;
case 2:
printf("VPLIB Scale Test\n");
ret = scale_test();
break;
case 3:
printf("VPLIB Convert Test\n");
ret = convert_test(args);
break;
default:
ret = -1;
break;
}
if (ret != 0)
{
printf("Test failed!\n");
return -1;
}
return 0;
}