Skip to content

Commit

Permalink
Remove Dcraw binary usage
Browse files Browse the repository at this point in the history
Removes dependence on the dcraw binary in order to produce a more portable binary that can be moved into other directories without errors about the location of the dcraw binary.
  • Loading branch information
Titaniumtown committed Apr 7, 2019
1 parent c5e7891 commit d7c35ce
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10,314 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Note: The user "Titaniumtown" is now the primary maintainer of this repository;
Original Document on the subject (by Timothy Brooks): http://timothybrooks.com/tech/hdr-plus

### Compilation instructions:
1. Install libraw¹, libpng, and libjpeg.²
1. Install libraw, libpng, and libjpeg.¹
2. Download and compile llvm 3.9
3. Download the "2017-05-03" source of Halide from https://github.com/halide/Halide_old_history/releases
4. Compile Halide according to the README.md file included with the source file zip of halide.
Expand Down Expand Up @@ -32,9 +32,5 @@ Usage: ./hdrplus [-c comp -g gain (optional)] dir_path out_img raw_img1 raw_img2
The -c and -g flags change the amount of dynamic range compression and gain respectively. Although they are optional because they both have default values.

### Footnotes:

¹ If you are on macOS the included dcraw binary will not work so I included the macos version in the same directory. If you are on macOS change the following "../tools/dcraw" to "../tools/dcraw_macos" in the files below before compiling:
- batch_dcraw.py
- halide_load_raw.h

² Also to install libraw, libpng, and libjpeg on macOS run ```brew install libraw libpng libjpeg```
¹Also to install libraw, libpng, and libjpeg on macOS run ```brew install libraw libpng libjpeg```
8 changes: 0 additions & 8 deletions src/batch_dcraw.py

This file was deleted.

49 changes: 9 additions & 40 deletions src/halide_load_raw.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,50 +45,19 @@ inline void swap_endian_16(uint16_t &value) {

template<Internal::CheckFunc check = Internal::CheckFail>
bool load_raw(const std::string &filename, uint16_t* data, int width, int height) {

Internal::PipeOpener f(("../tools/dcraw -c -D -6 -W -g 1 1 " + filename).c_str(), "r");
if (!check(f.f != nullptr, "File could not be opened for reading\n"))
return false;

int in_width, in_height, maxval;
char header[256];
char buf[1024];
bool fmt_binary = false;

f.readLine(buf, 1024);
if (!check(sscanf(buf, "%255s", header) == 1, "Could not read PGM header\n")) return false;
if (header == std::string("P5") || header == std::string("p5"))
fmt_binary = true;
if (!check(fmt_binary, "Input is not binary PGM\n")) return false;

f.readLine(buf, 1024);
if (!check(sscanf(buf, "%d %d\n", &in_width, &in_height) == 2, "Could not read PGM width and height\n")) return false;

if (!check(in_width == width, "Input image has width %d, but must must have width of %d\n")) return false;

if (!check(in_height == height, "Input image '%s' has height %d, but must must have height of %d\n")) return false;

f.readLine(buf, 1024);
if (!check(sscanf(buf, "%d", &maxval) == 1, "Could not read PGM max value\n")) return false;

if (!check(maxval == 65535, "Invalid bit depth (not 16 bits) in PGM\n")) return false;

if (!check(fread((void *) data, sizeof(uint16_t), width*height, f.f) == (size_t) (width*height), "Could not read PGM 16-bit data\n")) return false;

if (is_little_endian()) {

for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {

swap_endian_16(data[y * width + x]);
}
}
LibRaw RawProcessor;
int ret = RawProcessor.dcraw_process();

if (LIBRAW_SUCCESS != ret)
{
fprintf(stderr, "Cannot open %s: %s\n", filename, libraw_strerror(ret));
return ret;
}

return true;
}

} // namespace Tools
} // namespace Halide

#endif
#endif
Binary file removed tools/dcraw
Binary file not shown.
Binary file removed tools/dcraw_macos
Binary file not shown.
Loading

0 comments on commit d7c35ce

Please sign in to comment.