mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2025-12-06 16:56:55 +08:00
BUG=212 TESTED=manual test by removing mjpeg_decode.cc from gyp file and built/ran unittests Review URL: https://webrtc-codereview.appspot.com/1310007 git-svn-id: http://libyuv.googlecode.com/svn/trunk@656 16f28f9a-4ce2-e073-06de-1de4eb20be90
42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
/*
|
|
* Copyright 2012 The LibYuv Project Authors. All rights reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "libyuv/mjpeg_decoder.h"
|
|
|
|
namespace libyuv {
|
|
|
|
// Helper function to validate the jpeg appears intact.
|
|
// TODO(fbarchard): Optimize case where SOI is found but EOI is not.
|
|
bool ValidateJpeg(const uint8* sample, size_t sample_size) {
|
|
if (sample_size < 64) {
|
|
// ERROR: Invalid jpeg size: sample_size
|
|
return false;
|
|
}
|
|
if (sample[0] != 0xff || sample[1] != 0xd8) { // Start Of Image
|
|
// ERROR: Invalid jpeg initial start code
|
|
return false;
|
|
}
|
|
for (int i = static_cast<int>(sample_size) - 2; i > 1;) {
|
|
if (sample[i] != 0xd9) {
|
|
if (sample[i] == 0xff && sample[i + 1] == 0xd9) { // End Of Image
|
|
return true;
|
|
}
|
|
--i;
|
|
}
|
|
--i;
|
|
}
|
|
// ERROR: Invalid jpeg end code not found. Size sample_size
|
|
return false;
|
|
}
|
|
|
|
} // namespace libyuv
|
|
|
|
|