Commit b36eeee8 authored by fbarchard@google.com's avatar fbarchard@google.com

Validate MJPG test performance.

BUG=210
TEST=none
Review URL: https://webrtc-codereview.appspot.com/1268004

git-svn-id: http://libyuv.googlecode.com/svn/trunk@626 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent 8c9de166
Name: libyuv
URL: http://code.google.com/p/libyuv/
Version: 624
Version: 626
License: BSD
License File: LICENSE
......
......@@ -23,6 +23,8 @@ struct jpeg_source_mgr;
namespace libyuv {
bool ValidateJpeg(const uint8* sample, size_t sample_size);
static const uint32 kUnknownDataSize = 0xFFFFFFFF;
enum JpegSubsamplingType {
......
......@@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
#define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 624
#define LIBYUV_VERSION 626
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
......@@ -18,6 +18,7 @@
'testing/gtest.gyp:gtest_main',
],
'defines': [
'HAVE_JPEG',
'LIBYUV_SVNREVISION="<!(svnversion -n)"',
# Enable the following 3 macros to turn off assembly for specified CPU.
# 'LIBYUV_DISABLE_X86',
......
......@@ -18,6 +18,9 @@
#include "libyuv/convert_from_argb.h"
#include "libyuv/cpu_id.h"
#include "libyuv/format_conversion.h"
#ifdef HAVE_JPEG
#include "libyuv/mjpeg_decoder.h"
#endif
#include "libyuv/planar_functions.h"
#include "libyuv/rotate.h"
#include "../unit_test/unit_test.h"
......@@ -35,7 +38,7 @@ namespace libyuv {
#define TESTPLANARTOPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \
FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, W1280, N, NEG, OFF) \
TEST_F(libyuvTest, SRC_FMT_PLANAR##To##FMT_PLANAR##N) { \
const int kWidth = W1280 > 1 ? W1280 : 1; \
const int kWidth = W1280; \
const int kHeight = benchmark_height_; \
align_buffer_64(src_y, kWidth * kHeight + OFF); \
align_buffer_64(src_u, \
......@@ -170,7 +173,7 @@ TESTPLANARTOP(I444, 1, 1, I444, 1, 1)
#define TESTPLANARTOBPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \
FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, W1280, N, NEG, OFF) \
TEST_F(libyuvTest, SRC_FMT_PLANAR##To##FMT_PLANAR##N) { \
const int kWidth = W1280 > 1 ? W1280 : 1; \
const int kWidth = W1280; \
const int kHeight = benchmark_height_; \
align_buffer_64(src_y, kWidth * kHeight + OFF); \
align_buffer_64(src_u, \
......@@ -273,7 +276,7 @@ TESTPLANARTOBP(I420, 2, 2, NV21, 2, 2)
#define TESTBIPLANARTOPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \
FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, W1280, N, NEG, OFF) \
TEST_F(libyuvTest, SRC_FMT_PLANAR##To##FMT_PLANAR##N) { \
const int kWidth = W1280 > 1 ? W1280 : 1; \
const int kWidth = W1280; \
const int kHeight = benchmark_height_; \
align_buffer_64(src_y, kWidth * kHeight + OFF); \
align_buffer_64(src_uv, 2 * SUBSAMPLE(kWidth, SRC_SUBSAMP_X) * \
......@@ -389,7 +392,7 @@ TESTBIPLANARTOP(NV21, 2, 2, I420, 2, 2)
#define TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \
W1280, DIFF, N, NEG, OFF, FMT_C, BPP_C) \
TEST_F(libyuvTest, FMT_PLANAR##To##FMT_B##N) { \
const int kWidth = W1280 > 1 ? W1280 : 1; \
const int kWidth = W1280; \
const int kHeight = benchmark_height_; \
const int kStrideB = ((kWidth * 8 * BPP_B + 7) / 8 + ALIGN - 1) / \
ALIGN * ALIGN; \
......@@ -503,7 +506,7 @@ TESTPLANARTOB(I420, 2, 2, I400, 1, 1, 0, ARGB, 4)
#define TESTBIPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, \
W1280, DIFF, N, NEG, OFF) \
TEST_F(libyuvTest, FMT_PLANAR##To##FMT_B##N) { \
const int kWidth = W1280 > 1 ? W1280 : 1; \
const int kWidth = W1280; \
const int kHeight = benchmark_height_; \
const int kStrideB = kWidth * BPP_B; \
align_buffer_64(src_y, kWidth * kHeight + OFF); \
......@@ -582,7 +585,7 @@ TESTBIPLANARTOB(NV21, 2, 2, RGB565, 2, 9)
#define TESTATOPLANARI(FMT_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \
W1280, DIFF, N, NEG, OFF) \
TEST_F(libyuvTest, FMT_A##To##FMT_PLANAR##N) { \
const int kWidth = W1280 > 1 ? W1280 : 1; \
const int kWidth = W1280; \
const int kHeight = benchmark_height_; \
const int kStride = (kWidth * 8 * BPP_A + 7) / 8; \
align_buffer_64(src_argb, kStride * kHeight + OFF); \
......@@ -712,7 +715,7 @@ TESTATOPLANAR(BayerGRBG, 1, I420, 2, 2, 4)
#define TESTATOBIPLANARI(FMT_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \
W1280, N, NEG, OFF) \
TEST_F(libyuvTest, FMT_A##To##FMT_PLANAR##N) { \
const int kWidth = W1280 > 1 ? W1280 : 1; \
const int kWidth = W1280; \
const int kHeight = benchmark_height_; \
const int kStride = (kWidth * 8 * BPP_A + 7) / 8; \
align_buffer_64(src_argb, kStride * kHeight + OFF); \
......@@ -789,7 +792,7 @@ TESTATOBIPLANAR(ARGB, 4, NV21, 2, 2)
FMT_B, BPP_B, STRIDE_B, \
W1280, DIFF, N, NEG, OFF) \
TEST_F(libyuvTest, FMT_A##To##FMT_B##N) { \
const int kWidth = W1280 > 1 ? W1280 : 1; \
const int kWidth = W1280; \
const int kHeight = benchmark_height_; \
const int kStrideA = (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \
const int kStrideB = (kWidth * BPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \
......@@ -814,7 +817,6 @@ TEST_F(libyuvTest, FMT_A##To##FMT_B##N) { \
} \
int max_diff = 0; \
for (int i = 0; i < kStrideB * kHeight; ++i) { \
EXPECT_NEAR(dst_argb_c[i], dst_argb_opt[i], DIFF); \
int abs_diff = \
abs(static_cast<int>(dst_argb_c[i]) - \
static_cast<int>(dst_argb_opt[i])); \
......@@ -860,7 +862,6 @@ TEST_F(libyuvTest, FMT_A##To##FMT_B##_Random) { \
int abs_diff = \
abs(static_cast<int>(dst_argb_c[i]) - \
static_cast<int>(dst_argb_opt[i])); \
EXPECT_NEAR(dst_argb_c[i], dst_argb_opt[i], DIFF); \
if (abs_diff > max_diff) { \
max_diff = abs_diff; \
} \
......@@ -905,7 +906,7 @@ TESTATOB(ARGB, 4, 4, 1, BayerGRBG, 1, 2, 2, 0)
TESTATOB(ARGB, 4, 4, 1, YUY2, 2, 4, 1, 4)
TESTATOB(ARGB, 4, 4, 1, UYVY, 2, 4, 1, 4)
TESTATOB(ARGB, 4, 4, 1, I400, 1, 1, 1, 2)
TESTATOB(ARGB, 4, 4, 1, J400, 1, 1, 1, 0)
TESTATOB(ARGB, 4, 4, 1, J400, 1, 1, 1, 2)
TESTATOB(BGRA, 4, 4, 1, ARGB, 4, 4, 1, 0)
TESTATOB(ABGR, 4, 4, 1, ARGB, 4, 4, 1, 0)
TESTATOB(RGBA, 4, 4, 1, ARGB, 4, 4, 1, 0)
......@@ -940,4 +941,51 @@ TEST_F(libyuvTest, Test565) {
EXPECT_EQ(610919429u, checksum);
}
#ifdef HAVE_JPEG
TEST_F(libyuvTest, ValidateJpeg) {
const int kOff = 10;
const int kSize = benchmark_width_ * benchmark_height_ + kOff;
align_buffer_64(orig_pixels, benchmark_width_ * benchmark_height_ + kOff);
// No SOI or EOI. Expect fail.
memset(orig_pixels, 0, kSize);
// EOI, SOI. Expect pass.
orig_pixels[0] = 0xff;
orig_pixels[1] = 0xd8; // SOI.
orig_pixels[kSize - kOff + 0] = 0xff;
orig_pixels[kSize - kOff + 1] = 0xd9; // EOI.
for (int times = 0; times < benchmark_iterations_; ++times) {
EXPECT_TRUE(ValidateJpeg(orig_pixels, kSize));
}
free_aligned_buffer_page_end(orig_pixels);
}
TEST_F(libyuvTest, InvalidateJpeg) {
const int kOff = 10;
const int kSize = benchmark_width_ * benchmark_height_ + kOff;
align_buffer_64(orig_pixels, kSize);
// No SOI or EOI. Expect fail.
memset(orig_pixels, 0, kSize);
EXPECT_FALSE(ValidateJpeg(orig_pixels, kSize));
// SOI but no EOI. Expect fail.
orig_pixels[0] = 0xff;
orig_pixels[1] = 0xd8; // SOI.
for (int times = 0; times < benchmark_iterations_; ++times) {
EXPECT_FALSE(ValidateJpeg(orig_pixels, kSize));
}
// EOI but no SOI. Expect fail.
orig_pixels[0] = 0;
orig_pixels[1] = 0;
orig_pixels[kSize - kOff + 0] = 0xff;
orig_pixels[kSize - kOff + 1] = 0xd9; // EOI.
EXPECT_FALSE(ValidateJpeg(orig_pixels, kSize));
free_aligned_buffer_page_end(orig_pixels);
}
#endif
} // namespace libyuv
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment