Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Aug 27, 2014
0 parents commit a581d41
Show file tree
Hide file tree
Showing 7 changed files with 5,448 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
g++ -o test_tinyexr tinyexr.cc test.cc
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Tiny OpenEXR image loader.

![Example](https://github.com/syoyo/tinyexr/blob/master/asakusa.png?raw=true)

`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 added asakusa.exr
Binary file not shown.
Binary file added asakusa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions test.cc
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;
}
5,333 changes: 5,333 additions & 0 deletions tinyexr.cc

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions tinyexr.h
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__

0 comments on commit a581d41

Please sign in to comment.