mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
cleanup + img.raw
This commit is contained in:
parent
a505222184
commit
7fc66b2026
|
@ -21,7 +21,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
|
||||||
set(SAPI_ROOT "" CACHE PATH "Path to the Sandboxed API source tree")
|
set(SAPI_ROOT "" CACHE PATH "Path to the Sandboxed API source tree")
|
||||||
|
|
||||||
if(NOT TARGET sapi::sapi)
|
if (NOT TARGET sapi::sapi)
|
||||||
set(SAPI_ROOT "../.." CACHE PATH "Path to the Sandboxed API source tree")
|
set(SAPI_ROOT "../.." CACHE PATH "Path to the Sandboxed API source tree")
|
||||||
add_subdirectory(
|
add_subdirectory(
|
||||||
"${SAPI_ROOT}"
|
"${SAPI_ROOT}"
|
||||||
|
@ -74,16 +74,17 @@ add_sapi_library(
|
||||||
NAMESPACE ""
|
NAMESPACE ""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_library(sapi_contrib::libraw ALIAS sapi_libraw)
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
sapi_libraw INTERFACE
|
sapi_libraw INTERFACE
|
||||||
|
|
||||||
"${PROJECT_BINARY_DIR}"
|
"${PROJECT_BINARY_DIR}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if(SAPI_ENABLE_EXAMPLES)
|
if (SAPI_ENABLE_EXAMPLES)
|
||||||
add_subdirectory(example)
|
add_subdirectory(example)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(SAPI_ENABLE_TESTS)
|
if (SAPI_ENABLE_TESTS)
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -13,15 +13,15 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
add_executable(
|
add_executable(
|
||||||
sapi_minilibraw
|
sapi_minilibraw
|
||||||
|
|
||||||
main.cc
|
main.cc
|
||||||
../utils/utils_libraw.cc
|
../utils/utils_libraw.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
sapi_minilibraw PRIVATE
|
sapi_minilibraw PRIVATE
|
||||||
|
|
||||||
sapi_libraw
|
sapi_libraw
|
||||||
sapi::sapi
|
sapi::sapi
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,33 +12,31 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "contrib/libraw/sandboxed.h"
|
#include "contrib/libraw/sandboxed.h"
|
||||||
#include "contrib/libraw/utils/utils_libraw.h"
|
#include "contrib/libraw/utils/utils_libraw.h"
|
||||||
|
|
||||||
void usage(const char* av) {
|
void usage(const char* av) {
|
||||||
printf(
|
std::cout << "Dump (small) selecton of RAW file as tab-separated text file\n"
|
||||||
"Dump (small) selecton of RAW file as tab-separated text file\n"
|
<< "Usage: " << av
|
||||||
"Usage: %s inputfile COL ROW [CHANNEL] [width] [height]\n"
|
<< " inputfile COL ROW [CHANNEL] [width] [height]\n"
|
||||||
" COL - start column\n"
|
" COL - start column\n"
|
||||||
" ROW - start row\n"
|
" ROW - start row\n"
|
||||||
" CHANNEL - raw channel to dump, default is 0 (red for rggb)\n"
|
" CHANNEL - raw channel to dump, default is 0 (red for rggb)\n"
|
||||||
" width - area width to dump, default is 16\n"
|
" width - area width to dump, default is 16\n"
|
||||||
" height - area height to dump, default is 4\n",
|
" height - area height to dump, default is 4\n";
|
||||||
av);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned subtract_bl(int val, int bl) {
|
unsigned subtract_bl(int val, int bl) { return val > bl ? val - bl : 0; }
|
||||||
return val > bl ? val - bl : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int ac, char* av[]) {
|
int main(int ac, char* av[]) {
|
||||||
google::InitGoogleLogging(av[0]);
|
google::InitGoogleLogging(av[0]);
|
||||||
|
|
||||||
if (ac < 4)
|
if (ac < 4) {
|
||||||
{
|
|
||||||
usage(av[0]);
|
usage(av[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -50,8 +48,7 @@ int main(int ac, char* av[]) {
|
||||||
if (ac > 5) width = atoi(av[5]);
|
if (ac > 5) width = atoi(av[5]);
|
||||||
int height = 4;
|
int height = 4;
|
||||||
if (ac > 6) height = atoi(av[6]);
|
if (ac > 6) height = atoi(av[6]);
|
||||||
if (width < 1 || height < 1)
|
if (width < 1 || height < 1) {
|
||||||
{
|
|
||||||
usage(av[0]);
|
usage(av[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -59,8 +56,7 @@ int main(int ac, char* av[]) {
|
||||||
sapi::v::ConstCStr file_name(av[1]);
|
sapi::v::ConstCStr file_name(av[1]);
|
||||||
|
|
||||||
LibRawSapiSandbox sandbox(file_name.GetData());
|
LibRawSapiSandbox sandbox(file_name.GetData());
|
||||||
if (!sandbox.Init().ok())
|
if (!sandbox.Init().ok()) {
|
||||||
{
|
|
||||||
std::cerr << "Unable to start sandbox\n";
|
std::cerr << "Unable to start sandbox\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -68,107 +64,85 @@ int main(int ac, char* av[]) {
|
||||||
absl::Status status;
|
absl::Status status;
|
||||||
|
|
||||||
LibRaw lr(&sandbox, av[1]);
|
LibRaw lr(&sandbox, av[1]);
|
||||||
if (not lr.CheckIsInit().ok())
|
if (not lr.CheckIsInit().ok()) {
|
||||||
{
|
std::cerr << "Unable init LibRaw";
|
||||||
fprintf(stderr, "Unable init LibRaw");
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = lr.OpenFile();
|
status = lr.OpenFile();
|
||||||
if (not status.ok())
|
if (not status.ok()) {
|
||||||
{
|
std::cerr << "Unable to open file" << av[1] << "\n";
|
||||||
fprintf(stderr, "Unable to open file %s\n", av[1]);
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((lr.GetImgData().idata.colors == 1 and channel > 0)
|
if ((lr.GetImgData().idata.colors == 1 and channel > 0) or (channel > 3)) {
|
||||||
or
|
std::cerr << "Incorrect CHANNEL specified:" << channel << "\n";
|
||||||
(channel > 3))
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Incorrect CHANNEL specified: %d\n", channel);
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = lr.Unpack();
|
status = lr.Unpack();
|
||||||
if (not status.ok())
|
if (not status.ok()) {
|
||||||
{
|
std::cerr << "Unable to unpack file" << av[1] << "\n";
|
||||||
fprintf(stderr, "Unable to unpack file %s\n", av[1]);
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = lr.SubtractBlack();
|
status = lr.SubtractBlack();
|
||||||
if (not status.ok())
|
if (not status.ok()) {
|
||||||
{
|
std::cerr << "Unable to subtract black level";
|
||||||
fprintf(stderr, "Unable to subtract black level");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s\t%d-%d-%dx%d\tchannel: %d\n",
|
std::cout << av[1] << "\t" << colstart << "-" << rowstart << "-" << width
|
||||||
av[1], colstart, rowstart, width, height, channel);
|
<< "x" << height << "\t"
|
||||||
printf("%6s", "R\\C");
|
<< "channel: " << channel << "\n";
|
||||||
|
std::cout << std::setw(6) << "R\\C";
|
||||||
for (int col = colstart;
|
for (int col = colstart;
|
||||||
col < colstart + width and
|
col < colstart + width and col < lr.GetImgData().sizes.raw_width;
|
||||||
col < lr.GetImgData().sizes.raw_width;
|
col++) {
|
||||||
col++)
|
std::cout << std::setw(6) << col;
|
||||||
{
|
|
||||||
printf("%6u", col);
|
|
||||||
}
|
}
|
||||||
printf("\n");
|
std::cout << "\n";
|
||||||
|
|
||||||
if (lr.GetImgData().rawdata.raw_image)
|
if (lr.GetImgData().rawdata.raw_image) {
|
||||||
{
|
|
||||||
absl::StatusOr<std::vector<uint16_t>> rawdata = lr.RawData();
|
absl::StatusOr<std::vector<uint16_t>> rawdata = lr.RawData();
|
||||||
if (not rawdata.ok())
|
if (not rawdata.ok()) {
|
||||||
{
|
std::cerr << "Unable to get raw data\n";
|
||||||
fprintf(stderr, "Unable to get raw data\n");
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int row = rowstart;
|
for (int row = rowstart;
|
||||||
row < rowstart + height &&
|
row < rowstart + height && row < lr.GetImgData().sizes.raw_height;
|
||||||
row < lr.GetImgData().sizes.raw_height;
|
row++) {
|
||||||
row++)
|
|
||||||
{
|
|
||||||
unsigned rcolors[48];
|
unsigned rcolors[48];
|
||||||
if (lr.GetImgData().idata.colors > 1)
|
if (lr.GetImgData().idata.colors > 1) {
|
||||||
{
|
|
||||||
absl::StatusOr<int> color;
|
absl::StatusOr<int> color;
|
||||||
for (int c = 0; c < 48; c++)
|
for (int c = 0; c < 48; c++) {
|
||||||
{
|
|
||||||
color = lr.COLOR(row, c);
|
color = lr.COLOR(row, c);
|
||||||
if (color.ok()) rcolors[c] = *color;
|
if (color.ok()) rcolors[c] = *color;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
memset(rcolors, 0, sizeof(rcolors));
|
memset(rcolors, 0, sizeof(rcolors));
|
||||||
}
|
}
|
||||||
printf("%6u", row);
|
std::cout << std::setw(6) << row;
|
||||||
|
|
||||||
for (int col = colstart;
|
for (int col = colstart;
|
||||||
col < colstart + width &&
|
col < colstart + width && col < lr.GetImgData().sizes.raw_width;
|
||||||
col < lr.GetImgData().sizes.raw_width;
|
|
||||||
col++) {
|
col++) {
|
||||||
int idx = row * lr.GetImgData().sizes.raw_pitch / 2 + col;
|
int idx = row * lr.GetImgData().sizes.raw_pitch / 2 + col;
|
||||||
|
|
||||||
if (rcolors[col % 48] == (unsigned)channel)
|
if (rcolors[col % 48] == (unsigned)channel) {
|
||||||
{
|
std::cout << std::setw(6)
|
||||||
printf("%6u",
|
<< subtract_bl((*rawdata)[idx],
|
||||||
subtract_bl((*rawdata)[idx],
|
lr.GetImgData().color.cblack[channel]);
|
||||||
lr.GetImgData().color.cblack[channel]));
|
} else {
|
||||||
}
|
std::cout << " -";
|
||||||
else
|
|
||||||
{
|
|
||||||
printf(" -");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("\n");
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
std::cout
|
||||||
{
|
<< "Unsupported file data (e.g. floating point format), or incorrect "
|
||||||
printf(
|
"channel specified\n";
|
||||||
"Unsupported file data (e.g. floating point format), or incorrect "
|
|
||||||
"channel specified\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
BIN
contrib/libraw/files/img.raw
Normal file
BIN
contrib/libraw/files/img.raw
Normal file
Binary file not shown.
|
@ -13,8 +13,8 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "contrib/libraw/utils/utils_libraw.h"
|
#include "contrib/libraw/utils/utils_libraw.h"
|
||||||
#include "contrib/libraw/sandboxed.h"
|
|
||||||
|
|
||||||
|
#include "contrib/libraw/sandboxed.h"
|
||||||
|
|
||||||
absl::Status LibRaw::InitLibRaw() {
|
absl::Status LibRaw::InitLibRaw() {
|
||||||
SAPI_ASSIGN_OR_RETURN(libraw_data_t * lr_data, api_.libraw_init(0));
|
SAPI_ASSIGN_OR_RETURN(libraw_data_t * lr_data, api_.libraw_init(0));
|
||||||
|
@ -73,20 +73,20 @@ absl::Status LibRaw::SubtractBlack() {
|
||||||
return api_.libraw_subtract_black(sapi_libraw_data_t_.PtrAfter());
|
return api_.libraw_subtract_black(sapi_libraw_data_t_.PtrAfter());
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::StatusOr<std::vector<char *>> LibRaw::GetCameraList() {
|
absl::StatusOr<std::vector<char*>> LibRaw::GetCameraList() {
|
||||||
SAPI_RETURN_IF_ERROR(CheckIsInit());
|
SAPI_RETURN_IF_ERROR(CheckIsInit());
|
||||||
|
|
||||||
int size;
|
int size;
|
||||||
SAPI_ASSIGN_OR_RETURN(size, api_.libraw_cameraCount());
|
SAPI_ASSIGN_OR_RETURN(size, api_.libraw_cameraCount());
|
||||||
|
|
||||||
std::vector<char *> buf(size);
|
std::vector<char*> buf(size);
|
||||||
sapi::v::Array<char *> camera_list(buf.data(), buf.size());
|
sapi::v::Array<char*> camera_list(buf.data(), buf.size());
|
||||||
|
|
||||||
char ** sapi_camera_list;
|
char** sapi_camera_list;
|
||||||
SAPI_ASSIGN_OR_RETURN(sapi_camera_list, api_.libraw_cameraList());
|
SAPI_ASSIGN_OR_RETURN(sapi_camera_list, api_.libraw_cameraList());
|
||||||
|
|
||||||
camera_list.SetRemote(sapi_camera_list);
|
camera_list.SetRemote(sapi_camera_list);
|
||||||
SAPI_RETURN_IF_ERROR(api_.GetSandbox()->TransferFromSandboxee(&camera_list));
|
SAPI_RETURN_IF_ERROR(sandbox_->TransferFromSandboxee(&camera_list));
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ absl::StatusOr<std::vector<uint16_t>> LibRaw::RawData() {
|
||||||
sapi::v::Array<uint16_t> rawdata(buf.data(), buf.size());
|
sapi::v::Array<uint16_t> rawdata(buf.data(), buf.size());
|
||||||
|
|
||||||
rawdata.SetRemote(sapi_libraw_data_t_.data().rawdata.raw_image);
|
rawdata.SetRemote(sapi_libraw_data_t_.data().rawdata.raw_image);
|
||||||
SAPI_RETURN_IF_ERROR(api_.GetSandbox()->TransferFromSandboxee(&rawdata));
|
SAPI_RETURN_IF_ERROR(sandbox_->TransferFromSandboxee(&rawdata));
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
#define CONTRIB_LIBRAW_UTILS_UTILS_LIBRAW_H_
|
#define CONTRIB_LIBRAW_UTILS_UTILS_LIBRAW_H_
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "contrib/libraw/sandboxed.h"
|
#include "contrib/libraw/sandboxed.h"
|
||||||
|
|
||||||
enum LibRaw_errors
|
enum LibRaw_errors {
|
||||||
{
|
|
||||||
LIBRAW_SUCCESS = 0,
|
LIBRAW_SUCCESS = 0,
|
||||||
LIBRAW_UNSPECIFIED_ERROR = -1,
|
LIBRAW_UNSPECIFIED_ERROR = -1,
|
||||||
LIBRAW_FILE_UNSUPPORTED = -2,
|
LIBRAW_FILE_UNSUPPORTED = -2,
|
||||||
|
@ -38,7 +38,6 @@ enum LibRaw_errors
|
||||||
LIBRAW_MEMPOOL_OVERFLOW = -100013
|
LIBRAW_MEMPOOL_OVERFLOW = -100013
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class LibRaw {
|
class LibRaw {
|
||||||
public:
|
public:
|
||||||
LibRaw(LibRawSapiSandbox* sandbox, const std::string& file_name)
|
LibRaw(LibRawSapiSandbox* sandbox, const std::string& file_name)
|
||||||
|
@ -59,19 +58,20 @@ class LibRaw {
|
||||||
absl::Status OpenFile();
|
absl::Status OpenFile();
|
||||||
absl::Status Unpack();
|
absl::Status Unpack();
|
||||||
absl::Status SubtractBlack();
|
absl::Status SubtractBlack();
|
||||||
absl::StatusOr<std::vector<char *>> GetCameraList();
|
absl::StatusOr<std::vector<char*>> GetCameraList();
|
||||||
absl::StatusOr<int> COLOR(int row, int col);
|
absl::StatusOr<int> COLOR(int row, int col);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
absl::Status InitLibRaw();
|
absl::Status InitLibRaw();
|
||||||
|
|
||||||
LibRawSapiSandbox * sandbox_;
|
LibRawSapiSandbox* sandbox_;
|
||||||
LibRawApi api_;
|
LibRawApi api_;
|
||||||
absl::Status init_status_;
|
absl::Status init_status_;
|
||||||
|
|
||||||
std::string file_name_;
|
std::string file_name_;
|
||||||
|
|
||||||
public: sapi::v::Struct<libraw_data_t> sapi_libraw_data_t_;
|
public:
|
||||||
|
sapi::v::Struct<libraw_data_t> sapi_libraw_data_t_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTRIB_LIBRAW_UTILS_UTILS_LIBRAW_H_
|
#endif // CONTRIB_LIBRAW_UTILS_UTILS_LIBRAW_H_
|
Loading…
Reference in New Issue
Block a user