-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a581d41
Showing
7 changed files
with
5,448 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
all: | ||
g++ -o test_tinyexr tinyexr.cc test.cc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Tiny OpenEXR image loader. | ||
|
||
 | ||
|
||
`tinyexr` is a small library to load OpenEXR(.exr) image. | ||
TO use `tinyexr`, simply copy `tinyexr.cc` and `tinyexr.h` into your project. | ||
|
||
`tinyexr` currently supports: | ||
|
||
* OpenEXR version 1.x. | ||
* RGB(A) channel. | ||
* Scanline format. | ||
* ZIP compression. | ||
* Half pixel type. | ||
* Litte endian machine. | ||
|
||
## TODO | ||
|
||
* Tile format. | ||
* Support for various compression type. | ||
* Multi-channel. | ||
* Pixel order. | ||
* EXR 2.0(deep image). | ||
* Big endian machine. | ||
|
||
## License | ||
|
||
3-clause BSD | ||
|
||
`tinyexr` uses miniz, which is developed by Rich Geldreich <[email protected]>, and licensed under public domain. | ||
|
||
## Author(s) | ||
|
||
Syoyo Fujita([email protected]) |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <cstdlib> | ||
#include <cstdio> | ||
#include <vector> | ||
|
||
#include "tinyexr.h" | ||
|
||
void | ||
SaveAsPFM(const char* filename, int width, int height, float* data) | ||
{ | ||
FILE* fp = fopen(filename, "wb"); | ||
if (!fp) { | ||
fprintf(stderr, "failed to write a PFM file.\n"); | ||
return; | ||
} | ||
|
||
fprintf(fp, "PF\n"); | ||
fprintf(fp, "%d %d\n", width, height); | ||
fprintf(fp, "-1\n"); // -1: little endian, 1: big endian | ||
|
||
// RGBA -> RGB | ||
std::vector<float> rgb(width*height*3); | ||
|
||
for (size_t i = 0; i < width * height; i++) { | ||
rgb[3*i+0] = data[4*i+0]; | ||
rgb[3*i+1] = data[4*i+1]; | ||
rgb[3*i+2] = data[4*i+2]; | ||
} | ||
|
||
fwrite(&rgb.at(0), sizeof(float), width * height * 3, fp); | ||
|
||
fclose(fp); | ||
} | ||
|
||
int | ||
main(int argc, char** argv) | ||
{ | ||
float* out; | ||
int width; | ||
int height; | ||
const char* err; | ||
|
||
if (argc < 2) { | ||
fprintf(stderr, "Needs input.exr.\n"); | ||
exit(-1); | ||
} | ||
|
||
int ret = LoadEXR(&out, &width, &height, argv[1], &err); | ||
if (ret != 0) { | ||
fprintf(stderr, "Load EXR err.\n"); | ||
return ret; | ||
} | ||
|
||
printf("EXR: %d x %d\n", width, height); | ||
|
||
SaveAsPFM("output.pfm", width, height, out); | ||
|
||
printf("Saved pfm file.\n"); | ||
|
||
free(out); | ||
|
||
return ret; | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef __TINYEXR_H__ | ||
#define __TINYEXR_H__ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
// Application must free image data as returned by `out_rgba` | ||
// Result image format is: float x RGBA x width x hight | ||
// returns error string in `err` when there's an error | ||
extern int LoadEXR(float** out_rgba, int* width, int* height, const char* filename, const char** err); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // __TINYEXR_H__ |