xref: /aosp_15_r20/external/sandboxed-api/contrib/libraw/utils/utils_libraw.h (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1 // Copyright 2022 Google LLC
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 //     https://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 #ifndef CONTRIB_LIBRAW_UTILS_UTILS_LIBRAW_H_
16 #define CONTRIB_LIBRAW_UTILS_UTILS_LIBRAW_H_
17 
18 #include <vector>
19 
20 #include "absl/log/die_if_null.h"
21 #include "contrib/libraw/sandboxed.h"
22 
23 enum LibRaw_errors {
24   LIBRAW_SUCCESS = 0,
25   LIBRAW_UNSPECIFIED_ERROR = -1,
26   LIBRAW_FILE_UNSUPPORTED = -2,
27   LIBRAW_REQUEST_FOR_NONEXISTENT_IMAGE = -3,
28   LIBRAW_OUT_OF_ORDER_CALL = -4,
29   LIBRAW_NO_THUMBNAIL = -5,
30   LIBRAW_UNSUPPORTED_THUMBNAIL = -6,
31   LIBRAW_INPUT_CLOSED = -7,
32   LIBRAW_NOT_IMPLEMENTED = -8,
33   LIBRAW_UNSUFFICIENT_MEMORY = -100007,
34   LIBRAW_DATA_ERROR = -100008,
35   LIBRAW_IO_ERROR = -100009,
36   LIBRAW_CANCELLED_BY_CALLBACK = -100010,
37   LIBRAW_BAD_CROP = -100011,
38   LIBRAW_TOO_BIG = -100012,
39   LIBRAW_MEMPOOL_OVERFLOW = -100013
40 };
41 
42 class LibRaw {
43  public:
LibRaw(LibRawSapiSandbox * sandbox,const std::string & file_name)44   LibRaw(LibRawSapiSandbox* sandbox, const std::string& file_name)
45       : sandbox_(ABSL_DIE_IF_NULL(sandbox)),
46         api_(sandbox_),
47         file_name_(file_name) {
48     init_status_ = InitLibRaw();
49   }
50 
51   ~LibRaw();
52 
53   absl::Status CheckIsInit();
54   bool IsInit();
55 
56   libraw_data_t GetImgData();
57   absl::StatusOr<std::vector<uint16_t>> RawData();
58 
59   absl::Status OpenFile();
60   absl::Status Unpack();
61   absl::Status SubtractBlack();
62   absl::StatusOr<std::vector<char*>> GetCameraList();
63   absl::StatusOr<int> COLOR(int row, int col);
64   absl::StatusOr<int> GetRawHeight();
65   absl::StatusOr<int> GetRawWidth();
66   absl::StatusOr<unsigned int> GetCBlack(int channel);
67   int GetColorCount();
68 
69  private:
70   absl::Status InitLibRaw();
71 
72   LibRawSapiSandbox* sandbox_;
73   LibRawApi api_;
74   absl::Status init_status_;
75 
76   std::string file_name_;
77 
78   sapi::v::Struct<libraw_data_t> sapi_libraw_data_t_;
79 };
80 
81 #endif  // CONTRIB_LIBRAW_UTILS_UTILS_LIBRAW_H_
82