1*4d671364SKiyoung Kim // Copyright 2015 Google Inc. 2*4d671364SKiyoung Kim // 3*4d671364SKiyoung Kim // Licensed under the Apache License, Version 2.0 (the "License"); 4*4d671364SKiyoung Kim // you may not use this file except in compliance with the License. 5*4d671364SKiyoung Kim // You may obtain a copy of the License at 6*4d671364SKiyoung Kim // 7*4d671364SKiyoung Kim // http://www.apache.org/licenses/LICENSE-2.0 8*4d671364SKiyoung Kim // 9*4d671364SKiyoung Kim // Unless required by applicable law or agreed to in writing, software 10*4d671364SKiyoung Kim // distributed under the License is distributed on an "AS IS" BASIS, 11*4d671364SKiyoung Kim // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*4d671364SKiyoung Kim // See the License for the specific language governing permissions and 13*4d671364SKiyoung Kim // limitations under the License. 14*4d671364SKiyoung Kim // 15*4d671364SKiyoung Kim //////////////////////////////////////////////////////////////////////////////// 16*4d671364SKiyoung Kim // 17*4d671364SKiyoung Kim // The purpose of the preview-image-extractor (piex) is to find and extract the 18*4d671364SKiyoung Kim // largest JPEG compressed preview image contained in a RAW file. 19*4d671364SKiyoung Kim // 20*4d671364SKiyoung Kim // Even for unsupported RAW files we want to provide high quality images using a 21*4d671364SKiyoung Kim // dedicated, small and portable library. That is possible by taking the preview 22*4d671364SKiyoung Kim // image contained in all RAW files. 23*4d671364SKiyoung Kim // 24*4d671364SKiyoung Kim // Typically a preview image is stored as JPEG compressed, full size (or at 25*4d671364SKiyoung Kim // least half size) image in a RAW file. 26*4d671364SKiyoung Kim // 27*4d671364SKiyoung Kim // A typical client code snippet: 28*4d671364SKiyoung Kim // 29*4d671364SKiyoung Kim // // In C++ 30*4d671364SKiyoung Kim // PreviewImageData image_data; 31*4d671364SKiyoung Kim // unique_ptr<StreamInterface> data_stream(new DataStream(file)); 32*4d671364SKiyoung Kim // Error err = GetPreviewImageData(data_stream.get(), &image_data)); 33*4d671364SKiyoung Kim // if (err == Error::kFail) { 34*4d671364SKiyoung Kim // // The input data seems to be broken. 35*4d671364SKiyoung Kim // return; 36*4d671364SKiyoung Kim // } else if (err == Error::kUnsupported) { 37*4d671364SKiyoung Kim // // The input data is not supported. 38*4d671364SKiyoung Kim // return; 39*4d671364SKiyoung Kim // } 40*4d671364SKiyoung Kim // 41*4d671364SKiyoung Kim // // Uncompress the JPEG as usual, e.g. on Android with the BitmapFactory: 42*4d671364SKiyoung Kim // // In Java 43*4d671364SKiyoung Kim // Bitmap bitmap = BitmapFactory.decodeByteArray( 44*4d671364SKiyoung Kim // file.at(image_data.preview_offset), image_data.preview_length); 45*4d671364SKiyoung Kim 46*4d671364SKiyoung Kim #ifndef PIEX_PIEX_H_ 47*4d671364SKiyoung Kim #define PIEX_PIEX_H_ 48*4d671364SKiyoung Kim 49*4d671364SKiyoung Kim #include <string> 50*4d671364SKiyoung Kim #include <vector> 51*4d671364SKiyoung Kim 52*4d671364SKiyoung Kim #include "src/image_type_recognition/image_type_recognition_lite.h" 53*4d671364SKiyoung Kim #include "src/piex_types.h" 54*4d671364SKiyoung Kim 55*4d671364SKiyoung Kim namespace piex { 56*4d671364SKiyoung Kim 57*4d671364SKiyoung Kim // Returns the maximum number of bytes IsRaw() will read from the stream. 58*4d671364SKiyoung Kim size_t BytesRequiredForIsRaw(); 59*4d671364SKiyoung Kim 60*4d671364SKiyoung Kim // Returns true if 'data' contains a RAW file format, even if it is not 61*4d671364SKiyoung Kim // supported by Piex, false otherwise. Reads at most BytesRequiredForIsRaw() 62*4d671364SKiyoung Kim // from the stream. 63*4d671364SKiyoung Kim bool IsRaw(StreamInterface* data); 64*4d671364SKiyoung Kim 65*4d671364SKiyoung Kim // Gets the largest JPEG compressed preview image data. On success 66*4d671364SKiyoung Kim // 'preview_image_data' contains image metadata, the unverified length and the 67*4d671364SKiyoung Kim // offset to a JPEG compressed image from the beginning of the file. 68*4d671364SKiyoung Kim // 69*4d671364SKiyoung Kim // Returns 'kFail' when something with the data is wrong. 70*4d671364SKiyoung Kim // Returns 'kUnsupported' if file format is not supported. 71*4d671364SKiyoung Kim // 72*4d671364SKiyoung Kim // One could check the "preview_image_data->preview_length != 0" for the 73*4d671364SKiyoung Kim // existance of a preview image. 74*4d671364SKiyoung Kim // 75*4d671364SKiyoung Kim // Updates output_type based on data, if output_type is non-null. 76*4d671364SKiyoung Kim Error GetPreviewImageData( 77*4d671364SKiyoung Kim StreamInterface* data, PreviewImageData* preview_image_data, 78*4d671364SKiyoung Kim image_type_recognition::RawImageTypes* output_type = nullptr); 79*4d671364SKiyoung Kim 80*4d671364SKiyoung Kim // Returns true if the full width and height and the mosaic pattern dimension of 81*4d671364SKiyoung Kim // a DNG image could be obtained. False otherwise. 82*4d671364SKiyoung Kim bool GetDngInformation(StreamInterface* data, std::uint32_t* width, 83*4d671364SKiyoung Kim std::uint32_t* height, 84*4d671364SKiyoung Kim std::vector<std::uint32_t>* cfa_pattern_dim); 85*4d671364SKiyoung Kim 86*4d671364SKiyoung Kim // Returns true if Exif orientation for the image can be obtained. False 87*4d671364SKiyoung Kim // otherwise. 88*4d671364SKiyoung Kim bool GetOrientation(StreamInterface* data, std::uint32_t* orientation); 89*4d671364SKiyoung Kim 90*4d671364SKiyoung Kim // Returns a vector of upper case file extensions, which are used as a first 91*4d671364SKiyoung Kim // step to quickly guess a supported file format. 92*4d671364SKiyoung Kim std::vector<std::string> SupportedExtensions(); 93*4d671364SKiyoung Kim 94*4d671364SKiyoung Kim } // namespace piex 95*4d671364SKiyoung Kim 96*4d671364SKiyoung Kim #endif // PIEX_PIEX_H_ 97