1 // Copyright 2015 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 //////////////////////////////////////////////////////////////////////////////// 16 // 17 // This file offers functions to determine the type of binary input source. The 18 // type recognition here is not 100% accurate, it only offers a quick and rough 19 // check about the input source. The general functions use RangeCheckedBytePtr 20 // as input, there are also linux only functions that use StringPiece as input. 21 // A linux only IsRawLite() method is also implemented. 22 // The "lite" implementation focuses on performance and guarantees to not read 23 // more than specified by GetNumberOfBytesForIsRawLite. 24 25 #ifndef PIEX_IMAGE_TYPE_RECOGNITION_IMAGE_TYPE_RECOGNITION_LITE_H_ 26 #define PIEX_IMAGE_TYPE_RECOGNITION_IMAGE_TYPE_RECOGNITION_LITE_H_ 27 28 #include <stddef.h> 29 30 #include "src/binary_parse/range_checked_byte_ptr.h" 31 32 namespace piex { 33 namespace image_type_recognition { 34 35 // Type of RAW images. Keep the order in alphabet. 36 enum RawImageTypes { 37 // Non-RAW-image type 38 kNonRawImage = 0, 39 40 // raw image types 41 kArwImage, 42 kCr2Image, 43 kCr3Image, 44 kCrwImage, 45 kDcrImage, 46 kDngImage, 47 kKdcImage, 48 kMosImage, 49 kMrwImage, 50 kNefImage, 51 kNrwImage, 52 kOrfImage, 53 kPefImage, 54 kQtkImage, 55 kRafImage, 56 kRawContaxNImage, 57 kRw2Image, 58 kSrwImage, 59 kX3fImage, 60 }; 61 62 // Checks if the given type is a RAW image type. 63 bool IsRaw(const RawImageTypes type); 64 65 // Checks if the given source is from given type. 66 bool IsOfType(const binary_parse::RangeCheckedBytePtr& source, 67 const RawImageTypes type); 68 69 // This function will check the source and return the corresponding image type. 70 // If the source is not a recognizable type, this function will return 71 // kNonRawImage. 72 RawImageTypes RecognizeRawImageTypeLite( 73 const binary_parse::RangeCheckedBytePtr& source); 74 75 // Returns the maximum number of bytes needed to recognize a RAW image type in 76 // IsRawLite(). 77 size_t GetNumberOfBytesForIsRawLite(); 78 79 // Returns the maximum number of bytes needed to recognize a RAF image type in 80 // IsOfType(). 81 size_t GetNumberOfBytesForIsOfType(const RawImageTypes type); 82 83 // This function will check if the source belongs to one of the known RAW types. 84 bool IsRawLite(const binary_parse::RangeCheckedBytePtr& source); 85 86 } // namespace image_type_recognition 87 } // namespace piex 88 89 #endif // PIEX_IMAGE_TYPE_RECOGNITION_IMAGE_TYPE_RECOGNITION_LITE_H_ 90