50 #define MAXELEN 0x7fff
57 typedef unsigned char RGBE[4];
61 #define COPY_RGBE(c1, c2) \
62 (c2[RED] = c1[RED], c2[GRN] = c1[GRN], c2[BLU] = c1[BLU], c2[EXP] = c1[EXP])
66 const unsigned char *mem,
68 const unsigned char *mem_eof)
70 size_t i, rshift = 0,
len = xmax;
75 scan[0][
RED] = *mem++;
76 scan[0][
GRN] = *mem++;
77 scan[0][
BLU] = *mem++;
78 scan[0][
EXP] = *mem++;
79 if (scan[0][
RED] == 1 && scan[0][
GRN] == 1 && scan[0][
BLU] == 1) {
80 for (i = scan[0][
EXP] << rshift; i > 0 &&
len > 0; i--) {
97 const unsigned char *mem,
99 const unsigned char *mem_eof)
114 scan[0][
GRN] = *mem++;
115 scan[0][
BLU] = *mem++;
119 if (scan[0][
GRN] != 2 || scan[0][
BLU] & 128) {
125 if (
UNLIKELY(((scan[0][
BLU] << 8) | val) != xmax)) {
129 for (
size_t i = 0; i < 4; i++) {
133 for (
size_t j = 0; j < xmax;) {
142 scan[j++][i] = (
unsigned char)val;
146 if (
UNLIKELY(mem_eof - mem < code)) {
153 scan[j++][i] = *mem++;
167 if (rgbe[
EXP] == 0) {
171 float f = ldexp(1.0, rgbe[
EXP] - (
COLXS + 8));
172 fcol[
RED] = f * (rgbe[
RED] + 0.5f);
173 fcol[
GRN] = f * (rgbe[
GRN] + 0.5f);
174 fcol[
BLU] = f * (rgbe[
BLU] + 0.5f);
182 float d = (fcol[
RED] > fcol[
GRN]) ? fcol[
RED] : fcol[
GRN];
190 d = (
float)frexp(d, &
e) * 256.0f / d;
191 rgbe[
RED] = (
unsigned char)(fcol[
RED] * d);
192 rgbe[
GRN] = (
unsigned char)(fcol[
GRN] * d);
193 rgbe[
BLU] = (
unsigned char)(fcol[
BLU] * d);
211 const unsigned char magic[2] = {
'#',
'?'};
215 return memcmp(buf,
magic,
sizeof(
magic)) == 0;
229 const unsigned char *
ptr, *mem_eof = mem +
size;
230 char oriY[3], oriX[3];
241 if ((mem[
x - 1] ==
'\n') && (mem[
x] ==
'\n')) {
247 if ((found && (
x < (
size - 1))) == 0) {
256 memcpy(buf, &mem[
x],
MIN2(
sizeof(buf) - 1,
size -
x));
275 ptr = (
const unsigned char *)strchr((
const char *)&mem[
x],
'\n');
292 ibuf->
ftype = IMB_FTYPE_RADHDR;
309 printf(
"WARNING! HDR decode error, image may be just truncated, or completely wrong...\n");
322 if (oriY[0] ==
'-') {
335 FILE *
file,
int width,
int channels,
const unsigned char *ibufscan,
const float *fpscan)
337 int beg, c2, cnt = 0;
339 RGBE rgbe, *rgbe_scan;
348 for (
size_t i = 0, j = 0; i <
width; i++) {
350 fcol[
RED] = fpscan[j];
351 fcol[
GRN] = (
channels >= 2) ? fpscan[j + 1] : fpscan[j];
352 fcol[
BLU] = (
channels >= 3) ? fpscan[j + 2] : fpscan[j];
355 fcol[
RED] = (
float)ibufscan[j] / 255.0f;
356 fcol[
GRN] = (
float)((
channels >= 2) ? ibufscan[j + 1] : ibufscan[j]) / 255.0f;
357 fcol[
BLU] = (
float)((
channels >= 3) ? ibufscan[j + 2] : ibufscan[j]) / 255.0f;
373 putc((
unsigned char)(
width & 255),
file);
375 for (
size_t i = 0; i < 4; i++) {
376 for (
size_t j = 0; j <
width; j += cnt) {
377 for (beg = j; beg <
width; beg += cnt) {
378 for (cnt = 1; (cnt < 127) && ((beg + cnt) <
width) &&
379 (rgbe_scan[beg + cnt][i] == rgbe_scan[beg][i]);
387 if (((beg - j) > 1) && ((beg - j) <
MINRUN)) {
389 while (rgbe_scan[c2++][i] == rgbe_scan[j][i]) {
391 putc((
unsigned char)(128 + beg - j),
file);
392 putc((
unsigned char)(rgbe_scan[j][i]),
file);
399 if ((c2 = beg - j) > 128) {
402 putc((
unsigned char)(c2),
file);
404 putc(rgbe_scan[j++][i],
file);
408 putc((
unsigned char)(128 + cnt),
file);
409 putc(rgbe_scan[beg][i],
file);
417 return (ferror(
file) ? -1 : 0);
422 fprintf(
file,
"#?RADIANCE");
424 fprintf(
file,
"# %s",
"Created with Blender");
426 fprintf(
file,
"EXPOSURE=%25.13f", 1.0);
428 fprintf(
file,
"FORMAT=32-bit_rle_rgbe");
440 unsigned char *cp =
NULL;
460 printf(
"HDR write error\n");
typedef float(TangentPoint)[2]
File and directory operations.
FILE * BLI_fopen(const char *filename, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
Header file for allocimbuf.c.
@ COLOR_ROLE_DEFAULT_FLOAT
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
void IMB_rect_from_float(struct ImBuf *ibuf)
void IMB_flipy(struct ImBuf *ibuf)
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void colorspace_set_default_role(char *colorspace, int size, int role)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
static const unsigned char * oldreadcolrs(RGBE *scan, const unsigned char *mem, int xmax, const unsigned char *mem_eof)
static const unsigned char * freadcolrs(RGBE *scan, const unsigned char *mem, int xmax, const unsigned char *mem_eof)
static void writeHeader(FILE *file, int width, int height)
struct ImBuf * imb_loadhdr(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
static void FLOAT2RGBE(const fCOLOR fcol, RGBE rgbe)
bool imb_is_a_hdr(const unsigned char *buf, const size_t size)
static int fwritecolrs(FILE *file, int width, int channels, const unsigned char *ibufscan, const float *fpscan)
bool imb_savehdr(struct ImBuf *ibuf, const char *filepath, int flags)
#define COPY_RGBE(c1, c2)
static void RGBE2FLOAT(RGBE rgbe, fCOLOR fcol)
static int magic(const Tex *tex, const float texvec[3], TexResult *texres)