michael@0: /* michael@0: * Copyright 2012 The LibYuv Project Authors. All rights reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: #include "libyuv/mjpeg_decoder.h" michael@0: michael@0: #ifdef __cplusplus michael@0: namespace libyuv { michael@0: extern "C" { michael@0: #endif michael@0: michael@0: // Helper function to validate the jpeg appears intact. michael@0: // TODO(fbarchard): Optimize case where SOI is found but EOI is not. michael@0: LIBYUV_BOOL ValidateJpeg(const uint8* sample, size_t sample_size) { michael@0: size_t i; michael@0: if (sample_size < 64) { michael@0: // ERROR: Invalid jpeg size: sample_size michael@0: return LIBYUV_FALSE; michael@0: } michael@0: if (sample[0] != 0xff || sample[1] != 0xd8) { // Start Of Image michael@0: // ERROR: Invalid jpeg initial start code michael@0: return LIBYUV_FALSE; michael@0: } michael@0: for (i = sample_size - 2; i > 1;) { michael@0: if (sample[i] != 0xd9) { michael@0: if (sample[i] == 0xff && sample[i + 1] == 0xd9) { // End Of Image michael@0: return LIBYUV_TRUE; // Success: Valid jpeg. michael@0: } michael@0: --i; michael@0: } michael@0: --i; michael@0: } michael@0: // ERROR: Invalid jpeg end code not found. Size sample_size michael@0: return LIBYUV_FALSE; michael@0: } michael@0: michael@0: #ifdef __cplusplus michael@0: } // extern "C" michael@0: } // namespace libyuv michael@0: #endif michael@0: