blob: 8d74ca0275040d80bc5aaf3866002342a586b12c [file] [log] [blame]
Jaesung Chung29345532016-01-14 02:28:47 +09001// 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// The purpose of the preview-image-extractor (piex) is to find and extract the
18// largest JPEG compressed preview image contained in a RAW file.
Jaesung Chung29345532016-01-14 02:28:47 +090019//
20// Even for unsupported RAW files we want to provide high quality images using a
21// dedicated, small and portable library. That is possible by taking the preview
22// image contained in all RAW files.
23//
24// Typically a preview image is stored as JPEG compressed, full size (or at
25// least half size) image in a RAW file.
26//
27// A typical client code snippet:
28//
29// // In C++
30// PreviewImageData image_data;
31// unique_ptr<StreamInterface> data_stream(new DataStream(file));
32// Error err = GetPreviewImageData(data_stream.get(), &image_data));
33// if (err == Error::kFail) {
34// // The input data seems to be broken.
35// return;
36// } else if (err == Error::kUnsupported) {
37// // The input data is not supported.
38// return;
39// }
40//
41// // Uncompress the JPEG as usual, e.g. on Android with the BitmapFactory:
42// // In Java
43// Bitmap bitmap = BitmapFactory.decodeByteArray(
Yujie Qin3eaa8312016-01-15 16:22:20 +010044// file.at(image_data.preview_offset), image_data.preview_length);
Jaesung Chung29345532016-01-14 02:28:47 +090045
46#ifndef PIEX_PIEX_H_
47#define PIEX_PIEX_H_
48
49#include <string>
50#include <vector>
51
Nick Chusid5c5b6712021-06-03 15:33:24 -040052#include "src/image_type_recognition/image_type_recognition_lite.h"
Jaesung Chung29345532016-01-14 02:28:47 +090053#include "src/piex_types.h"
54
55namespace piex {
56
57// Returns the maximum number of bytes IsRaw() will read from the stream.
58size_t BytesRequiredForIsRaw();
59
60// Returns true if 'data' contains a RAW file format, even if it is not
61// supported by Piex, false otherwise. Reads at most BytesRequiredForIsRaw()
62// from the stream.
63bool IsRaw(StreamInterface* data);
64
65// Gets the largest JPEG compressed preview image data. On success
66// 'preview_image_data' contains image metadata, the unverified length and the
67// offset to a JPEG compressed image from the beginning of the file.
68//
69// Returns 'kFail' when something with the data is wrong.
70// Returns 'kUnsupported' if file format is not supported.
71//
Yujie Qin3eaa8312016-01-15 16:22:20 +010072// One could check the "preview_image_data->preview_length != 0" for the
73// existance of a preview image.
Nick Chusid5c5b6712021-06-03 15:33:24 -040074//
75// Updates output_type based on data, if output_type is non-null.
76Error GetPreviewImageData(
77 StreamInterface* data, PreviewImageData* preview_image_data,
78 image_type_recognition::RawImageTypes* output_type = nullptr);
Jaesung Chung29345532016-01-14 02:28:47 +090079
Yujie Qin2f5d8ea2016-04-06 12:55:08 +020080// Returns true if the full width and height and the mosaic pattern dimension of
81// a DNG image could be obtained. False otherwise.
82bool GetDngInformation(StreamInterface* data, std::uint32_t* width,
83 std::uint32_t* height,
84 std::vector<std::uint32_t>* cfa_pattern_dim);
85
86// Returns true if Exif orientation for the image can be obtained. False
87// otherwise.
88bool GetOrientation(StreamInterface* data, std::uint32_t* orientation);
89
Jaesung Chung29345532016-01-14 02:28:47 +090090// Returns a vector of upper case file extensions, which are used as a first
91// step to quickly guess a supported file format.
92std::vector<std::string> SupportedExtensions();
93
94} // namespace piex
95
96#endif // PIEX_PIEX_H_