cleanup + img.raw

This commit is contained in:
Piotr Bartman 2022-03-30 17:39:48 +02:00
parent a505222184
commit 7fc66b2026
6 changed files with 77 additions and 102 deletions

View File

@ -21,7 +21,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
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")
add_subdirectory(
"${SAPI_ROOT}"
@ -74,16 +74,17 @@ add_sapi_library(
NAMESPACE ""
)
add_library(sapi_contrib::libraw ALIAS sapi_libraw)
target_include_directories(
sapi_libraw INTERFACE
"${PROJECT_BINARY_DIR}"
)
if(SAPI_ENABLE_EXAMPLES)
if (SAPI_ENABLE_EXAMPLES)
add_subdirectory(example)
endif()
if(SAPI_ENABLE_TESTS)
if (SAPI_ENABLE_TESTS)
add_subdirectory(test)
endif()

View File

@ -13,15 +13,15 @@
# limitations under the License.
add_executable(
sapi_minilibraw
sapi_minilibraw
main.cc
../utils/utils_libraw.cc
main.cc
../utils/utils_libraw.cc
)
target_link_libraries(
sapi_minilibraw PRIVATE
sapi_minilibraw PRIVATE
sapi_libraw
sapi::sapi
sapi_libraw
sapi::sapi
)

View File

@ -12,33 +12,31 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdio.h>
#include <string.h>
#include <iomanip>
#include <iostream>
#include "contrib/libraw/sandboxed.h"
#include "contrib/libraw/utils/utils_libraw.h"
void usage(const char* av) {
printf(
"Dump (small) selecton of RAW file as tab-separated text file\n"
"Usage: %s inputfile COL ROW [CHANNEL] [width] [height]\n"
" COL - start column\n"
" ROW - start row\n"
" CHANNEL - raw channel to dump, default is 0 (red for rggb)\n"
" width - area width to dump, default is 16\n"
" height - area height to dump, default is 4\n",
av);
std::cout << "Dump (small) selecton of RAW file as tab-separated text file\n"
<< "Usage: " << av
<< " inputfile COL ROW [CHANNEL] [width] [height]\n"
" COL - start column\n"
" ROW - start row\n"
" CHANNEL - raw channel to dump, default is 0 (red for rggb)\n"
" width - area width to dump, default is 16\n"
" height - area height to dump, default is 4\n";
}
unsigned subtract_bl(int val, int bl) {
return val > bl ? val - bl : 0;
}
unsigned subtract_bl(int val, int bl) { return val > bl ? val - bl : 0; }
int main(int ac, char* av[]) {
google::InitGoogleLogging(av[0]);
if (ac < 4)
{
if (ac < 4) {
usage(av[0]);
exit(1);
}
@ -50,8 +48,7 @@ int main(int ac, char* av[]) {
if (ac > 5) width = atoi(av[5]);
int height = 4;
if (ac > 6) height = atoi(av[6]);
if (width < 1 || height < 1)
{
if (width < 1 || height < 1) {
usage(av[0]);
exit(1);
}
@ -59,8 +56,7 @@ int main(int ac, char* av[]) {
sapi::v::ConstCStr file_name(av[1]);
LibRawSapiSandbox sandbox(file_name.GetData());
if (!sandbox.Init().ok())
{
if (!sandbox.Init().ok()) {
std::cerr << "Unable to start sandbox\n";
return EXIT_FAILURE;
}
@ -68,107 +64,85 @@ int main(int ac, char* av[]) {
absl::Status status;
LibRaw lr(&sandbox, av[1]);
if (not lr.CheckIsInit().ok())
{
fprintf(stderr, "Unable init LibRaw");
if (not lr.CheckIsInit().ok()) {
std::cerr << "Unable init LibRaw";
return EXIT_FAILURE;
}
status = lr.OpenFile();
if (not status.ok())
{
fprintf(stderr, "Unable to open file %s\n", av[1]);
if (not status.ok()) {
std::cerr << "Unable to open file" << av[1] << "\n";
return EXIT_FAILURE;
}
if ((lr.GetImgData().idata.colors == 1 and channel > 0)
or
(channel > 3))
{
fprintf(stderr, "Incorrect CHANNEL specified: %d\n", channel);
if ((lr.GetImgData().idata.colors == 1 and channel > 0) or (channel > 3)) {
std::cerr << "Incorrect CHANNEL specified:" << channel << "\n";
return EXIT_FAILURE;
}
status = lr.Unpack();
if (not status.ok())
{
fprintf(stderr, "Unable to unpack file %s\n", av[1]);
if (not status.ok()) {
std::cerr << "Unable to unpack file" << av[1] << "\n";
return EXIT_FAILURE;
}
status = lr.SubtractBlack();
if (not status.ok())
{
fprintf(stderr, "Unable to subtract black level");
if (not status.ok()) {
std::cerr << "Unable to subtract black level";
}
printf("%s\t%d-%d-%dx%d\tchannel: %d\n",
av[1], colstart, rowstart, width, height, channel);
printf("%6s", "R\\C");
std::cout << av[1] << "\t" << colstart << "-" << rowstart << "-" << width
<< "x" << height << "\t"
<< "channel: " << channel << "\n";
std::cout << std::setw(6) << "R\\C";
for (int col = colstart;
col < colstart + width and
col < lr.GetImgData().sizes.raw_width;
col++)
{
printf("%6u", col);
col < colstart + width and col < lr.GetImgData().sizes.raw_width;
col++) {
std::cout << std::setw(6) << 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();
if (not rawdata.ok())
{
fprintf(stderr, "Unable to get raw data\n");
if (not rawdata.ok()) {
std::cerr << "Unable to get raw data\n";
return EXIT_FAILURE;
}
for (int row = rowstart;
row < rowstart + height &&
row < lr.GetImgData().sizes.raw_height;
row++)
{
row < rowstart + height && row < lr.GetImgData().sizes.raw_height;
row++) {
unsigned rcolors[48];
if (lr.GetImgData().idata.colors > 1)
{
if (lr.GetImgData().idata.colors > 1) {
absl::StatusOr<int> color;
for (int c = 0; c < 48; c++)
{
for (int c = 0; c < 48; c++) {
color = lr.COLOR(row, c);
if (color.ok()) rcolors[c] = *color;
}
}
else
{
} else {
memset(rcolors, 0, sizeof(rcolors));
}
printf("%6u", row);
std::cout << std::setw(6) << row;
for (int col = colstart;
col < colstart + width &&
col < lr.GetImgData().sizes.raw_width;
col < colstart + width && col < lr.GetImgData().sizes.raw_width;
col++) {
int idx = row * lr.GetImgData().sizes.raw_pitch / 2 + col;
if (rcolors[col % 48] == (unsigned)channel)
{
printf("%6u",
subtract_bl((*rawdata)[idx],
lr.GetImgData().color.cblack[channel]));
}
else
{
printf(" -");
if (rcolors[col % 48] == (unsigned)channel) {
std::cout << std::setw(6)
<< subtract_bl((*rawdata)[idx],
lr.GetImgData().color.cblack[channel]);
} else {
std::cout << " -";
}
}
printf("\n");
std::cout << "\n";
}
}
else
{
printf(
"Unsupported file data (e.g. floating point format), or incorrect "
"channel specified\n");
} else {
std::cout
<< "Unsupported file data (e.g. floating point format), or incorrect "
"channel specified\n";
}
return EXIT_SUCCESS;

Binary file not shown.

View File

@ -13,8 +13,8 @@
// limitations under the License.
#include "contrib/libraw/utils/utils_libraw.h"
#include "contrib/libraw/sandboxed.h"
#include "contrib/libraw/sandboxed.h"
absl::Status LibRaw::InitLibRaw() {
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());
}
absl::StatusOr<std::vector<char *>> LibRaw::GetCameraList() {
absl::StatusOr<std::vector<char*>> LibRaw::GetCameraList() {
SAPI_RETURN_IF_ERROR(CheckIsInit());
int size;
SAPI_ASSIGN_OR_RETURN(size, api_.libraw_cameraCount());
std::vector<char *> buf(size);
sapi::v::Array<char *> camera_list(buf.data(), buf.size());
std::vector<char*> 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());
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;
}
@ -112,7 +112,7 @@ absl::StatusOr<std::vector<uint16_t>> LibRaw::RawData() {
sapi::v::Array<uint16_t> rawdata(buf.data(), buf.size());
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;
}

View File

@ -16,10 +16,10 @@
#define CONTRIB_LIBRAW_UTILS_UTILS_LIBRAW_H_
#include <vector>
#include "contrib/libraw/sandboxed.h"
enum LibRaw_errors
{
enum LibRaw_errors {
LIBRAW_SUCCESS = 0,
LIBRAW_UNSPECIFIED_ERROR = -1,
LIBRAW_FILE_UNSUPPORTED = -2,
@ -38,7 +38,6 @@ enum LibRaw_errors
LIBRAW_MEMPOOL_OVERFLOW = -100013
};
class LibRaw {
public:
LibRaw(LibRawSapiSandbox* sandbox, const std::string& file_name)
@ -59,19 +58,20 @@ class LibRaw {
absl::Status OpenFile();
absl::Status Unpack();
absl::Status SubtractBlack();
absl::StatusOr<std::vector<char *>> GetCameraList();
absl::StatusOr<std::vector<char*>> GetCameraList();
absl::StatusOr<int> COLOR(int row, int col);
private:
absl::Status InitLibRaw();
LibRawSapiSandbox * sandbox_;
LibRawSapiSandbox* sandbox_;
LibRawApi api_;
absl::Status init_status_;
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_