Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2012 The LibYuv Project Authors. All rights reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include "libyuv/mjpeg_decoder.h" |
michael@0 | 12 | |
michael@0 | 13 | #ifdef __cplusplus |
michael@0 | 14 | namespace libyuv { |
michael@0 | 15 | extern "C" { |
michael@0 | 16 | #endif |
michael@0 | 17 | |
michael@0 | 18 | // Helper function to validate the jpeg appears intact. |
michael@0 | 19 | // TODO(fbarchard): Optimize case where SOI is found but EOI is not. |
michael@0 | 20 | LIBYUV_BOOL ValidateJpeg(const uint8* sample, size_t sample_size) { |
michael@0 | 21 | size_t i; |
michael@0 | 22 | if (sample_size < 64) { |
michael@0 | 23 | // ERROR: Invalid jpeg size: sample_size |
michael@0 | 24 | return LIBYUV_FALSE; |
michael@0 | 25 | } |
michael@0 | 26 | if (sample[0] != 0xff || sample[1] != 0xd8) { // Start Of Image |
michael@0 | 27 | // ERROR: Invalid jpeg initial start code |
michael@0 | 28 | return LIBYUV_FALSE; |
michael@0 | 29 | } |
michael@0 | 30 | for (i = sample_size - 2; i > 1;) { |
michael@0 | 31 | if (sample[i] != 0xd9) { |
michael@0 | 32 | if (sample[i] == 0xff && sample[i + 1] == 0xd9) { // End Of Image |
michael@0 | 33 | return LIBYUV_TRUE; // Success: Valid jpeg. |
michael@0 | 34 | } |
michael@0 | 35 | --i; |
michael@0 | 36 | } |
michael@0 | 37 | --i; |
michael@0 | 38 | } |
michael@0 | 39 | // ERROR: Invalid jpeg end code not found. Size sample_size |
michael@0 | 40 | return LIBYUV_FALSE; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | #ifdef __cplusplus |
michael@0 | 44 | } // extern "C" |
michael@0 | 45 | } // namespace libyuv |
michael@0 | 46 | #endif |
michael@0 | 47 |