mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-29 21:30:53 +00:00
Split LoadEXR and SaveEXR to expose functions that take a FILE*
This commit is contained in:
+35
-5
@@ -6979,7 +6979,7 @@ void DecompressZip(unsigned char *dst, unsigned long &uncompressedSize,
|
||||
|
||||
int LoadEXR(float **out_rgba, int *width, int *height, const char *filename,
|
||||
const char **err) {
|
||||
if (out_rgba == NULL) {
|
||||
if (filename == NULL) {
|
||||
if (err) {
|
||||
(*err) = "Invalid argument.";
|
||||
}
|
||||
@@ -6994,6 +6994,23 @@ int LoadEXR(float **out_rgba, int *width, int *height, const char *filename,
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = LoadEXRFP(out_rgba, width, height, fp, err);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LoadEXRFP(float **out_rgba, int *width, int *height, FILE *fp,
|
||||
const char **err)
|
||||
{
|
||||
if (out_rgba == NULL || fp == NULL) {
|
||||
if (err) {
|
||||
(*err) = "Invalid argument.";
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t filesize;
|
||||
// Compute size
|
||||
fseek(fp, 0, SEEK_END);
|
||||
@@ -7005,7 +7022,6 @@ int LoadEXR(float **out_rgba, int *width, int *height, const char *filename,
|
||||
size_t ret;
|
||||
ret = fread(&buf[0], 1, filesize, fp);
|
||||
assert(ret == filesize);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
const char *head = &buf[0];
|
||||
@@ -7570,7 +7586,7 @@ int LoadMultiChannelEXR(EXRImage *exrImage, const char *filename,
|
||||
|
||||
int SaveEXR(const float *in_rgba, int width, int height, const char *filename,
|
||||
const char **err) {
|
||||
if (in_rgba == NULL || filename == NULL) {
|
||||
if (filename == NULL) {
|
||||
if (err) {
|
||||
(*err) = "Invalid argument.";
|
||||
}
|
||||
@@ -7585,6 +7601,22 @@ int SaveEXR(const float *in_rgba, int width, int height, const char *filename,
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = SaveEXRFP(in_rgba, width, height, fp, err);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SaveEXRFP(const float *in_rgba, int width, int height, FILE *fp,
|
||||
const char **err) {
|
||||
if (in_rgba == NULL || fp == NULL) {
|
||||
if (err) {
|
||||
(*err) = "Invalid argument.";
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Header
|
||||
{
|
||||
const char header[] = {0x76, 0x2f, 0x31, 0x01};
|
||||
@@ -7733,8 +7765,6 @@ int SaveEXR(const float *in_rgba, int width, int height, const char *filename,
|
||||
|
||||
fwrite(&data.at(0), 1, data.size(), fp);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return 0; // OK
|
||||
}
|
||||
|
||||
|
||||
Vendored
+19
@@ -49,6 +49,7 @@ typedef struct {
|
||||
} DeepImage;
|
||||
|
||||
// Loads single-frame OpenEXR image. Assume EXR image contains RGB(A) channels.
|
||||
// Takes filename as parameter
|
||||
// Application must free image data as returned by `out_rgba`
|
||||
// Result image format is: float x RGBA x width x hight
|
||||
// Return 0 if success
|
||||
@@ -56,6 +57,15 @@ typedef struct {
|
||||
extern int LoadEXR(float **out_rgba, int *width, int *height,
|
||||
const char *filename, const char **err);
|
||||
|
||||
// Loads single-frame OpenEXR image. Assume EXR image contains RGB(A) channels.
|
||||
// Takes file pointer as parameter.
|
||||
// Application must free image data as returned by `out_rgba`
|
||||
// Result image format is: float x RGBA x width x hight
|
||||
// Return 0 if success
|
||||
// Returns error string in `err` when there's an error
|
||||
extern int LoadEXRFP(float **out_rgba, int *width, int *height,
|
||||
FILE *fp, const char **err);
|
||||
|
||||
// Loads multi-channel, single-frame OpenEXR image.
|
||||
// Application must free EXRImage
|
||||
// Return 0 if success
|
||||
@@ -64,12 +74,21 @@ extern int LoadMultiChannelEXR(EXRImage *image, const char *filename,
|
||||
const char **err);
|
||||
|
||||
// Saves floating point RGBA image as OpenEXR.
|
||||
// Takes filename as parameter
|
||||
// Image is compressed with ZIP.
|
||||
// Return 0 if success
|
||||
// Returns error string in `err` when there's an error
|
||||
extern int SaveEXR(const float *in_rgba, int width, int height,
|
||||
const char *filename, const char **err);
|
||||
|
||||
// Saves floating point RGBA image as OpenEXR.
|
||||
// Takes file pointer as parameter.
|
||||
// Image is compressed with ZIP.
|
||||
// Return 0 if success
|
||||
// Returns error string in `err` when there's an error
|
||||
extern int SaveEXRFP(const float *in_rgba, int width, int height,
|
||||
FILE *fp, const char **err);
|
||||
|
||||
// Saves multi-channel, single-frame OpenEXR image.
|
||||
// Application must free EXRImage
|
||||
// Return 0 if success
|
||||
|
||||
Reference in New Issue
Block a user