Home | History | Annotate | Download | only in image_type_recognition
      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   kCrwImage,
     44   kDcrImage,
     45   kDngImage,
     46   kKdcImage,
     47   kMosImage,
     48   kMrwImage,
     49   kNefImage,
     50   kNrwImage,
     51   kOrfImage,
     52   kPefImage,
     53   kQtkImage,
     54   kRafImage,
     55   kRawContaxNImage,
     56   kRw2Image,
     57   kSrwImage,
     58   kX3fImage,
     59 };
     60 
     61 // Checks if the given type is a RAW image type.
     62 bool IsRaw(const RawImageTypes type);
     63 
     64 // Checks if the given source is from given type.
     65 bool IsOfType(const binary_parse::RangeCheckedBytePtr& source,
     66               const RawImageTypes type);
     67 
     68 // This function will check the source and return the corresponding image type.
     69 // If the source is not a recognizable type, this function will return
     70 // kNonRawImage.
     71 RawImageTypes RecognizeRawImageTypeLite(
     72     const binary_parse::RangeCheckedBytePtr& source);
     73 
     74 // Returns the maximum number of bytes needed to recognize a RAW image type in
     75 // IsRawLite().
     76 size_t GetNumberOfBytesForIsRawLite();
     77 
     78 // Returns the maximum number of bytes needed to recognize a RAF image type in
     79 // IsOfType().
     80 size_t GetNumberOfBytesForIsOfType(const RawImageTypes type);
     81 
     82 // This function will check if the source belongs to one of the known RAW types.
     83 bool IsRawLite(const binary_parse::RangeCheckedBytePtr& source);
     84 
     85 }  // namespace image_type_recognition
     86 }  // namespace piex
     87 
     88 #endif  // PIEX_IMAGE_TYPE_RECOGNITION_IMAGE_TYPE_RECOGNITION_LITE_H_
     89